diff options
author | Pieter Wuille <pieter@wuille.net> | 2023-07-10 14:32:17 -0400 |
---|---|---|
committer | Pieter Wuille <pieter@wuille.net> | 2023-07-12 22:40:55 -0400 |
commit | 40e6c5b9fce92ffe64e91c2aba38bb2ed57bfbfb (patch) | |
tree | 1a55dbdccfa81563518e70c72bc2080d198744c5 /src/test/fuzz/crypto_poly1305.cpp | |
parent | 50269b391fa18556bad72dc8c2fb4e2493a6a054 (diff) |
crypto: add Poly1305 class with std::byte Span interface
Diffstat (limited to 'src/test/fuzz/crypto_poly1305.cpp')
-rw-r--r-- | src/test/fuzz/crypto_poly1305.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/fuzz/crypto_poly1305.cpp b/src/test/fuzz/crypto_poly1305.cpp index ac555ed68c..94a7ed06e9 100644 --- a/src/test/fuzz/crypto_poly1305.cpp +++ b/src/test/fuzz/crypto_poly1305.cpp @@ -20,3 +20,34 @@ FUZZ_TARGET(crypto_poly1305) std::vector<uint8_t> tag_out(POLY1305_TAGLEN); poly1305_auth(tag_out.data(), in.data(), in.size(), key.data()); } + + +FUZZ_TARGET(crypto_poly1305_split) +{ + FuzzedDataProvider provider{buffer.data(), buffer.size()}; + + // Read key and instantiate two Poly1305 objects with it. + auto key = provider.ConsumeBytes<std::byte>(Poly1305::KEYLEN); + key.resize(Poly1305::KEYLEN); + Poly1305 poly_full{key}, poly_split{key}; + + // Vector that holds all bytes processed so far. + std::vector<std::byte> total_input; + + // Process input in pieces. + LIMITED_WHILE(provider.remaining_bytes(), 100) { + auto in = provider.ConsumeRandomLengthString(); + poly_split.Update(MakeByteSpan(in)); + // Update total_input to match what was processed. + total_input.insert(total_input.end(), MakeByteSpan(in).begin(), MakeByteSpan(in).end()); + } + + // Process entire input at once. + poly_full.Update(total_input); + + // Verify both agree. + std::array<std::byte, Poly1305::TAGLEN> tag_split, tag_full; + poly_split.Finalize(tag_split); + poly_full.Finalize(tag_full); + assert(tag_full == tag_split); +} |