mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 19:23:26 -03:00
tests: miscellaneous hex / std::byte improvements
This commit is contained in:
parent
bdcbc8594c
commit
da0ec62e34
1 changed files with 5 additions and 6 deletions
|
@ -226,10 +226,9 @@ static void TestPoly1305(const std::string &hexmessage, const std::string &hexke
|
||||||
{
|
{
|
||||||
auto key = ParseHex<std::byte>(hexkey);
|
auto key = ParseHex<std::byte>(hexkey);
|
||||||
auto m = ParseHex<std::byte>(hexmessage);
|
auto m = ParseHex<std::byte>(hexmessage);
|
||||||
auto tag = ParseHex<std::byte>(hextag);
|
|
||||||
std::vector<std::byte> tagres(Poly1305::TAGLEN);
|
std::vector<std::byte> tagres(Poly1305::TAGLEN);
|
||||||
Poly1305{key}.Update(m).Finalize(tagres);
|
Poly1305{key}.Update(m).Finalize(tagres);
|
||||||
BOOST_CHECK(tag == tagres);
|
BOOST_CHECK_EQUAL(HexStr(tagres), hextag);
|
||||||
|
|
||||||
// Test incremental interface
|
// Test incremental interface
|
||||||
for (int splits = 0; splits < 10; ++splits) {
|
for (int splits = 0; splits < 10; ++splits) {
|
||||||
|
@ -243,7 +242,7 @@ static void TestPoly1305(const std::string &hexmessage, const std::string &hexke
|
||||||
}
|
}
|
||||||
tagres.assign(Poly1305::TAGLEN, std::byte{});
|
tagres.assign(Poly1305::TAGLEN, std::byte{});
|
||||||
poly1305.Update(data).Finalize(tagres);
|
poly1305.Update(data).Finalize(tagres);
|
||||||
BOOST_CHECK(tag == tagres);
|
BOOST_CHECK_EQUAL(HexStr(tagres), hextag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -922,15 +921,15 @@ BOOST_AUTO_TEST_CASE(poly1305_testvector)
|
||||||
auto total_key = ParseHex<std::byte>("01020304050607fffefdfcfbfaf9ffffffffffffffffffffffffffff00000000");
|
auto total_key = ParseHex<std::byte>("01020304050607fffefdfcfbfaf9ffffffffffffffffffffffffffff00000000");
|
||||||
Poly1305 total_ctx(total_key);
|
Poly1305 total_ctx(total_key);
|
||||||
for (unsigned i = 0; i < 256; ++i) {
|
for (unsigned i = 0; i < 256; ++i) {
|
||||||
std::vector<std::byte> key(32, std::byte{(uint8_t)i});
|
std::vector<std::byte> key(32, std::byte{uint8_t(i)});
|
||||||
std::vector<std::byte> msg(i, std::byte{(uint8_t)i});
|
std::vector<std::byte> msg(i, std::byte{uint8_t(i)});
|
||||||
std::array<std::byte, Poly1305::TAGLEN> tag;
|
std::array<std::byte, Poly1305::TAGLEN> tag;
|
||||||
Poly1305{key}.Update(msg).Finalize(tag);
|
Poly1305{key}.Update(msg).Finalize(tag);
|
||||||
total_ctx.Update(tag);
|
total_ctx.Update(tag);
|
||||||
}
|
}
|
||||||
std::vector<std::byte> total_tag(Poly1305::TAGLEN);
|
std::vector<std::byte> total_tag(Poly1305::TAGLEN);
|
||||||
total_ctx.Finalize(total_tag);
|
total_ctx.Finalize(total_tag);
|
||||||
BOOST_CHECK(total_tag == ParseHex<std::byte>("64afe2e8d6ad7bbdd287f97c44623d39"));
|
BOOST_CHECK_EQUAL(HexStr(total_tag), "64afe2e8d6ad7bbdd287f97c44623d39");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests with sparse messages and random keys.
|
// Tests with sparse messages and random keys.
|
||||||
|
|
Loading…
Add table
Reference in a new issue