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