diff --git a/src/Makefile.test.include b/src/Makefile.test.include index d22d687b78..33f2a59d93 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -16,6 +16,7 @@ FUZZ_BINARY=test/fuzz/fuzz$(EXEEXT) JSON_TEST_FILES = \ test/data/script_tests.json \ + test/data/bip324_vectors.json \ test/data/bip341_wallet_vectors.json \ test/data/base58_encode_decode.json \ test/data/blockfilters.json \ diff --git a/src/test/data/bip324_vectors.json b/src/test/data/bip324_vectors.json new file mode 100644 index 0000000000..e3ad4c1aa3 --- /dev/null +++ b/src/test/data/bip324_vectors.json @@ -0,0 +1,170 @@ +[ + { + "in_idx": 1, + "in_priv_ours": "e79f04ad4c684525ff3e3cf7c19f4cdb11193d387d7f3fe82a948a0c3165f5fe", + "in_ellswift_ours": "4eff53ea1945e57b5d170565e760d771e5d496101c1005c302fd687af80d8b858c5a681c474fc4c0546ee464a1b95899ecb9d4f50c2c0854fe029fc054ae6777", + "in_ellswift_theirs": "824a1da0530fa695b95b375fee2a56ec96ce375ddd2fcf8367cc8ec1c0b751a3304bbef5dc96543acaac50c24be8cb39906ef8521727de0c6e96c2060a026bd7", + "in_initiating": 1, + "in_contents": "1f", + "in_multiply": 1, + "in_aad": "", + "in_ignore": 0, + "mid_x_ours": "b63341693587b4944b865485cffcc34707b3e0760a6ba8d1d402fc1c996c4e91", + "mid_x_shared": "961fa6c9491bde887a6e67898c9335579d1931b435af16d969f3c9f12e58c698", + "mid_shared_secret": "05ac09c882b2cddd57fd4a1a14f93ae78d78a2ab2adb8cb6d67176cdb3101e15", + "mid_initiator_l": "c845747c92a2f0d83058ccceee69322cfd84cf3b086c30790f2a8789b303defc", + "mid_initiator_p": "3d0c55fa080de10236da830c7b092f63f6897c5243259adcedc4288a847ee9bc", + "mid_responder_l": "f32949925481a88ad5246c408aeb8b9c0dc5dbc21fd6e5484331e1c0cd0ef6d6", + "mid_responder_p": "5b94f3fce2b276e9d7ef5646657e61dbbc8ea27a9bf531ce23c553de1fdfd27d", + "mid_rekey_salt": "0e8a665616c8828d9cb702d4ed1178b7e3958704909abd", + "mid_send_garbage_terminator": "38d7b65a6d58a08b2506e799caacd4f6", + "mid_recv_garbage_terminator": "d6156094782d98fa27f37758dcd0677f", + "mid_session_id": "4418cf03c0d7cd5849022a7976014f234b4d4f5c18a6d3a6540c11e01a7180c1", + "out_ciphertext": "d88ea86cdd6b61592e038741b474eeef0de0802412", + "out_ciphertext_endswith": "" + }, + { + "in_idx": 999, + "in_priv_ours": "53a915e6d8f6c5bbb93e537081085e9e642dc525649acf05be74e3a825e20921", + "in_ellswift_ours": "715d7b8357dd4d15a07b3f8c6764ebd9927140f75047fb50478c33ea8889d710511cdf39aa0fd6b1e94ea660d87f9d97bffc548646f9e2aaebc1468fe563fb97", + "in_ellswift_theirs": "cea7abc3112397b894bd3e89a615248af473f897bbdd30997c20e53e7ce499a295e55c4c5655cd3d21191e76c8af0aa1bbea10fd1b540a42d0fbed388dc59877", + "in_initiating": 0, + "in_contents": "e4", + "in_multiply": 1, + "in_aad": "", + "in_ignore": 0, + "mid_x_ours": "533bbaefc711f303be5e8271fdecfd31d03abd42128ff73479e2a427059e4a74", + "mid_x_shared": "ed679745127d32714ff84bcce7651a14b9f275bf4b18bc8e880ff51cd7ac012b", + "mid_shared_secret": "08cbe6a86ff92a9757b2aeea92b8b2f4d78426786a2caec99c3cc73d7dda47ab", + "mid_initiator_l": "953a372f0d3933afef342fec533fa4fed644cc1cbc9252d31883e10fbca9b81a", + "mid_initiator_p": "e8c1759d865d59f37e5cf0404296fb0530f0fc601ad783853791e5459ca7f135", + "mid_responder_l": "52925c95091e7dac8e580e9a0548e18915e01919a416c5aac22096b8bab17c31", + "mid_responder_p": "ba778684047d705839590c466daef7c0ac53a3f8790b9744f154712e5644c647", + "mid_rekey_salt": "b0d15cd56a8cd5dddad169093a5eef58083bebf28e3921", + "mid_send_garbage_terminator": "0442c66254045c5018d828d42afaa69f", + "mid_recv_garbage_terminator": "930c6d7cbf8c7c2006ed287c2ba6d941", + "mid_session_id": "9619dd4731d6160617da82da407c80732455a67b59ad7be07f86252aadb79440", + "out_ciphertext": "543ab974d50bf7a122cc118b546830f54e18f838b4", + "out_ciphertext_endswith": "" + }, + { + "in_idx": 0, + "in_priv_ours": "dcf45714d450a32cdd05997b75acd34e8786969dfcff34295c287a13ba3225f0", + "in_ellswift_ours": "feaa1ef8bb05296a8d5153855357868835fc5bc59d96dcbccb108e0e2dd671676c5683ad566ee4290ede5236ba6259ab47668e25853d64c0678641d27d5d0eed", + "in_ellswift_theirs": "c8067851ccc5df7331e9f137e66ebce1220306c4644266ff3e38436a1036ea36582dac8ce2c30de59a890f81611f866f659c1334bdd82cce1ea20ab0128b7f56", + "in_initiating": 1, + "in_contents": "d3ed40688778a439928b38f1f67e04afb94843625ce1932590fe0606fcabffad25df7d2476214dc1d06aa368a4dc1e6d940a974307836e291c54f6948623ce", + "in_multiply": 1, + "in_aad": "3c208efa88a545dbd29d71bbf41268fe3d123eac7e20e92be7f227b93166ee3cfd2f26639b27f20513ec5fe25c4e762096b3e49c29110a5b0d170eb9292e1ecdd3d3bab3660f9970811330d6a0f7112709666bb9d3443c9f35a84e7bde9bf2b5e29b903c64e86aca86bb5799fcf6a7416f48d98668749852c49e4cb2f3325c44d63995cea48af98bb42bcf4fbe03681bb552cf5d51b424bd53f1ffb6d6cb70af606debbe07124aeb14b28f2b26e63f3421c6ac512d5cdb7f97540f2ae64487d84dc57fb8c97f5785b60bcf12a22225988007c4dcc8895301a6e36c59f3a33ab5fa099945b1dd4d6e0a3822ffea087b01f9fb27b38c7711211c523b0e153422a5e06c8200ed45560ed4eb1317b7b730b5d31096bd3ac5cfc1e876a178851d297bec38b7a753013d7590533b5f6d654add3b38ca046d932d9739a5f0fbe6cda89cc97597a046d08b66fde7533fcb0528562960832f623dadbbe35d2d54ff15e1a9a260477169e2d8a95ec66e6ed8ccc2366f5ded2fddc2b351d6475c4b3831b6dd5c330917ea1b0b229ce719b5bd6d839861e5374f51a176b500e7546a2b4b1325be9615305d591605783279a73f28b9a281b17a45bb79029a30bf3c0b248945f4523979bbb57d69df4881d8030a4146080dbf13255b712919fb4fa016c66dd323d7a5c56b3ceeb57c4120fd554719a3851b9f3e810c4ad35b141ebff6b7c7038fdfa784681f20dcf99773721d4ec07e58a312d638fa7a90c1afbb282f30ea74d7002288441c93263eebb593f2b36cf795a8a0ee7cc119d28caa13332fdb6f2f5a6011e26e1f33941fa275d2d75af014c7739b9a999f018c7c96b854332225cb9104c016f94ff255191ab93df7c1ac29e566d672e8ccb1a4b1f53f201d583da6c410df98fc502f3b366d7624cd812cb9dedce92329b6e591366bb83c7b84c1fb30301f0199ee9ec727a33d3a9a0382af1fcf1f42e945a5acf1ea8db30a03856b8d4e0361c08028bcfc05c5204fd508e67b9924600526a1f297efd091e3a0bdc6de5a46229792069c08af9b7961ec890a3ecd6af6b08ae08f3892084a8224dd5ac50b99a7034ba48b6f599ab3e3f9fe30734229558694b8e3091161f8bd425cc2e63635c1ff82e6b6b6c89d3ea4a0dc4193b80e6014f87571bc8499107576a910f0aa50d471fb35fa07dfd0488a404ef9907ee767b1f3786415561c445e0487feed348da527bd5e8adad8de928159fb32cfac4430f51dcf710507baedf326597d8039cbecd07e9cde781d0e307d589d52b5ac262a69b366541efc78e9398dc69345f00004268c9c6ae079f09aa4e4afb830ae35715623451ee2520ef201cb5885030aec9a24d9968f8c6f25d234c69cb2f569ae2a91029b6401110fed798b2289de1e7e8621dcbe466a2fef44f09176e252dae6707ecc35695a156f6b97ab4cbaabd325fd8eb941248490824f2520f49aae6eaab95a1cf92c061c57c90910873f1866b8763b78f90b2b737020527ad16c33938ab438f0eb7845a034aec20253e71ab717c4243dbcc084f4b09a87ceeb8ef124755ac8802a66b02cf9396a700a661e16b418cf838ea1262935bb7bdeec1648f0cacb1c3236ec1856d93f172c5a9a938246606db326336425c27e2adfa428f347b9f7aa4cf1648dd4e7e66f5e8a858d499c95dc2092a0a9c8b80a05c93bd359ba5b1acc714be5a1c26be118abe8abafce45d0b9bb668a8204fccf166bb85ce17f70330c0c8ca8dc7394beee22a52624558b69b81e223c779447ee09d822dc44226432a0c86f9b25e7d85a98e187d879a4ddeeb2463d12bce3eb137e227d41e2a3df55dad1219cf18129dd23ad50930286b732037cbe7d474d06ae9f7d93f7285d2db44a8e72011460e3d34381bfe6d3221f49915312d00a5a2c7ef98ab829c995081abf9dc5551f472f34f9b39607b8e55bdb047e68582d27d2582afb9a07549c7a134a34f7d0e5a1a046cb2c3959feb98fe7a698291a2defa5fbb32473b9c9ed02d02284559325e12cda1bf0bc24ea9849fc4c87eaed71f2537242b8635fdc969872b1017d218943647fca47f9430af3b78ae2c39882118612c288d474b0298de3c3ec1efd23c65554f6d6813b4ccbf604250d295f795b679fe0ecceef5b4739eb6b418376d2fd47f95685a259cd2e2e7c00c18e93329a80a467a2a0aeb22e361732c943beb0c3dc7ca57699b690d26e6314d0b28082f8f26894c249d1587b8895dd1c5e8863bbe31cdebbce06b1d6aa17f64a125f4cbad47f2e02761259973ea164b22a580d74413d900023f03d2b2587bca60501f639050262b61a67bec83246d6ec7726f5a8a62d99c582a159db6a539ae88732f8d101d324550c9fa2dd9ba60c449d329cba823ec4b3d80d613d8df5256b3ce6ffec42ab23e5e27c001aec29d080fb519a6cce5b974f65375870c22577a2f6e76760870de047ff65dca90bfd6a303b4605b6f90631d57a8f66969ec7b96749c1f1a4ee70e8915396e114100fde651700416239d82ce7e32be5f20e5886510a37b3cd3eefe78c40ccb0425f03bcaab1aa9eeffa2f4681b7938a813f49f10a34c280de09345ffe00af340a451ebdae630ddade51a6510fdda44c3fcacfaf3f2f748d8bfe48ff71871eaec9b1790df27d4ae913d1ad16b0b33a04266540a49cb5acb8d2e16df7a35933bba7c5af1ac1f522419e76c58cddee219cf5d3229d5a27af4411ae890b4329ae5699820766b0d73841baddc11c24802684c7f7c738bf4843595dd508850b69dbd38671a385ea39188a04e7b489daabf860f4747a7172cb72a578b9903ce161e7b8a7f31ea7e8630f97571bae93f51186b94cf3c697839a6dcb2f53de9893e53a7bc2f94c9a33b2dd112cdae81f60019b7c20aa7c4921f72492329afb8841a4c80a42d1a12fcc09cf7094cadf6a48ffd6f200bd64ec17906cf4ceda6f10313bdc9ce23eba2d8d8bdba728fac90321b4893a0a61e443f611ce16486aa477ed59ccd27b58bf01a5d6d396ffa249c0728eaf87f1c41dd56c7cbc1491b369aec1a576e286fceb37746891aa37da87fa77db443bbc2df63c589f928532c6e8f4e6e3186441dca4c7118d1bfdd0a1e24087837d7dabff8d64f7df1d4cd1628eb312d6c631f092ac0172642de2f2c3c1a71573de41d2165b8f3164db59070593d8c16dd6c161303a6523a33da328fd88929e434da4d102c0ef7303eafeb6a0c3583f74bc277ae1fac36efe68b98af3340a766b0ddb61e268f3dfdc6d858a90aab491e00e010ef195bbe12435a6f225395a1c3d0ba05a094cb2c6610353fb5bdda198c6c6a1564ddf21ab51b2e13e735969d109acf4ff05ac0071d018e98b42b18692ff2dff6bb1fdc6aa630d2a978b652fa6944fbf693a251db943e10cdabfd7e26276ef16844024432286400d36d15c6acf43cb6247c6316b0729ad2a465ed215a97c937e9f9a405ae9f520d91a198cd18077e7d6134f268741b73c6ad16d1e2164102e8bd276237599ff5811837faa0b1b4ac6b61092c14da64ee83904d62c57d336b80f4476f5a9fa6f0ce6ba6b34454906bf5af60b5e42170bc358bb90927c20f753b8d69d80e5aff23daee4727bdf16e01cb549783816b9a066ade19c26bf2e30aad9f3faf35c5e17c81062f53fdb9f57c2608f6c638f0f2e8c071581107bba371eb0cfec67bd823c3d892d21d14e65b366343839bddb2b7da0d7af7e7b3b927c4d71441ecbf14f5276d0da11cf33723a10fbf1e5a97b1f95072de9872932d7bfc200080043cec2dbf2f0840be85933d8f0cb6862316d1dc18292b90b8a583df01464fe1d6a4720ea361ff2280398df7008023f364989692c86bd2ceb94e466febe2fae6bb2635c1cfcdde45c4d3b6ff55106a432a64e6827f52cc0a25f4581a058c962e99ee9b3ca2c10e32eb93729690b3066d9b9343be9863faaa0599b99daddb2e53704002cc3dc09d5df8f3bb783b37e3ef85f01b272d84073576352428720ee08b9bc527020413346c0bb7f7040fd9b149197bdc4988eebc4e012e73d75bc4f4d2d2a3cc30dae96836c590e5a5976f0392102e1c592da1fd373be252fc3b0d34a6dec22725dd697ac55d4d50e07ccba88f70a44b75abb5dfececacb1b5483760e5d40b84255455fdb93faecbc24ae3b30d73311d6afd5fbad5b6e61e64530e7645cc43adc3053a40d6fc0e63d6c664df163f197d2d3efbb5a5abcf4a7ad69d07bb866876fc22d9c7a2fe529260153283cdbe1fc5768d625ad09a9bdb60442a744d22a827264d2722baae4549097f745bcf0de7f21c80951cc5ed8a48e4099663dbf6ac1f995e7ab3d6c8fe2c3e817e13b26741f2a7f33bad56bb002ebf0c69282dc763e1e9cb44bc0a0814170116d2dc16fdf1e08158fc571c5a5285242ab6376f9c213953e3a0a315eff722831cc27e426b0fe299fb325933ba9631be00ffd51f7bb3d13d962f5b6a0a01ad0c60455993699b9ec594cb749c82c870dc443c7466db518e4a5ebc7c530539ae48bea63d77c0e175d673edff001511bbdbddf30f2c231cba0565f043aa52c584fc05069728a95e040893d4e9c6c8d3b7bae906be38b9e1480f8e4665f157f4b347be01d1c355c94576b32a335864f6cd341857a696fe5f8af10a4ae87246cd119d33205bb969009655e36db394f750382fd58648aee80179bb3f1df7f291b4de27edf056c3968aca546e0e81d131b3fb52ae8b3fdedf297289420c4aa1aa74560aae150f623e120b08592c0304dbf7ff2e432e737227ac1e7e9e65485b30d058b30f81807a18fba48822baaf2e7ec6c88a604495a000e62340273db9079c2a7123a8a197b63d9616e7e9ebef572ba3efec09fb038a57adceffeffcbbb6c4e0e9bd73c1d1e82d26d39bda2420a45fb2463218b2988b5fbd316b3f4e81e7b0728d700637333fe5448b395e384169c4bfc57ff6062c962ac4f13e66cd5b6166a7a049b6459291d2d2a632d749060d8070b9e2db3159db8047e8024bc12c92562c7b4ee953b426c551d1b9064551833c758683693a57e724bed8a5c05e55d8e5f27d22b4adc246116747f23cc8ec35b51148168cd27dfb8a466cb8f4b1980209735694e411184875da7254a2ff850a73377c1f9f0b87f808b76a9f0882231fcc4446ed01c9876edf92fc505040583d9ccd0fcaf3935f215dd45022a9464835a505022cdd54de634fe207b5e202f7bcad463e00312952d3d4b421cc77be0cac587426f0239b8d3d94c0c24141b10cc8ab33aa655388fa5a323016e7a1fe2470d4dad92cb19acf779ce1c48f64bf588c99a766010252b983edcd4725ff16c15683bd7be62323c39405358358fcff306182a3a147c025dc91801258f4d71e1888b0a19f4e52a8c5885cc99474e94448c0081d1ce2a7110e1a6c7e23184cd76a44c806b0f1ea3de321cfdf8569dd35221e9ab1ccbcf6dee81cc611d0731226228d71e98abf05a0db761bf6807d4c0400a39835f33b144f85ddcdee7945e63027d3cd25d44b7e9fdda2548284497af9b57dc72b3e026d49e86950b434fc9a9713f5be858500b54614d5d4c79186289d744fa0df3d655f9fb79ec60f49dc72eea538515b53f74c578f9d4ffc9e79063e19f3a38d9dde42f7c3910ac5ca16f60afefcccd4a49b1d93032b7e82189caebd2993991f7f4f1610d3b7cd4b8dbf895523b28d0a3e672232412145649b1a28570d9c114a851f10e6761f52ade202167d94fb69135f3d2932849a85267b998a23f6c6229697e0098097cb6a6dc4f84cff4c7da997d5631b694", + "in_ignore": 0, + "mid_x_ours": "d23f19ad26c7ab984c682c5b1475f5a7df0452a05dd29a164974d2027a6e488a", + "mid_x_shared": "6f8420ebf786ee13dcf65855b11428db43061cb599e6fe9ed79e59d9f273dc44", + "mid_shared_secret": "33a1ef8464def100bf031dae882ae4b7837b481f6adbc63c44baa8ef61c102eb", + "mid_initiator_l": "8edefd89c5ddb77db6333981740b83fd4d9c246639e0dcfd1ea2a26d4a26f508", + "mid_initiator_p": "6b0aae6192e7a92c7a3b5de8ab1349d26637b17e500da162cf25df13c85d35df", + "mid_responder_l": "87a8da66207605720c64d5267b5ce90becb01248a60808a921c5eff59013d59f", + "mid_responder_p": "e9292dc44be3294db04cf689a3141bbe0d0dbaca2dd8d8fb606a45b8d7d8e089", + "mid_rekey_salt": "b6194760814976e42e00d7cb8e52634b32ec48c6493c18", + "mid_send_garbage_terminator": "57b8c1343aea943714ff848970b2a89b", + "mid_recv_garbage_terminator": "ce7988ab7ce5c93b89328ff815ae803b", + "mid_session_id": "a306c86bea9e6befa7f72bd5cde761d5f4f86cfbc8749c1e844100c540a6cefc", + "out_ciphertext": "a844ddeb465f302c4b408a6ab972d4ff4035109bc25fb8fe88d4892bccefc238cf93e5a61459f9c0cb4877cb03967d592c5d8dc6d4c4b5f489005a645b2f7a2ee368749f0b172b9ddbcaa76f20485a272b2347", + "out_ciphertext_endswith": "" + }, + { + "in_idx": 255, + "in_priv_ours": "f360308206fb441c7713b1a24ba4096a2fa0d5401411198b7008f82ae85257fe", + "in_ellswift_ours": "3d4aa6a71a8a734e014b4d9e6b62989f022c1e2238ae476b11465cb86fe8cf7243db6f9472e188590705cf9b35121e06e57cb106a6043ab147b7c73871da8222", + "in_ellswift_theirs": "f0ebc3c872339622fbf2ab1b8aa2117c4d752b64eac9203962c03a47497a89c0dd298348e5bb63d3433c48ed6da6bc2e2dbe78f7b91247dd29f1f51a858d464a", + "in_initiating": 0, + "in_contents": "b766200432932708a77dd15337bf70ca58397907a1cd31ecd1b43fab27fa0de0e85d5c4dea99543e79a75b149d325044934efccf679a764f683b2fbcb7c6dc4baea9797554779aff937f5195c172892c38dc423bc809885e5a19d07733e7c5f5806ffb865074cf2c46fbb5be4f9b5833c6829b8217ccb301dad7cb49e4fbcad1", + "in_multiply": 1, + "in_aad": "", + "in_ignore": 1, + "mid_x_ours": "29bf8fe2cbd12835d3e6652840b8b1a2acf99d7b44610e738aafd7fd207c9b25", + "mid_x_shared": "8f088a98122e3ffae5fee255fbfdf653a1f830f85dfe595707a1f4a7f74dab76", + "mid_shared_secret": "07eff272cd331aeb14db342b82f6df98303b01471f4dbe71028b127577216d9b", + "mid_initiator_l": "74ee2a5f9221cb386e587ac9a0c724bc6f65ea04cf3b0686c10b3e39e66bca02", + "mid_initiator_p": "35d93b912c54f3d28f834ee96a787f76f84b543fc231a45242fa4953b89cfc9f", + "mid_responder_l": "70c4abb811bb6c209c6f108be383f67c8a14cd2dd25815f6156e6c3edd7d1e3d", + "mid_responder_p": "3a16c6f3ff6f2b735b89d2af77c94b9dd328f5330e1283627835d32c5c856446", + "mid_rekey_salt": "77db9b59b22f86b1687c45fc5d7582bcab7d3d373a9ec7", + "mid_send_garbage_terminator": "e09f7df050a3f76bc8d5a21697fefb9b", + "mid_recv_garbage_terminator": "b8951fd528743d2e8625de363d9ae0e7", + "mid_session_id": "b1d1e3ae7d9337f31a410986fe6e377726eb0f2334f24d66b38ec4d29529d1a5", + "out_ciphertext": "8a4af8b26e56cb461e021551a73f5a8179c0b28181ed1d18fa911358462c4667e51225d18cf4a1d8d73601982d03422065ee781ada48eb4c72ab31dc3a4ab451f8bf2e82b4ab3c4ea3f946b3bb351e3ae9723e35192c59c3a66477ecc9bff100b180a49ce21aed6f0b7c99ae57de2827de5389c93f549f6d9fbb2fa0e62a3a2cd1309b9f05fbb3b8c3fa5a383166b3ae57079432", + "out_ciphertext_endswith": "" + }, + { + "in_idx": 512, + "in_priv_ours": "073f53403256e2b699e32cd4cebadfab63d9076a7cd541d9656e27b1baff66bb", + "in_ellswift_ours": "5c9c90c4e216f8a4c2642535d1f699364f9054ca01bca0239fa65bcaf0ec0278e5a36bc85eae96850feff889b66c9106c170fe655f973f533ee3557bd3cb6e64", + "in_ellswift_theirs": "e9221c9698cb69b63c5a4e224132389d346fd2f0f3262218301be51687b8de846c652ea8aa7425a5c08a7bd52078168d28ecf42196e33e155e215553ce6aee83", + "in_initiating": 1, + "in_contents": "196391ebfe9af3a9186d82692a00e485d6653c8408050e2efbfd864642860022af68053ee4230f69ea565fee775778bc231307b5b534545878f864364bb2690acc9e8991fed5a777eb2850c3c54cca94a5bc2cb92729bcd4e27c57ebddbdf14974030115bc5a8a600b207a4884f568d6a9d3d9367977410577674601d1cc5f1f672f4e54d4944e1f7807416159eb5ece5b805c8a23e6735351a8cf8de654d87228ba21baf815190ef026b29612498121fe85480d9e0050d4781fa9f0e60cab5195", + "in_multiply": 1, + "in_aad": "", + "in_ignore": 0, + "mid_x_ours": "0ce4860107efd6deb9e8fc71cfc2522b4a5a0dc171746fb995ce485570449ab5", + "mid_x_shared": "d87966cc3cbdcc14ce06a1ef6c28125cec3136647a499d4b4465c925a5f85efd", + "mid_shared_secret": "88cf0eb49ee4b7b46cd39fb3f4126b285750d897fdcba72b08d9da351167e227", + "mid_initiator_l": "df6857d7fbb822069d3f284973cdc6677a539d81844247ca2ac174b818623550", + "mid_initiator_p": "4f1c0b4b834681298ef127067369747074e571c68fc69966f3ad20673f786b82", + "mid_responder_l": "5b9aa4239daed582b04d316f0550fdf1efc5309544349b01d62ea4f045e3425f", + "mid_responder_p": "0c1d30189bf24a5032a93add5335fcbf351b2071870fd1626b66e23be99e1df5", + "mid_rekey_salt": "02a476dddbdee8e475639f3c668c156c5c72a807c324e2", + "mid_send_garbage_terminator": "ece7e13c65def883efc1f0dac6d55974", + "mid_recv_garbage_terminator": "efca4cefee7a95602ebab090875e4212", + "mid_session_id": "afde967955012c17bfa7bea218bff3aa1aef10a49139c66080e9e7c567706409", + "out_ciphertext": "7d674fcca8ff3a3146bda19d2404e2411b8d724ca775c365b0956819264c95553526befed63ab5d6cbcbe81c15a6fddd09eb11e410846477635f47f1d78e842ad4b5e14f9ce40ddaaac3cba343dc9422b671d3beb084df04d2814a6ee387bb07c48ed5f06e76114430c9557b9dba9832353c15560587485dd61800d19af1c3593b2d1dff044ac2b72363d595f755b9fdfc5f00fed12ec4a87b1555c06fa8038c6dd3acc748584b2af591ff6789af43d31cb434b6e1396ff49d8d029194b7ae6167d397158551c0768b31a1e12b3c01bb97f9470ad1", + "out_ciphertext_endswith": "" + }, + { + "in_idx": 769, + "in_priv_ours": "810159fc6708a85aa9d6c8e7c4f8c587056594910174c0309b2c323055efaa6a", + "in_ellswift_ours": "2a875927b98fd441d8c469f6902c167eb440e52d3331a4b7406f21cad216e80917401ddb8795a9706fe42a7ddfca70fee7240b1e918b9f32414b8b26e611d571", + "in_ellswift_theirs": "758bcf0381c0a1c35a174503a43b08f79eb407aa61eb9e6579a62400d4a13f8d3cef884728c34cb79c7f088b4d4e735ce796361e71bd8b66d637f56326b49af3", + "in_initiating": 0, + "in_contents": "0f492bc40bc635ca20a46c6fd97b7de536f8326e677e0dcf9ed91e4c7873ec903198010f7cf0ff1595", + "in_multiply": 97561, + "in_aad": "", + "in_ignore": 0, + "mid_x_ours": "27cdbeb6c8ef5f97982a7af00018a16ba243176fe6bb5d5c30c8a466a0193a47", + "mid_x_shared": "85bbb016a00056ffd3878b2a5cfac4352d581bfec5a0407f0733585513d4b463", + "mid_shared_secret": "17624a0ed455d13430bf27337e27a1d55402cb1c7ebb32a4a66b3ef2f9947f1d", + "mid_initiator_l": "aeb3befd6841f8ec867e154424b5c6d49ad3fc1f789e7d3048750302c5d89c09", + "mid_initiator_p": "80033fb9014f1a407e46d35cf36a7c4245e55e6a810abaaad88ec5d25f89443f", + "mid_responder_l": "65b0f93ac2a34327a4aacf14c2c54d92210294b425c3b6bb4ced8c44dad80457", + "mid_responder_p": "4893a9b0ec706fcc7a05c1fed011ced86afd7324c63537e49ec2974df481a83c", + "mid_rekey_salt": "de7a5be308f7a21f80df8a0258d2e191f5a06486ce7e2c", + "mid_send_garbage_terminator": "330b7aae0e4d13f5806bc1f696042155", + "mid_recv_garbage_terminator": "d514d7861e65ced36c7ea6ad2a8f6938", + "mid_session_id": "2ad4f52fd2a9cd078c0664dc4ba33904095d4affb5227fbc779662ca6140376c", + "out_ciphertext": "", + "out_ciphertext_endswith": "09afb85b3677a099e44afe8147c515804558fa128fc772cd125b3089b124977f79e7d11e1a1a03095979d4bddf40adbda5a837e84e82916bfb504fe605dd25531be008701b314c030c04ba3ee808ac68b837c3e7035b0d4847a2d448b218f91cce1fff03b35935a4661088e6ea5d5cded7ca21d3c0f75796debc593f1730b698b901044b3989e1ea425668ef2fdcfe0af4942d24f893857b693b53599039e3c814e797d7b2aed37806510aaa6dc9dda44aee0fa0d814b9459111a73503538230a905f016650169d4c9ca531bbd58eb2ae5c40c9a11aefd7d117d690706855d5ce30ff74865de26112096a88d445397e2e2bf02fd149663d92ff764156f09709e" + }, + { + "in_idx": 1024, + "in_priv_ours": "f7c11ca3b55137fa6124c49b25dea0287815b887760e1b986497e976444eb5bb", + "in_ellswift_ours": "5a2a0ce42feb17e70a96db1e55bc380e26a40a589dfc453d6c2e82bbc4c2b161716a05df9039ccffb6df45183480119deb69299e44d48e38de746ad084156edd", + "in_ellswift_theirs": "2c402d53332d914e4f5501c8db682bec6738ed53c7410655d9346db99bae37642beb6a1d48394502941965ea7140e1172ce591923235640f964c0d597caae304", + "in_initiating": 1, + "in_contents": "bc5fdee9e87d05b9723871a35823f643cc53c400851686d69d87433028c19cc295ceea1513d8056021800c86d886f27f6018e4053121df4db5216bff17160f7b1bc4d3be67354f0551f55a353de5f15add353605e2a0761bb0c1b3bb8a37787e797e619ebf902a8ed4fcf1c741c897c8469cf54565b21c85e2b4fac5ef6e948f2c36df269f7189d1f293d2a95a08a1b9d00528521ff407ff992726712c8c9d6273a878d1700912ff2ef5b1b6899e9b88f6999bc628c8a390b37d9be99bd742e16a1eb83b0d1b8bfb6858e3fddb33ce2d9ef40afefd29833fd59dbc0aef25c35771b17d62595b5de9dc7426f1d976deea78", + "in_multiply": 69615, + "in_aad": "", + "in_ignore": 1, + "mid_x_ours": "6d89eb9e87319fd088ee1e77fa5b36d2d2d9e66fae8d11ab7bd70407d4aaba29", + "mid_x_shared": "0b6c87c76983e5c84428bd646d24c133d9321af5f7cb4624ca1524bcab828ffd", + "mid_shared_secret": "2a4d8d7ab2d2e92c429c8c4cb0d78f0f170a244410d588b92c7fd8baf7c27e59", + "mid_initiator_l": "001f5a1254d1734551f7895221f370aa5eb2ea382dfefd586941becac178d8a2", + "mid_initiator_p": "acf0ffecff0851e065af2a149f1c0a0db21c8a885613ebd1c445957b56c3d705", + "mid_responder_l": "42b3699eec52f5f4648bdb40c25c956944f0a3e9986552917a3498078a8de907", + "mid_responder_p": "a721aa5cf8d2b4ce9f46f20693438d94f75130585b6ab137894b273a436c90d4", + "mid_rekey_salt": "1512ee97517ecf95bf4a66689852ea011b8810891b4b0b", + "mid_send_garbage_terminator": "a5e8c7130b7b8cb34e303bc3da911230", + "mid_recv_garbage_terminator": "0169b4c927c5a809bd3b0981887e7e0b", + "mid_session_id": "462c77437e78cb8620e0572e5a401d151e6ae45aed57d7638d924f569eccd73e", + "out_ciphertext": "", + "out_ciphertext_endswith": "de5b3741446139c453cb8d88696018f02473c3b84a27fc10ed78f21860398a0de3abc9b3dccad4eacfb604034e541c201adcaba5ceffb98502cc7e98f6f6d896e3a4bd122102c43ab491923164c41c12e2ff7bd63f39255c671a87e49596ed06dcf58293febebe3ff3ada97826b0ad2258b46817275c2f95fbd4b0fa5e1cbca33e5f0e5a97a2e2493060eea6033cdb9c8002aaf17d73afc7fc968258acbb3b83cdf2272682fb4cbda84e8c3ca2cece5e24d0606761a3cd611de58976a1cd448e34b67d0a4dd19a1bcfe59e5c7c215747d9e8ef3504edbd1eaf0ca8c272247d6b9cc137d0299e48191a18f839018ac312928e76fe1b6c13f7175bd6266fb4febb" + } +] diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp index 81c131010a..140f64b664 100644 --- a/src/test/net_tests.cpp +++ b/src/test/net_tests.cpp @@ -2,6 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include + #include #include #include @@ -34,6 +36,8 @@ #include #include +#include + using namespace std::literals; BOOST_FIXTURE_TEST_SUITE(net_tests, RegTestingSetup) @@ -1054,4 +1058,130 @@ BOOST_AUTO_TEST_CASE(net_v2) message_serialize_deserialize_test(false, test_msgs); } +void assert_bip324_test_vector(uint16_t in_idx, + const std::string& in_priv_ours_hex, + const std::string& in_ellswift_ours_hex, + const std::string& in_ellswift_theirs_hex, + bool in_initiating, + const std::string& in_contents_hex, + uint32_t in_multiply, + const std::string& in_aad_hex, + bool in_ignore, + const std::string& mid_shared_secret_hex, + const std::string& mid_initiator_L_hex, + const std::string& mid_initiator_P_hex, + const std::string& mid_responder_L_hex, + const std::string& mid_responder_P_hex, + const std::string& mid_session_id_hex, + const std::string& mid_rekey_salt_hex, + const std::string& mid_send_garbage_terminator_hex, + const std::string& mid_recv_garbage_terminator_hex, + const std::string& out_ciphertext_hex, + const std::string& out_ciphertext_endswith_hex) +{ + auto parsed_hex = ParseHex(in_priv_ours_hex); + + CKey in_priv_ours; + in_priv_ours.Set(parsed_hex.begin(), parsed_hex.end(), false); + + EllSwiftPubKey in_ellswift_ours, in_ellswift_theirs; + + parsed_hex = ParseHex(in_ellswift_ours_hex); + memcpy(in_ellswift_ours.data(), parsed_hex.data(), parsed_hex.size()); + parsed_hex = ParseHex(in_ellswift_theirs_hex); + memcpy(in_ellswift_theirs.data(), parsed_hex.data(), parsed_hex.size()); + + std::vector in_contents; + auto contents_bytes = ParseHex(in_contents_hex); + for (size_t i = 0; i < in_multiply; i++) { + std::copy(contents_bytes.begin(), contents_bytes.end(), std::back_inserter(in_contents)); + } + + auto in_aad = ParseHex(in_aad_hex); + + BIP324HeaderFlags flags{BIP324_NONE}; + if (in_ignore) { + flags = BIP324_IGNORE; + } + + auto shared_secret = in_priv_ours.ComputeBIP324ECDHSecret(in_ellswift_theirs, + in_ellswift_ours, + in_initiating); + BOOST_CHECK_EQUAL(HexStr(shared_secret.value()), mid_shared_secret_hex); + + BIP324Session session; + DeriveBIP324Session(std::move(shared_secret.value()), session); + + BOOST_CHECK_EQUAL(HexStr(session.initiator_L), mid_initiator_L_hex); + BOOST_CHECK_EQUAL(HexStr(session.initiator_P), mid_initiator_P_hex); + BOOST_CHECK_EQUAL(HexStr(session.responder_L), mid_responder_L_hex); + BOOST_CHECK_EQUAL(HexStr(session.responder_P), mid_responder_P_hex); + BOOST_CHECK_EQUAL(HexStr(session.session_id), mid_session_id_hex); + BOOST_CHECK_EQUAL(HexStr(session.rekey_salt), mid_rekey_salt_hex); + + std::unique_ptr suite; + if (in_initiating) { + BOOST_CHECK_EQUAL(HexStr(session.initiator_garbage_terminator), mid_send_garbage_terminator_hex); + BOOST_CHECK_EQUAL(HexStr(session.responder_garbage_terminator), mid_recv_garbage_terminator_hex); + suite = std::make_unique(session.initiator_L, session.initiator_P, session.rekey_salt); + + } else { + BOOST_CHECK_EQUAL(HexStr(session.responder_garbage_terminator), mid_send_garbage_terminator_hex); + BOOST_CHECK_EQUAL(HexStr(session.initiator_garbage_terminator), mid_recv_garbage_terminator_hex); + suite = std::make_unique(session.responder_L, session.responder_P, session.rekey_salt); + } + + std::vector ciphertext(V2_MIN_PACKET_LENGTH + in_contents.size()); + std::array throwaway_ct; + + for (auto i = 0; i < in_idx; i++) { + BOOST_CHECK(suite->Crypt({}, {}, throwaway_ct, flags, true)); + } + + BOOST_CHECK(suite->Crypt(in_aad, in_contents, ciphertext, flags, true)); + if (!out_ciphertext_hex.empty()) { + BOOST_CHECK_EQUAL(HexStr(ciphertext), out_ciphertext_hex); + } + + if (!out_ciphertext_endswith_hex.empty()) { + auto ciphertext_endswith_hex = HexStr( + MakeUCharSpan(ciphertext).last(out_ciphertext_endswith_hex.size() / 2)); + BOOST_CHECK_EQUAL(ciphertext_endswith_hex, out_ciphertext_endswith_hex); + } +} + + +BOOST_AUTO_TEST_CASE(bip324_vectors_test) +{ + // BIP324 key derivation uses network magic in the HKDF derivation process. + SelectParams(CBaseChainParams::MAIN); + + UniValue tests; + tests.read((const char*)json_tests::bip324_vectors, sizeof(json_tests::bip324_vectors)); + for (const auto& vec : tests.getValues()) { + assert_bip324_test_vector( + vec["in_idx"].getInt(), + vec["in_priv_ours"].get_str(), + vec["in_ellswift_ours"].get_str(), + vec["in_ellswift_theirs"].get_str(), + vec["in_initiating"].getInt() == 0 ? false : true, + vec["in_contents"].get_str(), + vec["in_multiply"].getInt(), + vec["in_aad"].get_str(), + vec["in_ignore"].getInt() == 0 ? false : true, + vec["mid_shared_secret"].get_str(), + vec["mid_initiator_l"].get_str(), + vec["mid_initiator_p"].get_str(), + vec["mid_responder_l"].get_str(), + vec["mid_responder_p"].get_str(), + vec["mid_session_id"].get_str(), + vec["mid_rekey_salt"].get_str(), + vec["mid_send_garbage_terminator"].get_str(), + vec["mid_recv_garbage_terminator"].get_str(), + vec["out_ciphertext"].get_str(), + vec["out_ciphertext_endswith"].get_str()); + } + + SelectParams(CBaseChainParams::REGTEST); +} BOOST_AUTO_TEST_SUITE_END()