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/crypto_tests.cpp | |
parent | 50269b391fa18556bad72dc8c2fb4e2493a6a054 (diff) | |
download | bitcoin-40e6c5b9fce92ffe64e91c2aba38bb2ed57bfbfb.tar.xz |
crypto: add Poly1305 class with std::byte Span interface
Diffstat (limited to 'src/test/crypto_tests.cpp')
-rw-r--r-- | src/test/crypto_tests.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/test/crypto_tests.cpp b/src/test/crypto_tests.cpp index b29df832b4..85494e1b20 100644 --- a/src/test/crypto_tests.cpp +++ b/src/test/crypto_tests.cpp @@ -191,6 +191,22 @@ static void TestPoly1305(const std::string &hexmessage, const std::string &hexke tagres.resize(POLY1305_TAGLEN); poly1305_auth(tagres.data(), m.data(), m.size(), key.data()); BOOST_CHECK(tag == tagres); + + // Test incremental interface + for (int splits = 0; splits < 10; ++splits) { + for (int iter = 0; iter < 10; ++iter) { + auto data = MakeByteSpan(m); + Poly1305 poly1305{MakeByteSpan(key)}; + for (int chunk = 0; chunk < splits; ++chunk) { + size_t now = InsecureRandRange(data.size() + 1); + poly1305.Update(data.first(now)); + data = data.subspan(now); + } + tagres.assign(POLY1305_TAGLEN, 0); + poly1305.Update(data).Finalize(MakeWritableByteSpan(tagres)); + BOOST_CHECK(tag == tagres); + } + } } static void TestHKDF_SHA256_32(const std::string &ikm_hex, const std::string &salt_hex, const std::string &info_hex, const std::string &okm_check_hex) { |