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