MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / Decrypt

Method Decrypt

src/crypto/chacha20poly1305.cpp:83–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83bool AEADChaCha20Poly1305::Decrypt(std::span<const std::byte> cipher, std::span<const std::byte> aad, Nonce96 nonce, std::span<std::byte> plain1, std::span<std::byte> plain2) noexcept
84{
85 assert(cipher.size() == plain1.size() + plain2.size() + EXPANSION);
86
87 // Verify tag (using key drawn from block 0).
88 m_chacha20.Seek(nonce, 0);
89 std::byte expected_tag[EXPANSION];
90 ComputeTag(m_chacha20, aad, cipher.first(cipher.size() - EXPANSION), expected_tag);
91 if (timingsafe_bcmp_internal(UCharCast(expected_tag), UCharCast(cipher.last(EXPANSION).data()), EXPANSION)) return false;
92
93 // Decrypt (starting at block 1).
94 m_chacha20.Crypt(cipher.first(plain1.size()), plain1);
95 m_chacha20.Crypt(cipher.subspan(plain1.size()).first(plain2.size()), plain2);
96 return true;
97}
98
99void AEADChaCha20Poly1305::Keystream(Nonce96 nonce, std::span<std::byte> keystream) noexcept
100{

Callers

nothing calls this directly

Calls 7

ComputeTagFunction · 0.85
timingsafe_bcmp_internalFunction · 0.85
UCharCastFunction · 0.85
CryptMethod · 0.80
sizeMethod · 0.45
SeekMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected