Commit | Line | Data |
---|---|---|
da7f033d HX |
1 | /* |
2 | * Algorithm testing framework and tests. | |
3 | * | |
4 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> | |
5 | * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org> | |
6 | * Copyright (c) 2007 Nokia Siemens Networks | |
7 | * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au> | |
8 | * | |
69435b94 AH |
9 | * Updated RFC4106 AES-GCM testing. |
10 | * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com) | |
11 | * Adrian Hoban <adrian.hoban@intel.com> | |
12 | * Gabriele Paoloni <gabriele.paoloni@intel.com> | |
13 | * Tadeusz Struk (tadeusz.struk@intel.com) | |
14 | * Copyright (c) 2010, Intel Corporation. | |
15 | * | |
da7f033d HX |
16 | * This program is free software; you can redistribute it and/or modify it |
17 | * under the terms of the GNU General Public License as published by the Free | |
18 | * Software Foundation; either version 2 of the License, or (at your option) | |
19 | * any later version. | |
20 | * | |
21 | */ | |
22 | ||
23 | #include <crypto/hash.h> | |
24 | #include <linux/err.h> | |
1c41b882 | 25 | #include <linux/fips.h> |
da7f033d HX |
26 | #include <linux/module.h> |
27 | #include <linux/scatterlist.h> | |
28 | #include <linux/slab.h> | |
29 | #include <linux/string.h> | |
7647d6ce | 30 | #include <crypto/rng.h> |
64d1cdfb | 31 | #include <crypto/drbg.h> |
da7f033d HX |
32 | |
33 | #include "internal.h" | |
0b767f96 | 34 | |
326a6346 | 35 | #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS |
0b767f96 AS |
36 | |
37 | /* a perfect nop */ | |
38 | int alg_test(const char *driver, const char *alg, u32 type, u32 mask) | |
39 | { | |
40 | return 0; | |
41 | } | |
42 | ||
43 | #else | |
44 | ||
da7f033d HX |
45 | #include "testmgr.h" |
46 | ||
47 | /* | |
48 | * Need slab memory for testing (size in number of pages). | |
49 | */ | |
50 | #define XBUFSIZE 8 | |
51 | ||
52 | /* | |
53 | * Indexes into the xbuf to simulate cross-page access. | |
54 | */ | |
55 | #define IDX1 32 | |
56 | #define IDX2 32400 | |
57 | #define IDX3 1 | |
58 | #define IDX4 8193 | |
59 | #define IDX5 22222 | |
60 | #define IDX6 17101 | |
61 | #define IDX7 27333 | |
62 | #define IDX8 3000 | |
63 | ||
64 | /* | |
65 | * Used by test_cipher() | |
66 | */ | |
67 | #define ENCRYPT 1 | |
68 | #define DECRYPT 0 | |
69 | ||
70 | struct tcrypt_result { | |
71 | struct completion completion; | |
72 | int err; | |
73 | }; | |
74 | ||
75 | struct aead_test_suite { | |
76 | struct { | |
77 | struct aead_testvec *vecs; | |
78 | unsigned int count; | |
79 | } enc, dec; | |
80 | }; | |
81 | ||
82 | struct cipher_test_suite { | |
83 | struct { | |
84 | struct cipher_testvec *vecs; | |
85 | unsigned int count; | |
86 | } enc, dec; | |
87 | }; | |
88 | ||
89 | struct comp_test_suite { | |
90 | struct { | |
91 | struct comp_testvec *vecs; | |
92 | unsigned int count; | |
93 | } comp, decomp; | |
94 | }; | |
95 | ||
8064efb8 GU |
96 | struct pcomp_test_suite { |
97 | struct { | |
98 | struct pcomp_testvec *vecs; | |
99 | unsigned int count; | |
100 | } comp, decomp; | |
101 | }; | |
102 | ||
da7f033d HX |
103 | struct hash_test_suite { |
104 | struct hash_testvec *vecs; | |
105 | unsigned int count; | |
106 | }; | |
107 | ||
7647d6ce JW |
108 | struct cprng_test_suite { |
109 | struct cprng_testvec *vecs; | |
110 | unsigned int count; | |
111 | }; | |
112 | ||
64d1cdfb SM |
113 | struct drbg_test_suite { |
114 | struct drbg_testvec *vecs; | |
115 | unsigned int count; | |
116 | }; | |
117 | ||
da7f033d HX |
118 | struct alg_test_desc { |
119 | const char *alg; | |
120 | int (*test)(const struct alg_test_desc *desc, const char *driver, | |
121 | u32 type, u32 mask); | |
a1915d51 | 122 | int fips_allowed; /* set if alg is allowed in fips mode */ |
da7f033d HX |
123 | |
124 | union { | |
125 | struct aead_test_suite aead; | |
126 | struct cipher_test_suite cipher; | |
127 | struct comp_test_suite comp; | |
8064efb8 | 128 | struct pcomp_test_suite pcomp; |
da7f033d | 129 | struct hash_test_suite hash; |
7647d6ce | 130 | struct cprng_test_suite cprng; |
64d1cdfb | 131 | struct drbg_test_suite drbg; |
da7f033d HX |
132 | } suite; |
133 | }; | |
134 | ||
135 | static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; | |
136 | ||
da7f033d HX |
137 | static void hexdump(unsigned char *buf, unsigned int len) |
138 | { | |
139 | print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET, | |
140 | 16, 1, | |
141 | buf, len, false); | |
142 | } | |
143 | ||
144 | static void tcrypt_complete(struct crypto_async_request *req, int err) | |
145 | { | |
146 | struct tcrypt_result *res = req->data; | |
147 | ||
148 | if (err == -EINPROGRESS) | |
149 | return; | |
150 | ||
151 | res->err = err; | |
152 | complete(&res->completion); | |
153 | } | |
154 | ||
f8b0d4d0 HX |
155 | static int testmgr_alloc_buf(char *buf[XBUFSIZE]) |
156 | { | |
157 | int i; | |
158 | ||
159 | for (i = 0; i < XBUFSIZE; i++) { | |
160 | buf[i] = (void *)__get_free_page(GFP_KERNEL); | |
161 | if (!buf[i]) | |
162 | goto err_free_buf; | |
163 | } | |
164 | ||
165 | return 0; | |
166 | ||
167 | err_free_buf: | |
168 | while (i-- > 0) | |
169 | free_page((unsigned long)buf[i]); | |
170 | ||
171 | return -ENOMEM; | |
172 | } | |
173 | ||
174 | static void testmgr_free_buf(char *buf[XBUFSIZE]) | |
175 | { | |
176 | int i; | |
177 | ||
178 | for (i = 0; i < XBUFSIZE; i++) | |
179 | free_page((unsigned long)buf[i]); | |
180 | } | |
181 | ||
d4c85f9b | 182 | static int wait_async_op(struct tcrypt_result *tr, int ret) |
a8f1a052 DM |
183 | { |
184 | if (ret == -EINPROGRESS || ret == -EBUSY) { | |
8a45ac12 | 185 | wait_for_completion(&tr->completion); |
16735d02 | 186 | reinit_completion(&tr->completion); |
8a45ac12 | 187 | ret = tr->err; |
a8f1a052 DM |
188 | } |
189 | return ret; | |
190 | } | |
191 | ||
da5ffe11 JK |
192 | static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, |
193 | unsigned int tcount, bool use_digest, | |
194 | const int align_offset) | |
da7f033d HX |
195 | { |
196 | const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm)); | |
197 | unsigned int i, j, k, temp; | |
198 | struct scatterlist sg[8]; | |
29b77e5d HG |
199 | char *result; |
200 | char *key; | |
da7f033d HX |
201 | struct ahash_request *req; |
202 | struct tcrypt_result tresult; | |
da7f033d | 203 | void *hash_buff; |
f8b0d4d0 HX |
204 | char *xbuf[XBUFSIZE]; |
205 | int ret = -ENOMEM; | |
206 | ||
29b77e5d HG |
207 | result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL); |
208 | if (!result) | |
209 | return ret; | |
210 | key = kmalloc(MAX_KEYLEN, GFP_KERNEL); | |
211 | if (!key) | |
212 | goto out_nobuf; | |
f8b0d4d0 HX |
213 | if (testmgr_alloc_buf(xbuf)) |
214 | goto out_nobuf; | |
da7f033d HX |
215 | |
216 | init_completion(&tresult.completion); | |
217 | ||
218 | req = ahash_request_alloc(tfm, GFP_KERNEL); | |
219 | if (!req) { | |
220 | printk(KERN_ERR "alg: hash: Failed to allocate request for " | |
221 | "%s\n", algo); | |
da7f033d HX |
222 | goto out_noreq; |
223 | } | |
224 | ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, | |
225 | tcrypt_complete, &tresult); | |
226 | ||
a0cfae59 | 227 | j = 0; |
da7f033d | 228 | for (i = 0; i < tcount; i++) { |
a0cfae59 HX |
229 | if (template[i].np) |
230 | continue; | |
231 | ||
da5ffe11 JK |
232 | ret = -EINVAL; |
233 | if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE)) | |
234 | goto out; | |
235 | ||
a0cfae59 | 236 | j++; |
29b77e5d | 237 | memset(result, 0, MAX_DIGEST_SIZE); |
da7f033d HX |
238 | |
239 | hash_buff = xbuf[0]; | |
da5ffe11 | 240 | hash_buff += align_offset; |
da7f033d HX |
241 | |
242 | memcpy(hash_buff, template[i].plaintext, template[i].psize); | |
243 | sg_init_one(&sg[0], hash_buff, template[i].psize); | |
244 | ||
245 | if (template[i].ksize) { | |
246 | crypto_ahash_clear_flags(tfm, ~0); | |
29b77e5d HG |
247 | if (template[i].ksize > MAX_KEYLEN) { |
248 | pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n", | |
249 | j, algo, template[i].ksize, MAX_KEYLEN); | |
250 | ret = -EINVAL; | |
251 | goto out; | |
252 | } | |
253 | memcpy(key, template[i].key, template[i].ksize); | |
254 | ret = crypto_ahash_setkey(tfm, key, template[i].ksize); | |
da7f033d HX |
255 | if (ret) { |
256 | printk(KERN_ERR "alg: hash: setkey failed on " | |
a0cfae59 | 257 | "test %d for %s: ret=%d\n", j, algo, |
da7f033d HX |
258 | -ret); |
259 | goto out; | |
260 | } | |
261 | } | |
262 | ||
263 | ahash_request_set_crypt(req, sg, result, template[i].psize); | |
a8f1a052 | 264 | if (use_digest) { |
d4c85f9b | 265 | ret = wait_async_op(&tresult, crypto_ahash_digest(req)); |
a8f1a052 DM |
266 | if (ret) { |
267 | pr_err("alg: hash: digest failed on test %d " | |
268 | "for %s: ret=%d\n", j, algo, -ret); | |
269 | goto out; | |
270 | } | |
271 | } else { | |
d4c85f9b | 272 | ret = wait_async_op(&tresult, crypto_ahash_init(req)); |
a8f1a052 DM |
273 | if (ret) { |
274 | pr_err("alt: hash: init failed on test %d " | |
275 | "for %s: ret=%d\n", j, algo, -ret); | |
276 | goto out; | |
277 | } | |
d4c85f9b | 278 | ret = wait_async_op(&tresult, crypto_ahash_update(req)); |
a8f1a052 DM |
279 | if (ret) { |
280 | pr_err("alt: hash: update failed on test %d " | |
281 | "for %s: ret=%d\n", j, algo, -ret); | |
282 | goto out; | |
283 | } | |
d4c85f9b | 284 | ret = wait_async_op(&tresult, crypto_ahash_final(req)); |
a8f1a052 DM |
285 | if (ret) { |
286 | pr_err("alt: hash: final failed on test %d " | |
287 | "for %s: ret=%d\n", j, algo, -ret); | |
288 | goto out; | |
da7f033d | 289 | } |
da7f033d HX |
290 | } |
291 | ||
292 | if (memcmp(result, template[i].digest, | |
293 | crypto_ahash_digestsize(tfm))) { | |
294 | printk(KERN_ERR "alg: hash: Test %d failed for %s\n", | |
a0cfae59 | 295 | j, algo); |
da7f033d HX |
296 | hexdump(result, crypto_ahash_digestsize(tfm)); |
297 | ret = -EINVAL; | |
298 | goto out; | |
299 | } | |
300 | } | |
301 | ||
302 | j = 0; | |
303 | for (i = 0; i < tcount; i++) { | |
da5ffe11 JK |
304 | /* alignment tests are only done with continuous buffers */ |
305 | if (align_offset != 0) | |
306 | break; | |
307 | ||
5f2b424e CS |
308 | if (!template[i].np) |
309 | continue; | |
da7f033d | 310 | |
5f2b424e CS |
311 | j++; |
312 | memset(result, 0, MAX_DIGEST_SIZE); | |
da7f033d | 313 | |
5f2b424e CS |
314 | temp = 0; |
315 | sg_init_table(sg, template[i].np); | |
316 | ret = -EINVAL; | |
317 | for (k = 0; k < template[i].np; k++) { | |
318 | if (WARN_ON(offset_in_page(IDX[k]) + | |
319 | template[i].tap[k] > PAGE_SIZE)) | |
320 | goto out; | |
321 | sg_set_buf(&sg[k], | |
322 | memcpy(xbuf[IDX[k] >> PAGE_SHIFT] + | |
323 | offset_in_page(IDX[k]), | |
324 | template[i].plaintext + temp, | |
325 | template[i].tap[k]), | |
326 | template[i].tap[k]); | |
327 | temp += template[i].tap[k]; | |
328 | } | |
da7f033d | 329 | |
5f2b424e CS |
330 | if (template[i].ksize) { |
331 | if (template[i].ksize > MAX_KEYLEN) { | |
332 | pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n", | |
333 | j, algo, template[i].ksize, MAX_KEYLEN); | |
334 | ret = -EINVAL; | |
da7f033d HX |
335 | goto out; |
336 | } | |
5f2b424e CS |
337 | crypto_ahash_clear_flags(tfm, ~0); |
338 | memcpy(key, template[i].key, template[i].ksize); | |
339 | ret = crypto_ahash_setkey(tfm, key, template[i].ksize); | |
da7f033d | 340 | |
5f2b424e CS |
341 | if (ret) { |
342 | printk(KERN_ERR "alg: hash: setkey " | |
343 | "failed on chunking test %d " | |
344 | "for %s: ret=%d\n", j, algo, -ret); | |
da7f033d HX |
345 | goto out; |
346 | } | |
347 | } | |
5f2b424e CS |
348 | |
349 | ahash_request_set_crypt(req, sg, result, template[i].psize); | |
350 | ret = crypto_ahash_digest(req); | |
351 | switch (ret) { | |
352 | case 0: | |
353 | break; | |
354 | case -EINPROGRESS: | |
355 | case -EBUSY: | |
8a45ac12 RV |
356 | wait_for_completion(&tresult.completion); |
357 | reinit_completion(&tresult.completion); | |
358 | ret = tresult.err; | |
359 | if (!ret) | |
5f2b424e | 360 | break; |
5f2b424e CS |
361 | /* fall through */ |
362 | default: | |
363 | printk(KERN_ERR "alg: hash: digest failed " | |
364 | "on chunking test %d for %s: " | |
365 | "ret=%d\n", j, algo, -ret); | |
366 | goto out; | |
367 | } | |
368 | ||
369 | if (memcmp(result, template[i].digest, | |
370 | crypto_ahash_digestsize(tfm))) { | |
371 | printk(KERN_ERR "alg: hash: Chunking test %d " | |
372 | "failed for %s\n", j, algo); | |
373 | hexdump(result, crypto_ahash_digestsize(tfm)); | |
374 | ret = -EINVAL; | |
375 | goto out; | |
376 | } | |
da7f033d HX |
377 | } |
378 | ||
379 | ret = 0; | |
380 | ||
381 | out: | |
382 | ahash_request_free(req); | |
383 | out_noreq: | |
f8b0d4d0 HX |
384 | testmgr_free_buf(xbuf); |
385 | out_nobuf: | |
29b77e5d HG |
386 | kfree(key); |
387 | kfree(result); | |
da7f033d HX |
388 | return ret; |
389 | } | |
390 | ||
da5ffe11 JK |
391 | static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, |
392 | unsigned int tcount, bool use_digest) | |
393 | { | |
394 | unsigned int alignmask; | |
395 | int ret; | |
396 | ||
397 | ret = __test_hash(tfm, template, tcount, use_digest, 0); | |
398 | if (ret) | |
399 | return ret; | |
400 | ||
401 | /* test unaligned buffers, check with one byte offset */ | |
402 | ret = __test_hash(tfm, template, tcount, use_digest, 1); | |
403 | if (ret) | |
404 | return ret; | |
405 | ||
406 | alignmask = crypto_tfm_alg_alignmask(&tfm->base); | |
407 | if (alignmask) { | |
408 | /* Check if alignment mask for tfm is correctly set. */ | |
409 | ret = __test_hash(tfm, template, tcount, use_digest, | |
410 | alignmask + 1); | |
411 | if (ret) | |
412 | return ret; | |
413 | } | |
414 | ||
415 | return 0; | |
416 | } | |
417 | ||
d8a32ac2 JK |
418 | static int __test_aead(struct crypto_aead *tfm, int enc, |
419 | struct aead_testvec *template, unsigned int tcount, | |
58dcf548 | 420 | const bool diff_dst, const int align_offset) |
da7f033d HX |
421 | { |
422 | const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)); | |
423 | unsigned int i, j, k, n, temp; | |
f8b0d4d0 | 424 | int ret = -ENOMEM; |
da7f033d HX |
425 | char *q; |
426 | char *key; | |
427 | struct aead_request *req; | |
d8a32ac2 JK |
428 | struct scatterlist *sg; |
429 | struct scatterlist *asg; | |
430 | struct scatterlist *sgout; | |
431 | const char *e, *d; | |
da7f033d | 432 | struct tcrypt_result result; |
424a5da6 | 433 | unsigned int authsize, iv_len; |
da7f033d | 434 | void *input; |
d8a32ac2 | 435 | void *output; |
da7f033d | 436 | void *assoc; |
9bac019d | 437 | char *iv; |
f8b0d4d0 | 438 | char *xbuf[XBUFSIZE]; |
d8a32ac2 | 439 | char *xoutbuf[XBUFSIZE]; |
f8b0d4d0 HX |
440 | char *axbuf[XBUFSIZE]; |
441 | ||
9bac019d TS |
442 | iv = kzalloc(MAX_IVLEN, GFP_KERNEL); |
443 | if (!iv) | |
444 | return ret; | |
29b77e5d HG |
445 | key = kmalloc(MAX_KEYLEN, GFP_KERNEL); |
446 | if (!key) | |
447 | goto out_noxbuf; | |
f8b0d4d0 HX |
448 | if (testmgr_alloc_buf(xbuf)) |
449 | goto out_noxbuf; | |
450 | if (testmgr_alloc_buf(axbuf)) | |
451 | goto out_noaxbuf; | |
d8a32ac2 JK |
452 | if (diff_dst && testmgr_alloc_buf(xoutbuf)) |
453 | goto out_nooutbuf; | |
454 | ||
455 | /* avoid "the frame size is larger than 1024 bytes" compiler warning */ | |
456 | sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL); | |
457 | if (!sg) | |
458 | goto out_nosg; | |
459 | asg = &sg[8]; | |
460 | sgout = &asg[8]; | |
461 | ||
462 | if (diff_dst) | |
463 | d = "-ddst"; | |
464 | else | |
465 | d = ""; | |
466 | ||
da7f033d HX |
467 | if (enc == ENCRYPT) |
468 | e = "encryption"; | |
469 | else | |
470 | e = "decryption"; | |
471 | ||
472 | init_completion(&result.completion); | |
473 | ||
474 | req = aead_request_alloc(tfm, GFP_KERNEL); | |
475 | if (!req) { | |
d8a32ac2 JK |
476 | pr_err("alg: aead%s: Failed to allocate request for %s\n", |
477 | d, algo); | |
da7f033d HX |
478 | goto out; |
479 | } | |
480 | ||
481 | aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, | |
482 | tcrypt_complete, &result); | |
483 | ||
484 | for (i = 0, j = 0; i < tcount; i++) { | |
05b1d338 CS |
485 | if (template[i].np) |
486 | continue; | |
da7f033d | 487 | |
05b1d338 | 488 | j++; |
fd57f22a | 489 | |
05b1d338 CS |
490 | /* some templates have no input data but they will |
491 | * touch input | |
492 | */ | |
493 | input = xbuf[0]; | |
494 | input += align_offset; | |
495 | assoc = axbuf[0]; | |
da7f033d | 496 | |
05b1d338 CS |
497 | ret = -EINVAL; |
498 | if (WARN_ON(align_offset + template[i].ilen > | |
499 | PAGE_SIZE || template[i].alen > PAGE_SIZE)) | |
500 | goto out; | |
da7f033d | 501 | |
05b1d338 CS |
502 | memcpy(input, template[i].input, template[i].ilen); |
503 | memcpy(assoc, template[i].assoc, template[i].alen); | |
424a5da6 | 504 | iv_len = crypto_aead_ivsize(tfm); |
05b1d338 | 505 | if (template[i].iv) |
424a5da6 | 506 | memcpy(iv, template[i].iv, iv_len); |
05b1d338 | 507 | else |
424a5da6 | 508 | memset(iv, 0, iv_len); |
05b1d338 CS |
509 | |
510 | crypto_aead_clear_flags(tfm, ~0); | |
511 | if (template[i].wk) | |
512 | crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); | |
513 | ||
514 | if (template[i].klen > MAX_KEYLEN) { | |
515 | pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n", | |
516 | d, j, algo, template[i].klen, | |
517 | MAX_KEYLEN); | |
518 | ret = -EINVAL; | |
519 | goto out; | |
520 | } | |
521 | memcpy(key, template[i].key, template[i].klen); | |
da7f033d | 522 | |
05b1d338 CS |
523 | ret = crypto_aead_setkey(tfm, key, template[i].klen); |
524 | if (!ret == template[i].fail) { | |
525 | pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n", | |
526 | d, j, algo, crypto_aead_get_flags(tfm)); | |
527 | goto out; | |
528 | } else if (ret) | |
529 | continue; | |
da7f033d | 530 | |
05b1d338 CS |
531 | authsize = abs(template[i].rlen - template[i].ilen); |
532 | ret = crypto_aead_setauthsize(tfm, authsize); | |
533 | if (ret) { | |
534 | pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n", | |
535 | d, authsize, j, algo); | |
536 | goto out; | |
537 | } | |
da7f033d | 538 | |
05b1d338 CS |
539 | if (diff_dst) { |
540 | output = xoutbuf[0]; | |
541 | output += align_offset; | |
542 | sg_init_one(&sg[0], input, template[i].ilen); | |
543 | sg_init_one(&sgout[0], output, template[i].rlen); | |
544 | } else { | |
545 | sg_init_one(&sg[0], input, | |
546 | template[i].ilen + (enc ? authsize : 0)); | |
547 | output = input; | |
548 | } | |
d8a32ac2 | 549 | |
05b1d338 | 550 | sg_init_one(&asg[0], assoc, template[i].alen); |
da7f033d | 551 | |
05b1d338 CS |
552 | aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, |
553 | template[i].ilen, iv); | |
da7f033d | 554 | |
05b1d338 | 555 | aead_request_set_assoc(req, asg, template[i].alen); |
da7f033d | 556 | |
05b1d338 | 557 | ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req); |
da7f033d | 558 | |
05b1d338 CS |
559 | switch (ret) { |
560 | case 0: | |
561 | if (template[i].novrfy) { | |
562 | /* verification was supposed to fail */ | |
563 | pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n", | |
564 | d, e, j, algo); | |
565 | /* so really, we got a bad message */ | |
566 | ret = -EBADMSG; | |
da7f033d HX |
567 | goto out; |
568 | } | |
05b1d338 CS |
569 | break; |
570 | case -EINPROGRESS: | |
571 | case -EBUSY: | |
8a45ac12 RV |
572 | wait_for_completion(&result.completion); |
573 | reinit_completion(&result.completion); | |
574 | ret = result.err; | |
575 | if (!ret) | |
05b1d338 | 576 | break; |
05b1d338 CS |
577 | case -EBADMSG: |
578 | if (template[i].novrfy) | |
579 | /* verification failure was expected */ | |
580 | continue; | |
581 | /* fall through */ | |
582 | default: | |
583 | pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n", | |
584 | d, e, j, algo, -ret); | |
585 | goto out; | |
586 | } | |
587 | ||
588 | q = output; | |
589 | if (memcmp(q, template[i].result, template[i].rlen)) { | |
590 | pr_err("alg: aead%s: Test %d failed on %s for %s\n", | |
591 | d, j, e, algo); | |
592 | hexdump(q, template[i].rlen); | |
593 | ret = -EINVAL; | |
594 | goto out; | |
da7f033d HX |
595 | } |
596 | } | |
597 | ||
598 | for (i = 0, j = 0; i < tcount; i++) { | |
58dcf548 JK |
599 | /* alignment tests are only done with continuous buffers */ |
600 | if (align_offset != 0) | |
601 | break; | |
602 | ||
05b1d338 CS |
603 | if (!template[i].np) |
604 | continue; | |
da7f033d | 605 | |
05b1d338 | 606 | j++; |
da7f033d | 607 | |
05b1d338 CS |
608 | if (template[i].iv) |
609 | memcpy(iv, template[i].iv, MAX_IVLEN); | |
610 | else | |
611 | memset(iv, 0, MAX_IVLEN); | |
612 | ||
613 | crypto_aead_clear_flags(tfm, ~0); | |
614 | if (template[i].wk) | |
615 | crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); | |
616 | if (template[i].klen > MAX_KEYLEN) { | |
617 | pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n", | |
618 | d, j, algo, template[i].klen, MAX_KEYLEN); | |
619 | ret = -EINVAL; | |
620 | goto out; | |
621 | } | |
622 | memcpy(key, template[i].key, template[i].klen); | |
da7f033d | 623 | |
05b1d338 CS |
624 | ret = crypto_aead_setkey(tfm, key, template[i].klen); |
625 | if (!ret == template[i].fail) { | |
626 | pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n", | |
627 | d, j, algo, crypto_aead_get_flags(tfm)); | |
628 | goto out; | |
629 | } else if (ret) | |
630 | continue; | |
da7f033d | 631 | |
05b1d338 | 632 | authsize = abs(template[i].rlen - template[i].ilen); |
da7f033d | 633 | |
05b1d338 CS |
634 | ret = -EINVAL; |
635 | sg_init_table(sg, template[i].np); | |
636 | if (diff_dst) | |
637 | sg_init_table(sgout, template[i].np); | |
638 | for (k = 0, temp = 0; k < template[i].np; k++) { | |
639 | if (WARN_ON(offset_in_page(IDX[k]) + | |
640 | template[i].tap[k] > PAGE_SIZE)) | |
641 | goto out; | |
da7f033d | 642 | |
05b1d338 CS |
643 | q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]); |
644 | memcpy(q, template[i].input + temp, template[i].tap[k]); | |
645 | sg_set_buf(&sg[k], q, template[i].tap[k]); | |
da7f033d | 646 | |
05b1d338 CS |
647 | if (diff_dst) { |
648 | q = xoutbuf[IDX[k] >> PAGE_SHIFT] + | |
649 | offset_in_page(IDX[k]); | |
d8a32ac2 | 650 | |
05b1d338 | 651 | memset(q, 0, template[i].tap[k]); |
d8a32ac2 | 652 | |
05b1d338 CS |
653 | sg_set_buf(&sgout[k], q, template[i].tap[k]); |
654 | } | |
d8a32ac2 | 655 | |
05b1d338 CS |
656 | n = template[i].tap[k]; |
657 | if (k == template[i].np - 1 && enc) | |
658 | n += authsize; | |
659 | if (offset_in_page(q) + n < PAGE_SIZE) | |
660 | q[n] = 0; | |
d8a32ac2 | 661 | |
05b1d338 CS |
662 | temp += template[i].tap[k]; |
663 | } | |
8ec25c51 | 664 | |
05b1d338 CS |
665 | ret = crypto_aead_setauthsize(tfm, authsize); |
666 | if (ret) { | |
667 | pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n", | |
668 | d, authsize, j, algo); | |
669 | goto out; | |
670 | } | |
da7f033d | 671 | |
05b1d338 CS |
672 | if (enc) { |
673 | if (WARN_ON(sg[k - 1].offset + | |
674 | sg[k - 1].length + authsize > | |
675 | PAGE_SIZE)) { | |
676 | ret = -EINVAL; | |
da7f033d HX |
677 | goto out; |
678 | } | |
679 | ||
05b1d338 CS |
680 | if (diff_dst) |
681 | sgout[k - 1].length += authsize; | |
682 | else | |
683 | sg[k - 1].length += authsize; | |
684 | } | |
da7f033d | 685 | |
05b1d338 CS |
686 | sg_init_table(asg, template[i].anp); |
687 | ret = -EINVAL; | |
688 | for (k = 0, temp = 0; k < template[i].anp; k++) { | |
689 | if (WARN_ON(offset_in_page(IDX[k]) + | |
690 | template[i].atap[k] > PAGE_SIZE)) | |
691 | goto out; | |
692 | sg_set_buf(&asg[k], | |
693 | memcpy(axbuf[IDX[k] >> PAGE_SHIFT] + | |
694 | offset_in_page(IDX[k]), | |
695 | template[i].assoc + temp, | |
696 | template[i].atap[k]), | |
697 | template[i].atap[k]); | |
698 | temp += template[i].atap[k]; | |
699 | } | |
da7f033d | 700 | |
05b1d338 CS |
701 | aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, |
702 | template[i].ilen, | |
703 | iv); | |
da7f033d | 704 | |
05b1d338 | 705 | aead_request_set_assoc(req, asg, template[i].alen); |
da7f033d | 706 | |
05b1d338 | 707 | ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req); |
da7f033d | 708 | |
05b1d338 CS |
709 | switch (ret) { |
710 | case 0: | |
711 | if (template[i].novrfy) { | |
712 | /* verification was supposed to fail */ | |
713 | pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n", | |
714 | d, e, j, algo); | |
715 | /* so really, we got a bad message */ | |
716 | ret = -EBADMSG; | |
da7f033d HX |
717 | goto out; |
718 | } | |
05b1d338 CS |
719 | break; |
720 | case -EINPROGRESS: | |
721 | case -EBUSY: | |
8a45ac12 RV |
722 | wait_for_completion(&result.completion); |
723 | reinit_completion(&result.completion); | |
724 | ret = result.err; | |
725 | if (!ret) | |
05b1d338 | 726 | break; |
05b1d338 CS |
727 | case -EBADMSG: |
728 | if (template[i].novrfy) | |
729 | /* verification failure was expected */ | |
730 | continue; | |
731 | /* fall through */ | |
732 | default: | |
733 | pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n", | |
734 | d, e, j, algo, -ret); | |
735 | goto out; | |
736 | } | |
da7f033d | 737 | |
05b1d338 CS |
738 | ret = -EINVAL; |
739 | for (k = 0, temp = 0; k < template[i].np; k++) { | |
740 | if (diff_dst) | |
741 | q = xoutbuf[IDX[k] >> PAGE_SHIFT] + | |
742 | offset_in_page(IDX[k]); | |
743 | else | |
744 | q = xbuf[IDX[k] >> PAGE_SHIFT] + | |
745 | offset_in_page(IDX[k]); | |
da7f033d | 746 | |
05b1d338 CS |
747 | n = template[i].tap[k]; |
748 | if (k == template[i].np - 1) | |
749 | n += enc ? authsize : -authsize; | |
da7f033d | 750 | |
05b1d338 CS |
751 | if (memcmp(q, template[i].result + temp, n)) { |
752 | pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n", | |
753 | d, j, e, k, algo); | |
754 | hexdump(q, n); | |
755 | goto out; | |
756 | } | |
da7f033d | 757 | |
05b1d338 CS |
758 | q += n; |
759 | if (k == template[i].np - 1 && !enc) { | |
760 | if (!diff_dst && | |
761 | memcmp(q, template[i].input + | |
762 | temp + n, authsize)) | |
763 | n = authsize; | |
764 | else | |
765 | n = 0; | |
766 | } else { | |
767 | for (n = 0; offset_in_page(q + n) && q[n]; n++) | |
768 | ; | |
769 | } | |
770 | if (n) { | |
771 | pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n", | |
772 | d, j, e, k, algo, n); | |
773 | hexdump(q, n); | |
774 | goto out; | |
da7f033d | 775 | } |
05b1d338 CS |
776 | |
777 | temp += template[i].tap[k]; | |
da7f033d HX |
778 | } |
779 | } | |
780 | ||
781 | ret = 0; | |
782 | ||
783 | out: | |
784 | aead_request_free(req); | |
d8a32ac2 JK |
785 | kfree(sg); |
786 | out_nosg: | |
787 | if (diff_dst) | |
788 | testmgr_free_buf(xoutbuf); | |
789 | out_nooutbuf: | |
f8b0d4d0 HX |
790 | testmgr_free_buf(axbuf); |
791 | out_noaxbuf: | |
792 | testmgr_free_buf(xbuf); | |
793 | out_noxbuf: | |
29b77e5d | 794 | kfree(key); |
9bac019d | 795 | kfree(iv); |
da7f033d HX |
796 | return ret; |
797 | } | |
798 | ||
d8a32ac2 JK |
799 | static int test_aead(struct crypto_aead *tfm, int enc, |
800 | struct aead_testvec *template, unsigned int tcount) | |
801 | { | |
58dcf548 | 802 | unsigned int alignmask; |
d8a32ac2 JK |
803 | int ret; |
804 | ||
805 | /* test 'dst == src' case */ | |
58dcf548 | 806 | ret = __test_aead(tfm, enc, template, tcount, false, 0); |
d8a32ac2 JK |
807 | if (ret) |
808 | return ret; | |
809 | ||
810 | /* test 'dst != src' case */ | |
58dcf548 JK |
811 | ret = __test_aead(tfm, enc, template, tcount, true, 0); |
812 | if (ret) | |
813 | return ret; | |
814 | ||
815 | /* test unaligned buffers, check with one byte offset */ | |
816 | ret = __test_aead(tfm, enc, template, tcount, true, 1); | |
817 | if (ret) | |
818 | return ret; | |
819 | ||
820 | alignmask = crypto_tfm_alg_alignmask(&tfm->base); | |
821 | if (alignmask) { | |
822 | /* Check if alignment mask for tfm is correctly set. */ | |
823 | ret = __test_aead(tfm, enc, template, tcount, true, | |
824 | alignmask + 1); | |
825 | if (ret) | |
826 | return ret; | |
827 | } | |
828 | ||
829 | return 0; | |
d8a32ac2 JK |
830 | } |
831 | ||
1aa4ecd9 | 832 | static int test_cipher(struct crypto_cipher *tfm, int enc, |
da7f033d | 833 | struct cipher_testvec *template, unsigned int tcount) |
1aa4ecd9 HX |
834 | { |
835 | const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm)); | |
836 | unsigned int i, j, k; | |
1aa4ecd9 HX |
837 | char *q; |
838 | const char *e; | |
839 | void *data; | |
f8b0d4d0 HX |
840 | char *xbuf[XBUFSIZE]; |
841 | int ret = -ENOMEM; | |
842 | ||
843 | if (testmgr_alloc_buf(xbuf)) | |
844 | goto out_nobuf; | |
1aa4ecd9 HX |
845 | |
846 | if (enc == ENCRYPT) | |
847 | e = "encryption"; | |
848 | else | |
849 | e = "decryption"; | |
850 | ||
851 | j = 0; | |
852 | for (i = 0; i < tcount; i++) { | |
853 | if (template[i].np) | |
854 | continue; | |
855 | ||
856 | j++; | |
857 | ||
fd57f22a HX |
858 | ret = -EINVAL; |
859 | if (WARN_ON(template[i].ilen > PAGE_SIZE)) | |
860 | goto out; | |
861 | ||
1aa4ecd9 HX |
862 | data = xbuf[0]; |
863 | memcpy(data, template[i].input, template[i].ilen); | |
864 | ||
865 | crypto_cipher_clear_flags(tfm, ~0); | |
866 | if (template[i].wk) | |
867 | crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); | |
868 | ||
869 | ret = crypto_cipher_setkey(tfm, template[i].key, | |
870 | template[i].klen); | |
871 | if (!ret == template[i].fail) { | |
872 | printk(KERN_ERR "alg: cipher: setkey failed " | |
873 | "on test %d for %s: flags=%x\n", j, | |
874 | algo, crypto_cipher_get_flags(tfm)); | |
875 | goto out; | |
876 | } else if (ret) | |
877 | continue; | |
878 | ||
879 | for (k = 0; k < template[i].ilen; | |
880 | k += crypto_cipher_blocksize(tfm)) { | |
881 | if (enc) | |
882 | crypto_cipher_encrypt_one(tfm, data + k, | |
883 | data + k); | |
884 | else | |
885 | crypto_cipher_decrypt_one(tfm, data + k, | |
886 | data + k); | |
887 | } | |
888 | ||
889 | q = data; | |
890 | if (memcmp(q, template[i].result, template[i].rlen)) { | |
891 | printk(KERN_ERR "alg: cipher: Test %d failed " | |
892 | "on %s for %s\n", j, e, algo); | |
893 | hexdump(q, template[i].rlen); | |
894 | ret = -EINVAL; | |
895 | goto out; | |
896 | } | |
897 | } | |
898 | ||
899 | ret = 0; | |
900 | ||
901 | out: | |
f8b0d4d0 HX |
902 | testmgr_free_buf(xbuf); |
903 | out_nobuf: | |
1aa4ecd9 HX |
904 | return ret; |
905 | } | |
906 | ||
08d6af8c JK |
907 | static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc, |
908 | struct cipher_testvec *template, unsigned int tcount, | |
3a338f20 | 909 | const bool diff_dst, const int align_offset) |
da7f033d HX |
910 | { |
911 | const char *algo = | |
912 | crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm)); | |
913 | unsigned int i, j, k, n, temp; | |
da7f033d HX |
914 | char *q; |
915 | struct ablkcipher_request *req; | |
916 | struct scatterlist sg[8]; | |
08d6af8c JK |
917 | struct scatterlist sgout[8]; |
918 | const char *e, *d; | |
da7f033d HX |
919 | struct tcrypt_result result; |
920 | void *data; | |
921 | char iv[MAX_IVLEN]; | |
f8b0d4d0 | 922 | char *xbuf[XBUFSIZE]; |
08d6af8c | 923 | char *xoutbuf[XBUFSIZE]; |
f8b0d4d0 HX |
924 | int ret = -ENOMEM; |
925 | ||
926 | if (testmgr_alloc_buf(xbuf)) | |
927 | goto out_nobuf; | |
da7f033d | 928 | |
08d6af8c JK |
929 | if (diff_dst && testmgr_alloc_buf(xoutbuf)) |
930 | goto out_nooutbuf; | |
931 | ||
932 | if (diff_dst) | |
933 | d = "-ddst"; | |
934 | else | |
935 | d = ""; | |
936 | ||
da7f033d HX |
937 | if (enc == ENCRYPT) |
938 | e = "encryption"; | |
939 | else | |
940 | e = "decryption"; | |
941 | ||
942 | init_completion(&result.completion); | |
943 | ||
944 | req = ablkcipher_request_alloc(tfm, GFP_KERNEL); | |
945 | if (!req) { | |
08d6af8c JK |
946 | pr_err("alg: skcipher%s: Failed to allocate request for %s\n", |
947 | d, algo); | |
da7f033d HX |
948 | goto out; |
949 | } | |
950 | ||
951 | ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, | |
952 | tcrypt_complete, &result); | |
953 | ||
954 | j = 0; | |
955 | for (i = 0; i < tcount; i++) { | |
bbb9a7dd CS |
956 | if (template[i].np && !template[i].also_non_np) |
957 | continue; | |
958 | ||
da7f033d HX |
959 | if (template[i].iv) |
960 | memcpy(iv, template[i].iv, MAX_IVLEN); | |
961 | else | |
962 | memset(iv, 0, MAX_IVLEN); | |
963 | ||
a1aa44a2 | 964 | j++; |
a1aa44a2 CS |
965 | ret = -EINVAL; |
966 | if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE)) | |
967 | goto out; | |
da7f033d | 968 | |
a1aa44a2 CS |
969 | data = xbuf[0]; |
970 | data += align_offset; | |
971 | memcpy(data, template[i].input, template[i].ilen); | |
972 | ||
973 | crypto_ablkcipher_clear_flags(tfm, ~0); | |
974 | if (template[i].wk) | |
975 | crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); | |
da7f033d | 976 | |
a1aa44a2 CS |
977 | ret = crypto_ablkcipher_setkey(tfm, template[i].key, |
978 | template[i].klen); | |
979 | if (!ret == template[i].fail) { | |
980 | pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n", | |
981 | d, j, algo, crypto_ablkcipher_get_flags(tfm)); | |
982 | goto out; | |
983 | } else if (ret) | |
984 | continue; | |
985 | ||
986 | sg_init_one(&sg[0], data, template[i].ilen); | |
987 | if (diff_dst) { | |
988 | data = xoutbuf[0]; | |
989 | data += align_offset; | |
990 | sg_init_one(&sgout[0], data, template[i].ilen); | |
991 | } | |
da7f033d | 992 | |
a1aa44a2 CS |
993 | ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, |
994 | template[i].ilen, iv); | |
995 | ret = enc ? crypto_ablkcipher_encrypt(req) : | |
996 | crypto_ablkcipher_decrypt(req); | |
997 | ||
998 | switch (ret) { | |
999 | case 0: | |
1000 | break; | |
1001 | case -EINPROGRESS: | |
1002 | case -EBUSY: | |
8a45ac12 RV |
1003 | wait_for_completion(&result.completion); |
1004 | reinit_completion(&result.completion); | |
1005 | ret = result.err; | |
1006 | if (!ret) | |
da7f033d | 1007 | break; |
a1aa44a2 CS |
1008 | /* fall through */ |
1009 | default: | |
1010 | pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n", | |
1011 | d, e, j, algo, -ret); | |
1012 | goto out; | |
1013 | } | |
da7f033d | 1014 | |
a1aa44a2 CS |
1015 | q = data; |
1016 | if (memcmp(q, template[i].result, template[i].rlen)) { | |
1017 | pr_err("alg: skcipher%s: Test %d failed on %s for %s\n", | |
1018 | d, j, e, algo); | |
1019 | hexdump(q, template[i].rlen); | |
1020 | ret = -EINVAL; | |
1021 | goto out; | |
da7f033d HX |
1022 | } |
1023 | } | |
1024 | ||
1025 | j = 0; | |
1026 | for (i = 0; i < tcount; i++) { | |
3a338f20 JK |
1027 | /* alignment tests are only done with continuous buffers */ |
1028 | if (align_offset != 0) | |
1029 | break; | |
da7f033d | 1030 | |
bbb9a7dd CS |
1031 | if (!template[i].np) |
1032 | continue; | |
1033 | ||
da7f033d HX |
1034 | if (template[i].iv) |
1035 | memcpy(iv, template[i].iv, MAX_IVLEN); | |
1036 | else | |
1037 | memset(iv, 0, MAX_IVLEN); | |
1038 | ||
a1aa44a2 | 1039 | j++; |
a1aa44a2 CS |
1040 | crypto_ablkcipher_clear_flags(tfm, ~0); |
1041 | if (template[i].wk) | |
1042 | crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); | |
da7f033d | 1043 | |
a1aa44a2 CS |
1044 | ret = crypto_ablkcipher_setkey(tfm, template[i].key, |
1045 | template[i].klen); | |
1046 | if (!ret == template[i].fail) { | |
1047 | pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n", | |
1048 | d, j, algo, crypto_ablkcipher_get_flags(tfm)); | |
1049 | goto out; | |
1050 | } else if (ret) | |
1051 | continue; | |
da7f033d | 1052 | |
a1aa44a2 CS |
1053 | temp = 0; |
1054 | ret = -EINVAL; | |
1055 | sg_init_table(sg, template[i].np); | |
1056 | if (diff_dst) | |
1057 | sg_init_table(sgout, template[i].np); | |
1058 | for (k = 0; k < template[i].np; k++) { | |
1059 | if (WARN_ON(offset_in_page(IDX[k]) + | |
1060 | template[i].tap[k] > PAGE_SIZE)) | |
da7f033d | 1061 | goto out; |
da7f033d | 1062 | |
a1aa44a2 | 1063 | q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]); |
da7f033d | 1064 | |
a1aa44a2 CS |
1065 | memcpy(q, template[i].input + temp, template[i].tap[k]); |
1066 | ||
1067 | if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE) | |
1068 | q[template[i].tap[k]] = 0; | |
1069 | ||
1070 | sg_set_buf(&sg[k], q, template[i].tap[k]); | |
1071 | if (diff_dst) { | |
1072 | q = xoutbuf[IDX[k] >> PAGE_SHIFT] + | |
da7f033d HX |
1073 | offset_in_page(IDX[k]); |
1074 | ||
a1aa44a2 | 1075 | sg_set_buf(&sgout[k], q, template[i].tap[k]); |
da7f033d | 1076 | |
a1aa44a2 CS |
1077 | memset(q, 0, template[i].tap[k]); |
1078 | if (offset_in_page(q) + | |
1079 | template[i].tap[k] < PAGE_SIZE) | |
da7f033d | 1080 | q[template[i].tap[k]] = 0; |
a1aa44a2 | 1081 | } |
da7f033d | 1082 | |
a1aa44a2 CS |
1083 | temp += template[i].tap[k]; |
1084 | } | |
08d6af8c | 1085 | |
a1aa44a2 CS |
1086 | ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, |
1087 | template[i].ilen, iv); | |
08d6af8c | 1088 | |
a1aa44a2 CS |
1089 | ret = enc ? crypto_ablkcipher_encrypt(req) : |
1090 | crypto_ablkcipher_decrypt(req); | |
da7f033d | 1091 | |
a1aa44a2 CS |
1092 | switch (ret) { |
1093 | case 0: | |
1094 | break; | |
1095 | case -EINPROGRESS: | |
1096 | case -EBUSY: | |
8a45ac12 RV |
1097 | wait_for_completion(&result.completion); |
1098 | reinit_completion(&result.completion); | |
1099 | ret = result.err; | |
1100 | if (!ret) | |
a1aa44a2 | 1101 | break; |
a1aa44a2 CS |
1102 | /* fall through */ |
1103 | default: | |
1104 | pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n", | |
1105 | d, e, j, algo, -ret); | |
1106 | goto out; | |
1107 | } | |
da7f033d | 1108 | |
a1aa44a2 CS |
1109 | temp = 0; |
1110 | ret = -EINVAL; | |
1111 | for (k = 0; k < template[i].np; k++) { | |
1112 | if (diff_dst) | |
1113 | q = xoutbuf[IDX[k] >> PAGE_SHIFT] + | |
1114 | offset_in_page(IDX[k]); | |
1115 | else | |
1116 | q = xbuf[IDX[k] >> PAGE_SHIFT] + | |
1117 | offset_in_page(IDX[k]); | |
da7f033d | 1118 | |
a1aa44a2 CS |
1119 | if (memcmp(q, template[i].result + temp, |
1120 | template[i].tap[k])) { | |
1121 | pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n", | |
1122 | d, j, e, k, algo); | |
1123 | hexdump(q, template[i].tap[k]); | |
da7f033d HX |
1124 | goto out; |
1125 | } | |
1126 | ||
a1aa44a2 CS |
1127 | q += template[i].tap[k]; |
1128 | for (n = 0; offset_in_page(q + n) && q[n]; n++) | |
1129 | ; | |
1130 | if (n) { | |
1131 | pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n", | |
1132 | d, j, e, k, algo, n); | |
1133 | hexdump(q, n); | |
1134 | goto out; | |
da7f033d | 1135 | } |
a1aa44a2 | 1136 | temp += template[i].tap[k]; |
da7f033d HX |
1137 | } |
1138 | } | |
1139 | ||
1140 | ret = 0; | |
1141 | ||
1142 | out: | |
1143 | ablkcipher_request_free(req); | |
08d6af8c JK |
1144 | if (diff_dst) |
1145 | testmgr_free_buf(xoutbuf); | |
1146 | out_nooutbuf: | |
f8b0d4d0 HX |
1147 | testmgr_free_buf(xbuf); |
1148 | out_nobuf: | |
da7f033d HX |
1149 | return ret; |
1150 | } | |
1151 | ||
08d6af8c JK |
1152 | static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, |
1153 | struct cipher_testvec *template, unsigned int tcount) | |
1154 | { | |
3a338f20 | 1155 | unsigned int alignmask; |
08d6af8c JK |
1156 | int ret; |
1157 | ||
1158 | /* test 'dst == src' case */ | |
3a338f20 | 1159 | ret = __test_skcipher(tfm, enc, template, tcount, false, 0); |
08d6af8c JK |
1160 | if (ret) |
1161 | return ret; | |
1162 | ||
1163 | /* test 'dst != src' case */ | |
3a338f20 JK |
1164 | ret = __test_skcipher(tfm, enc, template, tcount, true, 0); |
1165 | if (ret) | |
1166 | return ret; | |
1167 | ||
1168 | /* test unaligned buffers, check with one byte offset */ | |
1169 | ret = __test_skcipher(tfm, enc, template, tcount, true, 1); | |
1170 | if (ret) | |
1171 | return ret; | |
1172 | ||
1173 | alignmask = crypto_tfm_alg_alignmask(&tfm->base); | |
1174 | if (alignmask) { | |
1175 | /* Check if alignment mask for tfm is correctly set. */ | |
1176 | ret = __test_skcipher(tfm, enc, template, tcount, true, | |
1177 | alignmask + 1); | |
1178 | if (ret) | |
1179 | return ret; | |
1180 | } | |
1181 | ||
1182 | return 0; | |
08d6af8c JK |
1183 | } |
1184 | ||
da7f033d HX |
1185 | static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, |
1186 | struct comp_testvec *dtemplate, int ctcount, int dtcount) | |
1187 | { | |
1188 | const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm)); | |
1189 | unsigned int i; | |
1190 | char result[COMP_BUF_SIZE]; | |
1191 | int ret; | |
1192 | ||
1193 | for (i = 0; i < ctcount; i++) { | |
c79cf910 GU |
1194 | int ilen; |
1195 | unsigned int dlen = COMP_BUF_SIZE; | |
da7f033d HX |
1196 | |
1197 | memset(result, 0, sizeof (result)); | |
1198 | ||
1199 | ilen = ctemplate[i].inlen; | |
1200 | ret = crypto_comp_compress(tfm, ctemplate[i].input, | |
1201 | ilen, result, &dlen); | |
1202 | if (ret) { | |
1203 | printk(KERN_ERR "alg: comp: compression failed " | |
1204 | "on test %d for %s: ret=%d\n", i + 1, algo, | |
1205 | -ret); | |
1206 | goto out; | |
1207 | } | |
1208 | ||
b812eb00 GU |
1209 | if (dlen != ctemplate[i].outlen) { |
1210 | printk(KERN_ERR "alg: comp: Compression test %d " | |
1211 | "failed for %s: output len = %d\n", i + 1, algo, | |
1212 | dlen); | |
1213 | ret = -EINVAL; | |
1214 | goto out; | |
1215 | } | |
1216 | ||
da7f033d HX |
1217 | if (memcmp(result, ctemplate[i].output, dlen)) { |
1218 | printk(KERN_ERR "alg: comp: Compression test %d " | |
1219 | "failed for %s\n", i + 1, algo); | |
1220 | hexdump(result, dlen); | |
1221 | ret = -EINVAL; | |
1222 | goto out; | |
1223 | } | |
1224 | } | |
1225 | ||
1226 | for (i = 0; i < dtcount; i++) { | |
c79cf910 GU |
1227 | int ilen; |
1228 | unsigned int dlen = COMP_BUF_SIZE; | |
da7f033d HX |
1229 | |
1230 | memset(result, 0, sizeof (result)); | |
1231 | ||
1232 | ilen = dtemplate[i].inlen; | |
1233 | ret = crypto_comp_decompress(tfm, dtemplate[i].input, | |
1234 | ilen, result, &dlen); | |
1235 | if (ret) { | |
1236 | printk(KERN_ERR "alg: comp: decompression failed " | |
1237 | "on test %d for %s: ret=%d\n", i + 1, algo, | |
1238 | -ret); | |
1239 | goto out; | |
1240 | } | |
1241 | ||
b812eb00 GU |
1242 | if (dlen != dtemplate[i].outlen) { |
1243 | printk(KERN_ERR "alg: comp: Decompression test %d " | |
1244 | "failed for %s: output len = %d\n", i + 1, algo, | |
1245 | dlen); | |
1246 | ret = -EINVAL; | |
1247 | goto out; | |
1248 | } | |
1249 | ||
da7f033d HX |
1250 | if (memcmp(result, dtemplate[i].output, dlen)) { |
1251 | printk(KERN_ERR "alg: comp: Decompression test %d " | |
1252 | "failed for %s\n", i + 1, algo); | |
1253 | hexdump(result, dlen); | |
1254 | ret = -EINVAL; | |
1255 | goto out; | |
1256 | } | |
1257 | } | |
1258 | ||
1259 | ret = 0; | |
1260 | ||
1261 | out: | |
1262 | return ret; | |
1263 | } | |
1264 | ||
8064efb8 GU |
1265 | static int test_pcomp(struct crypto_pcomp *tfm, |
1266 | struct pcomp_testvec *ctemplate, | |
1267 | struct pcomp_testvec *dtemplate, int ctcount, | |
1268 | int dtcount) | |
1269 | { | |
1270 | const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm)); | |
1271 | unsigned int i; | |
1272 | char result[COMP_BUF_SIZE]; | |
3ce858cb | 1273 | int res; |
8064efb8 GU |
1274 | |
1275 | for (i = 0; i < ctcount; i++) { | |
1276 | struct comp_request req; | |
3ce858cb | 1277 | unsigned int produced = 0; |
8064efb8 | 1278 | |
3ce858cb GU |
1279 | res = crypto_compress_setup(tfm, ctemplate[i].params, |
1280 | ctemplate[i].paramsize); | |
1281 | if (res) { | |
8064efb8 | 1282 | pr_err("alg: pcomp: compression setup failed on test " |
3ce858cb GU |
1283 | "%d for %s: error=%d\n", i + 1, algo, res); |
1284 | return res; | |
8064efb8 GU |
1285 | } |
1286 | ||
3ce858cb GU |
1287 | res = crypto_compress_init(tfm); |
1288 | if (res) { | |
8064efb8 | 1289 | pr_err("alg: pcomp: compression init failed on test " |
3ce858cb GU |
1290 | "%d for %s: error=%d\n", i + 1, algo, res); |
1291 | return res; | |
8064efb8 GU |
1292 | } |
1293 | ||
1294 | memset(result, 0, sizeof(result)); | |
1295 | ||
1296 | req.next_in = ctemplate[i].input; | |
1297 | req.avail_in = ctemplate[i].inlen / 2; | |
1298 | req.next_out = result; | |
1299 | req.avail_out = ctemplate[i].outlen / 2; | |
1300 | ||
3ce858cb GU |
1301 | res = crypto_compress_update(tfm, &req); |
1302 | if (res < 0 && (res != -EAGAIN || req.avail_in)) { | |
8064efb8 | 1303 | pr_err("alg: pcomp: compression update failed on test " |
3ce858cb GU |
1304 | "%d for %s: error=%d\n", i + 1, algo, res); |
1305 | return res; | |
8064efb8 | 1306 | } |
3ce858cb GU |
1307 | if (res > 0) |
1308 | produced += res; | |
8064efb8 GU |
1309 | |
1310 | /* Add remaining input data */ | |
1311 | req.avail_in += (ctemplate[i].inlen + 1) / 2; | |
1312 | ||
3ce858cb GU |
1313 | res = crypto_compress_update(tfm, &req); |
1314 | if (res < 0 && (res != -EAGAIN || req.avail_in)) { | |
8064efb8 | 1315 | pr_err("alg: pcomp: compression update failed on test " |
3ce858cb GU |
1316 | "%d for %s: error=%d\n", i + 1, algo, res); |
1317 | return res; | |
8064efb8 | 1318 | } |
3ce858cb GU |
1319 | if (res > 0) |
1320 | produced += res; | |
8064efb8 GU |
1321 | |
1322 | /* Provide remaining output space */ | |
1323 | req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2; | |
1324 | ||
3ce858cb GU |
1325 | res = crypto_compress_final(tfm, &req); |
1326 | if (res < 0) { | |
8064efb8 | 1327 | pr_err("alg: pcomp: compression final failed on test " |
3ce858cb GU |
1328 | "%d for %s: error=%d\n", i + 1, algo, res); |
1329 | return res; | |
8064efb8 | 1330 | } |
3ce858cb | 1331 | produced += res; |
8064efb8 GU |
1332 | |
1333 | if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) { | |
1334 | pr_err("alg: comp: Compression test %d failed for %s: " | |
1335 | "output len = %d (expected %d)\n", i + 1, algo, | |
1336 | COMP_BUF_SIZE - req.avail_out, | |
1337 | ctemplate[i].outlen); | |
1338 | return -EINVAL; | |
1339 | } | |
1340 | ||
3ce858cb GU |
1341 | if (produced != ctemplate[i].outlen) { |
1342 | pr_err("alg: comp: Compression test %d failed for %s: " | |
1343 | "returned len = %u (expected %d)\n", i + 1, | |
1344 | algo, produced, ctemplate[i].outlen); | |
1345 | return -EINVAL; | |
1346 | } | |
1347 | ||
8064efb8 GU |
1348 | if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) { |
1349 | pr_err("alg: pcomp: Compression test %d failed for " | |
1350 | "%s\n", i + 1, algo); | |
1351 | hexdump(result, ctemplate[i].outlen); | |
1352 | return -EINVAL; | |
1353 | } | |
1354 | } | |
1355 | ||
1356 | for (i = 0; i < dtcount; i++) { | |
1357 | struct comp_request req; | |
3ce858cb | 1358 | unsigned int produced = 0; |
8064efb8 | 1359 | |
3ce858cb GU |
1360 | res = crypto_decompress_setup(tfm, dtemplate[i].params, |
1361 | dtemplate[i].paramsize); | |
1362 | if (res) { | |
8064efb8 | 1363 | pr_err("alg: pcomp: decompression setup failed on " |
3ce858cb GU |
1364 | "test %d for %s: error=%d\n", i + 1, algo, res); |
1365 | return res; | |
8064efb8 GU |
1366 | } |
1367 | ||
3ce858cb GU |
1368 | res = crypto_decompress_init(tfm); |
1369 | if (res) { | |
8064efb8 | 1370 | pr_err("alg: pcomp: decompression init failed on test " |
3ce858cb GU |
1371 | "%d for %s: error=%d\n", i + 1, algo, res); |
1372 | return res; | |
8064efb8 GU |
1373 | } |
1374 | ||
1375 | memset(result, 0, sizeof(result)); | |
1376 | ||
1377 | req.next_in = dtemplate[i].input; | |
1378 | req.avail_in = dtemplate[i].inlen / 2; | |
1379 | req.next_out = result; | |
1380 | req.avail_out = dtemplate[i].outlen / 2; | |
1381 | ||
3ce858cb GU |
1382 | res = crypto_decompress_update(tfm, &req); |
1383 | if (res < 0 && (res != -EAGAIN || req.avail_in)) { | |
8064efb8 | 1384 | pr_err("alg: pcomp: decompression update failed on " |
3ce858cb GU |
1385 | "test %d for %s: error=%d\n", i + 1, algo, res); |
1386 | return res; | |
8064efb8 | 1387 | } |
3ce858cb GU |
1388 | if (res > 0) |
1389 | produced += res; | |
8064efb8 GU |
1390 | |
1391 | /* Add remaining input data */ | |
1392 | req.avail_in += (dtemplate[i].inlen + 1) / 2; | |
1393 | ||
3ce858cb GU |
1394 | res = crypto_decompress_update(tfm, &req); |
1395 | if (res < 0 && (res != -EAGAIN || req.avail_in)) { | |
8064efb8 | 1396 | pr_err("alg: pcomp: decompression update failed on " |
3ce858cb GU |
1397 | "test %d for %s: error=%d\n", i + 1, algo, res); |
1398 | return res; | |
8064efb8 | 1399 | } |
3ce858cb GU |
1400 | if (res > 0) |
1401 | produced += res; | |
8064efb8 GU |
1402 | |
1403 | /* Provide remaining output space */ | |
1404 | req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2; | |
1405 | ||
3ce858cb GU |
1406 | res = crypto_decompress_final(tfm, &req); |
1407 | if (res < 0 && (res != -EAGAIN || req.avail_in)) { | |
8064efb8 | 1408 | pr_err("alg: pcomp: decompression final failed on " |
3ce858cb GU |
1409 | "test %d for %s: error=%d\n", i + 1, algo, res); |
1410 | return res; | |
8064efb8 | 1411 | } |
3ce858cb GU |
1412 | if (res > 0) |
1413 | produced += res; | |
8064efb8 GU |
1414 | |
1415 | if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) { | |
1416 | pr_err("alg: comp: Decompression test %d failed for " | |
1417 | "%s: output len = %d (expected %d)\n", i + 1, | |
1418 | algo, COMP_BUF_SIZE - req.avail_out, | |
1419 | dtemplate[i].outlen); | |
1420 | return -EINVAL; | |
1421 | } | |
1422 | ||
3ce858cb GU |
1423 | if (produced != dtemplate[i].outlen) { |
1424 | pr_err("alg: comp: Decompression test %d failed for " | |
1425 | "%s: returned len = %u (expected %d)\n", i + 1, | |
1426 | algo, produced, dtemplate[i].outlen); | |
1427 | return -EINVAL; | |
1428 | } | |
1429 | ||
8064efb8 GU |
1430 | if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) { |
1431 | pr_err("alg: pcomp: Decompression test %d failed for " | |
1432 | "%s\n", i + 1, algo); | |
1433 | hexdump(result, dtemplate[i].outlen); | |
1434 | return -EINVAL; | |
1435 | } | |
1436 | } | |
1437 | ||
1438 | return 0; | |
1439 | } | |
1440 | ||
7647d6ce JW |
1441 | |
1442 | static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template, | |
1443 | unsigned int tcount) | |
1444 | { | |
1445 | const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm)); | |
fa4ef8a6 | 1446 | int err = 0, i, j, seedsize; |
7647d6ce JW |
1447 | u8 *seed; |
1448 | char result[32]; | |
1449 | ||
1450 | seedsize = crypto_rng_seedsize(tfm); | |
1451 | ||
1452 | seed = kmalloc(seedsize, GFP_KERNEL); | |
1453 | if (!seed) { | |
1454 | printk(KERN_ERR "alg: cprng: Failed to allocate seed space " | |
1455 | "for %s\n", algo); | |
1456 | return -ENOMEM; | |
1457 | } | |
1458 | ||
1459 | for (i = 0; i < tcount; i++) { | |
1460 | memset(result, 0, 32); | |
1461 | ||
1462 | memcpy(seed, template[i].v, template[i].vlen); | |
1463 | memcpy(seed + template[i].vlen, template[i].key, | |
1464 | template[i].klen); | |
1465 | memcpy(seed + template[i].vlen + template[i].klen, | |
1466 | template[i].dt, template[i].dtlen); | |
1467 | ||
1468 | err = crypto_rng_reset(tfm, seed, seedsize); | |
1469 | if (err) { | |
1470 | printk(KERN_ERR "alg: cprng: Failed to reset rng " | |
1471 | "for %s\n", algo); | |
1472 | goto out; | |
1473 | } | |
1474 | ||
1475 | for (j = 0; j < template[i].loops; j++) { | |
1476 | err = crypto_rng_get_bytes(tfm, result, | |
1477 | template[i].rlen); | |
19e60e13 | 1478 | if (err < 0) { |
7647d6ce JW |
1479 | printk(KERN_ERR "alg: cprng: Failed to obtain " |
1480 | "the correct amount of random data for " | |
19e60e13 SM |
1481 | "%s (requested %d)\n", algo, |
1482 | template[i].rlen); | |
7647d6ce JW |
1483 | goto out; |
1484 | } | |
1485 | } | |
1486 | ||
1487 | err = memcmp(result, template[i].result, | |
1488 | template[i].rlen); | |
1489 | if (err) { | |
1490 | printk(KERN_ERR "alg: cprng: Test %d failed for %s\n", | |
1491 | i, algo); | |
1492 | hexdump(result, template[i].rlen); | |
1493 | err = -EINVAL; | |
1494 | goto out; | |
1495 | } | |
1496 | } | |
1497 | ||
1498 | out: | |
1499 | kfree(seed); | |
1500 | return err; | |
1501 | } | |
1502 | ||
da7f033d HX |
1503 | static int alg_test_aead(const struct alg_test_desc *desc, const char *driver, |
1504 | u32 type, u32 mask) | |
1505 | { | |
1506 | struct crypto_aead *tfm; | |
1507 | int err = 0; | |
1508 | ||
425a8829 | 1509 | tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask); |
da7f033d HX |
1510 | if (IS_ERR(tfm)) { |
1511 | printk(KERN_ERR "alg: aead: Failed to load transform for %s: " | |
1512 | "%ld\n", driver, PTR_ERR(tfm)); | |
1513 | return PTR_ERR(tfm); | |
1514 | } | |
1515 | ||
1516 | if (desc->suite.aead.enc.vecs) { | |
1517 | err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs, | |
1518 | desc->suite.aead.enc.count); | |
1519 | if (err) | |
1520 | goto out; | |
1521 | } | |
1522 | ||
1523 | if (!err && desc->suite.aead.dec.vecs) | |
1524 | err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs, | |
1525 | desc->suite.aead.dec.count); | |
1526 | ||
1527 | out: | |
1528 | crypto_free_aead(tfm); | |
1529 | return err; | |
1530 | } | |
1531 | ||
1532 | static int alg_test_cipher(const struct alg_test_desc *desc, | |
1533 | const char *driver, u32 type, u32 mask) | |
1534 | { | |
1aa4ecd9 | 1535 | struct crypto_cipher *tfm; |
da7f033d HX |
1536 | int err = 0; |
1537 | ||
425a8829 | 1538 | tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask); |
da7f033d HX |
1539 | if (IS_ERR(tfm)) { |
1540 | printk(KERN_ERR "alg: cipher: Failed to load transform for " | |
1541 | "%s: %ld\n", driver, PTR_ERR(tfm)); | |
1542 | return PTR_ERR(tfm); | |
1543 | } | |
1544 | ||
1545 | if (desc->suite.cipher.enc.vecs) { | |
1546 | err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs, | |
1547 | desc->suite.cipher.enc.count); | |
1548 | if (err) | |
1549 | goto out; | |
1550 | } | |
1551 | ||
1552 | if (desc->suite.cipher.dec.vecs) | |
1553 | err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs, | |
1554 | desc->suite.cipher.dec.count); | |
1555 | ||
1aa4ecd9 HX |
1556 | out: |
1557 | crypto_free_cipher(tfm); | |
1558 | return err; | |
1559 | } | |
1560 | ||
1561 | static int alg_test_skcipher(const struct alg_test_desc *desc, | |
1562 | const char *driver, u32 type, u32 mask) | |
1563 | { | |
1564 | struct crypto_ablkcipher *tfm; | |
1565 | int err = 0; | |
1566 | ||
425a8829 | 1567 | tfm = crypto_alloc_ablkcipher(driver, type | CRYPTO_ALG_INTERNAL, mask); |
1aa4ecd9 HX |
1568 | if (IS_ERR(tfm)) { |
1569 | printk(KERN_ERR "alg: skcipher: Failed to load transform for " | |
1570 | "%s: %ld\n", driver, PTR_ERR(tfm)); | |
1571 | return PTR_ERR(tfm); | |
1572 | } | |
1573 | ||
1574 | if (desc->suite.cipher.enc.vecs) { | |
1575 | err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs, | |
1576 | desc->suite.cipher.enc.count); | |
1577 | if (err) | |
1578 | goto out; | |
1579 | } | |
1580 | ||
1581 | if (desc->suite.cipher.dec.vecs) | |
1582 | err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs, | |
1583 | desc->suite.cipher.dec.count); | |
1584 | ||
da7f033d HX |
1585 | out: |
1586 | crypto_free_ablkcipher(tfm); | |
1587 | return err; | |
1588 | } | |
1589 | ||
1590 | static int alg_test_comp(const struct alg_test_desc *desc, const char *driver, | |
1591 | u32 type, u32 mask) | |
1592 | { | |
1593 | struct crypto_comp *tfm; | |
1594 | int err; | |
1595 | ||
1596 | tfm = crypto_alloc_comp(driver, type, mask); | |
1597 | if (IS_ERR(tfm)) { | |
1598 | printk(KERN_ERR "alg: comp: Failed to load transform for %s: " | |
1599 | "%ld\n", driver, PTR_ERR(tfm)); | |
1600 | return PTR_ERR(tfm); | |
1601 | } | |
1602 | ||
1603 | err = test_comp(tfm, desc->suite.comp.comp.vecs, | |
1604 | desc->suite.comp.decomp.vecs, | |
1605 | desc->suite.comp.comp.count, | |
1606 | desc->suite.comp.decomp.count); | |
1607 | ||
1608 | crypto_free_comp(tfm); | |
1609 | return err; | |
1610 | } | |
1611 | ||
8064efb8 GU |
1612 | static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver, |
1613 | u32 type, u32 mask) | |
1614 | { | |
1615 | struct crypto_pcomp *tfm; | |
1616 | int err; | |
1617 | ||
1618 | tfm = crypto_alloc_pcomp(driver, type, mask); | |
1619 | if (IS_ERR(tfm)) { | |
1620 | pr_err("alg: pcomp: Failed to load transform for %s: %ld\n", | |
1621 | driver, PTR_ERR(tfm)); | |
1622 | return PTR_ERR(tfm); | |
1623 | } | |
1624 | ||
1625 | err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs, | |
1626 | desc->suite.pcomp.decomp.vecs, | |
1627 | desc->suite.pcomp.comp.count, | |
1628 | desc->suite.pcomp.decomp.count); | |
1629 | ||
1630 | crypto_free_pcomp(tfm); | |
1631 | return err; | |
1632 | } | |
1633 | ||
da7f033d HX |
1634 | static int alg_test_hash(const struct alg_test_desc *desc, const char *driver, |
1635 | u32 type, u32 mask) | |
1636 | { | |
1637 | struct crypto_ahash *tfm; | |
1638 | int err; | |
1639 | ||
425a8829 | 1640 | tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask); |
da7f033d HX |
1641 | if (IS_ERR(tfm)) { |
1642 | printk(KERN_ERR "alg: hash: Failed to load transform for %s: " | |
1643 | "%ld\n", driver, PTR_ERR(tfm)); | |
1644 | return PTR_ERR(tfm); | |
1645 | } | |
1646 | ||
a8f1a052 DM |
1647 | err = test_hash(tfm, desc->suite.hash.vecs, |
1648 | desc->suite.hash.count, true); | |
1649 | if (!err) | |
1650 | err = test_hash(tfm, desc->suite.hash.vecs, | |
1651 | desc->suite.hash.count, false); | |
da7f033d HX |
1652 | |
1653 | crypto_free_ahash(tfm); | |
1654 | return err; | |
1655 | } | |
1656 | ||
8e3ee85e HX |
1657 | static int alg_test_crc32c(const struct alg_test_desc *desc, |
1658 | const char *driver, u32 type, u32 mask) | |
1659 | { | |
1660 | struct crypto_shash *tfm; | |
1661 | u32 val; | |
1662 | int err; | |
1663 | ||
1664 | err = alg_test_hash(desc, driver, type, mask); | |
1665 | if (err) | |
1666 | goto out; | |
1667 | ||
425a8829 | 1668 | tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask); |
8e3ee85e HX |
1669 | if (IS_ERR(tfm)) { |
1670 | printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: " | |
1671 | "%ld\n", driver, PTR_ERR(tfm)); | |
1672 | err = PTR_ERR(tfm); | |
1673 | goto out; | |
1674 | } | |
1675 | ||
1676 | do { | |
4c5c3024 JSM |
1677 | SHASH_DESC_ON_STACK(shash, tfm); |
1678 | u32 *ctx = (u32 *)shash_desc_ctx(shash); | |
8e3ee85e | 1679 | |
4c5c3024 JSM |
1680 | shash->tfm = tfm; |
1681 | shash->flags = 0; | |
8e3ee85e | 1682 | |
4c5c3024 JSM |
1683 | *ctx = le32_to_cpu(420553207); |
1684 | err = crypto_shash_final(shash, (u8 *)&val); | |
8e3ee85e HX |
1685 | if (err) { |
1686 | printk(KERN_ERR "alg: crc32c: Operation failed for " | |
1687 | "%s: %d\n", driver, err); | |
1688 | break; | |
1689 | } | |
1690 | ||
1691 | if (val != ~420553207) { | |
1692 | printk(KERN_ERR "alg: crc32c: Test failed for %s: " | |
1693 | "%d\n", driver, val); | |
1694 | err = -EINVAL; | |
1695 | } | |
1696 | } while (0); | |
1697 | ||
1698 | crypto_free_shash(tfm); | |
1699 | ||
1700 | out: | |
1701 | return err; | |
1702 | } | |
1703 | ||
7647d6ce JW |
1704 | static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver, |
1705 | u32 type, u32 mask) | |
1706 | { | |
1707 | struct crypto_rng *rng; | |
1708 | int err; | |
1709 | ||
425a8829 | 1710 | rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask); |
7647d6ce JW |
1711 | if (IS_ERR(rng)) { |
1712 | printk(KERN_ERR "alg: cprng: Failed to load transform for %s: " | |
1713 | "%ld\n", driver, PTR_ERR(rng)); | |
1714 | return PTR_ERR(rng); | |
1715 | } | |
1716 | ||
1717 | err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count); | |
1718 | ||
1719 | crypto_free_rng(rng); | |
1720 | ||
1721 | return err; | |
1722 | } | |
1723 | ||
64d1cdfb SM |
1724 | |
1725 | static int drbg_cavs_test(struct drbg_testvec *test, int pr, | |
1726 | const char *driver, u32 type, u32 mask) | |
1727 | { | |
1728 | int ret = -EAGAIN; | |
1729 | struct crypto_rng *drng; | |
1730 | struct drbg_test_data test_data; | |
1731 | struct drbg_string addtl, pers, testentropy; | |
1732 | unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL); | |
1733 | ||
1734 | if (!buf) | |
1735 | return -ENOMEM; | |
1736 | ||
425a8829 | 1737 | drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask); |
64d1cdfb | 1738 | if (IS_ERR(drng)) { |
2fc0d258 | 1739 | printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for " |
64d1cdfb SM |
1740 | "%s\n", driver); |
1741 | kzfree(buf); | |
1742 | return -ENOMEM; | |
1743 | } | |
1744 | ||
1745 | test_data.testentropy = &testentropy; | |
1746 | drbg_string_fill(&testentropy, test->entropy, test->entropylen); | |
1747 | drbg_string_fill(&pers, test->pers, test->perslen); | |
1748 | ret = crypto_drbg_reset_test(drng, &pers, &test_data); | |
1749 | if (ret) { | |
1750 | printk(KERN_ERR "alg: drbg: Failed to reset rng\n"); | |
1751 | goto outbuf; | |
1752 | } | |
1753 | ||
1754 | drbg_string_fill(&addtl, test->addtla, test->addtllen); | |
1755 | if (pr) { | |
1756 | drbg_string_fill(&testentropy, test->entpra, test->entprlen); | |
1757 | ret = crypto_drbg_get_bytes_addtl_test(drng, | |
1758 | buf, test->expectedlen, &addtl, &test_data); | |
1759 | } else { | |
1760 | ret = crypto_drbg_get_bytes_addtl(drng, | |
1761 | buf, test->expectedlen, &addtl); | |
1762 | } | |
19e60e13 | 1763 | if (ret < 0) { |
2fc0d258 | 1764 | printk(KERN_ERR "alg: drbg: could not obtain random data for " |
64d1cdfb SM |
1765 | "driver %s\n", driver); |
1766 | goto outbuf; | |
1767 | } | |
1768 | ||
1769 | drbg_string_fill(&addtl, test->addtlb, test->addtllen); | |
1770 | if (pr) { | |
1771 | drbg_string_fill(&testentropy, test->entprb, test->entprlen); | |
1772 | ret = crypto_drbg_get_bytes_addtl_test(drng, | |
1773 | buf, test->expectedlen, &addtl, &test_data); | |
1774 | } else { | |
1775 | ret = crypto_drbg_get_bytes_addtl(drng, | |
1776 | buf, test->expectedlen, &addtl); | |
1777 | } | |
19e60e13 | 1778 | if (ret < 0) { |
2fc0d258 | 1779 | printk(KERN_ERR "alg: drbg: could not obtain random data for " |
64d1cdfb SM |
1780 | "driver %s\n", driver); |
1781 | goto outbuf; | |
1782 | } | |
1783 | ||
1784 | ret = memcmp(test->expected, buf, test->expectedlen); | |
1785 | ||
1786 | outbuf: | |
1787 | crypto_free_rng(drng); | |
1788 | kzfree(buf); | |
1789 | return ret; | |
1790 | } | |
1791 | ||
1792 | ||
1793 | static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver, | |
1794 | u32 type, u32 mask) | |
1795 | { | |
1796 | int err = 0; | |
1797 | int pr = 0; | |
1798 | int i = 0; | |
1799 | struct drbg_testvec *template = desc->suite.drbg.vecs; | |
1800 | unsigned int tcount = desc->suite.drbg.count; | |
1801 | ||
1802 | if (0 == memcmp(driver, "drbg_pr_", 8)) | |
1803 | pr = 1; | |
1804 | ||
1805 | for (i = 0; i < tcount; i++) { | |
1806 | err = drbg_cavs_test(&template[i], pr, driver, type, mask); | |
1807 | if (err) { | |
1808 | printk(KERN_ERR "alg: drbg: Test %d failed for %s\n", | |
1809 | i, driver); | |
1810 | err = -EINVAL; | |
1811 | break; | |
1812 | } | |
1813 | } | |
1814 | return err; | |
1815 | ||
1816 | } | |
1817 | ||
863b557a YS |
1818 | static int alg_test_null(const struct alg_test_desc *desc, |
1819 | const char *driver, u32 type, u32 mask) | |
1820 | { | |
1821 | return 0; | |
1822 | } | |
1823 | ||
da7f033d HX |
1824 | /* Please keep this list sorted by algorithm name. */ |
1825 | static const struct alg_test_desc alg_test_descs[] = { | |
1826 | { | |
4d6d6a2c JG |
1827 | .alg = "__cbc-cast5-avx", |
1828 | .test = alg_test_null, | |
4ea1277d JG |
1829 | }, { |
1830 | .alg = "__cbc-cast6-avx", | |
1831 | .test = alg_test_null, | |
4d6d6a2c | 1832 | }, { |
7efe4076 JG |
1833 | .alg = "__cbc-serpent-avx", |
1834 | .test = alg_test_null, | |
56d76c96 JK |
1835 | }, { |
1836 | .alg = "__cbc-serpent-avx2", | |
1837 | .test = alg_test_null, | |
7efe4076 | 1838 | }, { |
937c30d7 JK |
1839 | .alg = "__cbc-serpent-sse2", |
1840 | .test = alg_test_null, | |
107778b5 JG |
1841 | }, { |
1842 | .alg = "__cbc-twofish-avx", | |
1843 | .test = alg_test_null, | |
937c30d7 | 1844 | }, { |
863b557a YS |
1845 | .alg = "__driver-cbc-aes-aesni", |
1846 | .test = alg_test_null, | |
6c79294f | 1847 | .fips_allowed = 1, |
d9b1d2e7 JK |
1848 | }, { |
1849 | .alg = "__driver-cbc-camellia-aesni", | |
1850 | .test = alg_test_null, | |
f3f935a7 JK |
1851 | }, { |
1852 | .alg = "__driver-cbc-camellia-aesni-avx2", | |
1853 | .test = alg_test_null, | |
4d6d6a2c JG |
1854 | }, { |
1855 | .alg = "__driver-cbc-cast5-avx", | |
1856 | .test = alg_test_null, | |
4ea1277d JG |
1857 | }, { |
1858 | .alg = "__driver-cbc-cast6-avx", | |
1859 | .test = alg_test_null, | |
7efe4076 JG |
1860 | }, { |
1861 | .alg = "__driver-cbc-serpent-avx", | |
1862 | .test = alg_test_null, | |
56d76c96 JK |
1863 | }, { |
1864 | .alg = "__driver-cbc-serpent-avx2", | |
1865 | .test = alg_test_null, | |
937c30d7 JK |
1866 | }, { |
1867 | .alg = "__driver-cbc-serpent-sse2", | |
1868 | .test = alg_test_null, | |
107778b5 JG |
1869 | }, { |
1870 | .alg = "__driver-cbc-twofish-avx", | |
1871 | .test = alg_test_null, | |
863b557a YS |
1872 | }, { |
1873 | .alg = "__driver-ecb-aes-aesni", | |
1874 | .test = alg_test_null, | |
6c79294f | 1875 | .fips_allowed = 1, |
d9b1d2e7 JK |
1876 | }, { |
1877 | .alg = "__driver-ecb-camellia-aesni", | |
1878 | .test = alg_test_null, | |
f3f935a7 JK |
1879 | }, { |
1880 | .alg = "__driver-ecb-camellia-aesni-avx2", | |
1881 | .test = alg_test_null, | |
4d6d6a2c JG |
1882 | }, { |
1883 | .alg = "__driver-ecb-cast5-avx", | |
1884 | .test = alg_test_null, | |
4ea1277d JG |
1885 | }, { |
1886 | .alg = "__driver-ecb-cast6-avx", | |
1887 | .test = alg_test_null, | |
7efe4076 JG |
1888 | }, { |
1889 | .alg = "__driver-ecb-serpent-avx", | |
1890 | .test = alg_test_null, | |
56d76c96 JK |
1891 | }, { |
1892 | .alg = "__driver-ecb-serpent-avx2", | |
1893 | .test = alg_test_null, | |
937c30d7 JK |
1894 | }, { |
1895 | .alg = "__driver-ecb-serpent-sse2", | |
1896 | .test = alg_test_null, | |
107778b5 JG |
1897 | }, { |
1898 | .alg = "__driver-ecb-twofish-avx", | |
1899 | .test = alg_test_null, | |
863b557a YS |
1900 | }, { |
1901 | .alg = "__ghash-pclmulqdqni", | |
1902 | .test = alg_test_null, | |
6c79294f | 1903 | .fips_allowed = 1, |
863b557a | 1904 | }, { |
e08ca2da JW |
1905 | .alg = "ansi_cprng", |
1906 | .test = alg_test_cprng, | |
a1915d51 | 1907 | .fips_allowed = 1, |
e08ca2da JW |
1908 | .suite = { |
1909 | .cprng = { | |
1910 | .vecs = ansi_cprng_aes_tv_template, | |
1911 | .count = ANSI_CPRNG_AES_TEST_VECTORS | |
1912 | } | |
1913 | } | |
bca4feb0 HG |
1914 | }, { |
1915 | .alg = "authenc(hmac(md5),ecb(cipher_null))", | |
1916 | .test = alg_test_aead, | |
1917 | .fips_allowed = 1, | |
1918 | .suite = { | |
1919 | .aead = { | |
1920 | .enc = { | |
1921 | .vecs = hmac_md5_ecb_cipher_null_enc_tv_template, | |
1922 | .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS | |
1923 | }, | |
1924 | .dec = { | |
1925 | .vecs = hmac_md5_ecb_cipher_null_dec_tv_template, | |
1926 | .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS | |
1927 | } | |
1928 | } | |
1929 | } | |
e46e9a46 HG |
1930 | }, { |
1931 | .alg = "authenc(hmac(sha1),cbc(aes))", | |
1932 | .test = alg_test_aead, | |
1933 | .fips_allowed = 1, | |
1934 | .suite = { | |
1935 | .aead = { | |
1936 | .enc = { | |
5208ed2c NL |
1937 | .vecs = |
1938 | hmac_sha1_aes_cbc_enc_tv_temp, | |
1939 | .count = | |
1940 | HMAC_SHA1_AES_CBC_ENC_TEST_VEC | |
1941 | } | |
1942 | } | |
1943 | } | |
1944 | }, { | |
1945 | .alg = "authenc(hmac(sha1),cbc(des))", | |
1946 | .test = alg_test_aead, | |
1947 | .fips_allowed = 1, | |
1948 | .suite = { | |
1949 | .aead = { | |
1950 | .enc = { | |
1951 | .vecs = | |
1952 | hmac_sha1_des_cbc_enc_tv_temp, | |
1953 | .count = | |
1954 | HMAC_SHA1_DES_CBC_ENC_TEST_VEC | |
1955 | } | |
1956 | } | |
1957 | } | |
1958 | }, { | |
1959 | .alg = "authenc(hmac(sha1),cbc(des3_ede))", | |
1960 | .test = alg_test_aead, | |
1961 | .fips_allowed = 1, | |
1962 | .suite = { | |
1963 | .aead = { | |
1964 | .enc = { | |
1965 | .vecs = | |
1966 | hmac_sha1_des3_ede_cbc_enc_tv_temp, | |
1967 | .count = | |
1968 | HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC | |
e46e9a46 HG |
1969 | } |
1970 | } | |
1971 | } | |
bca4feb0 HG |
1972 | }, { |
1973 | .alg = "authenc(hmac(sha1),ecb(cipher_null))", | |
1974 | .test = alg_test_aead, | |
1975 | .fips_allowed = 1, | |
1976 | .suite = { | |
1977 | .aead = { | |
1978 | .enc = { | |
5208ed2c NL |
1979 | .vecs = |
1980 | hmac_sha1_ecb_cipher_null_enc_tv_temp, | |
1981 | .count = | |
1982 | HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC | |
bca4feb0 HG |
1983 | }, |
1984 | .dec = { | |
5208ed2c NL |
1985 | .vecs = |
1986 | hmac_sha1_ecb_cipher_null_dec_tv_temp, | |
1987 | .count = | |
1988 | HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC | |
1989 | } | |
1990 | } | |
1991 | } | |
1992 | }, { | |
1993 | .alg = "authenc(hmac(sha224),cbc(des))", | |
1994 | .test = alg_test_aead, | |
1995 | .fips_allowed = 1, | |
1996 | .suite = { | |
1997 | .aead = { | |
1998 | .enc = { | |
1999 | .vecs = | |
2000 | hmac_sha224_des_cbc_enc_tv_temp, | |
2001 | .count = | |
2002 | HMAC_SHA224_DES_CBC_ENC_TEST_VEC | |
2003 | } | |
2004 | } | |
2005 | } | |
2006 | }, { | |
2007 | .alg = "authenc(hmac(sha224),cbc(des3_ede))", | |
2008 | .test = alg_test_aead, | |
2009 | .fips_allowed = 1, | |
2010 | .suite = { | |
2011 | .aead = { | |
2012 | .enc = { | |
2013 | .vecs = | |
2014 | hmac_sha224_des3_ede_cbc_enc_tv_temp, | |
2015 | .count = | |
2016 | HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC | |
bca4feb0 HG |
2017 | } |
2018 | } | |
2019 | } | |
e46e9a46 HG |
2020 | }, { |
2021 | .alg = "authenc(hmac(sha256),cbc(aes))", | |
2022 | .test = alg_test_aead, | |
2023 | .fips_allowed = 1, | |
2024 | .suite = { | |
2025 | .aead = { | |
2026 | .enc = { | |
5208ed2c NL |
2027 | .vecs = |
2028 | hmac_sha256_aes_cbc_enc_tv_temp, | |
2029 | .count = | |
2030 | HMAC_SHA256_AES_CBC_ENC_TEST_VEC | |
2031 | } | |
2032 | } | |
2033 | } | |
2034 | }, { | |
2035 | .alg = "authenc(hmac(sha256),cbc(des))", | |
2036 | .test = alg_test_aead, | |
2037 | .fips_allowed = 1, | |
2038 | .suite = { | |
2039 | .aead = { | |
2040 | .enc = { | |
2041 | .vecs = | |
2042 | hmac_sha256_des_cbc_enc_tv_temp, | |
2043 | .count = | |
2044 | HMAC_SHA256_DES_CBC_ENC_TEST_VEC | |
2045 | } | |
2046 | } | |
2047 | } | |
2048 | }, { | |
2049 | .alg = "authenc(hmac(sha256),cbc(des3_ede))", | |
2050 | .test = alg_test_aead, | |
2051 | .fips_allowed = 1, | |
2052 | .suite = { | |
2053 | .aead = { | |
2054 | .enc = { | |
2055 | .vecs = | |
2056 | hmac_sha256_des3_ede_cbc_enc_tv_temp, | |
2057 | .count = | |
2058 | HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC | |
2059 | } | |
2060 | } | |
2061 | } | |
2062 | }, { | |
2063 | .alg = "authenc(hmac(sha384),cbc(des))", | |
2064 | .test = alg_test_aead, | |
2065 | .fips_allowed = 1, | |
2066 | .suite = { | |
2067 | .aead = { | |
2068 | .enc = { | |
2069 | .vecs = | |
2070 | hmac_sha384_des_cbc_enc_tv_temp, | |
2071 | .count = | |
2072 | HMAC_SHA384_DES_CBC_ENC_TEST_VEC | |
2073 | } | |
2074 | } | |
2075 | } | |
2076 | }, { | |
2077 | .alg = "authenc(hmac(sha384),cbc(des3_ede))", | |
2078 | .test = alg_test_aead, | |
2079 | .fips_allowed = 1, | |
2080 | .suite = { | |
2081 | .aead = { | |
2082 | .enc = { | |
2083 | .vecs = | |
2084 | hmac_sha384_des3_ede_cbc_enc_tv_temp, | |
2085 | .count = | |
2086 | HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC | |
e46e9a46 HG |
2087 | } |
2088 | } | |
2089 | } | |
2090 | }, { | |
2091 | .alg = "authenc(hmac(sha512),cbc(aes))", | |
2092 | .test = alg_test_aead, | |
2093 | .fips_allowed = 1, | |
2094 | .suite = { | |
2095 | .aead = { | |
2096 | .enc = { | |
5208ed2c NL |
2097 | .vecs = |
2098 | hmac_sha512_aes_cbc_enc_tv_temp, | |
2099 | .count = | |
2100 | HMAC_SHA512_AES_CBC_ENC_TEST_VEC | |
2101 | } | |
2102 | } | |
2103 | } | |
2104 | }, { | |
2105 | .alg = "authenc(hmac(sha512),cbc(des))", | |
2106 | .test = alg_test_aead, | |
2107 | .fips_allowed = 1, | |
2108 | .suite = { | |
2109 | .aead = { | |
2110 | .enc = { | |
2111 | .vecs = | |
2112 | hmac_sha512_des_cbc_enc_tv_temp, | |
2113 | .count = | |
2114 | HMAC_SHA512_DES_CBC_ENC_TEST_VEC | |
2115 | } | |
2116 | } | |
2117 | } | |
2118 | }, { | |
2119 | .alg = "authenc(hmac(sha512),cbc(des3_ede))", | |
2120 | .test = alg_test_aead, | |
2121 | .fips_allowed = 1, | |
2122 | .suite = { | |
2123 | .aead = { | |
2124 | .enc = { | |
2125 | .vecs = | |
2126 | hmac_sha512_des3_ede_cbc_enc_tv_temp, | |
2127 | .count = | |
2128 | HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC | |
e46e9a46 HG |
2129 | } |
2130 | } | |
2131 | } | |
e08ca2da | 2132 | }, { |
da7f033d | 2133 | .alg = "cbc(aes)", |
1aa4ecd9 | 2134 | .test = alg_test_skcipher, |
a1915d51 | 2135 | .fips_allowed = 1, |
da7f033d HX |
2136 | .suite = { |
2137 | .cipher = { | |
2138 | .enc = { | |
2139 | .vecs = aes_cbc_enc_tv_template, | |
2140 | .count = AES_CBC_ENC_TEST_VECTORS | |
2141 | }, | |
2142 | .dec = { | |
2143 | .vecs = aes_cbc_dec_tv_template, | |
2144 | .count = AES_CBC_DEC_TEST_VECTORS | |
2145 | } | |
2146 | } | |
2147 | } | |
2148 | }, { | |
2149 | .alg = "cbc(anubis)", | |
1aa4ecd9 | 2150 | .test = alg_test_skcipher, |
da7f033d HX |
2151 | .suite = { |
2152 | .cipher = { | |
2153 | .enc = { | |
2154 | .vecs = anubis_cbc_enc_tv_template, | |
2155 | .count = ANUBIS_CBC_ENC_TEST_VECTORS | |
2156 | }, | |
2157 | .dec = { | |
2158 | .vecs = anubis_cbc_dec_tv_template, | |
2159 | .count = ANUBIS_CBC_DEC_TEST_VECTORS | |
2160 | } | |
2161 | } | |
2162 | } | |
2163 | }, { | |
2164 | .alg = "cbc(blowfish)", | |
1aa4ecd9 | 2165 | .test = alg_test_skcipher, |
da7f033d HX |
2166 | .suite = { |
2167 | .cipher = { | |
2168 | .enc = { | |
2169 | .vecs = bf_cbc_enc_tv_template, | |
2170 | .count = BF_CBC_ENC_TEST_VECTORS | |
2171 | }, | |
2172 | .dec = { | |
2173 | .vecs = bf_cbc_dec_tv_template, | |
2174 | .count = BF_CBC_DEC_TEST_VECTORS | |
2175 | } | |
2176 | } | |
2177 | } | |
2178 | }, { | |
2179 | .alg = "cbc(camellia)", | |
1aa4ecd9 | 2180 | .test = alg_test_skcipher, |
da7f033d HX |
2181 | .suite = { |
2182 | .cipher = { | |
2183 | .enc = { | |
2184 | .vecs = camellia_cbc_enc_tv_template, | |
2185 | .count = CAMELLIA_CBC_ENC_TEST_VECTORS | |
2186 | }, | |
2187 | .dec = { | |
2188 | .vecs = camellia_cbc_dec_tv_template, | |
2189 | .count = CAMELLIA_CBC_DEC_TEST_VECTORS | |
2190 | } | |
2191 | } | |
2192 | } | |
a2c58260 JG |
2193 | }, { |
2194 | .alg = "cbc(cast5)", | |
2195 | .test = alg_test_skcipher, | |
2196 | .suite = { | |
2197 | .cipher = { | |
2198 | .enc = { | |
2199 | .vecs = cast5_cbc_enc_tv_template, | |
2200 | .count = CAST5_CBC_ENC_TEST_VECTORS | |
2201 | }, | |
2202 | .dec = { | |
2203 | .vecs = cast5_cbc_dec_tv_template, | |
2204 | .count = CAST5_CBC_DEC_TEST_VECTORS | |
2205 | } | |
2206 | } | |
2207 | } | |
9b8b0405 JG |
2208 | }, { |
2209 | .alg = "cbc(cast6)", | |
2210 | .test = alg_test_skcipher, | |
2211 | .suite = { | |
2212 | .cipher = { | |
2213 | .enc = { | |
2214 | .vecs = cast6_cbc_enc_tv_template, | |
2215 | .count = CAST6_CBC_ENC_TEST_VECTORS | |
2216 | }, | |
2217 | .dec = { | |
2218 | .vecs = cast6_cbc_dec_tv_template, | |
2219 | .count = CAST6_CBC_DEC_TEST_VECTORS | |
2220 | } | |
2221 | } | |
2222 | } | |
da7f033d HX |
2223 | }, { |
2224 | .alg = "cbc(des)", | |
1aa4ecd9 | 2225 | .test = alg_test_skcipher, |
da7f033d HX |
2226 | .suite = { |
2227 | .cipher = { | |
2228 | .enc = { | |
2229 | .vecs = des_cbc_enc_tv_template, | |
2230 | .count = DES_CBC_ENC_TEST_VECTORS | |
2231 | }, | |
2232 | .dec = { | |
2233 | .vecs = des_cbc_dec_tv_template, | |
2234 | .count = DES_CBC_DEC_TEST_VECTORS | |
2235 | } | |
2236 | } | |
2237 | } | |
2238 | }, { | |
2239 | .alg = "cbc(des3_ede)", | |
1aa4ecd9 | 2240 | .test = alg_test_skcipher, |
a1915d51 | 2241 | .fips_allowed = 1, |
da7f033d HX |
2242 | .suite = { |
2243 | .cipher = { | |
2244 | .enc = { | |
2245 | .vecs = des3_ede_cbc_enc_tv_template, | |
2246 | .count = DES3_EDE_CBC_ENC_TEST_VECTORS | |
2247 | }, | |
2248 | .dec = { | |
2249 | .vecs = des3_ede_cbc_dec_tv_template, | |
2250 | .count = DES3_EDE_CBC_DEC_TEST_VECTORS | |
2251 | } | |
2252 | } | |
2253 | } | |
9d25917d JK |
2254 | }, { |
2255 | .alg = "cbc(serpent)", | |
2256 | .test = alg_test_skcipher, | |
2257 | .suite = { | |
2258 | .cipher = { | |
2259 | .enc = { | |
2260 | .vecs = serpent_cbc_enc_tv_template, | |
2261 | .count = SERPENT_CBC_ENC_TEST_VECTORS | |
2262 | }, | |
2263 | .dec = { | |
2264 | .vecs = serpent_cbc_dec_tv_template, | |
2265 | .count = SERPENT_CBC_DEC_TEST_VECTORS | |
2266 | } | |
2267 | } | |
2268 | } | |
da7f033d HX |
2269 | }, { |
2270 | .alg = "cbc(twofish)", | |
1aa4ecd9 | 2271 | .test = alg_test_skcipher, |
da7f033d HX |
2272 | .suite = { |
2273 | .cipher = { | |
2274 | .enc = { | |
2275 | .vecs = tf_cbc_enc_tv_template, | |
2276 | .count = TF_CBC_ENC_TEST_VECTORS | |
2277 | }, | |
2278 | .dec = { | |
2279 | .vecs = tf_cbc_dec_tv_template, | |
2280 | .count = TF_CBC_DEC_TEST_VECTORS | |
2281 | } | |
2282 | } | |
2283 | } | |
2284 | }, { | |
2285 | .alg = "ccm(aes)", | |
2286 | .test = alg_test_aead, | |
a1915d51 | 2287 | .fips_allowed = 1, |
da7f033d HX |
2288 | .suite = { |
2289 | .aead = { | |
2290 | .enc = { | |
2291 | .vecs = aes_ccm_enc_tv_template, | |
2292 | .count = AES_CCM_ENC_TEST_VECTORS | |
2293 | }, | |
2294 | .dec = { | |
2295 | .vecs = aes_ccm_dec_tv_template, | |
2296 | .count = AES_CCM_DEC_TEST_VECTORS | |
2297 | } | |
2298 | } | |
2299 | } | |
93b5e86a JK |
2300 | }, { |
2301 | .alg = "cmac(aes)", | |
2302 | .test = alg_test_hash, | |
2303 | .suite = { | |
2304 | .hash = { | |
2305 | .vecs = aes_cmac128_tv_template, | |
2306 | .count = CMAC_AES_TEST_VECTORS | |
2307 | } | |
2308 | } | |
2309 | }, { | |
2310 | .alg = "cmac(des3_ede)", | |
2311 | .test = alg_test_hash, | |
2312 | .suite = { | |
2313 | .hash = { | |
2314 | .vecs = des3_ede_cmac64_tv_template, | |
2315 | .count = CMAC_DES3_EDE_TEST_VECTORS | |
2316 | } | |
2317 | } | |
e448370d JK |
2318 | }, { |
2319 | .alg = "compress_null", | |
2320 | .test = alg_test_null, | |
da7f033d HX |
2321 | }, { |
2322 | .alg = "crc32c", | |
8e3ee85e | 2323 | .test = alg_test_crc32c, |
a1915d51 | 2324 | .fips_allowed = 1, |
da7f033d HX |
2325 | .suite = { |
2326 | .hash = { | |
2327 | .vecs = crc32c_tv_template, | |
2328 | .count = CRC32C_TEST_VECTORS | |
2329 | } | |
2330 | } | |
68411521 HX |
2331 | }, { |
2332 | .alg = "crct10dif", | |
2333 | .test = alg_test_hash, | |
2334 | .fips_allowed = 1, | |
2335 | .suite = { | |
2336 | .hash = { | |
2337 | .vecs = crct10dif_tv_template, | |
2338 | .count = CRCT10DIF_TEST_VECTORS | |
2339 | } | |
2340 | } | |
6c79294f MB |
2341 | }, { |
2342 | .alg = "cryptd(__driver-cbc-aes-aesni)", | |
2343 | .test = alg_test_null, | |
2344 | .fips_allowed = 1, | |
d9b1d2e7 JK |
2345 | }, { |
2346 | .alg = "cryptd(__driver-cbc-camellia-aesni)", | |
2347 | .test = alg_test_null, | |
f3f935a7 JK |
2348 | }, { |
2349 | .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)", | |
2350 | .test = alg_test_null, | |
56d76c96 JK |
2351 | }, { |
2352 | .alg = "cryptd(__driver-cbc-serpent-avx2)", | |
2353 | .test = alg_test_null, | |
863b557a YS |
2354 | }, { |
2355 | .alg = "cryptd(__driver-ecb-aes-aesni)", | |
2356 | .test = alg_test_null, | |
6c79294f | 2357 | .fips_allowed = 1, |
d9b1d2e7 JK |
2358 | }, { |
2359 | .alg = "cryptd(__driver-ecb-camellia-aesni)", | |
2360 | .test = alg_test_null, | |
f3f935a7 JK |
2361 | }, { |
2362 | .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)", | |
2363 | .test = alg_test_null, | |
4d6d6a2c JG |
2364 | }, { |
2365 | .alg = "cryptd(__driver-ecb-cast5-avx)", | |
2366 | .test = alg_test_null, | |
4ea1277d JG |
2367 | }, { |
2368 | .alg = "cryptd(__driver-ecb-cast6-avx)", | |
2369 | .test = alg_test_null, | |
7efe4076 JG |
2370 | }, { |
2371 | .alg = "cryptd(__driver-ecb-serpent-avx)", | |
2372 | .test = alg_test_null, | |
56d76c96 JK |
2373 | }, { |
2374 | .alg = "cryptd(__driver-ecb-serpent-avx2)", | |
2375 | .test = alg_test_null, | |
937c30d7 JK |
2376 | }, { |
2377 | .alg = "cryptd(__driver-ecb-serpent-sse2)", | |
2378 | .test = alg_test_null, | |
107778b5 JG |
2379 | }, { |
2380 | .alg = "cryptd(__driver-ecb-twofish-avx)", | |
2381 | .test = alg_test_null, | |
6c79294f MB |
2382 | }, { |
2383 | .alg = "cryptd(__driver-gcm-aes-aesni)", | |
2384 | .test = alg_test_null, | |
2385 | .fips_allowed = 1, | |
863b557a YS |
2386 | }, { |
2387 | .alg = "cryptd(__ghash-pclmulqdqni)", | |
2388 | .test = alg_test_null, | |
6c79294f | 2389 | .fips_allowed = 1, |
f7cb80f2 JW |
2390 | }, { |
2391 | .alg = "ctr(aes)", | |
2392 | .test = alg_test_skcipher, | |
a1915d51 | 2393 | .fips_allowed = 1, |
f7cb80f2 JW |
2394 | .suite = { |
2395 | .cipher = { | |
2396 | .enc = { | |
2397 | .vecs = aes_ctr_enc_tv_template, | |
2398 | .count = AES_CTR_ENC_TEST_VECTORS | |
2399 | }, | |
2400 | .dec = { | |
2401 | .vecs = aes_ctr_dec_tv_template, | |
2402 | .count = AES_CTR_DEC_TEST_VECTORS | |
2403 | } | |
2404 | } | |
2405 | } | |
85b63e34 JK |
2406 | }, { |
2407 | .alg = "ctr(blowfish)", | |
2408 | .test = alg_test_skcipher, | |
2409 | .suite = { | |
2410 | .cipher = { | |
2411 | .enc = { | |
2412 | .vecs = bf_ctr_enc_tv_template, | |
2413 | .count = BF_CTR_ENC_TEST_VECTORS | |
2414 | }, | |
2415 | .dec = { | |
2416 | .vecs = bf_ctr_dec_tv_template, | |
2417 | .count = BF_CTR_DEC_TEST_VECTORS | |
2418 | } | |
2419 | } | |
2420 | } | |
0840605e JK |
2421 | }, { |
2422 | .alg = "ctr(camellia)", | |
2423 | .test = alg_test_skcipher, | |
2424 | .suite = { | |
2425 | .cipher = { | |
2426 | .enc = { | |
2427 | .vecs = camellia_ctr_enc_tv_template, | |
2428 | .count = CAMELLIA_CTR_ENC_TEST_VECTORS | |
2429 | }, | |
2430 | .dec = { | |
2431 | .vecs = camellia_ctr_dec_tv_template, | |
2432 | .count = CAMELLIA_CTR_DEC_TEST_VECTORS | |
2433 | } | |
2434 | } | |
2435 | } | |
a2c58260 JG |
2436 | }, { |
2437 | .alg = "ctr(cast5)", | |
2438 | .test = alg_test_skcipher, | |
2439 | .suite = { | |
2440 | .cipher = { | |
2441 | .enc = { | |
2442 | .vecs = cast5_ctr_enc_tv_template, | |
2443 | .count = CAST5_CTR_ENC_TEST_VECTORS | |
2444 | }, | |
2445 | .dec = { | |
2446 | .vecs = cast5_ctr_dec_tv_template, | |
2447 | .count = CAST5_CTR_DEC_TEST_VECTORS | |
2448 | } | |
2449 | } | |
2450 | } | |
9b8b0405 JG |
2451 | }, { |
2452 | .alg = "ctr(cast6)", | |
2453 | .test = alg_test_skcipher, | |
2454 | .suite = { | |
2455 | .cipher = { | |
2456 | .enc = { | |
2457 | .vecs = cast6_ctr_enc_tv_template, | |
2458 | .count = CAST6_CTR_ENC_TEST_VECTORS | |
2459 | }, | |
2460 | .dec = { | |
2461 | .vecs = cast6_ctr_dec_tv_template, | |
2462 | .count = CAST6_CTR_DEC_TEST_VECTORS | |
2463 | } | |
2464 | } | |
2465 | } | |
8163fc30 JK |
2466 | }, { |
2467 | .alg = "ctr(des)", | |
2468 | .test = alg_test_skcipher, | |
2469 | .suite = { | |
2470 | .cipher = { | |
2471 | .enc = { | |
2472 | .vecs = des_ctr_enc_tv_template, | |
2473 | .count = DES_CTR_ENC_TEST_VECTORS | |
2474 | }, | |
2475 | .dec = { | |
2476 | .vecs = des_ctr_dec_tv_template, | |
2477 | .count = DES_CTR_DEC_TEST_VECTORS | |
2478 | } | |
2479 | } | |
2480 | } | |
e080b17a JK |
2481 | }, { |
2482 | .alg = "ctr(des3_ede)", | |
2483 | .test = alg_test_skcipher, | |
2484 | .suite = { | |
2485 | .cipher = { | |
2486 | .enc = { | |
2487 | .vecs = des3_ede_ctr_enc_tv_template, | |
2488 | .count = DES3_EDE_CTR_ENC_TEST_VECTORS | |
2489 | }, | |
2490 | .dec = { | |
2491 | .vecs = des3_ede_ctr_dec_tv_template, | |
2492 | .count = DES3_EDE_CTR_DEC_TEST_VECTORS | |
2493 | } | |
2494 | } | |
2495 | } | |
9d25917d JK |
2496 | }, { |
2497 | .alg = "ctr(serpent)", | |
2498 | .test = alg_test_skcipher, | |
2499 | .suite = { | |
2500 | .cipher = { | |
2501 | .enc = { | |
2502 | .vecs = serpent_ctr_enc_tv_template, | |
2503 | .count = SERPENT_CTR_ENC_TEST_VECTORS | |
2504 | }, | |
2505 | .dec = { | |
2506 | .vecs = serpent_ctr_dec_tv_template, | |
2507 | .count = SERPENT_CTR_DEC_TEST_VECTORS | |
2508 | } | |
2509 | } | |
2510 | } | |
573da620 JK |
2511 | }, { |
2512 | .alg = "ctr(twofish)", | |
2513 | .test = alg_test_skcipher, | |
2514 | .suite = { | |
2515 | .cipher = { | |
2516 | .enc = { | |
2517 | .vecs = tf_ctr_enc_tv_template, | |
2518 | .count = TF_CTR_ENC_TEST_VECTORS | |
2519 | }, | |
2520 | .dec = { | |
2521 | .vecs = tf_ctr_dec_tv_template, | |
2522 | .count = TF_CTR_DEC_TEST_VECTORS | |
2523 | } | |
2524 | } | |
2525 | } | |
da7f033d HX |
2526 | }, { |
2527 | .alg = "cts(cbc(aes))", | |
1aa4ecd9 | 2528 | .test = alg_test_skcipher, |
da7f033d HX |
2529 | .suite = { |
2530 | .cipher = { | |
2531 | .enc = { | |
2532 | .vecs = cts_mode_enc_tv_template, | |
2533 | .count = CTS_MODE_ENC_TEST_VECTORS | |
2534 | }, | |
2535 | .dec = { | |
2536 | .vecs = cts_mode_dec_tv_template, | |
2537 | .count = CTS_MODE_DEC_TEST_VECTORS | |
2538 | } | |
2539 | } | |
2540 | } | |
2541 | }, { | |
2542 | .alg = "deflate", | |
2543 | .test = alg_test_comp, | |
0818904d | 2544 | .fips_allowed = 1, |
da7f033d HX |
2545 | .suite = { |
2546 | .comp = { | |
2547 | .comp = { | |
2548 | .vecs = deflate_comp_tv_template, | |
2549 | .count = DEFLATE_COMP_TEST_VECTORS | |
2550 | }, | |
2551 | .decomp = { | |
2552 | .vecs = deflate_decomp_tv_template, | |
2553 | .count = DEFLATE_DECOMP_TEST_VECTORS | |
2554 | } | |
2555 | } | |
2556 | } | |
e448370d JK |
2557 | }, { |
2558 | .alg = "digest_null", | |
2559 | .test = alg_test_null, | |
64d1cdfb SM |
2560 | }, { |
2561 | .alg = "drbg_nopr_ctr_aes128", | |
2562 | .test = alg_test_drbg, | |
2563 | .fips_allowed = 1, | |
2564 | .suite = { | |
2565 | .drbg = { | |
2566 | .vecs = drbg_nopr_ctr_aes128_tv_template, | |
2567 | .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template) | |
2568 | } | |
2569 | } | |
2570 | }, { | |
2571 | .alg = "drbg_nopr_ctr_aes192", | |
2572 | .test = alg_test_drbg, | |
2573 | .fips_allowed = 1, | |
2574 | .suite = { | |
2575 | .drbg = { | |
2576 | .vecs = drbg_nopr_ctr_aes192_tv_template, | |
2577 | .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template) | |
2578 | } | |
2579 | } | |
2580 | }, { | |
2581 | .alg = "drbg_nopr_ctr_aes256", | |
2582 | .test = alg_test_drbg, | |
2583 | .fips_allowed = 1, | |
2584 | .suite = { | |
2585 | .drbg = { | |
2586 | .vecs = drbg_nopr_ctr_aes256_tv_template, | |
2587 | .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template) | |
2588 | } | |
2589 | } | |
2590 | }, { | |
2591 | /* | |
2592 | * There is no need to specifically test the DRBG with every | |
2593 | * backend cipher -- covered by drbg_nopr_hmac_sha256 test | |
2594 | */ | |
2595 | .alg = "drbg_nopr_hmac_sha1", | |
2596 | .fips_allowed = 1, | |
2597 | .test = alg_test_null, | |
2598 | }, { | |
2599 | .alg = "drbg_nopr_hmac_sha256", | |
2600 | .test = alg_test_drbg, | |
2601 | .fips_allowed = 1, | |
2602 | .suite = { | |
2603 | .drbg = { | |
2604 | .vecs = drbg_nopr_hmac_sha256_tv_template, | |
2605 | .count = | |
2606 | ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template) | |
2607 | } | |
2608 | } | |
2609 | }, { | |
2610 | /* covered by drbg_nopr_hmac_sha256 test */ | |
2611 | .alg = "drbg_nopr_hmac_sha384", | |
2612 | .fips_allowed = 1, | |
2613 | .test = alg_test_null, | |
2614 | }, { | |
2615 | .alg = "drbg_nopr_hmac_sha512", | |
2616 | .test = alg_test_null, | |
2617 | .fips_allowed = 1, | |
2618 | }, { | |
2619 | .alg = "drbg_nopr_sha1", | |
2620 | .fips_allowed = 1, | |
2621 | .test = alg_test_null, | |
2622 | }, { | |
2623 | .alg = "drbg_nopr_sha256", | |
2624 | .test = alg_test_drbg, | |
2625 | .fips_allowed = 1, | |
2626 | .suite = { | |
2627 | .drbg = { | |
2628 | .vecs = drbg_nopr_sha256_tv_template, | |
2629 | .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template) | |
2630 | } | |
2631 | } | |
2632 | }, { | |
2633 | /* covered by drbg_nopr_sha256 test */ | |
2634 | .alg = "drbg_nopr_sha384", | |
2635 | .fips_allowed = 1, | |
2636 | .test = alg_test_null, | |
2637 | }, { | |
2638 | .alg = "drbg_nopr_sha512", | |
2639 | .fips_allowed = 1, | |
2640 | .test = alg_test_null, | |
2641 | }, { | |
2642 | .alg = "drbg_pr_ctr_aes128", | |
2643 | .test = alg_test_drbg, | |
2644 | .fips_allowed = 1, | |
2645 | .suite = { | |
2646 | .drbg = { | |
2647 | .vecs = drbg_pr_ctr_aes128_tv_template, | |
2648 | .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template) | |
2649 | } | |
2650 | } | |
2651 | }, { | |
2652 | /* covered by drbg_pr_ctr_aes128 test */ | |
2653 | .alg = "drbg_pr_ctr_aes192", | |
2654 | .fips_allowed = 1, | |
2655 | .test = alg_test_null, | |
2656 | }, { | |
2657 | .alg = "drbg_pr_ctr_aes256", | |
2658 | .fips_allowed = 1, | |
2659 | .test = alg_test_null, | |
2660 | }, { | |
2661 | .alg = "drbg_pr_hmac_sha1", | |
2662 | .fips_allowed = 1, | |
2663 | .test = alg_test_null, | |
2664 | }, { | |
2665 | .alg = "drbg_pr_hmac_sha256", | |
2666 | .test = alg_test_drbg, | |
2667 | .fips_allowed = 1, | |
2668 | .suite = { | |
2669 | .drbg = { | |
2670 | .vecs = drbg_pr_hmac_sha256_tv_template, | |
2671 | .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template) | |
2672 | } | |
2673 | } | |
2674 | }, { | |
2675 | /* covered by drbg_pr_hmac_sha256 test */ | |
2676 | .alg = "drbg_pr_hmac_sha384", | |
2677 | .fips_allowed = 1, | |
2678 | .test = alg_test_null, | |
2679 | }, { | |
2680 | .alg = "drbg_pr_hmac_sha512", | |
2681 | .test = alg_test_null, | |
2682 | .fips_allowed = 1, | |
2683 | }, { | |
2684 | .alg = "drbg_pr_sha1", | |
2685 | .fips_allowed = 1, | |
2686 | .test = alg_test_null, | |
2687 | }, { | |
2688 | .alg = "drbg_pr_sha256", | |
2689 | .test = alg_test_drbg, | |
2690 | .fips_allowed = 1, | |
2691 | .suite = { | |
2692 | .drbg = { | |
2693 | .vecs = drbg_pr_sha256_tv_template, | |
2694 | .count = ARRAY_SIZE(drbg_pr_sha256_tv_template) | |
2695 | } | |
2696 | } | |
2697 | }, { | |
2698 | /* covered by drbg_pr_sha256 test */ | |
2699 | .alg = "drbg_pr_sha384", | |
2700 | .fips_allowed = 1, | |
2701 | .test = alg_test_null, | |
2702 | }, { | |
2703 | .alg = "drbg_pr_sha512", | |
2704 | .fips_allowed = 1, | |
2705 | .test = alg_test_null, | |
863b557a YS |
2706 | }, { |
2707 | .alg = "ecb(__aes-aesni)", | |
2708 | .test = alg_test_null, | |
6c79294f | 2709 | .fips_allowed = 1, |
da7f033d HX |
2710 | }, { |
2711 | .alg = "ecb(aes)", | |
1aa4ecd9 | 2712 | .test = alg_test_skcipher, |
a1915d51 | 2713 | .fips_allowed = 1, |
da7f033d HX |
2714 | .suite = { |
2715 | .cipher = { | |
2716 | .enc = { | |
2717 | .vecs = aes_enc_tv_template, | |
2718 | .count = AES_ENC_TEST_VECTORS | |
2719 | }, | |
2720 | .dec = { | |
2721 | .vecs = aes_dec_tv_template, | |
2722 | .count = AES_DEC_TEST_VECTORS | |
2723 | } | |
2724 | } | |
2725 | } | |
2726 | }, { | |
2727 | .alg = "ecb(anubis)", | |
1aa4ecd9 | 2728 | .test = alg_test_skcipher, |
da7f033d HX |
2729 | .suite = { |
2730 | .cipher = { | |
2731 | .enc = { | |
2732 | .vecs = anubis_enc_tv_template, | |
2733 | .count = ANUBIS_ENC_TEST_VECTORS | |
2734 | }, | |
2735 | .dec = { | |
2736 | .vecs = anubis_dec_tv_template, | |
2737 | .count = ANUBIS_DEC_TEST_VECTORS | |
2738 | } | |
2739 | } | |
2740 | } | |
2741 | }, { | |
2742 | .alg = "ecb(arc4)", | |
1aa4ecd9 | 2743 | .test = alg_test_skcipher, |
da7f033d HX |
2744 | .suite = { |
2745 | .cipher = { | |
2746 | .enc = { | |
2747 | .vecs = arc4_enc_tv_template, | |
2748 | .count = ARC4_ENC_TEST_VECTORS | |
2749 | }, | |
2750 | .dec = { | |
2751 | .vecs = arc4_dec_tv_template, | |
2752 | .count = ARC4_DEC_TEST_VECTORS | |
2753 | } | |
2754 | } | |
2755 | } | |
2756 | }, { | |
2757 | .alg = "ecb(blowfish)", | |
1aa4ecd9 | 2758 | .test = alg_test_skcipher, |
da7f033d HX |
2759 | .suite = { |
2760 | .cipher = { | |
2761 | .enc = { | |
2762 | .vecs = bf_enc_tv_template, | |
2763 | .count = BF_ENC_TEST_VECTORS | |
2764 | }, | |
2765 | .dec = { | |
2766 | .vecs = bf_dec_tv_template, | |
2767 | .count = BF_DEC_TEST_VECTORS | |
2768 | } | |
2769 | } | |
2770 | } | |
2771 | }, { | |
2772 | .alg = "ecb(camellia)", | |
1aa4ecd9 | 2773 | .test = alg_test_skcipher, |
da7f033d HX |
2774 | .suite = { |
2775 | .cipher = { | |
2776 | .enc = { | |
2777 | .vecs = camellia_enc_tv_template, | |
2778 | .count = CAMELLIA_ENC_TEST_VECTORS | |
2779 | }, | |
2780 | .dec = { | |
2781 | .vecs = camellia_dec_tv_template, | |
2782 | .count = CAMELLIA_DEC_TEST_VECTORS | |
2783 | } | |
2784 | } | |
2785 | } | |
2786 | }, { | |
2787 | .alg = "ecb(cast5)", | |
1aa4ecd9 | 2788 | .test = alg_test_skcipher, |
da7f033d HX |
2789 | .suite = { |
2790 | .cipher = { | |
2791 | .enc = { | |
2792 | .vecs = cast5_enc_tv_template, | |
2793 | .count = CAST5_ENC_TEST_VECTORS | |
2794 | }, | |
2795 | .dec = { | |
2796 | .vecs = cast5_dec_tv_template, | |
2797 | .count = CAST5_DEC_TEST_VECTORS | |
2798 | } | |
2799 | } | |
2800 | } | |
2801 | }, { | |
2802 | .alg = "ecb(cast6)", | |
1aa4ecd9 | 2803 | .test = alg_test_skcipher, |
da7f033d HX |
2804 | .suite = { |
2805 | .cipher = { | |
2806 | .enc = { | |
2807 | .vecs = cast6_enc_tv_template, | |
2808 | .count = CAST6_ENC_TEST_VECTORS | |
2809 | }, | |
2810 | .dec = { | |
2811 | .vecs = cast6_dec_tv_template, | |
2812 | .count = CAST6_DEC_TEST_VECTORS | |
2813 | } | |
2814 | } | |
2815 | } | |
e448370d JK |
2816 | }, { |
2817 | .alg = "ecb(cipher_null)", | |
2818 | .test = alg_test_null, | |
da7f033d HX |
2819 | }, { |
2820 | .alg = "ecb(des)", | |
1aa4ecd9 | 2821 | .test = alg_test_skcipher, |
a1915d51 | 2822 | .fips_allowed = 1, |
da7f033d HX |
2823 | .suite = { |
2824 | .cipher = { | |
2825 | .enc = { | |
2826 | .vecs = des_enc_tv_template, | |
2827 | .count = DES_ENC_TEST_VECTORS | |
2828 | }, | |
2829 | .dec = { | |
2830 | .vecs = des_dec_tv_template, | |
2831 | .count = DES_DEC_TEST_VECTORS | |
2832 | } | |
2833 | } | |
2834 | } | |
2835 | }, { | |
2836 | .alg = "ecb(des3_ede)", | |
1aa4ecd9 | 2837 | .test = alg_test_skcipher, |
a1915d51 | 2838 | .fips_allowed = 1, |
da7f033d HX |
2839 | .suite = { |
2840 | .cipher = { | |
2841 | .enc = { | |
2842 | .vecs = des3_ede_enc_tv_template, | |
2843 | .count = DES3_EDE_ENC_TEST_VECTORS | |
2844 | }, | |
2845 | .dec = { | |
2846 | .vecs = des3_ede_dec_tv_template, | |
2847 | .count = DES3_EDE_DEC_TEST_VECTORS | |
2848 | } | |
2849 | } | |
2850 | } | |
66e5bd00 JK |
2851 | }, { |
2852 | .alg = "ecb(fcrypt)", | |
2853 | .test = alg_test_skcipher, | |
2854 | .suite = { | |
2855 | .cipher = { | |
2856 | .enc = { | |
2857 | .vecs = fcrypt_pcbc_enc_tv_template, | |
2858 | .count = 1 | |
2859 | }, | |
2860 | .dec = { | |
2861 | .vecs = fcrypt_pcbc_dec_tv_template, | |
2862 | .count = 1 | |
2863 | } | |
2864 | } | |
2865 | } | |
da7f033d HX |
2866 | }, { |
2867 | .alg = "ecb(khazad)", | |
1aa4ecd9 | 2868 | .test = alg_test_skcipher, |
da7f033d HX |
2869 | .suite = { |
2870 | .cipher = { | |
2871 | .enc = { | |
2872 | .vecs = khazad_enc_tv_template, | |
2873 | .count = KHAZAD_ENC_TEST_VECTORS | |
2874 | }, | |
2875 | .dec = { | |
2876 | .vecs = khazad_dec_tv_template, | |
2877 | .count = KHAZAD_DEC_TEST_VECTORS | |
2878 | } | |
2879 | } | |
2880 | } | |
2881 | }, { | |
2882 | .alg = "ecb(seed)", | |
1aa4ecd9 | 2883 | .test = alg_test_skcipher, |
da7f033d HX |
2884 | .suite = { |
2885 | .cipher = { | |
2886 | .enc = { | |
2887 | .vecs = seed_enc_tv_template, | |
2888 | .count = SEED_ENC_TEST_VECTORS | |
2889 | }, | |
2890 | .dec = { | |
2891 | .vecs = seed_dec_tv_template, | |
2892 | .count = SEED_DEC_TEST_VECTORS | |
2893 | } | |
2894 | } | |
2895 | } | |
2896 | }, { | |
2897 | .alg = "ecb(serpent)", | |
1aa4ecd9 | 2898 | .test = alg_test_skcipher, |
da7f033d HX |
2899 | .suite = { |
2900 | .cipher = { | |
2901 | .enc = { | |
2902 | .vecs = serpent_enc_tv_template, | |
2903 | .count = SERPENT_ENC_TEST_VECTORS | |
2904 | }, | |
2905 | .dec = { | |
2906 | .vecs = serpent_dec_tv_template, | |
2907 | .count = SERPENT_DEC_TEST_VECTORS | |
2908 | } | |
2909 | } | |
2910 | } | |
2911 | }, { | |
2912 | .alg = "ecb(tea)", | |
1aa4ecd9 | 2913 | .test = alg_test_skcipher, |
da7f033d HX |
2914 | .suite = { |
2915 | .cipher = { | |
2916 | .enc = { | |
2917 | .vecs = tea_enc_tv_template, | |
2918 | .count = TEA_ENC_TEST_VECTORS | |
2919 | }, | |
2920 | .dec = { | |
2921 | .vecs = tea_dec_tv_template, | |
2922 | .count = TEA_DEC_TEST_VECTORS | |
2923 | } | |
2924 | } | |
2925 | } | |
2926 | }, { | |
2927 | .alg = "ecb(tnepres)", | |
1aa4ecd9 | 2928 | .test = alg_test_skcipher, |
da7f033d HX |
2929 | .suite = { |
2930 | .cipher = { | |
2931 | .enc = { | |
2932 | .vecs = tnepres_enc_tv_template, | |
2933 | .count = TNEPRES_ENC_TEST_VECTORS | |
2934 | }, | |
2935 | .dec = { | |
2936 | .vecs = tnepres_dec_tv_template, | |
2937 | .count = TNEPRES_DEC_TEST_VECTORS | |
2938 | } | |
2939 | } | |
2940 | } | |
2941 | }, { | |
2942 | .alg = "ecb(twofish)", | |
1aa4ecd9 | 2943 | .test = alg_test_skcipher, |
da7f033d HX |
2944 | .suite = { |
2945 | .cipher = { | |
2946 | .enc = { | |
2947 | .vecs = tf_enc_tv_template, | |
2948 | .count = TF_ENC_TEST_VECTORS | |
2949 | }, | |
2950 | .dec = { | |
2951 | .vecs = tf_dec_tv_template, | |
2952 | .count = TF_DEC_TEST_VECTORS | |
2953 | } | |
2954 | } | |
2955 | } | |
2956 | }, { | |
2957 | .alg = "ecb(xeta)", | |
1aa4ecd9 | 2958 | .test = alg_test_skcipher, |
da7f033d HX |
2959 | .suite = { |
2960 | .cipher = { | |
2961 | .enc = { | |
2962 | .vecs = xeta_enc_tv_template, | |
2963 | .count = XETA_ENC_TEST_VECTORS | |
2964 | }, | |
2965 | .dec = { | |
2966 | .vecs = xeta_dec_tv_template, | |
2967 | .count = XETA_DEC_TEST_VECTORS | |
2968 | } | |
2969 | } | |
2970 | } | |
2971 | }, { | |
2972 | .alg = "ecb(xtea)", | |
1aa4ecd9 | 2973 | .test = alg_test_skcipher, |
da7f033d HX |
2974 | .suite = { |
2975 | .cipher = { | |
2976 | .enc = { | |
2977 | .vecs = xtea_enc_tv_template, | |
2978 | .count = XTEA_ENC_TEST_VECTORS | |
2979 | }, | |
2980 | .dec = { | |
2981 | .vecs = xtea_dec_tv_template, | |
2982 | .count = XTEA_DEC_TEST_VECTORS | |
2983 | } | |
2984 | } | |
2985 | } | |
2986 | }, { | |
2987 | .alg = "gcm(aes)", | |
2988 | .test = alg_test_aead, | |
a1915d51 | 2989 | .fips_allowed = 1, |
da7f033d HX |
2990 | .suite = { |
2991 | .aead = { | |
2992 | .enc = { | |
2993 | .vecs = aes_gcm_enc_tv_template, | |
2994 | .count = AES_GCM_ENC_TEST_VECTORS | |
2995 | }, | |
2996 | .dec = { | |
2997 | .vecs = aes_gcm_dec_tv_template, | |
2998 | .count = AES_GCM_DEC_TEST_VECTORS | |
2999 | } | |
3000 | } | |
3001 | } | |
507069c9 YS |
3002 | }, { |
3003 | .alg = "ghash", | |
3004 | .test = alg_test_hash, | |
18c0ebd2 | 3005 | .fips_allowed = 1, |
507069c9 YS |
3006 | .suite = { |
3007 | .hash = { | |
3008 | .vecs = ghash_tv_template, | |
3009 | .count = GHASH_TEST_VECTORS | |
3010 | } | |
3011 | } | |
a482b081 SZ |
3012 | }, { |
3013 | .alg = "hmac(crc32)", | |
3014 | .test = alg_test_hash, | |
3015 | .suite = { | |
3016 | .hash = { | |
3017 | .vecs = bfin_crc_tv_template, | |
3018 | .count = BFIN_CRC_TEST_VECTORS | |
3019 | } | |
3020 | } | |
da7f033d HX |
3021 | }, { |
3022 | .alg = "hmac(md5)", | |
3023 | .test = alg_test_hash, | |
3024 | .suite = { | |
3025 | .hash = { | |
3026 | .vecs = hmac_md5_tv_template, | |
3027 | .count = HMAC_MD5_TEST_VECTORS | |
3028 | } | |
3029 | } | |
3030 | }, { | |
3031 | .alg = "hmac(rmd128)", | |
3032 | .test = alg_test_hash, | |
3033 | .suite = { | |
3034 | .hash = { | |
3035 | .vecs = hmac_rmd128_tv_template, | |
3036 | .count = HMAC_RMD128_TEST_VECTORS | |
3037 | } | |
3038 | } | |
3039 | }, { | |
3040 | .alg = "hmac(rmd160)", | |
3041 | .test = alg_test_hash, | |
3042 | .suite = { | |
3043 | .hash = { | |
3044 | .vecs = hmac_rmd160_tv_template, | |
3045 | .count = HMAC_RMD160_TEST_VECTORS | |
3046 | } | |
3047 | } | |
3048 | }, { | |
3049 | .alg = "hmac(sha1)", | |
3050 | .test = alg_test_hash, | |
a1915d51 | 3051 | .fips_allowed = 1, |
da7f033d HX |
3052 | .suite = { |
3053 | .hash = { | |
3054 | .vecs = hmac_sha1_tv_template, | |
3055 | .count = HMAC_SHA1_TEST_VECTORS | |
3056 | } | |
3057 | } | |
3058 | }, { | |
3059 | .alg = "hmac(sha224)", | |
3060 | .test = alg_test_hash, | |
a1915d51 | 3061 | .fips_allowed = 1, |
da7f033d HX |
3062 | .suite = { |
3063 | .hash = { | |
3064 | .vecs = hmac_sha224_tv_template, | |
3065 | .count = HMAC_SHA224_TEST_VECTORS | |
3066 | } | |
3067 | } | |
3068 | }, { | |
3069 | .alg = "hmac(sha256)", | |
3070 | .test = alg_test_hash, | |
a1915d51 | 3071 | .fips_allowed = 1, |
da7f033d HX |
3072 | .suite = { |
3073 | .hash = { | |
3074 | .vecs = hmac_sha256_tv_template, | |
3075 | .count = HMAC_SHA256_TEST_VECTORS | |
3076 | } | |
3077 | } | |
3078 | }, { | |
3079 | .alg = "hmac(sha384)", | |
3080 | .test = alg_test_hash, | |
a1915d51 | 3081 | .fips_allowed = 1, |
da7f033d HX |
3082 | .suite = { |
3083 | .hash = { | |
3084 | .vecs = hmac_sha384_tv_template, | |
3085 | .count = HMAC_SHA384_TEST_VECTORS | |
3086 | } | |
3087 | } | |
3088 | }, { | |
3089 | .alg = "hmac(sha512)", | |
3090 | .test = alg_test_hash, | |
a1915d51 | 3091 | .fips_allowed = 1, |
da7f033d HX |
3092 | .suite = { |
3093 | .hash = { | |
3094 | .vecs = hmac_sha512_tv_template, | |
3095 | .count = HMAC_SHA512_TEST_VECTORS | |
3096 | } | |
3097 | } | |
3098 | }, { | |
3099 | .alg = "lrw(aes)", | |
1aa4ecd9 | 3100 | .test = alg_test_skcipher, |
da7f033d HX |
3101 | .suite = { |
3102 | .cipher = { | |
3103 | .enc = { | |
3104 | .vecs = aes_lrw_enc_tv_template, | |
3105 | .count = AES_LRW_ENC_TEST_VECTORS | |
3106 | }, | |
3107 | .dec = { | |
3108 | .vecs = aes_lrw_dec_tv_template, | |
3109 | .count = AES_LRW_DEC_TEST_VECTORS | |
3110 | } | |
3111 | } | |
3112 | } | |
0840605e JK |
3113 | }, { |
3114 | .alg = "lrw(camellia)", | |
3115 | .test = alg_test_skcipher, | |
3116 | .suite = { | |
3117 | .cipher = { | |
3118 | .enc = { | |
3119 | .vecs = camellia_lrw_enc_tv_template, | |
3120 | .count = CAMELLIA_LRW_ENC_TEST_VECTORS | |
3121 | }, | |
3122 | .dec = { | |
3123 | .vecs = camellia_lrw_dec_tv_template, | |
3124 | .count = CAMELLIA_LRW_DEC_TEST_VECTORS | |
3125 | } | |
3126 | } | |
3127 | } | |
9b8b0405 JG |
3128 | }, { |
3129 | .alg = "lrw(cast6)", | |
3130 | .test = alg_test_skcipher, | |
3131 | .suite = { | |
3132 | .cipher = { | |
3133 | .enc = { | |
3134 | .vecs = cast6_lrw_enc_tv_template, | |
3135 | .count = CAST6_LRW_ENC_TEST_VECTORS | |
3136 | }, | |
3137 | .dec = { | |
3138 | .vecs = cast6_lrw_dec_tv_template, | |
3139 | .count = CAST6_LRW_DEC_TEST_VECTORS | |
3140 | } | |
3141 | } | |
3142 | } | |
d7bfc0fa JK |
3143 | }, { |
3144 | .alg = "lrw(serpent)", | |
3145 | .test = alg_test_skcipher, | |
3146 | .suite = { | |
3147 | .cipher = { | |
3148 | .enc = { | |
3149 | .vecs = serpent_lrw_enc_tv_template, | |
3150 | .count = SERPENT_LRW_ENC_TEST_VECTORS | |
3151 | }, | |
3152 | .dec = { | |
3153 | .vecs = serpent_lrw_dec_tv_template, | |
3154 | .count = SERPENT_LRW_DEC_TEST_VECTORS | |
3155 | } | |
3156 | } | |
3157 | } | |
0b2a1551 JK |
3158 | }, { |
3159 | .alg = "lrw(twofish)", | |
3160 | .test = alg_test_skcipher, | |
3161 | .suite = { | |
3162 | .cipher = { | |
3163 | .enc = { | |
3164 | .vecs = tf_lrw_enc_tv_template, | |
3165 | .count = TF_LRW_ENC_TEST_VECTORS | |
3166 | }, | |
3167 | .dec = { | |
3168 | .vecs = tf_lrw_dec_tv_template, | |
3169 | .count = TF_LRW_DEC_TEST_VECTORS | |
3170 | } | |
3171 | } | |
3172 | } | |
1443cc9b KK |
3173 | }, { |
3174 | .alg = "lz4", | |
3175 | .test = alg_test_comp, | |
3176 | .fips_allowed = 1, | |
3177 | .suite = { | |
3178 | .comp = { | |
3179 | .comp = { | |
3180 | .vecs = lz4_comp_tv_template, | |
3181 | .count = LZ4_COMP_TEST_VECTORS | |
3182 | }, | |
3183 | .decomp = { | |
3184 | .vecs = lz4_decomp_tv_template, | |
3185 | .count = LZ4_DECOMP_TEST_VECTORS | |
3186 | } | |
3187 | } | |
3188 | } | |
3189 | }, { | |
3190 | .alg = "lz4hc", | |
3191 | .test = alg_test_comp, | |
3192 | .fips_allowed = 1, | |
3193 | .suite = { | |
3194 | .comp = { | |
3195 | .comp = { | |
3196 | .vecs = lz4hc_comp_tv_template, | |
3197 | .count = LZ4HC_COMP_TEST_VECTORS | |
3198 | }, | |
3199 | .decomp = { | |
3200 | .vecs = lz4hc_decomp_tv_template, | |
3201 | .count = LZ4HC_DECOMP_TEST_VECTORS | |
3202 | } | |
3203 | } | |
3204 | } | |
da7f033d HX |
3205 | }, { |
3206 | .alg = "lzo", | |
3207 | .test = alg_test_comp, | |
0818904d | 3208 | .fips_allowed = 1, |
da7f033d HX |
3209 | .suite = { |
3210 | .comp = { | |
3211 | .comp = { | |
3212 | .vecs = lzo_comp_tv_template, | |
3213 | .count = LZO_COMP_TEST_VECTORS | |
3214 | }, | |
3215 | .decomp = { | |
3216 | .vecs = lzo_decomp_tv_template, | |
3217 | .count = LZO_DECOMP_TEST_VECTORS | |
3218 | } | |
3219 | } | |
3220 | } | |
3221 | }, { | |
3222 | .alg = "md4", | |
3223 | .test = alg_test_hash, | |
3224 | .suite = { | |
3225 | .hash = { | |
3226 | .vecs = md4_tv_template, | |
3227 | .count = MD4_TEST_VECTORS | |
3228 | } | |
3229 | } | |
3230 | }, { | |
3231 | .alg = "md5", | |
3232 | .test = alg_test_hash, | |
3233 | .suite = { | |
3234 | .hash = { | |
3235 | .vecs = md5_tv_template, | |
3236 | .count = MD5_TEST_VECTORS | |
3237 | } | |
3238 | } | |
3239 | }, { | |
3240 | .alg = "michael_mic", | |
3241 | .test = alg_test_hash, | |
3242 | .suite = { | |
3243 | .hash = { | |
3244 | .vecs = michael_mic_tv_template, | |
3245 | .count = MICHAEL_MIC_TEST_VECTORS | |
3246 | } | |
3247 | } | |
ba0e14ac PS |
3248 | }, { |
3249 | .alg = "ofb(aes)", | |
3250 | .test = alg_test_skcipher, | |
3251 | .fips_allowed = 1, | |
3252 | .suite = { | |
3253 | .cipher = { | |
3254 | .enc = { | |
3255 | .vecs = aes_ofb_enc_tv_template, | |
3256 | .count = AES_OFB_ENC_TEST_VECTORS | |
3257 | }, | |
3258 | .dec = { | |
3259 | .vecs = aes_ofb_dec_tv_template, | |
3260 | .count = AES_OFB_DEC_TEST_VECTORS | |
3261 | } | |
3262 | } | |
3263 | } | |
da7f033d HX |
3264 | }, { |
3265 | .alg = "pcbc(fcrypt)", | |
1aa4ecd9 | 3266 | .test = alg_test_skcipher, |
da7f033d HX |
3267 | .suite = { |
3268 | .cipher = { | |
3269 | .enc = { | |
3270 | .vecs = fcrypt_pcbc_enc_tv_template, | |
3271 | .count = FCRYPT_ENC_TEST_VECTORS | |
3272 | }, | |
3273 | .dec = { | |
3274 | .vecs = fcrypt_pcbc_dec_tv_template, | |
3275 | .count = FCRYPT_DEC_TEST_VECTORS | |
3276 | } | |
3277 | } | |
3278 | } | |
3279 | }, { | |
3280 | .alg = "rfc3686(ctr(aes))", | |
1aa4ecd9 | 3281 | .test = alg_test_skcipher, |
a1915d51 | 3282 | .fips_allowed = 1, |
da7f033d HX |
3283 | .suite = { |
3284 | .cipher = { | |
3285 | .enc = { | |
f7cb80f2 JW |
3286 | .vecs = aes_ctr_rfc3686_enc_tv_template, |
3287 | .count = AES_CTR_3686_ENC_TEST_VECTORS | |
da7f033d HX |
3288 | }, |
3289 | .dec = { | |
f7cb80f2 JW |
3290 | .vecs = aes_ctr_rfc3686_dec_tv_template, |
3291 | .count = AES_CTR_3686_DEC_TEST_VECTORS | |
da7f033d HX |
3292 | } |
3293 | } | |
3294 | } | |
5d667322 | 3295 | }, { |
69435b94 AH |
3296 | .alg = "rfc4106(gcm(aes))", |
3297 | .test = alg_test_aead, | |
db71f29a | 3298 | .fips_allowed = 1, |
69435b94 AH |
3299 | .suite = { |
3300 | .aead = { | |
3301 | .enc = { | |
3302 | .vecs = aes_gcm_rfc4106_enc_tv_template, | |
3303 | .count = AES_GCM_4106_ENC_TEST_VECTORS | |
3304 | }, | |
3305 | .dec = { | |
3306 | .vecs = aes_gcm_rfc4106_dec_tv_template, | |
3307 | .count = AES_GCM_4106_DEC_TEST_VECTORS | |
3308 | } | |
3309 | } | |
3310 | } | |
3311 | }, { | |
5d667322 JW |
3312 | .alg = "rfc4309(ccm(aes))", |
3313 | .test = alg_test_aead, | |
a1915d51 | 3314 | .fips_allowed = 1, |
5d667322 JW |
3315 | .suite = { |
3316 | .aead = { | |
3317 | .enc = { | |
3318 | .vecs = aes_ccm_rfc4309_enc_tv_template, | |
3319 | .count = AES_CCM_4309_ENC_TEST_VECTORS | |
3320 | }, | |
3321 | .dec = { | |
3322 | .vecs = aes_ccm_rfc4309_dec_tv_template, | |
3323 | .count = AES_CCM_4309_DEC_TEST_VECTORS | |
3324 | } | |
3325 | } | |
3326 | } | |
e9b7441a JK |
3327 | }, { |
3328 | .alg = "rfc4543(gcm(aes))", | |
3329 | .test = alg_test_aead, | |
3330 | .suite = { | |
3331 | .aead = { | |
3332 | .enc = { | |
3333 | .vecs = aes_gcm_rfc4543_enc_tv_template, | |
3334 | .count = AES_GCM_4543_ENC_TEST_VECTORS | |
3335 | }, | |
3336 | .dec = { | |
3337 | .vecs = aes_gcm_rfc4543_dec_tv_template, | |
3338 | .count = AES_GCM_4543_DEC_TEST_VECTORS | |
3339 | }, | |
3340 | } | |
3341 | } | |
da7f033d HX |
3342 | }, { |
3343 | .alg = "rmd128", | |
3344 | .test = alg_test_hash, | |
3345 | .suite = { | |
3346 | .hash = { | |
3347 | .vecs = rmd128_tv_template, | |
3348 | .count = RMD128_TEST_VECTORS | |
3349 | } | |
3350 | } | |
3351 | }, { | |
3352 | .alg = "rmd160", | |
3353 | .test = alg_test_hash, | |
3354 | .suite = { | |
3355 | .hash = { | |
3356 | .vecs = rmd160_tv_template, | |
3357 | .count = RMD160_TEST_VECTORS | |
3358 | } | |
3359 | } | |
3360 | }, { | |
3361 | .alg = "rmd256", | |
3362 | .test = alg_test_hash, | |
3363 | .suite = { | |
3364 | .hash = { | |
3365 | .vecs = rmd256_tv_template, | |
3366 | .count = RMD256_TEST_VECTORS | |
3367 | } | |
3368 | } | |
3369 | }, { | |
3370 | .alg = "rmd320", | |
3371 | .test = alg_test_hash, | |
3372 | .suite = { | |
3373 | .hash = { | |
3374 | .vecs = rmd320_tv_template, | |
3375 | .count = RMD320_TEST_VECTORS | |
3376 | } | |
3377 | } | |
3378 | }, { | |
3379 | .alg = "salsa20", | |
1aa4ecd9 | 3380 | .test = alg_test_skcipher, |
da7f033d HX |
3381 | .suite = { |
3382 | .cipher = { | |
3383 | .enc = { | |
3384 | .vecs = salsa20_stream_enc_tv_template, | |
3385 | .count = SALSA20_STREAM_ENC_TEST_VECTORS | |
3386 | } | |
3387 | } | |
3388 | } | |
3389 | }, { | |
3390 | .alg = "sha1", | |
3391 | .test = alg_test_hash, | |
a1915d51 | 3392 | .fips_allowed = 1, |
da7f033d HX |
3393 | .suite = { |
3394 | .hash = { | |
3395 | .vecs = sha1_tv_template, | |
3396 | .count = SHA1_TEST_VECTORS | |
3397 | } | |
3398 | } | |
3399 | }, { | |
3400 | .alg = "sha224", | |
3401 | .test = alg_test_hash, | |
a1915d51 | 3402 | .fips_allowed = 1, |
da7f033d HX |
3403 | .suite = { |
3404 | .hash = { | |
3405 | .vecs = sha224_tv_template, | |
3406 | .count = SHA224_TEST_VECTORS | |
3407 | } | |
3408 | } | |
3409 | }, { | |
3410 | .alg = "sha256", | |
3411 | .test = alg_test_hash, | |
a1915d51 | 3412 | .fips_allowed = 1, |
da7f033d HX |
3413 | .suite = { |
3414 | .hash = { | |
3415 | .vecs = sha256_tv_template, | |
3416 | .count = SHA256_TEST_VECTORS | |
3417 | } | |
3418 | } | |
3419 | }, { | |
3420 | .alg = "sha384", | |
3421 | .test = alg_test_hash, | |
a1915d51 | 3422 | .fips_allowed = 1, |
da7f033d HX |
3423 | .suite = { |
3424 | .hash = { | |
3425 | .vecs = sha384_tv_template, | |
3426 | .count = SHA384_TEST_VECTORS | |
3427 | } | |
3428 | } | |
3429 | }, { | |
3430 | .alg = "sha512", | |
3431 | .test = alg_test_hash, | |
a1915d51 | 3432 | .fips_allowed = 1, |
da7f033d HX |
3433 | .suite = { |
3434 | .hash = { | |
3435 | .vecs = sha512_tv_template, | |
3436 | .count = SHA512_TEST_VECTORS | |
3437 | } | |
3438 | } | |
3439 | }, { | |
3440 | .alg = "tgr128", | |
3441 | .test = alg_test_hash, | |
3442 | .suite = { | |
3443 | .hash = { | |
3444 | .vecs = tgr128_tv_template, | |
3445 | .count = TGR128_TEST_VECTORS | |
3446 | } | |
3447 | } | |
3448 | }, { | |
3449 | .alg = "tgr160", | |
3450 | .test = alg_test_hash, | |
3451 | .suite = { | |
3452 | .hash = { | |
3453 | .vecs = tgr160_tv_template, | |
3454 | .count = TGR160_TEST_VECTORS | |
3455 | } | |
3456 | } | |
3457 | }, { | |
3458 | .alg = "tgr192", | |
3459 | .test = alg_test_hash, | |
3460 | .suite = { | |
3461 | .hash = { | |
3462 | .vecs = tgr192_tv_template, | |
3463 | .count = TGR192_TEST_VECTORS | |
3464 | } | |
3465 | } | |
f1939f7c SW |
3466 | }, { |
3467 | .alg = "vmac(aes)", | |
3468 | .test = alg_test_hash, | |
3469 | .suite = { | |
3470 | .hash = { | |
3471 | .vecs = aes_vmac128_tv_template, | |
3472 | .count = VMAC_AES_TEST_VECTORS | |
3473 | } | |
3474 | } | |
da7f033d HX |
3475 | }, { |
3476 | .alg = "wp256", | |
3477 | .test = alg_test_hash, | |
3478 | .suite = { | |
3479 | .hash = { | |
3480 | .vecs = wp256_tv_template, | |
3481 | .count = WP256_TEST_VECTORS | |
3482 | } | |
3483 | } | |
3484 | }, { | |
3485 | .alg = "wp384", | |
3486 | .test = alg_test_hash, | |
3487 | .suite = { | |
3488 | .hash = { | |
3489 | .vecs = wp384_tv_template, | |
3490 | .count = WP384_TEST_VECTORS | |
3491 | } | |
3492 | } | |
3493 | }, { | |
3494 | .alg = "wp512", | |
3495 | .test = alg_test_hash, | |
3496 | .suite = { | |
3497 | .hash = { | |
3498 | .vecs = wp512_tv_template, | |
3499 | .count = WP512_TEST_VECTORS | |
3500 | } | |
3501 | } | |
3502 | }, { | |
3503 | .alg = "xcbc(aes)", | |
3504 | .test = alg_test_hash, | |
3505 | .suite = { | |
3506 | .hash = { | |
3507 | .vecs = aes_xcbc128_tv_template, | |
3508 | .count = XCBC_AES_TEST_VECTORS | |
3509 | } | |
3510 | } | |
3511 | }, { | |
3512 | .alg = "xts(aes)", | |
1aa4ecd9 | 3513 | .test = alg_test_skcipher, |
2918aa8d | 3514 | .fips_allowed = 1, |
da7f033d HX |
3515 | .suite = { |
3516 | .cipher = { | |
3517 | .enc = { | |
3518 | .vecs = aes_xts_enc_tv_template, | |
3519 | .count = AES_XTS_ENC_TEST_VECTORS | |
3520 | }, | |
3521 | .dec = { | |
3522 | .vecs = aes_xts_dec_tv_template, | |
3523 | .count = AES_XTS_DEC_TEST_VECTORS | |
3524 | } | |
3525 | } | |
3526 | } | |
0840605e JK |
3527 | }, { |
3528 | .alg = "xts(camellia)", | |
3529 | .test = alg_test_skcipher, | |
3530 | .suite = { | |
3531 | .cipher = { | |
3532 | .enc = { | |
3533 | .vecs = camellia_xts_enc_tv_template, | |
3534 | .count = CAMELLIA_XTS_ENC_TEST_VECTORS | |
3535 | }, | |
3536 | .dec = { | |
3537 | .vecs = camellia_xts_dec_tv_template, | |
3538 | .count = CAMELLIA_XTS_DEC_TEST_VECTORS | |
3539 | } | |
3540 | } | |
3541 | } | |
9b8b0405 JG |
3542 | }, { |
3543 | .alg = "xts(cast6)", | |
3544 | .test = alg_test_skcipher, | |
3545 | .suite = { | |
3546 | .cipher = { | |
3547 | .enc = { | |
3548 | .vecs = cast6_xts_enc_tv_template, | |
3549 | .count = CAST6_XTS_ENC_TEST_VECTORS | |
3550 | }, | |
3551 | .dec = { | |
3552 | .vecs = cast6_xts_dec_tv_template, | |
3553 | .count = CAST6_XTS_DEC_TEST_VECTORS | |
3554 | } | |
3555 | } | |
3556 | } | |
18be20b9 JK |
3557 | }, { |
3558 | .alg = "xts(serpent)", | |
3559 | .test = alg_test_skcipher, | |
3560 | .suite = { | |
3561 | .cipher = { | |
3562 | .enc = { | |
3563 | .vecs = serpent_xts_enc_tv_template, | |
3564 | .count = SERPENT_XTS_ENC_TEST_VECTORS | |
3565 | }, | |
3566 | .dec = { | |
3567 | .vecs = serpent_xts_dec_tv_template, | |
3568 | .count = SERPENT_XTS_DEC_TEST_VECTORS | |
3569 | } | |
3570 | } | |
3571 | } | |
aed265b9 JK |
3572 | }, { |
3573 | .alg = "xts(twofish)", | |
3574 | .test = alg_test_skcipher, | |
3575 | .suite = { | |
3576 | .cipher = { | |
3577 | .enc = { | |
3578 | .vecs = tf_xts_enc_tv_template, | |
3579 | .count = TF_XTS_ENC_TEST_VECTORS | |
3580 | }, | |
3581 | .dec = { | |
3582 | .vecs = tf_xts_dec_tv_template, | |
3583 | .count = TF_XTS_DEC_TEST_VECTORS | |
3584 | } | |
3585 | } | |
3586 | } | |
0c01aed5 GU |
3587 | }, { |
3588 | .alg = "zlib", | |
3589 | .test = alg_test_pcomp, | |
0818904d | 3590 | .fips_allowed = 1, |
0c01aed5 GU |
3591 | .suite = { |
3592 | .pcomp = { | |
3593 | .comp = { | |
3594 | .vecs = zlib_comp_tv_template, | |
3595 | .count = ZLIB_COMP_TEST_VECTORS | |
3596 | }, | |
3597 | .decomp = { | |
3598 | .vecs = zlib_decomp_tv_template, | |
3599 | .count = ZLIB_DECOMP_TEST_VECTORS | |
3600 | } | |
3601 | } | |
3602 | } | |
da7f033d HX |
3603 | } |
3604 | }; | |
3605 | ||
5714758b JK |
3606 | static bool alg_test_descs_checked; |
3607 | ||
3608 | static void alg_test_descs_check_order(void) | |
3609 | { | |
3610 | int i; | |
3611 | ||
3612 | /* only check once */ | |
3613 | if (alg_test_descs_checked) | |
3614 | return; | |
3615 | ||
3616 | alg_test_descs_checked = true; | |
3617 | ||
3618 | for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) { | |
3619 | int diff = strcmp(alg_test_descs[i - 1].alg, | |
3620 | alg_test_descs[i].alg); | |
3621 | ||
3622 | if (WARN_ON(diff > 0)) { | |
3623 | pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n", | |
3624 | alg_test_descs[i - 1].alg, | |
3625 | alg_test_descs[i].alg); | |
3626 | } | |
3627 | ||
3628 | if (WARN_ON(diff == 0)) { | |
3629 | pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n", | |
3630 | alg_test_descs[i].alg); | |
3631 | } | |
3632 | } | |
3633 | } | |
3634 | ||
1aa4ecd9 | 3635 | static int alg_find_test(const char *alg) |
da7f033d HX |
3636 | { |
3637 | int start = 0; | |
3638 | int end = ARRAY_SIZE(alg_test_descs); | |
3639 | ||
3640 | while (start < end) { | |
3641 | int i = (start + end) / 2; | |
3642 | int diff = strcmp(alg_test_descs[i].alg, alg); | |
3643 | ||
3644 | if (diff > 0) { | |
3645 | end = i; | |
3646 | continue; | |
3647 | } | |
3648 | ||
3649 | if (diff < 0) { | |
3650 | start = i + 1; | |
3651 | continue; | |
3652 | } | |
3653 | ||
1aa4ecd9 HX |
3654 | return i; |
3655 | } | |
3656 | ||
3657 | return -1; | |
3658 | } | |
3659 | ||
3660 | int alg_test(const char *driver, const char *alg, u32 type, u32 mask) | |
3661 | { | |
3662 | int i; | |
a68f6610 | 3663 | int j; |
d12d6b6d | 3664 | int rc; |
1aa4ecd9 | 3665 | |
5714758b JK |
3666 | alg_test_descs_check_order(); |
3667 | ||
1aa4ecd9 HX |
3668 | if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) { |
3669 | char nalg[CRYPTO_MAX_ALG_NAME]; | |
3670 | ||
3671 | if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >= | |
3672 | sizeof(nalg)) | |
3673 | return -ENAMETOOLONG; | |
3674 | ||
3675 | i = alg_find_test(nalg); | |
3676 | if (i < 0) | |
3677 | goto notest; | |
3678 | ||
a3bef3a3 JW |
3679 | if (fips_enabled && !alg_test_descs[i].fips_allowed) |
3680 | goto non_fips_alg; | |
3681 | ||
941fb328 JW |
3682 | rc = alg_test_cipher(alg_test_descs + i, driver, type, mask); |
3683 | goto test_done; | |
da7f033d HX |
3684 | } |
3685 | ||
1aa4ecd9 | 3686 | i = alg_find_test(alg); |
a68f6610 HX |
3687 | j = alg_find_test(driver); |
3688 | if (i < 0 && j < 0) | |
1aa4ecd9 HX |
3689 | goto notest; |
3690 | ||
a68f6610 HX |
3691 | if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) || |
3692 | (j >= 0 && !alg_test_descs[j].fips_allowed))) | |
a3bef3a3 JW |
3693 | goto non_fips_alg; |
3694 | ||
a68f6610 HX |
3695 | rc = 0; |
3696 | if (i >= 0) | |
3697 | rc |= alg_test_descs[i].test(alg_test_descs + i, driver, | |
3698 | type, mask); | |
032c8cac | 3699 | if (j >= 0 && j != i) |
a68f6610 HX |
3700 | rc |= alg_test_descs[j].test(alg_test_descs + j, driver, |
3701 | type, mask); | |
3702 | ||
941fb328 | 3703 | test_done: |
d12d6b6d NH |
3704 | if (fips_enabled && rc) |
3705 | panic("%s: %s alg self test failed in fips mode!\n", driver, alg); | |
3706 | ||
29ecd4ab | 3707 | if (fips_enabled && !rc) |
3e8cffd4 | 3708 | pr_info("alg: self-tests for %s (%s) passed\n", driver, alg); |
29ecd4ab | 3709 | |
d12d6b6d | 3710 | return rc; |
1aa4ecd9 HX |
3711 | |
3712 | notest: | |
da7f033d HX |
3713 | printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver); |
3714 | return 0; | |
a3bef3a3 JW |
3715 | non_fips_alg: |
3716 | return -EINVAL; | |
da7f033d | 3717 | } |
0b767f96 | 3718 | |
326a6346 | 3719 | #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */ |
0b767f96 | 3720 | |
da7f033d | 3721 | EXPORT_SYMBOL_GPL(alg_test); |