blob: ded50b67c75784a98f4104fa95632d7fed681893 [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>
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +010036#include <crypto/acompress.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080037
38#include "internal.h"
Alexander Shishkin0b767f92010-06-03 20:53:43 +100039
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +010040static bool notests;
41module_param(notests, bool, 0644);
42MODULE_PARM_DESC(notests, "disable crypto self-tests");
43
Herbert Xu326a6342010-08-06 09:40:28 +080044#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
Alexander Shishkin0b767f92010-06-03 20:53:43 +100045
46/* a perfect nop */
47int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
48{
49 return 0;
50}
51
52#else
53
Herbert Xuda7f0332008-07-31 17:08:25 +080054#include "testmgr.h"
55
56/*
57 * Need slab memory for testing (size in number of pages).
58 */
59#define XBUFSIZE 8
60
61/*
62 * Indexes into the xbuf to simulate cross-page access.
63 */
64#define IDX1 32
65#define IDX2 32400
66#define IDX3 1
67#define IDX4 8193
68#define IDX5 22222
69#define IDX6 17101
70#define IDX7 27333
71#define IDX8 3000
72
73/*
74* Used by test_cipher()
75*/
76#define ENCRYPT 1
77#define DECRYPT 0
78
79struct tcrypt_result {
80 struct completion completion;
81 int err;
82};
83
84struct aead_test_suite {
85 struct {
86 struct aead_testvec *vecs;
87 unsigned int count;
88 } enc, dec;
89};
90
91struct cipher_test_suite {
92 struct {
93 struct cipher_testvec *vecs;
94 unsigned int count;
95 } enc, dec;
96};
97
98struct comp_test_suite {
99 struct {
100 struct comp_testvec *vecs;
101 unsigned int count;
102 } comp, decomp;
103};
104
105struct hash_test_suite {
106 struct hash_testvec *vecs;
107 unsigned int count;
108};
109
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800110struct cprng_test_suite {
111 struct cprng_testvec *vecs;
112 unsigned int count;
113};
114
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200115struct drbg_test_suite {
116 struct drbg_testvec *vecs;
117 unsigned int count;
118};
119
Tadeusz Struk946cc462015-06-16 10:31:06 -0700120struct akcipher_test_suite {
121 struct akcipher_testvec *vecs;
122 unsigned int count;
123};
124
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100125struct kpp_test_suite {
126 struct kpp_testvec *vecs;
127 unsigned int count;
128};
129
Herbert Xuda7f0332008-07-31 17:08:25 +0800130struct alg_test_desc {
131 const char *alg;
132 int (*test)(const struct alg_test_desc *desc, const char *driver,
133 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000134 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800135
136 union {
137 struct aead_test_suite aead;
138 struct cipher_test_suite cipher;
139 struct comp_test_suite comp;
140 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800141 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200142 struct drbg_test_suite drbg;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700143 struct akcipher_test_suite akcipher;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100144 struct kpp_test_suite kpp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800145 } suite;
146};
147
148static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
149
Herbert Xuda7f0332008-07-31 17:08:25 +0800150static void hexdump(unsigned char *buf, unsigned int len)
151{
152 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
153 16, 1,
154 buf, len, false);
155}
156
157static void tcrypt_complete(struct crypto_async_request *req, int err)
158{
159 struct tcrypt_result *res = req->data;
160
161 if (err == -EINPROGRESS)
162 return;
163
164 res->err = err;
165 complete(&res->completion);
166}
167
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800168static int testmgr_alloc_buf(char *buf[XBUFSIZE])
169{
170 int i;
171
172 for (i = 0; i < XBUFSIZE; i++) {
173 buf[i] = (void *)__get_free_page(GFP_KERNEL);
174 if (!buf[i])
175 goto err_free_buf;
176 }
177
178 return 0;
179
180err_free_buf:
181 while (i-- > 0)
182 free_page((unsigned long)buf[i]);
183
184 return -ENOMEM;
185}
186
187static void testmgr_free_buf(char *buf[XBUFSIZE])
188{
189 int i;
190
191 for (i = 0; i < XBUFSIZE; i++)
192 free_page((unsigned long)buf[i]);
193}
194
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300195static int wait_async_op(struct tcrypt_result *tr, int ret)
David S. Millera8f1a052010-05-19 14:12:03 +1000196{
197 if (ret == -EINPROGRESS || ret == -EBUSY) {
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100198 wait_for_completion(&tr->completion);
Wolfram Sang16735d02013-11-14 14:32:02 -0800199 reinit_completion(&tr->completion);
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100200 ret = tr->err;
David S. Millera8f1a052010-05-19 14:12:03 +1000201 }
202 return ret;
203}
204
Wang, Rui Y018ba952016-02-03 18:26:57 +0800205static int ahash_partial_update(struct ahash_request **preq,
206 struct crypto_ahash *tfm, struct hash_testvec *template,
207 void *hash_buff, int k, int temp, struct scatterlist *sg,
208 const char *algo, char *result, struct tcrypt_result *tresult)
209{
210 char *state;
211 struct ahash_request *req;
212 int statesize, ret = -EINVAL;
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200213 const char guard[] = { 0x00, 0xba, 0xad, 0x00 };
Wang, Rui Y018ba952016-02-03 18:26:57 +0800214
215 req = *preq;
216 statesize = crypto_ahash_statesize(
217 crypto_ahash_reqtfm(req));
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200218 state = kmalloc(statesize + sizeof(guard), GFP_KERNEL);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800219 if (!state) {
220 pr_err("alt: hash: Failed to alloc state for %s\n", algo);
221 goto out_nostate;
222 }
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200223 memcpy(state + statesize, guard, sizeof(guard));
Wang, Rui Y018ba952016-02-03 18:26:57 +0800224 ret = crypto_ahash_export(req, state);
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200225 WARN_ON(memcmp(state + statesize, guard, sizeof(guard)));
Wang, Rui Y018ba952016-02-03 18:26:57 +0800226 if (ret) {
227 pr_err("alt: hash: Failed to export() for %s\n", algo);
228 goto out;
229 }
230 ahash_request_free(req);
231 req = ahash_request_alloc(tfm, GFP_KERNEL);
232 if (!req) {
233 pr_err("alg: hash: Failed to alloc request for %s\n", algo);
234 goto out_noreq;
235 }
236 ahash_request_set_callback(req,
237 CRYPTO_TFM_REQ_MAY_BACKLOG,
238 tcrypt_complete, tresult);
239
240 memcpy(hash_buff, template->plaintext + temp,
241 template->tap[k]);
242 sg_init_one(&sg[0], hash_buff, template->tap[k]);
243 ahash_request_set_crypt(req, sg, result, template->tap[k]);
244 ret = crypto_ahash_import(req, state);
245 if (ret) {
246 pr_err("alg: hash: Failed to import() for %s\n", algo);
247 goto out;
248 }
249 ret = wait_async_op(tresult, crypto_ahash_update(req));
250 if (ret)
251 goto out;
252 *preq = req;
253 ret = 0;
254 goto out_noreq;
255out:
256 ahash_request_free(req);
257out_noreq:
258 kfree(state);
259out_nostate:
260 return ret;
261}
262
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300263static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
264 unsigned int tcount, bool use_digest,
265 const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800266{
267 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
268 unsigned int i, j, k, temp;
269 struct scatterlist sg[8];
Horia Geanta29b77e52014-07-23 11:59:38 +0300270 char *result;
271 char *key;
Herbert Xuda7f0332008-07-31 17:08:25 +0800272 struct ahash_request *req;
273 struct tcrypt_result tresult;
Herbert Xuda7f0332008-07-31 17:08:25 +0800274 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800275 char *xbuf[XBUFSIZE];
276 int ret = -ENOMEM;
277
Horia Geanta29b77e52014-07-23 11:59:38 +0300278 result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
279 if (!result)
280 return ret;
281 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
282 if (!key)
283 goto out_nobuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800284 if (testmgr_alloc_buf(xbuf))
285 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800286
287 init_completion(&tresult.completion);
288
289 req = ahash_request_alloc(tfm, GFP_KERNEL);
290 if (!req) {
291 printk(KERN_ERR "alg: hash: Failed to allocate request for "
292 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800293 goto out_noreq;
294 }
295 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
296 tcrypt_complete, &tresult);
297
Herbert Xua0cfae52009-05-29 16:23:12 +1000298 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800299 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000300 if (template[i].np)
301 continue;
302
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300303 ret = -EINVAL;
304 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
305 goto out;
306
Herbert Xua0cfae52009-05-29 16:23:12 +1000307 j++;
Horia Geanta29b77e52014-07-23 11:59:38 +0300308 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800309
310 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300311 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800312
313 memcpy(hash_buff, template[i].plaintext, template[i].psize);
314 sg_init_one(&sg[0], hash_buff, template[i].psize);
315
316 if (template[i].ksize) {
317 crypto_ahash_clear_flags(tfm, ~0);
Horia Geanta29b77e52014-07-23 11:59:38 +0300318 if (template[i].ksize > MAX_KEYLEN) {
319 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
320 j, algo, template[i].ksize, MAX_KEYLEN);
321 ret = -EINVAL;
322 goto out;
323 }
324 memcpy(key, template[i].key, template[i].ksize);
325 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
Herbert Xuda7f0332008-07-31 17:08:25 +0800326 if (ret) {
327 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000328 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800329 -ret);
330 goto out;
331 }
332 }
333
334 ahash_request_set_crypt(req, sg, result, template[i].psize);
David S. Millera8f1a052010-05-19 14:12:03 +1000335 if (use_digest) {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300336 ret = wait_async_op(&tresult, crypto_ahash_digest(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000337 if (ret) {
338 pr_err("alg: hash: digest failed on test %d "
339 "for %s: ret=%d\n", j, algo, -ret);
340 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800341 }
David S. Millera8f1a052010-05-19 14:12:03 +1000342 } else {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300343 ret = wait_async_op(&tresult, crypto_ahash_init(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000344 if (ret) {
345 pr_err("alt: hash: init failed on test %d "
346 "for %s: ret=%d\n", j, algo, -ret);
347 goto out;
348 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300349 ret = wait_async_op(&tresult, crypto_ahash_update(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000350 if (ret) {
351 pr_err("alt: hash: update failed on test %d "
352 "for %s: ret=%d\n", j, algo, -ret);
353 goto out;
354 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300355 ret = wait_async_op(&tresult, crypto_ahash_final(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000356 if (ret) {
357 pr_err("alt: hash: final failed on test %d "
358 "for %s: ret=%d\n", j, algo, -ret);
359 goto out;
360 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800361 }
362
363 if (memcmp(result, template[i].digest,
364 crypto_ahash_digestsize(tfm))) {
365 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000366 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800367 hexdump(result, crypto_ahash_digestsize(tfm));
368 ret = -EINVAL;
369 goto out;
370 }
371 }
372
373 j = 0;
374 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300375 /* alignment tests are only done with continuous buffers */
376 if (align_offset != 0)
377 break;
378
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300379 if (!template[i].np)
380 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800381
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300382 j++;
383 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800384
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300385 temp = 0;
386 sg_init_table(sg, template[i].np);
387 ret = -EINVAL;
388 for (k = 0; k < template[i].np; k++) {
389 if (WARN_ON(offset_in_page(IDX[k]) +
390 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +0800391 goto out;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300392 sg_set_buf(&sg[k],
393 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
394 offset_in_page(IDX[k]),
395 template[i].plaintext + temp,
396 template[i].tap[k]),
397 template[i].tap[k]);
398 temp += template[i].tap[k];
399 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800400
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300401 if (template[i].ksize) {
402 if (template[i].ksize > MAX_KEYLEN) {
403 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
404 j, algo, template[i].ksize, MAX_KEYLEN);
Herbert Xuda7f0332008-07-31 17:08:25 +0800405 ret = -EINVAL;
406 goto out;
407 }
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300408 crypto_ahash_clear_flags(tfm, ~0);
409 memcpy(key, template[i].key, template[i].ksize);
410 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
411
412 if (ret) {
413 printk(KERN_ERR "alg: hash: setkey "
414 "failed on chunking test %d "
415 "for %s: ret=%d\n", j, algo, -ret);
416 goto out;
417 }
418 }
419
420 ahash_request_set_crypt(req, sg, result, template[i].psize);
421 ret = crypto_ahash_digest(req);
422 switch (ret) {
423 case 0:
424 break;
425 case -EINPROGRESS:
426 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100427 wait_for_completion(&tresult.completion);
428 reinit_completion(&tresult.completion);
429 ret = tresult.err;
430 if (!ret)
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300431 break;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300432 /* fall through */
433 default:
434 printk(KERN_ERR "alg: hash: digest failed "
435 "on chunking test %d for %s: "
436 "ret=%d\n", j, algo, -ret);
437 goto out;
438 }
439
440 if (memcmp(result, template[i].digest,
441 crypto_ahash_digestsize(tfm))) {
442 printk(KERN_ERR "alg: hash: Chunking test %d "
443 "failed for %s\n", j, algo);
444 hexdump(result, crypto_ahash_digestsize(tfm));
445 ret = -EINVAL;
446 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800447 }
448 }
449
Wang, Rui Y018ba952016-02-03 18:26:57 +0800450 /* partial update exercise */
451 j = 0;
452 for (i = 0; i < tcount; i++) {
453 /* alignment tests are only done with continuous buffers */
454 if (align_offset != 0)
455 break;
456
457 if (template[i].np < 2)
458 continue;
459
460 j++;
461 memset(result, 0, MAX_DIGEST_SIZE);
462
463 ret = -EINVAL;
464 hash_buff = xbuf[0];
465 memcpy(hash_buff, template[i].plaintext,
466 template[i].tap[0]);
467 sg_init_one(&sg[0], hash_buff, template[i].tap[0]);
468
469 if (template[i].ksize) {
470 crypto_ahash_clear_flags(tfm, ~0);
471 if (template[i].ksize > MAX_KEYLEN) {
472 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
473 j, algo, template[i].ksize, MAX_KEYLEN);
474 ret = -EINVAL;
475 goto out;
476 }
477 memcpy(key, template[i].key, template[i].ksize);
478 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
479 if (ret) {
480 pr_err("alg: hash: setkey failed on test %d for %s: ret=%d\n",
481 j, algo, -ret);
482 goto out;
483 }
484 }
485
486 ahash_request_set_crypt(req, sg, result, template[i].tap[0]);
487 ret = wait_async_op(&tresult, crypto_ahash_init(req));
488 if (ret) {
489 pr_err("alt: hash: init failed on test %d for %s: ret=%d\n",
490 j, algo, -ret);
491 goto out;
492 }
493 ret = wait_async_op(&tresult, crypto_ahash_update(req));
494 if (ret) {
495 pr_err("alt: hash: update failed on test %d for %s: ret=%d\n",
496 j, algo, -ret);
497 goto out;
498 }
499
500 temp = template[i].tap[0];
501 for (k = 1; k < template[i].np; k++) {
502 ret = ahash_partial_update(&req, tfm, &template[i],
503 hash_buff, k, temp, &sg[0], algo, result,
504 &tresult);
505 if (ret) {
506 pr_err("hash: partial update failed on test %d for %s: ret=%d\n",
507 j, algo, -ret);
508 goto out_noreq;
509 }
510 temp += template[i].tap[k];
511 }
512 ret = wait_async_op(&tresult, crypto_ahash_final(req));
513 if (ret) {
514 pr_err("alt: hash: final failed on test %d for %s: ret=%d\n",
515 j, algo, -ret);
516 goto out;
517 }
518 if (memcmp(result, template[i].digest,
519 crypto_ahash_digestsize(tfm))) {
520 pr_err("alg: hash: Partial Test %d failed for %s\n",
521 j, algo);
522 hexdump(result, crypto_ahash_digestsize(tfm));
523 ret = -EINVAL;
524 goto out;
525 }
526 }
527
Herbert Xuda7f0332008-07-31 17:08:25 +0800528 ret = 0;
529
530out:
531 ahash_request_free(req);
532out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800533 testmgr_free_buf(xbuf);
534out_nobuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300535 kfree(key);
536 kfree(result);
Herbert Xuda7f0332008-07-31 17:08:25 +0800537 return ret;
538}
539
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300540static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
541 unsigned int tcount, bool use_digest)
542{
543 unsigned int alignmask;
544 int ret;
545
546 ret = __test_hash(tfm, template, tcount, use_digest, 0);
547 if (ret)
548 return ret;
549
550 /* test unaligned buffers, check with one byte offset */
551 ret = __test_hash(tfm, template, tcount, use_digest, 1);
552 if (ret)
553 return ret;
554
555 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
556 if (alignmask) {
557 /* Check if alignment mask for tfm is correctly set. */
558 ret = __test_hash(tfm, template, tcount, use_digest,
559 alignmask + 1);
560 if (ret)
561 return ret;
562 }
563
564 return 0;
565}
566
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300567static int __test_aead(struct crypto_aead *tfm, int enc,
568 struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300569 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800570{
571 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
572 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800573 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800574 char *q;
575 char *key;
576 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300577 struct scatterlist *sg;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300578 struct scatterlist *sgout;
579 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800580 struct tcrypt_result result;
Cristian Stoica424a5da2015-01-28 11:03:05 +0200581 unsigned int authsize, iv_len;
Herbert Xuda7f0332008-07-31 17:08:25 +0800582 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300583 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800584 void *assoc;
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700585 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800586 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300587 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800588 char *axbuf[XBUFSIZE];
589
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700590 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
591 if (!iv)
592 return ret;
Horia Geanta29b77e52014-07-23 11:59:38 +0300593 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
594 if (!key)
595 goto out_noxbuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800596 if (testmgr_alloc_buf(xbuf))
597 goto out_noxbuf;
598 if (testmgr_alloc_buf(axbuf))
599 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300600 if (diff_dst && testmgr_alloc_buf(xoutbuf))
601 goto out_nooutbuf;
602
603 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800604 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 4 : 2), GFP_KERNEL);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300605 if (!sg)
606 goto out_nosg;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800607 sgout = &sg[16];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300608
609 if (diff_dst)
610 d = "-ddst";
611 else
612 d = "";
613
Herbert Xuda7f0332008-07-31 17:08:25 +0800614 if (enc == ENCRYPT)
615 e = "encryption";
616 else
617 e = "decryption";
618
619 init_completion(&result.completion);
620
621 req = aead_request_alloc(tfm, GFP_KERNEL);
622 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300623 pr_err("alg: aead%s: Failed to allocate request for %s\n",
624 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800625 goto out;
626 }
627
628 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
629 tcrypt_complete, &result);
630
Jerome Marchandabfa7f42016-02-03 13:58:12 +0100631 iv_len = crypto_aead_ivsize(tfm);
632
Herbert Xuda7f0332008-07-31 17:08:25 +0800633 for (i = 0, j = 0; i < tcount; i++) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300634 if (template[i].np)
635 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800636
Cristian Stoica05b1d332014-07-28 13:11:23 +0300637 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800638
Cristian Stoica05b1d332014-07-28 13:11:23 +0300639 /* some templates have no input data but they will
640 * touch input
641 */
642 input = xbuf[0];
643 input += align_offset;
644 assoc = axbuf[0];
645
646 ret = -EINVAL;
647 if (WARN_ON(align_offset + template[i].ilen >
648 PAGE_SIZE || template[i].alen > PAGE_SIZE))
649 goto out;
650
651 memcpy(input, template[i].input, template[i].ilen);
652 memcpy(assoc, template[i].assoc, template[i].alen);
653 if (template[i].iv)
Cristian Stoica424a5da2015-01-28 11:03:05 +0200654 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300655 else
Cristian Stoica424a5da2015-01-28 11:03:05 +0200656 memset(iv, 0, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300657
658 crypto_aead_clear_flags(tfm, ~0);
659 if (template[i].wk)
660 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
661
662 if (template[i].klen > MAX_KEYLEN) {
663 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
664 d, j, algo, template[i].klen,
665 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +1000666 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300667 goto out;
668 }
669 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +1000670
Cristian Stoica05b1d332014-07-28 13:11:23 +0300671 ret = crypto_aead_setkey(tfm, key, template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +0800672 if (template[i].fail == !ret) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300673 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
674 d, j, algo, crypto_aead_get_flags(tfm));
675 goto out;
676 } else if (ret)
677 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800678
Cristian Stoica05b1d332014-07-28 13:11:23 +0300679 authsize = abs(template[i].rlen - template[i].ilen);
680 ret = crypto_aead_setauthsize(tfm, authsize);
681 if (ret) {
682 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
683 d, authsize, j, algo);
684 goto out;
685 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800686
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800687 k = !!template[i].alen;
688 sg_init_table(sg, k + 1);
689 sg_set_buf(&sg[0], assoc, template[i].alen);
690 sg_set_buf(&sg[k], input,
691 template[i].ilen + (enc ? authsize : 0));
692 output = input;
693
Cristian Stoica05b1d332014-07-28 13:11:23 +0300694 if (diff_dst) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800695 sg_init_table(sgout, k + 1);
696 sg_set_buf(&sgout[0], assoc, template[i].alen);
697
Cristian Stoica05b1d332014-07-28 13:11:23 +0300698 output = xoutbuf[0];
699 output += align_offset;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800700 sg_set_buf(&sgout[k], output,
701 template[i].rlen + (enc ? 0 : authsize));
Cristian Stoica05b1d332014-07-28 13:11:23 +0300702 }
703
Cristian Stoica05b1d332014-07-28 13:11:23 +0300704 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
705 template[i].ilen, iv);
706
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800707 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300708
709 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
710
711 switch (ret) {
712 case 0:
713 if (template[i].novrfy) {
714 /* verification was supposed to fail */
715 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
716 d, e, j, algo);
717 /* so really, we got a bad message */
718 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +0300719 goto out;
720 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300721 break;
722 case -EINPROGRESS:
723 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100724 wait_for_completion(&result.completion);
725 reinit_completion(&result.completion);
726 ret = result.err;
727 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +0800728 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300729 case -EBADMSG:
730 if (template[i].novrfy)
731 /* verification failure was expected */
732 continue;
733 /* fall through */
734 default:
735 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
736 d, e, j, algo, -ret);
737 goto out;
738 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800739
Cristian Stoica05b1d332014-07-28 13:11:23 +0300740 q = output;
741 if (memcmp(q, template[i].result, template[i].rlen)) {
742 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
743 d, j, e, algo);
744 hexdump(q, template[i].rlen);
745 ret = -EINVAL;
746 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800747 }
748 }
749
750 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300751 /* alignment tests are only done with continuous buffers */
752 if (align_offset != 0)
753 break;
754
Cristian Stoica05b1d332014-07-28 13:11:23 +0300755 if (!template[i].np)
756 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800757
Cristian Stoica05b1d332014-07-28 13:11:23 +0300758 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800759
Cristian Stoica05b1d332014-07-28 13:11:23 +0300760 if (template[i].iv)
Jerome Marchandabfa7f42016-02-03 13:58:12 +0100761 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300762 else
763 memset(iv, 0, MAX_IVLEN);
764
765 crypto_aead_clear_flags(tfm, ~0);
766 if (template[i].wk)
767 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
768 if (template[i].klen > MAX_KEYLEN) {
769 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
770 d, j, algo, template[i].klen, MAX_KEYLEN);
771 ret = -EINVAL;
772 goto out;
773 }
774 memcpy(key, template[i].key, template[i].klen);
775
776 ret = crypto_aead_setkey(tfm, key, template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +0800777 if (template[i].fail == !ret) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300778 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
779 d, j, algo, crypto_aead_get_flags(tfm));
780 goto out;
781 } else if (ret)
782 continue;
783
784 authsize = abs(template[i].rlen - template[i].ilen);
785
786 ret = -EINVAL;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800787 sg_init_table(sg, template[i].anp + template[i].np);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300788 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800789 sg_init_table(sgout, template[i].anp + template[i].np);
790
791 ret = -EINVAL;
792 for (k = 0, temp = 0; k < template[i].anp; k++) {
793 if (WARN_ON(offset_in_page(IDX[k]) +
794 template[i].atap[k] > PAGE_SIZE))
795 goto out;
796 sg_set_buf(&sg[k],
797 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
798 offset_in_page(IDX[k]),
799 template[i].assoc + temp,
800 template[i].atap[k]),
801 template[i].atap[k]);
802 if (diff_dst)
803 sg_set_buf(&sgout[k],
804 axbuf[IDX[k] >> PAGE_SHIFT] +
805 offset_in_page(IDX[k]),
806 template[i].atap[k]);
807 temp += template[i].atap[k];
808 }
809
Cristian Stoica05b1d332014-07-28 13:11:23 +0300810 for (k = 0, temp = 0; k < template[i].np; k++) {
811 if (WARN_ON(offset_in_page(IDX[k]) +
812 template[i].tap[k] > PAGE_SIZE))
813 goto out;
814
815 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
816 memcpy(q, template[i].input + temp, template[i].tap[k]);
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800817 sg_set_buf(&sg[template[i].anp + k],
818 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300819
820 if (diff_dst) {
821 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
822 offset_in_page(IDX[k]);
823
824 memset(q, 0, template[i].tap[k]);
825
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800826 sg_set_buf(&sgout[template[i].anp + k],
827 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300828 }
829
830 n = template[i].tap[k];
831 if (k == template[i].np - 1 && enc)
832 n += authsize;
833 if (offset_in_page(q) + n < PAGE_SIZE)
834 q[n] = 0;
835
836 temp += template[i].tap[k];
837 }
838
839 ret = crypto_aead_setauthsize(tfm, authsize);
840 if (ret) {
841 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
842 d, authsize, j, algo);
843 goto out;
844 }
845
846 if (enc) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800847 if (WARN_ON(sg[template[i].anp + k - 1].offset +
848 sg[template[i].anp + k - 1].length +
849 authsize > PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300850 ret = -EINVAL;
851 goto out;
852 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800853
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300854 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800855 sgout[template[i].anp + k - 1].length +=
856 authsize;
857 sg[template[i].anp + k - 1].length += authsize;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300858 }
859
860 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
861 template[i].ilen,
862 iv);
863
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800864 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300865
866 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
867
868 switch (ret) {
869 case 0:
870 if (template[i].novrfy) {
871 /* verification was supposed to fail */
872 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
873 d, e, j, algo);
874 /* so really, we got a bad message */
875 ret = -EBADMSG;
876 goto out;
877 }
878 break;
879 case -EINPROGRESS:
880 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100881 wait_for_completion(&result.completion);
882 reinit_completion(&result.completion);
883 ret = result.err;
884 if (!ret)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300885 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300886 case -EBADMSG:
887 if (template[i].novrfy)
888 /* verification failure was expected */
889 continue;
890 /* fall through */
891 default:
892 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
893 d, e, j, algo, -ret);
894 goto out;
895 }
896
897 ret = -EINVAL;
898 for (k = 0, temp = 0; k < template[i].np; k++) {
899 if (diff_dst)
900 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
901 offset_in_page(IDX[k]);
902 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800903 q = xbuf[IDX[k] >> PAGE_SHIFT] +
904 offset_in_page(IDX[k]);
905
Cristian Stoica05b1d332014-07-28 13:11:23 +0300906 n = template[i].tap[k];
907 if (k == template[i].np - 1)
908 n += enc ? authsize : -authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800909
Cristian Stoica05b1d332014-07-28 13:11:23 +0300910 if (memcmp(q, template[i].result + temp, n)) {
911 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
912 d, j, e, k, algo);
913 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800914 goto out;
915 }
916
Cristian Stoica05b1d332014-07-28 13:11:23 +0300917 q += n;
918 if (k == template[i].np - 1 && !enc) {
919 if (!diff_dst &&
920 memcmp(q, template[i].input +
921 temp + n, authsize))
922 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200923 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300924 n = 0;
925 } else {
926 for (n = 0; offset_in_page(q + n) && q[n]; n++)
927 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800928 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300929 if (n) {
930 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
931 d, j, e, k, algo, n);
932 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800933 goto out;
934 }
935
Cristian Stoica05b1d332014-07-28 13:11:23 +0300936 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800937 }
938 }
939
940 ret = 0;
941
942out:
943 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300944 kfree(sg);
945out_nosg:
946 if (diff_dst)
947 testmgr_free_buf(xoutbuf);
948out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800949 testmgr_free_buf(axbuf);
950out_noaxbuf:
951 testmgr_free_buf(xbuf);
952out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300953 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700954 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800955 return ret;
956}
957
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300958static int test_aead(struct crypto_aead *tfm, int enc,
959 struct aead_testvec *template, unsigned int tcount)
960{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300961 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300962 int ret;
963
964 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300965 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300966 if (ret)
967 return ret;
968
969 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300970 ret = __test_aead(tfm, enc, template, tcount, true, 0);
971 if (ret)
972 return ret;
973
974 /* test unaligned buffers, check with one byte offset */
975 ret = __test_aead(tfm, enc, template, tcount, true, 1);
976 if (ret)
977 return ret;
978
979 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
980 if (alignmask) {
981 /* Check if alignment mask for tfm is correctly set. */
982 ret = __test_aead(tfm, enc, template, tcount, true,
983 alignmask + 1);
984 if (ret)
985 return ret;
986 }
987
988 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300989}
990
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000991static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800992 struct cipher_testvec *template, unsigned int tcount)
993{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000994 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
995 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000996 char *q;
997 const char *e;
998 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800999 char *xbuf[XBUFSIZE];
1000 int ret = -ENOMEM;
1001
1002 if (testmgr_alloc_buf(xbuf))
1003 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001004
1005 if (enc == ENCRYPT)
1006 e = "encryption";
1007 else
1008 e = "decryption";
1009
1010 j = 0;
1011 for (i = 0; i < tcount; i++) {
1012 if (template[i].np)
1013 continue;
1014
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001015 if (fips_enabled && template[i].fips_skip)
1016 continue;
1017
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001018 j++;
1019
Herbert Xufd57f222009-05-29 16:05:42 +10001020 ret = -EINVAL;
1021 if (WARN_ON(template[i].ilen > PAGE_SIZE))
1022 goto out;
1023
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001024 data = xbuf[0];
1025 memcpy(data, template[i].input, template[i].ilen);
1026
1027 crypto_cipher_clear_flags(tfm, ~0);
1028 if (template[i].wk)
1029 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1030
1031 ret = crypto_cipher_setkey(tfm, template[i].key,
1032 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001033 if (template[i].fail == !ret) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001034 printk(KERN_ERR "alg: cipher: setkey failed "
1035 "on test %d for %s: flags=%x\n", j,
1036 algo, crypto_cipher_get_flags(tfm));
1037 goto out;
1038 } else if (ret)
1039 continue;
1040
1041 for (k = 0; k < template[i].ilen;
1042 k += crypto_cipher_blocksize(tfm)) {
1043 if (enc)
1044 crypto_cipher_encrypt_one(tfm, data + k,
1045 data + k);
1046 else
1047 crypto_cipher_decrypt_one(tfm, data + k,
1048 data + k);
1049 }
1050
1051 q = data;
1052 if (memcmp(q, template[i].result, template[i].rlen)) {
1053 printk(KERN_ERR "alg: cipher: Test %d failed "
1054 "on %s for %s\n", j, e, algo);
1055 hexdump(q, template[i].rlen);
1056 ret = -EINVAL;
1057 goto out;
1058 }
1059 }
1060
1061 ret = 0;
1062
1063out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001064 testmgr_free_buf(xbuf);
1065out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001066 return ret;
1067}
1068
Herbert Xu12773d92015-08-20 15:21:46 +08001069static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001070 struct cipher_testvec *template, unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001071 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001072{
Herbert Xuda7f0332008-07-31 17:08:25 +08001073 const char *algo =
Herbert Xu12773d92015-08-20 15:21:46 +08001074 crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +08001075 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +08001076 char *q;
Herbert Xu12773d92015-08-20 15:21:46 +08001077 struct skcipher_request *req;
Herbert Xuda7f0332008-07-31 17:08:25 +08001078 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001079 struct scatterlist sgout[8];
1080 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +08001081 struct tcrypt_result result;
1082 void *data;
1083 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001084 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001085 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001086 int ret = -ENOMEM;
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001087 unsigned int ivsize = crypto_skcipher_ivsize(tfm);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001088
1089 if (testmgr_alloc_buf(xbuf))
1090 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +08001091
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001092 if (diff_dst && testmgr_alloc_buf(xoutbuf))
1093 goto out_nooutbuf;
1094
1095 if (diff_dst)
1096 d = "-ddst";
1097 else
1098 d = "";
1099
Herbert Xuda7f0332008-07-31 17:08:25 +08001100 if (enc == ENCRYPT)
1101 e = "encryption";
1102 else
1103 e = "decryption";
1104
1105 init_completion(&result.completion);
1106
Herbert Xu12773d92015-08-20 15:21:46 +08001107 req = skcipher_request_alloc(tfm, GFP_KERNEL);
Herbert Xuda7f0332008-07-31 17:08:25 +08001108 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001109 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
1110 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +08001111 goto out;
1112 }
1113
Herbert Xu12773d92015-08-20 15:21:46 +08001114 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1115 tcrypt_complete, &result);
Herbert Xuda7f0332008-07-31 17:08:25 +08001116
1117 j = 0;
1118 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001119 if (template[i].np && !template[i].also_non_np)
1120 continue;
1121
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001122 if (fips_enabled && template[i].fips_skip)
1123 continue;
1124
Herbert Xuda7f0332008-07-31 17:08:25 +08001125 if (template[i].iv)
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001126 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001127 else
1128 memset(iv, 0, MAX_IVLEN);
1129
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001130 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001131 ret = -EINVAL;
1132 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
1133 goto out;
1134
1135 data = xbuf[0];
1136 data += align_offset;
1137 memcpy(data, template[i].input, template[i].ilen);
1138
Herbert Xu12773d92015-08-20 15:21:46 +08001139 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001140 if (template[i].wk)
Herbert Xu12773d92015-08-20 15:21:46 +08001141 crypto_skcipher_set_flags(tfm,
1142 CRYPTO_TFM_REQ_WEAK_KEY);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001143
Herbert Xu12773d92015-08-20 15:21:46 +08001144 ret = crypto_skcipher_setkey(tfm, template[i].key,
1145 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001146 if (template[i].fail == !ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001147 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001148 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001149 goto out;
1150 } else if (ret)
1151 continue;
1152
1153 sg_init_one(&sg[0], data, template[i].ilen);
1154 if (diff_dst) {
1155 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001156 data += align_offset;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001157 sg_init_one(&sgout[0], data, template[i].ilen);
1158 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001159
Herbert Xu12773d92015-08-20 15:21:46 +08001160 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1161 template[i].ilen, iv);
1162 ret = enc ? crypto_skcipher_encrypt(req) :
1163 crypto_skcipher_decrypt(req);
Herbert Xuda7f0332008-07-31 17:08:25 +08001164
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001165 switch (ret) {
1166 case 0:
1167 break;
1168 case -EINPROGRESS:
1169 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001170 wait_for_completion(&result.completion);
1171 reinit_completion(&result.completion);
1172 ret = result.err;
1173 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +08001174 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001175 /* fall through */
1176 default:
1177 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1178 d, e, j, algo, -ret);
1179 goto out;
1180 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001181
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001182 q = data;
1183 if (memcmp(q, template[i].result, template[i].rlen)) {
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001184 pr_err("alg: skcipher%s: Test %d failed (invalid result) on %s for %s\n",
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001185 d, j, e, algo);
1186 hexdump(q, template[i].rlen);
1187 ret = -EINVAL;
1188 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001189 }
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001190
1191 if (template[i].iv_out &&
1192 memcmp(iv, template[i].iv_out,
1193 crypto_skcipher_ivsize(tfm))) {
1194 pr_err("alg: skcipher%s: Test %d failed (invalid output IV) on %s for %s\n",
1195 d, j, e, algo);
1196 hexdump(iv, crypto_skcipher_ivsize(tfm));
1197 ret = -EINVAL;
1198 goto out;
1199 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001200 }
1201
1202 j = 0;
1203 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001204 /* alignment tests are only done with continuous buffers */
1205 if (align_offset != 0)
1206 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001207
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001208 if (!template[i].np)
1209 continue;
1210
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001211 if (fips_enabled && template[i].fips_skip)
1212 continue;
1213
Herbert Xuda7f0332008-07-31 17:08:25 +08001214 if (template[i].iv)
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001215 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001216 else
1217 memset(iv, 0, MAX_IVLEN);
1218
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001219 j++;
Herbert Xu12773d92015-08-20 15:21:46 +08001220 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001221 if (template[i].wk)
Herbert Xu12773d92015-08-20 15:21:46 +08001222 crypto_skcipher_set_flags(tfm,
1223 CRYPTO_TFM_REQ_WEAK_KEY);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001224
Herbert Xu12773d92015-08-20 15:21:46 +08001225 ret = crypto_skcipher_setkey(tfm, template[i].key,
1226 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001227 if (template[i].fail == !ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001228 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001229 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001230 goto out;
1231 } else if (ret)
1232 continue;
1233
1234 temp = 0;
1235 ret = -EINVAL;
1236 sg_init_table(sg, template[i].np);
1237 if (diff_dst)
1238 sg_init_table(sgout, template[i].np);
1239 for (k = 0; k < template[i].np; k++) {
1240 if (WARN_ON(offset_in_page(IDX[k]) +
1241 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001242 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001243
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001244 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1245
1246 memcpy(q, template[i].input + temp, template[i].tap[k]);
1247
1248 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1249 q[template[i].tap[k]] = 0;
1250
1251 sg_set_buf(&sg[k], q, template[i].tap[k]);
1252 if (diff_dst) {
1253 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1254 offset_in_page(IDX[k]);
1255
1256 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1257
1258 memset(q, 0, template[i].tap[k]);
1259 if (offset_in_page(q) +
1260 template[i].tap[k] < PAGE_SIZE)
1261 q[template[i].tap[k]] = 0;
1262 }
1263
1264 temp += template[i].tap[k];
1265 }
1266
Herbert Xu12773d92015-08-20 15:21:46 +08001267 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1268 template[i].ilen, iv);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001269
Herbert Xu12773d92015-08-20 15:21:46 +08001270 ret = enc ? crypto_skcipher_encrypt(req) :
1271 crypto_skcipher_decrypt(req);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001272
1273 switch (ret) {
1274 case 0:
1275 break;
1276 case -EINPROGRESS:
1277 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001278 wait_for_completion(&result.completion);
1279 reinit_completion(&result.completion);
1280 ret = result.err;
1281 if (!ret)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001282 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001283 /* fall through */
1284 default:
1285 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1286 d, e, j, algo, -ret);
1287 goto out;
1288 }
1289
1290 temp = 0;
1291 ret = -EINVAL;
1292 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001293 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001294 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1295 offset_in_page(IDX[k]);
1296 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001297 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1298 offset_in_page(IDX[k]);
1299
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001300 if (memcmp(q, template[i].result + temp,
1301 template[i].tap[k])) {
1302 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1303 d, j, e, k, algo);
1304 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001305 goto out;
1306 }
1307
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001308 q += template[i].tap[k];
1309 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1310 ;
1311 if (n) {
1312 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1313 d, j, e, k, algo, n);
1314 hexdump(q, n);
1315 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001316 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001317 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001318 }
1319 }
1320
1321 ret = 0;
1322
1323out:
Herbert Xu12773d92015-08-20 15:21:46 +08001324 skcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001325 if (diff_dst)
1326 testmgr_free_buf(xoutbuf);
1327out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001328 testmgr_free_buf(xbuf);
1329out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001330 return ret;
1331}
1332
Herbert Xu12773d92015-08-20 15:21:46 +08001333static int test_skcipher(struct crypto_skcipher *tfm, int enc,
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001334 struct cipher_testvec *template, unsigned int tcount)
1335{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001336 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001337 int ret;
1338
1339 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001340 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001341 if (ret)
1342 return ret;
1343
1344 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001345 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1346 if (ret)
1347 return ret;
1348
1349 /* test unaligned buffers, check with one byte offset */
1350 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1351 if (ret)
1352 return ret;
1353
1354 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1355 if (alignmask) {
1356 /* Check if alignment mask for tfm is correctly set. */
1357 ret = __test_skcipher(tfm, enc, template, tcount, true,
1358 alignmask + 1);
1359 if (ret)
1360 return ret;
1361 }
1362
1363 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001364}
1365
Herbert Xuda7f0332008-07-31 17:08:25 +08001366static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1367 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1368{
1369 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1370 unsigned int i;
1371 char result[COMP_BUF_SIZE];
1372 int ret;
1373
1374 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001375 int ilen;
1376 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001377
1378 memset(result, 0, sizeof (result));
1379
1380 ilen = ctemplate[i].inlen;
1381 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1382 ilen, result, &dlen);
1383 if (ret) {
1384 printk(KERN_ERR "alg: comp: compression failed "
1385 "on test %d for %s: ret=%d\n", i + 1, algo,
1386 -ret);
1387 goto out;
1388 }
1389
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001390 if (dlen != ctemplate[i].outlen) {
1391 printk(KERN_ERR "alg: comp: Compression test %d "
1392 "failed for %s: output len = %d\n", i + 1, algo,
1393 dlen);
1394 ret = -EINVAL;
1395 goto out;
1396 }
1397
Herbert Xuda7f0332008-07-31 17:08:25 +08001398 if (memcmp(result, ctemplate[i].output, dlen)) {
1399 printk(KERN_ERR "alg: comp: Compression test %d "
1400 "failed for %s\n", i + 1, algo);
1401 hexdump(result, dlen);
1402 ret = -EINVAL;
1403 goto out;
1404 }
1405 }
1406
1407 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001408 int ilen;
1409 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001410
1411 memset(result, 0, sizeof (result));
1412
1413 ilen = dtemplate[i].inlen;
1414 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1415 ilen, result, &dlen);
1416 if (ret) {
1417 printk(KERN_ERR "alg: comp: decompression failed "
1418 "on test %d for %s: ret=%d\n", i + 1, algo,
1419 -ret);
1420 goto out;
1421 }
1422
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001423 if (dlen != dtemplate[i].outlen) {
1424 printk(KERN_ERR "alg: comp: Decompression test %d "
1425 "failed for %s: output len = %d\n", i + 1, algo,
1426 dlen);
1427 ret = -EINVAL;
1428 goto out;
1429 }
1430
Herbert Xuda7f0332008-07-31 17:08:25 +08001431 if (memcmp(result, dtemplate[i].output, dlen)) {
1432 printk(KERN_ERR "alg: comp: Decompression test %d "
1433 "failed for %s\n", i + 1, algo);
1434 hexdump(result, dlen);
1435 ret = -EINVAL;
1436 goto out;
1437 }
1438 }
1439
1440 ret = 0;
1441
1442out:
1443 return ret;
1444}
1445
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001446static int test_acomp(struct crypto_acomp *tfm, struct comp_testvec *ctemplate,
1447 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1448{
1449 const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
1450 unsigned int i;
1451 char output[COMP_BUF_SIZE];
1452 int ret;
1453 struct scatterlist src, dst;
1454 struct acomp_req *req;
1455 struct tcrypt_result result;
1456
1457 for (i = 0; i < ctcount; i++) {
1458 unsigned int dlen = COMP_BUF_SIZE;
1459 int ilen = ctemplate[i].inlen;
1460
1461 memset(output, 0, sizeof(output));
1462 init_completion(&result.completion);
1463 sg_init_one(&src, ctemplate[i].input, ilen);
1464 sg_init_one(&dst, output, dlen);
1465
1466 req = acomp_request_alloc(tfm);
1467 if (!req) {
1468 pr_err("alg: acomp: request alloc failed for %s\n",
1469 algo);
1470 ret = -ENOMEM;
1471 goto out;
1472 }
1473
1474 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1475 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1476 tcrypt_complete, &result);
1477
1478 ret = wait_async_op(&result, crypto_acomp_compress(req));
1479 if (ret) {
1480 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
1481 i + 1, algo, -ret);
1482 acomp_request_free(req);
1483 goto out;
1484 }
1485
1486 if (req->dlen != ctemplate[i].outlen) {
1487 pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
1488 i + 1, algo, req->dlen);
1489 ret = -EINVAL;
1490 acomp_request_free(req);
1491 goto out;
1492 }
1493
1494 if (memcmp(output, ctemplate[i].output, req->dlen)) {
1495 pr_err("alg: acomp: Compression test %d failed for %s\n",
1496 i + 1, algo);
1497 hexdump(output, req->dlen);
1498 ret = -EINVAL;
1499 acomp_request_free(req);
1500 goto out;
1501 }
1502
1503 acomp_request_free(req);
1504 }
1505
1506 for (i = 0; i < dtcount; i++) {
1507 unsigned int dlen = COMP_BUF_SIZE;
1508 int ilen = dtemplate[i].inlen;
1509
1510 memset(output, 0, sizeof(output));
1511 init_completion(&result.completion);
1512 sg_init_one(&src, dtemplate[i].input, ilen);
1513 sg_init_one(&dst, output, dlen);
1514
1515 req = acomp_request_alloc(tfm);
1516 if (!req) {
1517 pr_err("alg: acomp: request alloc failed for %s\n",
1518 algo);
1519 ret = -ENOMEM;
1520 goto out;
1521 }
1522
1523 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1524 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1525 tcrypt_complete, &result);
1526
1527 ret = wait_async_op(&result, crypto_acomp_decompress(req));
1528 if (ret) {
1529 pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
1530 i + 1, algo, -ret);
1531 acomp_request_free(req);
1532 goto out;
1533 }
1534
1535 if (req->dlen != dtemplate[i].outlen) {
1536 pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
1537 i + 1, algo, req->dlen);
1538 ret = -EINVAL;
1539 acomp_request_free(req);
1540 goto out;
1541 }
1542
1543 if (memcmp(output, dtemplate[i].output, req->dlen)) {
1544 pr_err("alg: acomp: Decompression test %d failed for %s\n",
1545 i + 1, algo);
1546 hexdump(output, req->dlen);
1547 ret = -EINVAL;
1548 acomp_request_free(req);
1549 goto out;
1550 }
1551
1552 acomp_request_free(req);
1553 }
1554
1555 ret = 0;
1556
1557out:
1558 return ret;
1559}
1560
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001561static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1562 unsigned int tcount)
1563{
1564 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001565 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001566 u8 *seed;
1567 char result[32];
1568
1569 seedsize = crypto_rng_seedsize(tfm);
1570
1571 seed = kmalloc(seedsize, GFP_KERNEL);
1572 if (!seed) {
1573 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1574 "for %s\n", algo);
1575 return -ENOMEM;
1576 }
1577
1578 for (i = 0; i < tcount; i++) {
1579 memset(result, 0, 32);
1580
1581 memcpy(seed, template[i].v, template[i].vlen);
1582 memcpy(seed + template[i].vlen, template[i].key,
1583 template[i].klen);
1584 memcpy(seed + template[i].vlen + template[i].klen,
1585 template[i].dt, template[i].dtlen);
1586
1587 err = crypto_rng_reset(tfm, seed, seedsize);
1588 if (err) {
1589 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1590 "for %s\n", algo);
1591 goto out;
1592 }
1593
1594 for (j = 0; j < template[i].loops; j++) {
1595 err = crypto_rng_get_bytes(tfm, result,
1596 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01001597 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001598 printk(KERN_ERR "alg: cprng: Failed to obtain "
1599 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01001600 "%s (requested %d)\n", algo,
1601 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001602 goto out;
1603 }
1604 }
1605
1606 err = memcmp(result, template[i].result,
1607 template[i].rlen);
1608 if (err) {
1609 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1610 i, algo);
1611 hexdump(result, template[i].rlen);
1612 err = -EINVAL;
1613 goto out;
1614 }
1615 }
1616
1617out:
1618 kfree(seed);
1619 return err;
1620}
1621
Herbert Xuda7f0332008-07-31 17:08:25 +08001622static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1623 u32 type, u32 mask)
1624{
1625 struct crypto_aead *tfm;
1626 int err = 0;
1627
Stephan Mueller425a8822015-03-30 21:56:31 +02001628 tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001629 if (IS_ERR(tfm)) {
1630 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1631 "%ld\n", driver, PTR_ERR(tfm));
1632 return PTR_ERR(tfm);
1633 }
1634
1635 if (desc->suite.aead.enc.vecs) {
1636 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1637 desc->suite.aead.enc.count);
1638 if (err)
1639 goto out;
1640 }
1641
1642 if (!err && desc->suite.aead.dec.vecs)
1643 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1644 desc->suite.aead.dec.count);
1645
1646out:
1647 crypto_free_aead(tfm);
1648 return err;
1649}
1650
1651static int alg_test_cipher(const struct alg_test_desc *desc,
1652 const char *driver, u32 type, u32 mask)
1653{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001654 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001655 int err = 0;
1656
Stephan Mueller425a8822015-03-30 21:56:31 +02001657 tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001658 if (IS_ERR(tfm)) {
1659 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1660 "%s: %ld\n", driver, PTR_ERR(tfm));
1661 return PTR_ERR(tfm);
1662 }
1663
1664 if (desc->suite.cipher.enc.vecs) {
1665 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1666 desc->suite.cipher.enc.count);
1667 if (err)
1668 goto out;
1669 }
1670
1671 if (desc->suite.cipher.dec.vecs)
1672 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1673 desc->suite.cipher.dec.count);
1674
1675out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001676 crypto_free_cipher(tfm);
1677 return err;
1678}
1679
1680static int alg_test_skcipher(const struct alg_test_desc *desc,
1681 const char *driver, u32 type, u32 mask)
1682{
Herbert Xu12773d92015-08-20 15:21:46 +08001683 struct crypto_skcipher *tfm;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001684 int err = 0;
1685
Herbert Xu12773d92015-08-20 15:21:46 +08001686 tfm = crypto_alloc_skcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001687 if (IS_ERR(tfm)) {
1688 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1689 "%s: %ld\n", driver, PTR_ERR(tfm));
1690 return PTR_ERR(tfm);
1691 }
1692
1693 if (desc->suite.cipher.enc.vecs) {
1694 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1695 desc->suite.cipher.enc.count);
1696 if (err)
1697 goto out;
1698 }
1699
1700 if (desc->suite.cipher.dec.vecs)
1701 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1702 desc->suite.cipher.dec.count);
1703
1704out:
Herbert Xu12773d92015-08-20 15:21:46 +08001705 crypto_free_skcipher(tfm);
Herbert Xuda7f0332008-07-31 17:08:25 +08001706 return err;
1707}
1708
1709static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1710 u32 type, u32 mask)
1711{
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001712 struct crypto_comp *comp;
1713 struct crypto_acomp *acomp;
Herbert Xuda7f0332008-07-31 17:08:25 +08001714 int err;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001715 u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
Herbert Xuda7f0332008-07-31 17:08:25 +08001716
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001717 if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
1718 acomp = crypto_alloc_acomp(driver, type, mask);
1719 if (IS_ERR(acomp)) {
1720 pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
1721 driver, PTR_ERR(acomp));
1722 return PTR_ERR(acomp);
1723 }
1724 err = test_acomp(acomp, desc->suite.comp.comp.vecs,
1725 desc->suite.comp.decomp.vecs,
1726 desc->suite.comp.comp.count,
1727 desc->suite.comp.decomp.count);
1728 crypto_free_acomp(acomp);
1729 } else {
1730 comp = crypto_alloc_comp(driver, type, mask);
1731 if (IS_ERR(comp)) {
1732 pr_err("alg: comp: Failed to load transform for %s: %ld\n",
1733 driver, PTR_ERR(comp));
1734 return PTR_ERR(comp);
1735 }
1736
1737 err = test_comp(comp, desc->suite.comp.comp.vecs,
1738 desc->suite.comp.decomp.vecs,
1739 desc->suite.comp.comp.count,
1740 desc->suite.comp.decomp.count);
1741
1742 crypto_free_comp(comp);
Herbert Xuda7f0332008-07-31 17:08:25 +08001743 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001744 return err;
1745}
1746
1747static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1748 u32 type, u32 mask)
1749{
1750 struct crypto_ahash *tfm;
1751 int err;
1752
Stephan Mueller425a8822015-03-30 21:56:31 +02001753 tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001754 if (IS_ERR(tfm)) {
1755 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1756 "%ld\n", driver, PTR_ERR(tfm));
1757 return PTR_ERR(tfm);
1758 }
1759
David S. Millera8f1a052010-05-19 14:12:03 +10001760 err = test_hash(tfm, desc->suite.hash.vecs,
1761 desc->suite.hash.count, true);
1762 if (!err)
1763 err = test_hash(tfm, desc->suite.hash.vecs,
1764 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001765
1766 crypto_free_ahash(tfm);
1767 return err;
1768}
1769
Herbert Xu8e3ee852008-11-07 14:58:52 +08001770static int alg_test_crc32c(const struct alg_test_desc *desc,
1771 const char *driver, u32 type, u32 mask)
1772{
1773 struct crypto_shash *tfm;
1774 u32 val;
1775 int err;
1776
1777 err = alg_test_hash(desc, driver, type, mask);
1778 if (err)
1779 goto out;
1780
Stephan Mueller425a8822015-03-30 21:56:31 +02001781 tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001782 if (IS_ERR(tfm)) {
1783 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1784 "%ld\n", driver, PTR_ERR(tfm));
1785 err = PTR_ERR(tfm);
1786 goto out;
1787 }
1788
1789 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001790 SHASH_DESC_ON_STACK(shash, tfm);
1791 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001792
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001793 shash->tfm = tfm;
1794 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001795
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001796 *ctx = le32_to_cpu(420553207);
1797 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001798 if (err) {
1799 printk(KERN_ERR "alg: crc32c: Operation failed for "
1800 "%s: %d\n", driver, err);
1801 break;
1802 }
1803
1804 if (val != ~420553207) {
1805 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1806 "%d\n", driver, val);
1807 err = -EINVAL;
1808 }
1809 } while (0);
1810
1811 crypto_free_shash(tfm);
1812
1813out:
1814 return err;
1815}
1816
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001817static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1818 u32 type, u32 mask)
1819{
1820 struct crypto_rng *rng;
1821 int err;
1822
Stephan Mueller425a8822015-03-30 21:56:31 +02001823 rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001824 if (IS_ERR(rng)) {
1825 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1826 "%ld\n", driver, PTR_ERR(rng));
1827 return PTR_ERR(rng);
1828 }
1829
1830 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1831
1832 crypto_free_rng(rng);
1833
1834 return err;
1835}
1836
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001837
1838static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1839 const char *driver, u32 type, u32 mask)
1840{
1841 int ret = -EAGAIN;
1842 struct crypto_rng *drng;
1843 struct drbg_test_data test_data;
1844 struct drbg_string addtl, pers, testentropy;
1845 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1846
1847 if (!buf)
1848 return -ENOMEM;
1849
Stephan Mueller425a8822015-03-30 21:56:31 +02001850 drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001851 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001852 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001853 "%s\n", driver);
1854 kzfree(buf);
1855 return -ENOMEM;
1856 }
1857
1858 test_data.testentropy = &testentropy;
1859 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1860 drbg_string_fill(&pers, test->pers, test->perslen);
1861 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1862 if (ret) {
1863 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1864 goto outbuf;
1865 }
1866
1867 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1868 if (pr) {
1869 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1870 ret = crypto_drbg_get_bytes_addtl_test(drng,
1871 buf, test->expectedlen, &addtl, &test_data);
1872 } else {
1873 ret = crypto_drbg_get_bytes_addtl(drng,
1874 buf, test->expectedlen, &addtl);
1875 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001876 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001877 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001878 "driver %s\n", driver);
1879 goto outbuf;
1880 }
1881
1882 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1883 if (pr) {
1884 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1885 ret = crypto_drbg_get_bytes_addtl_test(drng,
1886 buf, test->expectedlen, &addtl, &test_data);
1887 } else {
1888 ret = crypto_drbg_get_bytes_addtl(drng,
1889 buf, test->expectedlen, &addtl);
1890 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001891 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001892 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001893 "driver %s\n", driver);
1894 goto outbuf;
1895 }
1896
1897 ret = memcmp(test->expected, buf, test->expectedlen);
1898
1899outbuf:
1900 crypto_free_rng(drng);
1901 kzfree(buf);
1902 return ret;
1903}
1904
1905
1906static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1907 u32 type, u32 mask)
1908{
1909 int err = 0;
1910 int pr = 0;
1911 int i = 0;
1912 struct drbg_testvec *template = desc->suite.drbg.vecs;
1913 unsigned int tcount = desc->suite.drbg.count;
1914
1915 if (0 == memcmp(driver, "drbg_pr_", 8))
1916 pr = 1;
1917
1918 for (i = 0; i < tcount; i++) {
1919 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1920 if (err) {
1921 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1922 i, driver);
1923 err = -EINVAL;
1924 break;
1925 }
1926 }
1927 return err;
1928
1929}
1930
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01001931static int do_test_kpp(struct crypto_kpp *tfm, struct kpp_testvec *vec,
1932 const char *alg)
1933{
1934 struct kpp_request *req;
1935 void *input_buf = NULL;
1936 void *output_buf = NULL;
1937 struct tcrypt_result result;
1938 unsigned int out_len_max;
1939 int err = -ENOMEM;
1940 struct scatterlist src, dst;
1941
1942 req = kpp_request_alloc(tfm, GFP_KERNEL);
1943 if (!req)
1944 return err;
1945
1946 init_completion(&result.completion);
1947
1948 err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
1949 if (err < 0)
1950 goto free_req;
1951
1952 out_len_max = crypto_kpp_maxsize(tfm);
1953 output_buf = kzalloc(out_len_max, GFP_KERNEL);
1954 if (!output_buf) {
1955 err = -ENOMEM;
1956 goto free_req;
1957 }
1958
1959 /* Use appropriate parameter as base */
1960 kpp_request_set_input(req, NULL, 0);
1961 sg_init_one(&dst, output_buf, out_len_max);
1962 kpp_request_set_output(req, &dst, out_len_max);
1963 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1964 tcrypt_complete, &result);
1965
1966 /* Compute public key */
1967 err = wait_async_op(&result, crypto_kpp_generate_public_key(req));
1968 if (err) {
1969 pr_err("alg: %s: generate public key test failed. err %d\n",
1970 alg, err);
1971 goto free_output;
1972 }
1973 /* Verify calculated public key */
1974 if (memcmp(vec->expected_a_public, sg_virt(req->dst),
1975 vec->expected_a_public_size)) {
1976 pr_err("alg: %s: generate public key test failed. Invalid output\n",
1977 alg);
1978 err = -EINVAL;
1979 goto free_output;
1980 }
1981
1982 /* Calculate shared secret key by using counter part (b) public key. */
1983 input_buf = kzalloc(vec->b_public_size, GFP_KERNEL);
1984 if (!input_buf) {
1985 err = -ENOMEM;
1986 goto free_output;
1987 }
1988
1989 memcpy(input_buf, vec->b_public, vec->b_public_size);
1990 sg_init_one(&src, input_buf, vec->b_public_size);
1991 sg_init_one(&dst, output_buf, out_len_max);
1992 kpp_request_set_input(req, &src, vec->b_public_size);
1993 kpp_request_set_output(req, &dst, out_len_max);
1994 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1995 tcrypt_complete, &result);
1996 err = wait_async_op(&result, crypto_kpp_compute_shared_secret(req));
1997 if (err) {
1998 pr_err("alg: %s: compute shard secret test failed. err %d\n",
1999 alg, err);
2000 goto free_all;
2001 }
2002 /*
2003 * verify shared secret from which the user will derive
2004 * secret key by executing whatever hash it has chosen
2005 */
2006 if (memcmp(vec->expected_ss, sg_virt(req->dst),
2007 vec->expected_ss_size)) {
2008 pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
2009 alg);
2010 err = -EINVAL;
2011 }
2012
2013free_all:
2014 kfree(input_buf);
2015free_output:
2016 kfree(output_buf);
2017free_req:
2018 kpp_request_free(req);
2019 return err;
2020}
2021
2022static int test_kpp(struct crypto_kpp *tfm, const char *alg,
2023 struct kpp_testvec *vecs, unsigned int tcount)
2024{
2025 int ret, i;
2026
2027 for (i = 0; i < tcount; i++) {
2028 ret = do_test_kpp(tfm, vecs++, alg);
2029 if (ret) {
2030 pr_err("alg: %s: test failed on vector %d, err=%d\n",
2031 alg, i + 1, ret);
2032 return ret;
2033 }
2034 }
2035 return 0;
2036}
2037
2038static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
2039 u32 type, u32 mask)
2040{
2041 struct crypto_kpp *tfm;
2042 int err = 0;
2043
2044 tfm = crypto_alloc_kpp(driver, type | CRYPTO_ALG_INTERNAL, mask);
2045 if (IS_ERR(tfm)) {
2046 pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
2047 driver, PTR_ERR(tfm));
2048 return PTR_ERR(tfm);
2049 }
2050 if (desc->suite.kpp.vecs)
2051 err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
2052 desc->suite.kpp.count);
2053
2054 crypto_free_kpp(tfm);
2055 return err;
2056}
2057
Herbert Xu50d2b6432016-06-29 19:32:20 +08002058static int test_akcipher_one(struct crypto_akcipher *tfm,
2059 struct akcipher_testvec *vecs)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002060{
Herbert Xudf27b262016-05-05 16:42:49 +08002061 char *xbuf[XBUFSIZE];
Tadeusz Struk946cc462015-06-16 10:31:06 -07002062 struct akcipher_request *req;
2063 void *outbuf_enc = NULL;
2064 void *outbuf_dec = NULL;
2065 struct tcrypt_result result;
2066 unsigned int out_len_max, out_len = 0;
2067 int err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002068 struct scatterlist src, dst, src_tab[2];
Tadeusz Struk946cc462015-06-16 10:31:06 -07002069
Herbert Xudf27b262016-05-05 16:42:49 +08002070 if (testmgr_alloc_buf(xbuf))
2071 return err;
2072
Tadeusz Struk946cc462015-06-16 10:31:06 -07002073 req = akcipher_request_alloc(tfm, GFP_KERNEL);
2074 if (!req)
Herbert Xudf27b262016-05-05 16:42:49 +08002075 goto free_xbuf;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002076
2077 init_completion(&result.completion);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002078
2079 if (vecs->public_key_vec)
2080 err = crypto_akcipher_set_pub_key(tfm, vecs->key,
2081 vecs->key_len);
2082 else
2083 err = crypto_akcipher_set_priv_key(tfm, vecs->key,
2084 vecs->key_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002085 if (err)
2086 goto free_req;
2087
Salvatore Benedetto57763f52016-07-04 10:52:34 +01002088 err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002089 out_len_max = crypto_akcipher_maxsize(tfm);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002090 outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
2091 if (!outbuf_enc)
2092 goto free_req;
2093
Herbert Xudf27b262016-05-05 16:42:49 +08002094 if (WARN_ON(vecs->m_size > PAGE_SIZE))
2095 goto free_all;
2096
2097 memcpy(xbuf[0], vecs->m, vecs->m_size);
2098
Tadeusz Struk22287b02015-10-08 09:26:55 -07002099 sg_init_table(src_tab, 2);
Herbert Xudf27b262016-05-05 16:42:49 +08002100 sg_set_buf(&src_tab[0], xbuf[0], 8);
2101 sg_set_buf(&src_tab[1], xbuf[0] + 8, vecs->m_size - 8);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002102 sg_init_one(&dst, outbuf_enc, out_len_max);
2103 akcipher_request_set_crypt(req, src_tab, &dst, vecs->m_size,
2104 out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002105 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
2106 tcrypt_complete, &result);
2107
2108 /* Run RSA encrypt - c = m^e mod n;*/
2109 err = wait_async_op(&result, crypto_akcipher_encrypt(req));
2110 if (err) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002111 pr_err("alg: akcipher: encrypt test failed. err %d\n", err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002112 goto free_all;
2113 }
Tadeusz Struk22287b02015-10-08 09:26:55 -07002114 if (req->dst_len != vecs->c_size) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002115 pr_err("alg: akcipher: encrypt test failed. Invalid output len\n");
Tadeusz Struk946cc462015-06-16 10:31:06 -07002116 err = -EINVAL;
2117 goto free_all;
2118 }
2119 /* verify that encrypted message is equal to expected */
Herbert Xudf27b262016-05-05 16:42:49 +08002120 if (memcmp(vecs->c, outbuf_enc, vecs->c_size)) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002121 pr_err("alg: akcipher: encrypt test failed. Invalid output\n");
2122 hexdump(outbuf_enc, vecs->c_size);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002123 err = -EINVAL;
2124 goto free_all;
2125 }
2126 /* Don't invoke decrypt for vectors with public key */
2127 if (vecs->public_key_vec) {
2128 err = 0;
2129 goto free_all;
2130 }
2131 outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
2132 if (!outbuf_dec) {
2133 err = -ENOMEM;
2134 goto free_all;
2135 }
Herbert Xudf27b262016-05-05 16:42:49 +08002136
2137 if (WARN_ON(vecs->c_size > PAGE_SIZE))
2138 goto free_all;
2139
2140 memcpy(xbuf[0], vecs->c, vecs->c_size);
2141
2142 sg_init_one(&src, xbuf[0], vecs->c_size);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002143 sg_init_one(&dst, outbuf_dec, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002144 init_completion(&result.completion);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002145 akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002146
2147 /* Run RSA decrypt - m = c^d mod n;*/
2148 err = wait_async_op(&result, crypto_akcipher_decrypt(req));
2149 if (err) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002150 pr_err("alg: akcipher: decrypt test failed. err %d\n", err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002151 goto free_all;
2152 }
2153 out_len = req->dst_len;
Herbert Xu50d2b6432016-06-29 19:32:20 +08002154 if (out_len < vecs->m_size) {
2155 pr_err("alg: akcipher: decrypt test failed. "
2156 "Invalid output len %u\n", out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002157 err = -EINVAL;
2158 goto free_all;
2159 }
2160 /* verify that decrypted message is equal to the original msg */
Herbert Xu50d2b6432016-06-29 19:32:20 +08002161 if (memchr_inv(outbuf_dec, 0, out_len - vecs->m_size) ||
2162 memcmp(vecs->m, outbuf_dec + out_len - vecs->m_size,
2163 vecs->m_size)) {
2164 pr_err("alg: akcipher: decrypt test failed. Invalid output\n");
2165 hexdump(outbuf_dec, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002166 err = -EINVAL;
2167 }
2168free_all:
2169 kfree(outbuf_dec);
2170 kfree(outbuf_enc);
2171free_req:
2172 akcipher_request_free(req);
Herbert Xudf27b262016-05-05 16:42:49 +08002173free_xbuf:
2174 testmgr_free_buf(xbuf);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002175 return err;
2176}
2177
Herbert Xu50d2b6432016-06-29 19:32:20 +08002178static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
2179 struct akcipher_testvec *vecs, unsigned int tcount)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002180{
Herbert Xu15226e42016-07-18 18:20:10 +08002181 const char *algo =
2182 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
Tadeusz Struk946cc462015-06-16 10:31:06 -07002183 int ret, i;
2184
2185 for (i = 0; i < tcount; i++) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002186 ret = test_akcipher_one(tfm, vecs++);
2187 if (!ret)
2188 continue;
2189
Herbert Xu15226e42016-07-18 18:20:10 +08002190 pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
2191 i + 1, algo, ret);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002192 return ret;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002193 }
2194 return 0;
2195}
2196
Tadeusz Struk946cc462015-06-16 10:31:06 -07002197static int alg_test_akcipher(const struct alg_test_desc *desc,
2198 const char *driver, u32 type, u32 mask)
2199{
2200 struct crypto_akcipher *tfm;
2201 int err = 0;
2202
2203 tfm = crypto_alloc_akcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
2204 if (IS_ERR(tfm)) {
2205 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
2206 driver, PTR_ERR(tfm));
2207 return PTR_ERR(tfm);
2208 }
2209 if (desc->suite.akcipher.vecs)
2210 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
2211 desc->suite.akcipher.count);
2212
2213 crypto_free_akcipher(tfm);
2214 return err;
2215}
2216
Youquan, Song863b5572009-12-23 19:45:20 +08002217static int alg_test_null(const struct alg_test_desc *desc,
2218 const char *driver, u32 type, u32 mask)
2219{
2220 return 0;
2221}
2222
Herbert Xuda7f0332008-07-31 17:08:25 +08002223/* Please keep this list sorted by algorithm name. */
2224static const struct alg_test_desc alg_test_descs[] = {
2225 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002226 .alg = "__cbc-cast5-avx",
2227 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002228 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002229 .alg = "__cbc-cast6-avx",
2230 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002231 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002232 .alg = "__cbc-serpent-avx",
2233 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002234 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002235 .alg = "__cbc-serpent-avx2",
2236 .test = alg_test_null,
2237 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002238 .alg = "__cbc-serpent-sse2",
2239 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002240 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002241 .alg = "__cbc-twofish-avx",
2242 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002243 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002244 .alg = "__driver-cbc-aes-aesni",
2245 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002246 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002247 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002248 .alg = "__driver-cbc-camellia-aesni",
2249 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002250 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002251 .alg = "__driver-cbc-camellia-aesni-avx2",
2252 .test = alg_test_null,
2253 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002254 .alg = "__driver-cbc-cast5-avx",
2255 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002256 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002257 .alg = "__driver-cbc-cast6-avx",
2258 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002259 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002260 .alg = "__driver-cbc-serpent-avx",
2261 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002262 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002263 .alg = "__driver-cbc-serpent-avx2",
2264 .test = alg_test_null,
2265 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002266 .alg = "__driver-cbc-serpent-sse2",
2267 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002268 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002269 .alg = "__driver-cbc-twofish-avx",
2270 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002271 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002272 .alg = "__driver-ecb-aes-aesni",
2273 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002274 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002275 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002276 .alg = "__driver-ecb-camellia-aesni",
2277 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002278 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002279 .alg = "__driver-ecb-camellia-aesni-avx2",
2280 .test = alg_test_null,
2281 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002282 .alg = "__driver-ecb-cast5-avx",
2283 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002284 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002285 .alg = "__driver-ecb-cast6-avx",
2286 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002287 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002288 .alg = "__driver-ecb-serpent-avx",
2289 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002290 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002291 .alg = "__driver-ecb-serpent-avx2",
2292 .test = alg_test_null,
2293 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002294 .alg = "__driver-ecb-serpent-sse2",
2295 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002296 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002297 .alg = "__driver-ecb-twofish-avx",
2298 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002299 }, {
Tadeusz Struk9d77b6c2015-06-24 09:01:30 -07002300 .alg = "__driver-gcm-aes-aesni",
2301 .test = alg_test_null,
2302 .fips_allowed = 1,
2303 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002304 .alg = "__ghash-pclmulqdqni",
2305 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002306 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002307 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002308 .alg = "ansi_cprng",
2309 .test = alg_test_cprng,
2310 .suite = {
2311 .cprng = {
2312 .vecs = ansi_cprng_aes_tv_template,
2313 .count = ANSI_CPRNG_AES_TEST_VECTORS
2314 }
2315 }
2316 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002317 .alg = "authenc(hmac(md5),ecb(cipher_null))",
2318 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002319 .suite = {
2320 .aead = {
2321 .enc = {
2322 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
2323 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
2324 },
2325 .dec = {
2326 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
2327 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
2328 }
2329 }
2330 }
2331 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002332 .alg = "authenc(hmac(sha1),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002333 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002334 .suite = {
2335 .aead = {
2336 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302337 .vecs =
2338 hmac_sha1_aes_cbc_enc_tv_temp,
2339 .count =
2340 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
2341 }
2342 }
2343 }
2344 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002345 .alg = "authenc(hmac(sha1),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302346 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302347 .suite = {
2348 .aead = {
2349 .enc = {
2350 .vecs =
2351 hmac_sha1_des_cbc_enc_tv_temp,
2352 .count =
2353 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
2354 }
2355 }
2356 }
2357 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002358 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302359 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002360 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302361 .suite = {
2362 .aead = {
2363 .enc = {
2364 .vecs =
2365 hmac_sha1_des3_ede_cbc_enc_tv_temp,
2366 .count =
2367 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002368 }
2369 }
2370 }
2371 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002372 .alg = "authenc(hmac(sha1),ctr(aes))",
2373 .test = alg_test_null,
2374 .fips_allowed = 1,
2375 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002376 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
2377 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002378 .suite = {
2379 .aead = {
2380 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302381 .vecs =
2382 hmac_sha1_ecb_cipher_null_enc_tv_temp,
2383 .count =
2384 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002385 },
2386 .dec = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302387 .vecs =
2388 hmac_sha1_ecb_cipher_null_dec_tv_temp,
2389 .count =
2390 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
2391 }
2392 }
2393 }
2394 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002395 .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
2396 .test = alg_test_null,
2397 .fips_allowed = 1,
2398 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002399 .alg = "authenc(hmac(sha224),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302400 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302401 .suite = {
2402 .aead = {
2403 .enc = {
2404 .vecs =
2405 hmac_sha224_des_cbc_enc_tv_temp,
2406 .count =
2407 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2408 }
2409 }
2410 }
2411 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002412 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302413 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002414 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302415 .suite = {
2416 .aead = {
2417 .enc = {
2418 .vecs =
2419 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2420 .count =
2421 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002422 }
2423 }
2424 }
2425 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002426 .alg = "authenc(hmac(sha256),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002427 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002428 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002429 .suite = {
2430 .aead = {
2431 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302432 .vecs =
2433 hmac_sha256_aes_cbc_enc_tv_temp,
2434 .count =
2435 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2436 }
2437 }
2438 }
2439 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002440 .alg = "authenc(hmac(sha256),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302441 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302442 .suite = {
2443 .aead = {
2444 .enc = {
2445 .vecs =
2446 hmac_sha256_des_cbc_enc_tv_temp,
2447 .count =
2448 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2449 }
2450 }
2451 }
2452 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002453 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302454 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002455 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302456 .suite = {
2457 .aead = {
2458 .enc = {
2459 .vecs =
2460 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2461 .count =
2462 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2463 }
2464 }
2465 }
2466 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002467 .alg = "authenc(hmac(sha256),ctr(aes))",
2468 .test = alg_test_null,
2469 .fips_allowed = 1,
2470 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002471 .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
2472 .test = alg_test_null,
2473 .fips_allowed = 1,
2474 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002475 .alg = "authenc(hmac(sha384),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302476 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302477 .suite = {
2478 .aead = {
2479 .enc = {
2480 .vecs =
2481 hmac_sha384_des_cbc_enc_tv_temp,
2482 .count =
2483 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2484 }
2485 }
2486 }
2487 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002488 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302489 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002490 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302491 .suite = {
2492 .aead = {
2493 .enc = {
2494 .vecs =
2495 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2496 .count =
2497 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002498 }
2499 }
2500 }
2501 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002502 .alg = "authenc(hmac(sha384),ctr(aes))",
2503 .test = alg_test_null,
2504 .fips_allowed = 1,
2505 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002506 .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
2507 .test = alg_test_null,
2508 .fips_allowed = 1,
2509 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002510 .alg = "authenc(hmac(sha512),cbc(aes))",
Marcus Meissnered1afac2016-02-05 14:23:33 +01002511 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002512 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002513 .suite = {
2514 .aead = {
2515 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302516 .vecs =
2517 hmac_sha512_aes_cbc_enc_tv_temp,
2518 .count =
2519 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2520 }
2521 }
2522 }
2523 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002524 .alg = "authenc(hmac(sha512),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302525 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302526 .suite = {
2527 .aead = {
2528 .enc = {
2529 .vecs =
2530 hmac_sha512_des_cbc_enc_tv_temp,
2531 .count =
2532 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2533 }
2534 }
2535 }
2536 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002537 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302538 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002539 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302540 .suite = {
2541 .aead = {
2542 .enc = {
2543 .vecs =
2544 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2545 .count =
2546 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002547 }
2548 }
2549 }
2550 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002551 .alg = "authenc(hmac(sha512),ctr(aes))",
2552 .test = alg_test_null,
2553 .fips_allowed = 1,
2554 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002555 .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
2556 .test = alg_test_null,
2557 .fips_allowed = 1,
2558 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002559 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002560 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002561 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002562 .suite = {
2563 .cipher = {
2564 .enc = {
2565 .vecs = aes_cbc_enc_tv_template,
2566 .count = AES_CBC_ENC_TEST_VECTORS
2567 },
2568 .dec = {
2569 .vecs = aes_cbc_dec_tv_template,
2570 .count = AES_CBC_DEC_TEST_VECTORS
2571 }
2572 }
2573 }
2574 }, {
2575 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002576 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002577 .suite = {
2578 .cipher = {
2579 .enc = {
2580 .vecs = anubis_cbc_enc_tv_template,
2581 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2582 },
2583 .dec = {
2584 .vecs = anubis_cbc_dec_tv_template,
2585 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2586 }
2587 }
2588 }
2589 }, {
2590 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002591 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002592 .suite = {
2593 .cipher = {
2594 .enc = {
2595 .vecs = bf_cbc_enc_tv_template,
2596 .count = BF_CBC_ENC_TEST_VECTORS
2597 },
2598 .dec = {
2599 .vecs = bf_cbc_dec_tv_template,
2600 .count = BF_CBC_DEC_TEST_VECTORS
2601 }
2602 }
2603 }
2604 }, {
2605 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002606 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002607 .suite = {
2608 .cipher = {
2609 .enc = {
2610 .vecs = camellia_cbc_enc_tv_template,
2611 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2612 },
2613 .dec = {
2614 .vecs = camellia_cbc_dec_tv_template,
2615 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2616 }
2617 }
2618 }
2619 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002620 .alg = "cbc(cast5)",
2621 .test = alg_test_skcipher,
2622 .suite = {
2623 .cipher = {
2624 .enc = {
2625 .vecs = cast5_cbc_enc_tv_template,
2626 .count = CAST5_CBC_ENC_TEST_VECTORS
2627 },
2628 .dec = {
2629 .vecs = cast5_cbc_dec_tv_template,
2630 .count = CAST5_CBC_DEC_TEST_VECTORS
2631 }
2632 }
2633 }
2634 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002635 .alg = "cbc(cast6)",
2636 .test = alg_test_skcipher,
2637 .suite = {
2638 .cipher = {
2639 .enc = {
2640 .vecs = cast6_cbc_enc_tv_template,
2641 .count = CAST6_CBC_ENC_TEST_VECTORS
2642 },
2643 .dec = {
2644 .vecs = cast6_cbc_dec_tv_template,
2645 .count = CAST6_CBC_DEC_TEST_VECTORS
2646 }
2647 }
2648 }
2649 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002650 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002651 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002652 .suite = {
2653 .cipher = {
2654 .enc = {
2655 .vecs = des_cbc_enc_tv_template,
2656 .count = DES_CBC_ENC_TEST_VECTORS
2657 },
2658 .dec = {
2659 .vecs = des_cbc_dec_tv_template,
2660 .count = DES_CBC_DEC_TEST_VECTORS
2661 }
2662 }
2663 }
2664 }, {
2665 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002666 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002667 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002668 .suite = {
2669 .cipher = {
2670 .enc = {
2671 .vecs = des3_ede_cbc_enc_tv_template,
2672 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2673 },
2674 .dec = {
2675 .vecs = des3_ede_cbc_dec_tv_template,
2676 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2677 }
2678 }
2679 }
2680 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002681 .alg = "cbc(serpent)",
2682 .test = alg_test_skcipher,
2683 .suite = {
2684 .cipher = {
2685 .enc = {
2686 .vecs = serpent_cbc_enc_tv_template,
2687 .count = SERPENT_CBC_ENC_TEST_VECTORS
2688 },
2689 .dec = {
2690 .vecs = serpent_cbc_dec_tv_template,
2691 .count = SERPENT_CBC_DEC_TEST_VECTORS
2692 }
2693 }
2694 }
2695 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002696 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002697 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002698 .suite = {
2699 .cipher = {
2700 .enc = {
2701 .vecs = tf_cbc_enc_tv_template,
2702 .count = TF_CBC_ENC_TEST_VECTORS
2703 },
2704 .dec = {
2705 .vecs = tf_cbc_dec_tv_template,
2706 .count = TF_CBC_DEC_TEST_VECTORS
2707 }
2708 }
2709 }
2710 }, {
2711 .alg = "ccm(aes)",
2712 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002713 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002714 .suite = {
2715 .aead = {
2716 .enc = {
2717 .vecs = aes_ccm_enc_tv_template,
2718 .count = AES_CCM_ENC_TEST_VECTORS
2719 },
2720 .dec = {
2721 .vecs = aes_ccm_dec_tv_template,
2722 .count = AES_CCM_DEC_TEST_VECTORS
2723 }
2724 }
2725 }
2726 }, {
Martin Willi3590ebf2015-06-01 13:43:57 +02002727 .alg = "chacha20",
2728 .test = alg_test_skcipher,
2729 .suite = {
2730 .cipher = {
2731 .enc = {
2732 .vecs = chacha20_enc_tv_template,
2733 .count = CHACHA20_ENC_TEST_VECTORS
2734 },
2735 .dec = {
2736 .vecs = chacha20_enc_tv_template,
2737 .count = CHACHA20_ENC_TEST_VECTORS
2738 },
2739 }
2740 }
2741 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002742 .alg = "cmac(aes)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002743 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002744 .test = alg_test_hash,
2745 .suite = {
2746 .hash = {
2747 .vecs = aes_cmac128_tv_template,
2748 .count = CMAC_AES_TEST_VECTORS
2749 }
2750 }
2751 }, {
2752 .alg = "cmac(des3_ede)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002753 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002754 .test = alg_test_hash,
2755 .suite = {
2756 .hash = {
2757 .vecs = des3_ede_cmac64_tv_template,
2758 .count = CMAC_DES3_EDE_TEST_VECTORS
2759 }
2760 }
2761 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002762 .alg = "compress_null",
2763 .test = alg_test_null,
2764 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02002765 .alg = "crc32",
2766 .test = alg_test_hash,
2767 .suite = {
2768 .hash = {
2769 .vecs = crc32_tv_template,
2770 .count = CRC32_TEST_VECTORS
2771 }
2772 }
2773 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002774 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002775 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002776 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002777 .suite = {
2778 .hash = {
2779 .vecs = crc32c_tv_template,
2780 .count = CRC32C_TEST_VECTORS
2781 }
2782 }
2783 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002784 .alg = "crct10dif",
2785 .test = alg_test_hash,
2786 .fips_allowed = 1,
2787 .suite = {
2788 .hash = {
2789 .vecs = crct10dif_tv_template,
2790 .count = CRCT10DIF_TEST_VECTORS
2791 }
2792 }
2793 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002794 .alg = "cryptd(__driver-cbc-aes-aesni)",
2795 .test = alg_test_null,
2796 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002797 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002798 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2799 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002800 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002801 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2802 .test = alg_test_null,
2803 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002804 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2805 .test = alg_test_null,
2806 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002807 .alg = "cryptd(__driver-ecb-aes-aesni)",
2808 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002809 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002810 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002811 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2812 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002813 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002814 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2815 .test = alg_test_null,
2816 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002817 .alg = "cryptd(__driver-ecb-cast5-avx)",
2818 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002819 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002820 .alg = "cryptd(__driver-ecb-cast6-avx)",
2821 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002822 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002823 .alg = "cryptd(__driver-ecb-serpent-avx)",
2824 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002825 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002826 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2827 .test = alg_test_null,
2828 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002829 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2830 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002831 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002832 .alg = "cryptd(__driver-ecb-twofish-avx)",
2833 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002834 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002835 .alg = "cryptd(__driver-gcm-aes-aesni)",
2836 .test = alg_test_null,
2837 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002838 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002839 .alg = "cryptd(__ghash-pclmulqdqni)",
2840 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002841 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002842 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002843 .alg = "ctr(aes)",
2844 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002845 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002846 .suite = {
2847 .cipher = {
2848 .enc = {
2849 .vecs = aes_ctr_enc_tv_template,
2850 .count = AES_CTR_ENC_TEST_VECTORS
2851 },
2852 .dec = {
2853 .vecs = aes_ctr_dec_tv_template,
2854 .count = AES_CTR_DEC_TEST_VECTORS
2855 }
2856 }
2857 }
2858 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002859 .alg = "ctr(blowfish)",
2860 .test = alg_test_skcipher,
2861 .suite = {
2862 .cipher = {
2863 .enc = {
2864 .vecs = bf_ctr_enc_tv_template,
2865 .count = BF_CTR_ENC_TEST_VECTORS
2866 },
2867 .dec = {
2868 .vecs = bf_ctr_dec_tv_template,
2869 .count = BF_CTR_DEC_TEST_VECTORS
2870 }
2871 }
2872 }
2873 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002874 .alg = "ctr(camellia)",
2875 .test = alg_test_skcipher,
2876 .suite = {
2877 .cipher = {
2878 .enc = {
2879 .vecs = camellia_ctr_enc_tv_template,
2880 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2881 },
2882 .dec = {
2883 .vecs = camellia_ctr_dec_tv_template,
2884 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2885 }
2886 }
2887 }
2888 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002889 .alg = "ctr(cast5)",
2890 .test = alg_test_skcipher,
2891 .suite = {
2892 .cipher = {
2893 .enc = {
2894 .vecs = cast5_ctr_enc_tv_template,
2895 .count = CAST5_CTR_ENC_TEST_VECTORS
2896 },
2897 .dec = {
2898 .vecs = cast5_ctr_dec_tv_template,
2899 .count = CAST5_CTR_DEC_TEST_VECTORS
2900 }
2901 }
2902 }
2903 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002904 .alg = "ctr(cast6)",
2905 .test = alg_test_skcipher,
2906 .suite = {
2907 .cipher = {
2908 .enc = {
2909 .vecs = cast6_ctr_enc_tv_template,
2910 .count = CAST6_CTR_ENC_TEST_VECTORS
2911 },
2912 .dec = {
2913 .vecs = cast6_ctr_dec_tv_template,
2914 .count = CAST6_CTR_DEC_TEST_VECTORS
2915 }
2916 }
2917 }
2918 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002919 .alg = "ctr(des)",
2920 .test = alg_test_skcipher,
2921 .suite = {
2922 .cipher = {
2923 .enc = {
2924 .vecs = des_ctr_enc_tv_template,
2925 .count = DES_CTR_ENC_TEST_VECTORS
2926 },
2927 .dec = {
2928 .vecs = des_ctr_dec_tv_template,
2929 .count = DES_CTR_DEC_TEST_VECTORS
2930 }
2931 }
2932 }
2933 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002934 .alg = "ctr(des3_ede)",
2935 .test = alg_test_skcipher,
2936 .suite = {
2937 .cipher = {
2938 .enc = {
2939 .vecs = des3_ede_ctr_enc_tv_template,
2940 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2941 },
2942 .dec = {
2943 .vecs = des3_ede_ctr_dec_tv_template,
2944 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2945 }
2946 }
2947 }
2948 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002949 .alg = "ctr(serpent)",
2950 .test = alg_test_skcipher,
2951 .suite = {
2952 .cipher = {
2953 .enc = {
2954 .vecs = serpent_ctr_enc_tv_template,
2955 .count = SERPENT_CTR_ENC_TEST_VECTORS
2956 },
2957 .dec = {
2958 .vecs = serpent_ctr_dec_tv_template,
2959 .count = SERPENT_CTR_DEC_TEST_VECTORS
2960 }
2961 }
2962 }
2963 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002964 .alg = "ctr(twofish)",
2965 .test = alg_test_skcipher,
2966 .suite = {
2967 .cipher = {
2968 .enc = {
2969 .vecs = tf_ctr_enc_tv_template,
2970 .count = TF_CTR_ENC_TEST_VECTORS
2971 },
2972 .dec = {
2973 .vecs = tf_ctr_dec_tv_template,
2974 .count = TF_CTR_DEC_TEST_VECTORS
2975 }
2976 }
2977 }
2978 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002979 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002980 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002981 .suite = {
2982 .cipher = {
2983 .enc = {
2984 .vecs = cts_mode_enc_tv_template,
2985 .count = CTS_MODE_ENC_TEST_VECTORS
2986 },
2987 .dec = {
2988 .vecs = cts_mode_dec_tv_template,
2989 .count = CTS_MODE_DEC_TEST_VECTORS
2990 }
2991 }
2992 }
2993 }, {
2994 .alg = "deflate",
2995 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002996 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002997 .suite = {
2998 .comp = {
2999 .comp = {
3000 .vecs = deflate_comp_tv_template,
3001 .count = DEFLATE_COMP_TEST_VECTORS
3002 },
3003 .decomp = {
3004 .vecs = deflate_decomp_tv_template,
3005 .count = DEFLATE_DECOMP_TEST_VECTORS
3006 }
3007 }
3008 }
3009 }, {
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003010 .alg = "dh",
3011 .test = alg_test_kpp,
3012 .fips_allowed = 1,
3013 .suite = {
3014 .kpp = {
3015 .vecs = dh_tv_template,
3016 .count = DH_TEST_VECTORS
3017 }
3018 }
3019 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003020 .alg = "digest_null",
3021 .test = alg_test_null,
3022 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003023 .alg = "drbg_nopr_ctr_aes128",
3024 .test = alg_test_drbg,
3025 .fips_allowed = 1,
3026 .suite = {
3027 .drbg = {
3028 .vecs = drbg_nopr_ctr_aes128_tv_template,
3029 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
3030 }
3031 }
3032 }, {
3033 .alg = "drbg_nopr_ctr_aes192",
3034 .test = alg_test_drbg,
3035 .fips_allowed = 1,
3036 .suite = {
3037 .drbg = {
3038 .vecs = drbg_nopr_ctr_aes192_tv_template,
3039 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
3040 }
3041 }
3042 }, {
3043 .alg = "drbg_nopr_ctr_aes256",
3044 .test = alg_test_drbg,
3045 .fips_allowed = 1,
3046 .suite = {
3047 .drbg = {
3048 .vecs = drbg_nopr_ctr_aes256_tv_template,
3049 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
3050 }
3051 }
3052 }, {
3053 /*
3054 * There is no need to specifically test the DRBG with every
3055 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
3056 */
3057 .alg = "drbg_nopr_hmac_sha1",
3058 .fips_allowed = 1,
3059 .test = alg_test_null,
3060 }, {
3061 .alg = "drbg_nopr_hmac_sha256",
3062 .test = alg_test_drbg,
3063 .fips_allowed = 1,
3064 .suite = {
3065 .drbg = {
3066 .vecs = drbg_nopr_hmac_sha256_tv_template,
3067 .count =
3068 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
3069 }
3070 }
3071 }, {
3072 /* covered by drbg_nopr_hmac_sha256 test */
3073 .alg = "drbg_nopr_hmac_sha384",
3074 .fips_allowed = 1,
3075 .test = alg_test_null,
3076 }, {
3077 .alg = "drbg_nopr_hmac_sha512",
3078 .test = alg_test_null,
3079 .fips_allowed = 1,
3080 }, {
3081 .alg = "drbg_nopr_sha1",
3082 .fips_allowed = 1,
3083 .test = alg_test_null,
3084 }, {
3085 .alg = "drbg_nopr_sha256",
3086 .test = alg_test_drbg,
3087 .fips_allowed = 1,
3088 .suite = {
3089 .drbg = {
3090 .vecs = drbg_nopr_sha256_tv_template,
3091 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
3092 }
3093 }
3094 }, {
3095 /* covered by drbg_nopr_sha256 test */
3096 .alg = "drbg_nopr_sha384",
3097 .fips_allowed = 1,
3098 .test = alg_test_null,
3099 }, {
3100 .alg = "drbg_nopr_sha512",
3101 .fips_allowed = 1,
3102 .test = alg_test_null,
3103 }, {
3104 .alg = "drbg_pr_ctr_aes128",
3105 .test = alg_test_drbg,
3106 .fips_allowed = 1,
3107 .suite = {
3108 .drbg = {
3109 .vecs = drbg_pr_ctr_aes128_tv_template,
3110 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
3111 }
3112 }
3113 }, {
3114 /* covered by drbg_pr_ctr_aes128 test */
3115 .alg = "drbg_pr_ctr_aes192",
3116 .fips_allowed = 1,
3117 .test = alg_test_null,
3118 }, {
3119 .alg = "drbg_pr_ctr_aes256",
3120 .fips_allowed = 1,
3121 .test = alg_test_null,
3122 }, {
3123 .alg = "drbg_pr_hmac_sha1",
3124 .fips_allowed = 1,
3125 .test = alg_test_null,
3126 }, {
3127 .alg = "drbg_pr_hmac_sha256",
3128 .test = alg_test_drbg,
3129 .fips_allowed = 1,
3130 .suite = {
3131 .drbg = {
3132 .vecs = drbg_pr_hmac_sha256_tv_template,
3133 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
3134 }
3135 }
3136 }, {
3137 /* covered by drbg_pr_hmac_sha256 test */
3138 .alg = "drbg_pr_hmac_sha384",
3139 .fips_allowed = 1,
3140 .test = alg_test_null,
3141 }, {
3142 .alg = "drbg_pr_hmac_sha512",
3143 .test = alg_test_null,
3144 .fips_allowed = 1,
3145 }, {
3146 .alg = "drbg_pr_sha1",
3147 .fips_allowed = 1,
3148 .test = alg_test_null,
3149 }, {
3150 .alg = "drbg_pr_sha256",
3151 .test = alg_test_drbg,
3152 .fips_allowed = 1,
3153 .suite = {
3154 .drbg = {
3155 .vecs = drbg_pr_sha256_tv_template,
3156 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
3157 }
3158 }
3159 }, {
3160 /* covered by drbg_pr_sha256 test */
3161 .alg = "drbg_pr_sha384",
3162 .fips_allowed = 1,
3163 .test = alg_test_null,
3164 }, {
3165 .alg = "drbg_pr_sha512",
3166 .fips_allowed = 1,
3167 .test = alg_test_null,
3168 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08003169 .alg = "ecb(__aes-aesni)",
3170 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02003171 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08003172 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003173 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003174 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003175 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003176 .suite = {
3177 .cipher = {
3178 .enc = {
3179 .vecs = aes_enc_tv_template,
3180 .count = AES_ENC_TEST_VECTORS
3181 },
3182 .dec = {
3183 .vecs = aes_dec_tv_template,
3184 .count = AES_DEC_TEST_VECTORS
3185 }
3186 }
3187 }
3188 }, {
3189 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003190 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003191 .suite = {
3192 .cipher = {
3193 .enc = {
3194 .vecs = anubis_enc_tv_template,
3195 .count = ANUBIS_ENC_TEST_VECTORS
3196 },
3197 .dec = {
3198 .vecs = anubis_dec_tv_template,
3199 .count = ANUBIS_DEC_TEST_VECTORS
3200 }
3201 }
3202 }
3203 }, {
3204 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003205 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003206 .suite = {
3207 .cipher = {
3208 .enc = {
3209 .vecs = arc4_enc_tv_template,
3210 .count = ARC4_ENC_TEST_VECTORS
3211 },
3212 .dec = {
3213 .vecs = arc4_dec_tv_template,
3214 .count = ARC4_DEC_TEST_VECTORS
3215 }
3216 }
3217 }
3218 }, {
3219 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003220 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003221 .suite = {
3222 .cipher = {
3223 .enc = {
3224 .vecs = bf_enc_tv_template,
3225 .count = BF_ENC_TEST_VECTORS
3226 },
3227 .dec = {
3228 .vecs = bf_dec_tv_template,
3229 .count = BF_DEC_TEST_VECTORS
3230 }
3231 }
3232 }
3233 }, {
3234 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003235 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003236 .suite = {
3237 .cipher = {
3238 .enc = {
3239 .vecs = camellia_enc_tv_template,
3240 .count = CAMELLIA_ENC_TEST_VECTORS
3241 },
3242 .dec = {
3243 .vecs = camellia_dec_tv_template,
3244 .count = CAMELLIA_DEC_TEST_VECTORS
3245 }
3246 }
3247 }
3248 }, {
3249 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003250 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003251 .suite = {
3252 .cipher = {
3253 .enc = {
3254 .vecs = cast5_enc_tv_template,
3255 .count = CAST5_ENC_TEST_VECTORS
3256 },
3257 .dec = {
3258 .vecs = cast5_dec_tv_template,
3259 .count = CAST5_DEC_TEST_VECTORS
3260 }
3261 }
3262 }
3263 }, {
3264 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003265 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003266 .suite = {
3267 .cipher = {
3268 .enc = {
3269 .vecs = cast6_enc_tv_template,
3270 .count = CAST6_ENC_TEST_VECTORS
3271 },
3272 .dec = {
3273 .vecs = cast6_dec_tv_template,
3274 .count = CAST6_DEC_TEST_VECTORS
3275 }
3276 }
3277 }
3278 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003279 .alg = "ecb(cipher_null)",
3280 .test = alg_test_null,
3281 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003282 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003283 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003284 .suite = {
3285 .cipher = {
3286 .enc = {
3287 .vecs = des_enc_tv_template,
3288 .count = DES_ENC_TEST_VECTORS
3289 },
3290 .dec = {
3291 .vecs = des_dec_tv_template,
3292 .count = DES_DEC_TEST_VECTORS
3293 }
3294 }
3295 }
3296 }, {
3297 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003298 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003299 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003300 .suite = {
3301 .cipher = {
3302 .enc = {
3303 .vecs = des3_ede_enc_tv_template,
3304 .count = DES3_EDE_ENC_TEST_VECTORS
3305 },
3306 .dec = {
3307 .vecs = des3_ede_dec_tv_template,
3308 .count = DES3_EDE_DEC_TEST_VECTORS
3309 }
3310 }
3311 }
3312 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003313 .alg = "ecb(fcrypt)",
3314 .test = alg_test_skcipher,
3315 .suite = {
3316 .cipher = {
3317 .enc = {
3318 .vecs = fcrypt_pcbc_enc_tv_template,
3319 .count = 1
3320 },
3321 .dec = {
3322 .vecs = fcrypt_pcbc_dec_tv_template,
3323 .count = 1
3324 }
3325 }
3326 }
3327 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003328 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003329 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003330 .suite = {
3331 .cipher = {
3332 .enc = {
3333 .vecs = khazad_enc_tv_template,
3334 .count = KHAZAD_ENC_TEST_VECTORS
3335 },
3336 .dec = {
3337 .vecs = khazad_dec_tv_template,
3338 .count = KHAZAD_DEC_TEST_VECTORS
3339 }
3340 }
3341 }
3342 }, {
3343 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003344 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003345 .suite = {
3346 .cipher = {
3347 .enc = {
3348 .vecs = seed_enc_tv_template,
3349 .count = SEED_ENC_TEST_VECTORS
3350 },
3351 .dec = {
3352 .vecs = seed_dec_tv_template,
3353 .count = SEED_DEC_TEST_VECTORS
3354 }
3355 }
3356 }
3357 }, {
3358 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003359 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003360 .suite = {
3361 .cipher = {
3362 .enc = {
3363 .vecs = serpent_enc_tv_template,
3364 .count = SERPENT_ENC_TEST_VECTORS
3365 },
3366 .dec = {
3367 .vecs = serpent_dec_tv_template,
3368 .count = SERPENT_DEC_TEST_VECTORS
3369 }
3370 }
3371 }
3372 }, {
3373 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003374 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003375 .suite = {
3376 .cipher = {
3377 .enc = {
3378 .vecs = tea_enc_tv_template,
3379 .count = TEA_ENC_TEST_VECTORS
3380 },
3381 .dec = {
3382 .vecs = tea_dec_tv_template,
3383 .count = TEA_DEC_TEST_VECTORS
3384 }
3385 }
3386 }
3387 }, {
3388 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003389 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003390 .suite = {
3391 .cipher = {
3392 .enc = {
3393 .vecs = tnepres_enc_tv_template,
3394 .count = TNEPRES_ENC_TEST_VECTORS
3395 },
3396 .dec = {
3397 .vecs = tnepres_dec_tv_template,
3398 .count = TNEPRES_DEC_TEST_VECTORS
3399 }
3400 }
3401 }
3402 }, {
3403 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003404 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003405 .suite = {
3406 .cipher = {
3407 .enc = {
3408 .vecs = tf_enc_tv_template,
3409 .count = TF_ENC_TEST_VECTORS
3410 },
3411 .dec = {
3412 .vecs = tf_dec_tv_template,
3413 .count = TF_DEC_TEST_VECTORS
3414 }
3415 }
3416 }
3417 }, {
3418 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003419 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003420 .suite = {
3421 .cipher = {
3422 .enc = {
3423 .vecs = xeta_enc_tv_template,
3424 .count = XETA_ENC_TEST_VECTORS
3425 },
3426 .dec = {
3427 .vecs = xeta_dec_tv_template,
3428 .count = XETA_DEC_TEST_VECTORS
3429 }
3430 }
3431 }
3432 }, {
3433 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003434 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003435 .suite = {
3436 .cipher = {
3437 .enc = {
3438 .vecs = xtea_enc_tv_template,
3439 .count = XTEA_ENC_TEST_VECTORS
3440 },
3441 .dec = {
3442 .vecs = xtea_dec_tv_template,
3443 .count = XTEA_DEC_TEST_VECTORS
3444 }
3445 }
3446 }
3447 }, {
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003448 .alg = "ecdh",
3449 .test = alg_test_kpp,
3450 .fips_allowed = 1,
3451 .suite = {
3452 .kpp = {
3453 .vecs = ecdh_tv_template,
3454 .count = ECDH_TEST_VECTORS
3455 }
3456 }
3457 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003458 .alg = "gcm(aes)",
3459 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003460 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003461 .suite = {
3462 .aead = {
3463 .enc = {
3464 .vecs = aes_gcm_enc_tv_template,
3465 .count = AES_GCM_ENC_TEST_VECTORS
3466 },
3467 .dec = {
3468 .vecs = aes_gcm_dec_tv_template,
3469 .count = AES_GCM_DEC_TEST_VECTORS
3470 }
3471 }
3472 }
3473 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003474 .alg = "ghash",
3475 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003476 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003477 .suite = {
3478 .hash = {
3479 .vecs = ghash_tv_template,
3480 .count = GHASH_TEST_VECTORS
3481 }
3482 }
3483 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003484 .alg = "hmac(crc32)",
3485 .test = alg_test_hash,
3486 .suite = {
3487 .hash = {
3488 .vecs = bfin_crc_tv_template,
3489 .count = BFIN_CRC_TEST_VECTORS
3490 }
3491 }
3492 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003493 .alg = "hmac(md5)",
3494 .test = alg_test_hash,
3495 .suite = {
3496 .hash = {
3497 .vecs = hmac_md5_tv_template,
3498 .count = HMAC_MD5_TEST_VECTORS
3499 }
3500 }
3501 }, {
3502 .alg = "hmac(rmd128)",
3503 .test = alg_test_hash,
3504 .suite = {
3505 .hash = {
3506 .vecs = hmac_rmd128_tv_template,
3507 .count = HMAC_RMD128_TEST_VECTORS
3508 }
3509 }
3510 }, {
3511 .alg = "hmac(rmd160)",
3512 .test = alg_test_hash,
3513 .suite = {
3514 .hash = {
3515 .vecs = hmac_rmd160_tv_template,
3516 .count = HMAC_RMD160_TEST_VECTORS
3517 }
3518 }
3519 }, {
3520 .alg = "hmac(sha1)",
3521 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003522 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003523 .suite = {
3524 .hash = {
3525 .vecs = hmac_sha1_tv_template,
3526 .count = HMAC_SHA1_TEST_VECTORS
3527 }
3528 }
3529 }, {
3530 .alg = "hmac(sha224)",
3531 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003532 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003533 .suite = {
3534 .hash = {
3535 .vecs = hmac_sha224_tv_template,
3536 .count = HMAC_SHA224_TEST_VECTORS
3537 }
3538 }
3539 }, {
3540 .alg = "hmac(sha256)",
3541 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003542 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003543 .suite = {
3544 .hash = {
3545 .vecs = hmac_sha256_tv_template,
3546 .count = HMAC_SHA256_TEST_VECTORS
3547 }
3548 }
3549 }, {
raveendra padasalagi98eca722016-07-01 11:16:54 +05303550 .alg = "hmac(sha3-224)",
3551 .test = alg_test_hash,
3552 .fips_allowed = 1,
3553 .suite = {
3554 .hash = {
3555 .vecs = hmac_sha3_224_tv_template,
3556 .count = HMAC_SHA3_224_TEST_VECTORS
3557 }
3558 }
3559 }, {
3560 .alg = "hmac(sha3-256)",
3561 .test = alg_test_hash,
3562 .fips_allowed = 1,
3563 .suite = {
3564 .hash = {
3565 .vecs = hmac_sha3_256_tv_template,
3566 .count = HMAC_SHA3_256_TEST_VECTORS
3567 }
3568 }
3569 }, {
3570 .alg = "hmac(sha3-384)",
3571 .test = alg_test_hash,
3572 .fips_allowed = 1,
3573 .suite = {
3574 .hash = {
3575 .vecs = hmac_sha3_384_tv_template,
3576 .count = HMAC_SHA3_384_TEST_VECTORS
3577 }
3578 }
3579 }, {
3580 .alg = "hmac(sha3-512)",
3581 .test = alg_test_hash,
3582 .fips_allowed = 1,
3583 .suite = {
3584 .hash = {
3585 .vecs = hmac_sha3_512_tv_template,
3586 .count = HMAC_SHA3_512_TEST_VECTORS
3587 }
3588 }
3589 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003590 .alg = "hmac(sha384)",
3591 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003592 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003593 .suite = {
3594 .hash = {
3595 .vecs = hmac_sha384_tv_template,
3596 .count = HMAC_SHA384_TEST_VECTORS
3597 }
3598 }
3599 }, {
3600 .alg = "hmac(sha512)",
3601 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003602 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003603 .suite = {
3604 .hash = {
3605 .vecs = hmac_sha512_tv_template,
3606 .count = HMAC_SHA512_TEST_VECTORS
3607 }
3608 }
3609 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003610 .alg = "jitterentropy_rng",
3611 .fips_allowed = 1,
3612 .test = alg_test_null,
3613 }, {
Stephan Mueller35351982015-09-21 20:59:56 +02003614 .alg = "kw(aes)",
3615 .test = alg_test_skcipher,
3616 .fips_allowed = 1,
3617 .suite = {
3618 .cipher = {
3619 .enc = {
3620 .vecs = aes_kw_enc_tv_template,
3621 .count = ARRAY_SIZE(aes_kw_enc_tv_template)
3622 },
3623 .dec = {
3624 .vecs = aes_kw_dec_tv_template,
3625 .count = ARRAY_SIZE(aes_kw_dec_tv_template)
3626 }
3627 }
3628 }
3629 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003630 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003631 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003632 .suite = {
3633 .cipher = {
3634 .enc = {
3635 .vecs = aes_lrw_enc_tv_template,
3636 .count = AES_LRW_ENC_TEST_VECTORS
3637 },
3638 .dec = {
3639 .vecs = aes_lrw_dec_tv_template,
3640 .count = AES_LRW_DEC_TEST_VECTORS
3641 }
3642 }
3643 }
3644 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003645 .alg = "lrw(camellia)",
3646 .test = alg_test_skcipher,
3647 .suite = {
3648 .cipher = {
3649 .enc = {
3650 .vecs = camellia_lrw_enc_tv_template,
3651 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3652 },
3653 .dec = {
3654 .vecs = camellia_lrw_dec_tv_template,
3655 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3656 }
3657 }
3658 }
3659 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003660 .alg = "lrw(cast6)",
3661 .test = alg_test_skcipher,
3662 .suite = {
3663 .cipher = {
3664 .enc = {
3665 .vecs = cast6_lrw_enc_tv_template,
3666 .count = CAST6_LRW_ENC_TEST_VECTORS
3667 },
3668 .dec = {
3669 .vecs = cast6_lrw_dec_tv_template,
3670 .count = CAST6_LRW_DEC_TEST_VECTORS
3671 }
3672 }
3673 }
3674 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003675 .alg = "lrw(serpent)",
3676 .test = alg_test_skcipher,
3677 .suite = {
3678 .cipher = {
3679 .enc = {
3680 .vecs = serpent_lrw_enc_tv_template,
3681 .count = SERPENT_LRW_ENC_TEST_VECTORS
3682 },
3683 .dec = {
3684 .vecs = serpent_lrw_dec_tv_template,
3685 .count = SERPENT_LRW_DEC_TEST_VECTORS
3686 }
3687 }
3688 }
3689 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003690 .alg = "lrw(twofish)",
3691 .test = alg_test_skcipher,
3692 .suite = {
3693 .cipher = {
3694 .enc = {
3695 .vecs = tf_lrw_enc_tv_template,
3696 .count = TF_LRW_ENC_TEST_VECTORS
3697 },
3698 .dec = {
3699 .vecs = tf_lrw_dec_tv_template,
3700 .count = TF_LRW_DEC_TEST_VECTORS
3701 }
3702 }
3703 }
3704 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003705 .alg = "lz4",
3706 .test = alg_test_comp,
3707 .fips_allowed = 1,
3708 .suite = {
3709 .comp = {
3710 .comp = {
3711 .vecs = lz4_comp_tv_template,
3712 .count = LZ4_COMP_TEST_VECTORS
3713 },
3714 .decomp = {
3715 .vecs = lz4_decomp_tv_template,
3716 .count = LZ4_DECOMP_TEST_VECTORS
3717 }
3718 }
3719 }
3720 }, {
3721 .alg = "lz4hc",
3722 .test = alg_test_comp,
3723 .fips_allowed = 1,
3724 .suite = {
3725 .comp = {
3726 .comp = {
3727 .vecs = lz4hc_comp_tv_template,
3728 .count = LZ4HC_COMP_TEST_VECTORS
3729 },
3730 .decomp = {
3731 .vecs = lz4hc_decomp_tv_template,
3732 .count = LZ4HC_DECOMP_TEST_VECTORS
3733 }
3734 }
3735 }
3736 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003737 .alg = "lzo",
3738 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003739 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003740 .suite = {
3741 .comp = {
3742 .comp = {
3743 .vecs = lzo_comp_tv_template,
3744 .count = LZO_COMP_TEST_VECTORS
3745 },
3746 .decomp = {
3747 .vecs = lzo_decomp_tv_template,
3748 .count = LZO_DECOMP_TEST_VECTORS
3749 }
3750 }
3751 }
3752 }, {
3753 .alg = "md4",
3754 .test = alg_test_hash,
3755 .suite = {
3756 .hash = {
3757 .vecs = md4_tv_template,
3758 .count = MD4_TEST_VECTORS
3759 }
3760 }
3761 }, {
3762 .alg = "md5",
3763 .test = alg_test_hash,
3764 .suite = {
3765 .hash = {
3766 .vecs = md5_tv_template,
3767 .count = MD5_TEST_VECTORS
3768 }
3769 }
3770 }, {
3771 .alg = "michael_mic",
3772 .test = alg_test_hash,
3773 .suite = {
3774 .hash = {
3775 .vecs = michael_mic_tv_template,
3776 .count = MICHAEL_MIC_TEST_VECTORS
3777 }
3778 }
3779 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003780 .alg = "ofb(aes)",
3781 .test = alg_test_skcipher,
3782 .fips_allowed = 1,
3783 .suite = {
3784 .cipher = {
3785 .enc = {
3786 .vecs = aes_ofb_enc_tv_template,
3787 .count = AES_OFB_ENC_TEST_VECTORS
3788 },
3789 .dec = {
3790 .vecs = aes_ofb_dec_tv_template,
3791 .count = AES_OFB_DEC_TEST_VECTORS
3792 }
3793 }
3794 }
3795 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003796 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003797 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003798 .suite = {
3799 .cipher = {
3800 .enc = {
3801 .vecs = fcrypt_pcbc_enc_tv_template,
3802 .count = FCRYPT_ENC_TEST_VECTORS
3803 },
3804 .dec = {
3805 .vecs = fcrypt_pcbc_dec_tv_template,
3806 .count = FCRYPT_DEC_TEST_VECTORS
3807 }
3808 }
3809 }
3810 }, {
Martin Willieee9dc62015-06-01 13:43:59 +02003811 .alg = "poly1305",
3812 .test = alg_test_hash,
3813 .suite = {
3814 .hash = {
3815 .vecs = poly1305_tv_template,
3816 .count = POLY1305_TEST_VECTORS
3817 }
3818 }
3819 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003820 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003821 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003822 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003823 .suite = {
3824 .cipher = {
3825 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003826 .vecs = aes_ctr_rfc3686_enc_tv_template,
3827 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003828 },
3829 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003830 .vecs = aes_ctr_rfc3686_dec_tv_template,
3831 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003832 }
3833 }
3834 }
3835 }, {
Herbert Xu3f31a742015-07-09 07:17:34 +08003836 .alg = "rfc4106(gcm(aes))",
Adrian Hoban69435b92010-11-04 15:02:04 -04003837 .test = alg_test_aead,
Jarod Wilsondb71f29a2015-01-23 12:42:15 -05003838 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003839 .suite = {
3840 .aead = {
3841 .enc = {
3842 .vecs = aes_gcm_rfc4106_enc_tv_template,
3843 .count = AES_GCM_4106_ENC_TEST_VECTORS
3844 },
3845 .dec = {
3846 .vecs = aes_gcm_rfc4106_dec_tv_template,
3847 .count = AES_GCM_4106_DEC_TEST_VECTORS
3848 }
3849 }
3850 }
3851 }, {
Herbert Xu544c4362015-07-14 16:53:22 +08003852 .alg = "rfc4309(ccm(aes))",
Jarod Wilson5d667322009-05-04 19:23:40 +08003853 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003854 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003855 .suite = {
3856 .aead = {
3857 .enc = {
3858 .vecs = aes_ccm_rfc4309_enc_tv_template,
3859 .count = AES_CCM_4309_ENC_TEST_VECTORS
3860 },
3861 .dec = {
3862 .vecs = aes_ccm_rfc4309_dec_tv_template,
3863 .count = AES_CCM_4309_DEC_TEST_VECTORS
3864 }
3865 }
3866 }
3867 }, {
Herbert Xubb687452015-06-16 13:54:24 +08003868 .alg = "rfc4543(gcm(aes))",
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003869 .test = alg_test_aead,
3870 .suite = {
3871 .aead = {
3872 .enc = {
3873 .vecs = aes_gcm_rfc4543_enc_tv_template,
3874 .count = AES_GCM_4543_ENC_TEST_VECTORS
3875 },
3876 .dec = {
3877 .vecs = aes_gcm_rfc4543_dec_tv_template,
3878 .count = AES_GCM_4543_DEC_TEST_VECTORS
3879 },
3880 }
3881 }
3882 }, {
Martin Williaf2b76b2015-06-01 13:44:01 +02003883 .alg = "rfc7539(chacha20,poly1305)",
3884 .test = alg_test_aead,
3885 .suite = {
3886 .aead = {
3887 .enc = {
3888 .vecs = rfc7539_enc_tv_template,
3889 .count = RFC7539_ENC_TEST_VECTORS
3890 },
3891 .dec = {
3892 .vecs = rfc7539_dec_tv_template,
3893 .count = RFC7539_DEC_TEST_VECTORS
3894 },
3895 }
3896 }
3897 }, {
Martin Willi59007582015-06-01 13:44:03 +02003898 .alg = "rfc7539esp(chacha20,poly1305)",
3899 .test = alg_test_aead,
3900 .suite = {
3901 .aead = {
3902 .enc = {
3903 .vecs = rfc7539esp_enc_tv_template,
3904 .count = RFC7539ESP_ENC_TEST_VECTORS
3905 },
3906 .dec = {
3907 .vecs = rfc7539esp_dec_tv_template,
3908 .count = RFC7539ESP_DEC_TEST_VECTORS
3909 },
3910 }
3911 }
3912 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003913 .alg = "rmd128",
3914 .test = alg_test_hash,
3915 .suite = {
3916 .hash = {
3917 .vecs = rmd128_tv_template,
3918 .count = RMD128_TEST_VECTORS
3919 }
3920 }
3921 }, {
3922 .alg = "rmd160",
3923 .test = alg_test_hash,
3924 .suite = {
3925 .hash = {
3926 .vecs = rmd160_tv_template,
3927 .count = RMD160_TEST_VECTORS
3928 }
3929 }
3930 }, {
3931 .alg = "rmd256",
3932 .test = alg_test_hash,
3933 .suite = {
3934 .hash = {
3935 .vecs = rmd256_tv_template,
3936 .count = RMD256_TEST_VECTORS
3937 }
3938 }
3939 }, {
3940 .alg = "rmd320",
3941 .test = alg_test_hash,
3942 .suite = {
3943 .hash = {
3944 .vecs = rmd320_tv_template,
3945 .count = RMD320_TEST_VECTORS
3946 }
3947 }
3948 }, {
Tadeusz Struk946cc462015-06-16 10:31:06 -07003949 .alg = "rsa",
3950 .test = alg_test_akcipher,
3951 .fips_allowed = 1,
3952 .suite = {
3953 .akcipher = {
3954 .vecs = rsa_tv_template,
3955 .count = RSA_TEST_VECTORS
3956 }
3957 }
3958 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003959 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003960 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003961 .suite = {
3962 .cipher = {
3963 .enc = {
3964 .vecs = salsa20_stream_enc_tv_template,
3965 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3966 }
3967 }
3968 }
3969 }, {
3970 .alg = "sha1",
3971 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003972 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003973 .suite = {
3974 .hash = {
3975 .vecs = sha1_tv_template,
3976 .count = SHA1_TEST_VECTORS
3977 }
3978 }
3979 }, {
3980 .alg = "sha224",
3981 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003982 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003983 .suite = {
3984 .hash = {
3985 .vecs = sha224_tv_template,
3986 .count = SHA224_TEST_VECTORS
3987 }
3988 }
3989 }, {
3990 .alg = "sha256",
3991 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003992 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003993 .suite = {
3994 .hash = {
3995 .vecs = sha256_tv_template,
3996 .count = SHA256_TEST_VECTORS
3997 }
3998 }
3999 }, {
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05304000 .alg = "sha3-224",
4001 .test = alg_test_hash,
4002 .fips_allowed = 1,
4003 .suite = {
4004 .hash = {
4005 .vecs = sha3_224_tv_template,
4006 .count = SHA3_224_TEST_VECTORS
4007 }
4008 }
4009 }, {
4010 .alg = "sha3-256",
4011 .test = alg_test_hash,
4012 .fips_allowed = 1,
4013 .suite = {
4014 .hash = {
4015 .vecs = sha3_256_tv_template,
4016 .count = SHA3_256_TEST_VECTORS
4017 }
4018 }
4019 }, {
4020 .alg = "sha3-384",
4021 .test = alg_test_hash,
4022 .fips_allowed = 1,
4023 .suite = {
4024 .hash = {
4025 .vecs = sha3_384_tv_template,
4026 .count = SHA3_384_TEST_VECTORS
4027 }
4028 }
4029 }, {
4030 .alg = "sha3-512",
4031 .test = alg_test_hash,
4032 .fips_allowed = 1,
4033 .suite = {
4034 .hash = {
4035 .vecs = sha3_512_tv_template,
4036 .count = SHA3_512_TEST_VECTORS
4037 }
4038 }
4039 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004040 .alg = "sha384",
4041 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004042 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004043 .suite = {
4044 .hash = {
4045 .vecs = sha384_tv_template,
4046 .count = SHA384_TEST_VECTORS
4047 }
4048 }
4049 }, {
4050 .alg = "sha512",
4051 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004052 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004053 .suite = {
4054 .hash = {
4055 .vecs = sha512_tv_template,
4056 .count = SHA512_TEST_VECTORS
4057 }
4058 }
4059 }, {
4060 .alg = "tgr128",
4061 .test = alg_test_hash,
4062 .suite = {
4063 .hash = {
4064 .vecs = tgr128_tv_template,
4065 .count = TGR128_TEST_VECTORS
4066 }
4067 }
4068 }, {
4069 .alg = "tgr160",
4070 .test = alg_test_hash,
4071 .suite = {
4072 .hash = {
4073 .vecs = tgr160_tv_template,
4074 .count = TGR160_TEST_VECTORS
4075 }
4076 }
4077 }, {
4078 .alg = "tgr192",
4079 .test = alg_test_hash,
4080 .suite = {
4081 .hash = {
4082 .vecs = tgr192_tv_template,
4083 .count = TGR192_TEST_VECTORS
4084 }
4085 }
4086 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10004087 .alg = "vmac(aes)",
4088 .test = alg_test_hash,
4089 .suite = {
4090 .hash = {
4091 .vecs = aes_vmac128_tv_template,
4092 .count = VMAC_AES_TEST_VECTORS
4093 }
4094 }
4095 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004096 .alg = "wp256",
4097 .test = alg_test_hash,
4098 .suite = {
4099 .hash = {
4100 .vecs = wp256_tv_template,
4101 .count = WP256_TEST_VECTORS
4102 }
4103 }
4104 }, {
4105 .alg = "wp384",
4106 .test = alg_test_hash,
4107 .suite = {
4108 .hash = {
4109 .vecs = wp384_tv_template,
4110 .count = WP384_TEST_VECTORS
4111 }
4112 }
4113 }, {
4114 .alg = "wp512",
4115 .test = alg_test_hash,
4116 .suite = {
4117 .hash = {
4118 .vecs = wp512_tv_template,
4119 .count = WP512_TEST_VECTORS
4120 }
4121 }
4122 }, {
4123 .alg = "xcbc(aes)",
4124 .test = alg_test_hash,
4125 .suite = {
4126 .hash = {
4127 .vecs = aes_xcbc128_tv_template,
4128 .count = XCBC_AES_TEST_VECTORS
4129 }
4130 }
4131 }, {
4132 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004133 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11004134 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004135 .suite = {
4136 .cipher = {
4137 .enc = {
4138 .vecs = aes_xts_enc_tv_template,
4139 .count = AES_XTS_ENC_TEST_VECTORS
4140 },
4141 .dec = {
4142 .vecs = aes_xts_dec_tv_template,
4143 .count = AES_XTS_DEC_TEST_VECTORS
4144 }
4145 }
4146 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08004147 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02004148 .alg = "xts(camellia)",
4149 .test = alg_test_skcipher,
4150 .suite = {
4151 .cipher = {
4152 .enc = {
4153 .vecs = camellia_xts_enc_tv_template,
4154 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
4155 },
4156 .dec = {
4157 .vecs = camellia_xts_dec_tv_template,
4158 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
4159 }
4160 }
4161 }
4162 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02004163 .alg = "xts(cast6)",
4164 .test = alg_test_skcipher,
4165 .suite = {
4166 .cipher = {
4167 .enc = {
4168 .vecs = cast6_xts_enc_tv_template,
4169 .count = CAST6_XTS_ENC_TEST_VECTORS
4170 },
4171 .dec = {
4172 .vecs = cast6_xts_dec_tv_template,
4173 .count = CAST6_XTS_DEC_TEST_VECTORS
4174 }
4175 }
4176 }
4177 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03004178 .alg = "xts(serpent)",
4179 .test = alg_test_skcipher,
4180 .suite = {
4181 .cipher = {
4182 .enc = {
4183 .vecs = serpent_xts_enc_tv_template,
4184 .count = SERPENT_XTS_ENC_TEST_VECTORS
4185 },
4186 .dec = {
4187 .vecs = serpent_xts_dec_tv_template,
4188 .count = SERPENT_XTS_DEC_TEST_VECTORS
4189 }
4190 }
4191 }
4192 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03004193 .alg = "xts(twofish)",
4194 .test = alg_test_skcipher,
4195 .suite = {
4196 .cipher = {
4197 .enc = {
4198 .vecs = tf_xts_enc_tv_template,
4199 .count = TF_XTS_ENC_TEST_VECTORS
4200 },
4201 .dec = {
4202 .vecs = tf_xts_dec_tv_template,
4203 .count = TF_XTS_DEC_TEST_VECTORS
4204 }
4205 }
4206 }
Herbert Xuda7f0332008-07-31 17:08:25 +08004207 }
4208};
4209
Jussi Kivilinna57147582013-06-13 17:37:40 +03004210static bool alg_test_descs_checked;
4211
4212static void alg_test_descs_check_order(void)
4213{
4214 int i;
4215
4216 /* only check once */
4217 if (alg_test_descs_checked)
4218 return;
4219
4220 alg_test_descs_checked = true;
4221
4222 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
4223 int diff = strcmp(alg_test_descs[i - 1].alg,
4224 alg_test_descs[i].alg);
4225
4226 if (WARN_ON(diff > 0)) {
4227 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
4228 alg_test_descs[i - 1].alg,
4229 alg_test_descs[i].alg);
4230 }
4231
4232 if (WARN_ON(diff == 0)) {
4233 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
4234 alg_test_descs[i].alg);
4235 }
4236 }
4237}
4238
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004239static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08004240{
4241 int start = 0;
4242 int end = ARRAY_SIZE(alg_test_descs);
4243
4244 while (start < end) {
4245 int i = (start + end) / 2;
4246 int diff = strcmp(alg_test_descs[i].alg, alg);
4247
4248 if (diff > 0) {
4249 end = i;
4250 continue;
4251 }
4252
4253 if (diff < 0) {
4254 start = i + 1;
4255 continue;
4256 }
4257
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004258 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08004259 }
4260
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004261 return -1;
4262}
4263
4264int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
4265{
4266 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08004267 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08004268 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004269
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +01004270 if (!fips_enabled && notests) {
4271 printk_once(KERN_INFO "alg: self-tests disabled\n");
4272 return 0;
4273 }
4274
Jussi Kivilinna57147582013-06-13 17:37:40 +03004275 alg_test_descs_check_order();
4276
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004277 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
4278 char nalg[CRYPTO_MAX_ALG_NAME];
4279
4280 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
4281 sizeof(nalg))
4282 return -ENAMETOOLONG;
4283
4284 i = alg_find_test(nalg);
4285 if (i < 0)
4286 goto notest;
4287
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004288 if (fips_enabled && !alg_test_descs[i].fips_allowed)
4289 goto non_fips_alg;
4290
Jarod Wilson941fb322009-05-04 19:49:23 +08004291 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
4292 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004293 }
4294
4295 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08004296 j = alg_find_test(driver);
4297 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004298 goto notest;
4299
Herbert Xua68f6612009-07-02 16:32:12 +08004300 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
4301 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004302 goto non_fips_alg;
4303
Herbert Xua68f6612009-07-02 16:32:12 +08004304 rc = 0;
4305 if (i >= 0)
4306 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
4307 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03004308 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08004309 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
4310 type, mask);
4311
Jarod Wilson941fb322009-05-04 19:49:23 +08004312test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08004313 if (fips_enabled && rc)
4314 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
4315
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004316 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09004317 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004318
Neil Hormand12d6b62008-10-12 20:36:51 +08004319 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004320
4321notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08004322 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
4323 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004324non_fips_alg:
4325 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08004326}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004327
Herbert Xu326a6342010-08-06 09:40:28 +08004328#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004329
Herbert Xuda7f0332008-07-31 17:08:25 +08004330EXPORT_SYMBOL_GPL(alg_test);