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