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/aes.h"
22 #include "lib/crypto/aes_ccm_128.h"
23 #include "lib/crypto/aes_test.h"
25 #ifndef AES_CCM_128_ONLY_TESTVECTORS
26 struct torture_context
;
27 bool torture_local_crypto_aes_ccm_128(struct torture_context
*torture
);
30 This uses our own test values as we rely on a 11 byte nonce
31 and the values from rfc rfc3610 use 13 byte nonce.
33 bool torture_local_crypto_aes_ccm_128(struct torture_context
*tctx
)
37 struct aes_mode_testvector testarray
[] = {
38 #endif /* AES_CCM_128_ONLY_TESTVECTORS */
39 #define AES_CCM_128_TESTVECTOR(_k, _n, _a, _p, _c, _t) \
40 AES_MODE_TESTVECTOR(aes_ccm_128, _k, _n, _a, _p, _c, _t)
42 AES_CCM_128_TESTVECTOR(
44 "8BF9FBC2B8149484FF11AB1F3A544FF6",
46 "010000000000000077F7A8",
48 "010000000000000077F7A80000000000"
49 "A8000000000001004100002C00980000",
51 "FE534D4240000100000000000B00811F"
52 "00000000000000000600000000000000"
53 "00000000010000004100002C00980000"
54 "00000000000000000000000000000000"
55 "3900000094010600FFFFFFFFFFFFFFFF"
56 "FFFFFFFFFFFFFFFF7800000030000000"
57 "000000007800000000000000FFFF0000"
59 "03005C003100370032002E0033003100"
60 "2E0039002E003100380033005C006E00"
61 "650074006C006F0067006F006E000000",
63 "25985364BF9AF90EB0B9C8FB55B7C446"
64 "780F310F1EC4677726BFBF34E38E6408"
65 "057EE228814F11CBAAB794A79F7A1F78"
66 "2DE73B7477985360A02D35A7A347ABF7"
67 "9F18DD8687767423BB08F18642B6EFEE"
68 "8B1543D83091AF5952F58BB4BD89FF6B"
69 "0206E7170481C7BC61F06653D0CF10F7"
71 "7B8BF34D687A5C3D4F783F926F7755C0"
72 "2D44C30848C69CFDD8E54395F1881611"
73 "E5502285870A7179068923105190C837",
75 "3C11F652F8EA5600C8607D2E0FEAFD42"
77 AES_CCM_128_TESTVECTOR(
79 "f9fdca4ac64fe7f014de0f43039c7571",
81 "5a8aa485c316e947125478",
83 "3796cf51b8726652a4204733b8fbb047"
84 "cf00fb91a9837e22ec22b1a268f88e2c",
86 "a265480ca88d5f536db0dc6abc40faf0"
87 "d05be7a9669777682345647586786983",
89 "65F8D8422006FB77FB7CCEFDFFF93729"
90 "B3EFCB06A0FAF3A2ABAB485723373F53",
92 "2C62BD82AD231887A7B326E1E045BC91"
94 AES_CCM_128_TESTVECTOR(
96 "197afb02ffbd8f699dacae87094d5243",
98 "5a8aa485c316e947125478",
102 "3796cf51b8726652a4204733b8fbb047"
105 "CA53910394115C5DAB5D7250F04D6A27"
108 "38E3A318F9BA88D4DD2FAF3521820001"
110 AES_CCM_128_TESTVECTOR(
112 "90929a4b0ac65b350ad1591611fe4829",
114 "5a8aa485c316e9403aff85",
118 "a16a2e741f1cd9717285b6d882c1fc53"
121 "ACA5E98D2784D131AE76E3C8BF9C3988"
124 "AE67C0EA38C5383BFDC7967F4E9D1678"
126 AES_CCM_128_TESTVECTOR(
128 "f9fdca4ac64fe7f014de0f43039c7571",
130 "5a8aa485c316e947125478",
132 "3796cf51b8726652a4204733b8fbb047"
133 "cf00fb91a9837e22ec22b1a268f88e2c",
135 "a265480ca88d5f536db0dc6abc40faf0"
138 "65F8D8422006FB77FB7CCEFDFFF93729"
141 "03C6E244586AFAB9B60D9F6DBDF7EB1A"
143 AES_CCM_128_TESTVECTOR(
145 "26511fb51fcfa75cb4b44da75a6e5a0e",
147 "5a8aa485c316e9403aff85",
149 "a16a2e741f1cd9717285b6d882c1fc53"
150 "655e9773761ad697a7ee6410184c7982",
152 "8739b4bea1a099fe547499cbc6d1b13d"
155 "D31F9FC23674D5272125375E0A2F5365"
158 "4F315233A76C4DD99972561C5158AB3B"
160 AES_CCM_128_TESTVECTOR(
162 "f9fdca4ac64fe7f014de0f43039c7571",
164 "5a8aa485c316e947125478",
166 "3796cf51b8726652a4204733b8fbb047"
167 "cf00fb91a9837e22ec22b1a268",
169 "a265480ca88d5f536db0dc6abc40faf0"
170 "d05be7a9669777682376345745",
172 "65F8D8422006FB77FB7CCEFDFFF93729"
173 "B3EFCB06A0FAF3A2AB981875E0",
175 "EA93AAEDA607226E9E79D2EE5C4B62F8"
177 AES_CCM_128_TESTVECTOR(
179 "26511fb51fcfa75cb4b44da75a6e5a0e",
181 "5a8aa485c316e9403aff85",
183 "a16a2e741f1cd9717285b6d882c1fc53"
186 "8739b4bea1a099fe547499cbc6d1b13d"
189 "D31F9FC23674D5272125375E0A2F5365"
192 "036F58DA2372B29BD0E01C58A0E7F9EE"
194 AES_CCM_128_TESTVECTOR(
196 "00000000000000000000000000000000",
198 "0000000000000000000000",
206 "61787D2C432A58293B73D01154E61B6B"
208 AES_CCM_128_TESTVECTOR(
210 "00000000000000000000000000000000",
212 "0000000000000000000000",
220 "E4284A0E813F0FFA146CF59F9ADAFBD7"
222 #ifndef AES_CCM_128_ONLY_TESTVECTORS
225 for (i
=0; i
< ARRAY_SIZE(testarray
); i
++) {
226 struct aes_ccm_128_context ctx
;
227 uint8_t T
[AES_BLOCK_SIZE
];
228 DATA_BLOB _T
= data_blob_const(T
, sizeof(T
));
232 C
= data_blob_dup_talloc(tctx
, testarray
[i
].P
);
234 aes_ccm_128_init(&ctx
, testarray
[i
].K
.data
, testarray
[i
].N
.data
,
235 testarray
[i
].A
.length
, testarray
[i
].P
.length
);
236 aes_ccm_128_update(&ctx
,
238 testarray
[i
].A
.length
);
239 aes_ccm_128_update(&ctx
, C
.data
, C
.length
);
240 aes_ccm_128_crypt(&ctx
, C
.data
, C
.length
);
241 aes_ccm_128_digest(&ctx
, T
);
243 e
= memcmp(testarray
[i
].T
.data
, T
, sizeof(T
));
245 aes_mode_testvector_debug(&testarray
[i
], NULL
, &C
, &_T
);
250 e
= memcmp(testarray
[i
].C
.data
, C
.data
, C
.length
);
252 aes_mode_testvector_debug(&testarray
[i
], NULL
, &C
, &_T
);
258 for (i
=0; i
< ARRAY_SIZE(testarray
); i
++) {
259 struct aes_ccm_128_context ctx
;
260 uint8_t T
[AES_BLOCK_SIZE
];
261 DATA_BLOB _T
= data_blob_const(T
, sizeof(T
));
266 C
= data_blob_dup_talloc(tctx
, testarray
[i
].P
);
268 aes_ccm_128_init(&ctx
, testarray
[i
].K
.data
, testarray
[i
].N
.data
,
269 testarray
[i
].A
.length
, testarray
[i
].P
.length
);
270 for (j
=0; j
< testarray
[i
].A
.length
; j
++) {
271 aes_ccm_128_update(&ctx
, NULL
, 0);
272 aes_ccm_128_update(&ctx
, &testarray
[i
].A
.data
[j
], 1);
273 aes_ccm_128_update(&ctx
, NULL
, 0);
275 for (j
=0; j
< C
.length
; j
++) {
276 aes_ccm_128_crypt(&ctx
, NULL
, 0);
277 aes_ccm_128_update(&ctx
, NULL
, 0);
278 aes_ccm_128_update(&ctx
, &C
.data
[j
], 1);
279 aes_ccm_128_crypt(&ctx
, &C
.data
[j
], 1);
280 aes_ccm_128_crypt(&ctx
, NULL
, 0);
281 aes_ccm_128_update(&ctx
, NULL
, 0);
283 aes_ccm_128_digest(&ctx
, T
);
285 e
= memcmp(testarray
[i
].T
.data
, T
, sizeof(T
));
287 aes_mode_testvector_debug(&testarray
[i
], NULL
, &C
, &_T
);
292 e
= memcmp(testarray
[i
].C
.data
, C
.data
, C
.length
);
294 aes_mode_testvector_debug(&testarray
[i
], NULL
, &C
, &_T
);
300 for (i
=0; i
< ARRAY_SIZE(testarray
); i
++) {
301 struct aes_ccm_128_context ctx
;
302 uint8_t T
[AES_BLOCK_SIZE
];
303 DATA_BLOB _T
= data_blob_const(T
, sizeof(T
));
308 P
= data_blob_dup_talloc(tctx
, testarray
[i
].C
);
310 aes_ccm_128_init(&ctx
, testarray
[i
].K
.data
, testarray
[i
].N
.data
,
311 testarray
[i
].A
.length
, testarray
[i
].P
.length
);
312 for (j
=0; j
< testarray
[i
].A
.length
; j
++) {
313 aes_ccm_128_update(&ctx
, NULL
, 0);
314 aes_ccm_128_update(&ctx
, &testarray
[i
].A
.data
[j
], 1);
315 aes_ccm_128_update(&ctx
, NULL
, 0);
317 for (j
=0; j
< P
.length
; j
++) {
318 aes_ccm_128_crypt(&ctx
, NULL
, 0);
319 aes_ccm_128_update(&ctx
, NULL
, 0);
320 aes_ccm_128_crypt(&ctx
, &P
.data
[j
], 1);
321 aes_ccm_128_update(&ctx
, &P
.data
[j
], 1);
322 aes_ccm_128_crypt(&ctx
, NULL
, 0);
323 aes_ccm_128_update(&ctx
, NULL
, 0);
325 aes_ccm_128_digest(&ctx
, T
);
327 e
= memcmp(testarray
[i
].T
.data
, T
, sizeof(T
));
329 aes_mode_testvector_debug(&testarray
[i
], &P
, NULL
, &_T
);
334 e
= memcmp(testarray
[i
].P
.data
, P
.data
, P
.length
);
336 aes_mode_testvector_debug(&testarray
[i
], &P
, NULL
, &_T
);
342 for (i
=0; i
< ARRAY_SIZE(testarray
); i
++) {
343 struct aes_ccm_128_context ctx
;
344 uint8_t T
[AES_BLOCK_SIZE
];
345 DATA_BLOB _T
= data_blob_const(T
, sizeof(T
));
349 P
= data_blob_dup_talloc(tctx
, testarray
[i
].C
);
351 aes_ccm_128_init(&ctx
, testarray
[i
].K
.data
, testarray
[i
].N
.data
,
352 testarray
[i
].A
.length
, testarray
[i
].P
.length
);
353 aes_ccm_128_update(&ctx
, testarray
[i
].A
.data
, testarray
[i
].A
.length
);
354 aes_ccm_128_crypt(&ctx
, P
.data
, P
.length
);
355 aes_ccm_128_update(&ctx
, P
.data
, P
.length
);
356 aes_ccm_128_digest(&ctx
, T
);
358 e
= memcmp(testarray
[i
].T
.data
, T
, sizeof(T
));
360 aes_mode_testvector_debug(&testarray
[i
], &P
, NULL
, &_T
);
365 e
= memcmp(testarray
[i
].P
.data
, P
.data
, P
.length
);
367 aes_mode_testvector_debug(&testarray
[i
], &P
, NULL
, &_T
);
377 #endif /* AES_CCM_128_ONLY_TESTVECTORS */