blob: 7fe4225b5513dcfeaffc7b7533c54edd613d4c05 [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
23#include <crypto/hash.h>
24#include <linux/err.h>
25#include <linux/module.h>
26#include <linux/scatterlist.h>
27#include <linux/slab.h>
28#include <linux/string.h>
Jarod Wilson7647d6c2009-05-04 19:44:50 +080029#include <crypto/rng.h>
Stephan Mueller64d1cdf2014-05-31 17:25:36 +020030#include <crypto/drbg.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080031
32#include "internal.h"
Alexander Shishkin0b767f92010-06-03 20:53:43 +100033
Herbert Xu326a6342010-08-06 09:40:28 +080034#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
Alexander Shishkin0b767f92010-06-03 20:53:43 +100035
36/* a perfect nop */
37int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
38{
39 return 0;
40}
41
42#else
43
Herbert Xuda7f0332008-07-31 17:08:25 +080044#include "testmgr.h"
45
46/*
47 * Need slab memory for testing (size in number of pages).
48 */
49#define XBUFSIZE 8
50
51/*
52 * Indexes into the xbuf to simulate cross-page access.
53 */
54#define IDX1 32
55#define IDX2 32400
56#define IDX3 1
57#define IDX4 8193
58#define IDX5 22222
59#define IDX6 17101
60#define IDX7 27333
61#define IDX8 3000
62
63/*
64* Used by test_cipher()
65*/
66#define ENCRYPT 1
67#define DECRYPT 0
68
69struct tcrypt_result {
70 struct completion completion;
71 int err;
72};
73
74struct aead_test_suite {
75 struct {
76 struct aead_testvec *vecs;
77 unsigned int count;
78 } enc, dec;
79};
80
81struct cipher_test_suite {
82 struct {
83 struct cipher_testvec *vecs;
84 unsigned int count;
85 } enc, dec;
86};
87
88struct comp_test_suite {
89 struct {
90 struct comp_testvec *vecs;
91 unsigned int count;
92 } comp, decomp;
93};
94
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +080095struct pcomp_test_suite {
96 struct {
97 struct pcomp_testvec *vecs;
98 unsigned int count;
99 } comp, decomp;
100};
101
Herbert Xuda7f0332008-07-31 17:08:25 +0800102struct hash_test_suite {
103 struct hash_testvec *vecs;
104 unsigned int count;
105};
106
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800107struct cprng_test_suite {
108 struct cprng_testvec *vecs;
109 unsigned int count;
110};
111
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200112struct drbg_test_suite {
113 struct drbg_testvec *vecs;
114 unsigned int count;
115};
116
Herbert Xuda7f0332008-07-31 17:08:25 +0800117struct alg_test_desc {
118 const char *alg;
119 int (*test)(const struct alg_test_desc *desc, const char *driver,
120 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000121 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800122
123 union {
124 struct aead_test_suite aead;
125 struct cipher_test_suite cipher;
126 struct comp_test_suite comp;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +0800127 struct pcomp_test_suite pcomp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800128 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800129 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200130 struct drbg_test_suite drbg;
Herbert Xuda7f0332008-07-31 17:08:25 +0800131 } suite;
132};
133
134static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
135
Herbert Xuda7f0332008-07-31 17:08:25 +0800136static void hexdump(unsigned char *buf, unsigned int len)
137{
138 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
139 16, 1,
140 buf, len, false);
141}
142
143static void tcrypt_complete(struct crypto_async_request *req, int err)
144{
145 struct tcrypt_result *res = req->data;
146
147 if (err == -EINPROGRESS)
148 return;
149
150 res->err = err;
151 complete(&res->completion);
152}
153
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800154static int testmgr_alloc_buf(char *buf[XBUFSIZE])
155{
156 int i;
157
158 for (i = 0; i < XBUFSIZE; i++) {
159 buf[i] = (void *)__get_free_page(GFP_KERNEL);
160 if (!buf[i])
161 goto err_free_buf;
162 }
163
164 return 0;
165
166err_free_buf:
167 while (i-- > 0)
168 free_page((unsigned long)buf[i]);
169
170 return -ENOMEM;
171}
172
173static void testmgr_free_buf(char *buf[XBUFSIZE])
174{
175 int i;
176
177 for (i = 0; i < XBUFSIZE; i++)
178 free_page((unsigned long)buf[i]);
179}
180
David S. Millera8f1a052010-05-19 14:12:03 +1000181static int do_one_async_hash_op(struct ahash_request *req,
182 struct tcrypt_result *tr,
183 int ret)
184{
185 if (ret == -EINPROGRESS || ret == -EBUSY) {
186 ret = wait_for_completion_interruptible(&tr->completion);
187 if (!ret)
188 ret = tr->err;
Wolfram Sang16735d02013-11-14 14:32:02 -0800189 reinit_completion(&tr->completion);
David S. Millera8f1a052010-05-19 14:12:03 +1000190 }
191 return ret;
192}
193
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300194static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
195 unsigned int tcount, bool use_digest,
196 const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800197{
198 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
199 unsigned int i, j, k, temp;
200 struct scatterlist sg[8];
Horia Geanta29b77e52014-07-23 11:59:38 +0300201 char *result;
202 char *key;
Herbert Xuda7f0332008-07-31 17:08:25 +0800203 struct ahash_request *req;
204 struct tcrypt_result tresult;
Herbert Xuda7f0332008-07-31 17:08:25 +0800205 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800206 char *xbuf[XBUFSIZE];
207 int ret = -ENOMEM;
208
Horia Geanta29b77e52014-07-23 11:59:38 +0300209 result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
210 if (!result)
211 return ret;
212 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
213 if (!key)
214 goto out_nobuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800215 if (testmgr_alloc_buf(xbuf))
216 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800217
218 init_completion(&tresult.completion);
219
220 req = ahash_request_alloc(tfm, GFP_KERNEL);
221 if (!req) {
222 printk(KERN_ERR "alg: hash: Failed to allocate request for "
223 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800224 goto out_noreq;
225 }
226 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
227 tcrypt_complete, &tresult);
228
Herbert Xua0cfae52009-05-29 16:23:12 +1000229 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800230 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000231 if (template[i].np)
232 continue;
233
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300234 ret = -EINVAL;
235 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
236 goto out;
237
Herbert Xua0cfae52009-05-29 16:23:12 +1000238 j++;
Horia Geanta29b77e52014-07-23 11:59:38 +0300239 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800240
241 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300242 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800243
244 memcpy(hash_buff, template[i].plaintext, template[i].psize);
245 sg_init_one(&sg[0], hash_buff, template[i].psize);
246
247 if (template[i].ksize) {
248 crypto_ahash_clear_flags(tfm, ~0);
Horia Geanta29b77e52014-07-23 11:59:38 +0300249 if (template[i].ksize > MAX_KEYLEN) {
250 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
251 j, algo, template[i].ksize, MAX_KEYLEN);
252 ret = -EINVAL;
253 goto out;
254 }
255 memcpy(key, template[i].key, template[i].ksize);
256 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
Herbert Xuda7f0332008-07-31 17:08:25 +0800257 if (ret) {
258 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000259 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800260 -ret);
261 goto out;
262 }
263 }
264
265 ahash_request_set_crypt(req, sg, result, template[i].psize);
David S. Millera8f1a052010-05-19 14:12:03 +1000266 if (use_digest) {
267 ret = do_one_async_hash_op(req, &tresult,
268 crypto_ahash_digest(req));
269 if (ret) {
270 pr_err("alg: hash: digest failed on test %d "
271 "for %s: ret=%d\n", j, algo, -ret);
272 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800273 }
David S. Millera8f1a052010-05-19 14:12:03 +1000274 } else {
275 ret = do_one_async_hash_op(req, &tresult,
276 crypto_ahash_init(req));
277 if (ret) {
278 pr_err("alt: hash: init failed on test %d "
279 "for %s: ret=%d\n", j, algo, -ret);
280 goto out;
281 }
282 ret = do_one_async_hash_op(req, &tresult,
283 crypto_ahash_update(req));
284 if (ret) {
285 pr_err("alt: hash: update failed on test %d "
286 "for %s: ret=%d\n", j, algo, -ret);
287 goto out;
288 }
289 ret = do_one_async_hash_op(req, &tresult,
290 crypto_ahash_final(req));
291 if (ret) {
292 pr_err("alt: hash: final failed on test %d "
293 "for %s: ret=%d\n", j, algo, -ret);
294 goto out;
295 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800296 }
297
298 if (memcmp(result, template[i].digest,
299 crypto_ahash_digestsize(tfm))) {
300 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000301 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800302 hexdump(result, crypto_ahash_digestsize(tfm));
303 ret = -EINVAL;
304 goto out;
305 }
306 }
307
308 j = 0;
309 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300310 /* alignment tests are only done with continuous buffers */
311 if (align_offset != 0)
312 break;
313
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300314 if (!template[i].np)
315 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800316
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300317 j++;
318 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800319
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300320 temp = 0;
321 sg_init_table(sg, template[i].np);
322 ret = -EINVAL;
323 for (k = 0; k < template[i].np; k++) {
324 if (WARN_ON(offset_in_page(IDX[k]) +
325 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +0800326 goto out;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300327 sg_set_buf(&sg[k],
328 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
329 offset_in_page(IDX[k]),
330 template[i].plaintext + temp,
331 template[i].tap[k]),
332 template[i].tap[k]);
333 temp += template[i].tap[k];
334 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800335
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300336 if (template[i].ksize) {
337 if (template[i].ksize > MAX_KEYLEN) {
338 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
339 j, algo, template[i].ksize, MAX_KEYLEN);
Herbert Xuda7f0332008-07-31 17:08:25 +0800340 ret = -EINVAL;
341 goto out;
342 }
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300343 crypto_ahash_clear_flags(tfm, ~0);
344 memcpy(key, template[i].key, template[i].ksize);
345 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
346
347 if (ret) {
348 printk(KERN_ERR "alg: hash: setkey "
349 "failed on chunking test %d "
350 "for %s: ret=%d\n", j, algo, -ret);
351 goto out;
352 }
353 }
354
355 ahash_request_set_crypt(req, sg, result, template[i].psize);
356 ret = crypto_ahash_digest(req);
357 switch (ret) {
358 case 0:
359 break;
360 case -EINPROGRESS:
361 case -EBUSY:
362 ret = wait_for_completion_interruptible(
363 &tresult.completion);
364 if (!ret && !(ret = tresult.err)) {
365 reinit_completion(&tresult.completion);
366 break;
367 }
368 /* fall through */
369 default:
370 printk(KERN_ERR "alg: hash: digest failed "
371 "on chunking test %d for %s: "
372 "ret=%d\n", j, algo, -ret);
373 goto out;
374 }
375
376 if (memcmp(result, template[i].digest,
377 crypto_ahash_digestsize(tfm))) {
378 printk(KERN_ERR "alg: hash: Chunking test %d "
379 "failed for %s\n", j, algo);
380 hexdump(result, crypto_ahash_digestsize(tfm));
381 ret = -EINVAL;
382 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800383 }
384 }
385
386 ret = 0;
387
388out:
389 ahash_request_free(req);
390out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800391 testmgr_free_buf(xbuf);
392out_nobuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300393 kfree(key);
394 kfree(result);
Herbert Xuda7f0332008-07-31 17:08:25 +0800395 return ret;
396}
397
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300398static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
399 unsigned int tcount, bool use_digest)
400{
401 unsigned int alignmask;
402 int ret;
403
404 ret = __test_hash(tfm, template, tcount, use_digest, 0);
405 if (ret)
406 return ret;
407
408 /* test unaligned buffers, check with one byte offset */
409 ret = __test_hash(tfm, template, tcount, use_digest, 1);
410 if (ret)
411 return ret;
412
413 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
414 if (alignmask) {
415 /* Check if alignment mask for tfm is correctly set. */
416 ret = __test_hash(tfm, template, tcount, use_digest,
417 alignmask + 1);
418 if (ret)
419 return ret;
420 }
421
422 return 0;
423}
424
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300425static int __test_aead(struct crypto_aead *tfm, int enc,
426 struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300427 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800428{
429 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
430 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800431 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800432 char *q;
433 char *key;
434 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300435 struct scatterlist *sg;
436 struct scatterlist *asg;
437 struct scatterlist *sgout;
438 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800439 struct tcrypt_result result;
440 unsigned int authsize;
441 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300442 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800443 void *assoc;
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700444 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800445 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300446 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800447 char *axbuf[XBUFSIZE];
448
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700449 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
450 if (!iv)
451 return ret;
Horia Geanta29b77e52014-07-23 11:59:38 +0300452 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
453 if (!key)
454 goto out_noxbuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800455 if (testmgr_alloc_buf(xbuf))
456 goto out_noxbuf;
457 if (testmgr_alloc_buf(axbuf))
458 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300459 if (diff_dst && testmgr_alloc_buf(xoutbuf))
460 goto out_nooutbuf;
461
462 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
463 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL);
464 if (!sg)
465 goto out_nosg;
466 asg = &sg[8];
467 sgout = &asg[8];
468
469 if (diff_dst)
470 d = "-ddst";
471 else
472 d = "";
473
Herbert Xuda7f0332008-07-31 17:08:25 +0800474 if (enc == ENCRYPT)
475 e = "encryption";
476 else
477 e = "decryption";
478
479 init_completion(&result.completion);
480
481 req = aead_request_alloc(tfm, GFP_KERNEL);
482 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300483 pr_err("alg: aead%s: Failed to allocate request for %s\n",
484 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800485 goto out;
486 }
487
488 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
489 tcrypt_complete, &result);
490
491 for (i = 0, j = 0; i < tcount; i++) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300492 if (template[i].np)
493 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800494
Cristian Stoica05b1d332014-07-28 13:11:23 +0300495 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800496
Cristian Stoica05b1d332014-07-28 13:11:23 +0300497 /* some templates have no input data but they will
498 * touch input
499 */
500 input = xbuf[0];
501 input += align_offset;
502 assoc = axbuf[0];
503
504 ret = -EINVAL;
505 if (WARN_ON(align_offset + template[i].ilen >
506 PAGE_SIZE || template[i].alen > PAGE_SIZE))
507 goto out;
508
509 memcpy(input, template[i].input, template[i].ilen);
510 memcpy(assoc, template[i].assoc, template[i].alen);
511 if (template[i].iv)
512 memcpy(iv, template[i].iv, MAX_IVLEN);
513 else
514 memset(iv, 0, MAX_IVLEN);
515
516 crypto_aead_clear_flags(tfm, ~0);
517 if (template[i].wk)
518 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
519
520 if (template[i].klen > MAX_KEYLEN) {
521 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
522 d, j, algo, template[i].klen,
523 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +1000524 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300525 goto out;
526 }
527 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +1000528
Cristian Stoica05b1d332014-07-28 13:11:23 +0300529 ret = crypto_aead_setkey(tfm, key, template[i].klen);
530 if (!ret == template[i].fail) {
531 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
532 d, j, algo, crypto_aead_get_flags(tfm));
533 goto out;
534 } else if (ret)
535 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800536
Cristian Stoica05b1d332014-07-28 13:11:23 +0300537 authsize = abs(template[i].rlen - template[i].ilen);
538 ret = crypto_aead_setauthsize(tfm, authsize);
539 if (ret) {
540 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
541 d, authsize, j, algo);
542 goto out;
543 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800544
Cristian Stoica05b1d332014-07-28 13:11:23 +0300545 if (diff_dst) {
546 output = xoutbuf[0];
547 output += align_offset;
548 sg_init_one(&sg[0], input, template[i].ilen);
549 sg_init_one(&sgout[0], output, template[i].rlen);
550 } else {
551 sg_init_one(&sg[0], input,
552 template[i].ilen + (enc ? authsize : 0));
553 output = input;
554 }
555
556 sg_init_one(&asg[0], assoc, template[i].alen);
557
558 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
559 template[i].ilen, iv);
560
561 aead_request_set_assoc(req, asg, template[i].alen);
562
563 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
564
565 switch (ret) {
566 case 0:
567 if (template[i].novrfy) {
568 /* verification was supposed to fail */
569 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
570 d, e, j, algo);
571 /* so really, we got a bad message */
572 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +0300573 goto out;
574 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300575 break;
576 case -EINPROGRESS:
577 case -EBUSY:
578 ret = wait_for_completion_interruptible(
579 &result.completion);
580 if (!ret && !(ret = result.err)) {
581 reinit_completion(&result.completion);
Herbert Xuda7f0332008-07-31 17:08:25 +0800582 break;
Herbert Xuda7f0332008-07-31 17:08:25 +0800583 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300584 case -EBADMSG:
585 if (template[i].novrfy)
586 /* verification failure was expected */
587 continue;
588 /* fall through */
589 default:
590 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
591 d, e, j, algo, -ret);
592 goto out;
593 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800594
Cristian Stoica05b1d332014-07-28 13:11:23 +0300595 q = output;
596 if (memcmp(q, template[i].result, template[i].rlen)) {
597 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
598 d, j, e, algo);
599 hexdump(q, template[i].rlen);
600 ret = -EINVAL;
601 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800602 }
603 }
604
605 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300606 /* alignment tests are only done with continuous buffers */
607 if (align_offset != 0)
608 break;
609
Cristian Stoica05b1d332014-07-28 13:11:23 +0300610 if (!template[i].np)
611 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800612
Cristian Stoica05b1d332014-07-28 13:11:23 +0300613 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800614
Cristian Stoica05b1d332014-07-28 13:11:23 +0300615 if (template[i].iv)
616 memcpy(iv, template[i].iv, MAX_IVLEN);
617 else
618 memset(iv, 0, MAX_IVLEN);
619
620 crypto_aead_clear_flags(tfm, ~0);
621 if (template[i].wk)
622 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
623 if (template[i].klen > MAX_KEYLEN) {
624 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
625 d, j, algo, template[i].klen, MAX_KEYLEN);
626 ret = -EINVAL;
627 goto out;
628 }
629 memcpy(key, template[i].key, template[i].klen);
630
631 ret = crypto_aead_setkey(tfm, key, template[i].klen);
632 if (!ret == template[i].fail) {
633 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
634 d, j, algo, crypto_aead_get_flags(tfm));
635 goto out;
636 } else if (ret)
637 continue;
638
639 authsize = abs(template[i].rlen - template[i].ilen);
640
641 ret = -EINVAL;
642 sg_init_table(sg, template[i].np);
643 if (diff_dst)
644 sg_init_table(sgout, template[i].np);
645 for (k = 0, temp = 0; k < template[i].np; k++) {
646 if (WARN_ON(offset_in_page(IDX[k]) +
647 template[i].tap[k] > PAGE_SIZE))
648 goto out;
649
650 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
651 memcpy(q, template[i].input + temp, template[i].tap[k]);
652 sg_set_buf(&sg[k], q, template[i].tap[k]);
653
654 if (diff_dst) {
655 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
656 offset_in_page(IDX[k]);
657
658 memset(q, 0, template[i].tap[k]);
659
660 sg_set_buf(&sgout[k], q, template[i].tap[k]);
661 }
662
663 n = template[i].tap[k];
664 if (k == template[i].np - 1 && enc)
665 n += authsize;
666 if (offset_in_page(q) + n < PAGE_SIZE)
667 q[n] = 0;
668
669 temp += template[i].tap[k];
670 }
671
672 ret = crypto_aead_setauthsize(tfm, authsize);
673 if (ret) {
674 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
675 d, authsize, j, algo);
676 goto out;
677 }
678
679 if (enc) {
680 if (WARN_ON(sg[k - 1].offset +
681 sg[k - 1].length + authsize >
682 PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300683 ret = -EINVAL;
684 goto out;
685 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800686
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300687 if (diff_dst)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300688 sgout[k - 1].length += authsize;
689 else
690 sg[k - 1].length += authsize;
691 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800692
Cristian Stoica05b1d332014-07-28 13:11:23 +0300693 sg_init_table(asg, template[i].anp);
694 ret = -EINVAL;
695 for (k = 0, temp = 0; k < template[i].anp; k++) {
696 if (WARN_ON(offset_in_page(IDX[k]) +
697 template[i].atap[k] > PAGE_SIZE))
698 goto out;
699 sg_set_buf(&asg[k],
700 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
701 offset_in_page(IDX[k]),
702 template[i].assoc + temp,
703 template[i].atap[k]),
704 template[i].atap[k]);
705 temp += template[i].atap[k];
706 }
707
708 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
709 template[i].ilen,
710 iv);
711
712 aead_request_set_assoc(req, asg, template[i].alen);
713
714 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
715
716 switch (ret) {
717 case 0:
718 if (template[i].novrfy) {
719 /* verification was supposed to fail */
720 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
721 d, e, j, algo);
722 /* so really, we got a bad message */
723 ret = -EBADMSG;
724 goto out;
725 }
726 break;
727 case -EINPROGRESS:
728 case -EBUSY:
729 ret = wait_for_completion_interruptible(
730 &result.completion);
731 if (!ret && !(ret = result.err)) {
732 reinit_completion(&result.completion);
733 break;
734 }
735 case -EBADMSG:
736 if (template[i].novrfy)
737 /* verification failure was expected */
738 continue;
739 /* fall through */
740 default:
741 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
742 d, e, j, algo, -ret);
743 goto out;
744 }
745
746 ret = -EINVAL;
747 for (k = 0, temp = 0; k < template[i].np; k++) {
748 if (diff_dst)
749 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
750 offset_in_page(IDX[k]);
751 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800752 q = xbuf[IDX[k] >> PAGE_SHIFT] +
753 offset_in_page(IDX[k]);
754
Cristian Stoica05b1d332014-07-28 13:11:23 +0300755 n = template[i].tap[k];
756 if (k == template[i].np - 1)
757 n += enc ? authsize : -authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800758
Cristian Stoica05b1d332014-07-28 13:11:23 +0300759 if (memcmp(q, template[i].result + temp, n)) {
760 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
761 d, j, e, k, algo);
762 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800763 goto out;
764 }
765
Cristian Stoica05b1d332014-07-28 13:11:23 +0300766 q += n;
767 if (k == template[i].np - 1 && !enc) {
768 if (!diff_dst &&
769 memcmp(q, template[i].input +
770 temp + n, authsize))
771 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200772 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300773 n = 0;
774 } else {
775 for (n = 0; offset_in_page(q + n) && q[n]; n++)
776 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800777 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300778 if (n) {
779 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
780 d, j, e, k, algo, n);
781 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800782 goto out;
783 }
784
Cristian Stoica05b1d332014-07-28 13:11:23 +0300785 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800786 }
787 }
788
789 ret = 0;
790
791out:
792 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300793 kfree(sg);
794out_nosg:
795 if (diff_dst)
796 testmgr_free_buf(xoutbuf);
797out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800798 testmgr_free_buf(axbuf);
799out_noaxbuf:
800 testmgr_free_buf(xbuf);
801out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300802 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700803 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800804 return ret;
805}
806
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300807static int test_aead(struct crypto_aead *tfm, int enc,
808 struct aead_testvec *template, unsigned int tcount)
809{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300810 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300811 int ret;
812
813 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300814 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300815 if (ret)
816 return ret;
817
818 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300819 ret = __test_aead(tfm, enc, template, tcount, true, 0);
820 if (ret)
821 return ret;
822
823 /* test unaligned buffers, check with one byte offset */
824 ret = __test_aead(tfm, enc, template, tcount, true, 1);
825 if (ret)
826 return ret;
827
828 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
829 if (alignmask) {
830 /* Check if alignment mask for tfm is correctly set. */
831 ret = __test_aead(tfm, enc, template, tcount, true,
832 alignmask + 1);
833 if (ret)
834 return ret;
835 }
836
837 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300838}
839
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000840static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800841 struct cipher_testvec *template, unsigned int tcount)
842{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000843 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
844 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000845 char *q;
846 const char *e;
847 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800848 char *xbuf[XBUFSIZE];
849 int ret = -ENOMEM;
850
851 if (testmgr_alloc_buf(xbuf))
852 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000853
854 if (enc == ENCRYPT)
855 e = "encryption";
856 else
857 e = "decryption";
858
859 j = 0;
860 for (i = 0; i < tcount; i++) {
861 if (template[i].np)
862 continue;
863
864 j++;
865
Herbert Xufd57f222009-05-29 16:05:42 +1000866 ret = -EINVAL;
867 if (WARN_ON(template[i].ilen > PAGE_SIZE))
868 goto out;
869
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000870 data = xbuf[0];
871 memcpy(data, template[i].input, template[i].ilen);
872
873 crypto_cipher_clear_flags(tfm, ~0);
874 if (template[i].wk)
875 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
876
877 ret = crypto_cipher_setkey(tfm, template[i].key,
878 template[i].klen);
879 if (!ret == template[i].fail) {
880 printk(KERN_ERR "alg: cipher: setkey failed "
881 "on test %d for %s: flags=%x\n", j,
882 algo, crypto_cipher_get_flags(tfm));
883 goto out;
884 } else if (ret)
885 continue;
886
887 for (k = 0; k < template[i].ilen;
888 k += crypto_cipher_blocksize(tfm)) {
889 if (enc)
890 crypto_cipher_encrypt_one(tfm, data + k,
891 data + k);
892 else
893 crypto_cipher_decrypt_one(tfm, data + k,
894 data + k);
895 }
896
897 q = data;
898 if (memcmp(q, template[i].result, template[i].rlen)) {
899 printk(KERN_ERR "alg: cipher: Test %d failed "
900 "on %s for %s\n", j, e, algo);
901 hexdump(q, template[i].rlen);
902 ret = -EINVAL;
903 goto out;
904 }
905 }
906
907 ret = 0;
908
909out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800910 testmgr_free_buf(xbuf);
911out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000912 return ret;
913}
914
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300915static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
916 struct cipher_testvec *template, unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300917 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000918{
Herbert Xuda7f0332008-07-31 17:08:25 +0800919 const char *algo =
920 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
921 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800922 char *q;
923 struct ablkcipher_request *req;
924 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300925 struct scatterlist sgout[8];
926 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800927 struct tcrypt_result result;
928 void *data;
929 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800930 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300931 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800932 int ret = -ENOMEM;
933
934 if (testmgr_alloc_buf(xbuf))
935 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800936
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300937 if (diff_dst && testmgr_alloc_buf(xoutbuf))
938 goto out_nooutbuf;
939
940 if (diff_dst)
941 d = "-ddst";
942 else
943 d = "";
944
Herbert Xuda7f0332008-07-31 17:08:25 +0800945 if (enc == ENCRYPT)
946 e = "encryption";
947 else
948 e = "decryption";
949
950 init_completion(&result.completion);
951
952 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
953 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300954 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
955 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800956 goto out;
957 }
958
959 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
960 tcrypt_complete, &result);
961
962 j = 0;
963 for (i = 0; i < tcount; i++) {
964 if (template[i].iv)
965 memcpy(iv, template[i].iv, MAX_IVLEN);
966 else
967 memset(iv, 0, MAX_IVLEN);
968
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300969 if (template[i].np && !template[i].also_non_np)
970 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800971
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300972 j++;
Herbert Xufd57f222009-05-29 16:05:42 +1000973
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300974 ret = -EINVAL;
975 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
976 goto out;
977
978 data = xbuf[0];
979 data += align_offset;
980 memcpy(data, template[i].input, template[i].ilen);
981
982 crypto_ablkcipher_clear_flags(tfm, ~0);
983 if (template[i].wk)
984 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
985
986 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
987 template[i].klen);
988 if (!ret == template[i].fail) {
989 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
990 d, j, algo, crypto_ablkcipher_get_flags(tfm));
991 goto out;
992 } else if (ret)
993 continue;
994
995 sg_init_one(&sg[0], data, template[i].ilen);
996 if (diff_dst) {
997 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300998 data += align_offset;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300999 sg_init_one(&sgout[0], data, template[i].ilen);
1000 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001001
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001002 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1003 template[i].ilen, iv);
1004 ret = enc ? crypto_ablkcipher_encrypt(req) :
1005 crypto_ablkcipher_decrypt(req);
Herbert Xuda7f0332008-07-31 17:08:25 +08001006
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001007 switch (ret) {
1008 case 0:
1009 break;
1010 case -EINPROGRESS:
1011 case -EBUSY:
1012 ret = wait_for_completion_interruptible(
1013 &result.completion);
1014 if (!ret && !((ret = result.err))) {
1015 reinit_completion(&result.completion);
Herbert Xuda7f0332008-07-31 17:08:25 +08001016 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001017 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001018 /* fall through */
1019 default:
1020 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1021 d, e, j, algo, -ret);
1022 goto out;
1023 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001024
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001025 q = data;
1026 if (memcmp(q, template[i].result, template[i].rlen)) {
1027 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1028 d, j, e, algo);
1029 hexdump(q, template[i].rlen);
1030 ret = -EINVAL;
1031 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001032 }
1033 }
1034
1035 j = 0;
1036 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001037 /* alignment tests are only done with continuous buffers */
1038 if (align_offset != 0)
1039 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001040
1041 if (template[i].iv)
1042 memcpy(iv, template[i].iv, MAX_IVLEN);
1043 else
1044 memset(iv, 0, MAX_IVLEN);
1045
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001046 if (!template[i].np)
1047 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +08001048
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001049 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +08001050
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001051 crypto_ablkcipher_clear_flags(tfm, ~0);
1052 if (template[i].wk)
1053 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1054
1055 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1056 template[i].klen);
1057 if (!ret == template[i].fail) {
1058 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1059 d, j, algo, crypto_ablkcipher_get_flags(tfm));
1060 goto out;
1061 } else if (ret)
1062 continue;
1063
1064 temp = 0;
1065 ret = -EINVAL;
1066 sg_init_table(sg, template[i].np);
1067 if (diff_dst)
1068 sg_init_table(sgout, template[i].np);
1069 for (k = 0; k < template[i].np; k++) {
1070 if (WARN_ON(offset_in_page(IDX[k]) +
1071 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001072 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001073
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001074 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1075
1076 memcpy(q, template[i].input + temp, template[i].tap[k]);
1077
1078 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1079 q[template[i].tap[k]] = 0;
1080
1081 sg_set_buf(&sg[k], q, template[i].tap[k]);
1082 if (diff_dst) {
1083 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1084 offset_in_page(IDX[k]);
1085
1086 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1087
1088 memset(q, 0, template[i].tap[k]);
1089 if (offset_in_page(q) +
1090 template[i].tap[k] < PAGE_SIZE)
1091 q[template[i].tap[k]] = 0;
1092 }
1093
1094 temp += template[i].tap[k];
1095 }
1096
1097 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1098 template[i].ilen, iv);
1099
1100 ret = enc ? crypto_ablkcipher_encrypt(req) :
1101 crypto_ablkcipher_decrypt(req);
1102
1103 switch (ret) {
1104 case 0:
1105 break;
1106 case -EINPROGRESS:
1107 case -EBUSY:
1108 ret = wait_for_completion_interruptible(
1109 &result.completion);
1110 if (!ret && !((ret = result.err))) {
1111 reinit_completion(&result.completion);
1112 break;
1113 }
1114 /* fall through */
1115 default:
1116 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1117 d, e, j, algo, -ret);
1118 goto out;
1119 }
1120
1121 temp = 0;
1122 ret = -EINVAL;
1123 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001124 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001125 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1126 offset_in_page(IDX[k]);
1127 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001128 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1129 offset_in_page(IDX[k]);
1130
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001131 if (memcmp(q, template[i].result + temp,
1132 template[i].tap[k])) {
1133 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1134 d, j, e, k, algo);
1135 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001136 goto out;
1137 }
1138
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001139 q += template[i].tap[k];
1140 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1141 ;
1142 if (n) {
1143 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1144 d, j, e, k, algo, n);
1145 hexdump(q, n);
1146 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001147 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001148 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001149 }
1150 }
1151
1152 ret = 0;
1153
1154out:
1155 ablkcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001156 if (diff_dst)
1157 testmgr_free_buf(xoutbuf);
1158out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001159 testmgr_free_buf(xbuf);
1160out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001161 return ret;
1162}
1163
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001164static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1165 struct cipher_testvec *template, unsigned int tcount)
1166{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001167 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001168 int ret;
1169
1170 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001171 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001172 if (ret)
1173 return ret;
1174
1175 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001176 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1177 if (ret)
1178 return ret;
1179
1180 /* test unaligned buffers, check with one byte offset */
1181 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1182 if (ret)
1183 return ret;
1184
1185 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1186 if (alignmask) {
1187 /* Check if alignment mask for tfm is correctly set. */
1188 ret = __test_skcipher(tfm, enc, template, tcount, true,
1189 alignmask + 1);
1190 if (ret)
1191 return ret;
1192 }
1193
1194 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001195}
1196
Herbert Xuda7f0332008-07-31 17:08:25 +08001197static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1198 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1199{
1200 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1201 unsigned int i;
1202 char result[COMP_BUF_SIZE];
1203 int ret;
1204
1205 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001206 int ilen;
1207 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001208
1209 memset(result, 0, sizeof (result));
1210
1211 ilen = ctemplate[i].inlen;
1212 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1213 ilen, result, &dlen);
1214 if (ret) {
1215 printk(KERN_ERR "alg: comp: compression failed "
1216 "on test %d for %s: ret=%d\n", i + 1, algo,
1217 -ret);
1218 goto out;
1219 }
1220
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001221 if (dlen != ctemplate[i].outlen) {
1222 printk(KERN_ERR "alg: comp: Compression test %d "
1223 "failed for %s: output len = %d\n", i + 1, algo,
1224 dlen);
1225 ret = -EINVAL;
1226 goto out;
1227 }
1228
Herbert Xuda7f0332008-07-31 17:08:25 +08001229 if (memcmp(result, ctemplate[i].output, dlen)) {
1230 printk(KERN_ERR "alg: comp: Compression test %d "
1231 "failed for %s\n", i + 1, algo);
1232 hexdump(result, dlen);
1233 ret = -EINVAL;
1234 goto out;
1235 }
1236 }
1237
1238 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001239 int ilen;
1240 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001241
1242 memset(result, 0, sizeof (result));
1243
1244 ilen = dtemplate[i].inlen;
1245 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1246 ilen, result, &dlen);
1247 if (ret) {
1248 printk(KERN_ERR "alg: comp: decompression failed "
1249 "on test %d for %s: ret=%d\n", i + 1, algo,
1250 -ret);
1251 goto out;
1252 }
1253
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001254 if (dlen != dtemplate[i].outlen) {
1255 printk(KERN_ERR "alg: comp: Decompression test %d "
1256 "failed for %s: output len = %d\n", i + 1, algo,
1257 dlen);
1258 ret = -EINVAL;
1259 goto out;
1260 }
1261
Herbert Xuda7f0332008-07-31 17:08:25 +08001262 if (memcmp(result, dtemplate[i].output, dlen)) {
1263 printk(KERN_ERR "alg: comp: Decompression test %d "
1264 "failed for %s\n", i + 1, algo);
1265 hexdump(result, dlen);
1266 ret = -EINVAL;
1267 goto out;
1268 }
1269 }
1270
1271 ret = 0;
1272
1273out:
1274 return ret;
1275}
1276
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001277static int test_pcomp(struct crypto_pcomp *tfm,
1278 struct pcomp_testvec *ctemplate,
1279 struct pcomp_testvec *dtemplate, int ctcount,
1280 int dtcount)
1281{
1282 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1283 unsigned int i;
1284 char result[COMP_BUF_SIZE];
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001285 int res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001286
1287 for (i = 0; i < ctcount; i++) {
1288 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001289 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001290
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001291 res = crypto_compress_setup(tfm, ctemplate[i].params,
1292 ctemplate[i].paramsize);
1293 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001294 pr_err("alg: pcomp: compression setup failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001295 "%d for %s: error=%d\n", i + 1, algo, res);
1296 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001297 }
1298
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001299 res = crypto_compress_init(tfm);
1300 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001301 pr_err("alg: pcomp: compression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001302 "%d for %s: error=%d\n", i + 1, algo, res);
1303 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001304 }
1305
1306 memset(result, 0, sizeof(result));
1307
1308 req.next_in = ctemplate[i].input;
1309 req.avail_in = ctemplate[i].inlen / 2;
1310 req.next_out = result;
1311 req.avail_out = ctemplate[i].outlen / 2;
1312
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001313 res = crypto_compress_update(tfm, &req);
1314 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001315 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001316 "%d for %s: error=%d\n", i + 1, algo, res);
1317 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001318 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001319 if (res > 0)
1320 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001321
1322 /* Add remaining input data */
1323 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1324
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001325 res = crypto_compress_update(tfm, &req);
1326 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001327 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001328 "%d for %s: error=%d\n", i + 1, algo, res);
1329 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001330 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001331 if (res > 0)
1332 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001333
1334 /* Provide remaining output space */
1335 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1336
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001337 res = crypto_compress_final(tfm, &req);
1338 if (res < 0) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001339 pr_err("alg: pcomp: compression final failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001340 "%d for %s: error=%d\n", i + 1, algo, res);
1341 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001342 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001343 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001344
1345 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1346 pr_err("alg: comp: Compression test %d failed for %s: "
1347 "output len = %d (expected %d)\n", i + 1, algo,
1348 COMP_BUF_SIZE - req.avail_out,
1349 ctemplate[i].outlen);
1350 return -EINVAL;
1351 }
1352
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001353 if (produced != ctemplate[i].outlen) {
1354 pr_err("alg: comp: Compression test %d failed for %s: "
1355 "returned len = %u (expected %d)\n", i + 1,
1356 algo, produced, ctemplate[i].outlen);
1357 return -EINVAL;
1358 }
1359
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001360 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1361 pr_err("alg: pcomp: Compression test %d failed for "
1362 "%s\n", i + 1, algo);
1363 hexdump(result, ctemplate[i].outlen);
1364 return -EINVAL;
1365 }
1366 }
1367
1368 for (i = 0; i < dtcount; i++) {
1369 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001370 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001371
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001372 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1373 dtemplate[i].paramsize);
1374 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001375 pr_err("alg: pcomp: decompression setup failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001376 "test %d for %s: error=%d\n", i + 1, algo, res);
1377 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001378 }
1379
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001380 res = crypto_decompress_init(tfm);
1381 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001382 pr_err("alg: pcomp: decompression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001383 "%d for %s: error=%d\n", i + 1, algo, res);
1384 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001385 }
1386
1387 memset(result, 0, sizeof(result));
1388
1389 req.next_in = dtemplate[i].input;
1390 req.avail_in = dtemplate[i].inlen / 2;
1391 req.next_out = result;
1392 req.avail_out = dtemplate[i].outlen / 2;
1393
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001394 res = crypto_decompress_update(tfm, &req);
1395 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001396 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001397 "test %d for %s: error=%d\n", i + 1, algo, res);
1398 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001399 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001400 if (res > 0)
1401 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001402
1403 /* Add remaining input data */
1404 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1405
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001406 res = crypto_decompress_update(tfm, &req);
1407 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001408 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001409 "test %d for %s: error=%d\n", i + 1, algo, res);
1410 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001411 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001412 if (res > 0)
1413 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001414
1415 /* Provide remaining output space */
1416 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1417
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001418 res = crypto_decompress_final(tfm, &req);
1419 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001420 pr_err("alg: pcomp: decompression final failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001421 "test %d for %s: error=%d\n", i + 1, algo, res);
1422 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001423 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001424 if (res > 0)
1425 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001426
1427 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1428 pr_err("alg: comp: Decompression test %d failed for "
1429 "%s: output len = %d (expected %d)\n", i + 1,
1430 algo, COMP_BUF_SIZE - req.avail_out,
1431 dtemplate[i].outlen);
1432 return -EINVAL;
1433 }
1434
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001435 if (produced != dtemplate[i].outlen) {
1436 pr_err("alg: comp: Decompression test %d failed for "
1437 "%s: returned len = %u (expected %d)\n", i + 1,
1438 algo, produced, dtemplate[i].outlen);
1439 return -EINVAL;
1440 }
1441
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001442 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1443 pr_err("alg: pcomp: Decompression test %d failed for "
1444 "%s\n", i + 1, algo);
1445 hexdump(result, dtemplate[i].outlen);
1446 return -EINVAL;
1447 }
1448 }
1449
1450 return 0;
1451}
1452
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001453
1454static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1455 unsigned int tcount)
1456{
1457 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001458 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001459 u8 *seed;
1460 char result[32];
1461
1462 seedsize = crypto_rng_seedsize(tfm);
1463
1464 seed = kmalloc(seedsize, GFP_KERNEL);
1465 if (!seed) {
1466 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1467 "for %s\n", algo);
1468 return -ENOMEM;
1469 }
1470
1471 for (i = 0; i < tcount; i++) {
1472 memset(result, 0, 32);
1473
1474 memcpy(seed, template[i].v, template[i].vlen);
1475 memcpy(seed + template[i].vlen, template[i].key,
1476 template[i].klen);
1477 memcpy(seed + template[i].vlen + template[i].klen,
1478 template[i].dt, template[i].dtlen);
1479
1480 err = crypto_rng_reset(tfm, seed, seedsize);
1481 if (err) {
1482 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1483 "for %s\n", algo);
1484 goto out;
1485 }
1486
1487 for (j = 0; j < template[i].loops; j++) {
1488 err = crypto_rng_get_bytes(tfm, result,
1489 template[i].rlen);
1490 if (err != template[i].rlen) {
1491 printk(KERN_ERR "alg: cprng: Failed to obtain "
1492 "the correct amount of random data for "
1493 "%s (requested %d, got %d)\n", algo,
1494 template[i].rlen, err);
1495 goto out;
1496 }
1497 }
1498
1499 err = memcmp(result, template[i].result,
1500 template[i].rlen);
1501 if (err) {
1502 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1503 i, algo);
1504 hexdump(result, template[i].rlen);
1505 err = -EINVAL;
1506 goto out;
1507 }
1508 }
1509
1510out:
1511 kfree(seed);
1512 return err;
1513}
1514
Herbert Xuda7f0332008-07-31 17:08:25 +08001515static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1516 u32 type, u32 mask)
1517{
1518 struct crypto_aead *tfm;
1519 int err = 0;
1520
1521 tfm = crypto_alloc_aead(driver, type, mask);
1522 if (IS_ERR(tfm)) {
1523 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1524 "%ld\n", driver, PTR_ERR(tfm));
1525 return PTR_ERR(tfm);
1526 }
1527
1528 if (desc->suite.aead.enc.vecs) {
1529 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1530 desc->suite.aead.enc.count);
1531 if (err)
1532 goto out;
1533 }
1534
1535 if (!err && desc->suite.aead.dec.vecs)
1536 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1537 desc->suite.aead.dec.count);
1538
1539out:
1540 crypto_free_aead(tfm);
1541 return err;
1542}
1543
1544static int alg_test_cipher(const struct alg_test_desc *desc,
1545 const char *driver, u32 type, u32 mask)
1546{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001547 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001548 int err = 0;
1549
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001550 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001551 if (IS_ERR(tfm)) {
1552 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1553 "%s: %ld\n", driver, PTR_ERR(tfm));
1554 return PTR_ERR(tfm);
1555 }
1556
1557 if (desc->suite.cipher.enc.vecs) {
1558 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1559 desc->suite.cipher.enc.count);
1560 if (err)
1561 goto out;
1562 }
1563
1564 if (desc->suite.cipher.dec.vecs)
1565 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1566 desc->suite.cipher.dec.count);
1567
1568out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001569 crypto_free_cipher(tfm);
1570 return err;
1571}
1572
1573static int alg_test_skcipher(const struct alg_test_desc *desc,
1574 const char *driver, u32 type, u32 mask)
1575{
1576 struct crypto_ablkcipher *tfm;
1577 int err = 0;
1578
1579 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1580 if (IS_ERR(tfm)) {
1581 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1582 "%s: %ld\n", driver, PTR_ERR(tfm));
1583 return PTR_ERR(tfm);
1584 }
1585
1586 if (desc->suite.cipher.enc.vecs) {
1587 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1588 desc->suite.cipher.enc.count);
1589 if (err)
1590 goto out;
1591 }
1592
1593 if (desc->suite.cipher.dec.vecs)
1594 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1595 desc->suite.cipher.dec.count);
1596
1597out:
Herbert Xuda7f0332008-07-31 17:08:25 +08001598 crypto_free_ablkcipher(tfm);
1599 return err;
1600}
1601
1602static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1603 u32 type, u32 mask)
1604{
1605 struct crypto_comp *tfm;
1606 int err;
1607
1608 tfm = crypto_alloc_comp(driver, type, mask);
1609 if (IS_ERR(tfm)) {
1610 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1611 "%ld\n", driver, PTR_ERR(tfm));
1612 return PTR_ERR(tfm);
1613 }
1614
1615 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1616 desc->suite.comp.decomp.vecs,
1617 desc->suite.comp.comp.count,
1618 desc->suite.comp.decomp.count);
1619
1620 crypto_free_comp(tfm);
1621 return err;
1622}
1623
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001624static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1625 u32 type, u32 mask)
1626{
1627 struct crypto_pcomp *tfm;
1628 int err;
1629
1630 tfm = crypto_alloc_pcomp(driver, type, mask);
1631 if (IS_ERR(tfm)) {
1632 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1633 driver, PTR_ERR(tfm));
1634 return PTR_ERR(tfm);
1635 }
1636
1637 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1638 desc->suite.pcomp.decomp.vecs,
1639 desc->suite.pcomp.comp.count,
1640 desc->suite.pcomp.decomp.count);
1641
1642 crypto_free_pcomp(tfm);
1643 return err;
1644}
1645
Herbert Xuda7f0332008-07-31 17:08:25 +08001646static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1647 u32 type, u32 mask)
1648{
1649 struct crypto_ahash *tfm;
1650 int err;
1651
1652 tfm = crypto_alloc_ahash(driver, type, mask);
1653 if (IS_ERR(tfm)) {
1654 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1655 "%ld\n", driver, PTR_ERR(tfm));
1656 return PTR_ERR(tfm);
1657 }
1658
David S. Millera8f1a052010-05-19 14:12:03 +10001659 err = test_hash(tfm, desc->suite.hash.vecs,
1660 desc->suite.hash.count, true);
1661 if (!err)
1662 err = test_hash(tfm, desc->suite.hash.vecs,
1663 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001664
1665 crypto_free_ahash(tfm);
1666 return err;
1667}
1668
Herbert Xu8e3ee852008-11-07 14:58:52 +08001669static int alg_test_crc32c(const struct alg_test_desc *desc,
1670 const char *driver, u32 type, u32 mask)
1671{
1672 struct crypto_shash *tfm;
1673 u32 val;
1674 int err;
1675
1676 err = alg_test_hash(desc, driver, type, mask);
1677 if (err)
1678 goto out;
1679
1680 tfm = crypto_alloc_shash(driver, type, mask);
1681 if (IS_ERR(tfm)) {
1682 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1683 "%ld\n", driver, PTR_ERR(tfm));
1684 err = PTR_ERR(tfm);
1685 goto out;
1686 }
1687
1688 do {
1689 struct {
1690 struct shash_desc shash;
1691 char ctx[crypto_shash_descsize(tfm)];
1692 } sdesc;
1693
1694 sdesc.shash.tfm = tfm;
1695 sdesc.shash.flags = 0;
1696
1697 *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1698 err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1699 if (err) {
1700 printk(KERN_ERR "alg: crc32c: Operation failed for "
1701 "%s: %d\n", driver, err);
1702 break;
1703 }
1704
1705 if (val != ~420553207) {
1706 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1707 "%d\n", driver, val);
1708 err = -EINVAL;
1709 }
1710 } while (0);
1711
1712 crypto_free_shash(tfm);
1713
1714out:
1715 return err;
1716}
1717
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001718static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1719 u32 type, u32 mask)
1720{
1721 struct crypto_rng *rng;
1722 int err;
1723
1724 rng = crypto_alloc_rng(driver, type, mask);
1725 if (IS_ERR(rng)) {
1726 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1727 "%ld\n", driver, PTR_ERR(rng));
1728 return PTR_ERR(rng);
1729 }
1730
1731 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1732
1733 crypto_free_rng(rng);
1734
1735 return err;
1736}
1737
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001738
1739static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1740 const char *driver, u32 type, u32 mask)
1741{
1742 int ret = -EAGAIN;
1743 struct crypto_rng *drng;
1744 struct drbg_test_data test_data;
1745 struct drbg_string addtl, pers, testentropy;
1746 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1747
1748 if (!buf)
1749 return -ENOMEM;
1750
1751 drng = crypto_alloc_rng(driver, type, mask);
1752 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001753 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001754 "%s\n", driver);
1755 kzfree(buf);
1756 return -ENOMEM;
1757 }
1758
1759 test_data.testentropy = &testentropy;
1760 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1761 drbg_string_fill(&pers, test->pers, test->perslen);
1762 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1763 if (ret) {
1764 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1765 goto outbuf;
1766 }
1767
1768 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1769 if (pr) {
1770 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1771 ret = crypto_drbg_get_bytes_addtl_test(drng,
1772 buf, test->expectedlen, &addtl, &test_data);
1773 } else {
1774 ret = crypto_drbg_get_bytes_addtl(drng,
1775 buf, test->expectedlen, &addtl);
1776 }
1777 if (ret <= 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001778 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001779 "driver %s\n", driver);
1780 goto outbuf;
1781 }
1782
1783 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1784 if (pr) {
1785 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1786 ret = crypto_drbg_get_bytes_addtl_test(drng,
1787 buf, test->expectedlen, &addtl, &test_data);
1788 } else {
1789 ret = crypto_drbg_get_bytes_addtl(drng,
1790 buf, test->expectedlen, &addtl);
1791 }
1792 if (ret <= 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001793 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001794 "driver %s\n", driver);
1795 goto outbuf;
1796 }
1797
1798 ret = memcmp(test->expected, buf, test->expectedlen);
1799
1800outbuf:
1801 crypto_free_rng(drng);
1802 kzfree(buf);
1803 return ret;
1804}
1805
1806
1807static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1808 u32 type, u32 mask)
1809{
1810 int err = 0;
1811 int pr = 0;
1812 int i = 0;
1813 struct drbg_testvec *template = desc->suite.drbg.vecs;
1814 unsigned int tcount = desc->suite.drbg.count;
1815
1816 if (0 == memcmp(driver, "drbg_pr_", 8))
1817 pr = 1;
1818
1819 for (i = 0; i < tcount; i++) {
1820 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1821 if (err) {
1822 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1823 i, driver);
1824 err = -EINVAL;
1825 break;
1826 }
1827 }
1828 return err;
1829
1830}
1831
Youquan, Song863b5572009-12-23 19:45:20 +08001832static int alg_test_null(const struct alg_test_desc *desc,
1833 const char *driver, u32 type, u32 mask)
1834{
1835 return 0;
1836}
1837
Herbert Xuda7f0332008-07-31 17:08:25 +08001838/* Please keep this list sorted by algorithm name. */
1839static const struct alg_test_desc alg_test_descs[] = {
1840 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001841 .alg = "__cbc-cast5-avx",
1842 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001843 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001844 .alg = "__cbc-cast6-avx",
1845 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001846 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001847 .alg = "__cbc-serpent-avx",
1848 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001849 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001850 .alg = "__cbc-serpent-avx2",
1851 .test = alg_test_null,
1852 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001853 .alg = "__cbc-serpent-sse2",
1854 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001855 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001856 .alg = "__cbc-twofish-avx",
1857 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001858 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001859 .alg = "__driver-cbc-aes-aesni",
1860 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001861 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001862 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001863 .alg = "__driver-cbc-camellia-aesni",
1864 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001865 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001866 .alg = "__driver-cbc-camellia-aesni-avx2",
1867 .test = alg_test_null,
1868 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001869 .alg = "__driver-cbc-cast5-avx",
1870 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001871 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001872 .alg = "__driver-cbc-cast6-avx",
1873 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001874 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001875 .alg = "__driver-cbc-serpent-avx",
1876 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001877 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001878 .alg = "__driver-cbc-serpent-avx2",
1879 .test = alg_test_null,
1880 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001881 .alg = "__driver-cbc-serpent-sse2",
1882 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001883 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001884 .alg = "__driver-cbc-twofish-avx",
1885 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001886 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001887 .alg = "__driver-ecb-aes-aesni",
1888 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001889 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001890 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001891 .alg = "__driver-ecb-camellia-aesni",
1892 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001893 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001894 .alg = "__driver-ecb-camellia-aesni-avx2",
1895 .test = alg_test_null,
1896 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001897 .alg = "__driver-ecb-cast5-avx",
1898 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001899 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001900 .alg = "__driver-ecb-cast6-avx",
1901 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001902 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001903 .alg = "__driver-ecb-serpent-avx",
1904 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001905 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001906 .alg = "__driver-ecb-serpent-avx2",
1907 .test = alg_test_null,
1908 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001909 .alg = "__driver-ecb-serpent-sse2",
1910 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001911 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001912 .alg = "__driver-ecb-twofish-avx",
1913 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001914 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001915 .alg = "__ghash-pclmulqdqni",
1916 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001917 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001918 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001919 .alg = "ansi_cprng",
1920 .test = alg_test_cprng,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001921 .fips_allowed = 1,
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001922 .suite = {
1923 .cprng = {
1924 .vecs = ansi_cprng_aes_tv_template,
1925 .count = ANSI_CPRNG_AES_TEST_VECTORS
1926 }
1927 }
1928 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001929 .alg = "authenc(hmac(md5),ecb(cipher_null))",
1930 .test = alg_test_aead,
1931 .fips_allowed = 1,
1932 .suite = {
1933 .aead = {
1934 .enc = {
1935 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
1936 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1937 },
1938 .dec = {
1939 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
1940 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1941 }
1942 }
1943 }
1944 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03001945 .alg = "authenc(hmac(sha1),cbc(aes))",
1946 .test = alg_test_aead,
1947 .fips_allowed = 1,
1948 .suite = {
1949 .aead = {
1950 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301951 .vecs =
1952 hmac_sha1_aes_cbc_enc_tv_temp,
1953 .count =
1954 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1955 }
1956 }
1957 }
1958 }, {
1959 .alg = "authenc(hmac(sha1),cbc(des))",
1960 .test = alg_test_aead,
1961 .fips_allowed = 1,
1962 .suite = {
1963 .aead = {
1964 .enc = {
1965 .vecs =
1966 hmac_sha1_des_cbc_enc_tv_temp,
1967 .count =
1968 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1969 }
1970 }
1971 }
1972 }, {
1973 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
1974 .test = alg_test_aead,
1975 .fips_allowed = 1,
1976 .suite = {
1977 .aead = {
1978 .enc = {
1979 .vecs =
1980 hmac_sha1_des3_ede_cbc_enc_tv_temp,
1981 .count =
1982 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03001983 }
1984 }
1985 }
1986 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001987 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
1988 .test = alg_test_aead,
1989 .fips_allowed = 1,
1990 .suite = {
1991 .aead = {
1992 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301993 .vecs =
1994 hmac_sha1_ecb_cipher_null_enc_tv_temp,
1995 .count =
1996 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02001997 },
1998 .dec = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301999 .vecs =
2000 hmac_sha1_ecb_cipher_null_dec_tv_temp,
2001 .count =
2002 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
2003 }
2004 }
2005 }
2006 }, {
2007 .alg = "authenc(hmac(sha224),cbc(des))",
2008 .test = alg_test_aead,
2009 .fips_allowed = 1,
2010 .suite = {
2011 .aead = {
2012 .enc = {
2013 .vecs =
2014 hmac_sha224_des_cbc_enc_tv_temp,
2015 .count =
2016 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2017 }
2018 }
2019 }
2020 }, {
2021 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
2022 .test = alg_test_aead,
2023 .fips_allowed = 1,
2024 .suite = {
2025 .aead = {
2026 .enc = {
2027 .vecs =
2028 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2029 .count =
2030 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002031 }
2032 }
2033 }
2034 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03002035 .alg = "authenc(hmac(sha256),cbc(aes))",
2036 .test = alg_test_aead,
2037 .fips_allowed = 1,
2038 .suite = {
2039 .aead = {
2040 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302041 .vecs =
2042 hmac_sha256_aes_cbc_enc_tv_temp,
2043 .count =
2044 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2045 }
2046 }
2047 }
2048 }, {
2049 .alg = "authenc(hmac(sha256),cbc(des))",
2050 .test = alg_test_aead,
2051 .fips_allowed = 1,
2052 .suite = {
2053 .aead = {
2054 .enc = {
2055 .vecs =
2056 hmac_sha256_des_cbc_enc_tv_temp,
2057 .count =
2058 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2059 }
2060 }
2061 }
2062 }, {
2063 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
2064 .test = alg_test_aead,
2065 .fips_allowed = 1,
2066 .suite = {
2067 .aead = {
2068 .enc = {
2069 .vecs =
2070 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2071 .count =
2072 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2073 }
2074 }
2075 }
2076 }, {
2077 .alg = "authenc(hmac(sha384),cbc(des))",
2078 .test = alg_test_aead,
2079 .fips_allowed = 1,
2080 .suite = {
2081 .aead = {
2082 .enc = {
2083 .vecs =
2084 hmac_sha384_des_cbc_enc_tv_temp,
2085 .count =
2086 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2087 }
2088 }
2089 }
2090 }, {
2091 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
2092 .test = alg_test_aead,
2093 .fips_allowed = 1,
2094 .suite = {
2095 .aead = {
2096 .enc = {
2097 .vecs =
2098 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2099 .count =
2100 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002101 }
2102 }
2103 }
2104 }, {
2105 .alg = "authenc(hmac(sha512),cbc(aes))",
2106 .test = alg_test_aead,
2107 .fips_allowed = 1,
2108 .suite = {
2109 .aead = {
2110 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302111 .vecs =
2112 hmac_sha512_aes_cbc_enc_tv_temp,
2113 .count =
2114 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2115 }
2116 }
2117 }
2118 }, {
2119 .alg = "authenc(hmac(sha512),cbc(des))",
2120 .test = alg_test_aead,
2121 .fips_allowed = 1,
2122 .suite = {
2123 .aead = {
2124 .enc = {
2125 .vecs =
2126 hmac_sha512_des_cbc_enc_tv_temp,
2127 .count =
2128 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2129 }
2130 }
2131 }
2132 }, {
2133 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2134 .test = alg_test_aead,
2135 .fips_allowed = 1,
2136 .suite = {
2137 .aead = {
2138 .enc = {
2139 .vecs =
2140 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2141 .count =
2142 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002143 }
2144 }
2145 }
2146 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002147 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002148 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002149 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002150 .suite = {
2151 .cipher = {
2152 .enc = {
2153 .vecs = aes_cbc_enc_tv_template,
2154 .count = AES_CBC_ENC_TEST_VECTORS
2155 },
2156 .dec = {
2157 .vecs = aes_cbc_dec_tv_template,
2158 .count = AES_CBC_DEC_TEST_VECTORS
2159 }
2160 }
2161 }
2162 }, {
2163 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002164 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002165 .suite = {
2166 .cipher = {
2167 .enc = {
2168 .vecs = anubis_cbc_enc_tv_template,
2169 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2170 },
2171 .dec = {
2172 .vecs = anubis_cbc_dec_tv_template,
2173 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2174 }
2175 }
2176 }
2177 }, {
2178 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002179 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002180 .suite = {
2181 .cipher = {
2182 .enc = {
2183 .vecs = bf_cbc_enc_tv_template,
2184 .count = BF_CBC_ENC_TEST_VECTORS
2185 },
2186 .dec = {
2187 .vecs = bf_cbc_dec_tv_template,
2188 .count = BF_CBC_DEC_TEST_VECTORS
2189 }
2190 }
2191 }
2192 }, {
2193 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002194 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002195 .suite = {
2196 .cipher = {
2197 .enc = {
2198 .vecs = camellia_cbc_enc_tv_template,
2199 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2200 },
2201 .dec = {
2202 .vecs = camellia_cbc_dec_tv_template,
2203 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2204 }
2205 }
2206 }
2207 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002208 .alg = "cbc(cast5)",
2209 .test = alg_test_skcipher,
2210 .suite = {
2211 .cipher = {
2212 .enc = {
2213 .vecs = cast5_cbc_enc_tv_template,
2214 .count = CAST5_CBC_ENC_TEST_VECTORS
2215 },
2216 .dec = {
2217 .vecs = cast5_cbc_dec_tv_template,
2218 .count = CAST5_CBC_DEC_TEST_VECTORS
2219 }
2220 }
2221 }
2222 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002223 .alg = "cbc(cast6)",
2224 .test = alg_test_skcipher,
2225 .suite = {
2226 .cipher = {
2227 .enc = {
2228 .vecs = cast6_cbc_enc_tv_template,
2229 .count = CAST6_CBC_ENC_TEST_VECTORS
2230 },
2231 .dec = {
2232 .vecs = cast6_cbc_dec_tv_template,
2233 .count = CAST6_CBC_DEC_TEST_VECTORS
2234 }
2235 }
2236 }
2237 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002238 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002239 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002240 .suite = {
2241 .cipher = {
2242 .enc = {
2243 .vecs = des_cbc_enc_tv_template,
2244 .count = DES_CBC_ENC_TEST_VECTORS
2245 },
2246 .dec = {
2247 .vecs = des_cbc_dec_tv_template,
2248 .count = DES_CBC_DEC_TEST_VECTORS
2249 }
2250 }
2251 }
2252 }, {
2253 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002254 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002255 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002256 .suite = {
2257 .cipher = {
2258 .enc = {
2259 .vecs = des3_ede_cbc_enc_tv_template,
2260 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2261 },
2262 .dec = {
2263 .vecs = des3_ede_cbc_dec_tv_template,
2264 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2265 }
2266 }
2267 }
2268 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002269 .alg = "cbc(serpent)",
2270 .test = alg_test_skcipher,
2271 .suite = {
2272 .cipher = {
2273 .enc = {
2274 .vecs = serpent_cbc_enc_tv_template,
2275 .count = SERPENT_CBC_ENC_TEST_VECTORS
2276 },
2277 .dec = {
2278 .vecs = serpent_cbc_dec_tv_template,
2279 .count = SERPENT_CBC_DEC_TEST_VECTORS
2280 }
2281 }
2282 }
2283 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002284 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002285 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002286 .suite = {
2287 .cipher = {
2288 .enc = {
2289 .vecs = tf_cbc_enc_tv_template,
2290 .count = TF_CBC_ENC_TEST_VECTORS
2291 },
2292 .dec = {
2293 .vecs = tf_cbc_dec_tv_template,
2294 .count = TF_CBC_DEC_TEST_VECTORS
2295 }
2296 }
2297 }
2298 }, {
2299 .alg = "ccm(aes)",
2300 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002301 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002302 .suite = {
2303 .aead = {
2304 .enc = {
2305 .vecs = aes_ccm_enc_tv_template,
2306 .count = AES_CCM_ENC_TEST_VECTORS
2307 },
2308 .dec = {
2309 .vecs = aes_ccm_dec_tv_template,
2310 .count = AES_CCM_DEC_TEST_VECTORS
2311 }
2312 }
2313 }
2314 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002315 .alg = "cmac(aes)",
2316 .test = alg_test_hash,
2317 .suite = {
2318 .hash = {
2319 .vecs = aes_cmac128_tv_template,
2320 .count = CMAC_AES_TEST_VECTORS
2321 }
2322 }
2323 }, {
2324 .alg = "cmac(des3_ede)",
2325 .test = alg_test_hash,
2326 .suite = {
2327 .hash = {
2328 .vecs = des3_ede_cmac64_tv_template,
2329 .count = CMAC_DES3_EDE_TEST_VECTORS
2330 }
2331 }
2332 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002333 .alg = "compress_null",
2334 .test = alg_test_null,
2335 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002336 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002337 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002338 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002339 .suite = {
2340 .hash = {
2341 .vecs = crc32c_tv_template,
2342 .count = CRC32C_TEST_VECTORS
2343 }
2344 }
2345 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002346 .alg = "crct10dif",
2347 .test = alg_test_hash,
2348 .fips_allowed = 1,
2349 .suite = {
2350 .hash = {
2351 .vecs = crct10dif_tv_template,
2352 .count = CRCT10DIF_TEST_VECTORS
2353 }
2354 }
2355 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002356 .alg = "cryptd(__driver-cbc-aes-aesni)",
2357 .test = alg_test_null,
2358 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002359 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002360 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2361 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002362 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002363 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2364 .test = alg_test_null,
2365 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002366 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2367 .test = alg_test_null,
2368 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002369 .alg = "cryptd(__driver-ecb-aes-aesni)",
2370 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002371 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002372 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002373 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2374 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002375 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002376 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2377 .test = alg_test_null,
2378 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002379 .alg = "cryptd(__driver-ecb-cast5-avx)",
2380 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002381 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002382 .alg = "cryptd(__driver-ecb-cast6-avx)",
2383 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002384 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002385 .alg = "cryptd(__driver-ecb-serpent-avx)",
2386 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002387 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002388 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2389 .test = alg_test_null,
2390 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002391 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2392 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002393 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002394 .alg = "cryptd(__driver-ecb-twofish-avx)",
2395 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002396 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002397 .alg = "cryptd(__driver-gcm-aes-aesni)",
2398 .test = alg_test_null,
2399 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002400 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002401 .alg = "cryptd(__ghash-pclmulqdqni)",
2402 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002403 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002404 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002405 .alg = "ctr(aes)",
2406 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002407 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002408 .suite = {
2409 .cipher = {
2410 .enc = {
2411 .vecs = aes_ctr_enc_tv_template,
2412 .count = AES_CTR_ENC_TEST_VECTORS
2413 },
2414 .dec = {
2415 .vecs = aes_ctr_dec_tv_template,
2416 .count = AES_CTR_DEC_TEST_VECTORS
2417 }
2418 }
2419 }
2420 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002421 .alg = "ctr(blowfish)",
2422 .test = alg_test_skcipher,
2423 .suite = {
2424 .cipher = {
2425 .enc = {
2426 .vecs = bf_ctr_enc_tv_template,
2427 .count = BF_CTR_ENC_TEST_VECTORS
2428 },
2429 .dec = {
2430 .vecs = bf_ctr_dec_tv_template,
2431 .count = BF_CTR_DEC_TEST_VECTORS
2432 }
2433 }
2434 }
2435 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002436 .alg = "ctr(camellia)",
2437 .test = alg_test_skcipher,
2438 .suite = {
2439 .cipher = {
2440 .enc = {
2441 .vecs = camellia_ctr_enc_tv_template,
2442 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2443 },
2444 .dec = {
2445 .vecs = camellia_ctr_dec_tv_template,
2446 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2447 }
2448 }
2449 }
2450 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002451 .alg = "ctr(cast5)",
2452 .test = alg_test_skcipher,
2453 .suite = {
2454 .cipher = {
2455 .enc = {
2456 .vecs = cast5_ctr_enc_tv_template,
2457 .count = CAST5_CTR_ENC_TEST_VECTORS
2458 },
2459 .dec = {
2460 .vecs = cast5_ctr_dec_tv_template,
2461 .count = CAST5_CTR_DEC_TEST_VECTORS
2462 }
2463 }
2464 }
2465 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002466 .alg = "ctr(cast6)",
2467 .test = alg_test_skcipher,
2468 .suite = {
2469 .cipher = {
2470 .enc = {
2471 .vecs = cast6_ctr_enc_tv_template,
2472 .count = CAST6_CTR_ENC_TEST_VECTORS
2473 },
2474 .dec = {
2475 .vecs = cast6_ctr_dec_tv_template,
2476 .count = CAST6_CTR_DEC_TEST_VECTORS
2477 }
2478 }
2479 }
2480 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002481 .alg = "ctr(des)",
2482 .test = alg_test_skcipher,
2483 .suite = {
2484 .cipher = {
2485 .enc = {
2486 .vecs = des_ctr_enc_tv_template,
2487 .count = DES_CTR_ENC_TEST_VECTORS
2488 },
2489 .dec = {
2490 .vecs = des_ctr_dec_tv_template,
2491 .count = DES_CTR_DEC_TEST_VECTORS
2492 }
2493 }
2494 }
2495 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002496 .alg = "ctr(des3_ede)",
2497 .test = alg_test_skcipher,
2498 .suite = {
2499 .cipher = {
2500 .enc = {
2501 .vecs = des3_ede_ctr_enc_tv_template,
2502 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2503 },
2504 .dec = {
2505 .vecs = des3_ede_ctr_dec_tv_template,
2506 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2507 }
2508 }
2509 }
2510 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002511 .alg = "ctr(serpent)",
2512 .test = alg_test_skcipher,
2513 .suite = {
2514 .cipher = {
2515 .enc = {
2516 .vecs = serpent_ctr_enc_tv_template,
2517 .count = SERPENT_CTR_ENC_TEST_VECTORS
2518 },
2519 .dec = {
2520 .vecs = serpent_ctr_dec_tv_template,
2521 .count = SERPENT_CTR_DEC_TEST_VECTORS
2522 }
2523 }
2524 }
2525 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002526 .alg = "ctr(twofish)",
2527 .test = alg_test_skcipher,
2528 .suite = {
2529 .cipher = {
2530 .enc = {
2531 .vecs = tf_ctr_enc_tv_template,
2532 .count = TF_CTR_ENC_TEST_VECTORS
2533 },
2534 .dec = {
2535 .vecs = tf_ctr_dec_tv_template,
2536 .count = TF_CTR_DEC_TEST_VECTORS
2537 }
2538 }
2539 }
2540 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002541 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002542 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002543 .suite = {
2544 .cipher = {
2545 .enc = {
2546 .vecs = cts_mode_enc_tv_template,
2547 .count = CTS_MODE_ENC_TEST_VECTORS
2548 },
2549 .dec = {
2550 .vecs = cts_mode_dec_tv_template,
2551 .count = CTS_MODE_DEC_TEST_VECTORS
2552 }
2553 }
2554 }
2555 }, {
2556 .alg = "deflate",
2557 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002558 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002559 .suite = {
2560 .comp = {
2561 .comp = {
2562 .vecs = deflate_comp_tv_template,
2563 .count = DEFLATE_COMP_TEST_VECTORS
2564 },
2565 .decomp = {
2566 .vecs = deflate_decomp_tv_template,
2567 .count = DEFLATE_DECOMP_TEST_VECTORS
2568 }
2569 }
2570 }
2571 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002572 .alg = "digest_null",
2573 .test = alg_test_null,
2574 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002575 .alg = "drbg_nopr_ctr_aes128",
2576 .test = alg_test_drbg,
2577 .fips_allowed = 1,
2578 .suite = {
2579 .drbg = {
2580 .vecs = drbg_nopr_ctr_aes128_tv_template,
2581 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2582 }
2583 }
2584 }, {
2585 .alg = "drbg_nopr_ctr_aes192",
2586 .test = alg_test_drbg,
2587 .fips_allowed = 1,
2588 .suite = {
2589 .drbg = {
2590 .vecs = drbg_nopr_ctr_aes192_tv_template,
2591 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2592 }
2593 }
2594 }, {
2595 .alg = "drbg_nopr_ctr_aes256",
2596 .test = alg_test_drbg,
2597 .fips_allowed = 1,
2598 .suite = {
2599 .drbg = {
2600 .vecs = drbg_nopr_ctr_aes256_tv_template,
2601 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2602 }
2603 }
2604 }, {
2605 /*
2606 * There is no need to specifically test the DRBG with every
2607 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2608 */
2609 .alg = "drbg_nopr_hmac_sha1",
2610 .fips_allowed = 1,
2611 .test = alg_test_null,
2612 }, {
2613 .alg = "drbg_nopr_hmac_sha256",
2614 .test = alg_test_drbg,
2615 .fips_allowed = 1,
2616 .suite = {
2617 .drbg = {
2618 .vecs = drbg_nopr_hmac_sha256_tv_template,
2619 .count =
2620 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2621 }
2622 }
2623 }, {
2624 /* covered by drbg_nopr_hmac_sha256 test */
2625 .alg = "drbg_nopr_hmac_sha384",
2626 .fips_allowed = 1,
2627 .test = alg_test_null,
2628 }, {
2629 .alg = "drbg_nopr_hmac_sha512",
2630 .test = alg_test_null,
2631 .fips_allowed = 1,
2632 }, {
2633 .alg = "drbg_nopr_sha1",
2634 .fips_allowed = 1,
2635 .test = alg_test_null,
2636 }, {
2637 .alg = "drbg_nopr_sha256",
2638 .test = alg_test_drbg,
2639 .fips_allowed = 1,
2640 .suite = {
2641 .drbg = {
2642 .vecs = drbg_nopr_sha256_tv_template,
2643 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2644 }
2645 }
2646 }, {
2647 /* covered by drbg_nopr_sha256 test */
2648 .alg = "drbg_nopr_sha384",
2649 .fips_allowed = 1,
2650 .test = alg_test_null,
2651 }, {
2652 .alg = "drbg_nopr_sha512",
2653 .fips_allowed = 1,
2654 .test = alg_test_null,
2655 }, {
2656 .alg = "drbg_pr_ctr_aes128",
2657 .test = alg_test_drbg,
2658 .fips_allowed = 1,
2659 .suite = {
2660 .drbg = {
2661 .vecs = drbg_pr_ctr_aes128_tv_template,
2662 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2663 }
2664 }
2665 }, {
2666 /* covered by drbg_pr_ctr_aes128 test */
2667 .alg = "drbg_pr_ctr_aes192",
2668 .fips_allowed = 1,
2669 .test = alg_test_null,
2670 }, {
2671 .alg = "drbg_pr_ctr_aes256",
2672 .fips_allowed = 1,
2673 .test = alg_test_null,
2674 }, {
2675 .alg = "drbg_pr_hmac_sha1",
2676 .fips_allowed = 1,
2677 .test = alg_test_null,
2678 }, {
2679 .alg = "drbg_pr_hmac_sha256",
2680 .test = alg_test_drbg,
2681 .fips_allowed = 1,
2682 .suite = {
2683 .drbg = {
2684 .vecs = drbg_pr_hmac_sha256_tv_template,
2685 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2686 }
2687 }
2688 }, {
2689 /* covered by drbg_pr_hmac_sha256 test */
2690 .alg = "drbg_pr_hmac_sha384",
2691 .fips_allowed = 1,
2692 .test = alg_test_null,
2693 }, {
2694 .alg = "drbg_pr_hmac_sha512",
2695 .test = alg_test_null,
2696 .fips_allowed = 1,
2697 }, {
2698 .alg = "drbg_pr_sha1",
2699 .fips_allowed = 1,
2700 .test = alg_test_null,
2701 }, {
2702 .alg = "drbg_pr_sha256",
2703 .test = alg_test_drbg,
2704 .fips_allowed = 1,
2705 .suite = {
2706 .drbg = {
2707 .vecs = drbg_pr_sha256_tv_template,
2708 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2709 }
2710 }
2711 }, {
2712 /* covered by drbg_pr_sha256 test */
2713 .alg = "drbg_pr_sha384",
2714 .fips_allowed = 1,
2715 .test = alg_test_null,
2716 }, {
2717 .alg = "drbg_pr_sha512",
2718 .fips_allowed = 1,
2719 .test = alg_test_null,
2720 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002721 .alg = "ecb(__aes-aesni)",
2722 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002723 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002724 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002725 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002726 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002727 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002728 .suite = {
2729 .cipher = {
2730 .enc = {
2731 .vecs = aes_enc_tv_template,
2732 .count = AES_ENC_TEST_VECTORS
2733 },
2734 .dec = {
2735 .vecs = aes_dec_tv_template,
2736 .count = AES_DEC_TEST_VECTORS
2737 }
2738 }
2739 }
2740 }, {
2741 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002742 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002743 .suite = {
2744 .cipher = {
2745 .enc = {
2746 .vecs = anubis_enc_tv_template,
2747 .count = ANUBIS_ENC_TEST_VECTORS
2748 },
2749 .dec = {
2750 .vecs = anubis_dec_tv_template,
2751 .count = ANUBIS_DEC_TEST_VECTORS
2752 }
2753 }
2754 }
2755 }, {
2756 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002757 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002758 .suite = {
2759 .cipher = {
2760 .enc = {
2761 .vecs = arc4_enc_tv_template,
2762 .count = ARC4_ENC_TEST_VECTORS
2763 },
2764 .dec = {
2765 .vecs = arc4_dec_tv_template,
2766 .count = ARC4_DEC_TEST_VECTORS
2767 }
2768 }
2769 }
2770 }, {
2771 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002772 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002773 .suite = {
2774 .cipher = {
2775 .enc = {
2776 .vecs = bf_enc_tv_template,
2777 .count = BF_ENC_TEST_VECTORS
2778 },
2779 .dec = {
2780 .vecs = bf_dec_tv_template,
2781 .count = BF_DEC_TEST_VECTORS
2782 }
2783 }
2784 }
2785 }, {
2786 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002787 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002788 .suite = {
2789 .cipher = {
2790 .enc = {
2791 .vecs = camellia_enc_tv_template,
2792 .count = CAMELLIA_ENC_TEST_VECTORS
2793 },
2794 .dec = {
2795 .vecs = camellia_dec_tv_template,
2796 .count = CAMELLIA_DEC_TEST_VECTORS
2797 }
2798 }
2799 }
2800 }, {
2801 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002802 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002803 .suite = {
2804 .cipher = {
2805 .enc = {
2806 .vecs = cast5_enc_tv_template,
2807 .count = CAST5_ENC_TEST_VECTORS
2808 },
2809 .dec = {
2810 .vecs = cast5_dec_tv_template,
2811 .count = CAST5_DEC_TEST_VECTORS
2812 }
2813 }
2814 }
2815 }, {
2816 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002817 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002818 .suite = {
2819 .cipher = {
2820 .enc = {
2821 .vecs = cast6_enc_tv_template,
2822 .count = CAST6_ENC_TEST_VECTORS
2823 },
2824 .dec = {
2825 .vecs = cast6_dec_tv_template,
2826 .count = CAST6_DEC_TEST_VECTORS
2827 }
2828 }
2829 }
2830 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002831 .alg = "ecb(cipher_null)",
2832 .test = alg_test_null,
2833 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002834 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002835 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002836 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002837 .suite = {
2838 .cipher = {
2839 .enc = {
2840 .vecs = des_enc_tv_template,
2841 .count = DES_ENC_TEST_VECTORS
2842 },
2843 .dec = {
2844 .vecs = des_dec_tv_template,
2845 .count = DES_DEC_TEST_VECTORS
2846 }
2847 }
2848 }
2849 }, {
2850 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002851 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002852 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002853 .suite = {
2854 .cipher = {
2855 .enc = {
2856 .vecs = des3_ede_enc_tv_template,
2857 .count = DES3_EDE_ENC_TEST_VECTORS
2858 },
2859 .dec = {
2860 .vecs = des3_ede_dec_tv_template,
2861 .count = DES3_EDE_DEC_TEST_VECTORS
2862 }
2863 }
2864 }
2865 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002866 .alg = "ecb(fcrypt)",
2867 .test = alg_test_skcipher,
2868 .suite = {
2869 .cipher = {
2870 .enc = {
2871 .vecs = fcrypt_pcbc_enc_tv_template,
2872 .count = 1
2873 },
2874 .dec = {
2875 .vecs = fcrypt_pcbc_dec_tv_template,
2876 .count = 1
2877 }
2878 }
2879 }
2880 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002881 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002882 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002883 .suite = {
2884 .cipher = {
2885 .enc = {
2886 .vecs = khazad_enc_tv_template,
2887 .count = KHAZAD_ENC_TEST_VECTORS
2888 },
2889 .dec = {
2890 .vecs = khazad_dec_tv_template,
2891 .count = KHAZAD_DEC_TEST_VECTORS
2892 }
2893 }
2894 }
2895 }, {
2896 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002897 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002898 .suite = {
2899 .cipher = {
2900 .enc = {
2901 .vecs = seed_enc_tv_template,
2902 .count = SEED_ENC_TEST_VECTORS
2903 },
2904 .dec = {
2905 .vecs = seed_dec_tv_template,
2906 .count = SEED_DEC_TEST_VECTORS
2907 }
2908 }
2909 }
2910 }, {
2911 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002912 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002913 .suite = {
2914 .cipher = {
2915 .enc = {
2916 .vecs = serpent_enc_tv_template,
2917 .count = SERPENT_ENC_TEST_VECTORS
2918 },
2919 .dec = {
2920 .vecs = serpent_dec_tv_template,
2921 .count = SERPENT_DEC_TEST_VECTORS
2922 }
2923 }
2924 }
2925 }, {
2926 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002927 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002928 .suite = {
2929 .cipher = {
2930 .enc = {
2931 .vecs = tea_enc_tv_template,
2932 .count = TEA_ENC_TEST_VECTORS
2933 },
2934 .dec = {
2935 .vecs = tea_dec_tv_template,
2936 .count = TEA_DEC_TEST_VECTORS
2937 }
2938 }
2939 }
2940 }, {
2941 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002942 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002943 .suite = {
2944 .cipher = {
2945 .enc = {
2946 .vecs = tnepres_enc_tv_template,
2947 .count = TNEPRES_ENC_TEST_VECTORS
2948 },
2949 .dec = {
2950 .vecs = tnepres_dec_tv_template,
2951 .count = TNEPRES_DEC_TEST_VECTORS
2952 }
2953 }
2954 }
2955 }, {
2956 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002957 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002958 .suite = {
2959 .cipher = {
2960 .enc = {
2961 .vecs = tf_enc_tv_template,
2962 .count = TF_ENC_TEST_VECTORS
2963 },
2964 .dec = {
2965 .vecs = tf_dec_tv_template,
2966 .count = TF_DEC_TEST_VECTORS
2967 }
2968 }
2969 }
2970 }, {
2971 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002972 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002973 .suite = {
2974 .cipher = {
2975 .enc = {
2976 .vecs = xeta_enc_tv_template,
2977 .count = XETA_ENC_TEST_VECTORS
2978 },
2979 .dec = {
2980 .vecs = xeta_dec_tv_template,
2981 .count = XETA_DEC_TEST_VECTORS
2982 }
2983 }
2984 }
2985 }, {
2986 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002987 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002988 .suite = {
2989 .cipher = {
2990 .enc = {
2991 .vecs = xtea_enc_tv_template,
2992 .count = XTEA_ENC_TEST_VECTORS
2993 },
2994 .dec = {
2995 .vecs = xtea_dec_tv_template,
2996 .count = XTEA_DEC_TEST_VECTORS
2997 }
2998 }
2999 }
3000 }, {
3001 .alg = "gcm(aes)",
3002 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003003 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003004 .suite = {
3005 .aead = {
3006 .enc = {
3007 .vecs = aes_gcm_enc_tv_template,
3008 .count = AES_GCM_ENC_TEST_VECTORS
3009 },
3010 .dec = {
3011 .vecs = aes_gcm_dec_tv_template,
3012 .count = AES_GCM_DEC_TEST_VECTORS
3013 }
3014 }
3015 }
3016 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003017 .alg = "ghash",
3018 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003019 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003020 .suite = {
3021 .hash = {
3022 .vecs = ghash_tv_template,
3023 .count = GHASH_TEST_VECTORS
3024 }
3025 }
3026 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003027 .alg = "hmac(crc32)",
3028 .test = alg_test_hash,
3029 .suite = {
3030 .hash = {
3031 .vecs = bfin_crc_tv_template,
3032 .count = BFIN_CRC_TEST_VECTORS
3033 }
3034 }
3035 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003036 .alg = "hmac(md5)",
3037 .test = alg_test_hash,
3038 .suite = {
3039 .hash = {
3040 .vecs = hmac_md5_tv_template,
3041 .count = HMAC_MD5_TEST_VECTORS
3042 }
3043 }
3044 }, {
3045 .alg = "hmac(rmd128)",
3046 .test = alg_test_hash,
3047 .suite = {
3048 .hash = {
3049 .vecs = hmac_rmd128_tv_template,
3050 .count = HMAC_RMD128_TEST_VECTORS
3051 }
3052 }
3053 }, {
3054 .alg = "hmac(rmd160)",
3055 .test = alg_test_hash,
3056 .suite = {
3057 .hash = {
3058 .vecs = hmac_rmd160_tv_template,
3059 .count = HMAC_RMD160_TEST_VECTORS
3060 }
3061 }
3062 }, {
3063 .alg = "hmac(sha1)",
3064 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003065 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003066 .suite = {
3067 .hash = {
3068 .vecs = hmac_sha1_tv_template,
3069 .count = HMAC_SHA1_TEST_VECTORS
3070 }
3071 }
3072 }, {
3073 .alg = "hmac(sha224)",
3074 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003075 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003076 .suite = {
3077 .hash = {
3078 .vecs = hmac_sha224_tv_template,
3079 .count = HMAC_SHA224_TEST_VECTORS
3080 }
3081 }
3082 }, {
3083 .alg = "hmac(sha256)",
3084 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003085 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003086 .suite = {
3087 .hash = {
3088 .vecs = hmac_sha256_tv_template,
3089 .count = HMAC_SHA256_TEST_VECTORS
3090 }
3091 }
3092 }, {
3093 .alg = "hmac(sha384)",
3094 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003095 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003096 .suite = {
3097 .hash = {
3098 .vecs = hmac_sha384_tv_template,
3099 .count = HMAC_SHA384_TEST_VECTORS
3100 }
3101 }
3102 }, {
3103 .alg = "hmac(sha512)",
3104 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003105 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003106 .suite = {
3107 .hash = {
3108 .vecs = hmac_sha512_tv_template,
3109 .count = HMAC_SHA512_TEST_VECTORS
3110 }
3111 }
3112 }, {
3113 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003114 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003115 .suite = {
3116 .cipher = {
3117 .enc = {
3118 .vecs = aes_lrw_enc_tv_template,
3119 .count = AES_LRW_ENC_TEST_VECTORS
3120 },
3121 .dec = {
3122 .vecs = aes_lrw_dec_tv_template,
3123 .count = AES_LRW_DEC_TEST_VECTORS
3124 }
3125 }
3126 }
3127 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003128 .alg = "lrw(camellia)",
3129 .test = alg_test_skcipher,
3130 .suite = {
3131 .cipher = {
3132 .enc = {
3133 .vecs = camellia_lrw_enc_tv_template,
3134 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3135 },
3136 .dec = {
3137 .vecs = camellia_lrw_dec_tv_template,
3138 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3139 }
3140 }
3141 }
3142 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003143 .alg = "lrw(cast6)",
3144 .test = alg_test_skcipher,
3145 .suite = {
3146 .cipher = {
3147 .enc = {
3148 .vecs = cast6_lrw_enc_tv_template,
3149 .count = CAST6_LRW_ENC_TEST_VECTORS
3150 },
3151 .dec = {
3152 .vecs = cast6_lrw_dec_tv_template,
3153 .count = CAST6_LRW_DEC_TEST_VECTORS
3154 }
3155 }
3156 }
3157 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003158 .alg = "lrw(serpent)",
3159 .test = alg_test_skcipher,
3160 .suite = {
3161 .cipher = {
3162 .enc = {
3163 .vecs = serpent_lrw_enc_tv_template,
3164 .count = SERPENT_LRW_ENC_TEST_VECTORS
3165 },
3166 .dec = {
3167 .vecs = serpent_lrw_dec_tv_template,
3168 .count = SERPENT_LRW_DEC_TEST_VECTORS
3169 }
3170 }
3171 }
3172 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003173 .alg = "lrw(twofish)",
3174 .test = alg_test_skcipher,
3175 .suite = {
3176 .cipher = {
3177 .enc = {
3178 .vecs = tf_lrw_enc_tv_template,
3179 .count = TF_LRW_ENC_TEST_VECTORS
3180 },
3181 .dec = {
3182 .vecs = tf_lrw_dec_tv_template,
3183 .count = TF_LRW_DEC_TEST_VECTORS
3184 }
3185 }
3186 }
3187 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003188 .alg = "lzo",
3189 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003190 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003191 .suite = {
3192 .comp = {
3193 .comp = {
3194 .vecs = lzo_comp_tv_template,
3195 .count = LZO_COMP_TEST_VECTORS
3196 },
3197 .decomp = {
3198 .vecs = lzo_decomp_tv_template,
3199 .count = LZO_DECOMP_TEST_VECTORS
3200 }
3201 }
3202 }
3203 }, {
3204 .alg = "md4",
3205 .test = alg_test_hash,
3206 .suite = {
3207 .hash = {
3208 .vecs = md4_tv_template,
3209 .count = MD4_TEST_VECTORS
3210 }
3211 }
3212 }, {
3213 .alg = "md5",
3214 .test = alg_test_hash,
3215 .suite = {
3216 .hash = {
3217 .vecs = md5_tv_template,
3218 .count = MD5_TEST_VECTORS
3219 }
3220 }
3221 }, {
3222 .alg = "michael_mic",
3223 .test = alg_test_hash,
3224 .suite = {
3225 .hash = {
3226 .vecs = michael_mic_tv_template,
3227 .count = MICHAEL_MIC_TEST_VECTORS
3228 }
3229 }
3230 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003231 .alg = "ofb(aes)",
3232 .test = alg_test_skcipher,
3233 .fips_allowed = 1,
3234 .suite = {
3235 .cipher = {
3236 .enc = {
3237 .vecs = aes_ofb_enc_tv_template,
3238 .count = AES_OFB_ENC_TEST_VECTORS
3239 },
3240 .dec = {
3241 .vecs = aes_ofb_dec_tv_template,
3242 .count = AES_OFB_DEC_TEST_VECTORS
3243 }
3244 }
3245 }
3246 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003247 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003248 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003249 .suite = {
3250 .cipher = {
3251 .enc = {
3252 .vecs = fcrypt_pcbc_enc_tv_template,
3253 .count = FCRYPT_ENC_TEST_VECTORS
3254 },
3255 .dec = {
3256 .vecs = fcrypt_pcbc_dec_tv_template,
3257 .count = FCRYPT_DEC_TEST_VECTORS
3258 }
3259 }
3260 }
3261 }, {
3262 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003263 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003264 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003265 .suite = {
3266 .cipher = {
3267 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003268 .vecs = aes_ctr_rfc3686_enc_tv_template,
3269 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003270 },
3271 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003272 .vecs = aes_ctr_rfc3686_dec_tv_template,
3273 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003274 }
3275 }
3276 }
3277 }, {
Adrian Hoban69435b92010-11-04 15:02:04 -04003278 .alg = "rfc4106(gcm(aes))",
3279 .test = alg_test_aead,
3280 .suite = {
3281 .aead = {
3282 .enc = {
3283 .vecs = aes_gcm_rfc4106_enc_tv_template,
3284 .count = AES_GCM_4106_ENC_TEST_VECTORS
3285 },
3286 .dec = {
3287 .vecs = aes_gcm_rfc4106_dec_tv_template,
3288 .count = AES_GCM_4106_DEC_TEST_VECTORS
3289 }
3290 }
3291 }
3292 }, {
Jarod Wilson5d667322009-05-04 19:23:40 +08003293 .alg = "rfc4309(ccm(aes))",
3294 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003295 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003296 .suite = {
3297 .aead = {
3298 .enc = {
3299 .vecs = aes_ccm_rfc4309_enc_tv_template,
3300 .count = AES_CCM_4309_ENC_TEST_VECTORS
3301 },
3302 .dec = {
3303 .vecs = aes_ccm_rfc4309_dec_tv_template,
3304 .count = AES_CCM_4309_DEC_TEST_VECTORS
3305 }
3306 }
3307 }
3308 }, {
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003309 .alg = "rfc4543(gcm(aes))",
3310 .test = alg_test_aead,
3311 .suite = {
3312 .aead = {
3313 .enc = {
3314 .vecs = aes_gcm_rfc4543_enc_tv_template,
3315 .count = AES_GCM_4543_ENC_TEST_VECTORS
3316 },
3317 .dec = {
3318 .vecs = aes_gcm_rfc4543_dec_tv_template,
3319 .count = AES_GCM_4543_DEC_TEST_VECTORS
3320 },
3321 }
3322 }
3323 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003324 .alg = "rmd128",
3325 .test = alg_test_hash,
3326 .suite = {
3327 .hash = {
3328 .vecs = rmd128_tv_template,
3329 .count = RMD128_TEST_VECTORS
3330 }
3331 }
3332 }, {
3333 .alg = "rmd160",
3334 .test = alg_test_hash,
3335 .suite = {
3336 .hash = {
3337 .vecs = rmd160_tv_template,
3338 .count = RMD160_TEST_VECTORS
3339 }
3340 }
3341 }, {
3342 .alg = "rmd256",
3343 .test = alg_test_hash,
3344 .suite = {
3345 .hash = {
3346 .vecs = rmd256_tv_template,
3347 .count = RMD256_TEST_VECTORS
3348 }
3349 }
3350 }, {
3351 .alg = "rmd320",
3352 .test = alg_test_hash,
3353 .suite = {
3354 .hash = {
3355 .vecs = rmd320_tv_template,
3356 .count = RMD320_TEST_VECTORS
3357 }
3358 }
3359 }, {
3360 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003361 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003362 .suite = {
3363 .cipher = {
3364 .enc = {
3365 .vecs = salsa20_stream_enc_tv_template,
3366 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3367 }
3368 }
3369 }
3370 }, {
3371 .alg = "sha1",
3372 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003373 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003374 .suite = {
3375 .hash = {
3376 .vecs = sha1_tv_template,
3377 .count = SHA1_TEST_VECTORS
3378 }
3379 }
3380 }, {
3381 .alg = "sha224",
3382 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003383 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003384 .suite = {
3385 .hash = {
3386 .vecs = sha224_tv_template,
3387 .count = SHA224_TEST_VECTORS
3388 }
3389 }
3390 }, {
3391 .alg = "sha256",
3392 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003393 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003394 .suite = {
3395 .hash = {
3396 .vecs = sha256_tv_template,
3397 .count = SHA256_TEST_VECTORS
3398 }
3399 }
3400 }, {
3401 .alg = "sha384",
3402 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003403 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003404 .suite = {
3405 .hash = {
3406 .vecs = sha384_tv_template,
3407 .count = SHA384_TEST_VECTORS
3408 }
3409 }
3410 }, {
3411 .alg = "sha512",
3412 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003413 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003414 .suite = {
3415 .hash = {
3416 .vecs = sha512_tv_template,
3417 .count = SHA512_TEST_VECTORS
3418 }
3419 }
3420 }, {
3421 .alg = "tgr128",
3422 .test = alg_test_hash,
3423 .suite = {
3424 .hash = {
3425 .vecs = tgr128_tv_template,
3426 .count = TGR128_TEST_VECTORS
3427 }
3428 }
3429 }, {
3430 .alg = "tgr160",
3431 .test = alg_test_hash,
3432 .suite = {
3433 .hash = {
3434 .vecs = tgr160_tv_template,
3435 .count = TGR160_TEST_VECTORS
3436 }
3437 }
3438 }, {
3439 .alg = "tgr192",
3440 .test = alg_test_hash,
3441 .suite = {
3442 .hash = {
3443 .vecs = tgr192_tv_template,
3444 .count = TGR192_TEST_VECTORS
3445 }
3446 }
3447 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003448 .alg = "vmac(aes)",
3449 .test = alg_test_hash,
3450 .suite = {
3451 .hash = {
3452 .vecs = aes_vmac128_tv_template,
3453 .count = VMAC_AES_TEST_VECTORS
3454 }
3455 }
3456 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003457 .alg = "wp256",
3458 .test = alg_test_hash,
3459 .suite = {
3460 .hash = {
3461 .vecs = wp256_tv_template,
3462 .count = WP256_TEST_VECTORS
3463 }
3464 }
3465 }, {
3466 .alg = "wp384",
3467 .test = alg_test_hash,
3468 .suite = {
3469 .hash = {
3470 .vecs = wp384_tv_template,
3471 .count = WP384_TEST_VECTORS
3472 }
3473 }
3474 }, {
3475 .alg = "wp512",
3476 .test = alg_test_hash,
3477 .suite = {
3478 .hash = {
3479 .vecs = wp512_tv_template,
3480 .count = WP512_TEST_VECTORS
3481 }
3482 }
3483 }, {
3484 .alg = "xcbc(aes)",
3485 .test = alg_test_hash,
3486 .suite = {
3487 .hash = {
3488 .vecs = aes_xcbc128_tv_template,
3489 .count = XCBC_AES_TEST_VECTORS
3490 }
3491 }
3492 }, {
3493 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003494 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003495 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003496 .suite = {
3497 .cipher = {
3498 .enc = {
3499 .vecs = aes_xts_enc_tv_template,
3500 .count = AES_XTS_ENC_TEST_VECTORS
3501 },
3502 .dec = {
3503 .vecs = aes_xts_dec_tv_template,
3504 .count = AES_XTS_DEC_TEST_VECTORS
3505 }
3506 }
3507 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003508 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003509 .alg = "xts(camellia)",
3510 .test = alg_test_skcipher,
3511 .suite = {
3512 .cipher = {
3513 .enc = {
3514 .vecs = camellia_xts_enc_tv_template,
3515 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3516 },
3517 .dec = {
3518 .vecs = camellia_xts_dec_tv_template,
3519 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3520 }
3521 }
3522 }
3523 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003524 .alg = "xts(cast6)",
3525 .test = alg_test_skcipher,
3526 .suite = {
3527 .cipher = {
3528 .enc = {
3529 .vecs = cast6_xts_enc_tv_template,
3530 .count = CAST6_XTS_ENC_TEST_VECTORS
3531 },
3532 .dec = {
3533 .vecs = cast6_xts_dec_tv_template,
3534 .count = CAST6_XTS_DEC_TEST_VECTORS
3535 }
3536 }
3537 }
3538 }, {
Jussi Kivilinna18be20b2011-10-18 13:33:17 +03003539 .alg = "xts(serpent)",
3540 .test = alg_test_skcipher,
3541 .suite = {
3542 .cipher = {
3543 .enc = {
3544 .vecs = serpent_xts_enc_tv_template,
3545 .count = SERPENT_XTS_ENC_TEST_VECTORS
3546 },
3547 .dec = {
3548 .vecs = serpent_xts_dec_tv_template,
3549 .count = SERPENT_XTS_DEC_TEST_VECTORS
3550 }
3551 }
3552 }
3553 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003554 .alg = "xts(twofish)",
3555 .test = alg_test_skcipher,
3556 .suite = {
3557 .cipher = {
3558 .enc = {
3559 .vecs = tf_xts_enc_tv_template,
3560 .count = TF_XTS_ENC_TEST_VECTORS
3561 },
3562 .dec = {
3563 .vecs = tf_xts_dec_tv_template,
3564 .count = TF_XTS_DEC_TEST_VECTORS
3565 }
3566 }
3567 }
3568 }, {
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003569 .alg = "zlib",
3570 .test = alg_test_pcomp,
Milan Broz08189042012-12-06 17:16:28 +08003571 .fips_allowed = 1,
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003572 .suite = {
3573 .pcomp = {
3574 .comp = {
3575 .vecs = zlib_comp_tv_template,
3576 .count = ZLIB_COMP_TEST_VECTORS
3577 },
3578 .decomp = {
3579 .vecs = zlib_decomp_tv_template,
3580 .count = ZLIB_DECOMP_TEST_VECTORS
3581 }
3582 }
3583 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003584 }
3585};
3586
Jussi Kivilinna57147582013-06-13 17:37:40 +03003587static bool alg_test_descs_checked;
3588
3589static void alg_test_descs_check_order(void)
3590{
3591 int i;
3592
3593 /* only check once */
3594 if (alg_test_descs_checked)
3595 return;
3596
3597 alg_test_descs_checked = true;
3598
3599 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3600 int diff = strcmp(alg_test_descs[i - 1].alg,
3601 alg_test_descs[i].alg);
3602
3603 if (WARN_ON(diff > 0)) {
3604 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3605 alg_test_descs[i - 1].alg,
3606 alg_test_descs[i].alg);
3607 }
3608
3609 if (WARN_ON(diff == 0)) {
3610 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3611 alg_test_descs[i].alg);
3612 }
3613 }
3614}
3615
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003616static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003617{
3618 int start = 0;
3619 int end = ARRAY_SIZE(alg_test_descs);
3620
3621 while (start < end) {
3622 int i = (start + end) / 2;
3623 int diff = strcmp(alg_test_descs[i].alg, alg);
3624
3625 if (diff > 0) {
3626 end = i;
3627 continue;
3628 }
3629
3630 if (diff < 0) {
3631 start = i + 1;
3632 continue;
3633 }
3634
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003635 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003636 }
3637
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003638 return -1;
3639}
3640
3641int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3642{
3643 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003644 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003645 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003646
Jussi Kivilinna57147582013-06-13 17:37:40 +03003647 alg_test_descs_check_order();
3648
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003649 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3650 char nalg[CRYPTO_MAX_ALG_NAME];
3651
3652 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3653 sizeof(nalg))
3654 return -ENAMETOOLONG;
3655
3656 i = alg_find_test(nalg);
3657 if (i < 0)
3658 goto notest;
3659
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003660 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3661 goto non_fips_alg;
3662
Jarod Wilson941fb322009-05-04 19:49:23 +08003663 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3664 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003665 }
3666
3667 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003668 j = alg_find_test(driver);
3669 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003670 goto notest;
3671
Herbert Xua68f6612009-07-02 16:32:12 +08003672 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3673 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003674 goto non_fips_alg;
3675
Herbert Xua68f6612009-07-02 16:32:12 +08003676 rc = 0;
3677 if (i >= 0)
3678 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3679 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003680 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003681 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3682 type, mask);
3683
Jarod Wilson941fb322009-05-04 19:49:23 +08003684test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003685 if (fips_enabled && rc)
3686 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3687
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003688 if (fips_enabled && !rc)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303689 pr_info(KERN_INFO "alg: self-tests for %s (%s) passed\n",
3690 driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003691
Neil Hormand12d6b62008-10-12 20:36:51 +08003692 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003693
3694notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003695 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3696 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003697non_fips_alg:
3698 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003699}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003700
Herbert Xu326a6342010-08-06 09:40:28 +08003701#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003702
Herbert Xuda7f0332008-07-31 17:08:25 +08003703EXPORT_SYMBOL_GPL(alg_test);