blob: 62dffa0028acdb54f286d2ca1aa89ca9b422945e [file] [log] [blame]
Herbert Xuda7f0332008-07-31 17:08:25 +08001/*
2 * Algorithm testing framework and tests.
3 *
4 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
5 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
6 * Copyright (c) 2007 Nokia Siemens Networks
7 * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
8 *
Adrian Hoban69435b92010-11-04 15:02:04 -04009 * Updated RFC4106 AES-GCM testing.
10 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
11 * Adrian Hoban <adrian.hoban@intel.com>
12 * Gabriele Paoloni <gabriele.paoloni@intel.com>
13 * Tadeusz Struk (tadeusz.struk@intel.com)
14 * Copyright (c) 2010, Intel Corporation.
15 *
Herbert Xuda7f0332008-07-31 17:08:25 +080016 * 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
Herbert Xu1ce33112015-04-22 15:06:31 +080023#include <crypto/aead.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080024#include <crypto/hash.h>
Herbert Xu12773d92015-08-20 15:21:46 +080025#include <crypto/skcipher.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080026#include <linux/err.h>
Herbert Xu1c41b882015-04-22 13:25:58 +080027#include <linux/fips.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080028#include <linux/module.h>
29#include <linux/scatterlist.h>
30#include <linux/slab.h>
31#include <linux/string.h>
Jarod Wilson7647d6c2009-05-04 19:44:50 +080032#include <crypto/rng.h>
Stephan Mueller64d1cdf2014-05-31 17:25:36 +020033#include <crypto/drbg.h>
Tadeusz Struk946cc462015-06-16 10:31:06 -070034#include <crypto/akcipher.h>
Salvatore Benedetto802c7f12016-06-22 17:49:14 +010035#include <crypto/kpp.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080036
37#include "internal.h"
Alexander Shishkin0b767f92010-06-03 20:53:43 +100038
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +010039static bool notests;
40module_param(notests, bool, 0644);
41MODULE_PARM_DESC(notests, "disable crypto self-tests");
42
Herbert Xu326a6342010-08-06 09:40:28 +080043#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
Alexander Shishkin0b767f92010-06-03 20:53:43 +100044
45/* a perfect nop */
46int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
47{
48 return 0;
49}
50
51#else
52
Herbert Xuda7f0332008-07-31 17:08:25 +080053#include "testmgr.h"
54
55/*
56 * Need slab memory for testing (size in number of pages).
57 */
58#define XBUFSIZE 8
59
60/*
61 * Indexes into the xbuf to simulate cross-page access.
62 */
63#define IDX1 32
64#define IDX2 32400
65#define IDX3 1
66#define IDX4 8193
67#define IDX5 22222
68#define IDX6 17101
69#define IDX7 27333
70#define IDX8 3000
71
72/*
73* Used by test_cipher()
74*/
75#define ENCRYPT 1
76#define DECRYPT 0
77
78struct tcrypt_result {
79 struct completion completion;
80 int err;
81};
82
83struct aead_test_suite {
84 struct {
85 struct aead_testvec *vecs;
86 unsigned int count;
87 } enc, dec;
88};
89
90struct cipher_test_suite {
91 struct {
92 struct cipher_testvec *vecs;
93 unsigned int count;
94 } enc, dec;
95};
96
97struct comp_test_suite {
98 struct {
99 struct comp_testvec *vecs;
100 unsigned int count;
101 } comp, decomp;
102};
103
104struct hash_test_suite {
105 struct hash_testvec *vecs;
106 unsigned int count;
107};
108
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800109struct cprng_test_suite {
110 struct cprng_testvec *vecs;
111 unsigned int count;
112};
113
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200114struct drbg_test_suite {
115 struct drbg_testvec *vecs;
116 unsigned int count;
117};
118
Tadeusz Struk946cc462015-06-16 10:31:06 -0700119struct akcipher_test_suite {
120 struct akcipher_testvec *vecs;
121 unsigned int count;
122};
123
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100124struct kpp_test_suite {
125 struct kpp_testvec *vecs;
126 unsigned int count;
127};
128
Herbert Xuda7f0332008-07-31 17:08:25 +0800129struct alg_test_desc {
130 const char *alg;
131 int (*test)(const struct alg_test_desc *desc, const char *driver,
132 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000133 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800134
135 union {
136 struct aead_test_suite aead;
137 struct cipher_test_suite cipher;
138 struct comp_test_suite comp;
139 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800140 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200141 struct drbg_test_suite drbg;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700142 struct akcipher_test_suite akcipher;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100143 struct kpp_test_suite kpp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800144 } suite;
145};
146
147static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
148
Herbert Xuda7f0332008-07-31 17:08:25 +0800149static void hexdump(unsigned char *buf, unsigned int len)
150{
151 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
152 16, 1,
153 buf, len, false);
154}
155
156static void tcrypt_complete(struct crypto_async_request *req, int err)
157{
158 struct tcrypt_result *res = req->data;
159
160 if (err == -EINPROGRESS)
161 return;
162
163 res->err = err;
164 complete(&res->completion);
165}
166
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800167static int testmgr_alloc_buf(char *buf[XBUFSIZE])
168{
169 int i;
170
171 for (i = 0; i < XBUFSIZE; i++) {
172 buf[i] = (void *)__get_free_page(GFP_KERNEL);
173 if (!buf[i])
174 goto err_free_buf;
175 }
176
177 return 0;
178
179err_free_buf:
180 while (i-- > 0)
181 free_page((unsigned long)buf[i]);
182
183 return -ENOMEM;
184}
185
186static void testmgr_free_buf(char *buf[XBUFSIZE])
187{
188 int i;
189
190 for (i = 0; i < XBUFSIZE; i++)
191 free_page((unsigned long)buf[i]);
192}
193
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300194static int wait_async_op(struct tcrypt_result *tr, int ret)
David S. Millera8f1a052010-05-19 14:12:03 +1000195{
196 if (ret == -EINPROGRESS || ret == -EBUSY) {
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100197 wait_for_completion(&tr->completion);
Wolfram Sang16735d02013-11-14 14:32:02 -0800198 reinit_completion(&tr->completion);
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100199 ret = tr->err;
David S. Millera8f1a052010-05-19 14:12:03 +1000200 }
201 return ret;
202}
203
Wang, Rui Y018ba952016-02-03 18:26:57 +0800204static int ahash_partial_update(struct ahash_request **preq,
205 struct crypto_ahash *tfm, struct hash_testvec *template,
206 void *hash_buff, int k, int temp, struct scatterlist *sg,
207 const char *algo, char *result, struct tcrypt_result *tresult)
208{
209 char *state;
210 struct ahash_request *req;
211 int statesize, ret = -EINVAL;
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200212 const char guard[] = { 0x00, 0xba, 0xad, 0x00 };
Wang, Rui Y018ba952016-02-03 18:26:57 +0800213
214 req = *preq;
215 statesize = crypto_ahash_statesize(
216 crypto_ahash_reqtfm(req));
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200217 state = kmalloc(statesize + sizeof(guard), GFP_KERNEL);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800218 if (!state) {
219 pr_err("alt: hash: Failed to alloc state for %s\n", algo);
220 goto out_nostate;
221 }
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200222 memcpy(state + statesize, guard, sizeof(guard));
Wang, Rui Y018ba952016-02-03 18:26:57 +0800223 ret = crypto_ahash_export(req, state);
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200224 WARN_ON(memcmp(state + statesize, guard, sizeof(guard)));
Wang, Rui Y018ba952016-02-03 18:26:57 +0800225 if (ret) {
226 pr_err("alt: hash: Failed to export() for %s\n", algo);
227 goto out;
228 }
229 ahash_request_free(req);
230 req = ahash_request_alloc(tfm, GFP_KERNEL);
231 if (!req) {
232 pr_err("alg: hash: Failed to alloc request for %s\n", algo);
233 goto out_noreq;
234 }
235 ahash_request_set_callback(req,
236 CRYPTO_TFM_REQ_MAY_BACKLOG,
237 tcrypt_complete, tresult);
238
239 memcpy(hash_buff, template->plaintext + temp,
240 template->tap[k]);
241 sg_init_one(&sg[0], hash_buff, template->tap[k]);
242 ahash_request_set_crypt(req, sg, result, template->tap[k]);
243 ret = crypto_ahash_import(req, state);
244 if (ret) {
245 pr_err("alg: hash: Failed to import() for %s\n", algo);
246 goto out;
247 }
248 ret = wait_async_op(tresult, crypto_ahash_update(req));
249 if (ret)
250 goto out;
251 *preq = req;
252 ret = 0;
253 goto out_noreq;
254out:
255 ahash_request_free(req);
256out_noreq:
257 kfree(state);
258out_nostate:
259 return ret;
260}
261
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300262static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
263 unsigned int tcount, bool use_digest,
264 const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800265{
266 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
267 unsigned int i, j, k, temp;
268 struct scatterlist sg[8];
Horia Geanta29b77e52014-07-23 11:59:38 +0300269 char *result;
270 char *key;
Herbert Xuda7f0332008-07-31 17:08:25 +0800271 struct ahash_request *req;
272 struct tcrypt_result tresult;
Herbert Xuda7f0332008-07-31 17:08:25 +0800273 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800274 char *xbuf[XBUFSIZE];
275 int ret = -ENOMEM;
276
Horia Geanta29b77e52014-07-23 11:59:38 +0300277 result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
278 if (!result)
279 return ret;
280 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
281 if (!key)
282 goto out_nobuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800283 if (testmgr_alloc_buf(xbuf))
284 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800285
286 init_completion(&tresult.completion);
287
288 req = ahash_request_alloc(tfm, GFP_KERNEL);
289 if (!req) {
290 printk(KERN_ERR "alg: hash: Failed to allocate request for "
291 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800292 goto out_noreq;
293 }
294 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
295 tcrypt_complete, &tresult);
296
Herbert Xua0cfae52009-05-29 16:23:12 +1000297 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800298 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000299 if (template[i].np)
300 continue;
301
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300302 ret = -EINVAL;
303 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
304 goto out;
305
Herbert Xua0cfae52009-05-29 16:23:12 +1000306 j++;
Horia Geanta29b77e52014-07-23 11:59:38 +0300307 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800308
309 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300310 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800311
312 memcpy(hash_buff, template[i].plaintext, template[i].psize);
313 sg_init_one(&sg[0], hash_buff, template[i].psize);
314
315 if (template[i].ksize) {
316 crypto_ahash_clear_flags(tfm, ~0);
Horia Geanta29b77e52014-07-23 11:59:38 +0300317 if (template[i].ksize > MAX_KEYLEN) {
318 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
319 j, algo, template[i].ksize, MAX_KEYLEN);
320 ret = -EINVAL;
321 goto out;
322 }
323 memcpy(key, template[i].key, template[i].ksize);
324 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
Herbert Xuda7f0332008-07-31 17:08:25 +0800325 if (ret) {
326 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000327 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800328 -ret);
329 goto out;
330 }
331 }
332
333 ahash_request_set_crypt(req, sg, result, template[i].psize);
David S. Millera8f1a052010-05-19 14:12:03 +1000334 if (use_digest) {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300335 ret = wait_async_op(&tresult, crypto_ahash_digest(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000336 if (ret) {
337 pr_err("alg: hash: digest failed on test %d "
338 "for %s: ret=%d\n", j, algo, -ret);
339 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800340 }
David S. Millera8f1a052010-05-19 14:12:03 +1000341 } else {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300342 ret = wait_async_op(&tresult, crypto_ahash_init(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000343 if (ret) {
344 pr_err("alt: hash: init failed on test %d "
345 "for %s: ret=%d\n", j, algo, -ret);
346 goto out;
347 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300348 ret = wait_async_op(&tresult, crypto_ahash_update(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000349 if (ret) {
350 pr_err("alt: hash: update failed on test %d "
351 "for %s: ret=%d\n", j, algo, -ret);
352 goto out;
353 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300354 ret = wait_async_op(&tresult, crypto_ahash_final(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000355 if (ret) {
356 pr_err("alt: hash: final failed on test %d "
357 "for %s: ret=%d\n", j, algo, -ret);
358 goto out;
359 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800360 }
361
362 if (memcmp(result, template[i].digest,
363 crypto_ahash_digestsize(tfm))) {
364 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000365 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800366 hexdump(result, crypto_ahash_digestsize(tfm));
367 ret = -EINVAL;
368 goto out;
369 }
370 }
371
372 j = 0;
373 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300374 /* alignment tests are only done with continuous buffers */
375 if (align_offset != 0)
376 break;
377
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300378 if (!template[i].np)
379 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800380
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300381 j++;
382 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800383
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300384 temp = 0;
385 sg_init_table(sg, template[i].np);
386 ret = -EINVAL;
387 for (k = 0; k < template[i].np; k++) {
388 if (WARN_ON(offset_in_page(IDX[k]) +
389 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +0800390 goto out;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300391 sg_set_buf(&sg[k],
392 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
393 offset_in_page(IDX[k]),
394 template[i].plaintext + temp,
395 template[i].tap[k]),
396 template[i].tap[k]);
397 temp += template[i].tap[k];
398 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800399
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300400 if (template[i].ksize) {
401 if (template[i].ksize > MAX_KEYLEN) {
402 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
403 j, algo, template[i].ksize, MAX_KEYLEN);
Herbert Xuda7f0332008-07-31 17:08:25 +0800404 ret = -EINVAL;
405 goto out;
406 }
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300407 crypto_ahash_clear_flags(tfm, ~0);
408 memcpy(key, template[i].key, template[i].ksize);
409 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
410
411 if (ret) {
412 printk(KERN_ERR "alg: hash: setkey "
413 "failed on chunking test %d "
414 "for %s: ret=%d\n", j, algo, -ret);
415 goto out;
416 }
417 }
418
419 ahash_request_set_crypt(req, sg, result, template[i].psize);
420 ret = crypto_ahash_digest(req);
421 switch (ret) {
422 case 0:
423 break;
424 case -EINPROGRESS:
425 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100426 wait_for_completion(&tresult.completion);
427 reinit_completion(&tresult.completion);
428 ret = tresult.err;
429 if (!ret)
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300430 break;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300431 /* fall through */
432 default:
433 printk(KERN_ERR "alg: hash: digest failed "
434 "on chunking test %d for %s: "
435 "ret=%d\n", j, algo, -ret);
436 goto out;
437 }
438
439 if (memcmp(result, template[i].digest,
440 crypto_ahash_digestsize(tfm))) {
441 printk(KERN_ERR "alg: hash: Chunking test %d "
442 "failed for %s\n", j, algo);
443 hexdump(result, crypto_ahash_digestsize(tfm));
444 ret = -EINVAL;
445 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800446 }
447 }
448
Wang, Rui Y018ba952016-02-03 18:26:57 +0800449 /* partial update exercise */
450 j = 0;
451 for (i = 0; i < tcount; i++) {
452 /* alignment tests are only done with continuous buffers */
453 if (align_offset != 0)
454 break;
455
456 if (template[i].np < 2)
457 continue;
458
459 j++;
460 memset(result, 0, MAX_DIGEST_SIZE);
461
462 ret = -EINVAL;
463 hash_buff = xbuf[0];
464 memcpy(hash_buff, template[i].plaintext,
465 template[i].tap[0]);
466 sg_init_one(&sg[0], hash_buff, template[i].tap[0]);
467
468 if (template[i].ksize) {
469 crypto_ahash_clear_flags(tfm, ~0);
470 if (template[i].ksize > MAX_KEYLEN) {
471 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
472 j, algo, template[i].ksize, MAX_KEYLEN);
473 ret = -EINVAL;
474 goto out;
475 }
476 memcpy(key, template[i].key, template[i].ksize);
477 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
478 if (ret) {
479 pr_err("alg: hash: setkey failed on test %d for %s: ret=%d\n",
480 j, algo, -ret);
481 goto out;
482 }
483 }
484
485 ahash_request_set_crypt(req, sg, result, template[i].tap[0]);
486 ret = wait_async_op(&tresult, crypto_ahash_init(req));
487 if (ret) {
488 pr_err("alt: hash: init failed on test %d for %s: ret=%d\n",
489 j, algo, -ret);
490 goto out;
491 }
492 ret = wait_async_op(&tresult, crypto_ahash_update(req));
493 if (ret) {
494 pr_err("alt: hash: update failed on test %d for %s: ret=%d\n",
495 j, algo, -ret);
496 goto out;
497 }
498
499 temp = template[i].tap[0];
500 for (k = 1; k < template[i].np; k++) {
501 ret = ahash_partial_update(&req, tfm, &template[i],
502 hash_buff, k, temp, &sg[0], algo, result,
503 &tresult);
504 if (ret) {
505 pr_err("hash: partial update failed on test %d for %s: ret=%d\n",
506 j, algo, -ret);
507 goto out_noreq;
508 }
509 temp += template[i].tap[k];
510 }
511 ret = wait_async_op(&tresult, crypto_ahash_final(req));
512 if (ret) {
513 pr_err("alt: hash: final failed on test %d for %s: ret=%d\n",
514 j, algo, -ret);
515 goto out;
516 }
517 if (memcmp(result, template[i].digest,
518 crypto_ahash_digestsize(tfm))) {
519 pr_err("alg: hash: Partial Test %d failed for %s\n",
520 j, algo);
521 hexdump(result, crypto_ahash_digestsize(tfm));
522 ret = -EINVAL;
523 goto out;
524 }
525 }
526
Herbert Xuda7f0332008-07-31 17:08:25 +0800527 ret = 0;
528
529out:
530 ahash_request_free(req);
531out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800532 testmgr_free_buf(xbuf);
533out_nobuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300534 kfree(key);
535 kfree(result);
Herbert Xuda7f0332008-07-31 17:08:25 +0800536 return ret;
537}
538
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300539static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
540 unsigned int tcount, bool use_digest)
541{
542 unsigned int alignmask;
543 int ret;
544
545 ret = __test_hash(tfm, template, tcount, use_digest, 0);
546 if (ret)
547 return ret;
548
549 /* test unaligned buffers, check with one byte offset */
550 ret = __test_hash(tfm, template, tcount, use_digest, 1);
551 if (ret)
552 return ret;
553
554 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
555 if (alignmask) {
556 /* Check if alignment mask for tfm is correctly set. */
557 ret = __test_hash(tfm, template, tcount, use_digest,
558 alignmask + 1);
559 if (ret)
560 return ret;
561 }
562
563 return 0;
564}
565
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300566static int __test_aead(struct crypto_aead *tfm, int enc,
567 struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300568 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800569{
570 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
571 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800572 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800573 char *q;
574 char *key;
575 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300576 struct scatterlist *sg;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300577 struct scatterlist *sgout;
578 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800579 struct tcrypt_result result;
Cristian Stoica424a5da2015-01-28 11:03:05 +0200580 unsigned int authsize, iv_len;
Herbert Xuda7f0332008-07-31 17:08:25 +0800581 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300582 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800583 void *assoc;
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700584 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800585 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300586 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800587 char *axbuf[XBUFSIZE];
588
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700589 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
590 if (!iv)
591 return ret;
Horia Geanta29b77e52014-07-23 11:59:38 +0300592 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
593 if (!key)
594 goto out_noxbuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800595 if (testmgr_alloc_buf(xbuf))
596 goto out_noxbuf;
597 if (testmgr_alloc_buf(axbuf))
598 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300599 if (diff_dst && testmgr_alloc_buf(xoutbuf))
600 goto out_nooutbuf;
601
602 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
Herbert Xu8a525fc2015-05-27 16:03:43 +0800603 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 4 : 2), GFP_KERNEL);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300604 if (!sg)
605 goto out_nosg;
Herbert Xu8a525fc2015-05-27 16:03:43 +0800606 sgout = &sg[16];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300607
608 if (diff_dst)
609 d = "-ddst";
610 else
611 d = "";
612
Herbert Xuda7f0332008-07-31 17:08:25 +0800613 if (enc == ENCRYPT)
614 e = "encryption";
615 else
616 e = "decryption";
617
618 init_completion(&result.completion);
619
620 req = aead_request_alloc(tfm, GFP_KERNEL);
621 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300622 pr_err("alg: aead%s: Failed to allocate request for %s\n",
623 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800624 goto out;
625 }
626
627 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
628 tcrypt_complete, &result);
629
Jerome Marchandabfa7f42016-02-03 13:58:12 +0100630 iv_len = crypto_aead_ivsize(tfm);
631
Herbert Xuda7f0332008-07-31 17:08:25 +0800632 for (i = 0, j = 0; i < tcount; i++) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300633 if (template[i].np)
634 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800635
Cristian Stoica05b1d332014-07-28 13:11:23 +0300636 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800637
Cristian Stoica05b1d332014-07-28 13:11:23 +0300638 /* some templates have no input data but they will
639 * touch input
640 */
641 input = xbuf[0];
642 input += align_offset;
643 assoc = axbuf[0];
644
645 ret = -EINVAL;
646 if (WARN_ON(align_offset + template[i].ilen >
647 PAGE_SIZE || template[i].alen > PAGE_SIZE))
648 goto out;
649
650 memcpy(input, template[i].input, template[i].ilen);
651 memcpy(assoc, template[i].assoc, template[i].alen);
652 if (template[i].iv)
Cristian Stoica424a5da2015-01-28 11:03:05 +0200653 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300654 else
Cristian Stoica424a5da2015-01-28 11:03:05 +0200655 memset(iv, 0, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300656
657 crypto_aead_clear_flags(tfm, ~0);
658 if (template[i].wk)
659 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
660
661 if (template[i].klen > MAX_KEYLEN) {
662 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
663 d, j, algo, template[i].klen,
664 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +1000665 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300666 goto out;
667 }
668 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +1000669
Cristian Stoica05b1d332014-07-28 13:11:23 +0300670 ret = crypto_aead_setkey(tfm, key, template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +0800671 if (template[i].fail == !ret) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300672 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
673 d, j, algo, crypto_aead_get_flags(tfm));
674 goto out;
675 } else if (ret)
676 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800677
Cristian Stoica05b1d332014-07-28 13:11:23 +0300678 authsize = abs(template[i].rlen - template[i].ilen);
679 ret = crypto_aead_setauthsize(tfm, authsize);
680 if (ret) {
681 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
682 d, authsize, j, algo);
683 goto out;
684 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800685
Herbert Xu8a525fc2015-05-27 16:03:43 +0800686 k = !!template[i].alen;
687 sg_init_table(sg, k + 1);
688 sg_set_buf(&sg[0], assoc, template[i].alen);
689 sg_set_buf(&sg[k], input,
690 template[i].ilen + (enc ? authsize : 0));
691 output = input;
692
Cristian Stoica05b1d332014-07-28 13:11:23 +0300693 if (diff_dst) {
Herbert Xu8a525fc2015-05-27 16:03:43 +0800694 sg_init_table(sgout, k + 1);
695 sg_set_buf(&sgout[0], assoc, template[i].alen);
696
Cristian Stoica05b1d332014-07-28 13:11:23 +0300697 output = xoutbuf[0];
698 output += align_offset;
Herbert Xu8a525fc2015-05-27 16:03:43 +0800699 sg_set_buf(&sgout[k], output,
700 template[i].rlen + (enc ? 0 : authsize));
Cristian Stoica05b1d332014-07-28 13:11:23 +0300701 }
702
Cristian Stoica05b1d332014-07-28 13:11:23 +0300703 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
704 template[i].ilen, iv);
705
Herbert Xu8a525fc2015-05-27 16:03:43 +0800706 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300707
708 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
709
710 switch (ret) {
711 case 0:
712 if (template[i].novrfy) {
713 /* verification was supposed to fail */
714 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
715 d, e, j, algo);
716 /* so really, we got a bad message */
717 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +0300718 goto out;
719 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300720 break;
721 case -EINPROGRESS:
722 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100723 wait_for_completion(&result.completion);
724 reinit_completion(&result.completion);
725 ret = result.err;
726 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +0800727 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300728 case -EBADMSG:
729 if (template[i].novrfy)
730 /* verification failure was expected */
731 continue;
732 /* fall through */
733 default:
734 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
735 d, e, j, algo, -ret);
736 goto out;
737 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800738
Cristian Stoica05b1d332014-07-28 13:11:23 +0300739 q = output;
740 if (memcmp(q, template[i].result, template[i].rlen)) {
741 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
742 d, j, e, algo);
743 hexdump(q, template[i].rlen);
744 ret = -EINVAL;
745 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800746 }
747 }
748
749 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300750 /* alignment tests are only done with continuous buffers */
751 if (align_offset != 0)
752 break;
753
Cristian Stoica05b1d332014-07-28 13:11:23 +0300754 if (!template[i].np)
755 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800756
Cristian Stoica05b1d332014-07-28 13:11:23 +0300757 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800758
Cristian Stoica05b1d332014-07-28 13:11:23 +0300759 if (template[i].iv)
Jerome Marchandabfa7f42016-02-03 13:58:12 +0100760 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300761 else
762 memset(iv, 0, MAX_IVLEN);
763
764 crypto_aead_clear_flags(tfm, ~0);
765 if (template[i].wk)
766 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
767 if (template[i].klen > MAX_KEYLEN) {
768 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
769 d, j, algo, template[i].klen, MAX_KEYLEN);
770 ret = -EINVAL;
771 goto out;
772 }
773 memcpy(key, template[i].key, template[i].klen);
774
775 ret = crypto_aead_setkey(tfm, key, template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +0800776 if (template[i].fail == !ret) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300777 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
778 d, j, algo, crypto_aead_get_flags(tfm));
779 goto out;
780 } else if (ret)
781 continue;
782
783 authsize = abs(template[i].rlen - template[i].ilen);
784
785 ret = -EINVAL;
Herbert Xu8a525fc2015-05-27 16:03:43 +0800786 sg_init_table(sg, template[i].anp + template[i].np);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300787 if (diff_dst)
Herbert Xu8a525fc2015-05-27 16:03:43 +0800788 sg_init_table(sgout, template[i].anp + template[i].np);
789
790 ret = -EINVAL;
791 for (k = 0, temp = 0; k < template[i].anp; k++) {
792 if (WARN_ON(offset_in_page(IDX[k]) +
793 template[i].atap[k] > PAGE_SIZE))
794 goto out;
795 sg_set_buf(&sg[k],
796 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
797 offset_in_page(IDX[k]),
798 template[i].assoc + temp,
799 template[i].atap[k]),
800 template[i].atap[k]);
801 if (diff_dst)
802 sg_set_buf(&sgout[k],
803 axbuf[IDX[k] >> PAGE_SHIFT] +
804 offset_in_page(IDX[k]),
805 template[i].atap[k]);
806 temp += template[i].atap[k];
807 }
808
Cristian Stoica05b1d332014-07-28 13:11:23 +0300809 for (k = 0, temp = 0; k < template[i].np; k++) {
810 if (WARN_ON(offset_in_page(IDX[k]) +
811 template[i].tap[k] > PAGE_SIZE))
812 goto out;
813
814 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
815 memcpy(q, template[i].input + temp, template[i].tap[k]);
Herbert Xu8a525fc2015-05-27 16:03:43 +0800816 sg_set_buf(&sg[template[i].anp + k],
817 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300818
819 if (diff_dst) {
820 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
821 offset_in_page(IDX[k]);
822
823 memset(q, 0, template[i].tap[k]);
824
Herbert Xu8a525fc2015-05-27 16:03:43 +0800825 sg_set_buf(&sgout[template[i].anp + k],
826 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300827 }
828
829 n = template[i].tap[k];
830 if (k == template[i].np - 1 && enc)
831 n += authsize;
832 if (offset_in_page(q) + n < PAGE_SIZE)
833 q[n] = 0;
834
835 temp += template[i].tap[k];
836 }
837
838 ret = crypto_aead_setauthsize(tfm, authsize);
839 if (ret) {
840 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
841 d, authsize, j, algo);
842 goto out;
843 }
844
845 if (enc) {
Herbert Xu8a525fc2015-05-27 16:03:43 +0800846 if (WARN_ON(sg[template[i].anp + k - 1].offset +
847 sg[template[i].anp + k - 1].length +
848 authsize > PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300849 ret = -EINVAL;
850 goto out;
851 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800852
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300853 if (diff_dst)
Herbert Xu8a525fc2015-05-27 16:03:43 +0800854 sgout[template[i].anp + k - 1].length +=
855 authsize;
856 sg[template[i].anp + k - 1].length += authsize;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300857 }
858
859 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
860 template[i].ilen,
861 iv);
862
Herbert Xu8a525fc2015-05-27 16:03:43 +0800863 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300864
865 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
866
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;
875 goto out;
876 }
877 break;
878 case -EINPROGRESS:
879 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100880 wait_for_completion(&result.completion);
881 reinit_completion(&result.completion);
882 ret = result.err;
883 if (!ret)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300884 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300885 case -EBADMSG:
886 if (template[i].novrfy)
887 /* verification failure was expected */
888 continue;
889 /* fall through */
890 default:
891 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
892 d, e, j, algo, -ret);
893 goto out;
894 }
895
896 ret = -EINVAL;
897 for (k = 0, temp = 0; k < template[i].np; k++) {
898 if (diff_dst)
899 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
900 offset_in_page(IDX[k]);
901 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800902 q = xbuf[IDX[k] >> PAGE_SHIFT] +
903 offset_in_page(IDX[k]);
904
Cristian Stoica05b1d332014-07-28 13:11:23 +0300905 n = template[i].tap[k];
906 if (k == template[i].np - 1)
907 n += enc ? authsize : -authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800908
Cristian Stoica05b1d332014-07-28 13:11:23 +0300909 if (memcmp(q, template[i].result + temp, n)) {
910 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
911 d, j, e, k, algo);
912 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800913 goto out;
914 }
915
Cristian Stoica05b1d332014-07-28 13:11:23 +0300916 q += n;
917 if (k == template[i].np - 1 && !enc) {
918 if (!diff_dst &&
919 memcmp(q, template[i].input +
920 temp + n, authsize))
921 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200922 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300923 n = 0;
924 } else {
925 for (n = 0; offset_in_page(q + n) && q[n]; n++)
926 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800927 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300928 if (n) {
929 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
930 d, j, e, k, algo, n);
931 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800932 goto out;
933 }
934
Cristian Stoica05b1d332014-07-28 13:11:23 +0300935 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800936 }
937 }
938
939 ret = 0;
940
941out:
942 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300943 kfree(sg);
944out_nosg:
945 if (diff_dst)
946 testmgr_free_buf(xoutbuf);
947out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800948 testmgr_free_buf(axbuf);
949out_noaxbuf:
950 testmgr_free_buf(xbuf);
951out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300952 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700953 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800954 return ret;
955}
956
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300957static int test_aead(struct crypto_aead *tfm, int enc,
958 struct aead_testvec *template, unsigned int tcount)
959{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300960 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300961 int ret;
962
963 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300964 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300965 if (ret)
966 return ret;
967
968 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300969 ret = __test_aead(tfm, enc, template, tcount, true, 0);
970 if (ret)
971 return ret;
972
973 /* test unaligned buffers, check with one byte offset */
974 ret = __test_aead(tfm, enc, template, tcount, true, 1);
975 if (ret)
976 return ret;
977
978 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
979 if (alignmask) {
980 /* Check if alignment mask for tfm is correctly set. */
981 ret = __test_aead(tfm, enc, template, tcount, true,
982 alignmask + 1);
983 if (ret)
984 return ret;
985 }
986
987 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300988}
989
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000990static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800991 struct cipher_testvec *template, unsigned int tcount)
992{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000993 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
994 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000995 char *q;
996 const char *e;
997 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800998 char *xbuf[XBUFSIZE];
999 int ret = -ENOMEM;
1000
1001 if (testmgr_alloc_buf(xbuf))
1002 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001003
1004 if (enc == ENCRYPT)
1005 e = "encryption";
1006 else
1007 e = "decryption";
1008
1009 j = 0;
1010 for (i = 0; i < tcount; i++) {
1011 if (template[i].np)
1012 continue;
1013
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001014 if (fips_enabled && template[i].fips_skip)
1015 continue;
1016
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001017 j++;
1018
Herbert Xufd57f222009-05-29 16:05:42 +10001019 ret = -EINVAL;
1020 if (WARN_ON(template[i].ilen > PAGE_SIZE))
1021 goto out;
1022
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001023 data = xbuf[0];
1024 memcpy(data, template[i].input, template[i].ilen);
1025
1026 crypto_cipher_clear_flags(tfm, ~0);
1027 if (template[i].wk)
1028 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1029
1030 ret = crypto_cipher_setkey(tfm, template[i].key,
1031 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001032 if (template[i].fail == !ret) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001033 printk(KERN_ERR "alg: cipher: setkey failed "
1034 "on test %d for %s: flags=%x\n", j,
1035 algo, crypto_cipher_get_flags(tfm));
1036 goto out;
1037 } else if (ret)
1038 continue;
1039
1040 for (k = 0; k < template[i].ilen;
1041 k += crypto_cipher_blocksize(tfm)) {
1042 if (enc)
1043 crypto_cipher_encrypt_one(tfm, data + k,
1044 data + k);
1045 else
1046 crypto_cipher_decrypt_one(tfm, data + k,
1047 data + k);
1048 }
1049
1050 q = data;
1051 if (memcmp(q, template[i].result, template[i].rlen)) {
1052 printk(KERN_ERR "alg: cipher: Test %d failed "
1053 "on %s for %s\n", j, e, algo);
1054 hexdump(q, template[i].rlen);
1055 ret = -EINVAL;
1056 goto out;
1057 }
1058 }
1059
1060 ret = 0;
1061
1062out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001063 testmgr_free_buf(xbuf);
1064out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001065 return ret;
1066}
1067
Herbert Xu12773d92015-08-20 15:21:46 +08001068static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001069 struct cipher_testvec *template, unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001070 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001071{
Herbert Xuda7f0332008-07-31 17:08:25 +08001072 const char *algo =
Herbert Xu12773d92015-08-20 15:21:46 +08001073 crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +08001074 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +08001075 char *q;
Herbert Xu12773d92015-08-20 15:21:46 +08001076 struct skcipher_request *req;
Herbert Xuda7f0332008-07-31 17:08:25 +08001077 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001078 struct scatterlist sgout[8];
1079 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +08001080 struct tcrypt_result result;
1081 void *data;
1082 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001083 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001084 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001085 int ret = -ENOMEM;
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001086 unsigned int ivsize = crypto_skcipher_ivsize(tfm);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001087
1088 if (testmgr_alloc_buf(xbuf))
1089 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +08001090
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001091 if (diff_dst && testmgr_alloc_buf(xoutbuf))
1092 goto out_nooutbuf;
1093
1094 if (diff_dst)
1095 d = "-ddst";
1096 else
1097 d = "";
1098
Herbert Xuda7f0332008-07-31 17:08:25 +08001099 if (enc == ENCRYPT)
1100 e = "encryption";
1101 else
1102 e = "decryption";
1103
1104 init_completion(&result.completion);
1105
Herbert Xu12773d92015-08-20 15:21:46 +08001106 req = skcipher_request_alloc(tfm, GFP_KERNEL);
Herbert Xuda7f0332008-07-31 17:08:25 +08001107 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001108 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
1109 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +08001110 goto out;
1111 }
1112
Herbert Xu12773d92015-08-20 15:21:46 +08001113 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1114 tcrypt_complete, &result);
Herbert Xuda7f0332008-07-31 17:08:25 +08001115
1116 j = 0;
1117 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001118 if (template[i].np && !template[i].also_non_np)
1119 continue;
1120
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001121 if (fips_enabled && template[i].fips_skip)
1122 continue;
1123
Herbert Xuda7f0332008-07-31 17:08:25 +08001124 if (template[i].iv)
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001125 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001126 else
1127 memset(iv, 0, MAX_IVLEN);
1128
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001129 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001130 ret = -EINVAL;
1131 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
1132 goto out;
1133
1134 data = xbuf[0];
1135 data += align_offset;
1136 memcpy(data, template[i].input, template[i].ilen);
1137
Herbert Xu12773d92015-08-20 15:21:46 +08001138 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001139 if (template[i].wk)
Herbert Xu12773d92015-08-20 15:21:46 +08001140 crypto_skcipher_set_flags(tfm,
1141 CRYPTO_TFM_REQ_WEAK_KEY);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001142
Herbert Xu12773d92015-08-20 15:21:46 +08001143 ret = crypto_skcipher_setkey(tfm, template[i].key,
1144 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001145 if (template[i].fail == !ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001146 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001147 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001148 goto out;
1149 } else if (ret)
1150 continue;
1151
1152 sg_init_one(&sg[0], data, template[i].ilen);
1153 if (diff_dst) {
1154 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001155 data += align_offset;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001156 sg_init_one(&sgout[0], data, template[i].ilen);
1157 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001158
Herbert Xu12773d92015-08-20 15:21:46 +08001159 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1160 template[i].ilen, iv);
1161 ret = enc ? crypto_skcipher_encrypt(req) :
1162 crypto_skcipher_decrypt(req);
Herbert Xuda7f0332008-07-31 17:08:25 +08001163
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001164 switch (ret) {
1165 case 0:
1166 break;
1167 case -EINPROGRESS:
1168 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001169 wait_for_completion(&result.completion);
1170 reinit_completion(&result.completion);
1171 ret = result.err;
1172 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +08001173 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001174 /* fall through */
1175 default:
1176 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1177 d, e, j, algo, -ret);
1178 goto out;
1179 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001180
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001181 q = data;
1182 if (memcmp(q, template[i].result, template[i].rlen)) {
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001183 pr_err("alg: skcipher%s: Test %d failed (invalid result) on %s for %s\n",
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001184 d, j, e, algo);
1185 hexdump(q, template[i].rlen);
1186 ret = -EINVAL;
1187 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001188 }
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001189
1190 if (template[i].iv_out &&
1191 memcmp(iv, template[i].iv_out,
1192 crypto_skcipher_ivsize(tfm))) {
1193 pr_err("alg: skcipher%s: Test %d failed (invalid output IV) on %s for %s\n",
1194 d, j, e, algo);
1195 hexdump(iv, crypto_skcipher_ivsize(tfm));
1196 ret = -EINVAL;
1197 goto out;
1198 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001199 }
1200
1201 j = 0;
1202 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001203 /* alignment tests are only done with continuous buffers */
1204 if (align_offset != 0)
1205 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001206
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001207 if (!template[i].np)
1208 continue;
1209
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001210 if (fips_enabled && template[i].fips_skip)
1211 continue;
1212
Herbert Xuda7f0332008-07-31 17:08:25 +08001213 if (template[i].iv)
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001214 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001215 else
1216 memset(iv, 0, MAX_IVLEN);
1217
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001218 j++;
Herbert Xu12773d92015-08-20 15:21:46 +08001219 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001220 if (template[i].wk)
Herbert Xu12773d92015-08-20 15:21:46 +08001221 crypto_skcipher_set_flags(tfm,
1222 CRYPTO_TFM_REQ_WEAK_KEY);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001223
Herbert Xu12773d92015-08-20 15:21:46 +08001224 ret = crypto_skcipher_setkey(tfm, template[i].key,
1225 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001226 if (template[i].fail == !ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001227 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001228 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001229 goto out;
1230 } else if (ret)
1231 continue;
1232
1233 temp = 0;
1234 ret = -EINVAL;
1235 sg_init_table(sg, template[i].np);
1236 if (diff_dst)
1237 sg_init_table(sgout, template[i].np);
1238 for (k = 0; k < template[i].np; k++) {
1239 if (WARN_ON(offset_in_page(IDX[k]) +
1240 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001241 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001242
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001243 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1244
1245 memcpy(q, template[i].input + temp, template[i].tap[k]);
1246
1247 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1248 q[template[i].tap[k]] = 0;
1249
1250 sg_set_buf(&sg[k], q, template[i].tap[k]);
1251 if (diff_dst) {
1252 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1253 offset_in_page(IDX[k]);
1254
1255 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1256
1257 memset(q, 0, template[i].tap[k]);
1258 if (offset_in_page(q) +
1259 template[i].tap[k] < PAGE_SIZE)
1260 q[template[i].tap[k]] = 0;
1261 }
1262
1263 temp += template[i].tap[k];
1264 }
1265
Herbert Xu12773d92015-08-20 15:21:46 +08001266 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1267 template[i].ilen, iv);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001268
Herbert Xu12773d92015-08-20 15:21:46 +08001269 ret = enc ? crypto_skcipher_encrypt(req) :
1270 crypto_skcipher_decrypt(req);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001271
1272 switch (ret) {
1273 case 0:
1274 break;
1275 case -EINPROGRESS:
1276 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001277 wait_for_completion(&result.completion);
1278 reinit_completion(&result.completion);
1279 ret = result.err;
1280 if (!ret)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001281 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001282 /* fall through */
1283 default:
1284 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1285 d, e, j, algo, -ret);
1286 goto out;
1287 }
1288
1289 temp = 0;
1290 ret = -EINVAL;
1291 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001292 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001293 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1294 offset_in_page(IDX[k]);
1295 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001296 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1297 offset_in_page(IDX[k]);
1298
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001299 if (memcmp(q, template[i].result + temp,
1300 template[i].tap[k])) {
1301 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1302 d, j, e, k, algo);
1303 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001304 goto out;
1305 }
1306
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001307 q += template[i].tap[k];
1308 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1309 ;
1310 if (n) {
1311 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1312 d, j, e, k, algo, n);
1313 hexdump(q, n);
1314 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001315 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001316 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001317 }
1318 }
1319
1320 ret = 0;
1321
1322out:
Herbert Xu12773d92015-08-20 15:21:46 +08001323 skcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001324 if (diff_dst)
1325 testmgr_free_buf(xoutbuf);
1326out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001327 testmgr_free_buf(xbuf);
1328out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001329 return ret;
1330}
1331
Herbert Xu12773d92015-08-20 15:21:46 +08001332static int test_skcipher(struct crypto_skcipher *tfm, int enc,
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001333 struct cipher_testvec *template, unsigned int tcount)
1334{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001335 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001336 int ret;
1337
1338 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001339 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001340 if (ret)
1341 return ret;
1342
1343 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001344 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1345 if (ret)
1346 return ret;
1347
1348 /* test unaligned buffers, check with one byte offset */
1349 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1350 if (ret)
1351 return ret;
1352
1353 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1354 if (alignmask) {
1355 /* Check if alignment mask for tfm is correctly set. */
1356 ret = __test_skcipher(tfm, enc, template, tcount, true,
1357 alignmask + 1);
1358 if (ret)
1359 return ret;
1360 }
1361
1362 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001363}
1364
Herbert Xuda7f0332008-07-31 17:08:25 +08001365static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1366 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1367{
1368 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1369 unsigned int i;
1370 char result[COMP_BUF_SIZE];
1371 int ret;
1372
1373 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001374 int ilen;
1375 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001376
1377 memset(result, 0, sizeof (result));
1378
1379 ilen = ctemplate[i].inlen;
1380 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1381 ilen, result, &dlen);
1382 if (ret) {
1383 printk(KERN_ERR "alg: comp: compression failed "
1384 "on test %d for %s: ret=%d\n", i + 1, algo,
1385 -ret);
1386 goto out;
1387 }
1388
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001389 if (dlen != ctemplate[i].outlen) {
1390 printk(KERN_ERR "alg: comp: Compression test %d "
1391 "failed for %s: output len = %d\n", i + 1, algo,
1392 dlen);
1393 ret = -EINVAL;
1394 goto out;
1395 }
1396
Herbert Xuda7f0332008-07-31 17:08:25 +08001397 if (memcmp(result, ctemplate[i].output, dlen)) {
1398 printk(KERN_ERR "alg: comp: Compression test %d "
1399 "failed for %s\n", i + 1, algo);
1400 hexdump(result, dlen);
1401 ret = -EINVAL;
1402 goto out;
1403 }
1404 }
1405
1406 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001407 int ilen;
1408 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001409
1410 memset(result, 0, sizeof (result));
1411
1412 ilen = dtemplate[i].inlen;
1413 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1414 ilen, result, &dlen);
1415 if (ret) {
1416 printk(KERN_ERR "alg: comp: decompression failed "
1417 "on test %d for %s: ret=%d\n", i + 1, algo,
1418 -ret);
1419 goto out;
1420 }
1421
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001422 if (dlen != dtemplate[i].outlen) {
1423 printk(KERN_ERR "alg: comp: Decompression test %d "
1424 "failed for %s: output len = %d\n", i + 1, algo,
1425 dlen);
1426 ret = -EINVAL;
1427 goto out;
1428 }
1429
Herbert Xuda7f0332008-07-31 17:08:25 +08001430 if (memcmp(result, dtemplate[i].output, dlen)) {
1431 printk(KERN_ERR "alg: comp: Decompression test %d "
1432 "failed for %s\n", i + 1, algo);
1433 hexdump(result, dlen);
1434 ret = -EINVAL;
1435 goto out;
1436 }
1437 }
1438
1439 ret = 0;
1440
1441out:
1442 return ret;
1443}
1444
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001445static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1446 unsigned int tcount)
1447{
1448 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001449 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001450 u8 *seed;
1451 char result[32];
1452
1453 seedsize = crypto_rng_seedsize(tfm);
1454
1455 seed = kmalloc(seedsize, GFP_KERNEL);
1456 if (!seed) {
1457 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1458 "for %s\n", algo);
1459 return -ENOMEM;
1460 }
1461
1462 for (i = 0; i < tcount; i++) {
1463 memset(result, 0, 32);
1464
1465 memcpy(seed, template[i].v, template[i].vlen);
1466 memcpy(seed + template[i].vlen, template[i].key,
1467 template[i].klen);
1468 memcpy(seed + template[i].vlen + template[i].klen,
1469 template[i].dt, template[i].dtlen);
1470
1471 err = crypto_rng_reset(tfm, seed, seedsize);
1472 if (err) {
1473 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1474 "for %s\n", algo);
1475 goto out;
1476 }
1477
1478 for (j = 0; j < template[i].loops; j++) {
1479 err = crypto_rng_get_bytes(tfm, result,
1480 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01001481 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001482 printk(KERN_ERR "alg: cprng: Failed to obtain "
1483 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01001484 "%s (requested %d)\n", algo,
1485 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001486 goto out;
1487 }
1488 }
1489
1490 err = memcmp(result, template[i].result,
1491 template[i].rlen);
1492 if (err) {
1493 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1494 i, algo);
1495 hexdump(result, template[i].rlen);
1496 err = -EINVAL;
1497 goto out;
1498 }
1499 }
1500
1501out:
1502 kfree(seed);
1503 return err;
1504}
1505
Herbert Xuda7f0332008-07-31 17:08:25 +08001506static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1507 u32 type, u32 mask)
1508{
1509 struct crypto_aead *tfm;
1510 int err = 0;
1511
Stephan Mueller425a8822015-03-30 21:56:31 +02001512 tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001513 if (IS_ERR(tfm)) {
1514 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1515 "%ld\n", driver, PTR_ERR(tfm));
1516 return PTR_ERR(tfm);
1517 }
1518
1519 if (desc->suite.aead.enc.vecs) {
1520 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1521 desc->suite.aead.enc.count);
1522 if (err)
1523 goto out;
1524 }
1525
1526 if (!err && desc->suite.aead.dec.vecs)
1527 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1528 desc->suite.aead.dec.count);
1529
1530out:
1531 crypto_free_aead(tfm);
1532 return err;
1533}
1534
1535static int alg_test_cipher(const struct alg_test_desc *desc,
1536 const char *driver, u32 type, u32 mask)
1537{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001538 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001539 int err = 0;
1540
Stephan Mueller425a8822015-03-30 21:56:31 +02001541 tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001542 if (IS_ERR(tfm)) {
1543 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1544 "%s: %ld\n", driver, PTR_ERR(tfm));
1545 return PTR_ERR(tfm);
1546 }
1547
1548 if (desc->suite.cipher.enc.vecs) {
1549 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1550 desc->suite.cipher.enc.count);
1551 if (err)
1552 goto out;
1553 }
1554
1555 if (desc->suite.cipher.dec.vecs)
1556 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1557 desc->suite.cipher.dec.count);
1558
1559out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001560 crypto_free_cipher(tfm);
1561 return err;
1562}
1563
1564static int alg_test_skcipher(const struct alg_test_desc *desc,
1565 const char *driver, u32 type, u32 mask)
1566{
Herbert Xu12773d92015-08-20 15:21:46 +08001567 struct crypto_skcipher *tfm;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001568 int err = 0;
1569
Herbert Xu12773d92015-08-20 15:21:46 +08001570 tfm = crypto_alloc_skcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001571 if (IS_ERR(tfm)) {
1572 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1573 "%s: %ld\n", driver, PTR_ERR(tfm));
1574 return PTR_ERR(tfm);
1575 }
1576
1577 if (desc->suite.cipher.enc.vecs) {
1578 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1579 desc->suite.cipher.enc.count);
1580 if (err)
1581 goto out;
1582 }
1583
1584 if (desc->suite.cipher.dec.vecs)
1585 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1586 desc->suite.cipher.dec.count);
1587
1588out:
Herbert Xu12773d92015-08-20 15:21:46 +08001589 crypto_free_skcipher(tfm);
Herbert Xuda7f0332008-07-31 17:08:25 +08001590 return err;
1591}
1592
1593static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1594 u32 type, u32 mask)
1595{
1596 struct crypto_comp *tfm;
1597 int err;
1598
1599 tfm = crypto_alloc_comp(driver, type, mask);
1600 if (IS_ERR(tfm)) {
1601 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1602 "%ld\n", driver, PTR_ERR(tfm));
1603 return PTR_ERR(tfm);
1604 }
1605
1606 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1607 desc->suite.comp.decomp.vecs,
1608 desc->suite.comp.comp.count,
1609 desc->suite.comp.decomp.count);
1610
1611 crypto_free_comp(tfm);
1612 return err;
1613}
1614
1615static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1616 u32 type, u32 mask)
1617{
1618 struct crypto_ahash *tfm;
1619 int err;
1620
Stephan Mueller425a8822015-03-30 21:56:31 +02001621 tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001622 if (IS_ERR(tfm)) {
1623 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1624 "%ld\n", driver, PTR_ERR(tfm));
1625 return PTR_ERR(tfm);
1626 }
1627
David S. Millera8f1a052010-05-19 14:12:03 +10001628 err = test_hash(tfm, desc->suite.hash.vecs,
1629 desc->suite.hash.count, true);
1630 if (!err)
1631 err = test_hash(tfm, desc->suite.hash.vecs,
1632 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001633
1634 crypto_free_ahash(tfm);
1635 return err;
1636}
1637
Herbert Xu8e3ee852008-11-07 14:58:52 +08001638static int alg_test_crc32c(const struct alg_test_desc *desc,
1639 const char *driver, u32 type, u32 mask)
1640{
1641 struct crypto_shash *tfm;
1642 u32 val;
1643 int err;
1644
1645 err = alg_test_hash(desc, driver, type, mask);
1646 if (err)
1647 goto out;
1648
Stephan Mueller425a8822015-03-30 21:56:31 +02001649 tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001650 if (IS_ERR(tfm)) {
1651 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1652 "%ld\n", driver, PTR_ERR(tfm));
1653 err = PTR_ERR(tfm);
1654 goto out;
1655 }
1656
1657 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001658 SHASH_DESC_ON_STACK(shash, tfm);
1659 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001660
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001661 shash->tfm = tfm;
1662 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001663
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001664 *ctx = le32_to_cpu(420553207);
1665 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001666 if (err) {
1667 printk(KERN_ERR "alg: crc32c: Operation failed for "
1668 "%s: %d\n", driver, err);
1669 break;
1670 }
1671
1672 if (val != ~420553207) {
1673 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1674 "%d\n", driver, val);
1675 err = -EINVAL;
1676 }
1677 } while (0);
1678
1679 crypto_free_shash(tfm);
1680
1681out:
1682 return err;
1683}
1684
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001685static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1686 u32 type, u32 mask)
1687{
1688 struct crypto_rng *rng;
1689 int err;
1690
Stephan Mueller425a8822015-03-30 21:56:31 +02001691 rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001692 if (IS_ERR(rng)) {
1693 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1694 "%ld\n", driver, PTR_ERR(rng));
1695 return PTR_ERR(rng);
1696 }
1697
1698 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1699
1700 crypto_free_rng(rng);
1701
1702 return err;
1703}
1704
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001705
1706static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1707 const char *driver, u32 type, u32 mask)
1708{
1709 int ret = -EAGAIN;
1710 struct crypto_rng *drng;
1711 struct drbg_test_data test_data;
1712 struct drbg_string addtl, pers, testentropy;
1713 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1714
1715 if (!buf)
1716 return -ENOMEM;
1717
Stephan Mueller425a8822015-03-30 21:56:31 +02001718 drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001719 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001720 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001721 "%s\n", driver);
1722 kzfree(buf);
1723 return -ENOMEM;
1724 }
1725
1726 test_data.testentropy = &testentropy;
1727 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1728 drbg_string_fill(&pers, test->pers, test->perslen);
1729 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1730 if (ret) {
1731 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1732 goto outbuf;
1733 }
1734
1735 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1736 if (pr) {
1737 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1738 ret = crypto_drbg_get_bytes_addtl_test(drng,
1739 buf, test->expectedlen, &addtl, &test_data);
1740 } else {
1741 ret = crypto_drbg_get_bytes_addtl(drng,
1742 buf, test->expectedlen, &addtl);
1743 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001744 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001745 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001746 "driver %s\n", driver);
1747 goto outbuf;
1748 }
1749
1750 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1751 if (pr) {
1752 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1753 ret = crypto_drbg_get_bytes_addtl_test(drng,
1754 buf, test->expectedlen, &addtl, &test_data);
1755 } else {
1756 ret = crypto_drbg_get_bytes_addtl(drng,
1757 buf, test->expectedlen, &addtl);
1758 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001759 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001760 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001761 "driver %s\n", driver);
1762 goto outbuf;
1763 }
1764
1765 ret = memcmp(test->expected, buf, test->expectedlen);
1766
1767outbuf:
1768 crypto_free_rng(drng);
1769 kzfree(buf);
1770 return ret;
1771}
1772
1773
1774static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1775 u32 type, u32 mask)
1776{
1777 int err = 0;
1778 int pr = 0;
1779 int i = 0;
1780 struct drbg_testvec *template = desc->suite.drbg.vecs;
1781 unsigned int tcount = desc->suite.drbg.count;
1782
1783 if (0 == memcmp(driver, "drbg_pr_", 8))
1784 pr = 1;
1785
1786 for (i = 0; i < tcount; i++) {
1787 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1788 if (err) {
1789 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1790 i, driver);
1791 err = -EINVAL;
1792 break;
1793 }
1794 }
1795 return err;
1796
1797}
1798
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01001799static int do_test_kpp(struct crypto_kpp *tfm, struct kpp_testvec *vec,
1800 const char *alg)
1801{
1802 struct kpp_request *req;
1803 void *input_buf = NULL;
1804 void *output_buf = NULL;
1805 struct tcrypt_result result;
1806 unsigned int out_len_max;
1807 int err = -ENOMEM;
1808 struct scatterlist src, dst;
1809
1810 req = kpp_request_alloc(tfm, GFP_KERNEL);
1811 if (!req)
1812 return err;
1813
1814 init_completion(&result.completion);
1815
1816 err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
1817 if (err < 0)
1818 goto free_req;
1819
1820 out_len_max = crypto_kpp_maxsize(tfm);
1821 output_buf = kzalloc(out_len_max, GFP_KERNEL);
1822 if (!output_buf) {
1823 err = -ENOMEM;
1824 goto free_req;
1825 }
1826
1827 /* Use appropriate parameter as base */
1828 kpp_request_set_input(req, NULL, 0);
1829 sg_init_one(&dst, output_buf, out_len_max);
1830 kpp_request_set_output(req, &dst, out_len_max);
1831 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1832 tcrypt_complete, &result);
1833
1834 /* Compute public key */
1835 err = wait_async_op(&result, crypto_kpp_generate_public_key(req));
1836 if (err) {
1837 pr_err("alg: %s: generate public key test failed. err %d\n",
1838 alg, err);
1839 goto free_output;
1840 }
1841 /* Verify calculated public key */
1842 if (memcmp(vec->expected_a_public, sg_virt(req->dst),
1843 vec->expected_a_public_size)) {
1844 pr_err("alg: %s: generate public key test failed. Invalid output\n",
1845 alg);
1846 err = -EINVAL;
1847 goto free_output;
1848 }
1849
1850 /* Calculate shared secret key by using counter part (b) public key. */
1851 input_buf = kzalloc(vec->b_public_size, GFP_KERNEL);
1852 if (!input_buf) {
1853 err = -ENOMEM;
1854 goto free_output;
1855 }
1856
1857 memcpy(input_buf, vec->b_public, vec->b_public_size);
1858 sg_init_one(&src, input_buf, vec->b_public_size);
1859 sg_init_one(&dst, output_buf, out_len_max);
1860 kpp_request_set_input(req, &src, vec->b_public_size);
1861 kpp_request_set_output(req, &dst, out_len_max);
1862 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1863 tcrypt_complete, &result);
1864 err = wait_async_op(&result, crypto_kpp_compute_shared_secret(req));
1865 if (err) {
1866 pr_err("alg: %s: compute shard secret test failed. err %d\n",
1867 alg, err);
1868 goto free_all;
1869 }
1870 /*
1871 * verify shared secret from which the user will derive
1872 * secret key by executing whatever hash it has chosen
1873 */
1874 if (memcmp(vec->expected_ss, sg_virt(req->dst),
1875 vec->expected_ss_size)) {
1876 pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
1877 alg);
1878 err = -EINVAL;
1879 }
1880
1881free_all:
1882 kfree(input_buf);
1883free_output:
1884 kfree(output_buf);
1885free_req:
1886 kpp_request_free(req);
1887 return err;
1888}
1889
1890static int test_kpp(struct crypto_kpp *tfm, const char *alg,
1891 struct kpp_testvec *vecs, unsigned int tcount)
1892{
1893 int ret, i;
1894
1895 for (i = 0; i < tcount; i++) {
1896 ret = do_test_kpp(tfm, vecs++, alg);
1897 if (ret) {
1898 pr_err("alg: %s: test failed on vector %d, err=%d\n",
1899 alg, i + 1, ret);
1900 return ret;
1901 }
1902 }
1903 return 0;
1904}
1905
1906static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
1907 u32 type, u32 mask)
1908{
1909 struct crypto_kpp *tfm;
1910 int err = 0;
1911
1912 tfm = crypto_alloc_kpp(driver, type | CRYPTO_ALG_INTERNAL, mask);
1913 if (IS_ERR(tfm)) {
1914 pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
1915 driver, PTR_ERR(tfm));
1916 return PTR_ERR(tfm);
1917 }
1918 if (desc->suite.kpp.vecs)
1919 err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
1920 desc->suite.kpp.count);
1921
1922 crypto_free_kpp(tfm);
1923 return err;
1924}
1925
Herbert Xu50d2b6432016-06-29 19:32:20 +08001926static int test_akcipher_one(struct crypto_akcipher *tfm,
1927 struct akcipher_testvec *vecs)
Tadeusz Struk946cc462015-06-16 10:31:06 -07001928{
Herbert Xudf27b262016-05-05 16:42:49 +08001929 char *xbuf[XBUFSIZE];
Tadeusz Struk946cc462015-06-16 10:31:06 -07001930 struct akcipher_request *req;
1931 void *outbuf_enc = NULL;
1932 void *outbuf_dec = NULL;
1933 struct tcrypt_result result;
1934 unsigned int out_len_max, out_len = 0;
1935 int err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07001936 struct scatterlist src, dst, src_tab[2];
Tadeusz Struk946cc462015-06-16 10:31:06 -07001937
Herbert Xudf27b262016-05-05 16:42:49 +08001938 if (testmgr_alloc_buf(xbuf))
1939 return err;
1940
Tadeusz Struk946cc462015-06-16 10:31:06 -07001941 req = akcipher_request_alloc(tfm, GFP_KERNEL);
1942 if (!req)
Herbert Xudf27b262016-05-05 16:42:49 +08001943 goto free_xbuf;
Tadeusz Struk946cc462015-06-16 10:31:06 -07001944
1945 init_completion(&result.completion);
Tadeusz Struk22287b02015-10-08 09:26:55 -07001946
1947 if (vecs->public_key_vec)
1948 err = crypto_akcipher_set_pub_key(tfm, vecs->key,
1949 vecs->key_len);
1950 else
1951 err = crypto_akcipher_set_priv_key(tfm, vecs->key,
1952 vecs->key_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07001953 if (err)
1954 goto free_req;
1955
Salvatore Benedetto57763f52016-07-04 10:52:34 +01001956 err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07001957 out_len_max = crypto_akcipher_maxsize(tfm);
Tadeusz Struk946cc462015-06-16 10:31:06 -07001958 outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
1959 if (!outbuf_enc)
1960 goto free_req;
1961
Herbert Xudf27b262016-05-05 16:42:49 +08001962 if (WARN_ON(vecs->m_size > PAGE_SIZE))
1963 goto free_all;
1964
1965 memcpy(xbuf[0], vecs->m, vecs->m_size);
1966
Tadeusz Struk22287b02015-10-08 09:26:55 -07001967 sg_init_table(src_tab, 2);
Herbert Xudf27b262016-05-05 16:42:49 +08001968 sg_set_buf(&src_tab[0], xbuf[0], 8);
1969 sg_set_buf(&src_tab[1], xbuf[0] + 8, vecs->m_size - 8);
Tadeusz Struk22287b02015-10-08 09:26:55 -07001970 sg_init_one(&dst, outbuf_enc, out_len_max);
1971 akcipher_request_set_crypt(req, src_tab, &dst, vecs->m_size,
1972 out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07001973 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1974 tcrypt_complete, &result);
1975
1976 /* Run RSA encrypt - c = m^e mod n;*/
1977 err = wait_async_op(&result, crypto_akcipher_encrypt(req));
1978 if (err) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08001979 pr_err("alg: akcipher: encrypt test failed. err %d\n", err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07001980 goto free_all;
1981 }
Tadeusz Struk22287b02015-10-08 09:26:55 -07001982 if (req->dst_len != vecs->c_size) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08001983 pr_err("alg: akcipher: encrypt test failed. Invalid output len\n");
Tadeusz Struk946cc462015-06-16 10:31:06 -07001984 err = -EINVAL;
1985 goto free_all;
1986 }
1987 /* verify that encrypted message is equal to expected */
Herbert Xudf27b262016-05-05 16:42:49 +08001988 if (memcmp(vecs->c, outbuf_enc, vecs->c_size)) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08001989 pr_err("alg: akcipher: encrypt test failed. Invalid output\n");
1990 hexdump(outbuf_enc, vecs->c_size);
Tadeusz Struk946cc462015-06-16 10:31:06 -07001991 err = -EINVAL;
1992 goto free_all;
1993 }
1994 /* Don't invoke decrypt for vectors with public key */
1995 if (vecs->public_key_vec) {
1996 err = 0;
1997 goto free_all;
1998 }
1999 outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
2000 if (!outbuf_dec) {
2001 err = -ENOMEM;
2002 goto free_all;
2003 }
Herbert Xudf27b262016-05-05 16:42:49 +08002004
2005 if (WARN_ON(vecs->c_size > PAGE_SIZE))
2006 goto free_all;
2007
2008 memcpy(xbuf[0], vecs->c, vecs->c_size);
2009
2010 sg_init_one(&src, xbuf[0], vecs->c_size);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002011 sg_init_one(&dst, outbuf_dec, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002012 init_completion(&result.completion);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002013 akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002014
2015 /* Run RSA decrypt - m = c^d mod n;*/
2016 err = wait_async_op(&result, crypto_akcipher_decrypt(req));
2017 if (err) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002018 pr_err("alg: akcipher: decrypt test failed. err %d\n", err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002019 goto free_all;
2020 }
2021 out_len = req->dst_len;
Herbert Xu50d2b6432016-06-29 19:32:20 +08002022 if (out_len < vecs->m_size) {
2023 pr_err("alg: akcipher: decrypt test failed. "
2024 "Invalid output len %u\n", out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002025 err = -EINVAL;
2026 goto free_all;
2027 }
2028 /* verify that decrypted message is equal to the original msg */
Herbert Xu50d2b6432016-06-29 19:32:20 +08002029 if (memchr_inv(outbuf_dec, 0, out_len - vecs->m_size) ||
2030 memcmp(vecs->m, outbuf_dec + out_len - vecs->m_size,
2031 vecs->m_size)) {
2032 pr_err("alg: akcipher: decrypt test failed. Invalid output\n");
2033 hexdump(outbuf_dec, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002034 err = -EINVAL;
2035 }
2036free_all:
2037 kfree(outbuf_dec);
2038 kfree(outbuf_enc);
2039free_req:
2040 akcipher_request_free(req);
Herbert Xudf27b262016-05-05 16:42:49 +08002041free_xbuf:
2042 testmgr_free_buf(xbuf);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002043 return err;
2044}
2045
Herbert Xu50d2b6432016-06-29 19:32:20 +08002046static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
2047 struct akcipher_testvec *vecs, unsigned int tcount)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002048{
Herbert Xu15226e42016-07-18 18:20:10 +08002049 const char *algo =
2050 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
Tadeusz Struk946cc462015-06-16 10:31:06 -07002051 int ret, i;
2052
2053 for (i = 0; i < tcount; i++) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002054 ret = test_akcipher_one(tfm, vecs++);
2055 if (!ret)
2056 continue;
2057
Herbert Xu15226e42016-07-18 18:20:10 +08002058 pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
2059 i + 1, algo, ret);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002060 return ret;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002061 }
2062 return 0;
2063}
2064
Tadeusz Struk946cc462015-06-16 10:31:06 -07002065static int alg_test_akcipher(const struct alg_test_desc *desc,
2066 const char *driver, u32 type, u32 mask)
2067{
2068 struct crypto_akcipher *tfm;
2069 int err = 0;
2070
2071 tfm = crypto_alloc_akcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
2072 if (IS_ERR(tfm)) {
2073 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
2074 driver, PTR_ERR(tfm));
2075 return PTR_ERR(tfm);
2076 }
2077 if (desc->suite.akcipher.vecs)
2078 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
2079 desc->suite.akcipher.count);
2080
2081 crypto_free_akcipher(tfm);
2082 return err;
2083}
2084
Youquan, Song863b5572009-12-23 19:45:20 +08002085static int alg_test_null(const struct alg_test_desc *desc,
2086 const char *driver, u32 type, u32 mask)
2087{
2088 return 0;
2089}
2090
Herbert Xuda7f0332008-07-31 17:08:25 +08002091/* Please keep this list sorted by algorithm name. */
2092static const struct alg_test_desc alg_test_descs[] = {
2093 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002094 .alg = "__cbc-cast5-avx",
2095 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002096 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002097 .alg = "__cbc-cast6-avx",
2098 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002099 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002100 .alg = "__cbc-serpent-avx",
2101 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002102 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002103 .alg = "__cbc-serpent-avx2",
2104 .test = alg_test_null,
2105 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002106 .alg = "__cbc-serpent-sse2",
2107 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002108 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002109 .alg = "__cbc-twofish-avx",
2110 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002111 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002112 .alg = "__driver-cbc-aes-aesni",
2113 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002114 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002115 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002116 .alg = "__driver-cbc-camellia-aesni",
2117 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002118 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002119 .alg = "__driver-cbc-camellia-aesni-avx2",
2120 .test = alg_test_null,
2121 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002122 .alg = "__driver-cbc-cast5-avx",
2123 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002124 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002125 .alg = "__driver-cbc-cast6-avx",
2126 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002127 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002128 .alg = "__driver-cbc-serpent-avx",
2129 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002130 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002131 .alg = "__driver-cbc-serpent-avx2",
2132 .test = alg_test_null,
2133 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002134 .alg = "__driver-cbc-serpent-sse2",
2135 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002136 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002137 .alg = "__driver-cbc-twofish-avx",
2138 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002139 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002140 .alg = "__driver-ecb-aes-aesni",
2141 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002142 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002143 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002144 .alg = "__driver-ecb-camellia-aesni",
2145 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002146 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002147 .alg = "__driver-ecb-camellia-aesni-avx2",
2148 .test = alg_test_null,
2149 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002150 .alg = "__driver-ecb-cast5-avx",
2151 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002152 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002153 .alg = "__driver-ecb-cast6-avx",
2154 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002155 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002156 .alg = "__driver-ecb-serpent-avx",
2157 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002158 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002159 .alg = "__driver-ecb-serpent-avx2",
2160 .test = alg_test_null,
2161 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002162 .alg = "__driver-ecb-serpent-sse2",
2163 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002164 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002165 .alg = "__driver-ecb-twofish-avx",
2166 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002167 }, {
Tadeusz Struk9d77b6c2015-06-24 09:01:30 -07002168 .alg = "__driver-gcm-aes-aesni",
2169 .test = alg_test_null,
2170 .fips_allowed = 1,
2171 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002172 .alg = "__ghash-pclmulqdqni",
2173 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002174 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002175 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002176 .alg = "ansi_cprng",
2177 .test = alg_test_cprng,
2178 .suite = {
2179 .cprng = {
2180 .vecs = ansi_cprng_aes_tv_template,
2181 .count = ANSI_CPRNG_AES_TEST_VECTORS
2182 }
2183 }
2184 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002185 .alg = "authenc(hmac(md5),ecb(cipher_null))",
2186 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002187 .suite = {
2188 .aead = {
2189 .enc = {
2190 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
2191 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
2192 },
2193 .dec = {
2194 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
2195 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
2196 }
2197 }
2198 }
2199 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002200 .alg = "authenc(hmac(sha1),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002201 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002202 .suite = {
2203 .aead = {
2204 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302205 .vecs =
2206 hmac_sha1_aes_cbc_enc_tv_temp,
2207 .count =
2208 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
2209 }
2210 }
2211 }
2212 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002213 .alg = "authenc(hmac(sha1),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302214 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302215 .suite = {
2216 .aead = {
2217 .enc = {
2218 .vecs =
2219 hmac_sha1_des_cbc_enc_tv_temp,
2220 .count =
2221 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
2222 }
2223 }
2224 }
2225 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002226 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302227 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002228 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302229 .suite = {
2230 .aead = {
2231 .enc = {
2232 .vecs =
2233 hmac_sha1_des3_ede_cbc_enc_tv_temp,
2234 .count =
2235 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002236 }
2237 }
2238 }
2239 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002240 .alg = "authenc(hmac(sha1),ctr(aes))",
2241 .test = alg_test_null,
2242 .fips_allowed = 1,
2243 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002244 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
2245 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002246 .suite = {
2247 .aead = {
2248 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302249 .vecs =
2250 hmac_sha1_ecb_cipher_null_enc_tv_temp,
2251 .count =
2252 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002253 },
2254 .dec = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302255 .vecs =
2256 hmac_sha1_ecb_cipher_null_dec_tv_temp,
2257 .count =
2258 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
2259 }
2260 }
2261 }
2262 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002263 .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
2264 .test = alg_test_null,
2265 .fips_allowed = 1,
2266 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002267 .alg = "authenc(hmac(sha224),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302268 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302269 .suite = {
2270 .aead = {
2271 .enc = {
2272 .vecs =
2273 hmac_sha224_des_cbc_enc_tv_temp,
2274 .count =
2275 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2276 }
2277 }
2278 }
2279 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002280 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302281 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002282 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302283 .suite = {
2284 .aead = {
2285 .enc = {
2286 .vecs =
2287 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2288 .count =
2289 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002290 }
2291 }
2292 }
2293 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002294 .alg = "authenc(hmac(sha256),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002295 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002296 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002297 .suite = {
2298 .aead = {
2299 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302300 .vecs =
2301 hmac_sha256_aes_cbc_enc_tv_temp,
2302 .count =
2303 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2304 }
2305 }
2306 }
2307 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002308 .alg = "authenc(hmac(sha256),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302309 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302310 .suite = {
2311 .aead = {
2312 .enc = {
2313 .vecs =
2314 hmac_sha256_des_cbc_enc_tv_temp,
2315 .count =
2316 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2317 }
2318 }
2319 }
2320 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002321 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302322 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002323 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302324 .suite = {
2325 .aead = {
2326 .enc = {
2327 .vecs =
2328 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2329 .count =
2330 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2331 }
2332 }
2333 }
2334 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002335 .alg = "authenc(hmac(sha256),ctr(aes))",
2336 .test = alg_test_null,
2337 .fips_allowed = 1,
2338 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002339 .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
2340 .test = alg_test_null,
2341 .fips_allowed = 1,
2342 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002343 .alg = "authenc(hmac(sha384),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302344 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302345 .suite = {
2346 .aead = {
2347 .enc = {
2348 .vecs =
2349 hmac_sha384_des_cbc_enc_tv_temp,
2350 .count =
2351 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2352 }
2353 }
2354 }
2355 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002356 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302357 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002358 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302359 .suite = {
2360 .aead = {
2361 .enc = {
2362 .vecs =
2363 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2364 .count =
2365 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002366 }
2367 }
2368 }
2369 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002370 .alg = "authenc(hmac(sha384),ctr(aes))",
2371 .test = alg_test_null,
2372 .fips_allowed = 1,
2373 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002374 .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
2375 .test = alg_test_null,
2376 .fips_allowed = 1,
2377 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002378 .alg = "authenc(hmac(sha512),cbc(aes))",
Marcus Meissnered1afac2016-02-05 14:23:33 +01002379 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002380 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002381 .suite = {
2382 .aead = {
2383 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302384 .vecs =
2385 hmac_sha512_aes_cbc_enc_tv_temp,
2386 .count =
2387 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2388 }
2389 }
2390 }
2391 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002392 .alg = "authenc(hmac(sha512),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302393 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302394 .suite = {
2395 .aead = {
2396 .enc = {
2397 .vecs =
2398 hmac_sha512_des_cbc_enc_tv_temp,
2399 .count =
2400 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2401 }
2402 }
2403 }
2404 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002405 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302406 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002407 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302408 .suite = {
2409 .aead = {
2410 .enc = {
2411 .vecs =
2412 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2413 .count =
2414 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002415 }
2416 }
2417 }
2418 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002419 .alg = "authenc(hmac(sha512),ctr(aes))",
2420 .test = alg_test_null,
2421 .fips_allowed = 1,
2422 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002423 .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
2424 .test = alg_test_null,
2425 .fips_allowed = 1,
2426 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002427 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002428 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002429 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002430 .suite = {
2431 .cipher = {
2432 .enc = {
2433 .vecs = aes_cbc_enc_tv_template,
2434 .count = AES_CBC_ENC_TEST_VECTORS
2435 },
2436 .dec = {
2437 .vecs = aes_cbc_dec_tv_template,
2438 .count = AES_CBC_DEC_TEST_VECTORS
2439 }
2440 }
2441 }
2442 }, {
2443 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002444 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002445 .suite = {
2446 .cipher = {
2447 .enc = {
2448 .vecs = anubis_cbc_enc_tv_template,
2449 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2450 },
2451 .dec = {
2452 .vecs = anubis_cbc_dec_tv_template,
2453 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2454 }
2455 }
2456 }
2457 }, {
2458 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002459 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002460 .suite = {
2461 .cipher = {
2462 .enc = {
2463 .vecs = bf_cbc_enc_tv_template,
2464 .count = BF_CBC_ENC_TEST_VECTORS
2465 },
2466 .dec = {
2467 .vecs = bf_cbc_dec_tv_template,
2468 .count = BF_CBC_DEC_TEST_VECTORS
2469 }
2470 }
2471 }
2472 }, {
2473 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002474 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002475 .suite = {
2476 .cipher = {
2477 .enc = {
2478 .vecs = camellia_cbc_enc_tv_template,
2479 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2480 },
2481 .dec = {
2482 .vecs = camellia_cbc_dec_tv_template,
2483 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2484 }
2485 }
2486 }
2487 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002488 .alg = "cbc(cast5)",
2489 .test = alg_test_skcipher,
2490 .suite = {
2491 .cipher = {
2492 .enc = {
2493 .vecs = cast5_cbc_enc_tv_template,
2494 .count = CAST5_CBC_ENC_TEST_VECTORS
2495 },
2496 .dec = {
2497 .vecs = cast5_cbc_dec_tv_template,
2498 .count = CAST5_CBC_DEC_TEST_VECTORS
2499 }
2500 }
2501 }
2502 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002503 .alg = "cbc(cast6)",
2504 .test = alg_test_skcipher,
2505 .suite = {
2506 .cipher = {
2507 .enc = {
2508 .vecs = cast6_cbc_enc_tv_template,
2509 .count = CAST6_CBC_ENC_TEST_VECTORS
2510 },
2511 .dec = {
2512 .vecs = cast6_cbc_dec_tv_template,
2513 .count = CAST6_CBC_DEC_TEST_VECTORS
2514 }
2515 }
2516 }
2517 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002518 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002519 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002520 .suite = {
2521 .cipher = {
2522 .enc = {
2523 .vecs = des_cbc_enc_tv_template,
2524 .count = DES_CBC_ENC_TEST_VECTORS
2525 },
2526 .dec = {
2527 .vecs = des_cbc_dec_tv_template,
2528 .count = DES_CBC_DEC_TEST_VECTORS
2529 }
2530 }
2531 }
2532 }, {
2533 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002534 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002535 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002536 .suite = {
2537 .cipher = {
2538 .enc = {
2539 .vecs = des3_ede_cbc_enc_tv_template,
2540 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2541 },
2542 .dec = {
2543 .vecs = des3_ede_cbc_dec_tv_template,
2544 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2545 }
2546 }
2547 }
2548 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002549 .alg = "cbc(serpent)",
2550 .test = alg_test_skcipher,
2551 .suite = {
2552 .cipher = {
2553 .enc = {
2554 .vecs = serpent_cbc_enc_tv_template,
2555 .count = SERPENT_CBC_ENC_TEST_VECTORS
2556 },
2557 .dec = {
2558 .vecs = serpent_cbc_dec_tv_template,
2559 .count = SERPENT_CBC_DEC_TEST_VECTORS
2560 }
2561 }
2562 }
2563 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002564 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002565 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002566 .suite = {
2567 .cipher = {
2568 .enc = {
2569 .vecs = tf_cbc_enc_tv_template,
2570 .count = TF_CBC_ENC_TEST_VECTORS
2571 },
2572 .dec = {
2573 .vecs = tf_cbc_dec_tv_template,
2574 .count = TF_CBC_DEC_TEST_VECTORS
2575 }
2576 }
2577 }
2578 }, {
2579 .alg = "ccm(aes)",
2580 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002581 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002582 .suite = {
2583 .aead = {
2584 .enc = {
2585 .vecs = aes_ccm_enc_tv_template,
2586 .count = AES_CCM_ENC_TEST_VECTORS
2587 },
2588 .dec = {
2589 .vecs = aes_ccm_dec_tv_template,
2590 .count = AES_CCM_DEC_TEST_VECTORS
2591 }
2592 }
2593 }
2594 }, {
Martin Willi3590ebf2015-06-01 13:43:57 +02002595 .alg = "chacha20",
2596 .test = alg_test_skcipher,
2597 .suite = {
2598 .cipher = {
2599 .enc = {
2600 .vecs = chacha20_enc_tv_template,
2601 .count = CHACHA20_ENC_TEST_VECTORS
2602 },
2603 .dec = {
2604 .vecs = chacha20_enc_tv_template,
2605 .count = CHACHA20_ENC_TEST_VECTORS
2606 },
2607 }
2608 }
2609 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002610 .alg = "cmac(aes)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002611 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002612 .test = alg_test_hash,
2613 .suite = {
2614 .hash = {
2615 .vecs = aes_cmac128_tv_template,
2616 .count = CMAC_AES_TEST_VECTORS
2617 }
2618 }
2619 }, {
2620 .alg = "cmac(des3_ede)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002621 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002622 .test = alg_test_hash,
2623 .suite = {
2624 .hash = {
2625 .vecs = des3_ede_cmac64_tv_template,
2626 .count = CMAC_DES3_EDE_TEST_VECTORS
2627 }
2628 }
2629 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002630 .alg = "compress_null",
2631 .test = alg_test_null,
2632 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02002633 .alg = "crc32",
2634 .test = alg_test_hash,
2635 .suite = {
2636 .hash = {
2637 .vecs = crc32_tv_template,
2638 .count = CRC32_TEST_VECTORS
2639 }
2640 }
2641 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002642 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002643 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002644 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002645 .suite = {
2646 .hash = {
2647 .vecs = crc32c_tv_template,
2648 .count = CRC32C_TEST_VECTORS
2649 }
2650 }
2651 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002652 .alg = "crct10dif",
2653 .test = alg_test_hash,
2654 .fips_allowed = 1,
2655 .suite = {
2656 .hash = {
2657 .vecs = crct10dif_tv_template,
2658 .count = CRCT10DIF_TEST_VECTORS
2659 }
2660 }
2661 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002662 .alg = "cryptd(__driver-cbc-aes-aesni)",
2663 .test = alg_test_null,
2664 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002665 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002666 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2667 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002668 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002669 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2670 .test = alg_test_null,
2671 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002672 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2673 .test = alg_test_null,
2674 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002675 .alg = "cryptd(__driver-ecb-aes-aesni)",
2676 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002677 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002678 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002679 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2680 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002681 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002682 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2683 .test = alg_test_null,
2684 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002685 .alg = "cryptd(__driver-ecb-cast5-avx)",
2686 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002687 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002688 .alg = "cryptd(__driver-ecb-cast6-avx)",
2689 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002690 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002691 .alg = "cryptd(__driver-ecb-serpent-avx)",
2692 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002693 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002694 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2695 .test = alg_test_null,
2696 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002697 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2698 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002699 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002700 .alg = "cryptd(__driver-ecb-twofish-avx)",
2701 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002702 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002703 .alg = "cryptd(__driver-gcm-aes-aesni)",
2704 .test = alg_test_null,
2705 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002706 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002707 .alg = "cryptd(__ghash-pclmulqdqni)",
2708 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002709 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002710 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002711 .alg = "ctr(aes)",
2712 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002713 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002714 .suite = {
2715 .cipher = {
2716 .enc = {
2717 .vecs = aes_ctr_enc_tv_template,
2718 .count = AES_CTR_ENC_TEST_VECTORS
2719 },
2720 .dec = {
2721 .vecs = aes_ctr_dec_tv_template,
2722 .count = AES_CTR_DEC_TEST_VECTORS
2723 }
2724 }
2725 }
2726 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002727 .alg = "ctr(blowfish)",
2728 .test = alg_test_skcipher,
2729 .suite = {
2730 .cipher = {
2731 .enc = {
2732 .vecs = bf_ctr_enc_tv_template,
2733 .count = BF_CTR_ENC_TEST_VECTORS
2734 },
2735 .dec = {
2736 .vecs = bf_ctr_dec_tv_template,
2737 .count = BF_CTR_DEC_TEST_VECTORS
2738 }
2739 }
2740 }
2741 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002742 .alg = "ctr(camellia)",
2743 .test = alg_test_skcipher,
2744 .suite = {
2745 .cipher = {
2746 .enc = {
2747 .vecs = camellia_ctr_enc_tv_template,
2748 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2749 },
2750 .dec = {
2751 .vecs = camellia_ctr_dec_tv_template,
2752 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2753 }
2754 }
2755 }
2756 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002757 .alg = "ctr(cast5)",
2758 .test = alg_test_skcipher,
2759 .suite = {
2760 .cipher = {
2761 .enc = {
2762 .vecs = cast5_ctr_enc_tv_template,
2763 .count = CAST5_CTR_ENC_TEST_VECTORS
2764 },
2765 .dec = {
2766 .vecs = cast5_ctr_dec_tv_template,
2767 .count = CAST5_CTR_DEC_TEST_VECTORS
2768 }
2769 }
2770 }
2771 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002772 .alg = "ctr(cast6)",
2773 .test = alg_test_skcipher,
2774 .suite = {
2775 .cipher = {
2776 .enc = {
2777 .vecs = cast6_ctr_enc_tv_template,
2778 .count = CAST6_CTR_ENC_TEST_VECTORS
2779 },
2780 .dec = {
2781 .vecs = cast6_ctr_dec_tv_template,
2782 .count = CAST6_CTR_DEC_TEST_VECTORS
2783 }
2784 }
2785 }
2786 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002787 .alg = "ctr(des)",
2788 .test = alg_test_skcipher,
2789 .suite = {
2790 .cipher = {
2791 .enc = {
2792 .vecs = des_ctr_enc_tv_template,
2793 .count = DES_CTR_ENC_TEST_VECTORS
2794 },
2795 .dec = {
2796 .vecs = des_ctr_dec_tv_template,
2797 .count = DES_CTR_DEC_TEST_VECTORS
2798 }
2799 }
2800 }
2801 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002802 .alg = "ctr(des3_ede)",
2803 .test = alg_test_skcipher,
2804 .suite = {
2805 .cipher = {
2806 .enc = {
2807 .vecs = des3_ede_ctr_enc_tv_template,
2808 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2809 },
2810 .dec = {
2811 .vecs = des3_ede_ctr_dec_tv_template,
2812 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2813 }
2814 }
2815 }
2816 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002817 .alg = "ctr(serpent)",
2818 .test = alg_test_skcipher,
2819 .suite = {
2820 .cipher = {
2821 .enc = {
2822 .vecs = serpent_ctr_enc_tv_template,
2823 .count = SERPENT_CTR_ENC_TEST_VECTORS
2824 },
2825 .dec = {
2826 .vecs = serpent_ctr_dec_tv_template,
2827 .count = SERPENT_CTR_DEC_TEST_VECTORS
2828 }
2829 }
2830 }
2831 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002832 .alg = "ctr(twofish)",
2833 .test = alg_test_skcipher,
2834 .suite = {
2835 .cipher = {
2836 .enc = {
2837 .vecs = tf_ctr_enc_tv_template,
2838 .count = TF_CTR_ENC_TEST_VECTORS
2839 },
2840 .dec = {
2841 .vecs = tf_ctr_dec_tv_template,
2842 .count = TF_CTR_DEC_TEST_VECTORS
2843 }
2844 }
2845 }
2846 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002847 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002848 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002849 .suite = {
2850 .cipher = {
2851 .enc = {
2852 .vecs = cts_mode_enc_tv_template,
2853 .count = CTS_MODE_ENC_TEST_VECTORS
2854 },
2855 .dec = {
2856 .vecs = cts_mode_dec_tv_template,
2857 .count = CTS_MODE_DEC_TEST_VECTORS
2858 }
2859 }
2860 }
2861 }, {
2862 .alg = "deflate",
2863 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002864 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002865 .suite = {
2866 .comp = {
2867 .comp = {
2868 .vecs = deflate_comp_tv_template,
2869 .count = DEFLATE_COMP_TEST_VECTORS
2870 },
2871 .decomp = {
2872 .vecs = deflate_decomp_tv_template,
2873 .count = DEFLATE_DECOMP_TEST_VECTORS
2874 }
2875 }
2876 }
2877 }, {
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002878 .alg = "dh",
2879 .test = alg_test_kpp,
2880 .fips_allowed = 1,
2881 .suite = {
2882 .kpp = {
2883 .vecs = dh_tv_template,
2884 .count = DH_TEST_VECTORS
2885 }
2886 }
2887 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002888 .alg = "digest_null",
2889 .test = alg_test_null,
2890 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002891 .alg = "drbg_nopr_ctr_aes128",
2892 .test = alg_test_drbg,
2893 .fips_allowed = 1,
2894 .suite = {
2895 .drbg = {
2896 .vecs = drbg_nopr_ctr_aes128_tv_template,
2897 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2898 }
2899 }
2900 }, {
2901 .alg = "drbg_nopr_ctr_aes192",
2902 .test = alg_test_drbg,
2903 .fips_allowed = 1,
2904 .suite = {
2905 .drbg = {
2906 .vecs = drbg_nopr_ctr_aes192_tv_template,
2907 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2908 }
2909 }
2910 }, {
2911 .alg = "drbg_nopr_ctr_aes256",
2912 .test = alg_test_drbg,
2913 .fips_allowed = 1,
2914 .suite = {
2915 .drbg = {
2916 .vecs = drbg_nopr_ctr_aes256_tv_template,
2917 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2918 }
2919 }
2920 }, {
2921 /*
2922 * There is no need to specifically test the DRBG with every
2923 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2924 */
2925 .alg = "drbg_nopr_hmac_sha1",
2926 .fips_allowed = 1,
2927 .test = alg_test_null,
2928 }, {
2929 .alg = "drbg_nopr_hmac_sha256",
2930 .test = alg_test_drbg,
2931 .fips_allowed = 1,
2932 .suite = {
2933 .drbg = {
2934 .vecs = drbg_nopr_hmac_sha256_tv_template,
2935 .count =
2936 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2937 }
2938 }
2939 }, {
2940 /* covered by drbg_nopr_hmac_sha256 test */
2941 .alg = "drbg_nopr_hmac_sha384",
2942 .fips_allowed = 1,
2943 .test = alg_test_null,
2944 }, {
2945 .alg = "drbg_nopr_hmac_sha512",
2946 .test = alg_test_null,
2947 .fips_allowed = 1,
2948 }, {
2949 .alg = "drbg_nopr_sha1",
2950 .fips_allowed = 1,
2951 .test = alg_test_null,
2952 }, {
2953 .alg = "drbg_nopr_sha256",
2954 .test = alg_test_drbg,
2955 .fips_allowed = 1,
2956 .suite = {
2957 .drbg = {
2958 .vecs = drbg_nopr_sha256_tv_template,
2959 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2960 }
2961 }
2962 }, {
2963 /* covered by drbg_nopr_sha256 test */
2964 .alg = "drbg_nopr_sha384",
2965 .fips_allowed = 1,
2966 .test = alg_test_null,
2967 }, {
2968 .alg = "drbg_nopr_sha512",
2969 .fips_allowed = 1,
2970 .test = alg_test_null,
2971 }, {
2972 .alg = "drbg_pr_ctr_aes128",
2973 .test = alg_test_drbg,
2974 .fips_allowed = 1,
2975 .suite = {
2976 .drbg = {
2977 .vecs = drbg_pr_ctr_aes128_tv_template,
2978 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2979 }
2980 }
2981 }, {
2982 /* covered by drbg_pr_ctr_aes128 test */
2983 .alg = "drbg_pr_ctr_aes192",
2984 .fips_allowed = 1,
2985 .test = alg_test_null,
2986 }, {
2987 .alg = "drbg_pr_ctr_aes256",
2988 .fips_allowed = 1,
2989 .test = alg_test_null,
2990 }, {
2991 .alg = "drbg_pr_hmac_sha1",
2992 .fips_allowed = 1,
2993 .test = alg_test_null,
2994 }, {
2995 .alg = "drbg_pr_hmac_sha256",
2996 .test = alg_test_drbg,
2997 .fips_allowed = 1,
2998 .suite = {
2999 .drbg = {
3000 .vecs = drbg_pr_hmac_sha256_tv_template,
3001 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
3002 }
3003 }
3004 }, {
3005 /* covered by drbg_pr_hmac_sha256 test */
3006 .alg = "drbg_pr_hmac_sha384",
3007 .fips_allowed = 1,
3008 .test = alg_test_null,
3009 }, {
3010 .alg = "drbg_pr_hmac_sha512",
3011 .test = alg_test_null,
3012 .fips_allowed = 1,
3013 }, {
3014 .alg = "drbg_pr_sha1",
3015 .fips_allowed = 1,
3016 .test = alg_test_null,
3017 }, {
3018 .alg = "drbg_pr_sha256",
3019 .test = alg_test_drbg,
3020 .fips_allowed = 1,
3021 .suite = {
3022 .drbg = {
3023 .vecs = drbg_pr_sha256_tv_template,
3024 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
3025 }
3026 }
3027 }, {
3028 /* covered by drbg_pr_sha256 test */
3029 .alg = "drbg_pr_sha384",
3030 .fips_allowed = 1,
3031 .test = alg_test_null,
3032 }, {
3033 .alg = "drbg_pr_sha512",
3034 .fips_allowed = 1,
3035 .test = alg_test_null,
3036 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08003037 .alg = "ecb(__aes-aesni)",
3038 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02003039 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08003040 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003041 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003042 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003043 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003044 .suite = {
3045 .cipher = {
3046 .enc = {
3047 .vecs = aes_enc_tv_template,
3048 .count = AES_ENC_TEST_VECTORS
3049 },
3050 .dec = {
3051 .vecs = aes_dec_tv_template,
3052 .count = AES_DEC_TEST_VECTORS
3053 }
3054 }
3055 }
3056 }, {
3057 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003058 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003059 .suite = {
3060 .cipher = {
3061 .enc = {
3062 .vecs = anubis_enc_tv_template,
3063 .count = ANUBIS_ENC_TEST_VECTORS
3064 },
3065 .dec = {
3066 .vecs = anubis_dec_tv_template,
3067 .count = ANUBIS_DEC_TEST_VECTORS
3068 }
3069 }
3070 }
3071 }, {
3072 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003073 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003074 .suite = {
3075 .cipher = {
3076 .enc = {
3077 .vecs = arc4_enc_tv_template,
3078 .count = ARC4_ENC_TEST_VECTORS
3079 },
3080 .dec = {
3081 .vecs = arc4_dec_tv_template,
3082 .count = ARC4_DEC_TEST_VECTORS
3083 }
3084 }
3085 }
3086 }, {
3087 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003088 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003089 .suite = {
3090 .cipher = {
3091 .enc = {
3092 .vecs = bf_enc_tv_template,
3093 .count = BF_ENC_TEST_VECTORS
3094 },
3095 .dec = {
3096 .vecs = bf_dec_tv_template,
3097 .count = BF_DEC_TEST_VECTORS
3098 }
3099 }
3100 }
3101 }, {
3102 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003103 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003104 .suite = {
3105 .cipher = {
3106 .enc = {
3107 .vecs = camellia_enc_tv_template,
3108 .count = CAMELLIA_ENC_TEST_VECTORS
3109 },
3110 .dec = {
3111 .vecs = camellia_dec_tv_template,
3112 .count = CAMELLIA_DEC_TEST_VECTORS
3113 }
3114 }
3115 }
3116 }, {
3117 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003118 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003119 .suite = {
3120 .cipher = {
3121 .enc = {
3122 .vecs = cast5_enc_tv_template,
3123 .count = CAST5_ENC_TEST_VECTORS
3124 },
3125 .dec = {
3126 .vecs = cast5_dec_tv_template,
3127 .count = CAST5_DEC_TEST_VECTORS
3128 }
3129 }
3130 }
3131 }, {
3132 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003133 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003134 .suite = {
3135 .cipher = {
3136 .enc = {
3137 .vecs = cast6_enc_tv_template,
3138 .count = CAST6_ENC_TEST_VECTORS
3139 },
3140 .dec = {
3141 .vecs = cast6_dec_tv_template,
3142 .count = CAST6_DEC_TEST_VECTORS
3143 }
3144 }
3145 }
3146 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003147 .alg = "ecb(cipher_null)",
3148 .test = alg_test_null,
3149 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003150 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003151 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003152 .suite = {
3153 .cipher = {
3154 .enc = {
3155 .vecs = des_enc_tv_template,
3156 .count = DES_ENC_TEST_VECTORS
3157 },
3158 .dec = {
3159 .vecs = des_dec_tv_template,
3160 .count = DES_DEC_TEST_VECTORS
3161 }
3162 }
3163 }
3164 }, {
3165 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003166 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003167 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003168 .suite = {
3169 .cipher = {
3170 .enc = {
3171 .vecs = des3_ede_enc_tv_template,
3172 .count = DES3_EDE_ENC_TEST_VECTORS
3173 },
3174 .dec = {
3175 .vecs = des3_ede_dec_tv_template,
3176 .count = DES3_EDE_DEC_TEST_VECTORS
3177 }
3178 }
3179 }
3180 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003181 .alg = "ecb(fcrypt)",
3182 .test = alg_test_skcipher,
3183 .suite = {
3184 .cipher = {
3185 .enc = {
3186 .vecs = fcrypt_pcbc_enc_tv_template,
3187 .count = 1
3188 },
3189 .dec = {
3190 .vecs = fcrypt_pcbc_dec_tv_template,
3191 .count = 1
3192 }
3193 }
3194 }
3195 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003196 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003197 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003198 .suite = {
3199 .cipher = {
3200 .enc = {
3201 .vecs = khazad_enc_tv_template,
3202 .count = KHAZAD_ENC_TEST_VECTORS
3203 },
3204 .dec = {
3205 .vecs = khazad_dec_tv_template,
3206 .count = KHAZAD_DEC_TEST_VECTORS
3207 }
3208 }
3209 }
3210 }, {
3211 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003212 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003213 .suite = {
3214 .cipher = {
3215 .enc = {
3216 .vecs = seed_enc_tv_template,
3217 .count = SEED_ENC_TEST_VECTORS
3218 },
3219 .dec = {
3220 .vecs = seed_dec_tv_template,
3221 .count = SEED_DEC_TEST_VECTORS
3222 }
3223 }
3224 }
3225 }, {
3226 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003227 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003228 .suite = {
3229 .cipher = {
3230 .enc = {
3231 .vecs = serpent_enc_tv_template,
3232 .count = SERPENT_ENC_TEST_VECTORS
3233 },
3234 .dec = {
3235 .vecs = serpent_dec_tv_template,
3236 .count = SERPENT_DEC_TEST_VECTORS
3237 }
3238 }
3239 }
3240 }, {
3241 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003242 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003243 .suite = {
3244 .cipher = {
3245 .enc = {
3246 .vecs = tea_enc_tv_template,
3247 .count = TEA_ENC_TEST_VECTORS
3248 },
3249 .dec = {
3250 .vecs = tea_dec_tv_template,
3251 .count = TEA_DEC_TEST_VECTORS
3252 }
3253 }
3254 }
3255 }, {
3256 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003257 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003258 .suite = {
3259 .cipher = {
3260 .enc = {
3261 .vecs = tnepres_enc_tv_template,
3262 .count = TNEPRES_ENC_TEST_VECTORS
3263 },
3264 .dec = {
3265 .vecs = tnepres_dec_tv_template,
3266 .count = TNEPRES_DEC_TEST_VECTORS
3267 }
3268 }
3269 }
3270 }, {
3271 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003272 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003273 .suite = {
3274 .cipher = {
3275 .enc = {
3276 .vecs = tf_enc_tv_template,
3277 .count = TF_ENC_TEST_VECTORS
3278 },
3279 .dec = {
3280 .vecs = tf_dec_tv_template,
3281 .count = TF_DEC_TEST_VECTORS
3282 }
3283 }
3284 }
3285 }, {
3286 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003287 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003288 .suite = {
3289 .cipher = {
3290 .enc = {
3291 .vecs = xeta_enc_tv_template,
3292 .count = XETA_ENC_TEST_VECTORS
3293 },
3294 .dec = {
3295 .vecs = xeta_dec_tv_template,
3296 .count = XETA_DEC_TEST_VECTORS
3297 }
3298 }
3299 }
3300 }, {
3301 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003302 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003303 .suite = {
3304 .cipher = {
3305 .enc = {
3306 .vecs = xtea_enc_tv_template,
3307 .count = XTEA_ENC_TEST_VECTORS
3308 },
3309 .dec = {
3310 .vecs = xtea_dec_tv_template,
3311 .count = XTEA_DEC_TEST_VECTORS
3312 }
3313 }
3314 }
3315 }, {
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003316 .alg = "ecdh",
3317 .test = alg_test_kpp,
3318 .fips_allowed = 1,
3319 .suite = {
3320 .kpp = {
3321 .vecs = ecdh_tv_template,
3322 .count = ECDH_TEST_VECTORS
3323 }
3324 }
3325 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003326 .alg = "gcm(aes)",
3327 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003328 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003329 .suite = {
3330 .aead = {
3331 .enc = {
3332 .vecs = aes_gcm_enc_tv_template,
3333 .count = AES_GCM_ENC_TEST_VECTORS
3334 },
3335 .dec = {
3336 .vecs = aes_gcm_dec_tv_template,
3337 .count = AES_GCM_DEC_TEST_VECTORS
3338 }
3339 }
3340 }
3341 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003342 .alg = "ghash",
3343 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003344 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003345 .suite = {
3346 .hash = {
3347 .vecs = ghash_tv_template,
3348 .count = GHASH_TEST_VECTORS
3349 }
3350 }
3351 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003352 .alg = "hmac(crc32)",
3353 .test = alg_test_hash,
3354 .suite = {
3355 .hash = {
3356 .vecs = bfin_crc_tv_template,
3357 .count = BFIN_CRC_TEST_VECTORS
3358 }
3359 }
3360 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003361 .alg = "hmac(md5)",
3362 .test = alg_test_hash,
3363 .suite = {
3364 .hash = {
3365 .vecs = hmac_md5_tv_template,
3366 .count = HMAC_MD5_TEST_VECTORS
3367 }
3368 }
3369 }, {
3370 .alg = "hmac(rmd128)",
3371 .test = alg_test_hash,
3372 .suite = {
3373 .hash = {
3374 .vecs = hmac_rmd128_tv_template,
3375 .count = HMAC_RMD128_TEST_VECTORS
3376 }
3377 }
3378 }, {
3379 .alg = "hmac(rmd160)",
3380 .test = alg_test_hash,
3381 .suite = {
3382 .hash = {
3383 .vecs = hmac_rmd160_tv_template,
3384 .count = HMAC_RMD160_TEST_VECTORS
3385 }
3386 }
3387 }, {
3388 .alg = "hmac(sha1)",
3389 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003390 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003391 .suite = {
3392 .hash = {
3393 .vecs = hmac_sha1_tv_template,
3394 .count = HMAC_SHA1_TEST_VECTORS
3395 }
3396 }
3397 }, {
3398 .alg = "hmac(sha224)",
3399 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003400 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003401 .suite = {
3402 .hash = {
3403 .vecs = hmac_sha224_tv_template,
3404 .count = HMAC_SHA224_TEST_VECTORS
3405 }
3406 }
3407 }, {
3408 .alg = "hmac(sha256)",
3409 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003410 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003411 .suite = {
3412 .hash = {
3413 .vecs = hmac_sha256_tv_template,
3414 .count = HMAC_SHA256_TEST_VECTORS
3415 }
3416 }
3417 }, {
raveendra padasalagi98eca722016-07-01 11:16:54 +05303418 .alg = "hmac(sha3-224)",
3419 .test = alg_test_hash,
3420 .fips_allowed = 1,
3421 .suite = {
3422 .hash = {
3423 .vecs = hmac_sha3_224_tv_template,
3424 .count = HMAC_SHA3_224_TEST_VECTORS
3425 }
3426 }
3427 }, {
3428 .alg = "hmac(sha3-256)",
3429 .test = alg_test_hash,
3430 .fips_allowed = 1,
3431 .suite = {
3432 .hash = {
3433 .vecs = hmac_sha3_256_tv_template,
3434 .count = HMAC_SHA3_256_TEST_VECTORS
3435 }
3436 }
3437 }, {
3438 .alg = "hmac(sha3-384)",
3439 .test = alg_test_hash,
3440 .fips_allowed = 1,
3441 .suite = {
3442 .hash = {
3443 .vecs = hmac_sha3_384_tv_template,
3444 .count = HMAC_SHA3_384_TEST_VECTORS
3445 }
3446 }
3447 }, {
3448 .alg = "hmac(sha3-512)",
3449 .test = alg_test_hash,
3450 .fips_allowed = 1,
3451 .suite = {
3452 .hash = {
3453 .vecs = hmac_sha3_512_tv_template,
3454 .count = HMAC_SHA3_512_TEST_VECTORS
3455 }
3456 }
3457 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003458 .alg = "hmac(sha384)",
3459 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003460 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003461 .suite = {
3462 .hash = {
3463 .vecs = hmac_sha384_tv_template,
3464 .count = HMAC_SHA384_TEST_VECTORS
3465 }
3466 }
3467 }, {
3468 .alg = "hmac(sha512)",
3469 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003470 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003471 .suite = {
3472 .hash = {
3473 .vecs = hmac_sha512_tv_template,
3474 .count = HMAC_SHA512_TEST_VECTORS
3475 }
3476 }
3477 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003478 .alg = "jitterentropy_rng",
3479 .fips_allowed = 1,
3480 .test = alg_test_null,
3481 }, {
Stephan Mueller35351982015-09-21 20:59:56 +02003482 .alg = "kw(aes)",
3483 .test = alg_test_skcipher,
3484 .fips_allowed = 1,
3485 .suite = {
3486 .cipher = {
3487 .enc = {
3488 .vecs = aes_kw_enc_tv_template,
3489 .count = ARRAY_SIZE(aes_kw_enc_tv_template)
3490 },
3491 .dec = {
3492 .vecs = aes_kw_dec_tv_template,
3493 .count = ARRAY_SIZE(aes_kw_dec_tv_template)
3494 }
3495 }
3496 }
3497 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003498 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003499 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003500 .suite = {
3501 .cipher = {
3502 .enc = {
3503 .vecs = aes_lrw_enc_tv_template,
3504 .count = AES_LRW_ENC_TEST_VECTORS
3505 },
3506 .dec = {
3507 .vecs = aes_lrw_dec_tv_template,
3508 .count = AES_LRW_DEC_TEST_VECTORS
3509 }
3510 }
3511 }
3512 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003513 .alg = "lrw(camellia)",
3514 .test = alg_test_skcipher,
3515 .suite = {
3516 .cipher = {
3517 .enc = {
3518 .vecs = camellia_lrw_enc_tv_template,
3519 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3520 },
3521 .dec = {
3522 .vecs = camellia_lrw_dec_tv_template,
3523 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3524 }
3525 }
3526 }
3527 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003528 .alg = "lrw(cast6)",
3529 .test = alg_test_skcipher,
3530 .suite = {
3531 .cipher = {
3532 .enc = {
3533 .vecs = cast6_lrw_enc_tv_template,
3534 .count = CAST6_LRW_ENC_TEST_VECTORS
3535 },
3536 .dec = {
3537 .vecs = cast6_lrw_dec_tv_template,
3538 .count = CAST6_LRW_DEC_TEST_VECTORS
3539 }
3540 }
3541 }
3542 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003543 .alg = "lrw(serpent)",
3544 .test = alg_test_skcipher,
3545 .suite = {
3546 .cipher = {
3547 .enc = {
3548 .vecs = serpent_lrw_enc_tv_template,
3549 .count = SERPENT_LRW_ENC_TEST_VECTORS
3550 },
3551 .dec = {
3552 .vecs = serpent_lrw_dec_tv_template,
3553 .count = SERPENT_LRW_DEC_TEST_VECTORS
3554 }
3555 }
3556 }
3557 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003558 .alg = "lrw(twofish)",
3559 .test = alg_test_skcipher,
3560 .suite = {
3561 .cipher = {
3562 .enc = {
3563 .vecs = tf_lrw_enc_tv_template,
3564 .count = TF_LRW_ENC_TEST_VECTORS
3565 },
3566 .dec = {
3567 .vecs = tf_lrw_dec_tv_template,
3568 .count = TF_LRW_DEC_TEST_VECTORS
3569 }
3570 }
3571 }
3572 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003573 .alg = "lz4",
3574 .test = alg_test_comp,
3575 .fips_allowed = 1,
3576 .suite = {
3577 .comp = {
3578 .comp = {
3579 .vecs = lz4_comp_tv_template,
3580 .count = LZ4_COMP_TEST_VECTORS
3581 },
3582 .decomp = {
3583 .vecs = lz4_decomp_tv_template,
3584 .count = LZ4_DECOMP_TEST_VECTORS
3585 }
3586 }
3587 }
3588 }, {
3589 .alg = "lz4hc",
3590 .test = alg_test_comp,
3591 .fips_allowed = 1,
3592 .suite = {
3593 .comp = {
3594 .comp = {
3595 .vecs = lz4hc_comp_tv_template,
3596 .count = LZ4HC_COMP_TEST_VECTORS
3597 },
3598 .decomp = {
3599 .vecs = lz4hc_decomp_tv_template,
3600 .count = LZ4HC_DECOMP_TEST_VECTORS
3601 }
3602 }
3603 }
3604 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003605 .alg = "lzo",
3606 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003607 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003608 .suite = {
3609 .comp = {
3610 .comp = {
3611 .vecs = lzo_comp_tv_template,
3612 .count = LZO_COMP_TEST_VECTORS
3613 },
3614 .decomp = {
3615 .vecs = lzo_decomp_tv_template,
3616 .count = LZO_DECOMP_TEST_VECTORS
3617 }
3618 }
3619 }
3620 }, {
3621 .alg = "md4",
3622 .test = alg_test_hash,
3623 .suite = {
3624 .hash = {
3625 .vecs = md4_tv_template,
3626 .count = MD4_TEST_VECTORS
3627 }
3628 }
3629 }, {
3630 .alg = "md5",
3631 .test = alg_test_hash,
3632 .suite = {
3633 .hash = {
3634 .vecs = md5_tv_template,
3635 .count = MD5_TEST_VECTORS
3636 }
3637 }
3638 }, {
3639 .alg = "michael_mic",
3640 .test = alg_test_hash,
3641 .suite = {
3642 .hash = {
3643 .vecs = michael_mic_tv_template,
3644 .count = MICHAEL_MIC_TEST_VECTORS
3645 }
3646 }
3647 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003648 .alg = "ofb(aes)",
3649 .test = alg_test_skcipher,
3650 .fips_allowed = 1,
3651 .suite = {
3652 .cipher = {
3653 .enc = {
3654 .vecs = aes_ofb_enc_tv_template,
3655 .count = AES_OFB_ENC_TEST_VECTORS
3656 },
3657 .dec = {
3658 .vecs = aes_ofb_dec_tv_template,
3659 .count = AES_OFB_DEC_TEST_VECTORS
3660 }
3661 }
3662 }
3663 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003664 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003665 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003666 .suite = {
3667 .cipher = {
3668 .enc = {
3669 .vecs = fcrypt_pcbc_enc_tv_template,
3670 .count = FCRYPT_ENC_TEST_VECTORS
3671 },
3672 .dec = {
3673 .vecs = fcrypt_pcbc_dec_tv_template,
3674 .count = FCRYPT_DEC_TEST_VECTORS
3675 }
3676 }
3677 }
3678 }, {
Martin Willieee9dc62015-06-01 13:43:59 +02003679 .alg = "poly1305",
3680 .test = alg_test_hash,
3681 .suite = {
3682 .hash = {
3683 .vecs = poly1305_tv_template,
3684 .count = POLY1305_TEST_VECTORS
3685 }
3686 }
3687 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003688 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003689 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003690 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003691 .suite = {
3692 .cipher = {
3693 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003694 .vecs = aes_ctr_rfc3686_enc_tv_template,
3695 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003696 },
3697 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003698 .vecs = aes_ctr_rfc3686_dec_tv_template,
3699 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003700 }
3701 }
3702 }
3703 }, {
Herbert Xu3f31a742015-07-09 07:17:34 +08003704 .alg = "rfc4106(gcm(aes))",
Adrian Hoban69435b92010-11-04 15:02:04 -04003705 .test = alg_test_aead,
Jarod Wilsondb71f292015-01-23 12:42:15 -05003706 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003707 .suite = {
3708 .aead = {
3709 .enc = {
3710 .vecs = aes_gcm_rfc4106_enc_tv_template,
3711 .count = AES_GCM_4106_ENC_TEST_VECTORS
3712 },
3713 .dec = {
3714 .vecs = aes_gcm_rfc4106_dec_tv_template,
3715 .count = AES_GCM_4106_DEC_TEST_VECTORS
3716 }
3717 }
3718 }
3719 }, {
Herbert Xu544c4362015-07-14 16:53:22 +08003720 .alg = "rfc4309(ccm(aes))",
Jarod Wilson5d667322009-05-04 19:23:40 +08003721 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003722 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003723 .suite = {
3724 .aead = {
3725 .enc = {
3726 .vecs = aes_ccm_rfc4309_enc_tv_template,
3727 .count = AES_CCM_4309_ENC_TEST_VECTORS
3728 },
3729 .dec = {
3730 .vecs = aes_ccm_rfc4309_dec_tv_template,
3731 .count = AES_CCM_4309_DEC_TEST_VECTORS
3732 }
3733 }
3734 }
3735 }, {
Herbert Xubb687452015-06-16 13:54:24 +08003736 .alg = "rfc4543(gcm(aes))",
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003737 .test = alg_test_aead,
3738 .suite = {
3739 .aead = {
3740 .enc = {
3741 .vecs = aes_gcm_rfc4543_enc_tv_template,
3742 .count = AES_GCM_4543_ENC_TEST_VECTORS
3743 },
3744 .dec = {
3745 .vecs = aes_gcm_rfc4543_dec_tv_template,
3746 .count = AES_GCM_4543_DEC_TEST_VECTORS
3747 },
3748 }
3749 }
3750 }, {
Martin Williaf2b76b2015-06-01 13:44:01 +02003751 .alg = "rfc7539(chacha20,poly1305)",
3752 .test = alg_test_aead,
3753 .suite = {
3754 .aead = {
3755 .enc = {
3756 .vecs = rfc7539_enc_tv_template,
3757 .count = RFC7539_ENC_TEST_VECTORS
3758 },
3759 .dec = {
3760 .vecs = rfc7539_dec_tv_template,
3761 .count = RFC7539_DEC_TEST_VECTORS
3762 },
3763 }
3764 }
3765 }, {
Martin Willi59007582015-06-01 13:44:03 +02003766 .alg = "rfc7539esp(chacha20,poly1305)",
3767 .test = alg_test_aead,
3768 .suite = {
3769 .aead = {
3770 .enc = {
3771 .vecs = rfc7539esp_enc_tv_template,
3772 .count = RFC7539ESP_ENC_TEST_VECTORS
3773 },
3774 .dec = {
3775 .vecs = rfc7539esp_dec_tv_template,
3776 .count = RFC7539ESP_DEC_TEST_VECTORS
3777 },
3778 }
3779 }
3780 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003781 .alg = "rmd128",
3782 .test = alg_test_hash,
3783 .suite = {
3784 .hash = {
3785 .vecs = rmd128_tv_template,
3786 .count = RMD128_TEST_VECTORS
3787 }
3788 }
3789 }, {
3790 .alg = "rmd160",
3791 .test = alg_test_hash,
3792 .suite = {
3793 .hash = {
3794 .vecs = rmd160_tv_template,
3795 .count = RMD160_TEST_VECTORS
3796 }
3797 }
3798 }, {
3799 .alg = "rmd256",
3800 .test = alg_test_hash,
3801 .suite = {
3802 .hash = {
3803 .vecs = rmd256_tv_template,
3804 .count = RMD256_TEST_VECTORS
3805 }
3806 }
3807 }, {
3808 .alg = "rmd320",
3809 .test = alg_test_hash,
3810 .suite = {
3811 .hash = {
3812 .vecs = rmd320_tv_template,
3813 .count = RMD320_TEST_VECTORS
3814 }
3815 }
3816 }, {
Tadeusz Struk946cc462015-06-16 10:31:06 -07003817 .alg = "rsa",
3818 .test = alg_test_akcipher,
3819 .fips_allowed = 1,
3820 .suite = {
3821 .akcipher = {
3822 .vecs = rsa_tv_template,
3823 .count = RSA_TEST_VECTORS
3824 }
3825 }
3826 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003827 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003828 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003829 .suite = {
3830 .cipher = {
3831 .enc = {
3832 .vecs = salsa20_stream_enc_tv_template,
3833 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3834 }
3835 }
3836 }
3837 }, {
3838 .alg = "sha1",
3839 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003840 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003841 .suite = {
3842 .hash = {
3843 .vecs = sha1_tv_template,
3844 .count = SHA1_TEST_VECTORS
3845 }
3846 }
3847 }, {
3848 .alg = "sha224",
3849 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003850 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003851 .suite = {
3852 .hash = {
3853 .vecs = sha224_tv_template,
3854 .count = SHA224_TEST_VECTORS
3855 }
3856 }
3857 }, {
3858 .alg = "sha256",
3859 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003860 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003861 .suite = {
3862 .hash = {
3863 .vecs = sha256_tv_template,
3864 .count = SHA256_TEST_VECTORS
3865 }
3866 }
3867 }, {
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303868 .alg = "sha3-224",
3869 .test = alg_test_hash,
3870 .fips_allowed = 1,
3871 .suite = {
3872 .hash = {
3873 .vecs = sha3_224_tv_template,
3874 .count = SHA3_224_TEST_VECTORS
3875 }
3876 }
3877 }, {
3878 .alg = "sha3-256",
3879 .test = alg_test_hash,
3880 .fips_allowed = 1,
3881 .suite = {
3882 .hash = {
3883 .vecs = sha3_256_tv_template,
3884 .count = SHA3_256_TEST_VECTORS
3885 }
3886 }
3887 }, {
3888 .alg = "sha3-384",
3889 .test = alg_test_hash,
3890 .fips_allowed = 1,
3891 .suite = {
3892 .hash = {
3893 .vecs = sha3_384_tv_template,
3894 .count = SHA3_384_TEST_VECTORS
3895 }
3896 }
3897 }, {
3898 .alg = "sha3-512",
3899 .test = alg_test_hash,
3900 .fips_allowed = 1,
3901 .suite = {
3902 .hash = {
3903 .vecs = sha3_512_tv_template,
3904 .count = SHA3_512_TEST_VECTORS
3905 }
3906 }
3907 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003908 .alg = "sha384",
3909 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003910 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003911 .suite = {
3912 .hash = {
3913 .vecs = sha384_tv_template,
3914 .count = SHA384_TEST_VECTORS
3915 }
3916 }
3917 }, {
3918 .alg = "sha512",
3919 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003920 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003921 .suite = {
3922 .hash = {
3923 .vecs = sha512_tv_template,
3924 .count = SHA512_TEST_VECTORS
3925 }
3926 }
3927 }, {
3928 .alg = "tgr128",
3929 .test = alg_test_hash,
3930 .suite = {
3931 .hash = {
3932 .vecs = tgr128_tv_template,
3933 .count = TGR128_TEST_VECTORS
3934 }
3935 }
3936 }, {
3937 .alg = "tgr160",
3938 .test = alg_test_hash,
3939 .suite = {
3940 .hash = {
3941 .vecs = tgr160_tv_template,
3942 .count = TGR160_TEST_VECTORS
3943 }
3944 }
3945 }, {
3946 .alg = "tgr192",
3947 .test = alg_test_hash,
3948 .suite = {
3949 .hash = {
3950 .vecs = tgr192_tv_template,
3951 .count = TGR192_TEST_VECTORS
3952 }
3953 }
3954 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003955 .alg = "vmac(aes)",
3956 .test = alg_test_hash,
3957 .suite = {
3958 .hash = {
3959 .vecs = aes_vmac128_tv_template,
3960 .count = VMAC_AES_TEST_VECTORS
3961 }
3962 }
3963 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003964 .alg = "wp256",
3965 .test = alg_test_hash,
3966 .suite = {
3967 .hash = {
3968 .vecs = wp256_tv_template,
3969 .count = WP256_TEST_VECTORS
3970 }
3971 }
3972 }, {
3973 .alg = "wp384",
3974 .test = alg_test_hash,
3975 .suite = {
3976 .hash = {
3977 .vecs = wp384_tv_template,
3978 .count = WP384_TEST_VECTORS
3979 }
3980 }
3981 }, {
3982 .alg = "wp512",
3983 .test = alg_test_hash,
3984 .suite = {
3985 .hash = {
3986 .vecs = wp512_tv_template,
3987 .count = WP512_TEST_VECTORS
3988 }
3989 }
3990 }, {
3991 .alg = "xcbc(aes)",
3992 .test = alg_test_hash,
3993 .suite = {
3994 .hash = {
3995 .vecs = aes_xcbc128_tv_template,
3996 .count = XCBC_AES_TEST_VECTORS
3997 }
3998 }
3999 }, {
4000 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004001 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11004002 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004003 .suite = {
4004 .cipher = {
4005 .enc = {
4006 .vecs = aes_xts_enc_tv_template,
4007 .count = AES_XTS_ENC_TEST_VECTORS
4008 },
4009 .dec = {
4010 .vecs = aes_xts_dec_tv_template,
4011 .count = AES_XTS_DEC_TEST_VECTORS
4012 }
4013 }
4014 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08004015 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02004016 .alg = "xts(camellia)",
4017 .test = alg_test_skcipher,
4018 .suite = {
4019 .cipher = {
4020 .enc = {
4021 .vecs = camellia_xts_enc_tv_template,
4022 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
4023 },
4024 .dec = {
4025 .vecs = camellia_xts_dec_tv_template,
4026 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
4027 }
4028 }
4029 }
4030 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02004031 .alg = "xts(cast6)",
4032 .test = alg_test_skcipher,
4033 .suite = {
4034 .cipher = {
4035 .enc = {
4036 .vecs = cast6_xts_enc_tv_template,
4037 .count = CAST6_XTS_ENC_TEST_VECTORS
4038 },
4039 .dec = {
4040 .vecs = cast6_xts_dec_tv_template,
4041 .count = CAST6_XTS_DEC_TEST_VECTORS
4042 }
4043 }
4044 }
4045 }, {
Jussi Kivilinna18be20b2011-10-18 13:33:17 +03004046 .alg = "xts(serpent)",
4047 .test = alg_test_skcipher,
4048 .suite = {
4049 .cipher = {
4050 .enc = {
4051 .vecs = serpent_xts_enc_tv_template,
4052 .count = SERPENT_XTS_ENC_TEST_VECTORS
4053 },
4054 .dec = {
4055 .vecs = serpent_xts_dec_tv_template,
4056 .count = SERPENT_XTS_DEC_TEST_VECTORS
4057 }
4058 }
4059 }
4060 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03004061 .alg = "xts(twofish)",
4062 .test = alg_test_skcipher,
4063 .suite = {
4064 .cipher = {
4065 .enc = {
4066 .vecs = tf_xts_enc_tv_template,
4067 .count = TF_XTS_ENC_TEST_VECTORS
4068 },
4069 .dec = {
4070 .vecs = tf_xts_dec_tv_template,
4071 .count = TF_XTS_DEC_TEST_VECTORS
4072 }
4073 }
4074 }
Herbert Xuda7f0332008-07-31 17:08:25 +08004075 }
4076};
4077
Jussi Kivilinna57147582013-06-13 17:37:40 +03004078static bool alg_test_descs_checked;
4079
4080static void alg_test_descs_check_order(void)
4081{
4082 int i;
4083
4084 /* only check once */
4085 if (alg_test_descs_checked)
4086 return;
4087
4088 alg_test_descs_checked = true;
4089
4090 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
4091 int diff = strcmp(alg_test_descs[i - 1].alg,
4092 alg_test_descs[i].alg);
4093
4094 if (WARN_ON(diff > 0)) {
4095 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
4096 alg_test_descs[i - 1].alg,
4097 alg_test_descs[i].alg);
4098 }
4099
4100 if (WARN_ON(diff == 0)) {
4101 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
4102 alg_test_descs[i].alg);
4103 }
4104 }
4105}
4106
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004107static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08004108{
4109 int start = 0;
4110 int end = ARRAY_SIZE(alg_test_descs);
4111
4112 while (start < end) {
4113 int i = (start + end) / 2;
4114 int diff = strcmp(alg_test_descs[i].alg, alg);
4115
4116 if (diff > 0) {
4117 end = i;
4118 continue;
4119 }
4120
4121 if (diff < 0) {
4122 start = i + 1;
4123 continue;
4124 }
4125
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004126 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08004127 }
4128
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004129 return -1;
4130}
4131
4132int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
4133{
4134 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08004135 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08004136 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004137
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +01004138 if (!fips_enabled && notests) {
4139 printk_once(KERN_INFO "alg: self-tests disabled\n");
4140 return 0;
4141 }
4142
Jussi Kivilinna57147582013-06-13 17:37:40 +03004143 alg_test_descs_check_order();
4144
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004145 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
4146 char nalg[CRYPTO_MAX_ALG_NAME];
4147
4148 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
4149 sizeof(nalg))
4150 return -ENAMETOOLONG;
4151
4152 i = alg_find_test(nalg);
4153 if (i < 0)
4154 goto notest;
4155
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004156 if (fips_enabled && !alg_test_descs[i].fips_allowed)
4157 goto non_fips_alg;
4158
Jarod Wilson941fb322009-05-04 19:49:23 +08004159 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
4160 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004161 }
4162
4163 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08004164 j = alg_find_test(driver);
4165 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004166 goto notest;
4167
Herbert Xua68f6612009-07-02 16:32:12 +08004168 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
4169 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004170 goto non_fips_alg;
4171
Herbert Xua68f6612009-07-02 16:32:12 +08004172 rc = 0;
4173 if (i >= 0)
4174 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
4175 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03004176 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08004177 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
4178 type, mask);
4179
Jarod Wilson941fb322009-05-04 19:49:23 +08004180test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08004181 if (fips_enabled && rc)
4182 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
4183
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004184 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09004185 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004186
Neil Hormand12d6b62008-10-12 20:36:51 +08004187 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004188
4189notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08004190 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
4191 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004192non_fips_alg:
4193 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08004194}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004195
Herbert Xu326a6342010-08-06 09:40:28 +08004196#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004197
Herbert Xuda7f0332008-07-31 17:08:25 +08004198EXPORT_SYMBOL_GPL(alg_test);