| 81 | } |
| 82 | |
| 83 | bool 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 | |
| 99 | void AEADChaCha20Poly1305::Keystream(Nonce96 nonce, std::span<std::byte> keystream) noexcept |
| 100 | { |
nothing calls this directly
no test coverage detected