@@ -67,26 +67,6 @@ static void TestHMACSHA512(const std::string &hexkey, const std::string &hexin,
67
67
TestVector (CHMAC_SHA512 (key.data (), key.size ()), ParseHex (hexin), ParseHex (hexout));
68
68
}
69
69
70
- static void TestAES128 (const std::string &hexkey, const std::string &hexin, const std::string &hexout)
71
- {
72
- std::vector<unsigned char > key = ParseHex (hexkey);
73
- std::vector<unsigned char > in = ParseHex (hexin);
74
- std::vector<unsigned char > correctout = ParseHex (hexout);
75
- std::vector<unsigned char > buf, buf2;
76
-
77
- assert (key.size () == 16 );
78
- assert (in.size () == 16 );
79
- assert (correctout.size () == 16 );
80
- AES128Encrypt enc (key.data ());
81
- buf.resize (correctout.size ());
82
- buf2.resize (correctout.size ());
83
- enc.Encrypt (buf.data (), in.data ());
84
- BOOST_CHECK_EQUAL (HexStr (buf), HexStr (correctout));
85
- AES128Decrypt dec (key.data ());
86
- dec.Decrypt (buf2.data (), buf.data ());
87
- BOOST_CHECK_EQUAL (HexStr (buf2), HexStr (in));
88
- }
89
-
90
70
static void TestAES256 (const std::string &hexkey, const std::string &hexin, const std::string &hexout)
91
71
{
92
72
std::vector<unsigned char > key = ParseHex (hexkey);
@@ -106,47 +86,6 @@ static void TestAES256(const std::string &hexkey, const std::string &hexin, cons
106
86
BOOST_CHECK (buf == in);
107
87
}
108
88
109
- static void TestAES128CBC (const std::string &hexkey, const std::string &hexiv, bool pad, const std::string &hexin, const std::string &hexout)
110
- {
111
- std::vector<unsigned char > key = ParseHex (hexkey);
112
- std::vector<unsigned char > iv = ParseHex (hexiv);
113
- std::vector<unsigned char > in = ParseHex (hexin);
114
- std::vector<unsigned char > correctout = ParseHex (hexout);
115
- std::vector<unsigned char > realout (in.size () + AES_BLOCKSIZE);
116
-
117
- // Encrypt the plaintext and verify that it equals the cipher
118
- AES128CBCEncrypt enc (key.data (), iv.data (), pad);
119
- int size = enc.Encrypt (in.data (), in.size (), realout.data ());
120
- realout.resize (size);
121
- BOOST_CHECK (realout.size () == correctout.size ());
122
- BOOST_CHECK_MESSAGE (realout == correctout, HexStr (realout) + std::string (" != " ) + hexout);
123
-
124
- // Decrypt the cipher and verify that it equals the plaintext
125
- std::vector<unsigned char > decrypted (correctout.size ());
126
- AES128CBCDecrypt dec (key.data (), iv.data (), pad);
127
- size = dec.Decrypt (correctout.data (), correctout.size (), decrypted.data ());
128
- decrypted.resize (size);
129
- BOOST_CHECK (decrypted.size () == in.size ());
130
- BOOST_CHECK_MESSAGE (decrypted == in, HexStr (decrypted) + std::string (" != " ) + hexin);
131
-
132
- // Encrypt and re-decrypt substrings of the plaintext and verify that they equal each-other
133
- for (std::vector<unsigned char >::iterator i (in.begin ()); i != in.end (); ++i)
134
- {
135
- std::vector<unsigned char > sub (i, in.end ());
136
- std::vector<unsigned char > subout (sub.size () + AES_BLOCKSIZE);
137
- int _size = enc.Encrypt (sub.data (), sub.size (), subout.data ());
138
- if (_size != 0 )
139
- {
140
- subout.resize (_size);
141
- std::vector<unsigned char > subdecrypted (subout.size ());
142
- _size = dec.Decrypt (subout.data (), subout.size (), subdecrypted.data ());
143
- subdecrypted.resize (_size);
144
- BOOST_CHECK (decrypted.size () == in.size ());
145
- BOOST_CHECK_MESSAGE (subdecrypted == sub, HexStr (subdecrypted) + std::string (" != " ) + HexStr (sub));
146
- }
147
- }
148
- }
149
-
150
89
static void TestAES256CBC (const std::string &hexkey, const std::string &hexiv, bool pad, const std::string &hexin, const std::string &hexout)
151
90
{
152
91
std::vector<unsigned char > key = ParseHex (hexkey);
@@ -440,42 +379,16 @@ BOOST_AUTO_TEST_CASE(hmac_sha512_testvectors) {
440
379
441
380
BOOST_AUTO_TEST_CASE (aes_testvectors) {
442
381
// AES test vectors from FIPS 197.
443
- TestAES128 (" 000102030405060708090a0b0c0d0e0f" , " 00112233445566778899aabbccddeeff" , " 69c4e0d86a7b0430d8cdb78070b4c55a" );
444
382
TestAES256 (" 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" , " 00112233445566778899aabbccddeeff" , " 8ea2b7ca516745bfeafc49904b496089" );
445
383
446
384
// AES-ECB test vectors from NIST sp800-38a.
447
- TestAES128 (" 2b7e151628aed2a6abf7158809cf4f3c" , " 6bc1bee22e409f96e93d7e117393172a" , " 3ad77bb40d7a3660a89ecaf32466ef97" );
448
- TestAES128 (" 2b7e151628aed2a6abf7158809cf4f3c" , " ae2d8a571e03ac9c9eb76fac45af8e51" , " f5d3d58503b9699de785895a96fdbaaf" );
449
- TestAES128 (" 2b7e151628aed2a6abf7158809cf4f3c" , " 30c81c46a35ce411e5fbc1191a0a52ef" , " 43b1cd7f598ece23881b00e3ed030688" );
450
- TestAES128 (" 2b7e151628aed2a6abf7158809cf4f3c" , " f69f2445df4f9b17ad2b417be66c3710" , " 7b0c785e27e8ad3f8223207104725dd4" );
451
385
TestAES256 (" 603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4" , " 6bc1bee22e409f96e93d7e117393172a" , " f3eed1bdb5d2a03c064b5a7e3db181f8" );
452
386
TestAES256 (" 603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4" , " ae2d8a571e03ac9c9eb76fac45af8e51" , " 591ccb10d410ed26dc5ba74a31362870" );
453
387
TestAES256 (" 603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4" , " 30c81c46a35ce411e5fbc1191a0a52ef" , " b6ed21b99ca6f4f9f153e7b1beafed1d" );
454
388
TestAES256 (" 603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4" , " f69f2445df4f9b17ad2b417be66c3710" , " 23304b7a39f9f3ff067d8d8f9e24ecc7" );
455
389
}
456
390
457
391
BOOST_AUTO_TEST_CASE (aes_cbc_testvectors) {
458
-
459
- // NIST AES CBC 128-bit encryption test-vectors
460
- TestAES128CBC (" 2b7e151628aed2a6abf7158809cf4f3c" , " 000102030405060708090A0B0C0D0E0F" , false , \
461
- " 6bc1bee22e409f96e93d7e117393172a" , " 7649abac8119b246cee98e9b12e9197d" );
462
- TestAES128CBC (" 2b7e151628aed2a6abf7158809cf4f3c" , " 7649ABAC8119B246CEE98E9B12E9197D" , false , \
463
- " ae2d8a571e03ac9c9eb76fac45af8e51" , " 5086cb9b507219ee95db113a917678b2" );
464
- TestAES128CBC (" 2b7e151628aed2a6abf7158809cf4f3c" , " 5086cb9b507219ee95db113a917678b2" , false , \
465
- " 30c81c46a35ce411e5fbc1191a0a52ef" , " 73bed6b8e3c1743b7116e69e22229516" );
466
- TestAES128CBC (" 2b7e151628aed2a6abf7158809cf4f3c" , " 73bed6b8e3c1743b7116e69e22229516" , false , \
467
- " f69f2445df4f9b17ad2b417be66c3710" , " 3ff1caa1681fac09120eca307586e1a7" );
468
-
469
- // The same vectors with padding enabled
470
- TestAES128CBC (" 2b7e151628aed2a6abf7158809cf4f3c" , " 000102030405060708090A0B0C0D0E0F" , true , \
471
- " 6bc1bee22e409f96e93d7e117393172a" , " 7649abac8119b246cee98e9b12e9197d8964e0b149c10b7b682e6e39aaeb731c" );
472
- TestAES128CBC (" 2b7e151628aed2a6abf7158809cf4f3c" , " 7649ABAC8119B246CEE98E9B12E9197D" , true , \
473
- " ae2d8a571e03ac9c9eb76fac45af8e51" , " 5086cb9b507219ee95db113a917678b255e21d7100b988ffec32feeafaf23538" );
474
- TestAES128CBC (" 2b7e151628aed2a6abf7158809cf4f3c" , " 5086cb9b507219ee95db113a917678b2" , true , \
475
- " 30c81c46a35ce411e5fbc1191a0a52ef" , " 73bed6b8e3c1743b7116e69e22229516f6eccda327bf8e5ec43718b0039adceb" );
476
- TestAES128CBC (" 2b7e151628aed2a6abf7158809cf4f3c" , " 73bed6b8e3c1743b7116e69e22229516" , true , \
477
- " f69f2445df4f9b17ad2b417be66c3710" , " 3ff1caa1681fac09120eca307586e1a78cb82807230e1321d3fae00d18cc2012" );
478
-
479
392
// NIST AES CBC 256-bit encryption test-vectors
480
393
TestAES256CBC (" 603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4" , \
481
394
" 000102030405060708090A0B0C0D0E0F" , false , " 6bc1bee22e409f96e93d7e117393172a" , \
0 commit comments