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

Method TestPoly1305

src/test/crypto_tests.cpp:230–253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

228}
229
230void TestPoly1305(const std::string &hexmessage, const std::string &hexkey, const std::string& hextag)
231{
232 auto key = ParseHex<std::byte>(hexkey);
233 auto m = ParseHex<std::byte>(hexmessage);
234 std::vector<std::byte> tagres(Poly1305::TAGLEN);
235 Poly1305{key}.Update(m).Finalize(tagres);
236 BOOST_CHECK_EQUAL(HexStr(tagres), hextag);
237
238 // Test incremental interface
239 for (int splits = 0; splits < 10; ++splits) {
240 for (int iter = 0; iter < 10; ++iter) {
241 auto data = std::span{m};
242 Poly1305 poly1305{key};
243 for (int chunk = 0; chunk < splits; ++chunk) {
244 size_t now = m_rng.randrange(data.size() + 1);
245 poly1305.Update(data.first(now));
246 data = data.subspan(now);
247 }
248 tagres.assign(Poly1305::TAGLEN, std::byte{});
249 poly1305.Update(data).Finalize(tagres);
250 BOOST_CHECK_EQUAL(HexStr(tagres), hextag);
251 }
252 }
253}
254
255void TestChaCha20Poly1305(const std::string& plain_hex, const std::string& aad_hex, const std::string& key_hex, ChaCha20::Nonce96 nonce, const std::string& cipher_hex)
256{

Callers

nothing calls this directly

Calls 6

UpdateMethod · 0.80
randrangeMethod · 0.80
HexStrFunction · 0.50
FinalizeMethod · 0.45
sizeMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected