4 Copyright (C) Stefan Metzmacher 2015
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "../lib/util/samba_util.h"
21 #include "../lib/crypto/crypto.h"
22 #include "../lib/crypto/aes_test.h"
24 #ifndef AES_CCM_128_ONLY_TESTVECTORS
25 struct torture_context
;
26 bool torture_local_crypto_aes_ccm_128(struct torture_context
*torture
);
29 This uses our own test values as we rely on a 11 byte nonce
30 and the values from rfc rfc3610 use 13 byte nonce.
32 bool torture_local_crypto_aes_ccm_128(struct torture_context
*tctx
)
36 struct aes_mode_testvector testarray
[] = {
37 #endif /* AES_CCM_128_ONLY_TESTVECTORS */
38 #define AES_CCM_128_TESTVECTOR(_k, _n, _a, _p, _c, _t) \
39 AES_MODE_TESTVECTOR(aes_ccm_128, _k, _n, _a, _p, _c, _t)
41 AES_CCM_128_TESTVECTOR(
43 "8BF9FBC2B8149484FF11AB1F3A544FF6",
45 "010000000000000077F7A8",
47 "010000000000000077F7A80000000000"
48 "A8000000000001004100002C00980000",
50 "FE534D4240000100000000000B00811F"
51 "00000000000000000600000000000000"
52 "00000000010000004100002C00980000"
53 "00000000000000000000000000000000"
54 "3900000094010600FFFFFFFFFFFFFFFF"
55 "FFFFFFFFFFFFFFFF7800000030000000"
56 "000000007800000000000000FFFF0000"
58 "03005C003100370032002E0033003100"
59 "2E0039002E003100380033005C006E00"
60 "650074006C006F0067006F006E000000",
62 "25985364BF9AF90EB0B9C8FB55B7C446"
63 "780F310F1EC4677726BFBF34E38E6408"
64 "057EE228814F11CBAAB794A79F7A1F78"
65 "2DE73B7477985360A02D35A7A347ABF7"
66 "9F18DD8687767423BB08F18642B6EFEE"
67 "8B1543D83091AF5952F58BB4BD89FF6B"
68 "0206E7170481C7BC61F06653D0CF10F7"
70 "7B8BF34D687A5C3D4F783F926F7755C0"
71 "2D44C30848C69CFDD8E54395F1881611"
72 "E5502285870A7179068923105190C837",
74 "3C11F652F8EA5600C8607D2E0FEAFD42"
76 AES_CCM_128_TESTVECTOR(
78 "f9fdca4ac64fe7f014de0f43039c7571",
80 "5a8aa485c316e947125478",
82 "3796cf51b8726652a4204733b8fbb047"
83 "cf00fb91a9837e22ec22b1a268f88e2c",
85 "a265480ca88d5f536db0dc6abc40faf0"
86 "d05be7a9669777682345647586786983",
88 "65F8D8422006FB77FB7CCEFDFFF93729"
89 "B3EFCB06A0FAF3A2ABAB485723373F53",
91 "2C62BD82AD231887A7B326E1E045BC91"
93 AES_CCM_128_TESTVECTOR(
95 "197afb02ffbd8f699dacae87094d5243",
97 "5a8aa485c316e947125478",
101 "3796cf51b8726652a4204733b8fbb047"
104 "CA53910394115C5DAB5D7250F04D6A27"
107 "38E3A318F9BA88D4DD2FAF3521820001"
109 AES_CCM_128_TESTVECTOR(
111 "90929a4b0ac65b350ad1591611fe4829",
113 "5a8aa485c316e9403aff85",
117 "a16a2e741f1cd9717285b6d882c1fc53"
120 "ACA5E98D2784D131AE76E3C8BF9C3988"
123 "AE67C0EA38C5383BFDC7967F4E9D1678"
125 AES_CCM_128_TESTVECTOR(
127 "f9fdca4ac64fe7f014de0f43039c7571",
129 "5a8aa485c316e947125478",
131 "3796cf51b8726652a4204733b8fbb047"
132 "cf00fb91a9837e22ec22b1a268f88e2c",
134 "a265480ca88d5f536db0dc6abc40faf0"
137 "65F8D8422006FB77FB7CCEFDFFF93729"
140 "03C6E244586AFAB9B60D9F6DBDF7EB1A"
142 AES_CCM_128_TESTVECTOR(
144 "26511fb51fcfa75cb4b44da75a6e5a0e",
146 "5a8aa485c316e9403aff85",
148 "a16a2e741f1cd9717285b6d882c1fc53"
149 "655e9773761ad697a7ee6410184c7982",
151 "8739b4bea1a099fe547499cbc6d1b13d"
154 "D31F9FC23674D5272125375E0A2F5365"
157 "4F315233A76C4DD99972561C5158AB3B"
159 AES_CCM_128_TESTVECTOR(
161 "f9fdca4ac64fe7f014de0f43039c7571",
163 "5a8aa485c316e947125478",
165 "3796cf51b8726652a4204733b8fbb047"
166 "cf00fb91a9837e22ec22b1a268",
168 "a265480ca88d5f536db0dc6abc40faf0"
169 "d05be7a9669777682376345745",
171 "65F8D8422006FB77FB7CCEFDFFF93729"
172 "B3EFCB06A0FAF3A2AB981875E0",
174 "EA93AAEDA607226E9E79D2EE5C4B62F8"
176 AES_CCM_128_TESTVECTOR(
178 "26511fb51fcfa75cb4b44da75a6e5a0e",
180 "5a8aa485c316e9403aff85",
182 "a16a2e741f1cd9717285b6d882c1fc53"
185 "8739b4bea1a099fe547499cbc6d1b13d"
188 "D31F9FC23674D5272125375E0A2F5365"
191 "036F58DA2372B29BD0E01C58A0E7F9EE"
193 AES_CCM_128_TESTVECTOR(
195 "00000000000000000000000000000000",
197 "0000000000000000000000",
205 "61787D2C432A58293B73D01154E61B6B"
207 AES_CCM_128_TESTVECTOR(
209 "00000000000000000000000000000000",
211 "0000000000000000000000",
219 "E4284A0E813F0FFA146CF59F9ADAFBD7"
221 #ifndef AES_CCM_128_ONLY_TESTVECTORS
224 for (i
=0; i
< ARRAY_SIZE(testarray
); i
++) {
225 struct aes_ccm_128_context ctx
;
226 uint8_t T
[AES_BLOCK_SIZE
];
227 DATA_BLOB _T
= data_blob_const(T
, sizeof(T
));
231 C
= data_blob_dup_talloc(tctx
, testarray
[i
].P
);
233 aes_ccm_128_init(&ctx
, testarray
[i
].K
.data
, testarray
[i
].N
.data
,
234 testarray
[i
].A
.length
, testarray
[i
].P
.length
);
235 aes_ccm_128_update(&ctx
,
237 testarray
[i
].A
.length
);
238 aes_ccm_128_update(&ctx
, C
.data
, C
.length
);
239 aes_ccm_128_crypt(&ctx
, C
.data
, C
.length
);
240 aes_ccm_128_digest(&ctx
, T
);
242 e
= memcmp(testarray
[i
].T
.data
, T
, sizeof(T
));
244 aes_mode_testvector_debug(&testarray
[i
], NULL
, &C
, &_T
);
249 e
= memcmp(testarray
[i
].C
.data
, C
.data
, C
.length
);
251 aes_mode_testvector_debug(&testarray
[i
], NULL
, &C
, &_T
);
257 for (i
=0; i
< ARRAY_SIZE(testarray
); i
++) {
258 struct aes_ccm_128_context ctx
;
259 uint8_t T
[AES_BLOCK_SIZE
];
260 DATA_BLOB _T
= data_blob_const(T
, sizeof(T
));
265 C
= data_blob_dup_talloc(tctx
, testarray
[i
].P
);
267 aes_ccm_128_init(&ctx
, testarray
[i
].K
.data
, testarray
[i
].N
.data
,
268 testarray
[i
].A
.length
, testarray
[i
].P
.length
);
269 for (j
=0; j
< testarray
[i
].A
.length
; j
++) {
270 aes_ccm_128_update(&ctx
, NULL
, 0);
271 aes_ccm_128_update(&ctx
, &testarray
[i
].A
.data
[j
], 1);
272 aes_ccm_128_update(&ctx
, NULL
, 0);
274 for (j
=0; j
< C
.length
; j
++) {
275 aes_ccm_128_crypt(&ctx
, NULL
, 0);
276 aes_ccm_128_update(&ctx
, NULL
, 0);
277 aes_ccm_128_update(&ctx
, &C
.data
[j
], 1);
278 aes_ccm_128_crypt(&ctx
, &C
.data
[j
], 1);
279 aes_ccm_128_crypt(&ctx
, NULL
, 0);
280 aes_ccm_128_update(&ctx
, NULL
, 0);
282 aes_ccm_128_digest(&ctx
, T
);
284 e
= memcmp(testarray
[i
].T
.data
, T
, sizeof(T
));
286 aes_mode_testvector_debug(&testarray
[i
], NULL
, &C
, &_T
);
291 e
= memcmp(testarray
[i
].C
.data
, C
.data
, C
.length
);
293 aes_mode_testvector_debug(&testarray
[i
], NULL
, &C
, &_T
);
299 for (i
=0; i
< ARRAY_SIZE(testarray
); i
++) {
300 struct aes_ccm_128_context ctx
;
301 uint8_t T
[AES_BLOCK_SIZE
];
302 DATA_BLOB _T
= data_blob_const(T
, sizeof(T
));
307 P
= data_blob_dup_talloc(tctx
, testarray
[i
].C
);
309 aes_ccm_128_init(&ctx
, testarray
[i
].K
.data
, testarray
[i
].N
.data
,
310 testarray
[i
].A
.length
, testarray
[i
].P
.length
);
311 for (j
=0; j
< testarray
[i
].A
.length
; j
++) {
312 aes_ccm_128_update(&ctx
, NULL
, 0);
313 aes_ccm_128_update(&ctx
, &testarray
[i
].A
.data
[j
], 1);
314 aes_ccm_128_update(&ctx
, NULL
, 0);
316 for (j
=0; j
< P
.length
; j
++) {
317 aes_ccm_128_crypt(&ctx
, NULL
, 0);
318 aes_ccm_128_update(&ctx
, NULL
, 0);
319 aes_ccm_128_crypt(&ctx
, &P
.data
[j
], 1);
320 aes_ccm_128_update(&ctx
, &P
.data
[j
], 1);
321 aes_ccm_128_crypt(&ctx
, NULL
, 0);
322 aes_ccm_128_update(&ctx
, NULL
, 0);
324 aes_ccm_128_digest(&ctx
, T
);
326 e
= memcmp(testarray
[i
].T
.data
, T
, sizeof(T
));
328 aes_mode_testvector_debug(&testarray
[i
], &P
, NULL
, &_T
);
333 e
= memcmp(testarray
[i
].P
.data
, P
.data
, P
.length
);
335 aes_mode_testvector_debug(&testarray
[i
], &P
, NULL
, &_T
);
341 for (i
=0; i
< ARRAY_SIZE(testarray
); i
++) {
342 struct aes_ccm_128_context ctx
;
343 uint8_t T
[AES_BLOCK_SIZE
];
344 DATA_BLOB _T
= data_blob_const(T
, sizeof(T
));
348 P
= data_blob_dup_talloc(tctx
, testarray
[i
].C
);
350 aes_ccm_128_init(&ctx
, testarray
[i
].K
.data
, testarray
[i
].N
.data
,
351 testarray
[i
].A
.length
, testarray
[i
].P
.length
);
352 aes_ccm_128_update(&ctx
, testarray
[i
].A
.data
, testarray
[i
].A
.length
);
353 aes_ccm_128_crypt(&ctx
, P
.data
, P
.length
);
354 aes_ccm_128_update(&ctx
, P
.data
, P
.length
);
355 aes_ccm_128_digest(&ctx
, T
);
357 e
= memcmp(testarray
[i
].T
.data
, T
, sizeof(T
));
359 aes_mode_testvector_debug(&testarray
[i
], &P
, NULL
, &_T
);
364 e
= memcmp(testarray
[i
].P
.data
, P
.data
, P
.length
);
366 aes_mode_testvector_debug(&testarray
[i
], &P
, NULL
, &_T
);
376 #endif /* AES_CCM_128_ONLY_TESTVECTORS */