4 Copyright (C) Stefan Metzmacher 2014
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"
23 struct torture_context
;
24 bool torture_local_crypto_aes_gcm_128(struct torture_context
*torture
);
27 This uses the test values from ...
29 bool torture_local_crypto_aes_gcm_128(struct torture_context
*torture
)
42 TALLOC_CTX
*tctx
= talloc_new(torture
);
43 if (!tctx
) { return false; };
45 ZERO_STRUCT(testarray
);
47 testarray
[0].K
= strhex_to_data_blob(tctx
,
48 "00000000000000000000000000000000");
49 testarray
[0].IV
= strhex_to_data_blob(tctx
,
50 "000000000000000000000000");
51 testarray
[0].A
= data_blob_null
;
52 testarray
[0].P
= data_blob_null
;
53 testarray
[0].C
= data_blob_null
;
54 testarray
[0].T
= strhex_to_data_blob(tctx
,
55 "58e2fccefa7e3061367f1d57a4e7455a");
57 testarray
[1].K
= strhex_to_data_blob(tctx
,
58 "00000000000000000000000000000000");
59 testarray
[1].IV
= strhex_to_data_blob(tctx
,
60 "000000000000000000000000");
61 testarray
[1].A
= data_blob_null
;
62 testarray
[1].P
= strhex_to_data_blob(tctx
,
63 "00000000000000000000000000000000");
64 testarray
[1].C
= strhex_to_data_blob(tctx
,
65 "0388dace60b6a392f328c2b971b2fe78");
66 testarray
[1].T
= strhex_to_data_blob(tctx
,
67 "ab6e47d42cec13bdf53a67b21257bddf");
69 testarray
[2].K
= strhex_to_data_blob(tctx
,
70 "feffe9928665731c6d6a8f9467308308");
71 testarray
[2].IV
= strhex_to_data_blob(tctx
,
72 "cafebabefacedbaddecaf888");
73 testarray
[2].A
= data_blob_null
;
74 testarray
[2].P
= strhex_to_data_blob(tctx
,
75 "d9313225f88406e5a55909c5aff5269a"
76 "86a7a9531534f7da2e4c303d8a318a72"
77 "1c3c0c95956809532fcf0e2449a6b525"
78 "b16aedf5aa0de657ba637b391aafd255");
79 testarray
[2].C
= strhex_to_data_blob(tctx
,
80 "42831ec2217774244b7221b784d0d49c"
81 "e3aa212f2c02a4e035c17e2329aca12e"
82 "21d514b25466931c7d8f6a5aac84aa05"
83 "1ba30b396a0aac973d58e091473f5985");
84 testarray
[2].T
= strhex_to_data_blob(tctx
,
85 "4d5c2af327cd64a62cf35abd2ba6fab4");
87 testarray
[3].K
= strhex_to_data_blob(tctx
,
88 "feffe9928665731c6d6a8f9467308308");
89 testarray
[3].IV
= strhex_to_data_blob(tctx
,
90 "cafebabefacedbaddecaf888");
91 testarray
[3].A
= strhex_to_data_blob(tctx
,
92 "feedfacedeadbeeffeedfacedeadbeef"
94 testarray
[3].P
= strhex_to_data_blob(tctx
,
95 "d9313225f88406e5a55909c5aff5269a"
96 "86a7a9531534f7da2e4c303d8a318a72"
97 "1c3c0c95956809532fcf0e2449a6b525"
98 "b16aedf5aa0de657ba637b39");
99 testarray
[3].C
= strhex_to_data_blob(tctx
,
100 "42831ec2217774244b7221b784d0d49c"
101 "e3aa212f2c02a4e035c17e2329aca12e"
102 "21d514b25466931c7d8f6a5aac84aa05"
103 "1ba30b396a0aac973d58e091");
104 testarray
[3].T
= strhex_to_data_blob(tctx
,
105 "5bc94fbc3221a5db94fae95ae7121a47");
107 for (i
=1; testarray
[i
].T
.length
!= 0; i
++) {
108 struct aes_gcm_128_context ctx
;
109 uint8_t T
[AES_BLOCK_SIZE
];
113 C
= data_blob_dup_talloc(tctx
, testarray
[i
].P
);
115 aes_gcm_128_init(&ctx
, testarray
[i
].K
.data
, testarray
[i
].IV
.data
);
116 aes_gcm_128_updateA(&ctx
,
118 testarray
[i
].A
.length
);
119 aes_gcm_128_crypt(&ctx
, C
.data
, C
.length
);
120 aes_gcm_128_updateC(&ctx
, C
.data
, C
.length
);
121 aes_gcm_128_digest(&ctx
, T
);
123 e
= memcmp(testarray
[i
].T
.data
, T
, sizeof(T
));
125 printf("%s: aes_gcm_128 test[%u]: failed\n", __location__
, i
);
127 dump_data(0, testarray
[i
].K
.data
, testarray
[i
].K
.length
);
129 dump_data(0, testarray
[i
].IV
.data
, testarray
[i
].IV
.length
);
131 dump_data(0, testarray
[i
].A
.data
, testarray
[i
].A
.length
);
133 dump_data(0, testarray
[i
].P
.data
, testarray
[i
].P
.length
);
135 dump_data(0, testarray
[i
].C
.data
, testarray
[i
].C
.length
);
137 dump_data(0, C
.data
, C
.length
);
139 dump_data(0, testarray
[i
].T
.data
, testarray
[i
].T
.length
);
141 dump_data(0, T
, sizeof(T
));
146 e
= memcmp(testarray
[i
].C
.data
, C
.data
, C
.length
);
148 printf("%s: aes_gcm_128 test[%u]: failed\n", __location__
, i
);
150 dump_data(0, testarray
[i
].K
.data
, testarray
[i
].K
.length
);
152 dump_data(0, testarray
[i
].IV
.data
, testarray
[i
].IV
.length
);
154 dump_data(0, testarray
[i
].A
.data
, testarray
[i
].A
.length
);
156 dump_data(0, testarray
[i
].P
.data
, testarray
[i
].P
.length
);
158 dump_data(0, testarray
[i
].C
.data
, testarray
[i
].C
.length
);
160 dump_data(0, C
.data
, C
.length
);
162 dump_data(0, testarray
[i
].T
.data
, testarray
[i
].T
.length
);
164 dump_data(0, T
, sizeof(T
));
170 for (i
=1; testarray
[i
].T
.length
!= 0; i
++) {
171 struct aes_gcm_128_context ctx
;
172 uint8_t T
[AES_BLOCK_SIZE
];
177 C
= data_blob_dup_talloc(tctx
, testarray
[i
].P
);
179 aes_gcm_128_init(&ctx
, testarray
[i
].K
.data
, testarray
[i
].IV
.data
);
180 for (j
=0; j
< testarray
[i
].A
.length
; j
++) {
181 aes_gcm_128_updateA(&ctx
, &testarray
[i
].A
.data
[j
], 1);
183 for (j
=0; j
< C
.length
; j
++) {
184 aes_gcm_128_crypt(&ctx
, &C
.data
[j
], 1);
185 aes_gcm_128_updateC(&ctx
, &C
.data
[j
], 1);
187 aes_gcm_128_digest(&ctx
, T
);
189 e
= memcmp(testarray
[i
].T
.data
, T
, sizeof(T
));
191 printf("%s: aes_gcm_128 test[%u]: failed\n", __location__
, i
);
193 dump_data(0, testarray
[i
].K
.data
, testarray
[i
].K
.length
);
195 dump_data(0, testarray
[i
].IV
.data
, testarray
[i
].IV
.length
);
197 dump_data(0, testarray
[i
].A
.data
, testarray
[i
].A
.length
);
199 dump_data(0, testarray
[i
].P
.data
, testarray
[i
].P
.length
);
201 dump_data(0, testarray
[i
].C
.data
, testarray
[i
].C
.length
);
203 dump_data(0, C
.data
, C
.length
);
205 dump_data(0, testarray
[i
].T
.data
, testarray
[i
].T
.length
);
207 dump_data(0, T
, sizeof(T
));
212 e
= memcmp(testarray
[i
].C
.data
, C
.data
, C
.length
);
214 printf("%s: aes_gcm_128 test[%u]: failed\n", __location__
, i
);
216 dump_data(0, testarray
[i
].K
.data
, testarray
[i
].K
.length
);
218 dump_data(0, testarray
[i
].IV
.data
, testarray
[i
].IV
.length
);
220 dump_data(0, testarray
[i
].A
.data
, testarray
[i
].A
.length
);
222 dump_data(0, testarray
[i
].P
.data
, testarray
[i
].P
.length
);
224 dump_data(0, testarray
[i
].C
.data
, testarray
[i
].C
.length
);
226 dump_data(0, C
.data
, C
.length
);
228 dump_data(0, testarray
[i
].T
.data
, testarray
[i
].T
.length
);
230 dump_data(0, T
, sizeof(T
));
236 for (i
=1; testarray
[i
].T
.length
!= 0; i
++) {
237 struct aes_gcm_128_context ctx
;
238 uint8_t T
[AES_BLOCK_SIZE
];
243 P
= data_blob_dup_talloc(tctx
, testarray
[i
].C
);
245 aes_gcm_128_init(&ctx
, testarray
[i
].K
.data
, testarray
[i
].IV
.data
);
246 for (j
=0; j
< testarray
[i
].A
.length
; j
++) {
247 aes_gcm_128_updateA(&ctx
, &testarray
[i
].A
.data
[j
], 1);
249 for (j
=0; j
< P
.length
; j
++) {
250 aes_gcm_128_updateC(&ctx
, &P
.data
[j
], 1);
251 aes_gcm_128_crypt(&ctx
, &P
.data
[j
], 1);
253 aes_gcm_128_digest(&ctx
, T
);
255 e
= memcmp(testarray
[i
].T
.data
, T
, sizeof(T
));
257 printf("%s: aes_gcm_128 test[%u]: failed\n", __location__
, i
);
259 dump_data(0, testarray
[i
].K
.data
, testarray
[i
].K
.length
);
261 dump_data(0, testarray
[i
].IV
.data
, testarray
[i
].IV
.length
);
263 dump_data(0, testarray
[i
].A
.data
, testarray
[i
].A
.length
);
265 dump_data(0, testarray
[i
].P
.data
, testarray
[i
].P
.length
);
267 dump_data(0, P
.data
, P
.length
);
269 dump_data(0, testarray
[i
].C
.data
, testarray
[i
].C
.length
);
271 dump_data(0, testarray
[i
].T
.data
, testarray
[i
].T
.length
);
273 dump_data(0, T
, sizeof(T
));
278 e
= memcmp(testarray
[i
].P
.data
, P
.data
, P
.length
);
280 printf("%s: aes_gcm_128 test[%u]: failed\n", __location__
, i
);
282 dump_data(0, testarray
[i
].K
.data
, testarray
[i
].K
.length
);
284 dump_data(0, testarray
[i
].IV
.data
, testarray
[i
].IV
.length
);
286 dump_data(0, testarray
[i
].A
.data
, testarray
[i
].A
.length
);
288 dump_data(0, testarray
[i
].P
.data
, testarray
[i
].P
.length
);
290 dump_data(0, P
.data
, P
.length
);
292 dump_data(0, testarray
[i
].C
.data
, testarray
[i
].C
.length
);
294 dump_data(0, testarray
[i
].T
.data
, testarray
[i
].T
.length
);
296 dump_data(0, T
, sizeof(T
));
302 for (i
=1; testarray
[i
].T
.length
!= 0; i
++) {
303 struct aes_gcm_128_context ctx
;
304 uint8_t T
[AES_BLOCK_SIZE
];
308 P
= data_blob_dup_talloc(tctx
, testarray
[i
].C
);
310 aes_gcm_128_init(&ctx
, testarray
[i
].K
.data
, testarray
[i
].IV
.data
);
311 aes_gcm_128_updateA(&ctx
, testarray
[i
].A
.data
, testarray
[i
].A
.length
);
312 aes_gcm_128_updateC(&ctx
, P
.data
, P
.length
);
313 aes_gcm_128_crypt(&ctx
, P
.data
, P
.length
);
314 aes_gcm_128_digest(&ctx
, T
);
316 e
= memcmp(testarray
[i
].T
.data
, T
, sizeof(T
));
318 printf("%s: aes_gcm_128 test[%u]: failed\n", __location__
, i
);
320 dump_data(0, testarray
[i
].K
.data
, testarray
[i
].K
.length
);
322 dump_data(0, testarray
[i
].IV
.data
, testarray
[i
].IV
.length
);
324 dump_data(0, testarray
[i
].A
.data
, testarray
[i
].A
.length
);
326 dump_data(0, testarray
[i
].P
.data
, testarray
[i
].P
.length
);
328 dump_data(0, P
.data
, P
.length
);
330 dump_data(0, testarray
[i
].C
.data
, testarray
[i
].C
.length
);
332 dump_data(0, testarray
[i
].T
.data
, testarray
[i
].T
.length
);
334 dump_data(0, T
, sizeof(T
));
339 e
= memcmp(testarray
[i
].P
.data
, P
.data
, P
.length
);
341 printf("%s: aes_gcm_128 test[%u]: failed\n", __location__
, i
);
343 dump_data(0, testarray
[i
].K
.data
, testarray
[i
].K
.length
);
345 dump_data(0, testarray
[i
].IV
.data
, testarray
[i
].IV
.length
);
347 dump_data(0, testarray
[i
].A
.data
, testarray
[i
].A
.length
);
349 dump_data(0, testarray
[i
].P
.data
, testarray
[i
].P
.length
);
351 dump_data(0, P
.data
, P
.length
);
353 dump_data(0, testarray
[i
].C
.data
, testarray
[i
].C
.length
);
355 dump_data(0, testarray
[i
].T
.data
, testarray
[i
].T
.length
);
357 dump_data(0, T
, sizeof(T
));