blob: 0f90612a00b9d79fc97f5dc826b585fd7dd1af9f [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];
201 char result[64];
202 struct ahash_request *req;
203 struct tcrypt_result tresult;
Herbert Xuda7f0332008-07-31 17:08:25 +0800204 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800205 char *xbuf[XBUFSIZE];
206 int ret = -ENOMEM;
207
208 if (testmgr_alloc_buf(xbuf))
209 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800210
211 init_completion(&tresult.completion);
212
213 req = ahash_request_alloc(tfm, GFP_KERNEL);
214 if (!req) {
215 printk(KERN_ERR "alg: hash: Failed to allocate request for "
216 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800217 goto out_noreq;
218 }
219 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
220 tcrypt_complete, &tresult);
221
Herbert Xua0cfae52009-05-29 16:23:12 +1000222 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800223 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000224 if (template[i].np)
225 continue;
226
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300227 ret = -EINVAL;
228 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
229 goto out;
230
Herbert Xua0cfae52009-05-29 16:23:12 +1000231 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800232 memset(result, 0, 64);
233
234 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300235 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800236
237 memcpy(hash_buff, template[i].plaintext, template[i].psize);
238 sg_init_one(&sg[0], hash_buff, template[i].psize);
239
240 if (template[i].ksize) {
241 crypto_ahash_clear_flags(tfm, ~0);
242 ret = crypto_ahash_setkey(tfm, template[i].key,
243 template[i].ksize);
244 if (ret) {
245 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000246 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800247 -ret);
248 goto out;
249 }
250 }
251
252 ahash_request_set_crypt(req, sg, result, template[i].psize);
David S. Millera8f1a052010-05-19 14:12:03 +1000253 if (use_digest) {
254 ret = do_one_async_hash_op(req, &tresult,
255 crypto_ahash_digest(req));
256 if (ret) {
257 pr_err("alg: hash: digest failed on test %d "
258 "for %s: ret=%d\n", j, algo, -ret);
259 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800260 }
David S. Millera8f1a052010-05-19 14:12:03 +1000261 } else {
262 ret = do_one_async_hash_op(req, &tresult,
263 crypto_ahash_init(req));
264 if (ret) {
265 pr_err("alt: hash: init failed on test %d "
266 "for %s: ret=%d\n", j, algo, -ret);
267 goto out;
268 }
269 ret = do_one_async_hash_op(req, &tresult,
270 crypto_ahash_update(req));
271 if (ret) {
272 pr_err("alt: hash: update failed on test %d "
273 "for %s: ret=%d\n", j, algo, -ret);
274 goto out;
275 }
276 ret = do_one_async_hash_op(req, &tresult,
277 crypto_ahash_final(req));
278 if (ret) {
279 pr_err("alt: hash: final failed on test %d "
280 "for %s: ret=%d\n", j, algo, -ret);
281 goto out;
282 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800283 }
284
285 if (memcmp(result, template[i].digest,
286 crypto_ahash_digestsize(tfm))) {
287 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000288 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800289 hexdump(result, crypto_ahash_digestsize(tfm));
290 ret = -EINVAL;
291 goto out;
292 }
293 }
294
295 j = 0;
296 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300297 /* alignment tests are only done with continuous buffers */
298 if (align_offset != 0)
299 break;
300
Herbert Xuda7f0332008-07-31 17:08:25 +0800301 if (template[i].np) {
302 j++;
303 memset(result, 0, 64);
304
305 temp = 0;
306 sg_init_table(sg, template[i].np);
Herbert Xufd57f222009-05-29 16:05:42 +1000307 ret = -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +0800308 for (k = 0; k < template[i].np; k++) {
Herbert Xufd57f222009-05-29 16:05:42 +1000309 if (WARN_ON(offset_in_page(IDX[k]) +
310 template[i].tap[k] > PAGE_SIZE))
311 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800312 sg_set_buf(&sg[k],
313 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
314 offset_in_page(IDX[k]),
315 template[i].plaintext + temp,
316 template[i].tap[k]),
317 template[i].tap[k]);
318 temp += template[i].tap[k];
319 }
320
321 if (template[i].ksize) {
322 crypto_ahash_clear_flags(tfm, ~0);
323 ret = crypto_ahash_setkey(tfm, template[i].key,
324 template[i].ksize);
325
326 if (ret) {
327 printk(KERN_ERR "alg: hash: setkey "
328 "failed on chunking test %d "
329 "for %s: ret=%d\n", j, algo,
330 -ret);
331 goto out;
332 }
333 }
334
335 ahash_request_set_crypt(req, sg, result,
336 template[i].psize);
337 ret = crypto_ahash_digest(req);
338 switch (ret) {
339 case 0:
340 break;
341 case -EINPROGRESS:
342 case -EBUSY:
343 ret = wait_for_completion_interruptible(
344 &tresult.completion);
345 if (!ret && !(ret = tresult.err)) {
Wolfram Sang16735d02013-11-14 14:32:02 -0800346 reinit_completion(&tresult.completion);
Herbert Xuda7f0332008-07-31 17:08:25 +0800347 break;
348 }
349 /* fall through */
350 default:
351 printk(KERN_ERR "alg: hash: digest failed "
352 "on chunking test %d for %s: "
353 "ret=%d\n", j, algo, -ret);
354 goto out;
355 }
356
357 if (memcmp(result, template[i].digest,
358 crypto_ahash_digestsize(tfm))) {
359 printk(KERN_ERR "alg: hash: Chunking test %d "
360 "failed for %s\n", j, algo);
361 hexdump(result, crypto_ahash_digestsize(tfm));
362 ret = -EINVAL;
363 goto out;
364 }
365 }
366 }
367
368 ret = 0;
369
370out:
371 ahash_request_free(req);
372out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800373 testmgr_free_buf(xbuf);
374out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +0800375 return ret;
376}
377
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300378static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
379 unsigned int tcount, bool use_digest)
380{
381 unsigned int alignmask;
382 int ret;
383
384 ret = __test_hash(tfm, template, tcount, use_digest, 0);
385 if (ret)
386 return ret;
387
388 /* test unaligned buffers, check with one byte offset */
389 ret = __test_hash(tfm, template, tcount, use_digest, 1);
390 if (ret)
391 return ret;
392
393 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
394 if (alignmask) {
395 /* Check if alignment mask for tfm is correctly set. */
396 ret = __test_hash(tfm, template, tcount, use_digest,
397 alignmask + 1);
398 if (ret)
399 return ret;
400 }
401
402 return 0;
403}
404
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300405static int __test_aead(struct crypto_aead *tfm, int enc,
406 struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300407 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800408{
409 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
410 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800411 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800412 char *q;
413 char *key;
414 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300415 struct scatterlist *sg;
416 struct scatterlist *asg;
417 struct scatterlist *sgout;
418 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800419 struct tcrypt_result result;
420 unsigned int authsize;
421 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300422 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800423 void *assoc;
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700424 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800425 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300426 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800427 char *axbuf[XBUFSIZE];
428
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700429 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
430 if (!iv)
431 return ret;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800432 if (testmgr_alloc_buf(xbuf))
433 goto out_noxbuf;
434 if (testmgr_alloc_buf(axbuf))
435 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300436 if (diff_dst && testmgr_alloc_buf(xoutbuf))
437 goto out_nooutbuf;
438
439 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
440 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL);
441 if (!sg)
442 goto out_nosg;
443 asg = &sg[8];
444 sgout = &asg[8];
445
446 if (diff_dst)
447 d = "-ddst";
448 else
449 d = "";
450
Herbert Xuda7f0332008-07-31 17:08:25 +0800451 if (enc == ENCRYPT)
452 e = "encryption";
453 else
454 e = "decryption";
455
456 init_completion(&result.completion);
457
458 req = aead_request_alloc(tfm, GFP_KERNEL);
459 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300460 pr_err("alg: aead%s: Failed to allocate request for %s\n",
461 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800462 goto out;
463 }
464
465 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
466 tcrypt_complete, &result);
467
468 for (i = 0, j = 0; i < tcount; i++) {
469 if (!template[i].np) {
470 j++;
471
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300472 /* some templates have no input data but they will
Herbert Xuda7f0332008-07-31 17:08:25 +0800473 * touch input
474 */
475 input = xbuf[0];
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300476 input += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800477 assoc = axbuf[0];
478
Herbert Xufd57f222009-05-29 16:05:42 +1000479 ret = -EINVAL;
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300480 if (WARN_ON(align_offset + template[i].ilen >
481 PAGE_SIZE || template[i].alen > PAGE_SIZE))
Herbert Xufd57f222009-05-29 16:05:42 +1000482 goto out;
483
Herbert Xuda7f0332008-07-31 17:08:25 +0800484 memcpy(input, template[i].input, template[i].ilen);
485 memcpy(assoc, template[i].assoc, template[i].alen);
486 if (template[i].iv)
487 memcpy(iv, template[i].iv, MAX_IVLEN);
488 else
489 memset(iv, 0, MAX_IVLEN);
490
491 crypto_aead_clear_flags(tfm, ~0);
492 if (template[i].wk)
493 crypto_aead_set_flags(
494 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
495
496 key = template[i].key;
497
498 ret = crypto_aead_setkey(tfm, key,
499 template[i].klen);
500 if (!ret == template[i].fail) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300501 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
502 d, j, algo, crypto_aead_get_flags(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +0800503 goto out;
504 } else if (ret)
505 continue;
506
507 authsize = abs(template[i].rlen - template[i].ilen);
508 ret = crypto_aead_setauthsize(tfm, authsize);
509 if (ret) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300510 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
511 d, authsize, j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800512 goto out;
513 }
514
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300515 if (diff_dst) {
516 output = xoutbuf[0];
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300517 output += align_offset;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200518 sg_init_one(&sg[0], input, template[i].ilen);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300519 sg_init_one(&sgout[0], output,
Horia Geanta8ec25c52013-11-28 15:11:18 +0200520 template[i].rlen);
521 } else {
522 sg_init_one(&sg[0], input,
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300523 template[i].ilen +
524 (enc ? authsize : 0));
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300525 output = input;
526 }
527
Herbert Xuda7f0332008-07-31 17:08:25 +0800528 sg_init_one(&asg[0], assoc, template[i].alen);
529
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300530 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Herbert Xuda7f0332008-07-31 17:08:25 +0800531 template[i].ilen, iv);
532
533 aead_request_set_assoc(req, asg, template[i].alen);
534
535 ret = enc ?
536 crypto_aead_encrypt(req) :
537 crypto_aead_decrypt(req);
538
539 switch (ret) {
540 case 0:
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800541 if (template[i].novrfy) {
542 /* verification was supposed to fail */
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300543 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
544 d, e, j, algo);
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800545 /* so really, we got a bad message */
546 ret = -EBADMSG;
547 goto out;
548 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800549 break;
550 case -EINPROGRESS:
551 case -EBUSY:
552 ret = wait_for_completion_interruptible(
553 &result.completion);
554 if (!ret && !(ret = result.err)) {
Wolfram Sang16735d02013-11-14 14:32:02 -0800555 reinit_completion(&result.completion);
Herbert Xuda7f0332008-07-31 17:08:25 +0800556 break;
557 }
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800558 case -EBADMSG:
559 if (template[i].novrfy)
560 /* verification failure was expected */
561 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800562 /* fall through */
563 default:
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300564 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
565 d, e, j, algo, -ret);
Herbert Xuda7f0332008-07-31 17:08:25 +0800566 goto out;
567 }
568
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300569 q = output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800570 if (memcmp(q, template[i].result, template[i].rlen)) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300571 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
572 d, j, e, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800573 hexdump(q, template[i].rlen);
574 ret = -EINVAL;
575 goto out;
576 }
577 }
578 }
579
580 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300581 /* alignment tests are only done with continuous buffers */
582 if (align_offset != 0)
583 break;
584
Herbert Xuda7f0332008-07-31 17:08:25 +0800585 if (template[i].np) {
586 j++;
587
588 if (template[i].iv)
589 memcpy(iv, template[i].iv, MAX_IVLEN);
590 else
591 memset(iv, 0, MAX_IVLEN);
592
593 crypto_aead_clear_flags(tfm, ~0);
594 if (template[i].wk)
595 crypto_aead_set_flags(
596 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
597 key = template[i].key;
598
599 ret = crypto_aead_setkey(tfm, key, template[i].klen);
600 if (!ret == template[i].fail) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300601 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
602 d, j, algo, crypto_aead_get_flags(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +0800603 goto out;
604 } else if (ret)
605 continue;
606
607 authsize = abs(template[i].rlen - template[i].ilen);
608
609 ret = -EINVAL;
610 sg_init_table(sg, template[i].np);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300611 if (diff_dst)
612 sg_init_table(sgout, template[i].np);
Herbert Xuda7f0332008-07-31 17:08:25 +0800613 for (k = 0, temp = 0; k < template[i].np; k++) {
614 if (WARN_ON(offset_in_page(IDX[k]) +
615 template[i].tap[k] > PAGE_SIZE))
616 goto out;
617
618 q = xbuf[IDX[k] >> PAGE_SHIFT] +
619 offset_in_page(IDX[k]);
620
621 memcpy(q, template[i].input + temp,
622 template[i].tap[k]);
623
Herbert Xuda7f0332008-07-31 17:08:25 +0800624 sg_set_buf(&sg[k], q, template[i].tap[k]);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300625
626 if (diff_dst) {
627 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
628 offset_in_page(IDX[k]);
629
630 memset(q, 0, template[i].tap[k]);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300631
632 sg_set_buf(&sgout[k], q,
633 template[i].tap[k]);
634 }
635
Horia Geanta8ec25c52013-11-28 15:11:18 +0200636 n = template[i].tap[k];
637 if (k == template[i].np - 1 && enc)
638 n += authsize;
639 if (offset_in_page(q) + n < PAGE_SIZE)
640 q[n] = 0;
641
Herbert Xuda7f0332008-07-31 17:08:25 +0800642 temp += template[i].tap[k];
643 }
644
645 ret = crypto_aead_setauthsize(tfm, authsize);
646 if (ret) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300647 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
648 d, authsize, j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800649 goto out;
650 }
651
652 if (enc) {
653 if (WARN_ON(sg[k - 1].offset +
654 sg[k - 1].length + authsize >
655 PAGE_SIZE)) {
656 ret = -EINVAL;
657 goto out;
658 }
659
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300660 if (diff_dst)
661 sgout[k - 1].length += authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200662 else
663 sg[k - 1].length += authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800664 }
665
666 sg_init_table(asg, template[i].anp);
Herbert Xufd57f222009-05-29 16:05:42 +1000667 ret = -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +0800668 for (k = 0, temp = 0; k < template[i].anp; k++) {
Herbert Xufd57f222009-05-29 16:05:42 +1000669 if (WARN_ON(offset_in_page(IDX[k]) +
670 template[i].atap[k] > PAGE_SIZE))
671 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800672 sg_set_buf(&asg[k],
673 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
674 offset_in_page(IDX[k]),
675 template[i].assoc + temp,
676 template[i].atap[k]),
677 template[i].atap[k]);
678 temp += template[i].atap[k];
679 }
680
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300681 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Herbert Xuda7f0332008-07-31 17:08:25 +0800682 template[i].ilen,
683 iv);
684
685 aead_request_set_assoc(req, asg, template[i].alen);
686
687 ret = enc ?
688 crypto_aead_encrypt(req) :
689 crypto_aead_decrypt(req);
690
691 switch (ret) {
692 case 0:
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800693 if (template[i].novrfy) {
694 /* verification was supposed to fail */
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300695 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
696 d, e, j, algo);
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800697 /* so really, we got a bad message */
698 ret = -EBADMSG;
699 goto out;
700 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800701 break;
702 case -EINPROGRESS:
703 case -EBUSY:
704 ret = wait_for_completion_interruptible(
705 &result.completion);
706 if (!ret && !(ret = result.err)) {
Wolfram Sang16735d02013-11-14 14:32:02 -0800707 reinit_completion(&result.completion);
Herbert Xuda7f0332008-07-31 17:08:25 +0800708 break;
709 }
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800710 case -EBADMSG:
711 if (template[i].novrfy)
712 /* verification failure was expected */
713 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800714 /* fall through */
715 default:
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300716 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
717 d, e, j, algo, -ret);
Herbert Xuda7f0332008-07-31 17:08:25 +0800718 goto out;
719 }
720
721 ret = -EINVAL;
722 for (k = 0, temp = 0; k < template[i].np; k++) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300723 if (diff_dst)
724 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
725 offset_in_page(IDX[k]);
726 else
727 q = xbuf[IDX[k] >> PAGE_SHIFT] +
728 offset_in_page(IDX[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +0800729
730 n = template[i].tap[k];
731 if (k == template[i].np - 1)
732 n += enc ? authsize : -authsize;
733
734 if (memcmp(q, template[i].result + temp, n)) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300735 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
736 d, j, e, k, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800737 hexdump(q, n);
738 goto out;
739 }
740
741 q += n;
742 if (k == template[i].np - 1 && !enc) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300743 if (!diff_dst &&
744 memcmp(q, template[i].input +
Herbert Xuda7f0332008-07-31 17:08:25 +0800745 temp + n, authsize))
746 n = authsize;
747 else
748 n = 0;
749 } else {
750 for (n = 0; offset_in_page(q + n) &&
751 q[n]; n++)
752 ;
753 }
754 if (n) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300755 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
756 d, j, e, k, algo, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800757 hexdump(q, n);
758 goto out;
759 }
760
761 temp += template[i].tap[k];
762 }
763 }
764 }
765
766 ret = 0;
767
768out:
769 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300770 kfree(sg);
771out_nosg:
772 if (diff_dst)
773 testmgr_free_buf(xoutbuf);
774out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800775 testmgr_free_buf(axbuf);
776out_noaxbuf:
777 testmgr_free_buf(xbuf);
778out_noxbuf:
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700779 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800780 return ret;
781}
782
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300783static int test_aead(struct crypto_aead *tfm, int enc,
784 struct aead_testvec *template, unsigned int tcount)
785{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300786 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300787 int ret;
788
789 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300790 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300791 if (ret)
792 return ret;
793
794 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300795 ret = __test_aead(tfm, enc, template, tcount, true, 0);
796 if (ret)
797 return ret;
798
799 /* test unaligned buffers, check with one byte offset */
800 ret = __test_aead(tfm, enc, template, tcount, true, 1);
801 if (ret)
802 return ret;
803
804 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
805 if (alignmask) {
806 /* Check if alignment mask for tfm is correctly set. */
807 ret = __test_aead(tfm, enc, template, tcount, true,
808 alignmask + 1);
809 if (ret)
810 return ret;
811 }
812
813 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300814}
815
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000816static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800817 struct cipher_testvec *template, unsigned int tcount)
818{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000819 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
820 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000821 char *q;
822 const char *e;
823 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800824 char *xbuf[XBUFSIZE];
825 int ret = -ENOMEM;
826
827 if (testmgr_alloc_buf(xbuf))
828 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000829
830 if (enc == ENCRYPT)
831 e = "encryption";
832 else
833 e = "decryption";
834
835 j = 0;
836 for (i = 0; i < tcount; i++) {
837 if (template[i].np)
838 continue;
839
840 j++;
841
Herbert Xufd57f222009-05-29 16:05:42 +1000842 ret = -EINVAL;
843 if (WARN_ON(template[i].ilen > PAGE_SIZE))
844 goto out;
845
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000846 data = xbuf[0];
847 memcpy(data, template[i].input, template[i].ilen);
848
849 crypto_cipher_clear_flags(tfm, ~0);
850 if (template[i].wk)
851 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
852
853 ret = crypto_cipher_setkey(tfm, template[i].key,
854 template[i].klen);
855 if (!ret == template[i].fail) {
856 printk(KERN_ERR "alg: cipher: setkey failed "
857 "on test %d for %s: flags=%x\n", j,
858 algo, crypto_cipher_get_flags(tfm));
859 goto out;
860 } else if (ret)
861 continue;
862
863 for (k = 0; k < template[i].ilen;
864 k += crypto_cipher_blocksize(tfm)) {
865 if (enc)
866 crypto_cipher_encrypt_one(tfm, data + k,
867 data + k);
868 else
869 crypto_cipher_decrypt_one(tfm, data + k,
870 data + k);
871 }
872
873 q = data;
874 if (memcmp(q, template[i].result, template[i].rlen)) {
875 printk(KERN_ERR "alg: cipher: Test %d failed "
876 "on %s for %s\n", j, e, algo);
877 hexdump(q, template[i].rlen);
878 ret = -EINVAL;
879 goto out;
880 }
881 }
882
883 ret = 0;
884
885out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800886 testmgr_free_buf(xbuf);
887out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000888 return ret;
889}
890
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300891static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
892 struct cipher_testvec *template, unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300893 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000894{
Herbert Xuda7f0332008-07-31 17:08:25 +0800895 const char *algo =
896 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
897 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800898 char *q;
899 struct ablkcipher_request *req;
900 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300901 struct scatterlist sgout[8];
902 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800903 struct tcrypt_result result;
904 void *data;
905 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800906 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300907 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800908 int ret = -ENOMEM;
909
910 if (testmgr_alloc_buf(xbuf))
911 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800912
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300913 if (diff_dst && testmgr_alloc_buf(xoutbuf))
914 goto out_nooutbuf;
915
916 if (diff_dst)
917 d = "-ddst";
918 else
919 d = "";
920
Herbert Xuda7f0332008-07-31 17:08:25 +0800921 if (enc == ENCRYPT)
922 e = "encryption";
923 else
924 e = "decryption";
925
926 init_completion(&result.completion);
927
928 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
929 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300930 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
931 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800932 goto out;
933 }
934
935 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
936 tcrypt_complete, &result);
937
938 j = 0;
939 for (i = 0; i < tcount; i++) {
940 if (template[i].iv)
941 memcpy(iv, template[i].iv, MAX_IVLEN);
942 else
943 memset(iv, 0, MAX_IVLEN);
944
Jussi Kivilinnaf44d83d2012-09-19 09:42:49 +0300945 if (!(template[i].np) || (template[i].also_non_np)) {
Herbert Xuda7f0332008-07-31 17:08:25 +0800946 j++;
947
Herbert Xufd57f222009-05-29 16:05:42 +1000948 ret = -EINVAL;
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300949 if (WARN_ON(align_offset + template[i].ilen >
950 PAGE_SIZE))
Herbert Xufd57f222009-05-29 16:05:42 +1000951 goto out;
952
Herbert Xuda7f0332008-07-31 17:08:25 +0800953 data = xbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300954 data += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800955 memcpy(data, template[i].input, template[i].ilen);
956
957 crypto_ablkcipher_clear_flags(tfm, ~0);
958 if (template[i].wk)
959 crypto_ablkcipher_set_flags(
960 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
961
962 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
963 template[i].klen);
964 if (!ret == template[i].fail) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300965 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
966 d, j, algo,
967 crypto_ablkcipher_get_flags(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +0800968 goto out;
969 } else if (ret)
970 continue;
971
972 sg_init_one(&sg[0], data, template[i].ilen);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300973 if (diff_dst) {
974 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300975 data += align_offset;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300976 sg_init_one(&sgout[0], data, template[i].ilen);
977 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800978
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300979 ablkcipher_request_set_crypt(req, sg,
980 (diff_dst) ? sgout : sg,
Herbert Xuda7f0332008-07-31 17:08:25 +0800981 template[i].ilen, iv);
982 ret = enc ?
983 crypto_ablkcipher_encrypt(req) :
984 crypto_ablkcipher_decrypt(req);
985
986 switch (ret) {
987 case 0:
988 break;
989 case -EINPROGRESS:
990 case -EBUSY:
991 ret = wait_for_completion_interruptible(
992 &result.completion);
993 if (!ret && !((ret = result.err))) {
Wolfram Sang16735d02013-11-14 14:32:02 -0800994 reinit_completion(&result.completion);
Herbert Xuda7f0332008-07-31 17:08:25 +0800995 break;
996 }
997 /* fall through */
998 default:
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300999 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1000 d, e, j, algo, -ret);
Herbert Xuda7f0332008-07-31 17:08:25 +08001001 goto out;
1002 }
1003
1004 q = data;
1005 if (memcmp(q, template[i].result, template[i].rlen)) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001006 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1007 d, j, e, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +08001008 hexdump(q, template[i].rlen);
1009 ret = -EINVAL;
1010 goto out;
1011 }
1012 }
1013 }
1014
1015 j = 0;
1016 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001017 /* alignment tests are only done with continuous buffers */
1018 if (align_offset != 0)
1019 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001020
1021 if (template[i].iv)
1022 memcpy(iv, template[i].iv, MAX_IVLEN);
1023 else
1024 memset(iv, 0, MAX_IVLEN);
1025
1026 if (template[i].np) {
1027 j++;
1028
1029 crypto_ablkcipher_clear_flags(tfm, ~0);
1030 if (template[i].wk)
1031 crypto_ablkcipher_set_flags(
1032 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1033
1034 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1035 template[i].klen);
1036 if (!ret == template[i].fail) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001037 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1038 d, j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +08001039 crypto_ablkcipher_get_flags(tfm));
1040 goto out;
1041 } else if (ret)
1042 continue;
1043
1044 temp = 0;
1045 ret = -EINVAL;
1046 sg_init_table(sg, template[i].np);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001047 if (diff_dst)
1048 sg_init_table(sgout, template[i].np);
Herbert Xuda7f0332008-07-31 17:08:25 +08001049 for (k = 0; k < template[i].np; k++) {
1050 if (WARN_ON(offset_in_page(IDX[k]) +
1051 template[i].tap[k] > PAGE_SIZE))
1052 goto out;
1053
1054 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1055 offset_in_page(IDX[k]);
1056
1057 memcpy(q, template[i].input + temp,
1058 template[i].tap[k]);
1059
1060 if (offset_in_page(q) + template[i].tap[k] <
1061 PAGE_SIZE)
1062 q[template[i].tap[k]] = 0;
1063
1064 sg_set_buf(&sg[k], q, template[i].tap[k]);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001065 if (diff_dst) {
1066 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1067 offset_in_page(IDX[k]);
1068
1069 sg_set_buf(&sgout[k], q,
1070 template[i].tap[k]);
1071
1072 memset(q, 0, template[i].tap[k]);
1073 if (offset_in_page(q) +
1074 template[i].tap[k] < PAGE_SIZE)
1075 q[template[i].tap[k]] = 0;
1076 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001077
1078 temp += template[i].tap[k];
1079 }
1080
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001081 ablkcipher_request_set_crypt(req, sg,
1082 (diff_dst) ? sgout : sg,
Herbert Xuda7f0332008-07-31 17:08:25 +08001083 template[i].ilen, iv);
1084
1085 ret = enc ?
1086 crypto_ablkcipher_encrypt(req) :
1087 crypto_ablkcipher_decrypt(req);
1088
1089 switch (ret) {
1090 case 0:
1091 break;
1092 case -EINPROGRESS:
1093 case -EBUSY:
1094 ret = wait_for_completion_interruptible(
1095 &result.completion);
1096 if (!ret && !((ret = result.err))) {
Wolfram Sang16735d02013-11-14 14:32:02 -08001097 reinit_completion(&result.completion);
Herbert Xuda7f0332008-07-31 17:08:25 +08001098 break;
1099 }
1100 /* fall through */
1101 default:
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001102 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1103 d, e, j, algo, -ret);
Herbert Xuda7f0332008-07-31 17:08:25 +08001104 goto out;
1105 }
1106
1107 temp = 0;
1108 ret = -EINVAL;
1109 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001110 if (diff_dst)
1111 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1112 offset_in_page(IDX[k]);
1113 else
1114 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1115 offset_in_page(IDX[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001116
1117 if (memcmp(q, template[i].result + temp,
1118 template[i].tap[k])) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001119 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1120 d, j, e, k, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +08001121 hexdump(q, template[i].tap[k]);
1122 goto out;
1123 }
1124
1125 q += template[i].tap[k];
1126 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1127 ;
1128 if (n) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001129 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1130 d, j, e, k, algo, n);
Herbert Xuda7f0332008-07-31 17:08:25 +08001131 hexdump(q, n);
1132 goto out;
1133 }
1134 temp += template[i].tap[k];
1135 }
1136 }
1137 }
1138
1139 ret = 0;
1140
1141out:
1142 ablkcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001143 if (diff_dst)
1144 testmgr_free_buf(xoutbuf);
1145out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001146 testmgr_free_buf(xbuf);
1147out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001148 return ret;
1149}
1150
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001151static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1152 struct cipher_testvec *template, unsigned int tcount)
1153{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001154 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001155 int ret;
1156
1157 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001158 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001159 if (ret)
1160 return ret;
1161
1162 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001163 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1164 if (ret)
1165 return ret;
1166
1167 /* test unaligned buffers, check with one byte offset */
1168 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1169 if (ret)
1170 return ret;
1171
1172 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1173 if (alignmask) {
1174 /* Check if alignment mask for tfm is correctly set. */
1175 ret = __test_skcipher(tfm, enc, template, tcount, true,
1176 alignmask + 1);
1177 if (ret)
1178 return ret;
1179 }
1180
1181 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001182}
1183
Herbert Xuda7f0332008-07-31 17:08:25 +08001184static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1185 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1186{
1187 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1188 unsigned int i;
1189 char result[COMP_BUF_SIZE];
1190 int ret;
1191
1192 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001193 int ilen;
1194 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001195
1196 memset(result, 0, sizeof (result));
1197
1198 ilen = ctemplate[i].inlen;
1199 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1200 ilen, result, &dlen);
1201 if (ret) {
1202 printk(KERN_ERR "alg: comp: compression failed "
1203 "on test %d for %s: ret=%d\n", i + 1, algo,
1204 -ret);
1205 goto out;
1206 }
1207
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001208 if (dlen != ctemplate[i].outlen) {
1209 printk(KERN_ERR "alg: comp: Compression test %d "
1210 "failed for %s: output len = %d\n", i + 1, algo,
1211 dlen);
1212 ret = -EINVAL;
1213 goto out;
1214 }
1215
Herbert Xuda7f0332008-07-31 17:08:25 +08001216 if (memcmp(result, ctemplate[i].output, dlen)) {
1217 printk(KERN_ERR "alg: comp: Compression test %d "
1218 "failed for %s\n", i + 1, algo);
1219 hexdump(result, dlen);
1220 ret = -EINVAL;
1221 goto out;
1222 }
1223 }
1224
1225 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001226 int ilen;
1227 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001228
1229 memset(result, 0, sizeof (result));
1230
1231 ilen = dtemplate[i].inlen;
1232 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1233 ilen, result, &dlen);
1234 if (ret) {
1235 printk(KERN_ERR "alg: comp: decompression failed "
1236 "on test %d for %s: ret=%d\n", i + 1, algo,
1237 -ret);
1238 goto out;
1239 }
1240
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001241 if (dlen != dtemplate[i].outlen) {
1242 printk(KERN_ERR "alg: comp: Decompression test %d "
1243 "failed for %s: output len = %d\n", i + 1, algo,
1244 dlen);
1245 ret = -EINVAL;
1246 goto out;
1247 }
1248
Herbert Xuda7f0332008-07-31 17:08:25 +08001249 if (memcmp(result, dtemplate[i].output, dlen)) {
1250 printk(KERN_ERR "alg: comp: Decompression test %d "
1251 "failed for %s\n", i + 1, algo);
1252 hexdump(result, dlen);
1253 ret = -EINVAL;
1254 goto out;
1255 }
1256 }
1257
1258 ret = 0;
1259
1260out:
1261 return ret;
1262}
1263
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001264static int test_pcomp(struct crypto_pcomp *tfm,
1265 struct pcomp_testvec *ctemplate,
1266 struct pcomp_testvec *dtemplate, int ctcount,
1267 int dtcount)
1268{
1269 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1270 unsigned int i;
1271 char result[COMP_BUF_SIZE];
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001272 int res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001273
1274 for (i = 0; i < ctcount; i++) {
1275 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001276 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001277
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001278 res = crypto_compress_setup(tfm, ctemplate[i].params,
1279 ctemplate[i].paramsize);
1280 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001281 pr_err("alg: pcomp: compression setup failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001282 "%d for %s: error=%d\n", i + 1, algo, res);
1283 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001284 }
1285
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001286 res = crypto_compress_init(tfm);
1287 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001288 pr_err("alg: pcomp: compression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001289 "%d for %s: error=%d\n", i + 1, algo, res);
1290 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001291 }
1292
1293 memset(result, 0, sizeof(result));
1294
1295 req.next_in = ctemplate[i].input;
1296 req.avail_in = ctemplate[i].inlen / 2;
1297 req.next_out = result;
1298 req.avail_out = ctemplate[i].outlen / 2;
1299
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001300 res = crypto_compress_update(tfm, &req);
1301 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001302 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001303 "%d for %s: error=%d\n", i + 1, algo, res);
1304 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001305 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001306 if (res > 0)
1307 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001308
1309 /* Add remaining input data */
1310 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1311
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001312 res = crypto_compress_update(tfm, &req);
1313 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001314 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001315 "%d for %s: error=%d\n", i + 1, algo, res);
1316 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001317 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001318 if (res > 0)
1319 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001320
1321 /* Provide remaining output space */
1322 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1323
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001324 res = crypto_compress_final(tfm, &req);
1325 if (res < 0) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001326 pr_err("alg: pcomp: compression final failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001327 "%d for %s: error=%d\n", i + 1, algo, res);
1328 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001329 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001330 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001331
1332 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1333 pr_err("alg: comp: Compression test %d failed for %s: "
1334 "output len = %d (expected %d)\n", i + 1, algo,
1335 COMP_BUF_SIZE - req.avail_out,
1336 ctemplate[i].outlen);
1337 return -EINVAL;
1338 }
1339
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001340 if (produced != ctemplate[i].outlen) {
1341 pr_err("alg: comp: Compression test %d failed for %s: "
1342 "returned len = %u (expected %d)\n", i + 1,
1343 algo, produced, ctemplate[i].outlen);
1344 return -EINVAL;
1345 }
1346
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001347 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1348 pr_err("alg: pcomp: Compression test %d failed for "
1349 "%s\n", i + 1, algo);
1350 hexdump(result, ctemplate[i].outlen);
1351 return -EINVAL;
1352 }
1353 }
1354
1355 for (i = 0; i < dtcount; i++) {
1356 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001357 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001358
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001359 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1360 dtemplate[i].paramsize);
1361 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001362 pr_err("alg: pcomp: decompression setup failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001363 "test %d for %s: error=%d\n", i + 1, algo, res);
1364 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001365 }
1366
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001367 res = crypto_decompress_init(tfm);
1368 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001369 pr_err("alg: pcomp: decompression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001370 "%d for %s: error=%d\n", i + 1, algo, res);
1371 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001372 }
1373
1374 memset(result, 0, sizeof(result));
1375
1376 req.next_in = dtemplate[i].input;
1377 req.avail_in = dtemplate[i].inlen / 2;
1378 req.next_out = result;
1379 req.avail_out = dtemplate[i].outlen / 2;
1380
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001381 res = crypto_decompress_update(tfm, &req);
1382 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001383 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001384 "test %d for %s: error=%d\n", i + 1, algo, res);
1385 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001386 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001387 if (res > 0)
1388 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001389
1390 /* Add remaining input data */
1391 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1392
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001393 res = crypto_decompress_update(tfm, &req);
1394 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001395 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001396 "test %d for %s: error=%d\n", i + 1, algo, res);
1397 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001398 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001399 if (res > 0)
1400 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001401
1402 /* Provide remaining output space */
1403 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1404
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001405 res = crypto_decompress_final(tfm, &req);
1406 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001407 pr_err("alg: pcomp: decompression final failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001408 "test %d for %s: error=%d\n", i + 1, algo, res);
1409 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001410 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001411 if (res > 0)
1412 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001413
1414 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1415 pr_err("alg: comp: Decompression test %d failed for "
1416 "%s: output len = %d (expected %d)\n", i + 1,
1417 algo, COMP_BUF_SIZE - req.avail_out,
1418 dtemplate[i].outlen);
1419 return -EINVAL;
1420 }
1421
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001422 if (produced != dtemplate[i].outlen) {
1423 pr_err("alg: comp: Decompression test %d failed for "
1424 "%s: returned len = %u (expected %d)\n", i + 1,
1425 algo, produced, dtemplate[i].outlen);
1426 return -EINVAL;
1427 }
1428
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001429 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1430 pr_err("alg: pcomp: Decompression test %d failed for "
1431 "%s\n", i + 1, algo);
1432 hexdump(result, dtemplate[i].outlen);
1433 return -EINVAL;
1434 }
1435 }
1436
1437 return 0;
1438}
1439
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001440
1441static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1442 unsigned int tcount)
1443{
1444 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001445 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001446 u8 *seed;
1447 char result[32];
1448
1449 seedsize = crypto_rng_seedsize(tfm);
1450
1451 seed = kmalloc(seedsize, GFP_KERNEL);
1452 if (!seed) {
1453 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1454 "for %s\n", algo);
1455 return -ENOMEM;
1456 }
1457
1458 for (i = 0; i < tcount; i++) {
1459 memset(result, 0, 32);
1460
1461 memcpy(seed, template[i].v, template[i].vlen);
1462 memcpy(seed + template[i].vlen, template[i].key,
1463 template[i].klen);
1464 memcpy(seed + template[i].vlen + template[i].klen,
1465 template[i].dt, template[i].dtlen);
1466
1467 err = crypto_rng_reset(tfm, seed, seedsize);
1468 if (err) {
1469 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1470 "for %s\n", algo);
1471 goto out;
1472 }
1473
1474 for (j = 0; j < template[i].loops; j++) {
1475 err = crypto_rng_get_bytes(tfm, result,
1476 template[i].rlen);
1477 if (err != template[i].rlen) {
1478 printk(KERN_ERR "alg: cprng: Failed to obtain "
1479 "the correct amount of random data for "
1480 "%s (requested %d, got %d)\n", algo,
1481 template[i].rlen, err);
1482 goto out;
1483 }
1484 }
1485
1486 err = memcmp(result, template[i].result,
1487 template[i].rlen);
1488 if (err) {
1489 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1490 i, algo);
1491 hexdump(result, template[i].rlen);
1492 err = -EINVAL;
1493 goto out;
1494 }
1495 }
1496
1497out:
1498 kfree(seed);
1499 return err;
1500}
1501
Herbert Xuda7f0332008-07-31 17:08:25 +08001502static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1503 u32 type, u32 mask)
1504{
1505 struct crypto_aead *tfm;
1506 int err = 0;
1507
1508 tfm = crypto_alloc_aead(driver, type, mask);
1509 if (IS_ERR(tfm)) {
1510 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1511 "%ld\n", driver, PTR_ERR(tfm));
1512 return PTR_ERR(tfm);
1513 }
1514
1515 if (desc->suite.aead.enc.vecs) {
1516 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1517 desc->suite.aead.enc.count);
1518 if (err)
1519 goto out;
1520 }
1521
1522 if (!err && desc->suite.aead.dec.vecs)
1523 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1524 desc->suite.aead.dec.count);
1525
1526out:
1527 crypto_free_aead(tfm);
1528 return err;
1529}
1530
1531static int alg_test_cipher(const struct alg_test_desc *desc,
1532 const char *driver, u32 type, u32 mask)
1533{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001534 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001535 int err = 0;
1536
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001537 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001538 if (IS_ERR(tfm)) {
1539 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1540 "%s: %ld\n", driver, PTR_ERR(tfm));
1541 return PTR_ERR(tfm);
1542 }
1543
1544 if (desc->suite.cipher.enc.vecs) {
1545 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1546 desc->suite.cipher.enc.count);
1547 if (err)
1548 goto out;
1549 }
1550
1551 if (desc->suite.cipher.dec.vecs)
1552 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1553 desc->suite.cipher.dec.count);
1554
1555out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001556 crypto_free_cipher(tfm);
1557 return err;
1558}
1559
1560static int alg_test_skcipher(const struct alg_test_desc *desc,
1561 const char *driver, u32 type, u32 mask)
1562{
1563 struct crypto_ablkcipher *tfm;
1564 int err = 0;
1565
1566 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1567 if (IS_ERR(tfm)) {
1568 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1569 "%s: %ld\n", driver, PTR_ERR(tfm));
1570 return PTR_ERR(tfm);
1571 }
1572
1573 if (desc->suite.cipher.enc.vecs) {
1574 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1575 desc->suite.cipher.enc.count);
1576 if (err)
1577 goto out;
1578 }
1579
1580 if (desc->suite.cipher.dec.vecs)
1581 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1582 desc->suite.cipher.dec.count);
1583
1584out:
Herbert Xuda7f0332008-07-31 17:08:25 +08001585 crypto_free_ablkcipher(tfm);
1586 return err;
1587}
1588
1589static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1590 u32 type, u32 mask)
1591{
1592 struct crypto_comp *tfm;
1593 int err;
1594
1595 tfm = crypto_alloc_comp(driver, type, mask);
1596 if (IS_ERR(tfm)) {
1597 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1598 "%ld\n", driver, PTR_ERR(tfm));
1599 return PTR_ERR(tfm);
1600 }
1601
1602 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1603 desc->suite.comp.decomp.vecs,
1604 desc->suite.comp.comp.count,
1605 desc->suite.comp.decomp.count);
1606
1607 crypto_free_comp(tfm);
1608 return err;
1609}
1610
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001611static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1612 u32 type, u32 mask)
1613{
1614 struct crypto_pcomp *tfm;
1615 int err;
1616
1617 tfm = crypto_alloc_pcomp(driver, type, mask);
1618 if (IS_ERR(tfm)) {
1619 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1620 driver, PTR_ERR(tfm));
1621 return PTR_ERR(tfm);
1622 }
1623
1624 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1625 desc->suite.pcomp.decomp.vecs,
1626 desc->suite.pcomp.comp.count,
1627 desc->suite.pcomp.decomp.count);
1628
1629 crypto_free_pcomp(tfm);
1630 return err;
1631}
1632
Herbert Xuda7f0332008-07-31 17:08:25 +08001633static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1634 u32 type, u32 mask)
1635{
1636 struct crypto_ahash *tfm;
1637 int err;
1638
1639 tfm = crypto_alloc_ahash(driver, type, mask);
1640 if (IS_ERR(tfm)) {
1641 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1642 "%ld\n", driver, PTR_ERR(tfm));
1643 return PTR_ERR(tfm);
1644 }
1645
David S. Millera8f1a052010-05-19 14:12:03 +10001646 err = test_hash(tfm, desc->suite.hash.vecs,
1647 desc->suite.hash.count, true);
1648 if (!err)
1649 err = test_hash(tfm, desc->suite.hash.vecs,
1650 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001651
1652 crypto_free_ahash(tfm);
1653 return err;
1654}
1655
Herbert Xu8e3ee852008-11-07 14:58:52 +08001656static int alg_test_crc32c(const struct alg_test_desc *desc,
1657 const char *driver, u32 type, u32 mask)
1658{
1659 struct crypto_shash *tfm;
1660 u32 val;
1661 int err;
1662
1663 err = alg_test_hash(desc, driver, type, mask);
1664 if (err)
1665 goto out;
1666
1667 tfm = crypto_alloc_shash(driver, type, mask);
1668 if (IS_ERR(tfm)) {
1669 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1670 "%ld\n", driver, PTR_ERR(tfm));
1671 err = PTR_ERR(tfm);
1672 goto out;
1673 }
1674
1675 do {
1676 struct {
1677 struct shash_desc shash;
1678 char ctx[crypto_shash_descsize(tfm)];
1679 } sdesc;
1680
1681 sdesc.shash.tfm = tfm;
1682 sdesc.shash.flags = 0;
1683
1684 *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1685 err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1686 if (err) {
1687 printk(KERN_ERR "alg: crc32c: Operation failed for "
1688 "%s: %d\n", driver, err);
1689 break;
1690 }
1691
1692 if (val != ~420553207) {
1693 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1694 "%d\n", driver, val);
1695 err = -EINVAL;
1696 }
1697 } while (0);
1698
1699 crypto_free_shash(tfm);
1700
1701out:
1702 return err;
1703}
1704
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001705static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1706 u32 type, u32 mask)
1707{
1708 struct crypto_rng *rng;
1709 int err;
1710
1711 rng = crypto_alloc_rng(driver, type, mask);
1712 if (IS_ERR(rng)) {
1713 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1714 "%ld\n", driver, PTR_ERR(rng));
1715 return PTR_ERR(rng);
1716 }
1717
1718 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1719
1720 crypto_free_rng(rng);
1721
1722 return err;
1723}
1724
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001725
1726static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1727 const char *driver, u32 type, u32 mask)
1728{
1729 int ret = -EAGAIN;
1730 struct crypto_rng *drng;
1731 struct drbg_test_data test_data;
1732 struct drbg_string addtl, pers, testentropy;
1733 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1734
1735 if (!buf)
1736 return -ENOMEM;
1737
1738 drng = crypto_alloc_rng(driver, type, mask);
1739 if (IS_ERR(drng)) {
1740 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for"
1741 "%s\n", driver);
1742 kzfree(buf);
1743 return -ENOMEM;
1744 }
1745
1746 test_data.testentropy = &testentropy;
1747 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1748 drbg_string_fill(&pers, test->pers, test->perslen);
1749 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1750 if (ret) {
1751 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1752 goto outbuf;
1753 }
1754
1755 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1756 if (pr) {
1757 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1758 ret = crypto_drbg_get_bytes_addtl_test(drng,
1759 buf, test->expectedlen, &addtl, &test_data);
1760 } else {
1761 ret = crypto_drbg_get_bytes_addtl(drng,
1762 buf, test->expectedlen, &addtl);
1763 }
1764 if (ret <= 0) {
1765 printk(KERN_ERR "alg: drbg: could not obtain random data for"
1766 "driver %s\n", driver);
1767 goto outbuf;
1768 }
1769
1770 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1771 if (pr) {
1772 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1773 ret = crypto_drbg_get_bytes_addtl_test(drng,
1774 buf, test->expectedlen, &addtl, &test_data);
1775 } else {
1776 ret = crypto_drbg_get_bytes_addtl(drng,
1777 buf, test->expectedlen, &addtl);
1778 }
1779 if (ret <= 0) {
1780 printk(KERN_ERR "alg: drbg: could not obtain random data for"
1781 "driver %s\n", driver);
1782 goto outbuf;
1783 }
1784
1785 ret = memcmp(test->expected, buf, test->expectedlen);
1786
1787outbuf:
1788 crypto_free_rng(drng);
1789 kzfree(buf);
1790 return ret;
1791}
1792
1793
1794static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1795 u32 type, u32 mask)
1796{
1797 int err = 0;
1798 int pr = 0;
1799 int i = 0;
1800 struct drbg_testvec *template = desc->suite.drbg.vecs;
1801 unsigned int tcount = desc->suite.drbg.count;
1802
1803 if (0 == memcmp(driver, "drbg_pr_", 8))
1804 pr = 1;
1805
1806 for (i = 0; i < tcount; i++) {
1807 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1808 if (err) {
1809 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1810 i, driver);
1811 err = -EINVAL;
1812 break;
1813 }
1814 }
1815 return err;
1816
1817}
1818
Youquan, Song863b5572009-12-23 19:45:20 +08001819static int alg_test_null(const struct alg_test_desc *desc,
1820 const char *driver, u32 type, u32 mask)
1821{
1822 return 0;
1823}
1824
Herbert Xuda7f0332008-07-31 17:08:25 +08001825/* Please keep this list sorted by algorithm name. */
1826static const struct alg_test_desc alg_test_descs[] = {
1827 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001828 .alg = "__cbc-cast5-avx",
1829 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001830 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001831 .alg = "__cbc-cast6-avx",
1832 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001833 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001834 .alg = "__cbc-serpent-avx",
1835 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001836 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001837 .alg = "__cbc-serpent-avx2",
1838 .test = alg_test_null,
1839 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001840 .alg = "__cbc-serpent-sse2",
1841 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001842 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001843 .alg = "__cbc-twofish-avx",
1844 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001845 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001846 .alg = "__driver-cbc-aes-aesni",
1847 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001848 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001849 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001850 .alg = "__driver-cbc-camellia-aesni",
1851 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001852 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001853 .alg = "__driver-cbc-camellia-aesni-avx2",
1854 .test = alg_test_null,
1855 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001856 .alg = "__driver-cbc-cast5-avx",
1857 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001858 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001859 .alg = "__driver-cbc-cast6-avx",
1860 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001861 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001862 .alg = "__driver-cbc-serpent-avx",
1863 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001864 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001865 .alg = "__driver-cbc-serpent-avx2",
1866 .test = alg_test_null,
1867 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001868 .alg = "__driver-cbc-serpent-sse2",
1869 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001870 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001871 .alg = "__driver-cbc-twofish-avx",
1872 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001873 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001874 .alg = "__driver-ecb-aes-aesni",
1875 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001876 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001877 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001878 .alg = "__driver-ecb-camellia-aesni",
1879 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001880 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001881 .alg = "__driver-ecb-camellia-aesni-avx2",
1882 .test = alg_test_null,
1883 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001884 .alg = "__driver-ecb-cast5-avx",
1885 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001886 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001887 .alg = "__driver-ecb-cast6-avx",
1888 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001889 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001890 .alg = "__driver-ecb-serpent-avx",
1891 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001892 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001893 .alg = "__driver-ecb-serpent-avx2",
1894 .test = alg_test_null,
1895 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001896 .alg = "__driver-ecb-serpent-sse2",
1897 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001898 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001899 .alg = "__driver-ecb-twofish-avx",
1900 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001901 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001902 .alg = "__ghash-pclmulqdqni",
1903 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001904 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001905 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001906 .alg = "ansi_cprng",
1907 .test = alg_test_cprng,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001908 .fips_allowed = 1,
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001909 .suite = {
1910 .cprng = {
1911 .vecs = ansi_cprng_aes_tv_template,
1912 .count = ANSI_CPRNG_AES_TEST_VECTORS
1913 }
1914 }
1915 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001916 .alg = "authenc(hmac(md5),ecb(cipher_null))",
1917 .test = alg_test_aead,
1918 .fips_allowed = 1,
1919 .suite = {
1920 .aead = {
1921 .enc = {
1922 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
1923 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1924 },
1925 .dec = {
1926 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
1927 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1928 }
1929 }
1930 }
1931 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03001932 .alg = "authenc(hmac(sha1),cbc(aes))",
1933 .test = alg_test_aead,
1934 .fips_allowed = 1,
1935 .suite = {
1936 .aead = {
1937 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301938 .vecs =
1939 hmac_sha1_aes_cbc_enc_tv_temp,
1940 .count =
1941 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1942 }
1943 }
1944 }
1945 }, {
1946 .alg = "authenc(hmac(sha1),cbc(des))",
1947 .test = alg_test_aead,
1948 .fips_allowed = 1,
1949 .suite = {
1950 .aead = {
1951 .enc = {
1952 .vecs =
1953 hmac_sha1_des_cbc_enc_tv_temp,
1954 .count =
1955 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1956 }
1957 }
1958 }
1959 }, {
1960 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
1961 .test = alg_test_aead,
1962 .fips_allowed = 1,
1963 .suite = {
1964 .aead = {
1965 .enc = {
1966 .vecs =
1967 hmac_sha1_des3_ede_cbc_enc_tv_temp,
1968 .count =
1969 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03001970 }
1971 }
1972 }
1973 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001974 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
1975 .test = alg_test_aead,
1976 .fips_allowed = 1,
1977 .suite = {
1978 .aead = {
1979 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301980 .vecs =
1981 hmac_sha1_ecb_cipher_null_enc_tv_temp,
1982 .count =
1983 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02001984 },
1985 .dec = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301986 .vecs =
1987 hmac_sha1_ecb_cipher_null_dec_tv_temp,
1988 .count =
1989 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
1990 }
1991 }
1992 }
1993 }, {
1994 .alg = "authenc(hmac(sha224),cbc(des))",
1995 .test = alg_test_aead,
1996 .fips_allowed = 1,
1997 .suite = {
1998 .aead = {
1999 .enc = {
2000 .vecs =
2001 hmac_sha224_des_cbc_enc_tv_temp,
2002 .count =
2003 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2004 }
2005 }
2006 }
2007 }, {
2008 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
2009 .test = alg_test_aead,
2010 .fips_allowed = 1,
2011 .suite = {
2012 .aead = {
2013 .enc = {
2014 .vecs =
2015 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2016 .count =
2017 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002018 }
2019 }
2020 }
2021 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03002022 .alg = "authenc(hmac(sha256),cbc(aes))",
2023 .test = alg_test_aead,
2024 .fips_allowed = 1,
2025 .suite = {
2026 .aead = {
2027 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302028 .vecs =
2029 hmac_sha256_aes_cbc_enc_tv_temp,
2030 .count =
2031 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2032 }
2033 }
2034 }
2035 }, {
2036 .alg = "authenc(hmac(sha256),cbc(des))",
2037 .test = alg_test_aead,
2038 .fips_allowed = 1,
2039 .suite = {
2040 .aead = {
2041 .enc = {
2042 .vecs =
2043 hmac_sha256_des_cbc_enc_tv_temp,
2044 .count =
2045 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2046 }
2047 }
2048 }
2049 }, {
2050 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
2051 .test = alg_test_aead,
2052 .fips_allowed = 1,
2053 .suite = {
2054 .aead = {
2055 .enc = {
2056 .vecs =
2057 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2058 .count =
2059 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2060 }
2061 }
2062 }
2063 }, {
2064 .alg = "authenc(hmac(sha384),cbc(des))",
2065 .test = alg_test_aead,
2066 .fips_allowed = 1,
2067 .suite = {
2068 .aead = {
2069 .enc = {
2070 .vecs =
2071 hmac_sha384_des_cbc_enc_tv_temp,
2072 .count =
2073 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2074 }
2075 }
2076 }
2077 }, {
2078 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
2079 .test = alg_test_aead,
2080 .fips_allowed = 1,
2081 .suite = {
2082 .aead = {
2083 .enc = {
2084 .vecs =
2085 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2086 .count =
2087 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002088 }
2089 }
2090 }
2091 }, {
2092 .alg = "authenc(hmac(sha512),cbc(aes))",
2093 .test = alg_test_aead,
2094 .fips_allowed = 1,
2095 .suite = {
2096 .aead = {
2097 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302098 .vecs =
2099 hmac_sha512_aes_cbc_enc_tv_temp,
2100 .count =
2101 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2102 }
2103 }
2104 }
2105 }, {
2106 .alg = "authenc(hmac(sha512),cbc(des))",
2107 .test = alg_test_aead,
2108 .fips_allowed = 1,
2109 .suite = {
2110 .aead = {
2111 .enc = {
2112 .vecs =
2113 hmac_sha512_des_cbc_enc_tv_temp,
2114 .count =
2115 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2116 }
2117 }
2118 }
2119 }, {
2120 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2121 .test = alg_test_aead,
2122 .fips_allowed = 1,
2123 .suite = {
2124 .aead = {
2125 .enc = {
2126 .vecs =
2127 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2128 .count =
2129 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002130 }
2131 }
2132 }
2133 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002134 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002135 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002136 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002137 .suite = {
2138 .cipher = {
2139 .enc = {
2140 .vecs = aes_cbc_enc_tv_template,
2141 .count = AES_CBC_ENC_TEST_VECTORS
2142 },
2143 .dec = {
2144 .vecs = aes_cbc_dec_tv_template,
2145 .count = AES_CBC_DEC_TEST_VECTORS
2146 }
2147 }
2148 }
2149 }, {
2150 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002151 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002152 .suite = {
2153 .cipher = {
2154 .enc = {
2155 .vecs = anubis_cbc_enc_tv_template,
2156 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2157 },
2158 .dec = {
2159 .vecs = anubis_cbc_dec_tv_template,
2160 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2161 }
2162 }
2163 }
2164 }, {
2165 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002166 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002167 .suite = {
2168 .cipher = {
2169 .enc = {
2170 .vecs = bf_cbc_enc_tv_template,
2171 .count = BF_CBC_ENC_TEST_VECTORS
2172 },
2173 .dec = {
2174 .vecs = bf_cbc_dec_tv_template,
2175 .count = BF_CBC_DEC_TEST_VECTORS
2176 }
2177 }
2178 }
2179 }, {
2180 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002181 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002182 .suite = {
2183 .cipher = {
2184 .enc = {
2185 .vecs = camellia_cbc_enc_tv_template,
2186 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2187 },
2188 .dec = {
2189 .vecs = camellia_cbc_dec_tv_template,
2190 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2191 }
2192 }
2193 }
2194 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002195 .alg = "cbc(cast5)",
2196 .test = alg_test_skcipher,
2197 .suite = {
2198 .cipher = {
2199 .enc = {
2200 .vecs = cast5_cbc_enc_tv_template,
2201 .count = CAST5_CBC_ENC_TEST_VECTORS
2202 },
2203 .dec = {
2204 .vecs = cast5_cbc_dec_tv_template,
2205 .count = CAST5_CBC_DEC_TEST_VECTORS
2206 }
2207 }
2208 }
2209 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002210 .alg = "cbc(cast6)",
2211 .test = alg_test_skcipher,
2212 .suite = {
2213 .cipher = {
2214 .enc = {
2215 .vecs = cast6_cbc_enc_tv_template,
2216 .count = CAST6_CBC_ENC_TEST_VECTORS
2217 },
2218 .dec = {
2219 .vecs = cast6_cbc_dec_tv_template,
2220 .count = CAST6_CBC_DEC_TEST_VECTORS
2221 }
2222 }
2223 }
2224 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002225 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002226 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002227 .suite = {
2228 .cipher = {
2229 .enc = {
2230 .vecs = des_cbc_enc_tv_template,
2231 .count = DES_CBC_ENC_TEST_VECTORS
2232 },
2233 .dec = {
2234 .vecs = des_cbc_dec_tv_template,
2235 .count = DES_CBC_DEC_TEST_VECTORS
2236 }
2237 }
2238 }
2239 }, {
2240 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002241 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002242 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002243 .suite = {
2244 .cipher = {
2245 .enc = {
2246 .vecs = des3_ede_cbc_enc_tv_template,
2247 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2248 },
2249 .dec = {
2250 .vecs = des3_ede_cbc_dec_tv_template,
2251 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2252 }
2253 }
2254 }
2255 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002256 .alg = "cbc(serpent)",
2257 .test = alg_test_skcipher,
2258 .suite = {
2259 .cipher = {
2260 .enc = {
2261 .vecs = serpent_cbc_enc_tv_template,
2262 .count = SERPENT_CBC_ENC_TEST_VECTORS
2263 },
2264 .dec = {
2265 .vecs = serpent_cbc_dec_tv_template,
2266 .count = SERPENT_CBC_DEC_TEST_VECTORS
2267 }
2268 }
2269 }
2270 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002271 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002272 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002273 .suite = {
2274 .cipher = {
2275 .enc = {
2276 .vecs = tf_cbc_enc_tv_template,
2277 .count = TF_CBC_ENC_TEST_VECTORS
2278 },
2279 .dec = {
2280 .vecs = tf_cbc_dec_tv_template,
2281 .count = TF_CBC_DEC_TEST_VECTORS
2282 }
2283 }
2284 }
2285 }, {
2286 .alg = "ccm(aes)",
2287 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002288 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002289 .suite = {
2290 .aead = {
2291 .enc = {
2292 .vecs = aes_ccm_enc_tv_template,
2293 .count = AES_CCM_ENC_TEST_VECTORS
2294 },
2295 .dec = {
2296 .vecs = aes_ccm_dec_tv_template,
2297 .count = AES_CCM_DEC_TEST_VECTORS
2298 }
2299 }
2300 }
2301 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002302 .alg = "cmac(aes)",
2303 .test = alg_test_hash,
2304 .suite = {
2305 .hash = {
2306 .vecs = aes_cmac128_tv_template,
2307 .count = CMAC_AES_TEST_VECTORS
2308 }
2309 }
2310 }, {
2311 .alg = "cmac(des3_ede)",
2312 .test = alg_test_hash,
2313 .suite = {
2314 .hash = {
2315 .vecs = des3_ede_cmac64_tv_template,
2316 .count = CMAC_DES3_EDE_TEST_VECTORS
2317 }
2318 }
2319 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002320 .alg = "compress_null",
2321 .test = alg_test_null,
2322 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002323 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002324 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002325 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002326 .suite = {
2327 .hash = {
2328 .vecs = crc32c_tv_template,
2329 .count = CRC32C_TEST_VECTORS
2330 }
2331 }
2332 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002333 .alg = "crct10dif",
2334 .test = alg_test_hash,
2335 .fips_allowed = 1,
2336 .suite = {
2337 .hash = {
2338 .vecs = crct10dif_tv_template,
2339 .count = CRCT10DIF_TEST_VECTORS
2340 }
2341 }
2342 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002343 .alg = "cryptd(__driver-cbc-aes-aesni)",
2344 .test = alg_test_null,
2345 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002346 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002347 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2348 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002349 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002350 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2351 .test = alg_test_null,
2352 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002353 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2354 .test = alg_test_null,
2355 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002356 .alg = "cryptd(__driver-ecb-aes-aesni)",
2357 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002358 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002359 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002360 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2361 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002362 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002363 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2364 .test = alg_test_null,
2365 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002366 .alg = "cryptd(__driver-ecb-cast5-avx)",
2367 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002368 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002369 .alg = "cryptd(__driver-ecb-cast6-avx)",
2370 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002371 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002372 .alg = "cryptd(__driver-ecb-serpent-avx)",
2373 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002374 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002375 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2376 .test = alg_test_null,
2377 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002378 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2379 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002380 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002381 .alg = "cryptd(__driver-ecb-twofish-avx)",
2382 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002383 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002384 .alg = "cryptd(__driver-gcm-aes-aesni)",
2385 .test = alg_test_null,
2386 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002387 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002388 .alg = "cryptd(__ghash-pclmulqdqni)",
2389 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002390 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002391 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002392 .alg = "ctr(aes)",
2393 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002394 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002395 .suite = {
2396 .cipher = {
2397 .enc = {
2398 .vecs = aes_ctr_enc_tv_template,
2399 .count = AES_CTR_ENC_TEST_VECTORS
2400 },
2401 .dec = {
2402 .vecs = aes_ctr_dec_tv_template,
2403 .count = AES_CTR_DEC_TEST_VECTORS
2404 }
2405 }
2406 }
2407 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002408 .alg = "ctr(blowfish)",
2409 .test = alg_test_skcipher,
2410 .suite = {
2411 .cipher = {
2412 .enc = {
2413 .vecs = bf_ctr_enc_tv_template,
2414 .count = BF_CTR_ENC_TEST_VECTORS
2415 },
2416 .dec = {
2417 .vecs = bf_ctr_dec_tv_template,
2418 .count = BF_CTR_DEC_TEST_VECTORS
2419 }
2420 }
2421 }
2422 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002423 .alg = "ctr(camellia)",
2424 .test = alg_test_skcipher,
2425 .suite = {
2426 .cipher = {
2427 .enc = {
2428 .vecs = camellia_ctr_enc_tv_template,
2429 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2430 },
2431 .dec = {
2432 .vecs = camellia_ctr_dec_tv_template,
2433 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2434 }
2435 }
2436 }
2437 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002438 .alg = "ctr(cast5)",
2439 .test = alg_test_skcipher,
2440 .suite = {
2441 .cipher = {
2442 .enc = {
2443 .vecs = cast5_ctr_enc_tv_template,
2444 .count = CAST5_CTR_ENC_TEST_VECTORS
2445 },
2446 .dec = {
2447 .vecs = cast5_ctr_dec_tv_template,
2448 .count = CAST5_CTR_DEC_TEST_VECTORS
2449 }
2450 }
2451 }
2452 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002453 .alg = "ctr(cast6)",
2454 .test = alg_test_skcipher,
2455 .suite = {
2456 .cipher = {
2457 .enc = {
2458 .vecs = cast6_ctr_enc_tv_template,
2459 .count = CAST6_CTR_ENC_TEST_VECTORS
2460 },
2461 .dec = {
2462 .vecs = cast6_ctr_dec_tv_template,
2463 .count = CAST6_CTR_DEC_TEST_VECTORS
2464 }
2465 }
2466 }
2467 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002468 .alg = "ctr(des)",
2469 .test = alg_test_skcipher,
2470 .suite = {
2471 .cipher = {
2472 .enc = {
2473 .vecs = des_ctr_enc_tv_template,
2474 .count = DES_CTR_ENC_TEST_VECTORS
2475 },
2476 .dec = {
2477 .vecs = des_ctr_dec_tv_template,
2478 .count = DES_CTR_DEC_TEST_VECTORS
2479 }
2480 }
2481 }
2482 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002483 .alg = "ctr(des3_ede)",
2484 .test = alg_test_skcipher,
2485 .suite = {
2486 .cipher = {
2487 .enc = {
2488 .vecs = des3_ede_ctr_enc_tv_template,
2489 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2490 },
2491 .dec = {
2492 .vecs = des3_ede_ctr_dec_tv_template,
2493 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2494 }
2495 }
2496 }
2497 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002498 .alg = "ctr(serpent)",
2499 .test = alg_test_skcipher,
2500 .suite = {
2501 .cipher = {
2502 .enc = {
2503 .vecs = serpent_ctr_enc_tv_template,
2504 .count = SERPENT_CTR_ENC_TEST_VECTORS
2505 },
2506 .dec = {
2507 .vecs = serpent_ctr_dec_tv_template,
2508 .count = SERPENT_CTR_DEC_TEST_VECTORS
2509 }
2510 }
2511 }
2512 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002513 .alg = "ctr(twofish)",
2514 .test = alg_test_skcipher,
2515 .suite = {
2516 .cipher = {
2517 .enc = {
2518 .vecs = tf_ctr_enc_tv_template,
2519 .count = TF_CTR_ENC_TEST_VECTORS
2520 },
2521 .dec = {
2522 .vecs = tf_ctr_dec_tv_template,
2523 .count = TF_CTR_DEC_TEST_VECTORS
2524 }
2525 }
2526 }
2527 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002528 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002529 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002530 .suite = {
2531 .cipher = {
2532 .enc = {
2533 .vecs = cts_mode_enc_tv_template,
2534 .count = CTS_MODE_ENC_TEST_VECTORS
2535 },
2536 .dec = {
2537 .vecs = cts_mode_dec_tv_template,
2538 .count = CTS_MODE_DEC_TEST_VECTORS
2539 }
2540 }
2541 }
2542 }, {
2543 .alg = "deflate",
2544 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002545 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002546 .suite = {
2547 .comp = {
2548 .comp = {
2549 .vecs = deflate_comp_tv_template,
2550 .count = DEFLATE_COMP_TEST_VECTORS
2551 },
2552 .decomp = {
2553 .vecs = deflate_decomp_tv_template,
2554 .count = DEFLATE_DECOMP_TEST_VECTORS
2555 }
2556 }
2557 }
2558 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002559 .alg = "digest_null",
2560 .test = alg_test_null,
2561 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002562 .alg = "drbg_nopr_ctr_aes128",
2563 .test = alg_test_drbg,
2564 .fips_allowed = 1,
2565 .suite = {
2566 .drbg = {
2567 .vecs = drbg_nopr_ctr_aes128_tv_template,
2568 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2569 }
2570 }
2571 }, {
2572 .alg = "drbg_nopr_ctr_aes192",
2573 .test = alg_test_drbg,
2574 .fips_allowed = 1,
2575 .suite = {
2576 .drbg = {
2577 .vecs = drbg_nopr_ctr_aes192_tv_template,
2578 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2579 }
2580 }
2581 }, {
2582 .alg = "drbg_nopr_ctr_aes256",
2583 .test = alg_test_drbg,
2584 .fips_allowed = 1,
2585 .suite = {
2586 .drbg = {
2587 .vecs = drbg_nopr_ctr_aes256_tv_template,
2588 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2589 }
2590 }
2591 }, {
2592 /*
2593 * There is no need to specifically test the DRBG with every
2594 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2595 */
2596 .alg = "drbg_nopr_hmac_sha1",
2597 .fips_allowed = 1,
2598 .test = alg_test_null,
2599 }, {
2600 .alg = "drbg_nopr_hmac_sha256",
2601 .test = alg_test_drbg,
2602 .fips_allowed = 1,
2603 .suite = {
2604 .drbg = {
2605 .vecs = drbg_nopr_hmac_sha256_tv_template,
2606 .count =
2607 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2608 }
2609 }
2610 }, {
2611 /* covered by drbg_nopr_hmac_sha256 test */
2612 .alg = "drbg_nopr_hmac_sha384",
2613 .fips_allowed = 1,
2614 .test = alg_test_null,
2615 }, {
2616 .alg = "drbg_nopr_hmac_sha512",
2617 .test = alg_test_null,
2618 .fips_allowed = 1,
2619 }, {
2620 .alg = "drbg_nopr_sha1",
2621 .fips_allowed = 1,
2622 .test = alg_test_null,
2623 }, {
2624 .alg = "drbg_nopr_sha256",
2625 .test = alg_test_drbg,
2626 .fips_allowed = 1,
2627 .suite = {
2628 .drbg = {
2629 .vecs = drbg_nopr_sha256_tv_template,
2630 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2631 }
2632 }
2633 }, {
2634 /* covered by drbg_nopr_sha256 test */
2635 .alg = "drbg_nopr_sha384",
2636 .fips_allowed = 1,
2637 .test = alg_test_null,
2638 }, {
2639 .alg = "drbg_nopr_sha512",
2640 .fips_allowed = 1,
2641 .test = alg_test_null,
2642 }, {
2643 .alg = "drbg_pr_ctr_aes128",
2644 .test = alg_test_drbg,
2645 .fips_allowed = 1,
2646 .suite = {
2647 .drbg = {
2648 .vecs = drbg_pr_ctr_aes128_tv_template,
2649 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2650 }
2651 }
2652 }, {
2653 /* covered by drbg_pr_ctr_aes128 test */
2654 .alg = "drbg_pr_ctr_aes192",
2655 .fips_allowed = 1,
2656 .test = alg_test_null,
2657 }, {
2658 .alg = "drbg_pr_ctr_aes256",
2659 .fips_allowed = 1,
2660 .test = alg_test_null,
2661 }, {
2662 .alg = "drbg_pr_hmac_sha1",
2663 .fips_allowed = 1,
2664 .test = alg_test_null,
2665 }, {
2666 .alg = "drbg_pr_hmac_sha256",
2667 .test = alg_test_drbg,
2668 .fips_allowed = 1,
2669 .suite = {
2670 .drbg = {
2671 .vecs = drbg_pr_hmac_sha256_tv_template,
2672 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2673 }
2674 }
2675 }, {
2676 /* covered by drbg_pr_hmac_sha256 test */
2677 .alg = "drbg_pr_hmac_sha384",
2678 .fips_allowed = 1,
2679 .test = alg_test_null,
2680 }, {
2681 .alg = "drbg_pr_hmac_sha512",
2682 .test = alg_test_null,
2683 .fips_allowed = 1,
2684 }, {
2685 .alg = "drbg_pr_sha1",
2686 .fips_allowed = 1,
2687 .test = alg_test_null,
2688 }, {
2689 .alg = "drbg_pr_sha256",
2690 .test = alg_test_drbg,
2691 .fips_allowed = 1,
2692 .suite = {
2693 .drbg = {
2694 .vecs = drbg_pr_sha256_tv_template,
2695 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2696 }
2697 }
2698 }, {
2699 /* covered by drbg_pr_sha256 test */
2700 .alg = "drbg_pr_sha384",
2701 .fips_allowed = 1,
2702 .test = alg_test_null,
2703 }, {
2704 .alg = "drbg_pr_sha512",
2705 .fips_allowed = 1,
2706 .test = alg_test_null,
2707 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002708 .alg = "ecb(__aes-aesni)",
2709 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002710 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002711 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002712 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002713 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002714 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002715 .suite = {
2716 .cipher = {
2717 .enc = {
2718 .vecs = aes_enc_tv_template,
2719 .count = AES_ENC_TEST_VECTORS
2720 },
2721 .dec = {
2722 .vecs = aes_dec_tv_template,
2723 .count = AES_DEC_TEST_VECTORS
2724 }
2725 }
2726 }
2727 }, {
2728 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002729 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002730 .suite = {
2731 .cipher = {
2732 .enc = {
2733 .vecs = anubis_enc_tv_template,
2734 .count = ANUBIS_ENC_TEST_VECTORS
2735 },
2736 .dec = {
2737 .vecs = anubis_dec_tv_template,
2738 .count = ANUBIS_DEC_TEST_VECTORS
2739 }
2740 }
2741 }
2742 }, {
2743 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002744 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002745 .suite = {
2746 .cipher = {
2747 .enc = {
2748 .vecs = arc4_enc_tv_template,
2749 .count = ARC4_ENC_TEST_VECTORS
2750 },
2751 .dec = {
2752 .vecs = arc4_dec_tv_template,
2753 .count = ARC4_DEC_TEST_VECTORS
2754 }
2755 }
2756 }
2757 }, {
2758 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002759 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002760 .suite = {
2761 .cipher = {
2762 .enc = {
2763 .vecs = bf_enc_tv_template,
2764 .count = BF_ENC_TEST_VECTORS
2765 },
2766 .dec = {
2767 .vecs = bf_dec_tv_template,
2768 .count = BF_DEC_TEST_VECTORS
2769 }
2770 }
2771 }
2772 }, {
2773 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002774 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002775 .suite = {
2776 .cipher = {
2777 .enc = {
2778 .vecs = camellia_enc_tv_template,
2779 .count = CAMELLIA_ENC_TEST_VECTORS
2780 },
2781 .dec = {
2782 .vecs = camellia_dec_tv_template,
2783 .count = CAMELLIA_DEC_TEST_VECTORS
2784 }
2785 }
2786 }
2787 }, {
2788 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002789 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002790 .suite = {
2791 .cipher = {
2792 .enc = {
2793 .vecs = cast5_enc_tv_template,
2794 .count = CAST5_ENC_TEST_VECTORS
2795 },
2796 .dec = {
2797 .vecs = cast5_dec_tv_template,
2798 .count = CAST5_DEC_TEST_VECTORS
2799 }
2800 }
2801 }
2802 }, {
2803 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002804 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002805 .suite = {
2806 .cipher = {
2807 .enc = {
2808 .vecs = cast6_enc_tv_template,
2809 .count = CAST6_ENC_TEST_VECTORS
2810 },
2811 .dec = {
2812 .vecs = cast6_dec_tv_template,
2813 .count = CAST6_DEC_TEST_VECTORS
2814 }
2815 }
2816 }
2817 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002818 .alg = "ecb(cipher_null)",
2819 .test = alg_test_null,
2820 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002821 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002822 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002823 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002824 .suite = {
2825 .cipher = {
2826 .enc = {
2827 .vecs = des_enc_tv_template,
2828 .count = DES_ENC_TEST_VECTORS
2829 },
2830 .dec = {
2831 .vecs = des_dec_tv_template,
2832 .count = DES_DEC_TEST_VECTORS
2833 }
2834 }
2835 }
2836 }, {
2837 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002838 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002839 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002840 .suite = {
2841 .cipher = {
2842 .enc = {
2843 .vecs = des3_ede_enc_tv_template,
2844 .count = DES3_EDE_ENC_TEST_VECTORS
2845 },
2846 .dec = {
2847 .vecs = des3_ede_dec_tv_template,
2848 .count = DES3_EDE_DEC_TEST_VECTORS
2849 }
2850 }
2851 }
2852 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002853 .alg = "ecb(fcrypt)",
2854 .test = alg_test_skcipher,
2855 .suite = {
2856 .cipher = {
2857 .enc = {
2858 .vecs = fcrypt_pcbc_enc_tv_template,
2859 .count = 1
2860 },
2861 .dec = {
2862 .vecs = fcrypt_pcbc_dec_tv_template,
2863 .count = 1
2864 }
2865 }
2866 }
2867 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002868 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002869 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002870 .suite = {
2871 .cipher = {
2872 .enc = {
2873 .vecs = khazad_enc_tv_template,
2874 .count = KHAZAD_ENC_TEST_VECTORS
2875 },
2876 .dec = {
2877 .vecs = khazad_dec_tv_template,
2878 .count = KHAZAD_DEC_TEST_VECTORS
2879 }
2880 }
2881 }
2882 }, {
2883 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002884 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002885 .suite = {
2886 .cipher = {
2887 .enc = {
2888 .vecs = seed_enc_tv_template,
2889 .count = SEED_ENC_TEST_VECTORS
2890 },
2891 .dec = {
2892 .vecs = seed_dec_tv_template,
2893 .count = SEED_DEC_TEST_VECTORS
2894 }
2895 }
2896 }
2897 }, {
2898 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002899 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002900 .suite = {
2901 .cipher = {
2902 .enc = {
2903 .vecs = serpent_enc_tv_template,
2904 .count = SERPENT_ENC_TEST_VECTORS
2905 },
2906 .dec = {
2907 .vecs = serpent_dec_tv_template,
2908 .count = SERPENT_DEC_TEST_VECTORS
2909 }
2910 }
2911 }
2912 }, {
2913 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002914 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002915 .suite = {
2916 .cipher = {
2917 .enc = {
2918 .vecs = tea_enc_tv_template,
2919 .count = TEA_ENC_TEST_VECTORS
2920 },
2921 .dec = {
2922 .vecs = tea_dec_tv_template,
2923 .count = TEA_DEC_TEST_VECTORS
2924 }
2925 }
2926 }
2927 }, {
2928 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002929 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002930 .suite = {
2931 .cipher = {
2932 .enc = {
2933 .vecs = tnepres_enc_tv_template,
2934 .count = TNEPRES_ENC_TEST_VECTORS
2935 },
2936 .dec = {
2937 .vecs = tnepres_dec_tv_template,
2938 .count = TNEPRES_DEC_TEST_VECTORS
2939 }
2940 }
2941 }
2942 }, {
2943 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002944 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002945 .suite = {
2946 .cipher = {
2947 .enc = {
2948 .vecs = tf_enc_tv_template,
2949 .count = TF_ENC_TEST_VECTORS
2950 },
2951 .dec = {
2952 .vecs = tf_dec_tv_template,
2953 .count = TF_DEC_TEST_VECTORS
2954 }
2955 }
2956 }
2957 }, {
2958 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002959 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002960 .suite = {
2961 .cipher = {
2962 .enc = {
2963 .vecs = xeta_enc_tv_template,
2964 .count = XETA_ENC_TEST_VECTORS
2965 },
2966 .dec = {
2967 .vecs = xeta_dec_tv_template,
2968 .count = XETA_DEC_TEST_VECTORS
2969 }
2970 }
2971 }
2972 }, {
2973 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002974 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002975 .suite = {
2976 .cipher = {
2977 .enc = {
2978 .vecs = xtea_enc_tv_template,
2979 .count = XTEA_ENC_TEST_VECTORS
2980 },
2981 .dec = {
2982 .vecs = xtea_dec_tv_template,
2983 .count = XTEA_DEC_TEST_VECTORS
2984 }
2985 }
2986 }
2987 }, {
2988 .alg = "gcm(aes)",
2989 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002990 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002991 .suite = {
2992 .aead = {
2993 .enc = {
2994 .vecs = aes_gcm_enc_tv_template,
2995 .count = AES_GCM_ENC_TEST_VECTORS
2996 },
2997 .dec = {
2998 .vecs = aes_gcm_dec_tv_template,
2999 .count = AES_GCM_DEC_TEST_VECTORS
3000 }
3001 }
3002 }
3003 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003004 .alg = "ghash",
3005 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003006 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003007 .suite = {
3008 .hash = {
3009 .vecs = ghash_tv_template,
3010 .count = GHASH_TEST_VECTORS
3011 }
3012 }
3013 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003014 .alg = "hmac(crc32)",
3015 .test = alg_test_hash,
3016 .suite = {
3017 .hash = {
3018 .vecs = bfin_crc_tv_template,
3019 .count = BFIN_CRC_TEST_VECTORS
3020 }
3021 }
3022 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003023 .alg = "hmac(md5)",
3024 .test = alg_test_hash,
3025 .suite = {
3026 .hash = {
3027 .vecs = hmac_md5_tv_template,
3028 .count = HMAC_MD5_TEST_VECTORS
3029 }
3030 }
3031 }, {
3032 .alg = "hmac(rmd128)",
3033 .test = alg_test_hash,
3034 .suite = {
3035 .hash = {
3036 .vecs = hmac_rmd128_tv_template,
3037 .count = HMAC_RMD128_TEST_VECTORS
3038 }
3039 }
3040 }, {
3041 .alg = "hmac(rmd160)",
3042 .test = alg_test_hash,
3043 .suite = {
3044 .hash = {
3045 .vecs = hmac_rmd160_tv_template,
3046 .count = HMAC_RMD160_TEST_VECTORS
3047 }
3048 }
3049 }, {
3050 .alg = "hmac(sha1)",
3051 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003052 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003053 .suite = {
3054 .hash = {
3055 .vecs = hmac_sha1_tv_template,
3056 .count = HMAC_SHA1_TEST_VECTORS
3057 }
3058 }
3059 }, {
3060 .alg = "hmac(sha224)",
3061 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003062 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003063 .suite = {
3064 .hash = {
3065 .vecs = hmac_sha224_tv_template,
3066 .count = HMAC_SHA224_TEST_VECTORS
3067 }
3068 }
3069 }, {
3070 .alg = "hmac(sha256)",
3071 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003072 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003073 .suite = {
3074 .hash = {
3075 .vecs = hmac_sha256_tv_template,
3076 .count = HMAC_SHA256_TEST_VECTORS
3077 }
3078 }
3079 }, {
3080 .alg = "hmac(sha384)",
3081 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003082 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003083 .suite = {
3084 .hash = {
3085 .vecs = hmac_sha384_tv_template,
3086 .count = HMAC_SHA384_TEST_VECTORS
3087 }
3088 }
3089 }, {
3090 .alg = "hmac(sha512)",
3091 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003092 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003093 .suite = {
3094 .hash = {
3095 .vecs = hmac_sha512_tv_template,
3096 .count = HMAC_SHA512_TEST_VECTORS
3097 }
3098 }
3099 }, {
3100 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003101 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003102 .suite = {
3103 .cipher = {
3104 .enc = {
3105 .vecs = aes_lrw_enc_tv_template,
3106 .count = AES_LRW_ENC_TEST_VECTORS
3107 },
3108 .dec = {
3109 .vecs = aes_lrw_dec_tv_template,
3110 .count = AES_LRW_DEC_TEST_VECTORS
3111 }
3112 }
3113 }
3114 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003115 .alg = "lrw(camellia)",
3116 .test = alg_test_skcipher,
3117 .suite = {
3118 .cipher = {
3119 .enc = {
3120 .vecs = camellia_lrw_enc_tv_template,
3121 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3122 },
3123 .dec = {
3124 .vecs = camellia_lrw_dec_tv_template,
3125 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3126 }
3127 }
3128 }
3129 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003130 .alg = "lrw(cast6)",
3131 .test = alg_test_skcipher,
3132 .suite = {
3133 .cipher = {
3134 .enc = {
3135 .vecs = cast6_lrw_enc_tv_template,
3136 .count = CAST6_LRW_ENC_TEST_VECTORS
3137 },
3138 .dec = {
3139 .vecs = cast6_lrw_dec_tv_template,
3140 .count = CAST6_LRW_DEC_TEST_VECTORS
3141 }
3142 }
3143 }
3144 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003145 .alg = "lrw(serpent)",
3146 .test = alg_test_skcipher,
3147 .suite = {
3148 .cipher = {
3149 .enc = {
3150 .vecs = serpent_lrw_enc_tv_template,
3151 .count = SERPENT_LRW_ENC_TEST_VECTORS
3152 },
3153 .dec = {
3154 .vecs = serpent_lrw_dec_tv_template,
3155 .count = SERPENT_LRW_DEC_TEST_VECTORS
3156 }
3157 }
3158 }
3159 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003160 .alg = "lrw(twofish)",
3161 .test = alg_test_skcipher,
3162 .suite = {
3163 .cipher = {
3164 .enc = {
3165 .vecs = tf_lrw_enc_tv_template,
3166 .count = TF_LRW_ENC_TEST_VECTORS
3167 },
3168 .dec = {
3169 .vecs = tf_lrw_dec_tv_template,
3170 .count = TF_LRW_DEC_TEST_VECTORS
3171 }
3172 }
3173 }
3174 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003175 .alg = "lzo",
3176 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003177 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003178 .suite = {
3179 .comp = {
3180 .comp = {
3181 .vecs = lzo_comp_tv_template,
3182 .count = LZO_COMP_TEST_VECTORS
3183 },
3184 .decomp = {
3185 .vecs = lzo_decomp_tv_template,
3186 .count = LZO_DECOMP_TEST_VECTORS
3187 }
3188 }
3189 }
3190 }, {
3191 .alg = "md4",
3192 .test = alg_test_hash,
3193 .suite = {
3194 .hash = {
3195 .vecs = md4_tv_template,
3196 .count = MD4_TEST_VECTORS
3197 }
3198 }
3199 }, {
3200 .alg = "md5",
3201 .test = alg_test_hash,
3202 .suite = {
3203 .hash = {
3204 .vecs = md5_tv_template,
3205 .count = MD5_TEST_VECTORS
3206 }
3207 }
3208 }, {
3209 .alg = "michael_mic",
3210 .test = alg_test_hash,
3211 .suite = {
3212 .hash = {
3213 .vecs = michael_mic_tv_template,
3214 .count = MICHAEL_MIC_TEST_VECTORS
3215 }
3216 }
3217 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003218 .alg = "ofb(aes)",
3219 .test = alg_test_skcipher,
3220 .fips_allowed = 1,
3221 .suite = {
3222 .cipher = {
3223 .enc = {
3224 .vecs = aes_ofb_enc_tv_template,
3225 .count = AES_OFB_ENC_TEST_VECTORS
3226 },
3227 .dec = {
3228 .vecs = aes_ofb_dec_tv_template,
3229 .count = AES_OFB_DEC_TEST_VECTORS
3230 }
3231 }
3232 }
3233 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003234 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003235 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003236 .suite = {
3237 .cipher = {
3238 .enc = {
3239 .vecs = fcrypt_pcbc_enc_tv_template,
3240 .count = FCRYPT_ENC_TEST_VECTORS
3241 },
3242 .dec = {
3243 .vecs = fcrypt_pcbc_dec_tv_template,
3244 .count = FCRYPT_DEC_TEST_VECTORS
3245 }
3246 }
3247 }
3248 }, {
3249 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003250 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003251 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003252 .suite = {
3253 .cipher = {
3254 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003255 .vecs = aes_ctr_rfc3686_enc_tv_template,
3256 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003257 },
3258 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003259 .vecs = aes_ctr_rfc3686_dec_tv_template,
3260 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003261 }
3262 }
3263 }
3264 }, {
Adrian Hoban69435b92010-11-04 15:02:04 -04003265 .alg = "rfc4106(gcm(aes))",
3266 .test = alg_test_aead,
3267 .suite = {
3268 .aead = {
3269 .enc = {
3270 .vecs = aes_gcm_rfc4106_enc_tv_template,
3271 .count = AES_GCM_4106_ENC_TEST_VECTORS
3272 },
3273 .dec = {
3274 .vecs = aes_gcm_rfc4106_dec_tv_template,
3275 .count = AES_GCM_4106_DEC_TEST_VECTORS
3276 }
3277 }
3278 }
3279 }, {
Jarod Wilson5d667322009-05-04 19:23:40 +08003280 .alg = "rfc4309(ccm(aes))",
3281 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003282 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003283 .suite = {
3284 .aead = {
3285 .enc = {
3286 .vecs = aes_ccm_rfc4309_enc_tv_template,
3287 .count = AES_CCM_4309_ENC_TEST_VECTORS
3288 },
3289 .dec = {
3290 .vecs = aes_ccm_rfc4309_dec_tv_template,
3291 .count = AES_CCM_4309_DEC_TEST_VECTORS
3292 }
3293 }
3294 }
3295 }, {
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003296 .alg = "rfc4543(gcm(aes))",
3297 .test = alg_test_aead,
3298 .suite = {
3299 .aead = {
3300 .enc = {
3301 .vecs = aes_gcm_rfc4543_enc_tv_template,
3302 .count = AES_GCM_4543_ENC_TEST_VECTORS
3303 },
3304 .dec = {
3305 .vecs = aes_gcm_rfc4543_dec_tv_template,
3306 .count = AES_GCM_4543_DEC_TEST_VECTORS
3307 },
3308 }
3309 }
3310 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003311 .alg = "rmd128",
3312 .test = alg_test_hash,
3313 .suite = {
3314 .hash = {
3315 .vecs = rmd128_tv_template,
3316 .count = RMD128_TEST_VECTORS
3317 }
3318 }
3319 }, {
3320 .alg = "rmd160",
3321 .test = alg_test_hash,
3322 .suite = {
3323 .hash = {
3324 .vecs = rmd160_tv_template,
3325 .count = RMD160_TEST_VECTORS
3326 }
3327 }
3328 }, {
3329 .alg = "rmd256",
3330 .test = alg_test_hash,
3331 .suite = {
3332 .hash = {
3333 .vecs = rmd256_tv_template,
3334 .count = RMD256_TEST_VECTORS
3335 }
3336 }
3337 }, {
3338 .alg = "rmd320",
3339 .test = alg_test_hash,
3340 .suite = {
3341 .hash = {
3342 .vecs = rmd320_tv_template,
3343 .count = RMD320_TEST_VECTORS
3344 }
3345 }
3346 }, {
3347 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003348 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003349 .suite = {
3350 .cipher = {
3351 .enc = {
3352 .vecs = salsa20_stream_enc_tv_template,
3353 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3354 }
3355 }
3356 }
3357 }, {
3358 .alg = "sha1",
3359 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003360 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003361 .suite = {
3362 .hash = {
3363 .vecs = sha1_tv_template,
3364 .count = SHA1_TEST_VECTORS
3365 }
3366 }
3367 }, {
3368 .alg = "sha224",
3369 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003370 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003371 .suite = {
3372 .hash = {
3373 .vecs = sha224_tv_template,
3374 .count = SHA224_TEST_VECTORS
3375 }
3376 }
3377 }, {
3378 .alg = "sha256",
3379 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003380 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003381 .suite = {
3382 .hash = {
3383 .vecs = sha256_tv_template,
3384 .count = SHA256_TEST_VECTORS
3385 }
3386 }
3387 }, {
3388 .alg = "sha384",
3389 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003390 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003391 .suite = {
3392 .hash = {
3393 .vecs = sha384_tv_template,
3394 .count = SHA384_TEST_VECTORS
3395 }
3396 }
3397 }, {
3398 .alg = "sha512",
3399 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003400 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003401 .suite = {
3402 .hash = {
3403 .vecs = sha512_tv_template,
3404 .count = SHA512_TEST_VECTORS
3405 }
3406 }
3407 }, {
3408 .alg = "tgr128",
3409 .test = alg_test_hash,
3410 .suite = {
3411 .hash = {
3412 .vecs = tgr128_tv_template,
3413 .count = TGR128_TEST_VECTORS
3414 }
3415 }
3416 }, {
3417 .alg = "tgr160",
3418 .test = alg_test_hash,
3419 .suite = {
3420 .hash = {
3421 .vecs = tgr160_tv_template,
3422 .count = TGR160_TEST_VECTORS
3423 }
3424 }
3425 }, {
3426 .alg = "tgr192",
3427 .test = alg_test_hash,
3428 .suite = {
3429 .hash = {
3430 .vecs = tgr192_tv_template,
3431 .count = TGR192_TEST_VECTORS
3432 }
3433 }
3434 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003435 .alg = "vmac(aes)",
3436 .test = alg_test_hash,
3437 .suite = {
3438 .hash = {
3439 .vecs = aes_vmac128_tv_template,
3440 .count = VMAC_AES_TEST_VECTORS
3441 }
3442 }
3443 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003444 .alg = "wp256",
3445 .test = alg_test_hash,
3446 .suite = {
3447 .hash = {
3448 .vecs = wp256_tv_template,
3449 .count = WP256_TEST_VECTORS
3450 }
3451 }
3452 }, {
3453 .alg = "wp384",
3454 .test = alg_test_hash,
3455 .suite = {
3456 .hash = {
3457 .vecs = wp384_tv_template,
3458 .count = WP384_TEST_VECTORS
3459 }
3460 }
3461 }, {
3462 .alg = "wp512",
3463 .test = alg_test_hash,
3464 .suite = {
3465 .hash = {
3466 .vecs = wp512_tv_template,
3467 .count = WP512_TEST_VECTORS
3468 }
3469 }
3470 }, {
3471 .alg = "xcbc(aes)",
3472 .test = alg_test_hash,
3473 .suite = {
3474 .hash = {
3475 .vecs = aes_xcbc128_tv_template,
3476 .count = XCBC_AES_TEST_VECTORS
3477 }
3478 }
3479 }, {
3480 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003481 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003482 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003483 .suite = {
3484 .cipher = {
3485 .enc = {
3486 .vecs = aes_xts_enc_tv_template,
3487 .count = AES_XTS_ENC_TEST_VECTORS
3488 },
3489 .dec = {
3490 .vecs = aes_xts_dec_tv_template,
3491 .count = AES_XTS_DEC_TEST_VECTORS
3492 }
3493 }
3494 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003495 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003496 .alg = "xts(camellia)",
3497 .test = alg_test_skcipher,
3498 .suite = {
3499 .cipher = {
3500 .enc = {
3501 .vecs = camellia_xts_enc_tv_template,
3502 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3503 },
3504 .dec = {
3505 .vecs = camellia_xts_dec_tv_template,
3506 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3507 }
3508 }
3509 }
3510 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003511 .alg = "xts(cast6)",
3512 .test = alg_test_skcipher,
3513 .suite = {
3514 .cipher = {
3515 .enc = {
3516 .vecs = cast6_xts_enc_tv_template,
3517 .count = CAST6_XTS_ENC_TEST_VECTORS
3518 },
3519 .dec = {
3520 .vecs = cast6_xts_dec_tv_template,
3521 .count = CAST6_XTS_DEC_TEST_VECTORS
3522 }
3523 }
3524 }
3525 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003526 .alg = "xts(serpent)",
3527 .test = alg_test_skcipher,
3528 .suite = {
3529 .cipher = {
3530 .enc = {
3531 .vecs = serpent_xts_enc_tv_template,
3532 .count = SERPENT_XTS_ENC_TEST_VECTORS
3533 },
3534 .dec = {
3535 .vecs = serpent_xts_dec_tv_template,
3536 .count = SERPENT_XTS_DEC_TEST_VECTORS
3537 }
3538 }
3539 }
3540 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003541 .alg = "xts(twofish)",
3542 .test = alg_test_skcipher,
3543 .suite = {
3544 .cipher = {
3545 .enc = {
3546 .vecs = tf_xts_enc_tv_template,
3547 .count = TF_XTS_ENC_TEST_VECTORS
3548 },
3549 .dec = {
3550 .vecs = tf_xts_dec_tv_template,
3551 .count = TF_XTS_DEC_TEST_VECTORS
3552 }
3553 }
3554 }
3555 }, {
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003556 .alg = "zlib",
3557 .test = alg_test_pcomp,
Milan Broz08189042012-12-06 17:16:28 +08003558 .fips_allowed = 1,
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003559 .suite = {
3560 .pcomp = {
3561 .comp = {
3562 .vecs = zlib_comp_tv_template,
3563 .count = ZLIB_COMP_TEST_VECTORS
3564 },
3565 .decomp = {
3566 .vecs = zlib_decomp_tv_template,
3567 .count = ZLIB_DECOMP_TEST_VECTORS
3568 }
3569 }
3570 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003571 }
3572};
3573
Jussi Kivilinna57147582013-06-13 17:37:40 +03003574static bool alg_test_descs_checked;
3575
3576static void alg_test_descs_check_order(void)
3577{
3578 int i;
3579
3580 /* only check once */
3581 if (alg_test_descs_checked)
3582 return;
3583
3584 alg_test_descs_checked = true;
3585
3586 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3587 int diff = strcmp(alg_test_descs[i - 1].alg,
3588 alg_test_descs[i].alg);
3589
3590 if (WARN_ON(diff > 0)) {
3591 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3592 alg_test_descs[i - 1].alg,
3593 alg_test_descs[i].alg);
3594 }
3595
3596 if (WARN_ON(diff == 0)) {
3597 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3598 alg_test_descs[i].alg);
3599 }
3600 }
3601}
3602
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003603static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003604{
3605 int start = 0;
3606 int end = ARRAY_SIZE(alg_test_descs);
3607
3608 while (start < end) {
3609 int i = (start + end) / 2;
3610 int diff = strcmp(alg_test_descs[i].alg, alg);
3611
3612 if (diff > 0) {
3613 end = i;
3614 continue;
3615 }
3616
3617 if (diff < 0) {
3618 start = i + 1;
3619 continue;
3620 }
3621
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003622 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003623 }
3624
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003625 return -1;
3626}
3627
3628int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3629{
3630 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003631 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003632 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003633
Jussi Kivilinna57147582013-06-13 17:37:40 +03003634 alg_test_descs_check_order();
3635
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003636 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3637 char nalg[CRYPTO_MAX_ALG_NAME];
3638
3639 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3640 sizeof(nalg))
3641 return -ENAMETOOLONG;
3642
3643 i = alg_find_test(nalg);
3644 if (i < 0)
3645 goto notest;
3646
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003647 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3648 goto non_fips_alg;
3649
Jarod Wilson941fb322009-05-04 19:49:23 +08003650 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3651 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003652 }
3653
3654 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003655 j = alg_find_test(driver);
3656 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003657 goto notest;
3658
Herbert Xua68f6612009-07-02 16:32:12 +08003659 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3660 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003661 goto non_fips_alg;
3662
Herbert Xua68f6612009-07-02 16:32:12 +08003663 rc = 0;
3664 if (i >= 0)
3665 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3666 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003667 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003668 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3669 type, mask);
3670
Jarod Wilson941fb322009-05-04 19:49:23 +08003671test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003672 if (fips_enabled && rc)
3673 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3674
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003675 if (fips_enabled && !rc)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303676 pr_info(KERN_INFO "alg: self-tests for %s (%s) passed\n",
3677 driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003678
Neil Hormand12d6b62008-10-12 20:36:51 +08003679 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003680
3681notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003682 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3683 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003684non_fips_alg:
3685 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003686}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003687
Herbert Xu326a6342010-08-06 09:40:28 +08003688#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003689
Herbert Xuda7f0332008-07-31 17:08:25 +08003690EXPORT_SYMBOL_GPL(alg_test);