@@ -851,7 +851,7 @@ BOOST_AUTO_TEST_CASE(hkdf_hmac_sha256_l32_tests)
851
851
" 8da4e775a563c18f715f802a063c5a31b8a11f5c5ee1879ec3454e5f3c738d2d" );
852
852
}
853
853
854
- static void TestBIP324CipherSuite (const std::string& hex_contents, const std::string& hex_key_L, const std::string& hex_key_P, const std::string& hex_expected_output_seq_0, const std::string& hex_expected_output_seq_999)
854
+ static void TestBIP324CipherSuite (const std::string& hex_aad, const std::string& hex_contents, const std::string& hex_key_L, const std::string& hex_key_P, const std::string& hex_expected_output_seq_0, const std::string& hex_expected_output_seq_999)
855
855
{
856
856
auto key_L_vec = ParseHex (hex_key_L);
857
857
BIP324Key key_L;
@@ -861,6 +861,8 @@ static void TestBIP324CipherSuite(const std::string& hex_contents, const std::st
861
861
BIP324Key key_P;
862
862
memcpy (key_P.data (), key_P_vec.data (), BIP324_KEY_LEN);
863
863
864
+ auto aad = ParseHex (hex_aad);
865
+
864
866
const auto original_contents_bytes = ParseHex (hex_contents);
865
867
auto contents_buf = original_contents_bytes;
866
868
@@ -877,7 +879,7 @@ static void TestBIP324CipherSuite(const std::string& hex_contents, const std::st
877
879
// encrypt / decrypt the packet 1000 times
878
880
for (size_t i = 0 ; i < 1000 ; ++i) {
879
881
// encrypt
880
- auto res = suite_enc.Crypt (MakeByteSpan (contents_buf), MakeWritableByteSpan (encrypted_pkt), flags, true );
882
+ auto res = suite_enc.Crypt (MakeByteSpan (aad), MakeByteSpan ( contents_buf), MakeWritableByteSpan (encrypted_pkt), flags, true );
881
883
BOOST_CHECK (res);
882
884
// verify ciphertext & mac against the test vector
883
885
if (i == 0 ) {
@@ -890,7 +892,7 @@ static void TestBIP324CipherSuite(const std::string& hex_contents, const std::st
890
892
out_len = suite_dec.DecryptLength (encrypted_pkt_len);
891
893
BOOST_CHECK_EQUAL (out_len, contents_buf.size ());
892
894
893
- res = suite_dec.Crypt ({reinterpret_cast <std::byte*>(encrypted_pkt.data ()) + BIP324_LENGTH_FIELD_LEN, encrypted_pkt.size () - BIP324_LENGTH_FIELD_LEN}, MakeWritableByteSpan (contents_buf_dec), flags, false );
895
+ res = suite_dec.Crypt (MakeByteSpan (aad), {reinterpret_cast <std::byte*>(encrypted_pkt.data ()) + BIP324_LENGTH_FIELD_LEN, encrypted_pkt.size () - BIP324_LENGTH_FIELD_LEN}, MakeWritableByteSpan (contents_buf_dec), flags, false );
894
896
BOOST_CHECK (res);
895
897
BOOST_CHECK_EQUAL (flags, BIP324_NONE);
896
898
@@ -908,29 +910,41 @@ BOOST_AUTO_TEST_CASE(bip324_cipher_suite_testvectors)
908
910
909
911
// encrypting an empty message should result in 20 bytes:
910
912
// 3 bytes of encrypted length, 1 byte header and 16 bytes MAC
911
- TestBIP324CipherSuite (/* plaintext */ " " ,
913
+ TestBIP324CipherSuite (/* aad */ " " ,
914
+ /* plaintext */ " " ,
912
915
/* k_l */ " 0000000000000000000000000000000000000000000000000000000000000000" ,
913
916
/* k_p */ " 0000000000000000000000000000000000000000000000000000000000000000" ,
914
917
/* ciphertext_and_mac_0 */ " 76b8e09fbedcfd1809ff3c10adf8277fcc0581b8" ,
915
918
/* ciphertext_and_mac_999 */ " 5dd1ef229ae773099415b4ae56d003d21b4e4a08" );
916
919
917
- TestBIP324CipherSuite (" 0000000000000000000000000000000000000000000000000000000000000000" ,
920
+ TestBIP324CipherSuite (" " ,
921
+ " 0000000000000000000000000000000000000000000000000000000000000000" ,
918
922
" 0000000000000000000000000000000000000000000000000000000000000000" ,
919
923
" 0000000000000000000000000000000000000000000000000000000000000000" ,
920
924
" 56b8e09f07e7be5551387a98ba977c732d080dcb0f29a048e3656912c6533e32ee7aed29e7e38bb44c94b6a43c525ffca66c79e9" ,
921
925
" 7dd1ef2205b549ef8e0dc60b16342f037e415cfcd3d6111532f8f9e7553e422129d9df0d58e083ad538381c1e30a51a5d296cce2" );
922
926
923
- TestBIP324CipherSuite (" 0100000000000000000000000000000000000000000000000000000000000000" ,
927
+ TestBIP324CipherSuite (" " ,
928
+ " 0100000000000000000000000000000000000000000000000000000000000000" ,
924
929
" 0000000000000000000000000000000000000000000000000000000000000000" ,
925
930
" 0000000000000000000000000000000000000000000000000000000000000000" ,
926
931
" 56b8e09f06e7be5551387a98ba977c732d080dcb0f29a048e3656912c6533e32ee7aed2929449b86c1e4e213676824f2c48e5336" ,
927
932
" 7dd1ef2204b549ef8e0dc60b16342f037e415cfcd3d6111532f8f9e7553e422129d9df0d04fc5b2ab5cb70895a90edddbe642c00" );
928
933
929
- TestBIP324CipherSuite (" fc0000f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b733b46413042c9440049176905d3be59ea1c53f15916155c2be8241a38008b9a26bc35941e2444177c8ade6689de95264986d95889fb60e84629c9bd9a5acb1cc118be563eb9b3a4a472f82e09a7e778492b562ef7130e88dfe031c79db9d4f7c7a899151b9a475032b63fc385245fe054e3dd5a97a5f576fe064025d3ce042c566ab2c507b138db853e3d6959660996546cc9c4a6eafdc777c040d70eaf46f76dad3979e5c5360c3317166a1c894c94a371876a94df7628fe4eaaf2ccb27d5aaae0ad7ad0f9d4b6ad3b54098746d4524d38407a6deb3ab78fab78c9" ,
934
+ TestBIP324CipherSuite (" " ,
935
+ " fc0000f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b733b46413042c9440049176905d3be59ea1c53f15916155c2be8241a38008b9a26bc35941e2444177c8ade6689de95264986d95889fb60e84629c9bd9a5acb1cc118be563eb9b3a4a472f82e09a7e778492b562ef7130e88dfe031c79db9d4f7c7a899151b9a475032b63fc385245fe054e3dd5a97a5f576fe064025d3ce042c566ab2c507b138db853e3d6959660996546cc9c4a6eafdc777c040d70eaf46f76dad3979e5c5360c3317166a1c894c94a371876a94df7628fe4eaaf2ccb27d5aaae0ad7ad0f9d4b6ad3b54098746d4524d38407a6deb3ab78fab78c9" ,
930
936
" ff0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" ,
931
937
" 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" ,
932
938
" 3940c1184442315c7340b89171039acb48f95287e66e56f7afa7cf00f95044d26fb69d46ac5c16a2d57a1cadc39160644717559e73480734410a3f543c5f231a7d7ed77af2a64681f6a7417283cef85504ac5de9fdea100e6c67ef7a1bfcd888a92a5f1ef2c9074b44b572aa748f29ff61a850ce40470004dff5cc1d926c5abe25ace47a12c5373094a26bab027e008154fb630aa062490b5421e96691a3f79557f7a79e3cfd9100796671ea241703ddf326f113adf1694bbd6e0ca032e16f936e7bfbf174e7ef4af5b53a6a9102e6fa41a8e589290f39a7bc7a6003088c612a43a36c2e9f2e740797ad3a2a1a80e0f67157fb9abc40487077368e94751a266a0b2dac24f0adabd5c6d7ba54316eee951da560" ,
933
939
" 2db339c8500d35db91994138b4ab5e698086b4ec7fb66e75d083b18f84a9da7d696be75c349cb1555a58f65f123d4b68e2be2277fd7b38ba26ad93040a22ac8f7782b00d75c7650dcff0442f7ef91980aaabecb2c8cefec5d5eb9d495b5e1768fe316ec2a0d69d46b7289cd2e2049f27d30a6183605651d48ac40e0d06af9ec7012d477e473f2af7842335c36acf4f5bdef45605ca243b9007b5363f095850a78945508cf3fa191b8fe7fc5359d6e00741e6504f1d50904152622f4c0bdeaa0745f00d28b995543621c96d9d9d30fa1fbf403b19a716411b1700e8401a3e1e01bb1546653fbda19d83ba5e561695baea229880ff33058f85754fe9fdc09db4491f47ae64ec030ec6163d2838d9474d40ef0579" );
940
+
941
+ // Repeat test with non-empty aad - only mac tags (last 16 bytes) in the expected outputs change
942
+ TestBIP324CipherSuite (" c6d7bc3a5079ae98fec7094bdfb42aac61d3ba64af179d672c7c33fd4a139647" ,
943
+ " fc0000f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b733b46413042c9440049176905d3be59ea1c53f15916155c2be8241a38008b9a26bc35941e2444177c8ade6689de95264986d95889fb60e84629c9bd9a5acb1cc118be563eb9b3a4a472f82e09a7e778492b562ef7130e88dfe031c79db9d4f7c7a899151b9a475032b63fc385245fe054e3dd5a97a5f576fe064025d3ce042c566ab2c507b138db853e3d6959660996546cc9c4a6eafdc777c040d70eaf46f76dad3979e5c5360c3317166a1c894c94a371876a94df7628fe4eaaf2ccb27d5aaae0ad7ad0f9d4b6ad3b54098746d4524d38407a6deb3ab78fab78c9" ,
944
+ " ff0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" ,
945
+ " 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" ,
946
+ " 3940c1184442315c7340b89171039acb48f95287e66e56f7afa7cf00f95044d26fb69d46ac5c16a2d57a1cadc39160644717559e73480734410a3f543c5f231a7d7ed77af2a64681f6a7417283cef85504ac5de9fdea100e6c67ef7a1bfcd888a92a5f1ef2c9074b44b572aa748f29ff61a850ce40470004dff5cc1d926c5abe25ace47a12c5373094a26bab027e008154fb630aa062490b5421e96691a3f79557f7a79e3cfd9100796671ea241703ddf326f113adf1694bbd6e0ca032e16f936e7bfbf174e7ef4af5b53a6a9102e6fa41a8e589290f39a7bc7a6003088c612a43a36c2e9f2e740797ad3a2a1a80e0f67157fb9abc40487077368e94751a266a0b2dac4d382097b958da569f3b6fae3faaaaf2" ,
947
+ " 2db339c8500d35db91994138b4ab5e698086b4ec7fb66e75d083b18f84a9da7d696be75c349cb1555a58f65f123d4b68e2be2277fd7b38ba26ad93040a22ac8f7782b00d75c7650dcff0442f7ef91980aaabecb2c8cefec5d5eb9d495b5e1768fe316ec2a0d69d46b7289cd2e2049f27d30a6183605651d48ac40e0d06af9ec7012d477e473f2af7842335c36acf4f5bdef45605ca243b9007b5363f095850a78945508cf3fa191b8fe7fc5359d6e00741e6504f1d50904152622f4c0bdeaa0745f00d28b995543621c96d9d9d30fa1fbf403b19a716411b1700e8401a3e1e01bb1546653fbda19d83ba5e561695baea229880ff33058f85754fe9fdc09db4491f47ae0623cf23941a59b7c7dc6cad9bd97cc1" );
934
948
}
935
949
936
950
BOOST_AUTO_TEST_CASE (countbits_tests)
0 commit comments