| 228 | } |
| 229 | |
| 230 | void 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 | |
| 255 | void 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 | { |