aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test-aes.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2014-10-07 10:48:45 (GMT)
committerJouni Malinen <j@w1.fi>2014-10-07 11:57:06 (GMT)
commiteefec1e40b8721b37aff8187741c824c7913d0f0 (patch)
treebcd9527c290b80feb96101186eb3e3317bf07805 /tests/test-aes.c
parent98a1571d8890a43c9b5fe1cf21f3a1a0e3d02656 (diff)
downloadhostap-eefec1e40b8721b37aff8187741c824c7913d0f0.zip
hostap-eefec1e40b8721b37aff8187741c824c7913d0f0.tar.gz
hostap-eefec1e40b8721b37aff8187741c824c7913d0f0.tar.bz2
AES: Extend key wrap design to support longer AES keys
This adds kek_len argument to aes_wrap() and aes_unwrap() functions and allows AES to be initialized with 192 and 256 bit KEK in addition to the previously supported 128 bit KEK. The test vectors in test-aes.c are extended to cover all the test vectors from RFC 3394. Signed-off-by: Jouni Malinen <j@w1.fi>
Diffstat (limited to 'tests/test-aes.c')
-rw-r--r--tests/test-aes.c255
1 files changed, 238 insertions, 17 deletions
diff --git a/tests/test-aes.c b/tests/test-aes.c
index e7b5534..596e38b 100644
--- a/tests/test-aes.c
+++ b/tests/test-aes.c
@@ -500,46 +500,267 @@ static struct omac1_test_vector test_vectors[] =
};
-int main(int argc, char *argv[])
+static int test_key_wrap(void)
{
- u8 kek[] = {
+ unsigned int i;
+ int ret = 0;
+
+ /* RFC 3394 - Test vector 4.1 */
+ u8 kek41[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
- u8 plain[] = {
+ u8 plain41[] = {
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
};
- u8 crypt[] = {
+ u8 crypt41[] = {
0x1F, 0xA6, 0x8B, 0x0A, 0x81, 0x12, 0xB4, 0x47,
0xAE, 0xF3, 0x4B, 0xD8, 0xFB, 0x5A, 0x7B, 0x82,
0x9D, 0x3E, 0x86, 0x23, 0x71, 0xD2, 0xCF, 0xE5
};
- u8 result[24];
- int ret = 0;
- unsigned int i;
- struct omac1_test_vector *tv;
+ /* RFC 3394 - Test vector 4.2 */
+ u8 kek42[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
+ };
+ u8 plain42[] = {
+ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+ 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
+ };
+ u8 crypt42[] = {
+ 0x96, 0x77, 0x8B, 0x25, 0xAE, 0x6C, 0xA4, 0x35,
+ 0xF9, 0x2B, 0x5B, 0x97, 0xC0, 0x50, 0xAE, 0xD2,
+ 0x46, 0x8A, 0xB8, 0xA1, 0x7A, 0xD8, 0x4E, 0x5D
+ };
+ /* RFC 3394 - Test vector 4.3 */
+ u8 kek43[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
+ };
+ u8 plain43[] = {
+ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+ 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
+ };
+ u8 crypt43[] = {
+ 0x64, 0xE8, 0xC3, 0xF9, 0xCE, 0x0F, 0x5B, 0xA2,
+ 0x63, 0xE9, 0x77, 0x79, 0x05, 0x81, 0x8A, 0x2A,
+ 0x93, 0xC8, 0x19, 0x1E, 0x7D, 0x6E, 0x8A, 0xE7,
+ };
+ /* RFC 3394 - Test vector 4.4 */
+ u8 kek44[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
+ };
+ u8 plain44[] = {
+ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+ 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
+ };
+ u8 crypt44[] = {
+ 0x03, 0x1D, 0x33, 0x26, 0x4E, 0x15, 0xD3, 0x32,
+ 0x68, 0xF2, 0x4E, 0xC2, 0x60, 0x74, 0x3E, 0xDC,
+ 0xE1, 0xC6, 0xC7, 0xDD, 0xEE, 0x72, 0x5A, 0x93,
+ 0x6B, 0xA8, 0x14, 0x91, 0x5C, 0x67, 0x62, 0xD2
+ };
+ /* RFC 3394 - Test vector 4.5 */
+ u8 kek45[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
+ };
+ u8 plain45[] = {
+ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+ 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
+ };
+ u8 crypt45[] = {
+ 0xA8, 0xF9, 0xBC, 0x16, 0x12, 0xC6, 0x8B, 0x3F,
+ 0xF6, 0xE6, 0xF4, 0xFB, 0xE3, 0x0E, 0x71, 0xE4,
+ 0x76, 0x9C, 0x8B, 0x80, 0xA3, 0x2C, 0xB8, 0x95,
+ 0x8C, 0xD5, 0xD1, 0x7D, 0x6B, 0x25, 0x4D, 0xA1,
+ };
+ /* RFC 3394 - Test vector 4.6 */
+ u8 kek46[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
+ };
+ u8 plain46[] = {
+ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+ 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
+ };
+ u8 crypt46[] = {
+ 0x28, 0xC9, 0xF4, 0x04, 0xC4, 0xB8, 0x10, 0xF4,
+ 0xCB, 0xCC, 0xB3, 0x5C, 0xFB, 0x87, 0xF8, 0x26,
+ 0x3F, 0x57, 0x86, 0xE2, 0xD8, 0x0E, 0xD3, 0x26,
+ 0xCB, 0xC7, 0xF0, 0xE7, 0x1A, 0x99, 0xF4, 0x3B,
+ 0xFB, 0x98, 0x8B, 0x9B, 0x7A, 0x02, 0xDD, 0x21
+ };
+ u8 result[40];
+
+ printf("RFC 3394 - Test vector 4.1\n");
+ if (aes_wrap(kek41, sizeof(kek41), sizeof(plain41) / 8, plain41,
+ result)) {
+ printf("AES-WRAP-128 reported failure\n");
+ ret++;
+ }
+ if (memcmp(result, crypt41, sizeof(crypt41)) != 0) {
+ printf("AES-WRAP-128 failed\n");
+ ret++;
+ }
+ if (aes_unwrap(kek41, sizeof(kek41), sizeof(plain41) / 8, crypt41,
+ result)) {
+ printf("AES-UNWRAP-128 reported failure\n");
+ ret++;
+ }
+ if (memcmp(result, plain41, sizeof(plain41)) != 0) {
+ printf("AES-UNWRAP-128 failed\n");
+ ret++;
+ for (i = 0; i < sizeof(plain41); i++)
+ printf(" %02x", result[i]);
+ printf("\n");
+ }
- if (aes_wrap(kek, 2, plain, result)) {
- printf("AES-WRAP-128-128 reported failure\n");
+ printf("RFC 3394 - Test vector 4.2\n");
+ if (aes_wrap(kek42, sizeof(kek42), sizeof(plain42) / 8, plain42,
+ result)) {
+ printf("AES-WRAP-192 reported failure\n");
ret++;
}
- if (memcmp(result, crypt, 24) != 0) {
- printf("AES-WRAP-128-128 failed\n");
+ if (memcmp(result, crypt42, sizeof(crypt42)) != 0) {
+ printf("AES-WRAP-192 failed\n");
ret++;
}
- if (aes_unwrap(kek, 2, crypt, result)) {
- printf("AES-UNWRAP-128-128 reported failure\n");
+ if (aes_unwrap(kek42, sizeof(kek42), sizeof(plain42) / 8, crypt42,
+ result)) {
+ printf("AES-UNWRAP-192 reported failure\n");
ret++;
}
- if (memcmp(result, plain, 16) != 0) {
- printf("AES-UNWRAP-128-128 failed\n");
+ if (memcmp(result, plain42, sizeof(plain42)) != 0) {
+ printf("AES-UNWRAP-192 failed\n");
ret++;
- for (i = 0; i < 16; i++)
+ for (i = 0; i < sizeof(plain42); i++)
printf(" %02x", result[i]);
printf("\n");
}
+ printf("RFC 3394 - Test vector 4.3\n");
+ if (aes_wrap(kek43, sizeof(kek43), sizeof(plain43) / 8, plain43,
+ result)) {
+ printf("AES-WRAP-256 reported failure\n");
+ ret++;
+ }
+ if (memcmp(result, crypt43, sizeof(crypt43)) != 0) {
+ printf("AES-WRAP-256 failed\n");
+ ret++;
+ }
+ if (aes_unwrap(kek43, sizeof(kek43), sizeof(plain43) / 8, crypt43,
+ result)) {
+ printf("AES-UNWRAP-256 reported failure\n");
+ ret++;
+ }
+ if (memcmp(result, plain43, sizeof(plain43)) != 0) {
+ printf("AES-UNWRAP-256 failed\n");
+ ret++;
+ for (i = 0; i < sizeof(plain43); i++)
+ printf(" %02x", result[i]);
+ printf("\n");
+ }
+
+ printf("RFC 3394 - Test vector 4.4\n");
+ if (aes_wrap(kek44, sizeof(kek44), sizeof(plain44) / 8, plain44,
+ result)) {
+ printf("AES-WRAP-192 reported failure\n");
+ ret++;
+ }
+ if (memcmp(result, crypt44, sizeof(crypt44)) != 0) {
+ printf("AES-WRAP-192 failed\n");
+ ret++;
+ }
+ if (aes_unwrap(kek44, sizeof(kek44), sizeof(plain44) / 8, crypt44,
+ result)) {
+ printf("AES-UNWRAP-192 reported failure\n");
+ ret++;
+ }
+ if (memcmp(result, plain44, sizeof(plain44)) != 0) {
+ printf("AES-UNWRAP-192 failed\n");
+ ret++;
+ for (i = 0; i < sizeof(plain44); i++)
+ printf(" %02x", result[i]);
+ printf("\n");
+ }
+
+ printf("RFC 3394 - Test vector 4.5\n");
+ if (aes_wrap(kek45, sizeof(kek45), sizeof(plain45) / 8, plain45,
+ result)) {
+ printf("AES-WRAP-256 reported failure\n");
+ ret++;
+ }
+ if (memcmp(result, crypt45, sizeof(crypt45)) != 0) {
+ printf("AES-WRAP-256 failed\n");
+ ret++;
+ for (i = 0; i < sizeof(crypt45); i++)
+ printf(" %02x", result[i]);
+ printf("\n");
+ }
+ if (aes_unwrap(kek45, sizeof(kek45), sizeof(plain45) / 8, crypt45,
+ result)) {
+ printf("AES-UNWRAP-256 reported failure\n");
+ ret++;
+ }
+ if (memcmp(result, plain45, sizeof(plain45)) != 0) {
+ printf("AES-UNWRAP-256 failed\n");
+ ret++;
+ for (i = 0; i < sizeof(plain45); i++)
+ printf(" %02x", result[i]);
+ printf("\n");
+ }
+
+ printf("RFC 3394 - Test vector 4.6\n");
+ if (aes_wrap(kek46, sizeof(kek46), sizeof(plain46) / 8, plain46,
+ result)) {
+ printf("AES-WRAP-256 reported failure\n");
+ ret++;
+ }
+ if (memcmp(result, crypt46, sizeof(crypt46)) != 0) {
+ printf("AES-WRAP-256 failed\n");
+ ret++;
+ }
+ if (aes_unwrap(kek46, sizeof(kek46), sizeof(plain46) / 8, crypt46,
+ result)) {
+ printf("AES-UNWRAP-256 reported failure\n");
+ ret++;
+ }
+ if (memcmp(result, plain46, sizeof(plain46)) != 0) {
+ printf("AES-UNWRAP-256 failed\n");
+ ret++;
+ for (i = 0; i < sizeof(plain46); i++)
+ printf(" %02x", result[i]);
+ printf("\n");
+ }
+
+ return ret;
+}
+
+
+int main(int argc, char *argv[])
+{
+ u8 result[24];
+ int ret = 0;
+ unsigned int i;
+ struct omac1_test_vector *tv;
+
+ ret += test_key_wrap();
+
test_aes_perf();
for (i = 0; i < ARRAY_SIZE(test_vectors); i++) {