Added test vectors for AES-CMAC.
[strongswan.git] / src / libstrongswan / plugins / test_vectors / test_vectors / aes_cmac.c
1 /*
2 * Copyright (C) 2012 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the Licenseor (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be usefulbut
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include <crypto/crypto_tester.h>
17
18 /**
19 * RFC 4493 Example #1: AES-CMAC with 0-byte input
20 */
21 prf_test_vector_t aes_cmac_p1 = {
22 .alg = PRF_AES128_CMAC, .key_size = 16, .len = 0,
23 .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
24 .seed = "",
25 .out = "\xbb\x1d\x69\x29\xe9\x59\x37\x28\x7f\xa3\x7d\x12\x9b\x75\x67\x46"
26 };
27
28 /**
29 * RFC 4493 Example #2: AES-CMAC with 16-byte input
30 */
31 prf_test_vector_t aes_cmac_p2 = {
32 .alg = PRF_AES128_CMAC, .key_size = 16, .len = 16,
33 .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
34 .seed = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
35 .out = "\x07\x0a\x16\xb4\x6b\x4d\x41\x44\xf7\x9b\xdd\x9d\xd0\x4a\x28\x7c"
36 };
37
38 /**
39 * RFC 4493 Example #3: AES-CMAC with 40-byte input
40 */
41 prf_test_vector_t aes_cmac_p3 = {
42 .alg = PRF_AES128_CMAC, .key_size = 16, .len = 40,
43 .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
44 .seed = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
45 "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
46 "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11",
47 .out = "\xdf\xa6\x67\x47\xde\x9a\xe6\x30\x30\xca\x32\x61\x14\x97\xc8\x27"
48 };
49
50 /**
51 * RFC 4493 Example #4: AES-CMAC with 64-byte input
52 */
53 prf_test_vector_t aes_cmac_p4 = {
54 .alg = PRF_AES128_CMAC, .key_size = 16, .len = 64,
55 .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
56 .seed = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
57 "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
58 "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
59 "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
60 .out = "\x51\xf0\xbe\xbf\x7e\x3b\x9d\x92\xfc\x49\x74\x17\x79\x36\x3c\xfe"
61 };
62
63 /**
64 * RFC 4615 Test Case #1: AES-CMAC with 20-byte input, 18-byte key
65 */
66 prf_test_vector_t aes_cmac_p5 = {
67 .alg = PRF_AES128_CMAC, .key_size = 18, .len = 20,
68 .key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
69 "\xed\xcb",
70 .seed = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
71 "\x10\x11\x12\x13",
72 .out = "\x84\xa3\x48\xa4\xa4\x5d\x23\x5b\xab\xff\xfc\x0d\x2b\x4d\xa0\x9a"
73 };
74
75 /**
76 * RFC 4615 Test Case #2: AES-CMAC with 20-byte input, 16-byte key
77 */
78 prf_test_vector_t aes_cmac_p6 = {
79 .alg = PRF_AES128_CMAC, .key_size = 16, .len = 20,
80 .key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
81 .seed = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
82 "\x10\x11\x12\x13",
83 .out = "\x98\x0a\xe8\x7b\x5f\x4c\x9c\x52\x14\xf5\xb6\xa8\x45\x5e\x4c\x2d"
84 };
85
86 /**
87 * RFC 4615 Test Case #3: AES-CMAC with 20-byte input, 10-byte key
88 */
89 prf_test_vector_t aes_cmac_p7 = {
90 .alg = PRF_AES128_CMAC, .key_size = 10, .len = 20,
91 .key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09",
92 .seed = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
93 "\x10\x11\x12\x13",
94 .out = "\x29\x0d\x9e\x11\x2e\xdb\x09\xee\x14\x1f\xcf\x64\xc0\xb7\x2f\x3d"
95 };
96
97 /**
98 * RFC 4494 Test Case #1: AES-CMAC-96 with 0-byte input
99 */
100 signer_test_vector_t aes_cmac_s1 = {
101 .alg = AUTH_AES_CMAC_96, .len = 0,
102 .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
103 .data = "",
104 .mac = "\xbb\x1d\x69\x29\xe9\x59\x37\x28\x7f\xa3\x7d\x12"
105 };
106
107
108 /**
109 * RFC 4494 Test Case #2: AES-CMAC-96 with 16-byte input
110 */
111 signer_test_vector_t aes_cmac_s2 = {
112 .alg = AUTH_AES_CMAC_96, .len = 16,
113 .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
114 .data = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a",
115 .mac = "\x07\x0a\x16\xb4\x6b\x4d\x41\x44\xf7\x9b\xdd\x9d"
116 };
117
118 /**
119 * RFC 4494 Test Case #3: AES-CMAC-96 with 40-byte input
120 */
121 signer_test_vector_t aes_cmac_s3 = {
122 .alg = AUTH_AES_CMAC_96, .len = 40,
123 .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
124 .data = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
125 "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
126 "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11",
127 .mac = "\xdf\xa6\x67\x47\xde\x9a\xe6\x30\x30\xca\x32\x61"
128 };
129
130 /**
131 * RFC 4494 Test Case #4: AES-CMAC-96 with 64-byte input
132 */
133 signer_test_vector_t aes_cmac_s4 = {
134 .alg = AUTH_AES_CMAC_96, .len = 64,
135 .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
136 .data = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
137 "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
138 "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
139 "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
140 .mac = "\x51\xf0\xbe\xbf\x7e\x3b\x9d\x92\xfc\x49\x74\x17"
141 };