blob: f217c622bc41789a09ca283735d625ab60c16139 [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++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +0300964 if (template[i].np && !template[i].also_non_np)
965 continue;
966
Herbert Xuda7f0332008-07-31 17:08:25 +0800967 if (template[i].iv)
968 memcpy(iv, template[i].iv, MAX_IVLEN);
969 else
970 memset(iv, 0, MAX_IVLEN);
971
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300972 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300973 ret = -EINVAL;
974 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
975 goto out;
976
977 data = xbuf[0];
978 data += align_offset;
979 memcpy(data, template[i].input, template[i].ilen);
980
981 crypto_ablkcipher_clear_flags(tfm, ~0);
982 if (template[i].wk)
983 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
984
985 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
986 template[i].klen);
987 if (!ret == template[i].fail) {
988 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
989 d, j, algo, crypto_ablkcipher_get_flags(tfm));
990 goto out;
991 } else if (ret)
992 continue;
993
994 sg_init_one(&sg[0], data, template[i].ilen);
995 if (diff_dst) {
996 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300997 data += align_offset;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300998 sg_init_one(&sgout[0], data, template[i].ilen);
999 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001000
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001001 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1002 template[i].ilen, iv);
1003 ret = enc ? crypto_ablkcipher_encrypt(req) :
1004 crypto_ablkcipher_decrypt(req);
Herbert Xuda7f0332008-07-31 17:08:25 +08001005
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001006 switch (ret) {
1007 case 0:
1008 break;
1009 case -EINPROGRESS:
1010 case -EBUSY:
1011 ret = wait_for_completion_interruptible(
1012 &result.completion);
1013 if (!ret && !((ret = result.err))) {
1014 reinit_completion(&result.completion);
Herbert Xuda7f0332008-07-31 17:08:25 +08001015 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001016 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001017 /* fall through */
1018 default:
1019 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1020 d, e, j, algo, -ret);
1021 goto out;
1022 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001023
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001024 q = data;
1025 if (memcmp(q, template[i].result, template[i].rlen)) {
1026 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1027 d, j, e, algo);
1028 hexdump(q, template[i].rlen);
1029 ret = -EINVAL;
1030 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001031 }
1032 }
1033
1034 j = 0;
1035 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001036 /* alignment tests are only done with continuous buffers */
1037 if (align_offset != 0)
1038 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001039
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001040 if (!template[i].np)
1041 continue;
1042
Herbert Xuda7f0332008-07-31 17:08:25 +08001043 if (template[i].iv)
1044 memcpy(iv, template[i].iv, MAX_IVLEN);
1045 else
1046 memset(iv, 0, MAX_IVLEN);
1047
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001048 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001049 crypto_ablkcipher_clear_flags(tfm, ~0);
1050 if (template[i].wk)
1051 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1052
1053 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1054 template[i].klen);
1055 if (!ret == template[i].fail) {
1056 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1057 d, j, algo, crypto_ablkcipher_get_flags(tfm));
1058 goto out;
1059 } else if (ret)
1060 continue;
1061
1062 temp = 0;
1063 ret = -EINVAL;
1064 sg_init_table(sg, template[i].np);
1065 if (diff_dst)
1066 sg_init_table(sgout, template[i].np);
1067 for (k = 0; k < template[i].np; k++) {
1068 if (WARN_ON(offset_in_page(IDX[k]) +
1069 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001070 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001071
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001072 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1073
1074 memcpy(q, template[i].input + temp, template[i].tap[k]);
1075
1076 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1077 q[template[i].tap[k]] = 0;
1078
1079 sg_set_buf(&sg[k], q, template[i].tap[k]);
1080 if (diff_dst) {
1081 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1082 offset_in_page(IDX[k]);
1083
1084 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1085
1086 memset(q, 0, template[i].tap[k]);
1087 if (offset_in_page(q) +
1088 template[i].tap[k] < PAGE_SIZE)
1089 q[template[i].tap[k]] = 0;
1090 }
1091
1092 temp += template[i].tap[k];
1093 }
1094
1095 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1096 template[i].ilen, iv);
1097
1098 ret = enc ? crypto_ablkcipher_encrypt(req) :
1099 crypto_ablkcipher_decrypt(req);
1100
1101 switch (ret) {
1102 case 0:
1103 break;
1104 case -EINPROGRESS:
1105 case -EBUSY:
1106 ret = wait_for_completion_interruptible(
1107 &result.completion);
1108 if (!ret && !((ret = result.err))) {
1109 reinit_completion(&result.completion);
1110 break;
1111 }
1112 /* fall through */
1113 default:
1114 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1115 d, e, j, algo, -ret);
1116 goto out;
1117 }
1118
1119 temp = 0;
1120 ret = -EINVAL;
1121 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001122 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001123 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1124 offset_in_page(IDX[k]);
1125 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001126 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1127 offset_in_page(IDX[k]);
1128
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001129 if (memcmp(q, template[i].result + temp,
1130 template[i].tap[k])) {
1131 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1132 d, j, e, k, algo);
1133 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001134 goto out;
1135 }
1136
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001137 q += template[i].tap[k];
1138 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1139 ;
1140 if (n) {
1141 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1142 d, j, e, k, algo, n);
1143 hexdump(q, n);
1144 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001145 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001146 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001147 }
1148 }
1149
1150 ret = 0;
1151
1152out:
1153 ablkcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001154 if (diff_dst)
1155 testmgr_free_buf(xoutbuf);
1156out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001157 testmgr_free_buf(xbuf);
1158out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001159 return ret;
1160}
1161
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001162static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1163 struct cipher_testvec *template, unsigned int tcount)
1164{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001165 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001166 int ret;
1167
1168 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001169 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001170 if (ret)
1171 return ret;
1172
1173 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001174 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1175 if (ret)
1176 return ret;
1177
1178 /* test unaligned buffers, check with one byte offset */
1179 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1180 if (ret)
1181 return ret;
1182
1183 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1184 if (alignmask) {
1185 /* Check if alignment mask for tfm is correctly set. */
1186 ret = __test_skcipher(tfm, enc, template, tcount, true,
1187 alignmask + 1);
1188 if (ret)
1189 return ret;
1190 }
1191
1192 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001193}
1194
Herbert Xuda7f0332008-07-31 17:08:25 +08001195static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1196 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1197{
1198 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1199 unsigned int i;
1200 char result[COMP_BUF_SIZE];
1201 int ret;
1202
1203 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001204 int ilen;
1205 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001206
1207 memset(result, 0, sizeof (result));
1208
1209 ilen = ctemplate[i].inlen;
1210 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1211 ilen, result, &dlen);
1212 if (ret) {
1213 printk(KERN_ERR "alg: comp: compression failed "
1214 "on test %d for %s: ret=%d\n", i + 1, algo,
1215 -ret);
1216 goto out;
1217 }
1218
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001219 if (dlen != ctemplate[i].outlen) {
1220 printk(KERN_ERR "alg: comp: Compression test %d "
1221 "failed for %s: output len = %d\n", i + 1, algo,
1222 dlen);
1223 ret = -EINVAL;
1224 goto out;
1225 }
1226
Herbert Xuda7f0332008-07-31 17:08:25 +08001227 if (memcmp(result, ctemplate[i].output, dlen)) {
1228 printk(KERN_ERR "alg: comp: Compression test %d "
1229 "failed for %s\n", i + 1, algo);
1230 hexdump(result, dlen);
1231 ret = -EINVAL;
1232 goto out;
1233 }
1234 }
1235
1236 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001237 int ilen;
1238 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001239
1240 memset(result, 0, sizeof (result));
1241
1242 ilen = dtemplate[i].inlen;
1243 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1244 ilen, result, &dlen);
1245 if (ret) {
1246 printk(KERN_ERR "alg: comp: decompression failed "
1247 "on test %d for %s: ret=%d\n", i + 1, algo,
1248 -ret);
1249 goto out;
1250 }
1251
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001252 if (dlen != dtemplate[i].outlen) {
1253 printk(KERN_ERR "alg: comp: Decompression test %d "
1254 "failed for %s: output len = %d\n", i + 1, algo,
1255 dlen);
1256 ret = -EINVAL;
1257 goto out;
1258 }
1259
Herbert Xuda7f0332008-07-31 17:08:25 +08001260 if (memcmp(result, dtemplate[i].output, dlen)) {
1261 printk(KERN_ERR "alg: comp: Decompression test %d "
1262 "failed for %s\n", i + 1, algo);
1263 hexdump(result, dlen);
1264 ret = -EINVAL;
1265 goto out;
1266 }
1267 }
1268
1269 ret = 0;
1270
1271out:
1272 return ret;
1273}
1274
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001275static int test_pcomp(struct crypto_pcomp *tfm,
1276 struct pcomp_testvec *ctemplate,
1277 struct pcomp_testvec *dtemplate, int ctcount,
1278 int dtcount)
1279{
1280 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1281 unsigned int i;
1282 char result[COMP_BUF_SIZE];
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001283 int res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001284
1285 for (i = 0; i < ctcount; i++) {
1286 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001287 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001288
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001289 res = crypto_compress_setup(tfm, ctemplate[i].params,
1290 ctemplate[i].paramsize);
1291 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001292 pr_err("alg: pcomp: compression setup failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001293 "%d for %s: error=%d\n", i + 1, algo, res);
1294 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001295 }
1296
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001297 res = crypto_compress_init(tfm);
1298 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001299 pr_err("alg: pcomp: compression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001300 "%d for %s: error=%d\n", i + 1, algo, res);
1301 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001302 }
1303
1304 memset(result, 0, sizeof(result));
1305
1306 req.next_in = ctemplate[i].input;
1307 req.avail_in = ctemplate[i].inlen / 2;
1308 req.next_out = result;
1309 req.avail_out = ctemplate[i].outlen / 2;
1310
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001311 res = crypto_compress_update(tfm, &req);
1312 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001313 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001314 "%d for %s: error=%d\n", i + 1, algo, res);
1315 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001316 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001317 if (res > 0)
1318 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001319
1320 /* Add remaining input data */
1321 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1322
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001323 res = crypto_compress_update(tfm, &req);
1324 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001325 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001326 "%d for %s: error=%d\n", i + 1, algo, res);
1327 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001328 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001329 if (res > 0)
1330 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001331
1332 /* Provide remaining output space */
1333 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1334
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001335 res = crypto_compress_final(tfm, &req);
1336 if (res < 0) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001337 pr_err("alg: pcomp: compression final failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001338 "%d for %s: error=%d\n", i + 1, algo, res);
1339 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001340 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001341 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001342
1343 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1344 pr_err("alg: comp: Compression test %d failed for %s: "
1345 "output len = %d (expected %d)\n", i + 1, algo,
1346 COMP_BUF_SIZE - req.avail_out,
1347 ctemplate[i].outlen);
1348 return -EINVAL;
1349 }
1350
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001351 if (produced != ctemplate[i].outlen) {
1352 pr_err("alg: comp: Compression test %d failed for %s: "
1353 "returned len = %u (expected %d)\n", i + 1,
1354 algo, produced, ctemplate[i].outlen);
1355 return -EINVAL;
1356 }
1357
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001358 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1359 pr_err("alg: pcomp: Compression test %d failed for "
1360 "%s\n", i + 1, algo);
1361 hexdump(result, ctemplate[i].outlen);
1362 return -EINVAL;
1363 }
1364 }
1365
1366 for (i = 0; i < dtcount; i++) {
1367 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001368 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001369
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001370 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1371 dtemplate[i].paramsize);
1372 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001373 pr_err("alg: pcomp: decompression setup failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001374 "test %d for %s: error=%d\n", i + 1, algo, res);
1375 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001376 }
1377
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001378 res = crypto_decompress_init(tfm);
1379 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001380 pr_err("alg: pcomp: decompression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001381 "%d for %s: error=%d\n", i + 1, algo, res);
1382 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001383 }
1384
1385 memset(result, 0, sizeof(result));
1386
1387 req.next_in = dtemplate[i].input;
1388 req.avail_in = dtemplate[i].inlen / 2;
1389 req.next_out = result;
1390 req.avail_out = dtemplate[i].outlen / 2;
1391
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001392 res = crypto_decompress_update(tfm, &req);
1393 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001394 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001395 "test %d for %s: error=%d\n", i + 1, algo, res);
1396 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001397 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001398 if (res > 0)
1399 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001400
1401 /* Add remaining input data */
1402 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1403
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001404 res = crypto_decompress_update(tfm, &req);
1405 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001406 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001407 "test %d for %s: error=%d\n", i + 1, algo, res);
1408 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001409 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001410 if (res > 0)
1411 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001412
1413 /* Provide remaining output space */
1414 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1415
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001416 res = crypto_decompress_final(tfm, &req);
1417 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001418 pr_err("alg: pcomp: decompression final failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001419 "test %d for %s: error=%d\n", i + 1, algo, res);
1420 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001421 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001422 if (res > 0)
1423 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001424
1425 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1426 pr_err("alg: comp: Decompression test %d failed for "
1427 "%s: output len = %d (expected %d)\n", i + 1,
1428 algo, COMP_BUF_SIZE - req.avail_out,
1429 dtemplate[i].outlen);
1430 return -EINVAL;
1431 }
1432
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001433 if (produced != dtemplate[i].outlen) {
1434 pr_err("alg: comp: Decompression test %d failed for "
1435 "%s: returned len = %u (expected %d)\n", i + 1,
1436 algo, produced, dtemplate[i].outlen);
1437 return -EINVAL;
1438 }
1439
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001440 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1441 pr_err("alg: pcomp: Decompression test %d failed for "
1442 "%s\n", i + 1, algo);
1443 hexdump(result, dtemplate[i].outlen);
1444 return -EINVAL;
1445 }
1446 }
1447
1448 return 0;
1449}
1450
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001451
1452static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1453 unsigned int tcount)
1454{
1455 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001456 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001457 u8 *seed;
1458 char result[32];
1459
1460 seedsize = crypto_rng_seedsize(tfm);
1461
1462 seed = kmalloc(seedsize, GFP_KERNEL);
1463 if (!seed) {
1464 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1465 "for %s\n", algo);
1466 return -ENOMEM;
1467 }
1468
1469 for (i = 0; i < tcount; i++) {
1470 memset(result, 0, 32);
1471
1472 memcpy(seed, template[i].v, template[i].vlen);
1473 memcpy(seed + template[i].vlen, template[i].key,
1474 template[i].klen);
1475 memcpy(seed + template[i].vlen + template[i].klen,
1476 template[i].dt, template[i].dtlen);
1477
1478 err = crypto_rng_reset(tfm, seed, seedsize);
1479 if (err) {
1480 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1481 "for %s\n", algo);
1482 goto out;
1483 }
1484
1485 for (j = 0; j < template[i].loops; j++) {
1486 err = crypto_rng_get_bytes(tfm, result,
1487 template[i].rlen);
1488 if (err != template[i].rlen) {
1489 printk(KERN_ERR "alg: cprng: Failed to obtain "
1490 "the correct amount of random data for "
1491 "%s (requested %d, got %d)\n", algo,
1492 template[i].rlen, err);
1493 goto out;
1494 }
1495 }
1496
1497 err = memcmp(result, template[i].result,
1498 template[i].rlen);
1499 if (err) {
1500 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1501 i, algo);
1502 hexdump(result, template[i].rlen);
1503 err = -EINVAL;
1504 goto out;
1505 }
1506 }
1507
1508out:
1509 kfree(seed);
1510 return err;
1511}
1512
Herbert Xuda7f0332008-07-31 17:08:25 +08001513static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1514 u32 type, u32 mask)
1515{
1516 struct crypto_aead *tfm;
1517 int err = 0;
1518
1519 tfm = crypto_alloc_aead(driver, type, mask);
1520 if (IS_ERR(tfm)) {
1521 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1522 "%ld\n", driver, PTR_ERR(tfm));
1523 return PTR_ERR(tfm);
1524 }
1525
1526 if (desc->suite.aead.enc.vecs) {
1527 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1528 desc->suite.aead.enc.count);
1529 if (err)
1530 goto out;
1531 }
1532
1533 if (!err && desc->suite.aead.dec.vecs)
1534 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1535 desc->suite.aead.dec.count);
1536
1537out:
1538 crypto_free_aead(tfm);
1539 return err;
1540}
1541
1542static int alg_test_cipher(const struct alg_test_desc *desc,
1543 const char *driver, u32 type, u32 mask)
1544{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001545 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001546 int err = 0;
1547
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001548 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001549 if (IS_ERR(tfm)) {
1550 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1551 "%s: %ld\n", driver, PTR_ERR(tfm));
1552 return PTR_ERR(tfm);
1553 }
1554
1555 if (desc->suite.cipher.enc.vecs) {
1556 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1557 desc->suite.cipher.enc.count);
1558 if (err)
1559 goto out;
1560 }
1561
1562 if (desc->suite.cipher.dec.vecs)
1563 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1564 desc->suite.cipher.dec.count);
1565
1566out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001567 crypto_free_cipher(tfm);
1568 return err;
1569}
1570
1571static int alg_test_skcipher(const struct alg_test_desc *desc,
1572 const char *driver, u32 type, u32 mask)
1573{
1574 struct crypto_ablkcipher *tfm;
1575 int err = 0;
1576
1577 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1578 if (IS_ERR(tfm)) {
1579 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1580 "%s: %ld\n", driver, PTR_ERR(tfm));
1581 return PTR_ERR(tfm);
1582 }
1583
1584 if (desc->suite.cipher.enc.vecs) {
1585 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1586 desc->suite.cipher.enc.count);
1587 if (err)
1588 goto out;
1589 }
1590
1591 if (desc->suite.cipher.dec.vecs)
1592 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1593 desc->suite.cipher.dec.count);
1594
1595out:
Herbert Xuda7f0332008-07-31 17:08:25 +08001596 crypto_free_ablkcipher(tfm);
1597 return err;
1598}
1599
1600static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1601 u32 type, u32 mask)
1602{
1603 struct crypto_comp *tfm;
1604 int err;
1605
1606 tfm = crypto_alloc_comp(driver, type, mask);
1607 if (IS_ERR(tfm)) {
1608 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1609 "%ld\n", driver, PTR_ERR(tfm));
1610 return PTR_ERR(tfm);
1611 }
1612
1613 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1614 desc->suite.comp.decomp.vecs,
1615 desc->suite.comp.comp.count,
1616 desc->suite.comp.decomp.count);
1617
1618 crypto_free_comp(tfm);
1619 return err;
1620}
1621
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001622static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1623 u32 type, u32 mask)
1624{
1625 struct crypto_pcomp *tfm;
1626 int err;
1627
1628 tfm = crypto_alloc_pcomp(driver, type, mask);
1629 if (IS_ERR(tfm)) {
1630 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1631 driver, PTR_ERR(tfm));
1632 return PTR_ERR(tfm);
1633 }
1634
1635 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1636 desc->suite.pcomp.decomp.vecs,
1637 desc->suite.pcomp.comp.count,
1638 desc->suite.pcomp.decomp.count);
1639
1640 crypto_free_pcomp(tfm);
1641 return err;
1642}
1643
Herbert Xuda7f0332008-07-31 17:08:25 +08001644static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1645 u32 type, u32 mask)
1646{
1647 struct crypto_ahash *tfm;
1648 int err;
1649
1650 tfm = crypto_alloc_ahash(driver, type, mask);
1651 if (IS_ERR(tfm)) {
1652 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1653 "%ld\n", driver, PTR_ERR(tfm));
1654 return PTR_ERR(tfm);
1655 }
1656
David S. Millera8f1a052010-05-19 14:12:03 +10001657 err = test_hash(tfm, desc->suite.hash.vecs,
1658 desc->suite.hash.count, true);
1659 if (!err)
1660 err = test_hash(tfm, desc->suite.hash.vecs,
1661 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001662
1663 crypto_free_ahash(tfm);
1664 return err;
1665}
1666
Herbert Xu8e3ee852008-11-07 14:58:52 +08001667static int alg_test_crc32c(const struct alg_test_desc *desc,
1668 const char *driver, u32 type, u32 mask)
1669{
1670 struct crypto_shash *tfm;
1671 u32 val;
1672 int err;
1673
1674 err = alg_test_hash(desc, driver, type, mask);
1675 if (err)
1676 goto out;
1677
1678 tfm = crypto_alloc_shash(driver, type, mask);
1679 if (IS_ERR(tfm)) {
1680 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1681 "%ld\n", driver, PTR_ERR(tfm));
1682 err = PTR_ERR(tfm);
1683 goto out;
1684 }
1685
1686 do {
1687 struct {
1688 struct shash_desc shash;
1689 char ctx[crypto_shash_descsize(tfm)];
1690 } sdesc;
1691
1692 sdesc.shash.tfm = tfm;
1693 sdesc.shash.flags = 0;
1694
1695 *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1696 err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1697 if (err) {
1698 printk(KERN_ERR "alg: crc32c: Operation failed for "
1699 "%s: %d\n", driver, err);
1700 break;
1701 }
1702
1703 if (val != ~420553207) {
1704 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1705 "%d\n", driver, val);
1706 err = -EINVAL;
1707 }
1708 } while (0);
1709
1710 crypto_free_shash(tfm);
1711
1712out:
1713 return err;
1714}
1715
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001716static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1717 u32 type, u32 mask)
1718{
1719 struct crypto_rng *rng;
1720 int err;
1721
1722 rng = crypto_alloc_rng(driver, type, mask);
1723 if (IS_ERR(rng)) {
1724 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1725 "%ld\n", driver, PTR_ERR(rng));
1726 return PTR_ERR(rng);
1727 }
1728
1729 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1730
1731 crypto_free_rng(rng);
1732
1733 return err;
1734}
1735
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001736
1737static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1738 const char *driver, u32 type, u32 mask)
1739{
1740 int ret = -EAGAIN;
1741 struct crypto_rng *drng;
1742 struct drbg_test_data test_data;
1743 struct drbg_string addtl, pers, testentropy;
1744 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1745
1746 if (!buf)
1747 return -ENOMEM;
1748
1749 drng = crypto_alloc_rng(driver, type, mask);
1750 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001751 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001752 "%s\n", driver);
1753 kzfree(buf);
1754 return -ENOMEM;
1755 }
1756
1757 test_data.testentropy = &testentropy;
1758 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1759 drbg_string_fill(&pers, test->pers, test->perslen);
1760 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1761 if (ret) {
1762 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1763 goto outbuf;
1764 }
1765
1766 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1767 if (pr) {
1768 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1769 ret = crypto_drbg_get_bytes_addtl_test(drng,
1770 buf, test->expectedlen, &addtl, &test_data);
1771 } else {
1772 ret = crypto_drbg_get_bytes_addtl(drng,
1773 buf, test->expectedlen, &addtl);
1774 }
1775 if (ret <= 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001776 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001777 "driver %s\n", driver);
1778 goto outbuf;
1779 }
1780
1781 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1782 if (pr) {
1783 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1784 ret = crypto_drbg_get_bytes_addtl_test(drng,
1785 buf, test->expectedlen, &addtl, &test_data);
1786 } else {
1787 ret = crypto_drbg_get_bytes_addtl(drng,
1788 buf, test->expectedlen, &addtl);
1789 }
1790 if (ret <= 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001791 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001792 "driver %s\n", driver);
1793 goto outbuf;
1794 }
1795
1796 ret = memcmp(test->expected, buf, test->expectedlen);
1797
1798outbuf:
1799 crypto_free_rng(drng);
1800 kzfree(buf);
1801 return ret;
1802}
1803
1804
1805static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1806 u32 type, u32 mask)
1807{
1808 int err = 0;
1809 int pr = 0;
1810 int i = 0;
1811 struct drbg_testvec *template = desc->suite.drbg.vecs;
1812 unsigned int tcount = desc->suite.drbg.count;
1813
1814 if (0 == memcmp(driver, "drbg_pr_", 8))
1815 pr = 1;
1816
1817 for (i = 0; i < tcount; i++) {
1818 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1819 if (err) {
1820 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1821 i, driver);
1822 err = -EINVAL;
1823 break;
1824 }
1825 }
1826 return err;
1827
1828}
1829
Youquan, Song863b5572009-12-23 19:45:20 +08001830static int alg_test_null(const struct alg_test_desc *desc,
1831 const char *driver, u32 type, u32 mask)
1832{
1833 return 0;
1834}
1835
Herbert Xuda7f0332008-07-31 17:08:25 +08001836/* Please keep this list sorted by algorithm name. */
1837static const struct alg_test_desc alg_test_descs[] = {
1838 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001839 .alg = "__cbc-cast5-avx",
1840 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001841 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001842 .alg = "__cbc-cast6-avx",
1843 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001844 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001845 .alg = "__cbc-serpent-avx",
1846 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001847 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001848 .alg = "__cbc-serpent-avx2",
1849 .test = alg_test_null,
1850 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001851 .alg = "__cbc-serpent-sse2",
1852 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001853 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001854 .alg = "__cbc-twofish-avx",
1855 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001856 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001857 .alg = "__driver-cbc-aes-aesni",
1858 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001859 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001860 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001861 .alg = "__driver-cbc-camellia-aesni",
1862 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001863 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001864 .alg = "__driver-cbc-camellia-aesni-avx2",
1865 .test = alg_test_null,
1866 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001867 .alg = "__driver-cbc-cast5-avx",
1868 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001869 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001870 .alg = "__driver-cbc-cast6-avx",
1871 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001872 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001873 .alg = "__driver-cbc-serpent-avx",
1874 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001875 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001876 .alg = "__driver-cbc-serpent-avx2",
1877 .test = alg_test_null,
1878 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001879 .alg = "__driver-cbc-serpent-sse2",
1880 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001881 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001882 .alg = "__driver-cbc-twofish-avx",
1883 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001884 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001885 .alg = "__driver-ecb-aes-aesni",
1886 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001887 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001888 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001889 .alg = "__driver-ecb-camellia-aesni",
1890 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001891 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001892 .alg = "__driver-ecb-camellia-aesni-avx2",
1893 .test = alg_test_null,
1894 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001895 .alg = "__driver-ecb-cast5-avx",
1896 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001897 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001898 .alg = "__driver-ecb-cast6-avx",
1899 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001900 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001901 .alg = "__driver-ecb-serpent-avx",
1902 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001903 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001904 .alg = "__driver-ecb-serpent-avx2",
1905 .test = alg_test_null,
1906 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001907 .alg = "__driver-ecb-serpent-sse2",
1908 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001909 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001910 .alg = "__driver-ecb-twofish-avx",
1911 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001912 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001913 .alg = "__ghash-pclmulqdqni",
1914 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001915 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001916 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001917 .alg = "ansi_cprng",
1918 .test = alg_test_cprng,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001919 .fips_allowed = 1,
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001920 .suite = {
1921 .cprng = {
1922 .vecs = ansi_cprng_aes_tv_template,
1923 .count = ANSI_CPRNG_AES_TEST_VECTORS
1924 }
1925 }
1926 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001927 .alg = "authenc(hmac(md5),ecb(cipher_null))",
1928 .test = alg_test_aead,
1929 .fips_allowed = 1,
1930 .suite = {
1931 .aead = {
1932 .enc = {
1933 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
1934 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1935 },
1936 .dec = {
1937 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
1938 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1939 }
1940 }
1941 }
1942 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03001943 .alg = "authenc(hmac(sha1),cbc(aes))",
1944 .test = alg_test_aead,
1945 .fips_allowed = 1,
1946 .suite = {
1947 .aead = {
1948 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301949 .vecs =
1950 hmac_sha1_aes_cbc_enc_tv_temp,
1951 .count =
1952 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1953 }
1954 }
1955 }
1956 }, {
1957 .alg = "authenc(hmac(sha1),cbc(des))",
1958 .test = alg_test_aead,
1959 .fips_allowed = 1,
1960 .suite = {
1961 .aead = {
1962 .enc = {
1963 .vecs =
1964 hmac_sha1_des_cbc_enc_tv_temp,
1965 .count =
1966 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1967 }
1968 }
1969 }
1970 }, {
1971 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
1972 .test = alg_test_aead,
1973 .fips_allowed = 1,
1974 .suite = {
1975 .aead = {
1976 .enc = {
1977 .vecs =
1978 hmac_sha1_des3_ede_cbc_enc_tv_temp,
1979 .count =
1980 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03001981 }
1982 }
1983 }
1984 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001985 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
1986 .test = alg_test_aead,
1987 .fips_allowed = 1,
1988 .suite = {
1989 .aead = {
1990 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301991 .vecs =
1992 hmac_sha1_ecb_cipher_null_enc_tv_temp,
1993 .count =
1994 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02001995 },
1996 .dec = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301997 .vecs =
1998 hmac_sha1_ecb_cipher_null_dec_tv_temp,
1999 .count =
2000 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
2001 }
2002 }
2003 }
2004 }, {
2005 .alg = "authenc(hmac(sha224),cbc(des))",
2006 .test = alg_test_aead,
2007 .fips_allowed = 1,
2008 .suite = {
2009 .aead = {
2010 .enc = {
2011 .vecs =
2012 hmac_sha224_des_cbc_enc_tv_temp,
2013 .count =
2014 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2015 }
2016 }
2017 }
2018 }, {
2019 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
2020 .test = alg_test_aead,
2021 .fips_allowed = 1,
2022 .suite = {
2023 .aead = {
2024 .enc = {
2025 .vecs =
2026 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2027 .count =
2028 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002029 }
2030 }
2031 }
2032 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03002033 .alg = "authenc(hmac(sha256),cbc(aes))",
2034 .test = alg_test_aead,
2035 .fips_allowed = 1,
2036 .suite = {
2037 .aead = {
2038 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302039 .vecs =
2040 hmac_sha256_aes_cbc_enc_tv_temp,
2041 .count =
2042 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2043 }
2044 }
2045 }
2046 }, {
2047 .alg = "authenc(hmac(sha256),cbc(des))",
2048 .test = alg_test_aead,
2049 .fips_allowed = 1,
2050 .suite = {
2051 .aead = {
2052 .enc = {
2053 .vecs =
2054 hmac_sha256_des_cbc_enc_tv_temp,
2055 .count =
2056 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2057 }
2058 }
2059 }
2060 }, {
2061 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
2062 .test = alg_test_aead,
2063 .fips_allowed = 1,
2064 .suite = {
2065 .aead = {
2066 .enc = {
2067 .vecs =
2068 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2069 .count =
2070 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2071 }
2072 }
2073 }
2074 }, {
2075 .alg = "authenc(hmac(sha384),cbc(des))",
2076 .test = alg_test_aead,
2077 .fips_allowed = 1,
2078 .suite = {
2079 .aead = {
2080 .enc = {
2081 .vecs =
2082 hmac_sha384_des_cbc_enc_tv_temp,
2083 .count =
2084 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2085 }
2086 }
2087 }
2088 }, {
2089 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
2090 .test = alg_test_aead,
2091 .fips_allowed = 1,
2092 .suite = {
2093 .aead = {
2094 .enc = {
2095 .vecs =
2096 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2097 .count =
2098 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002099 }
2100 }
2101 }
2102 }, {
2103 .alg = "authenc(hmac(sha512),cbc(aes))",
2104 .test = alg_test_aead,
2105 .fips_allowed = 1,
2106 .suite = {
2107 .aead = {
2108 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302109 .vecs =
2110 hmac_sha512_aes_cbc_enc_tv_temp,
2111 .count =
2112 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2113 }
2114 }
2115 }
2116 }, {
2117 .alg = "authenc(hmac(sha512),cbc(des))",
2118 .test = alg_test_aead,
2119 .fips_allowed = 1,
2120 .suite = {
2121 .aead = {
2122 .enc = {
2123 .vecs =
2124 hmac_sha512_des_cbc_enc_tv_temp,
2125 .count =
2126 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2127 }
2128 }
2129 }
2130 }, {
2131 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2132 .test = alg_test_aead,
2133 .fips_allowed = 1,
2134 .suite = {
2135 .aead = {
2136 .enc = {
2137 .vecs =
2138 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2139 .count =
2140 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002141 }
2142 }
2143 }
2144 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002145 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002146 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002147 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002148 .suite = {
2149 .cipher = {
2150 .enc = {
2151 .vecs = aes_cbc_enc_tv_template,
2152 .count = AES_CBC_ENC_TEST_VECTORS
2153 },
2154 .dec = {
2155 .vecs = aes_cbc_dec_tv_template,
2156 .count = AES_CBC_DEC_TEST_VECTORS
2157 }
2158 }
2159 }
2160 }, {
2161 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002162 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002163 .suite = {
2164 .cipher = {
2165 .enc = {
2166 .vecs = anubis_cbc_enc_tv_template,
2167 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2168 },
2169 .dec = {
2170 .vecs = anubis_cbc_dec_tv_template,
2171 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2172 }
2173 }
2174 }
2175 }, {
2176 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002177 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002178 .suite = {
2179 .cipher = {
2180 .enc = {
2181 .vecs = bf_cbc_enc_tv_template,
2182 .count = BF_CBC_ENC_TEST_VECTORS
2183 },
2184 .dec = {
2185 .vecs = bf_cbc_dec_tv_template,
2186 .count = BF_CBC_DEC_TEST_VECTORS
2187 }
2188 }
2189 }
2190 }, {
2191 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002192 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002193 .suite = {
2194 .cipher = {
2195 .enc = {
2196 .vecs = camellia_cbc_enc_tv_template,
2197 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2198 },
2199 .dec = {
2200 .vecs = camellia_cbc_dec_tv_template,
2201 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2202 }
2203 }
2204 }
2205 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002206 .alg = "cbc(cast5)",
2207 .test = alg_test_skcipher,
2208 .suite = {
2209 .cipher = {
2210 .enc = {
2211 .vecs = cast5_cbc_enc_tv_template,
2212 .count = CAST5_CBC_ENC_TEST_VECTORS
2213 },
2214 .dec = {
2215 .vecs = cast5_cbc_dec_tv_template,
2216 .count = CAST5_CBC_DEC_TEST_VECTORS
2217 }
2218 }
2219 }
2220 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002221 .alg = "cbc(cast6)",
2222 .test = alg_test_skcipher,
2223 .suite = {
2224 .cipher = {
2225 .enc = {
2226 .vecs = cast6_cbc_enc_tv_template,
2227 .count = CAST6_CBC_ENC_TEST_VECTORS
2228 },
2229 .dec = {
2230 .vecs = cast6_cbc_dec_tv_template,
2231 .count = CAST6_CBC_DEC_TEST_VECTORS
2232 }
2233 }
2234 }
2235 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002236 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002237 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002238 .suite = {
2239 .cipher = {
2240 .enc = {
2241 .vecs = des_cbc_enc_tv_template,
2242 .count = DES_CBC_ENC_TEST_VECTORS
2243 },
2244 .dec = {
2245 .vecs = des_cbc_dec_tv_template,
2246 .count = DES_CBC_DEC_TEST_VECTORS
2247 }
2248 }
2249 }
2250 }, {
2251 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002252 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002253 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002254 .suite = {
2255 .cipher = {
2256 .enc = {
2257 .vecs = des3_ede_cbc_enc_tv_template,
2258 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2259 },
2260 .dec = {
2261 .vecs = des3_ede_cbc_dec_tv_template,
2262 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2263 }
2264 }
2265 }
2266 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002267 .alg = "cbc(serpent)",
2268 .test = alg_test_skcipher,
2269 .suite = {
2270 .cipher = {
2271 .enc = {
2272 .vecs = serpent_cbc_enc_tv_template,
2273 .count = SERPENT_CBC_ENC_TEST_VECTORS
2274 },
2275 .dec = {
2276 .vecs = serpent_cbc_dec_tv_template,
2277 .count = SERPENT_CBC_DEC_TEST_VECTORS
2278 }
2279 }
2280 }
2281 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002282 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002283 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002284 .suite = {
2285 .cipher = {
2286 .enc = {
2287 .vecs = tf_cbc_enc_tv_template,
2288 .count = TF_CBC_ENC_TEST_VECTORS
2289 },
2290 .dec = {
2291 .vecs = tf_cbc_dec_tv_template,
2292 .count = TF_CBC_DEC_TEST_VECTORS
2293 }
2294 }
2295 }
2296 }, {
2297 .alg = "ccm(aes)",
2298 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002299 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002300 .suite = {
2301 .aead = {
2302 .enc = {
2303 .vecs = aes_ccm_enc_tv_template,
2304 .count = AES_CCM_ENC_TEST_VECTORS
2305 },
2306 .dec = {
2307 .vecs = aes_ccm_dec_tv_template,
2308 .count = AES_CCM_DEC_TEST_VECTORS
2309 }
2310 }
2311 }
2312 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002313 .alg = "cmac(aes)",
2314 .test = alg_test_hash,
2315 .suite = {
2316 .hash = {
2317 .vecs = aes_cmac128_tv_template,
2318 .count = CMAC_AES_TEST_VECTORS
2319 }
2320 }
2321 }, {
2322 .alg = "cmac(des3_ede)",
2323 .test = alg_test_hash,
2324 .suite = {
2325 .hash = {
2326 .vecs = des3_ede_cmac64_tv_template,
2327 .count = CMAC_DES3_EDE_TEST_VECTORS
2328 }
2329 }
2330 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002331 .alg = "compress_null",
2332 .test = alg_test_null,
2333 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002334 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002335 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002336 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002337 .suite = {
2338 .hash = {
2339 .vecs = crc32c_tv_template,
2340 .count = CRC32C_TEST_VECTORS
2341 }
2342 }
2343 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002344 .alg = "crct10dif",
2345 .test = alg_test_hash,
2346 .fips_allowed = 1,
2347 .suite = {
2348 .hash = {
2349 .vecs = crct10dif_tv_template,
2350 .count = CRCT10DIF_TEST_VECTORS
2351 }
2352 }
2353 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002354 .alg = "cryptd(__driver-cbc-aes-aesni)",
2355 .test = alg_test_null,
2356 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002357 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002358 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2359 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002360 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002361 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2362 .test = alg_test_null,
2363 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002364 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2365 .test = alg_test_null,
2366 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002367 .alg = "cryptd(__driver-ecb-aes-aesni)",
2368 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002369 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002370 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002371 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2372 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002373 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002374 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2375 .test = alg_test_null,
2376 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002377 .alg = "cryptd(__driver-ecb-cast5-avx)",
2378 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002379 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002380 .alg = "cryptd(__driver-ecb-cast6-avx)",
2381 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002382 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002383 .alg = "cryptd(__driver-ecb-serpent-avx)",
2384 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002385 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002386 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2387 .test = alg_test_null,
2388 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002389 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2390 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002391 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002392 .alg = "cryptd(__driver-ecb-twofish-avx)",
2393 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002394 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002395 .alg = "cryptd(__driver-gcm-aes-aesni)",
2396 .test = alg_test_null,
2397 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002398 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002399 .alg = "cryptd(__ghash-pclmulqdqni)",
2400 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002401 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002402 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002403 .alg = "ctr(aes)",
2404 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002405 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002406 .suite = {
2407 .cipher = {
2408 .enc = {
2409 .vecs = aes_ctr_enc_tv_template,
2410 .count = AES_CTR_ENC_TEST_VECTORS
2411 },
2412 .dec = {
2413 .vecs = aes_ctr_dec_tv_template,
2414 .count = AES_CTR_DEC_TEST_VECTORS
2415 }
2416 }
2417 }
2418 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002419 .alg = "ctr(blowfish)",
2420 .test = alg_test_skcipher,
2421 .suite = {
2422 .cipher = {
2423 .enc = {
2424 .vecs = bf_ctr_enc_tv_template,
2425 .count = BF_CTR_ENC_TEST_VECTORS
2426 },
2427 .dec = {
2428 .vecs = bf_ctr_dec_tv_template,
2429 .count = BF_CTR_DEC_TEST_VECTORS
2430 }
2431 }
2432 }
2433 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002434 .alg = "ctr(camellia)",
2435 .test = alg_test_skcipher,
2436 .suite = {
2437 .cipher = {
2438 .enc = {
2439 .vecs = camellia_ctr_enc_tv_template,
2440 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2441 },
2442 .dec = {
2443 .vecs = camellia_ctr_dec_tv_template,
2444 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2445 }
2446 }
2447 }
2448 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002449 .alg = "ctr(cast5)",
2450 .test = alg_test_skcipher,
2451 .suite = {
2452 .cipher = {
2453 .enc = {
2454 .vecs = cast5_ctr_enc_tv_template,
2455 .count = CAST5_CTR_ENC_TEST_VECTORS
2456 },
2457 .dec = {
2458 .vecs = cast5_ctr_dec_tv_template,
2459 .count = CAST5_CTR_DEC_TEST_VECTORS
2460 }
2461 }
2462 }
2463 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002464 .alg = "ctr(cast6)",
2465 .test = alg_test_skcipher,
2466 .suite = {
2467 .cipher = {
2468 .enc = {
2469 .vecs = cast6_ctr_enc_tv_template,
2470 .count = CAST6_CTR_ENC_TEST_VECTORS
2471 },
2472 .dec = {
2473 .vecs = cast6_ctr_dec_tv_template,
2474 .count = CAST6_CTR_DEC_TEST_VECTORS
2475 }
2476 }
2477 }
2478 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002479 .alg = "ctr(des)",
2480 .test = alg_test_skcipher,
2481 .suite = {
2482 .cipher = {
2483 .enc = {
2484 .vecs = des_ctr_enc_tv_template,
2485 .count = DES_CTR_ENC_TEST_VECTORS
2486 },
2487 .dec = {
2488 .vecs = des_ctr_dec_tv_template,
2489 .count = DES_CTR_DEC_TEST_VECTORS
2490 }
2491 }
2492 }
2493 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002494 .alg = "ctr(des3_ede)",
2495 .test = alg_test_skcipher,
2496 .suite = {
2497 .cipher = {
2498 .enc = {
2499 .vecs = des3_ede_ctr_enc_tv_template,
2500 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2501 },
2502 .dec = {
2503 .vecs = des3_ede_ctr_dec_tv_template,
2504 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2505 }
2506 }
2507 }
2508 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002509 .alg = "ctr(serpent)",
2510 .test = alg_test_skcipher,
2511 .suite = {
2512 .cipher = {
2513 .enc = {
2514 .vecs = serpent_ctr_enc_tv_template,
2515 .count = SERPENT_CTR_ENC_TEST_VECTORS
2516 },
2517 .dec = {
2518 .vecs = serpent_ctr_dec_tv_template,
2519 .count = SERPENT_CTR_DEC_TEST_VECTORS
2520 }
2521 }
2522 }
2523 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002524 .alg = "ctr(twofish)",
2525 .test = alg_test_skcipher,
2526 .suite = {
2527 .cipher = {
2528 .enc = {
2529 .vecs = tf_ctr_enc_tv_template,
2530 .count = TF_CTR_ENC_TEST_VECTORS
2531 },
2532 .dec = {
2533 .vecs = tf_ctr_dec_tv_template,
2534 .count = TF_CTR_DEC_TEST_VECTORS
2535 }
2536 }
2537 }
2538 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002539 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002540 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002541 .suite = {
2542 .cipher = {
2543 .enc = {
2544 .vecs = cts_mode_enc_tv_template,
2545 .count = CTS_MODE_ENC_TEST_VECTORS
2546 },
2547 .dec = {
2548 .vecs = cts_mode_dec_tv_template,
2549 .count = CTS_MODE_DEC_TEST_VECTORS
2550 }
2551 }
2552 }
2553 }, {
2554 .alg = "deflate",
2555 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002556 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002557 .suite = {
2558 .comp = {
2559 .comp = {
2560 .vecs = deflate_comp_tv_template,
2561 .count = DEFLATE_COMP_TEST_VECTORS
2562 },
2563 .decomp = {
2564 .vecs = deflate_decomp_tv_template,
2565 .count = DEFLATE_DECOMP_TEST_VECTORS
2566 }
2567 }
2568 }
2569 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002570 .alg = "digest_null",
2571 .test = alg_test_null,
2572 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002573 .alg = "drbg_nopr_ctr_aes128",
2574 .test = alg_test_drbg,
2575 .fips_allowed = 1,
2576 .suite = {
2577 .drbg = {
2578 .vecs = drbg_nopr_ctr_aes128_tv_template,
2579 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2580 }
2581 }
2582 }, {
2583 .alg = "drbg_nopr_ctr_aes192",
2584 .test = alg_test_drbg,
2585 .fips_allowed = 1,
2586 .suite = {
2587 .drbg = {
2588 .vecs = drbg_nopr_ctr_aes192_tv_template,
2589 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2590 }
2591 }
2592 }, {
2593 .alg = "drbg_nopr_ctr_aes256",
2594 .test = alg_test_drbg,
2595 .fips_allowed = 1,
2596 .suite = {
2597 .drbg = {
2598 .vecs = drbg_nopr_ctr_aes256_tv_template,
2599 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2600 }
2601 }
2602 }, {
2603 /*
2604 * There is no need to specifically test the DRBG with every
2605 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2606 */
2607 .alg = "drbg_nopr_hmac_sha1",
2608 .fips_allowed = 1,
2609 .test = alg_test_null,
2610 }, {
2611 .alg = "drbg_nopr_hmac_sha256",
2612 .test = alg_test_drbg,
2613 .fips_allowed = 1,
2614 .suite = {
2615 .drbg = {
2616 .vecs = drbg_nopr_hmac_sha256_tv_template,
2617 .count =
2618 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2619 }
2620 }
2621 }, {
2622 /* covered by drbg_nopr_hmac_sha256 test */
2623 .alg = "drbg_nopr_hmac_sha384",
2624 .fips_allowed = 1,
2625 .test = alg_test_null,
2626 }, {
2627 .alg = "drbg_nopr_hmac_sha512",
2628 .test = alg_test_null,
2629 .fips_allowed = 1,
2630 }, {
2631 .alg = "drbg_nopr_sha1",
2632 .fips_allowed = 1,
2633 .test = alg_test_null,
2634 }, {
2635 .alg = "drbg_nopr_sha256",
2636 .test = alg_test_drbg,
2637 .fips_allowed = 1,
2638 .suite = {
2639 .drbg = {
2640 .vecs = drbg_nopr_sha256_tv_template,
2641 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2642 }
2643 }
2644 }, {
2645 /* covered by drbg_nopr_sha256 test */
2646 .alg = "drbg_nopr_sha384",
2647 .fips_allowed = 1,
2648 .test = alg_test_null,
2649 }, {
2650 .alg = "drbg_nopr_sha512",
2651 .fips_allowed = 1,
2652 .test = alg_test_null,
2653 }, {
2654 .alg = "drbg_pr_ctr_aes128",
2655 .test = alg_test_drbg,
2656 .fips_allowed = 1,
2657 .suite = {
2658 .drbg = {
2659 .vecs = drbg_pr_ctr_aes128_tv_template,
2660 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2661 }
2662 }
2663 }, {
2664 /* covered by drbg_pr_ctr_aes128 test */
2665 .alg = "drbg_pr_ctr_aes192",
2666 .fips_allowed = 1,
2667 .test = alg_test_null,
2668 }, {
2669 .alg = "drbg_pr_ctr_aes256",
2670 .fips_allowed = 1,
2671 .test = alg_test_null,
2672 }, {
2673 .alg = "drbg_pr_hmac_sha1",
2674 .fips_allowed = 1,
2675 .test = alg_test_null,
2676 }, {
2677 .alg = "drbg_pr_hmac_sha256",
2678 .test = alg_test_drbg,
2679 .fips_allowed = 1,
2680 .suite = {
2681 .drbg = {
2682 .vecs = drbg_pr_hmac_sha256_tv_template,
2683 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2684 }
2685 }
2686 }, {
2687 /* covered by drbg_pr_hmac_sha256 test */
2688 .alg = "drbg_pr_hmac_sha384",
2689 .fips_allowed = 1,
2690 .test = alg_test_null,
2691 }, {
2692 .alg = "drbg_pr_hmac_sha512",
2693 .test = alg_test_null,
2694 .fips_allowed = 1,
2695 }, {
2696 .alg = "drbg_pr_sha1",
2697 .fips_allowed = 1,
2698 .test = alg_test_null,
2699 }, {
2700 .alg = "drbg_pr_sha256",
2701 .test = alg_test_drbg,
2702 .fips_allowed = 1,
2703 .suite = {
2704 .drbg = {
2705 .vecs = drbg_pr_sha256_tv_template,
2706 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2707 }
2708 }
2709 }, {
2710 /* covered by drbg_pr_sha256 test */
2711 .alg = "drbg_pr_sha384",
2712 .fips_allowed = 1,
2713 .test = alg_test_null,
2714 }, {
2715 .alg = "drbg_pr_sha512",
2716 .fips_allowed = 1,
2717 .test = alg_test_null,
2718 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002719 .alg = "ecb(__aes-aesni)",
2720 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002721 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002722 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002723 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002724 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002725 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002726 .suite = {
2727 .cipher = {
2728 .enc = {
2729 .vecs = aes_enc_tv_template,
2730 .count = AES_ENC_TEST_VECTORS
2731 },
2732 .dec = {
2733 .vecs = aes_dec_tv_template,
2734 .count = AES_DEC_TEST_VECTORS
2735 }
2736 }
2737 }
2738 }, {
2739 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002740 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002741 .suite = {
2742 .cipher = {
2743 .enc = {
2744 .vecs = anubis_enc_tv_template,
2745 .count = ANUBIS_ENC_TEST_VECTORS
2746 },
2747 .dec = {
2748 .vecs = anubis_dec_tv_template,
2749 .count = ANUBIS_DEC_TEST_VECTORS
2750 }
2751 }
2752 }
2753 }, {
2754 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002755 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002756 .suite = {
2757 .cipher = {
2758 .enc = {
2759 .vecs = arc4_enc_tv_template,
2760 .count = ARC4_ENC_TEST_VECTORS
2761 },
2762 .dec = {
2763 .vecs = arc4_dec_tv_template,
2764 .count = ARC4_DEC_TEST_VECTORS
2765 }
2766 }
2767 }
2768 }, {
2769 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002770 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002771 .suite = {
2772 .cipher = {
2773 .enc = {
2774 .vecs = bf_enc_tv_template,
2775 .count = BF_ENC_TEST_VECTORS
2776 },
2777 .dec = {
2778 .vecs = bf_dec_tv_template,
2779 .count = BF_DEC_TEST_VECTORS
2780 }
2781 }
2782 }
2783 }, {
2784 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002785 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002786 .suite = {
2787 .cipher = {
2788 .enc = {
2789 .vecs = camellia_enc_tv_template,
2790 .count = CAMELLIA_ENC_TEST_VECTORS
2791 },
2792 .dec = {
2793 .vecs = camellia_dec_tv_template,
2794 .count = CAMELLIA_DEC_TEST_VECTORS
2795 }
2796 }
2797 }
2798 }, {
2799 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002800 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002801 .suite = {
2802 .cipher = {
2803 .enc = {
2804 .vecs = cast5_enc_tv_template,
2805 .count = CAST5_ENC_TEST_VECTORS
2806 },
2807 .dec = {
2808 .vecs = cast5_dec_tv_template,
2809 .count = CAST5_DEC_TEST_VECTORS
2810 }
2811 }
2812 }
2813 }, {
2814 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002815 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002816 .suite = {
2817 .cipher = {
2818 .enc = {
2819 .vecs = cast6_enc_tv_template,
2820 .count = CAST6_ENC_TEST_VECTORS
2821 },
2822 .dec = {
2823 .vecs = cast6_dec_tv_template,
2824 .count = CAST6_DEC_TEST_VECTORS
2825 }
2826 }
2827 }
2828 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002829 .alg = "ecb(cipher_null)",
2830 .test = alg_test_null,
2831 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002832 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002833 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002834 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002835 .suite = {
2836 .cipher = {
2837 .enc = {
2838 .vecs = des_enc_tv_template,
2839 .count = DES_ENC_TEST_VECTORS
2840 },
2841 .dec = {
2842 .vecs = des_dec_tv_template,
2843 .count = DES_DEC_TEST_VECTORS
2844 }
2845 }
2846 }
2847 }, {
2848 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002849 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002850 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002851 .suite = {
2852 .cipher = {
2853 .enc = {
2854 .vecs = des3_ede_enc_tv_template,
2855 .count = DES3_EDE_ENC_TEST_VECTORS
2856 },
2857 .dec = {
2858 .vecs = des3_ede_dec_tv_template,
2859 .count = DES3_EDE_DEC_TEST_VECTORS
2860 }
2861 }
2862 }
2863 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002864 .alg = "ecb(fcrypt)",
2865 .test = alg_test_skcipher,
2866 .suite = {
2867 .cipher = {
2868 .enc = {
2869 .vecs = fcrypt_pcbc_enc_tv_template,
2870 .count = 1
2871 },
2872 .dec = {
2873 .vecs = fcrypt_pcbc_dec_tv_template,
2874 .count = 1
2875 }
2876 }
2877 }
2878 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002879 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002880 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002881 .suite = {
2882 .cipher = {
2883 .enc = {
2884 .vecs = khazad_enc_tv_template,
2885 .count = KHAZAD_ENC_TEST_VECTORS
2886 },
2887 .dec = {
2888 .vecs = khazad_dec_tv_template,
2889 .count = KHAZAD_DEC_TEST_VECTORS
2890 }
2891 }
2892 }
2893 }, {
2894 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002895 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002896 .suite = {
2897 .cipher = {
2898 .enc = {
2899 .vecs = seed_enc_tv_template,
2900 .count = SEED_ENC_TEST_VECTORS
2901 },
2902 .dec = {
2903 .vecs = seed_dec_tv_template,
2904 .count = SEED_DEC_TEST_VECTORS
2905 }
2906 }
2907 }
2908 }, {
2909 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002910 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002911 .suite = {
2912 .cipher = {
2913 .enc = {
2914 .vecs = serpent_enc_tv_template,
2915 .count = SERPENT_ENC_TEST_VECTORS
2916 },
2917 .dec = {
2918 .vecs = serpent_dec_tv_template,
2919 .count = SERPENT_DEC_TEST_VECTORS
2920 }
2921 }
2922 }
2923 }, {
2924 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002925 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002926 .suite = {
2927 .cipher = {
2928 .enc = {
2929 .vecs = tea_enc_tv_template,
2930 .count = TEA_ENC_TEST_VECTORS
2931 },
2932 .dec = {
2933 .vecs = tea_dec_tv_template,
2934 .count = TEA_DEC_TEST_VECTORS
2935 }
2936 }
2937 }
2938 }, {
2939 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002940 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002941 .suite = {
2942 .cipher = {
2943 .enc = {
2944 .vecs = tnepres_enc_tv_template,
2945 .count = TNEPRES_ENC_TEST_VECTORS
2946 },
2947 .dec = {
2948 .vecs = tnepres_dec_tv_template,
2949 .count = TNEPRES_DEC_TEST_VECTORS
2950 }
2951 }
2952 }
2953 }, {
2954 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002955 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002956 .suite = {
2957 .cipher = {
2958 .enc = {
2959 .vecs = tf_enc_tv_template,
2960 .count = TF_ENC_TEST_VECTORS
2961 },
2962 .dec = {
2963 .vecs = tf_dec_tv_template,
2964 .count = TF_DEC_TEST_VECTORS
2965 }
2966 }
2967 }
2968 }, {
2969 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002970 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002971 .suite = {
2972 .cipher = {
2973 .enc = {
2974 .vecs = xeta_enc_tv_template,
2975 .count = XETA_ENC_TEST_VECTORS
2976 },
2977 .dec = {
2978 .vecs = xeta_dec_tv_template,
2979 .count = XETA_DEC_TEST_VECTORS
2980 }
2981 }
2982 }
2983 }, {
2984 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002985 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002986 .suite = {
2987 .cipher = {
2988 .enc = {
2989 .vecs = xtea_enc_tv_template,
2990 .count = XTEA_ENC_TEST_VECTORS
2991 },
2992 .dec = {
2993 .vecs = xtea_dec_tv_template,
2994 .count = XTEA_DEC_TEST_VECTORS
2995 }
2996 }
2997 }
2998 }, {
2999 .alg = "gcm(aes)",
3000 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003001 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003002 .suite = {
3003 .aead = {
3004 .enc = {
3005 .vecs = aes_gcm_enc_tv_template,
3006 .count = AES_GCM_ENC_TEST_VECTORS
3007 },
3008 .dec = {
3009 .vecs = aes_gcm_dec_tv_template,
3010 .count = AES_GCM_DEC_TEST_VECTORS
3011 }
3012 }
3013 }
3014 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003015 .alg = "ghash",
3016 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003017 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003018 .suite = {
3019 .hash = {
3020 .vecs = ghash_tv_template,
3021 .count = GHASH_TEST_VECTORS
3022 }
3023 }
3024 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003025 .alg = "hmac(crc32)",
3026 .test = alg_test_hash,
3027 .suite = {
3028 .hash = {
3029 .vecs = bfin_crc_tv_template,
3030 .count = BFIN_CRC_TEST_VECTORS
3031 }
3032 }
3033 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003034 .alg = "hmac(md5)",
3035 .test = alg_test_hash,
3036 .suite = {
3037 .hash = {
3038 .vecs = hmac_md5_tv_template,
3039 .count = HMAC_MD5_TEST_VECTORS
3040 }
3041 }
3042 }, {
3043 .alg = "hmac(rmd128)",
3044 .test = alg_test_hash,
3045 .suite = {
3046 .hash = {
3047 .vecs = hmac_rmd128_tv_template,
3048 .count = HMAC_RMD128_TEST_VECTORS
3049 }
3050 }
3051 }, {
3052 .alg = "hmac(rmd160)",
3053 .test = alg_test_hash,
3054 .suite = {
3055 .hash = {
3056 .vecs = hmac_rmd160_tv_template,
3057 .count = HMAC_RMD160_TEST_VECTORS
3058 }
3059 }
3060 }, {
3061 .alg = "hmac(sha1)",
3062 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003063 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003064 .suite = {
3065 .hash = {
3066 .vecs = hmac_sha1_tv_template,
3067 .count = HMAC_SHA1_TEST_VECTORS
3068 }
3069 }
3070 }, {
3071 .alg = "hmac(sha224)",
3072 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003073 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003074 .suite = {
3075 .hash = {
3076 .vecs = hmac_sha224_tv_template,
3077 .count = HMAC_SHA224_TEST_VECTORS
3078 }
3079 }
3080 }, {
3081 .alg = "hmac(sha256)",
3082 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003083 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003084 .suite = {
3085 .hash = {
3086 .vecs = hmac_sha256_tv_template,
3087 .count = HMAC_SHA256_TEST_VECTORS
3088 }
3089 }
3090 }, {
3091 .alg = "hmac(sha384)",
3092 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003093 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003094 .suite = {
3095 .hash = {
3096 .vecs = hmac_sha384_tv_template,
3097 .count = HMAC_SHA384_TEST_VECTORS
3098 }
3099 }
3100 }, {
3101 .alg = "hmac(sha512)",
3102 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003103 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003104 .suite = {
3105 .hash = {
3106 .vecs = hmac_sha512_tv_template,
3107 .count = HMAC_SHA512_TEST_VECTORS
3108 }
3109 }
3110 }, {
3111 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003112 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003113 .suite = {
3114 .cipher = {
3115 .enc = {
3116 .vecs = aes_lrw_enc_tv_template,
3117 .count = AES_LRW_ENC_TEST_VECTORS
3118 },
3119 .dec = {
3120 .vecs = aes_lrw_dec_tv_template,
3121 .count = AES_LRW_DEC_TEST_VECTORS
3122 }
3123 }
3124 }
3125 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003126 .alg = "lrw(camellia)",
3127 .test = alg_test_skcipher,
3128 .suite = {
3129 .cipher = {
3130 .enc = {
3131 .vecs = camellia_lrw_enc_tv_template,
3132 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3133 },
3134 .dec = {
3135 .vecs = camellia_lrw_dec_tv_template,
3136 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3137 }
3138 }
3139 }
3140 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003141 .alg = "lrw(cast6)",
3142 .test = alg_test_skcipher,
3143 .suite = {
3144 .cipher = {
3145 .enc = {
3146 .vecs = cast6_lrw_enc_tv_template,
3147 .count = CAST6_LRW_ENC_TEST_VECTORS
3148 },
3149 .dec = {
3150 .vecs = cast6_lrw_dec_tv_template,
3151 .count = CAST6_LRW_DEC_TEST_VECTORS
3152 }
3153 }
3154 }
3155 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003156 .alg = "lrw(serpent)",
3157 .test = alg_test_skcipher,
3158 .suite = {
3159 .cipher = {
3160 .enc = {
3161 .vecs = serpent_lrw_enc_tv_template,
3162 .count = SERPENT_LRW_ENC_TEST_VECTORS
3163 },
3164 .dec = {
3165 .vecs = serpent_lrw_dec_tv_template,
3166 .count = SERPENT_LRW_DEC_TEST_VECTORS
3167 }
3168 }
3169 }
3170 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003171 .alg = "lrw(twofish)",
3172 .test = alg_test_skcipher,
3173 .suite = {
3174 .cipher = {
3175 .enc = {
3176 .vecs = tf_lrw_enc_tv_template,
3177 .count = TF_LRW_ENC_TEST_VECTORS
3178 },
3179 .dec = {
3180 .vecs = tf_lrw_dec_tv_template,
3181 .count = TF_LRW_DEC_TEST_VECTORS
3182 }
3183 }
3184 }
3185 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003186 .alg = "lzo",
3187 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003188 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003189 .suite = {
3190 .comp = {
3191 .comp = {
3192 .vecs = lzo_comp_tv_template,
3193 .count = LZO_COMP_TEST_VECTORS
3194 },
3195 .decomp = {
3196 .vecs = lzo_decomp_tv_template,
3197 .count = LZO_DECOMP_TEST_VECTORS
3198 }
3199 }
3200 }
3201 }, {
3202 .alg = "md4",
3203 .test = alg_test_hash,
3204 .suite = {
3205 .hash = {
3206 .vecs = md4_tv_template,
3207 .count = MD4_TEST_VECTORS
3208 }
3209 }
3210 }, {
3211 .alg = "md5",
3212 .test = alg_test_hash,
3213 .suite = {
3214 .hash = {
3215 .vecs = md5_tv_template,
3216 .count = MD5_TEST_VECTORS
3217 }
3218 }
3219 }, {
3220 .alg = "michael_mic",
3221 .test = alg_test_hash,
3222 .suite = {
3223 .hash = {
3224 .vecs = michael_mic_tv_template,
3225 .count = MICHAEL_MIC_TEST_VECTORS
3226 }
3227 }
3228 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003229 .alg = "ofb(aes)",
3230 .test = alg_test_skcipher,
3231 .fips_allowed = 1,
3232 .suite = {
3233 .cipher = {
3234 .enc = {
3235 .vecs = aes_ofb_enc_tv_template,
3236 .count = AES_OFB_ENC_TEST_VECTORS
3237 },
3238 .dec = {
3239 .vecs = aes_ofb_dec_tv_template,
3240 .count = AES_OFB_DEC_TEST_VECTORS
3241 }
3242 }
3243 }
3244 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003245 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003246 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003247 .suite = {
3248 .cipher = {
3249 .enc = {
3250 .vecs = fcrypt_pcbc_enc_tv_template,
3251 .count = FCRYPT_ENC_TEST_VECTORS
3252 },
3253 .dec = {
3254 .vecs = fcrypt_pcbc_dec_tv_template,
3255 .count = FCRYPT_DEC_TEST_VECTORS
3256 }
3257 }
3258 }
3259 }, {
3260 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003261 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003262 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003263 .suite = {
3264 .cipher = {
3265 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003266 .vecs = aes_ctr_rfc3686_enc_tv_template,
3267 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003268 },
3269 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003270 .vecs = aes_ctr_rfc3686_dec_tv_template,
3271 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003272 }
3273 }
3274 }
3275 }, {
Adrian Hoban69435b92010-11-04 15:02:04 -04003276 .alg = "rfc4106(gcm(aes))",
3277 .test = alg_test_aead,
3278 .suite = {
3279 .aead = {
3280 .enc = {
3281 .vecs = aes_gcm_rfc4106_enc_tv_template,
3282 .count = AES_GCM_4106_ENC_TEST_VECTORS
3283 },
3284 .dec = {
3285 .vecs = aes_gcm_rfc4106_dec_tv_template,
3286 .count = AES_GCM_4106_DEC_TEST_VECTORS
3287 }
3288 }
3289 }
3290 }, {
Jarod Wilson5d667322009-05-04 19:23:40 +08003291 .alg = "rfc4309(ccm(aes))",
3292 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003293 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003294 .suite = {
3295 .aead = {
3296 .enc = {
3297 .vecs = aes_ccm_rfc4309_enc_tv_template,
3298 .count = AES_CCM_4309_ENC_TEST_VECTORS
3299 },
3300 .dec = {
3301 .vecs = aes_ccm_rfc4309_dec_tv_template,
3302 .count = AES_CCM_4309_DEC_TEST_VECTORS
3303 }
3304 }
3305 }
3306 }, {
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003307 .alg = "rfc4543(gcm(aes))",
3308 .test = alg_test_aead,
3309 .suite = {
3310 .aead = {
3311 .enc = {
3312 .vecs = aes_gcm_rfc4543_enc_tv_template,
3313 .count = AES_GCM_4543_ENC_TEST_VECTORS
3314 },
3315 .dec = {
3316 .vecs = aes_gcm_rfc4543_dec_tv_template,
3317 .count = AES_GCM_4543_DEC_TEST_VECTORS
3318 },
3319 }
3320 }
3321 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003322 .alg = "rmd128",
3323 .test = alg_test_hash,
3324 .suite = {
3325 .hash = {
3326 .vecs = rmd128_tv_template,
3327 .count = RMD128_TEST_VECTORS
3328 }
3329 }
3330 }, {
3331 .alg = "rmd160",
3332 .test = alg_test_hash,
3333 .suite = {
3334 .hash = {
3335 .vecs = rmd160_tv_template,
3336 .count = RMD160_TEST_VECTORS
3337 }
3338 }
3339 }, {
3340 .alg = "rmd256",
3341 .test = alg_test_hash,
3342 .suite = {
3343 .hash = {
3344 .vecs = rmd256_tv_template,
3345 .count = RMD256_TEST_VECTORS
3346 }
3347 }
3348 }, {
3349 .alg = "rmd320",
3350 .test = alg_test_hash,
3351 .suite = {
3352 .hash = {
3353 .vecs = rmd320_tv_template,
3354 .count = RMD320_TEST_VECTORS
3355 }
3356 }
3357 }, {
3358 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003359 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003360 .suite = {
3361 .cipher = {
3362 .enc = {
3363 .vecs = salsa20_stream_enc_tv_template,
3364 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3365 }
3366 }
3367 }
3368 }, {
3369 .alg = "sha1",
3370 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003371 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003372 .suite = {
3373 .hash = {
3374 .vecs = sha1_tv_template,
3375 .count = SHA1_TEST_VECTORS
3376 }
3377 }
3378 }, {
3379 .alg = "sha224",
3380 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003381 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003382 .suite = {
3383 .hash = {
3384 .vecs = sha224_tv_template,
3385 .count = SHA224_TEST_VECTORS
3386 }
3387 }
3388 }, {
3389 .alg = "sha256",
3390 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003391 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003392 .suite = {
3393 .hash = {
3394 .vecs = sha256_tv_template,
3395 .count = SHA256_TEST_VECTORS
3396 }
3397 }
3398 }, {
3399 .alg = "sha384",
3400 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003401 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003402 .suite = {
3403 .hash = {
3404 .vecs = sha384_tv_template,
3405 .count = SHA384_TEST_VECTORS
3406 }
3407 }
3408 }, {
3409 .alg = "sha512",
3410 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003411 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003412 .suite = {
3413 .hash = {
3414 .vecs = sha512_tv_template,
3415 .count = SHA512_TEST_VECTORS
3416 }
3417 }
3418 }, {
3419 .alg = "tgr128",
3420 .test = alg_test_hash,
3421 .suite = {
3422 .hash = {
3423 .vecs = tgr128_tv_template,
3424 .count = TGR128_TEST_VECTORS
3425 }
3426 }
3427 }, {
3428 .alg = "tgr160",
3429 .test = alg_test_hash,
3430 .suite = {
3431 .hash = {
3432 .vecs = tgr160_tv_template,
3433 .count = TGR160_TEST_VECTORS
3434 }
3435 }
3436 }, {
3437 .alg = "tgr192",
3438 .test = alg_test_hash,
3439 .suite = {
3440 .hash = {
3441 .vecs = tgr192_tv_template,
3442 .count = TGR192_TEST_VECTORS
3443 }
3444 }
3445 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003446 .alg = "vmac(aes)",
3447 .test = alg_test_hash,
3448 .suite = {
3449 .hash = {
3450 .vecs = aes_vmac128_tv_template,
3451 .count = VMAC_AES_TEST_VECTORS
3452 }
3453 }
3454 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003455 .alg = "wp256",
3456 .test = alg_test_hash,
3457 .suite = {
3458 .hash = {
3459 .vecs = wp256_tv_template,
3460 .count = WP256_TEST_VECTORS
3461 }
3462 }
3463 }, {
3464 .alg = "wp384",
3465 .test = alg_test_hash,
3466 .suite = {
3467 .hash = {
3468 .vecs = wp384_tv_template,
3469 .count = WP384_TEST_VECTORS
3470 }
3471 }
3472 }, {
3473 .alg = "wp512",
3474 .test = alg_test_hash,
3475 .suite = {
3476 .hash = {
3477 .vecs = wp512_tv_template,
3478 .count = WP512_TEST_VECTORS
3479 }
3480 }
3481 }, {
3482 .alg = "xcbc(aes)",
3483 .test = alg_test_hash,
3484 .suite = {
3485 .hash = {
3486 .vecs = aes_xcbc128_tv_template,
3487 .count = XCBC_AES_TEST_VECTORS
3488 }
3489 }
3490 }, {
3491 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003492 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003493 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003494 .suite = {
3495 .cipher = {
3496 .enc = {
3497 .vecs = aes_xts_enc_tv_template,
3498 .count = AES_XTS_ENC_TEST_VECTORS
3499 },
3500 .dec = {
3501 .vecs = aes_xts_dec_tv_template,
3502 .count = AES_XTS_DEC_TEST_VECTORS
3503 }
3504 }
3505 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003506 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003507 .alg = "xts(camellia)",
3508 .test = alg_test_skcipher,
3509 .suite = {
3510 .cipher = {
3511 .enc = {
3512 .vecs = camellia_xts_enc_tv_template,
3513 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3514 },
3515 .dec = {
3516 .vecs = camellia_xts_dec_tv_template,
3517 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3518 }
3519 }
3520 }
3521 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003522 .alg = "xts(cast6)",
3523 .test = alg_test_skcipher,
3524 .suite = {
3525 .cipher = {
3526 .enc = {
3527 .vecs = cast6_xts_enc_tv_template,
3528 .count = CAST6_XTS_ENC_TEST_VECTORS
3529 },
3530 .dec = {
3531 .vecs = cast6_xts_dec_tv_template,
3532 .count = CAST6_XTS_DEC_TEST_VECTORS
3533 }
3534 }
3535 }
3536 }, {
Jussi Kivilinna18be20b2011-10-18 13:33:17 +03003537 .alg = "xts(serpent)",
3538 .test = alg_test_skcipher,
3539 .suite = {
3540 .cipher = {
3541 .enc = {
3542 .vecs = serpent_xts_enc_tv_template,
3543 .count = SERPENT_XTS_ENC_TEST_VECTORS
3544 },
3545 .dec = {
3546 .vecs = serpent_xts_dec_tv_template,
3547 .count = SERPENT_XTS_DEC_TEST_VECTORS
3548 }
3549 }
3550 }
3551 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003552 .alg = "xts(twofish)",
3553 .test = alg_test_skcipher,
3554 .suite = {
3555 .cipher = {
3556 .enc = {
3557 .vecs = tf_xts_enc_tv_template,
3558 .count = TF_XTS_ENC_TEST_VECTORS
3559 },
3560 .dec = {
3561 .vecs = tf_xts_dec_tv_template,
3562 .count = TF_XTS_DEC_TEST_VECTORS
3563 }
3564 }
3565 }
3566 }, {
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003567 .alg = "zlib",
3568 .test = alg_test_pcomp,
Milan Broz08189042012-12-06 17:16:28 +08003569 .fips_allowed = 1,
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003570 .suite = {
3571 .pcomp = {
3572 .comp = {
3573 .vecs = zlib_comp_tv_template,
3574 .count = ZLIB_COMP_TEST_VECTORS
3575 },
3576 .decomp = {
3577 .vecs = zlib_decomp_tv_template,
3578 .count = ZLIB_DECOMP_TEST_VECTORS
3579 }
3580 }
3581 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003582 }
3583};
3584
Jussi Kivilinna57147582013-06-13 17:37:40 +03003585static bool alg_test_descs_checked;
3586
3587static void alg_test_descs_check_order(void)
3588{
3589 int i;
3590
3591 /* only check once */
3592 if (alg_test_descs_checked)
3593 return;
3594
3595 alg_test_descs_checked = true;
3596
3597 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3598 int diff = strcmp(alg_test_descs[i - 1].alg,
3599 alg_test_descs[i].alg);
3600
3601 if (WARN_ON(diff > 0)) {
3602 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3603 alg_test_descs[i - 1].alg,
3604 alg_test_descs[i].alg);
3605 }
3606
3607 if (WARN_ON(diff == 0)) {
3608 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3609 alg_test_descs[i].alg);
3610 }
3611 }
3612}
3613
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003614static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003615{
3616 int start = 0;
3617 int end = ARRAY_SIZE(alg_test_descs);
3618
3619 while (start < end) {
3620 int i = (start + end) / 2;
3621 int diff = strcmp(alg_test_descs[i].alg, alg);
3622
3623 if (diff > 0) {
3624 end = i;
3625 continue;
3626 }
3627
3628 if (diff < 0) {
3629 start = i + 1;
3630 continue;
3631 }
3632
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003633 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003634 }
3635
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003636 return -1;
3637}
3638
3639int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3640{
3641 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003642 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003643 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003644
Jussi Kivilinna57147582013-06-13 17:37:40 +03003645 alg_test_descs_check_order();
3646
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003647 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3648 char nalg[CRYPTO_MAX_ALG_NAME];
3649
3650 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3651 sizeof(nalg))
3652 return -ENAMETOOLONG;
3653
3654 i = alg_find_test(nalg);
3655 if (i < 0)
3656 goto notest;
3657
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003658 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3659 goto non_fips_alg;
3660
Jarod Wilson941fb322009-05-04 19:49:23 +08003661 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3662 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003663 }
3664
3665 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003666 j = alg_find_test(driver);
3667 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003668 goto notest;
3669
Herbert Xua68f6612009-07-02 16:32:12 +08003670 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3671 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003672 goto non_fips_alg;
3673
Herbert Xua68f6612009-07-02 16:32:12 +08003674 rc = 0;
3675 if (i >= 0)
3676 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3677 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003678 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003679 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3680 type, mask);
3681
Jarod Wilson941fb322009-05-04 19:49:23 +08003682test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003683 if (fips_enabled && rc)
3684 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3685
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003686 if (fips_enabled && !rc)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303687 pr_info(KERN_INFO "alg: self-tests for %s (%s) passed\n",
3688 driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003689
Neil Hormand12d6b62008-10-12 20:36:51 +08003690 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003691
3692notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003693 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3694 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003695non_fips_alg:
3696 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003697}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003698
Herbert Xu326a6342010-08-06 09:40:28 +08003699#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003700
Herbert Xuda7f0332008-07-31 17:08:25 +08003701EXPORT_SYMBOL_GPL(alg_test);