|
4 | 4 |
|
5 | 5 | #include <crypto/aes.h>
|
6 | 6 | #include <crypto/chacha20.h>
|
| 7 | +#include <crypto/poly1305.h> |
7 | 8 | #include <crypto/ripemd160.h>
|
8 | 9 | #include <crypto/sha1.h>
|
9 | 10 | #include <crypto/sha256.h>
|
@@ -200,6 +201,17 @@ static void TestChaCha20(const std::string &hexkey, uint64_t nonce, uint64_t see
|
200 | 201 | BOOST_CHECK(out == outres);
|
201 | 202 | }
|
202 | 203 |
|
| 204 | +static void TestPoly1305(const std::string &hexmessage, const std::string &hexkey, const std::string& hextag) |
| 205 | +{ |
| 206 | + std::vector<unsigned char> key = ParseHex(hexkey); |
| 207 | + std::vector<unsigned char> m = ParseHex(hexmessage); |
| 208 | + std::vector<unsigned char> tag = ParseHex(hextag); |
| 209 | + std::vector<unsigned char> tagres; |
| 210 | + tagres.resize(POLY1305_TAGLEN); |
| 211 | + poly1305_auth(tagres.data(), m.data(), m.size(), key.data()); |
| 212 | + BOOST_CHECK(tag == tagres); |
| 213 | +} |
| 214 | + |
203 | 215 | static std::string LongTestString() {
|
204 | 216 | std::string ret;
|
205 | 217 | for (int i=0; i<200000; i++) {
|
@@ -524,6 +536,76 @@ BOOST_AUTO_TEST_CASE(chacha20_testvector)
|
524 | 536 | "fab78c9");
|
525 | 537 | }
|
526 | 538 |
|
| 539 | +BOOST_AUTO_TEST_CASE(poly1305_testvector) |
| 540 | +{ |
| 541 | + // RFC 7539, section 2.5.2. |
| 542 | + TestPoly1305("43727970746f6772617068696320466f72756d2052657365617263682047726f7570", |
| 543 | + "85d6be7857556d337f4452fe42d506a80103808afb0db2fd4abff6af4149f51b", |
| 544 | + "a8061dc1305136c6c22b8baf0c0127a9"); |
| 545 | + |
| 546 | + // RFC 7539, section A.3. |
| 547 | + TestPoly1305("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" |
| 548 | + "000000000000000000000000000", |
| 549 | + "0000000000000000000000000000000000000000000000000000000000000000", |
| 550 | + "00000000000000000000000000000000"); |
| 551 | + |
| 552 | + TestPoly1305("416e79207375626d697373696f6e20746f20746865204945544620696e74656e6465642062792074686520436f6e747269627" |
| 553 | + "5746f7220666f72207075626c69636174696f6e20617320616c6c206f722070617274206f6620616e204945544620496e7465" |
| 554 | + "726e65742d4472616674206f722052464320616e6420616e792073746174656d656e74206d6164652077697468696e2074686" |
| 555 | + "520636f6e74657874206f6620616e204945544620616374697669747920697320636f6e7369646572656420616e2022494554" |
| 556 | + "4620436f6e747269627574696f6e222e20537563682073746174656d656e747320696e636c756465206f72616c20737461746" |
| 557 | + "56d656e747320696e20494554462073657373696f6e732c2061732077656c6c206173207772697474656e20616e6420656c65" |
| 558 | + "6374726f6e696320636f6d6d756e69636174696f6e73206d61646520617420616e792074696d65206f7220706c6163652c207" |
| 559 | + "768696368206172652061646472657373656420746f", |
| 560 | + "0000000000000000000000000000000036e5f6b5c5e06070f0efca96227a863e", |
| 561 | + "36e5f6b5c5e06070f0efca96227a863e"); |
| 562 | + |
| 563 | + TestPoly1305("416e79207375626d697373696f6e20746f20746865204945544620696e74656e6465642062792074686520436f6e747269627" |
| 564 | + "5746f7220666f72207075626c69636174696f6e20617320616c6c206f722070617274206f6620616e204945544620496e7465" |
| 565 | + "726e65742d4472616674206f722052464320616e6420616e792073746174656d656e74206d6164652077697468696e2074686" |
| 566 | + "520636f6e74657874206f6620616e204945544620616374697669747920697320636f6e7369646572656420616e2022494554" |
| 567 | + "4620436f6e747269627574696f6e222e20537563682073746174656d656e747320696e636c756465206f72616c20737461746" |
| 568 | + "56d656e747320696e20494554462073657373696f6e732c2061732077656c6c206173207772697474656e20616e6420656c65" |
| 569 | + "6374726f6e696320636f6d6d756e69636174696f6e73206d61646520617420616e792074696d65206f7220706c6163652c207" |
| 570 | + "768696368206172652061646472657373656420746f", |
| 571 | + "36e5f6b5c5e06070f0efca96227a863e00000000000000000000000000000000", |
| 572 | + "f3477e7cd95417af89a6b8794c310cf0"); |
| 573 | + |
| 574 | + TestPoly1305("2754776173206272696c6c69672c20616e642074686520736c6974687920746f7665730a446964206779726520616e6420676" |
| 575 | + "96d626c6520696e2074686520776162653a0a416c6c206d696d737920776572652074686520626f726f676f7665732c0a416e" |
| 576 | + "6420746865206d6f6d65207261746873206f757467726162652e", |
| 577 | + "1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0", |
| 578 | + "4541669a7eaaee61e708dc7cbcc5eb62"); |
| 579 | + |
| 580 | + TestPoly1305("ffffffffffffffffffffffffffffffff", |
| 581 | + "0200000000000000000000000000000000000000000000000000000000000000", |
| 582 | + "03000000000000000000000000000000"); |
| 583 | + |
| 584 | + TestPoly1305("02000000000000000000000000000000", |
| 585 | + "02000000000000000000000000000000ffffffffffffffffffffffffffffffff", |
| 586 | + "03000000000000000000000000000000"); |
| 587 | + |
| 588 | + TestPoly1305("fffffffffffffffffffffffffffffffff0ffffffffffffffffffffffffffffff11000000000000000000000000000000", |
| 589 | + "0100000000000000000000000000000000000000000000000000000000000000", |
| 590 | + "05000000000000000000000000000000"); |
| 591 | + |
| 592 | + TestPoly1305("fffffffffffffffffffffffffffffffffbfefefefefefefefefefefefefefefe01010101010101010101010101010101", |
| 593 | + "0100000000000000000000000000000000000000000000000000000000000000", |
| 594 | + "00000000000000000000000000000000"); |
| 595 | + |
| 596 | + TestPoly1305("fdffffffffffffffffffffffffffffff", |
| 597 | + "0200000000000000000000000000000000000000000000000000000000000000", |
| 598 | + "faffffffffffffffffffffffffffffff"); |
| 599 | + |
| 600 | + TestPoly1305("e33594d7505e43b900000000000000003394d7505e4379cd01000000000000000000000000000000000000000000000001000000000000000000000000000000", |
| 601 | + "0100000000000000040000000000000000000000000000000000000000000000", |
| 602 | + "14000000000000005500000000000000"); |
| 603 | + |
| 604 | + TestPoly1305("e33594d7505e43b900000000000000003394d7505e4379cd010000000000000000000000000000000000000000000000", |
| 605 | + "0100000000000000040000000000000000000000000000000000000000000000", |
| 606 | + "13000000000000000000000000000000"); |
| 607 | +} |
| 608 | + |
527 | 609 | BOOST_AUTO_TEST_CASE(countbits_tests)
|
528 | 610 | {
|
529 | 611 | FastRandomContext ctx;
|
|
0 commit comments