Revert "nfs4acl: Fix owner mapping with ID_TYPE_BOTH"
[Samba.git] / lib / crypto / aes_ccm_128_test.c
blob67745e3e1ae31b0104c2eba3e31e96d44cb42d8a
1 /*
2 AES-CCM-128 tests
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/>.
19 #include "replace.h"
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)
35 bool ret = true;
36 uint32_t i;
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(
43 /* K */
44 "8BF9FBC2B8149484FF11AB1F3A544FF6",
45 /* N */
46 "010000000000000077F7A8",
47 /* A */
48 "010000000000000077F7A80000000000"
49 "A8000000000001004100002C00980000",
50 /* P */
51 "FE534D4240000100000000000B00811F"
52 "00000000000000000600000000000000"
53 "00000000010000004100002C00980000"
54 "00000000000000000000000000000000"
55 "3900000094010600FFFFFFFFFFFFFFFF"
56 "FFFFFFFFFFFFFFFF7800000030000000"
57 "000000007800000000000000FFFF0000"
58 "0100000000000000"
59 "03005C003100370032002E0033003100"
60 "2E0039002E003100380033005C006E00"
61 "650074006C006F0067006F006E000000",
62 /* C */
63 "25985364BF9AF90EB0B9C8FB55B7C446"
64 "780F310F1EC4677726BFBF34E38E6408"
65 "057EE228814F11CBAAB794A79F7A1F78"
66 "2DE73B7477985360A02D35A7A347ABF7"
67 "9F18DD8687767423BB08F18642B6EFEE"
68 "8B1543D83091AF5952F58BB4BD89FF6B"
69 "0206E7170481C7BC61F06653D0CF10F7"
70 "C78380389382C276"
71 "7B8BF34D687A5C3D4F783F926F7755C0"
72 "2D44C30848C69CFDD8E54395F1881611"
73 "E5502285870A7179068923105190C837",
74 /* T */
75 "3C11F652F8EA5600C8607D2E0FEAFD42"
77 AES_CCM_128_TESTVECTOR(
78 /* K */
79 "f9fdca4ac64fe7f014de0f43039c7571",
80 /* N */
81 "5a8aa485c316e947125478",
82 /* A */
83 "3796cf51b8726652a4204733b8fbb047"
84 "cf00fb91a9837e22ec22b1a268f88e2c",
85 /* P */
86 "a265480ca88d5f536db0dc6abc40faf0"
87 "d05be7a9669777682345647586786983",
88 /* C */
89 "65F8D8422006FB77FB7CCEFDFFF93729"
90 "B3EFCB06A0FAF3A2ABAB485723373F53",
91 /* T */
92 "2C62BD82AD231887A7B326E1E045BC91"
94 AES_CCM_128_TESTVECTOR(
95 /* K */
96 "197afb02ffbd8f699dacae87094d5243",
97 /* N */
98 "5a8aa485c316e947125478",
99 /* A */
101 /* P */
102 "3796cf51b8726652a4204733b8fbb047"
103 "cf00fb91a9837e22",
104 /* C */
105 "CA53910394115C5DAB5D7250F04D6A27"
106 "2BCFA4329528F3AC",
107 /* T */
108 "38E3A318F9BA88D4DD2FAF3521820001"
110 AES_CCM_128_TESTVECTOR(
111 /* K */
112 "90929a4b0ac65b350ad1591611fe4829",
113 /* N */
114 "5a8aa485c316e9403aff85",
115 /* A */
117 /* P */
118 "a16a2e741f1cd9717285b6d882c1fc53"
119 "655e9773761ad697",
120 /* C */
121 "ACA5E98D2784D131AE76E3C8BF9C3988"
122 "35C0206C71893F26",
123 /* T */
124 "AE67C0EA38C5383BFDC7967F4E9D1678"
126 AES_CCM_128_TESTVECTOR(
127 /* K */
128 "f9fdca4ac64fe7f014de0f43039c7571",
129 /* N */
130 "5a8aa485c316e947125478",
131 /* A */
132 "3796cf51b8726652a4204733b8fbb047"
133 "cf00fb91a9837e22ec22b1a268f88e2c",
134 /* P */
135 "a265480ca88d5f536db0dc6abc40faf0"
136 "d05be7a966977768",
137 /* C */
138 "65F8D8422006FB77FB7CCEFDFFF93729"
139 "B3EFCB06A0FAF3A2",
140 /* T */
141 "03C6E244586AFAB9B60D9F6DBDF7EB1A"
143 AES_CCM_128_TESTVECTOR(
144 /* K */
145 "26511fb51fcfa75cb4b44da75a6e5a0e",
146 /* N */
147 "5a8aa485c316e9403aff85",
148 /* A */
149 "a16a2e741f1cd9717285b6d882c1fc53"
150 "655e9773761ad697a7ee6410184c7982",
151 /* P */
152 "8739b4bea1a099fe547499cbc6d1b13d"
153 "849b8084c9b6acc5",
154 /* C */
155 "D31F9FC23674D5272125375E0A2F5365"
156 "41B1FAF1DD68C819",
157 /* T */
158 "4F315233A76C4DD99972561C5158AB3B"
160 AES_CCM_128_TESTVECTOR(
161 /* K */
162 "f9fdca4ac64fe7f014de0f43039c7571",
163 /* N */
164 "5a8aa485c316e947125478",
165 /* A */
166 "3796cf51b8726652a4204733b8fbb047"
167 "cf00fb91a9837e22ec22b1a268",
168 /* P */
169 "a265480ca88d5f536db0dc6abc40faf0"
170 "d05be7a9669777682376345745",
171 /* C */
172 "65F8D8422006FB77FB7CCEFDFFF93729"
173 "B3EFCB06A0FAF3A2AB981875E0",
174 /* T */
175 "EA93AAEDA607226E9E79D2EE5C4B62F8"
177 AES_CCM_128_TESTVECTOR(
178 /* K */
179 "26511fb51fcfa75cb4b44da75a6e5a0e",
180 /* N */
181 "5a8aa485c316e9403aff85",
182 /* A */
183 "a16a2e741f1cd9717285b6d882c1fc53"
184 "65",
185 /* P */
186 "8739b4bea1a099fe547499cbc6d1b13d"
187 "84",
188 /* C */
189 "D31F9FC23674D5272125375E0A2F5365"
190 "41",
191 /* T */
192 "036F58DA2372B29BD0E01C58A0E7F9EE"
194 AES_CCM_128_TESTVECTOR(
195 /* K */
196 "00000000000000000000000000000000",
197 /* N */
198 "0000000000000000000000",
199 /* A */
201 /* P */
202 "00",
203 /* C */
204 "2E",
205 /* T */
206 "61787D2C432A58293B73D01154E61B6B"
208 AES_CCM_128_TESTVECTOR(
209 /* K */
210 "00000000000000000000000000000000",
211 /* N */
212 "0000000000000000000000",
213 /* A */
214 "00",
215 /* P */
216 "00",
217 /* C */
218 "2E",
219 /* T */
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));
229 DATA_BLOB C;
230 int e;
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,
237 testarray[i].A.data,
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));
244 if (e != 0) {
245 aes_mode_testvector_debug(&testarray[i], NULL, &C, &_T);
246 ret = false;
247 goto fail;
250 e = memcmp(testarray[i].C.data, C.data, C.length);
251 if (e != 0) {
252 aes_mode_testvector_debug(&testarray[i], NULL, &C, &_T);
253 ret = false;
254 goto fail;
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));
262 DATA_BLOB C;
263 int e;
264 size_t j;
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));
286 if (e != 0) {
287 aes_mode_testvector_debug(&testarray[i], NULL, &C, &_T);
288 ret = false;
289 goto fail;
292 e = memcmp(testarray[i].C.data, C.data, C.length);
293 if (e != 0) {
294 aes_mode_testvector_debug(&testarray[i], NULL, &C, &_T);
295 ret = false;
296 goto fail;
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));
304 DATA_BLOB P;
305 int e;
306 size_t j;
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));
328 if (e != 0) {
329 aes_mode_testvector_debug(&testarray[i], &P, NULL, &_T);
330 ret = false;
331 goto fail;
334 e = memcmp(testarray[i].P.data, P.data, P.length);
335 if (e != 0) {
336 aes_mode_testvector_debug(&testarray[i], &P, NULL, &_T);
337 ret = false;
338 goto fail;
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));
346 DATA_BLOB P;
347 int e;
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));
359 if (e != 0) {
360 aes_mode_testvector_debug(&testarray[i], &P, NULL, &_T);
361 ret = false;
362 goto fail;
365 e = memcmp(testarray[i].P.data, P.data, P.length);
366 if (e != 0) {
367 aes_mode_testvector_debug(&testarray[i], &P, NULL, &_T);
368 ret = false;
369 goto fail;
373 fail:
374 return ret;
377 #endif /* AES_CCM_128_ONLY_TESTVECTORS */