blob: 18b7d49d1ca0f4f4dd9114881575aec02989754e [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>
Herbert Xu1c41b882015-04-22 13:25:58 +080025#include <linux/fips.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080026#include <linux/module.h>
27#include <linux/scatterlist.h>
28#include <linux/slab.h>
29#include <linux/string.h>
Jarod Wilson7647d6c2009-05-04 19:44:50 +080030#include <crypto/rng.h>
Stephan Mueller64d1cdf2014-05-31 17:25:36 +020031#include <crypto/drbg.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080032
33#include "internal.h"
Alexander Shishkin0b767f92010-06-03 20:53:43 +100034
Herbert Xu326a6342010-08-06 09:40:28 +080035#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
Alexander Shishkin0b767f92010-06-03 20:53:43 +100036
37/* a perfect nop */
38int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
39{
40 return 0;
41}
42
43#else
44
Herbert Xuda7f0332008-07-31 17:08:25 +080045#include "testmgr.h"
46
47/*
48 * Need slab memory for testing (size in number of pages).
49 */
50#define XBUFSIZE 8
51
52/*
53 * Indexes into the xbuf to simulate cross-page access.
54 */
55#define IDX1 32
56#define IDX2 32400
57#define IDX3 1
58#define IDX4 8193
59#define IDX5 22222
60#define IDX6 17101
61#define IDX7 27333
62#define IDX8 3000
63
64/*
65* Used by test_cipher()
66*/
67#define ENCRYPT 1
68#define DECRYPT 0
69
70struct tcrypt_result {
71 struct completion completion;
72 int err;
73};
74
75struct aead_test_suite {
76 struct {
77 struct aead_testvec *vecs;
78 unsigned int count;
79 } enc, dec;
80};
81
82struct cipher_test_suite {
83 struct {
84 struct cipher_testvec *vecs;
85 unsigned int count;
86 } enc, dec;
87};
88
89struct comp_test_suite {
90 struct {
91 struct comp_testvec *vecs;
92 unsigned int count;
93 } comp, decomp;
94};
95
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +080096struct pcomp_test_suite {
97 struct {
98 struct pcomp_testvec *vecs;
99 unsigned int count;
100 } comp, decomp;
101};
102
Herbert Xuda7f0332008-07-31 17:08:25 +0800103struct hash_test_suite {
104 struct hash_testvec *vecs;
105 unsigned int count;
106};
107
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800108struct cprng_test_suite {
109 struct cprng_testvec *vecs;
110 unsigned int count;
111};
112
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200113struct drbg_test_suite {
114 struct drbg_testvec *vecs;
115 unsigned int count;
116};
117
Herbert Xuda7f0332008-07-31 17:08:25 +0800118struct alg_test_desc {
119 const char *alg;
120 int (*test)(const struct alg_test_desc *desc, const char *driver,
121 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000122 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800123
124 union {
125 struct aead_test_suite aead;
126 struct cipher_test_suite cipher;
127 struct comp_test_suite comp;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +0800128 struct pcomp_test_suite pcomp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800129 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800130 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200131 struct drbg_test_suite drbg;
Herbert Xuda7f0332008-07-31 17:08:25 +0800132 } suite;
133};
134
135static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
136
Herbert Xuda7f0332008-07-31 17:08:25 +0800137static void hexdump(unsigned char *buf, unsigned int len)
138{
139 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
140 16, 1,
141 buf, len, false);
142}
143
144static void tcrypt_complete(struct crypto_async_request *req, int err)
145{
146 struct tcrypt_result *res = req->data;
147
148 if (err == -EINPROGRESS)
149 return;
150
151 res->err = err;
152 complete(&res->completion);
153}
154
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800155static int testmgr_alloc_buf(char *buf[XBUFSIZE])
156{
157 int i;
158
159 for (i = 0; i < XBUFSIZE; i++) {
160 buf[i] = (void *)__get_free_page(GFP_KERNEL);
161 if (!buf[i])
162 goto err_free_buf;
163 }
164
165 return 0;
166
167err_free_buf:
168 while (i-- > 0)
169 free_page((unsigned long)buf[i]);
170
171 return -ENOMEM;
172}
173
174static void testmgr_free_buf(char *buf[XBUFSIZE])
175{
176 int i;
177
178 for (i = 0; i < XBUFSIZE; i++)
179 free_page((unsigned long)buf[i]);
180}
181
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300182static int wait_async_op(struct tcrypt_result *tr, int ret)
David S. Millera8f1a052010-05-19 14:12:03 +1000183{
184 if (ret == -EINPROGRESS || ret == -EBUSY) {
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100185 wait_for_completion(&tr->completion);
Wolfram Sang16735d02013-11-14 14:32:02 -0800186 reinit_completion(&tr->completion);
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100187 ret = tr->err;
David S. Millera8f1a052010-05-19 14:12:03 +1000188 }
189 return ret;
190}
191
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300192static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
193 unsigned int tcount, bool use_digest,
194 const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800195{
196 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
197 unsigned int i, j, k, temp;
198 struct scatterlist sg[8];
Horia Geanta29b77e52014-07-23 11:59:38 +0300199 char *result;
200 char *key;
Herbert Xuda7f0332008-07-31 17:08:25 +0800201 struct ahash_request *req;
202 struct tcrypt_result tresult;
Herbert Xuda7f0332008-07-31 17:08:25 +0800203 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800204 char *xbuf[XBUFSIZE];
205 int ret = -ENOMEM;
206
Horia Geanta29b77e52014-07-23 11:59:38 +0300207 result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
208 if (!result)
209 return ret;
210 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
211 if (!key)
212 goto out_nobuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800213 if (testmgr_alloc_buf(xbuf))
214 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800215
216 init_completion(&tresult.completion);
217
218 req = ahash_request_alloc(tfm, GFP_KERNEL);
219 if (!req) {
220 printk(KERN_ERR "alg: hash: Failed to allocate request for "
221 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800222 goto out_noreq;
223 }
224 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
225 tcrypt_complete, &tresult);
226
Herbert Xua0cfae52009-05-29 16:23:12 +1000227 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800228 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000229 if (template[i].np)
230 continue;
231
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300232 ret = -EINVAL;
233 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
234 goto out;
235
Herbert Xua0cfae52009-05-29 16:23:12 +1000236 j++;
Horia Geanta29b77e52014-07-23 11:59:38 +0300237 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800238
239 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300240 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800241
242 memcpy(hash_buff, template[i].plaintext, template[i].psize);
243 sg_init_one(&sg[0], hash_buff, template[i].psize);
244
245 if (template[i].ksize) {
246 crypto_ahash_clear_flags(tfm, ~0);
Horia Geanta29b77e52014-07-23 11:59:38 +0300247 if (template[i].ksize > MAX_KEYLEN) {
248 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
249 j, algo, template[i].ksize, MAX_KEYLEN);
250 ret = -EINVAL;
251 goto out;
252 }
253 memcpy(key, template[i].key, template[i].ksize);
254 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
Herbert Xuda7f0332008-07-31 17:08:25 +0800255 if (ret) {
256 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000257 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800258 -ret);
259 goto out;
260 }
261 }
262
263 ahash_request_set_crypt(req, sg, result, template[i].psize);
David S. Millera8f1a052010-05-19 14:12:03 +1000264 if (use_digest) {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300265 ret = wait_async_op(&tresult, crypto_ahash_digest(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000266 if (ret) {
267 pr_err("alg: hash: digest failed on test %d "
268 "for %s: ret=%d\n", j, algo, -ret);
269 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800270 }
David S. Millera8f1a052010-05-19 14:12:03 +1000271 } else {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300272 ret = wait_async_op(&tresult, crypto_ahash_init(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000273 if (ret) {
274 pr_err("alt: hash: init failed on test %d "
275 "for %s: ret=%d\n", j, algo, -ret);
276 goto out;
277 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300278 ret = wait_async_op(&tresult, crypto_ahash_update(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000279 if (ret) {
280 pr_err("alt: hash: update failed on test %d "
281 "for %s: ret=%d\n", j, algo, -ret);
282 goto out;
283 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300284 ret = wait_async_op(&tresult, crypto_ahash_final(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000285 if (ret) {
286 pr_err("alt: hash: final failed on test %d "
287 "for %s: ret=%d\n", j, algo, -ret);
288 goto out;
289 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800290 }
291
292 if (memcmp(result, template[i].digest,
293 crypto_ahash_digestsize(tfm))) {
294 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000295 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800296 hexdump(result, crypto_ahash_digestsize(tfm));
297 ret = -EINVAL;
298 goto out;
299 }
300 }
301
302 j = 0;
303 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300304 /* alignment tests are only done with continuous buffers */
305 if (align_offset != 0)
306 break;
307
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300308 if (!template[i].np)
309 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800310
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300311 j++;
312 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800313
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300314 temp = 0;
315 sg_init_table(sg, template[i].np);
316 ret = -EINVAL;
317 for (k = 0; k < template[i].np; k++) {
318 if (WARN_ON(offset_in_page(IDX[k]) +
319 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +0800320 goto out;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300321 sg_set_buf(&sg[k],
322 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
323 offset_in_page(IDX[k]),
324 template[i].plaintext + temp,
325 template[i].tap[k]),
326 template[i].tap[k]);
327 temp += template[i].tap[k];
328 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800329
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300330 if (template[i].ksize) {
331 if (template[i].ksize > MAX_KEYLEN) {
332 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
333 j, algo, template[i].ksize, MAX_KEYLEN);
Herbert Xuda7f0332008-07-31 17:08:25 +0800334 ret = -EINVAL;
335 goto out;
336 }
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300337 crypto_ahash_clear_flags(tfm, ~0);
338 memcpy(key, template[i].key, template[i].ksize);
339 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
340
341 if (ret) {
342 printk(KERN_ERR "alg: hash: setkey "
343 "failed on chunking test %d "
344 "for %s: ret=%d\n", j, algo, -ret);
345 goto out;
346 }
347 }
348
349 ahash_request_set_crypt(req, sg, result, template[i].psize);
350 ret = crypto_ahash_digest(req);
351 switch (ret) {
352 case 0:
353 break;
354 case -EINPROGRESS:
355 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100356 wait_for_completion(&tresult.completion);
357 reinit_completion(&tresult.completion);
358 ret = tresult.err;
359 if (!ret)
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300360 break;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300361 /* fall through */
362 default:
363 printk(KERN_ERR "alg: hash: digest failed "
364 "on chunking test %d for %s: "
365 "ret=%d\n", j, algo, -ret);
366 goto out;
367 }
368
369 if (memcmp(result, template[i].digest,
370 crypto_ahash_digestsize(tfm))) {
371 printk(KERN_ERR "alg: hash: Chunking test %d "
372 "failed for %s\n", j, algo);
373 hexdump(result, crypto_ahash_digestsize(tfm));
374 ret = -EINVAL;
375 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800376 }
377 }
378
379 ret = 0;
380
381out:
382 ahash_request_free(req);
383out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800384 testmgr_free_buf(xbuf);
385out_nobuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300386 kfree(key);
387 kfree(result);
Herbert Xuda7f0332008-07-31 17:08:25 +0800388 return ret;
389}
390
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300391static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
392 unsigned int tcount, bool use_digest)
393{
394 unsigned int alignmask;
395 int ret;
396
397 ret = __test_hash(tfm, template, tcount, use_digest, 0);
398 if (ret)
399 return ret;
400
401 /* test unaligned buffers, check with one byte offset */
402 ret = __test_hash(tfm, template, tcount, use_digest, 1);
403 if (ret)
404 return ret;
405
406 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
407 if (alignmask) {
408 /* Check if alignment mask for tfm is correctly set. */
409 ret = __test_hash(tfm, template, tcount, use_digest,
410 alignmask + 1);
411 if (ret)
412 return ret;
413 }
414
415 return 0;
416}
417
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300418static int __test_aead(struct crypto_aead *tfm, int enc,
419 struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300420 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800421{
422 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
423 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800424 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800425 char *q;
426 char *key;
427 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300428 struct scatterlist *sg;
429 struct scatterlist *asg;
430 struct scatterlist *sgout;
431 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800432 struct tcrypt_result result;
Cristian Stoica424a5da2015-01-28 11:03:05 +0200433 unsigned int authsize, iv_len;
Herbert Xuda7f0332008-07-31 17:08:25 +0800434 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300435 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800436 void *assoc;
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700437 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800438 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300439 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800440 char *axbuf[XBUFSIZE];
441
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700442 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
443 if (!iv)
444 return ret;
Horia Geanta29b77e52014-07-23 11:59:38 +0300445 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
446 if (!key)
447 goto out_noxbuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800448 if (testmgr_alloc_buf(xbuf))
449 goto out_noxbuf;
450 if (testmgr_alloc_buf(axbuf))
451 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300452 if (diff_dst && testmgr_alloc_buf(xoutbuf))
453 goto out_nooutbuf;
454
455 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
456 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL);
457 if (!sg)
458 goto out_nosg;
459 asg = &sg[8];
460 sgout = &asg[8];
461
462 if (diff_dst)
463 d = "-ddst";
464 else
465 d = "";
466
Herbert Xuda7f0332008-07-31 17:08:25 +0800467 if (enc == ENCRYPT)
468 e = "encryption";
469 else
470 e = "decryption";
471
472 init_completion(&result.completion);
473
474 req = aead_request_alloc(tfm, GFP_KERNEL);
475 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300476 pr_err("alg: aead%s: Failed to allocate request for %s\n",
477 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800478 goto out;
479 }
480
481 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
482 tcrypt_complete, &result);
483
484 for (i = 0, j = 0; i < tcount; i++) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300485 if (template[i].np)
486 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800487
Cristian Stoica05b1d332014-07-28 13:11:23 +0300488 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800489
Cristian Stoica05b1d332014-07-28 13:11:23 +0300490 /* some templates have no input data but they will
491 * touch input
492 */
493 input = xbuf[0];
494 input += align_offset;
495 assoc = axbuf[0];
496
497 ret = -EINVAL;
498 if (WARN_ON(align_offset + template[i].ilen >
499 PAGE_SIZE || template[i].alen > PAGE_SIZE))
500 goto out;
501
502 memcpy(input, template[i].input, template[i].ilen);
503 memcpy(assoc, template[i].assoc, template[i].alen);
Cristian Stoica424a5da2015-01-28 11:03:05 +0200504 iv_len = crypto_aead_ivsize(tfm);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300505 if (template[i].iv)
Cristian Stoica424a5da2015-01-28 11:03:05 +0200506 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300507 else
Cristian Stoica424a5da2015-01-28 11:03:05 +0200508 memset(iv, 0, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300509
510 crypto_aead_clear_flags(tfm, ~0);
511 if (template[i].wk)
512 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
513
514 if (template[i].klen > MAX_KEYLEN) {
515 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
516 d, j, algo, template[i].klen,
517 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +1000518 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300519 goto out;
520 }
521 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +1000522
Cristian Stoica05b1d332014-07-28 13:11:23 +0300523 ret = crypto_aead_setkey(tfm, key, template[i].klen);
524 if (!ret == template[i].fail) {
525 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
526 d, j, algo, crypto_aead_get_flags(tfm));
527 goto out;
528 } else if (ret)
529 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800530
Cristian Stoica05b1d332014-07-28 13:11:23 +0300531 authsize = abs(template[i].rlen - template[i].ilen);
532 ret = crypto_aead_setauthsize(tfm, authsize);
533 if (ret) {
534 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
535 d, authsize, j, algo);
536 goto out;
537 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800538
Cristian Stoica05b1d332014-07-28 13:11:23 +0300539 if (diff_dst) {
540 output = xoutbuf[0];
541 output += align_offset;
542 sg_init_one(&sg[0], input, template[i].ilen);
543 sg_init_one(&sgout[0], output, template[i].rlen);
544 } else {
545 sg_init_one(&sg[0], input,
546 template[i].ilen + (enc ? authsize : 0));
547 output = input;
548 }
549
550 sg_init_one(&asg[0], assoc, template[i].alen);
551
552 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
553 template[i].ilen, iv);
554
555 aead_request_set_assoc(req, asg, template[i].alen);
556
557 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
558
559 switch (ret) {
560 case 0:
561 if (template[i].novrfy) {
562 /* verification was supposed to fail */
563 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
564 d, e, j, algo);
565 /* so really, we got a bad message */
566 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +0300567 goto out;
568 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300569 break;
570 case -EINPROGRESS:
571 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100572 wait_for_completion(&result.completion);
573 reinit_completion(&result.completion);
574 ret = result.err;
575 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +0800576 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300577 case -EBADMSG:
578 if (template[i].novrfy)
579 /* verification failure was expected */
580 continue;
581 /* fall through */
582 default:
583 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
584 d, e, j, algo, -ret);
585 goto out;
586 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800587
Cristian Stoica05b1d332014-07-28 13:11:23 +0300588 q = output;
589 if (memcmp(q, template[i].result, template[i].rlen)) {
590 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
591 d, j, e, algo);
592 hexdump(q, template[i].rlen);
593 ret = -EINVAL;
594 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800595 }
596 }
597
598 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300599 /* alignment tests are only done with continuous buffers */
600 if (align_offset != 0)
601 break;
602
Cristian Stoica05b1d332014-07-28 13:11:23 +0300603 if (!template[i].np)
604 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800605
Cristian Stoica05b1d332014-07-28 13:11:23 +0300606 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800607
Cristian Stoica05b1d332014-07-28 13:11:23 +0300608 if (template[i].iv)
609 memcpy(iv, template[i].iv, MAX_IVLEN);
610 else
611 memset(iv, 0, MAX_IVLEN);
612
613 crypto_aead_clear_flags(tfm, ~0);
614 if (template[i].wk)
615 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
616 if (template[i].klen > MAX_KEYLEN) {
617 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
618 d, j, algo, template[i].klen, MAX_KEYLEN);
619 ret = -EINVAL;
620 goto out;
621 }
622 memcpy(key, template[i].key, template[i].klen);
623
624 ret = crypto_aead_setkey(tfm, key, template[i].klen);
625 if (!ret == template[i].fail) {
626 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
627 d, j, algo, crypto_aead_get_flags(tfm));
628 goto out;
629 } else if (ret)
630 continue;
631
632 authsize = abs(template[i].rlen - template[i].ilen);
633
634 ret = -EINVAL;
635 sg_init_table(sg, template[i].np);
636 if (diff_dst)
637 sg_init_table(sgout, template[i].np);
638 for (k = 0, temp = 0; k < template[i].np; k++) {
639 if (WARN_ON(offset_in_page(IDX[k]) +
640 template[i].tap[k] > PAGE_SIZE))
641 goto out;
642
643 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
644 memcpy(q, template[i].input + temp, template[i].tap[k]);
645 sg_set_buf(&sg[k], q, template[i].tap[k]);
646
647 if (diff_dst) {
648 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
649 offset_in_page(IDX[k]);
650
651 memset(q, 0, template[i].tap[k]);
652
653 sg_set_buf(&sgout[k], q, template[i].tap[k]);
654 }
655
656 n = template[i].tap[k];
657 if (k == template[i].np - 1 && enc)
658 n += authsize;
659 if (offset_in_page(q) + n < PAGE_SIZE)
660 q[n] = 0;
661
662 temp += template[i].tap[k];
663 }
664
665 ret = crypto_aead_setauthsize(tfm, authsize);
666 if (ret) {
667 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
668 d, authsize, j, algo);
669 goto out;
670 }
671
672 if (enc) {
673 if (WARN_ON(sg[k - 1].offset +
674 sg[k - 1].length + authsize >
675 PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300676 ret = -EINVAL;
677 goto out;
678 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800679
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300680 if (diff_dst)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300681 sgout[k - 1].length += authsize;
682 else
683 sg[k - 1].length += authsize;
684 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800685
Cristian Stoica05b1d332014-07-28 13:11:23 +0300686 sg_init_table(asg, template[i].anp);
687 ret = -EINVAL;
688 for (k = 0, temp = 0; k < template[i].anp; k++) {
689 if (WARN_ON(offset_in_page(IDX[k]) +
690 template[i].atap[k] > PAGE_SIZE))
691 goto out;
692 sg_set_buf(&asg[k],
693 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
694 offset_in_page(IDX[k]),
695 template[i].assoc + temp,
696 template[i].atap[k]),
697 template[i].atap[k]);
698 temp += template[i].atap[k];
699 }
700
701 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
702 template[i].ilen,
703 iv);
704
705 aead_request_set_assoc(req, asg, template[i].alen);
706
707 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
708
709 switch (ret) {
710 case 0:
711 if (template[i].novrfy) {
712 /* verification was supposed to fail */
713 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
714 d, e, j, algo);
715 /* so really, we got a bad message */
716 ret = -EBADMSG;
717 goto out;
718 }
719 break;
720 case -EINPROGRESS:
721 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100722 wait_for_completion(&result.completion);
723 reinit_completion(&result.completion);
724 ret = result.err;
725 if (!ret)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300726 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300727 case -EBADMSG:
728 if (template[i].novrfy)
729 /* verification failure was expected */
730 continue;
731 /* fall through */
732 default:
733 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
734 d, e, j, algo, -ret);
735 goto out;
736 }
737
738 ret = -EINVAL;
739 for (k = 0, temp = 0; k < template[i].np; k++) {
740 if (diff_dst)
741 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
742 offset_in_page(IDX[k]);
743 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800744 q = xbuf[IDX[k] >> PAGE_SHIFT] +
745 offset_in_page(IDX[k]);
746
Cristian Stoica05b1d332014-07-28 13:11:23 +0300747 n = template[i].tap[k];
748 if (k == template[i].np - 1)
749 n += enc ? authsize : -authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800750
Cristian Stoica05b1d332014-07-28 13:11:23 +0300751 if (memcmp(q, template[i].result + temp, n)) {
752 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
753 d, j, e, k, algo);
754 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800755 goto out;
756 }
757
Cristian Stoica05b1d332014-07-28 13:11:23 +0300758 q += n;
759 if (k == template[i].np - 1 && !enc) {
760 if (!diff_dst &&
761 memcmp(q, template[i].input +
762 temp + n, authsize))
763 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200764 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300765 n = 0;
766 } else {
767 for (n = 0; offset_in_page(q + n) && q[n]; n++)
768 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800769 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300770 if (n) {
771 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
772 d, j, e, k, algo, n);
773 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800774 goto out;
775 }
776
Cristian Stoica05b1d332014-07-28 13:11:23 +0300777 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800778 }
779 }
780
781 ret = 0;
782
783out:
784 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300785 kfree(sg);
786out_nosg:
787 if (diff_dst)
788 testmgr_free_buf(xoutbuf);
789out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800790 testmgr_free_buf(axbuf);
791out_noaxbuf:
792 testmgr_free_buf(xbuf);
793out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300794 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700795 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800796 return ret;
797}
798
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300799static int test_aead(struct crypto_aead *tfm, int enc,
800 struct aead_testvec *template, unsigned int tcount)
801{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300802 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300803 int ret;
804
805 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300806 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300807 if (ret)
808 return ret;
809
810 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300811 ret = __test_aead(tfm, enc, template, tcount, true, 0);
812 if (ret)
813 return ret;
814
815 /* test unaligned buffers, check with one byte offset */
816 ret = __test_aead(tfm, enc, template, tcount, true, 1);
817 if (ret)
818 return ret;
819
820 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
821 if (alignmask) {
822 /* Check if alignment mask for tfm is correctly set. */
823 ret = __test_aead(tfm, enc, template, tcount, true,
824 alignmask + 1);
825 if (ret)
826 return ret;
827 }
828
829 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300830}
831
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000832static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800833 struct cipher_testvec *template, unsigned int tcount)
834{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000835 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
836 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000837 char *q;
838 const char *e;
839 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800840 char *xbuf[XBUFSIZE];
841 int ret = -ENOMEM;
842
843 if (testmgr_alloc_buf(xbuf))
844 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000845
846 if (enc == ENCRYPT)
847 e = "encryption";
848 else
849 e = "decryption";
850
851 j = 0;
852 for (i = 0; i < tcount; i++) {
853 if (template[i].np)
854 continue;
855
856 j++;
857
Herbert Xufd57f222009-05-29 16:05:42 +1000858 ret = -EINVAL;
859 if (WARN_ON(template[i].ilen > PAGE_SIZE))
860 goto out;
861
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000862 data = xbuf[0];
863 memcpy(data, template[i].input, template[i].ilen);
864
865 crypto_cipher_clear_flags(tfm, ~0);
866 if (template[i].wk)
867 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
868
869 ret = crypto_cipher_setkey(tfm, template[i].key,
870 template[i].klen);
871 if (!ret == template[i].fail) {
872 printk(KERN_ERR "alg: cipher: setkey failed "
873 "on test %d for %s: flags=%x\n", j,
874 algo, crypto_cipher_get_flags(tfm));
875 goto out;
876 } else if (ret)
877 continue;
878
879 for (k = 0; k < template[i].ilen;
880 k += crypto_cipher_blocksize(tfm)) {
881 if (enc)
882 crypto_cipher_encrypt_one(tfm, data + k,
883 data + k);
884 else
885 crypto_cipher_decrypt_one(tfm, data + k,
886 data + k);
887 }
888
889 q = data;
890 if (memcmp(q, template[i].result, template[i].rlen)) {
891 printk(KERN_ERR "alg: cipher: Test %d failed "
892 "on %s for %s\n", j, e, algo);
893 hexdump(q, template[i].rlen);
894 ret = -EINVAL;
895 goto out;
896 }
897 }
898
899 ret = 0;
900
901out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800902 testmgr_free_buf(xbuf);
903out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000904 return ret;
905}
906
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300907static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
908 struct cipher_testvec *template, unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300909 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000910{
Herbert Xuda7f0332008-07-31 17:08:25 +0800911 const char *algo =
912 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
913 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800914 char *q;
915 struct ablkcipher_request *req;
916 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300917 struct scatterlist sgout[8];
918 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800919 struct tcrypt_result result;
920 void *data;
921 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800922 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300923 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800924 int ret = -ENOMEM;
925
926 if (testmgr_alloc_buf(xbuf))
927 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800928
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300929 if (diff_dst && testmgr_alloc_buf(xoutbuf))
930 goto out_nooutbuf;
931
932 if (diff_dst)
933 d = "-ddst";
934 else
935 d = "";
936
Herbert Xuda7f0332008-07-31 17:08:25 +0800937 if (enc == ENCRYPT)
938 e = "encryption";
939 else
940 e = "decryption";
941
942 init_completion(&result.completion);
943
944 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
945 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300946 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
947 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800948 goto out;
949 }
950
951 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
952 tcrypt_complete, &result);
953
954 j = 0;
955 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +0300956 if (template[i].np && !template[i].also_non_np)
957 continue;
958
Herbert Xuda7f0332008-07-31 17:08:25 +0800959 if (template[i].iv)
960 memcpy(iv, template[i].iv, MAX_IVLEN);
961 else
962 memset(iv, 0, MAX_IVLEN);
963
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300964 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300965 ret = -EINVAL;
966 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
967 goto out;
968
969 data = xbuf[0];
970 data += align_offset;
971 memcpy(data, template[i].input, template[i].ilen);
972
973 crypto_ablkcipher_clear_flags(tfm, ~0);
974 if (template[i].wk)
975 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
976
977 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
978 template[i].klen);
979 if (!ret == template[i].fail) {
980 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
981 d, j, algo, crypto_ablkcipher_get_flags(tfm));
982 goto out;
983 } else if (ret)
984 continue;
985
986 sg_init_one(&sg[0], data, template[i].ilen);
987 if (diff_dst) {
988 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300989 data += align_offset;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300990 sg_init_one(&sgout[0], data, template[i].ilen);
991 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800992
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300993 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
994 template[i].ilen, iv);
995 ret = enc ? crypto_ablkcipher_encrypt(req) :
996 crypto_ablkcipher_decrypt(req);
Herbert Xuda7f0332008-07-31 17:08:25 +0800997
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300998 switch (ret) {
999 case 0:
1000 break;
1001 case -EINPROGRESS:
1002 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001003 wait_for_completion(&result.completion);
1004 reinit_completion(&result.completion);
1005 ret = result.err;
1006 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +08001007 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001008 /* fall through */
1009 default:
1010 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1011 d, e, j, algo, -ret);
1012 goto out;
1013 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001014
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001015 q = data;
1016 if (memcmp(q, template[i].result, template[i].rlen)) {
1017 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1018 d, j, e, algo);
1019 hexdump(q, template[i].rlen);
1020 ret = -EINVAL;
1021 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001022 }
1023 }
1024
1025 j = 0;
1026 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001027 /* alignment tests are only done with continuous buffers */
1028 if (align_offset != 0)
1029 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001030
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001031 if (!template[i].np)
1032 continue;
1033
Herbert Xuda7f0332008-07-31 17:08:25 +08001034 if (template[i].iv)
1035 memcpy(iv, template[i].iv, MAX_IVLEN);
1036 else
1037 memset(iv, 0, MAX_IVLEN);
1038
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001039 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001040 crypto_ablkcipher_clear_flags(tfm, ~0);
1041 if (template[i].wk)
1042 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1043
1044 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1045 template[i].klen);
1046 if (!ret == template[i].fail) {
1047 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1048 d, j, algo, crypto_ablkcipher_get_flags(tfm));
1049 goto out;
1050 } else if (ret)
1051 continue;
1052
1053 temp = 0;
1054 ret = -EINVAL;
1055 sg_init_table(sg, template[i].np);
1056 if (diff_dst)
1057 sg_init_table(sgout, template[i].np);
1058 for (k = 0; k < template[i].np; k++) {
1059 if (WARN_ON(offset_in_page(IDX[k]) +
1060 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001061 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001062
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001063 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1064
1065 memcpy(q, template[i].input + temp, template[i].tap[k]);
1066
1067 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1068 q[template[i].tap[k]] = 0;
1069
1070 sg_set_buf(&sg[k], q, template[i].tap[k]);
1071 if (diff_dst) {
1072 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1073 offset_in_page(IDX[k]);
1074
1075 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1076
1077 memset(q, 0, template[i].tap[k]);
1078 if (offset_in_page(q) +
1079 template[i].tap[k] < PAGE_SIZE)
1080 q[template[i].tap[k]] = 0;
1081 }
1082
1083 temp += template[i].tap[k];
1084 }
1085
1086 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1087 template[i].ilen, iv);
1088
1089 ret = enc ? crypto_ablkcipher_encrypt(req) :
1090 crypto_ablkcipher_decrypt(req);
1091
1092 switch (ret) {
1093 case 0:
1094 break;
1095 case -EINPROGRESS:
1096 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001097 wait_for_completion(&result.completion);
1098 reinit_completion(&result.completion);
1099 ret = result.err;
1100 if (!ret)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001101 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001102 /* fall through */
1103 default:
1104 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1105 d, e, j, algo, -ret);
1106 goto out;
1107 }
1108
1109 temp = 0;
1110 ret = -EINVAL;
1111 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001112 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001113 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1114 offset_in_page(IDX[k]);
1115 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001116 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1117 offset_in_page(IDX[k]);
1118
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001119 if (memcmp(q, template[i].result + temp,
1120 template[i].tap[k])) {
1121 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1122 d, j, e, k, algo);
1123 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001124 goto out;
1125 }
1126
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001127 q += template[i].tap[k];
1128 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1129 ;
1130 if (n) {
1131 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1132 d, j, e, k, algo, n);
1133 hexdump(q, n);
1134 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001135 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001136 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001137 }
1138 }
1139
1140 ret = 0;
1141
1142out:
1143 ablkcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001144 if (diff_dst)
1145 testmgr_free_buf(xoutbuf);
1146out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001147 testmgr_free_buf(xbuf);
1148out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001149 return ret;
1150}
1151
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001152static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1153 struct cipher_testvec *template, unsigned int tcount)
1154{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001155 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001156 int ret;
1157
1158 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001159 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001160 if (ret)
1161 return ret;
1162
1163 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001164 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1165 if (ret)
1166 return ret;
1167
1168 /* test unaligned buffers, check with one byte offset */
1169 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1170 if (ret)
1171 return ret;
1172
1173 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1174 if (alignmask) {
1175 /* Check if alignment mask for tfm is correctly set. */
1176 ret = __test_skcipher(tfm, enc, template, tcount, true,
1177 alignmask + 1);
1178 if (ret)
1179 return ret;
1180 }
1181
1182 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001183}
1184
Herbert Xuda7f0332008-07-31 17:08:25 +08001185static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1186 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1187{
1188 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1189 unsigned int i;
1190 char result[COMP_BUF_SIZE];
1191 int ret;
1192
1193 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001194 int ilen;
1195 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001196
1197 memset(result, 0, sizeof (result));
1198
1199 ilen = ctemplate[i].inlen;
1200 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1201 ilen, result, &dlen);
1202 if (ret) {
1203 printk(KERN_ERR "alg: comp: compression failed "
1204 "on test %d for %s: ret=%d\n", i + 1, algo,
1205 -ret);
1206 goto out;
1207 }
1208
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001209 if (dlen != ctemplate[i].outlen) {
1210 printk(KERN_ERR "alg: comp: Compression test %d "
1211 "failed for %s: output len = %d\n", i + 1, algo,
1212 dlen);
1213 ret = -EINVAL;
1214 goto out;
1215 }
1216
Herbert Xuda7f0332008-07-31 17:08:25 +08001217 if (memcmp(result, ctemplate[i].output, dlen)) {
1218 printk(KERN_ERR "alg: comp: Compression test %d "
1219 "failed for %s\n", i + 1, algo);
1220 hexdump(result, dlen);
1221 ret = -EINVAL;
1222 goto out;
1223 }
1224 }
1225
1226 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001227 int ilen;
1228 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001229
1230 memset(result, 0, sizeof (result));
1231
1232 ilen = dtemplate[i].inlen;
1233 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1234 ilen, result, &dlen);
1235 if (ret) {
1236 printk(KERN_ERR "alg: comp: decompression failed "
1237 "on test %d for %s: ret=%d\n", i + 1, algo,
1238 -ret);
1239 goto out;
1240 }
1241
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001242 if (dlen != dtemplate[i].outlen) {
1243 printk(KERN_ERR "alg: comp: Decompression test %d "
1244 "failed for %s: output len = %d\n", i + 1, algo,
1245 dlen);
1246 ret = -EINVAL;
1247 goto out;
1248 }
1249
Herbert Xuda7f0332008-07-31 17:08:25 +08001250 if (memcmp(result, dtemplate[i].output, dlen)) {
1251 printk(KERN_ERR "alg: comp: Decompression test %d "
1252 "failed for %s\n", i + 1, algo);
1253 hexdump(result, dlen);
1254 ret = -EINVAL;
1255 goto out;
1256 }
1257 }
1258
1259 ret = 0;
1260
1261out:
1262 return ret;
1263}
1264
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001265static int test_pcomp(struct crypto_pcomp *tfm,
1266 struct pcomp_testvec *ctemplate,
1267 struct pcomp_testvec *dtemplate, int ctcount,
1268 int dtcount)
1269{
1270 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1271 unsigned int i;
1272 char result[COMP_BUF_SIZE];
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001273 int res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001274
1275 for (i = 0; i < ctcount; i++) {
1276 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001277 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001278
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001279 res = crypto_compress_setup(tfm, ctemplate[i].params,
1280 ctemplate[i].paramsize);
1281 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001282 pr_err("alg: pcomp: compression setup failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001283 "%d for %s: error=%d\n", i + 1, algo, res);
1284 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001285 }
1286
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001287 res = crypto_compress_init(tfm);
1288 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001289 pr_err("alg: pcomp: compression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001290 "%d for %s: error=%d\n", i + 1, algo, res);
1291 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001292 }
1293
1294 memset(result, 0, sizeof(result));
1295
1296 req.next_in = ctemplate[i].input;
1297 req.avail_in = ctemplate[i].inlen / 2;
1298 req.next_out = result;
1299 req.avail_out = ctemplate[i].outlen / 2;
1300
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001301 res = crypto_compress_update(tfm, &req);
1302 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001303 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001304 "%d for %s: error=%d\n", i + 1, algo, res);
1305 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001306 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001307 if (res > 0)
1308 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001309
1310 /* Add remaining input data */
1311 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1312
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001313 res = crypto_compress_update(tfm, &req);
1314 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001315 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001316 "%d for %s: error=%d\n", i + 1, algo, res);
1317 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001318 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001319 if (res > 0)
1320 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001321
1322 /* Provide remaining output space */
1323 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1324
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001325 res = crypto_compress_final(tfm, &req);
1326 if (res < 0) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001327 pr_err("alg: pcomp: compression final failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001328 "%d for %s: error=%d\n", i + 1, algo, res);
1329 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001330 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001331 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001332
1333 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1334 pr_err("alg: comp: Compression test %d failed for %s: "
1335 "output len = %d (expected %d)\n", i + 1, algo,
1336 COMP_BUF_SIZE - req.avail_out,
1337 ctemplate[i].outlen);
1338 return -EINVAL;
1339 }
1340
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001341 if (produced != ctemplate[i].outlen) {
1342 pr_err("alg: comp: Compression test %d failed for %s: "
1343 "returned len = %u (expected %d)\n", i + 1,
1344 algo, produced, ctemplate[i].outlen);
1345 return -EINVAL;
1346 }
1347
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001348 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1349 pr_err("alg: pcomp: Compression test %d failed for "
1350 "%s\n", i + 1, algo);
1351 hexdump(result, ctemplate[i].outlen);
1352 return -EINVAL;
1353 }
1354 }
1355
1356 for (i = 0; i < dtcount; i++) {
1357 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001358 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001359
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001360 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1361 dtemplate[i].paramsize);
1362 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001363 pr_err("alg: pcomp: decompression setup failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001364 "test %d for %s: error=%d\n", i + 1, algo, res);
1365 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001366 }
1367
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001368 res = crypto_decompress_init(tfm);
1369 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001370 pr_err("alg: pcomp: decompression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001371 "%d for %s: error=%d\n", i + 1, algo, res);
1372 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001373 }
1374
1375 memset(result, 0, sizeof(result));
1376
1377 req.next_in = dtemplate[i].input;
1378 req.avail_in = dtemplate[i].inlen / 2;
1379 req.next_out = result;
1380 req.avail_out = dtemplate[i].outlen / 2;
1381
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001382 res = crypto_decompress_update(tfm, &req);
1383 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001384 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001385 "test %d for %s: error=%d\n", i + 1, algo, res);
1386 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001387 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001388 if (res > 0)
1389 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001390
1391 /* Add remaining input data */
1392 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1393
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001394 res = crypto_decompress_update(tfm, &req);
1395 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001396 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001397 "test %d for %s: error=%d\n", i + 1, algo, res);
1398 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001399 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001400 if (res > 0)
1401 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001402
1403 /* Provide remaining output space */
1404 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1405
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001406 res = crypto_decompress_final(tfm, &req);
1407 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001408 pr_err("alg: pcomp: decompression final failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001409 "test %d for %s: error=%d\n", i + 1, algo, res);
1410 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001411 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001412 if (res > 0)
1413 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001414
1415 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1416 pr_err("alg: comp: Decompression test %d failed for "
1417 "%s: output len = %d (expected %d)\n", i + 1,
1418 algo, COMP_BUF_SIZE - req.avail_out,
1419 dtemplate[i].outlen);
1420 return -EINVAL;
1421 }
1422
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001423 if (produced != dtemplate[i].outlen) {
1424 pr_err("alg: comp: Decompression test %d failed for "
1425 "%s: returned len = %u (expected %d)\n", i + 1,
1426 algo, produced, dtemplate[i].outlen);
1427 return -EINVAL;
1428 }
1429
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001430 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1431 pr_err("alg: pcomp: Decompression test %d failed for "
1432 "%s\n", i + 1, algo);
1433 hexdump(result, dtemplate[i].outlen);
1434 return -EINVAL;
1435 }
1436 }
1437
1438 return 0;
1439}
1440
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001441
1442static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1443 unsigned int tcount)
1444{
1445 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001446 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001447 u8 *seed;
1448 char result[32];
1449
1450 seedsize = crypto_rng_seedsize(tfm);
1451
1452 seed = kmalloc(seedsize, GFP_KERNEL);
1453 if (!seed) {
1454 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1455 "for %s\n", algo);
1456 return -ENOMEM;
1457 }
1458
1459 for (i = 0; i < tcount; i++) {
1460 memset(result, 0, 32);
1461
1462 memcpy(seed, template[i].v, template[i].vlen);
1463 memcpy(seed + template[i].vlen, template[i].key,
1464 template[i].klen);
1465 memcpy(seed + template[i].vlen + template[i].klen,
1466 template[i].dt, template[i].dtlen);
1467
1468 err = crypto_rng_reset(tfm, seed, seedsize);
1469 if (err) {
1470 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1471 "for %s\n", algo);
1472 goto out;
1473 }
1474
1475 for (j = 0; j < template[i].loops; j++) {
1476 err = crypto_rng_get_bytes(tfm, result,
1477 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01001478 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001479 printk(KERN_ERR "alg: cprng: Failed to obtain "
1480 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01001481 "%s (requested %d)\n", algo,
1482 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001483 goto out;
1484 }
1485 }
1486
1487 err = memcmp(result, template[i].result,
1488 template[i].rlen);
1489 if (err) {
1490 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1491 i, algo);
1492 hexdump(result, template[i].rlen);
1493 err = -EINVAL;
1494 goto out;
1495 }
1496 }
1497
1498out:
1499 kfree(seed);
1500 return err;
1501}
1502
Herbert Xuda7f0332008-07-31 17:08:25 +08001503static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1504 u32 type, u32 mask)
1505{
1506 struct crypto_aead *tfm;
1507 int err = 0;
1508
Stephan Mueller425a8822015-03-30 21:56:31 +02001509 tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001510 if (IS_ERR(tfm)) {
1511 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1512 "%ld\n", driver, PTR_ERR(tfm));
1513 return PTR_ERR(tfm);
1514 }
1515
1516 if (desc->suite.aead.enc.vecs) {
1517 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1518 desc->suite.aead.enc.count);
1519 if (err)
1520 goto out;
1521 }
1522
1523 if (!err && desc->suite.aead.dec.vecs)
1524 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1525 desc->suite.aead.dec.count);
1526
1527out:
1528 crypto_free_aead(tfm);
1529 return err;
1530}
1531
1532static int alg_test_cipher(const struct alg_test_desc *desc,
1533 const char *driver, u32 type, u32 mask)
1534{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001535 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001536 int err = 0;
1537
Stephan Mueller425a8822015-03-30 21:56:31 +02001538 tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001539 if (IS_ERR(tfm)) {
1540 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1541 "%s: %ld\n", driver, PTR_ERR(tfm));
1542 return PTR_ERR(tfm);
1543 }
1544
1545 if (desc->suite.cipher.enc.vecs) {
1546 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1547 desc->suite.cipher.enc.count);
1548 if (err)
1549 goto out;
1550 }
1551
1552 if (desc->suite.cipher.dec.vecs)
1553 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1554 desc->suite.cipher.dec.count);
1555
1556out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001557 crypto_free_cipher(tfm);
1558 return err;
1559}
1560
1561static int alg_test_skcipher(const struct alg_test_desc *desc,
1562 const char *driver, u32 type, u32 mask)
1563{
1564 struct crypto_ablkcipher *tfm;
1565 int err = 0;
1566
Stephan Mueller425a8822015-03-30 21:56:31 +02001567 tfm = crypto_alloc_ablkcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001568 if (IS_ERR(tfm)) {
1569 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1570 "%s: %ld\n", driver, PTR_ERR(tfm));
1571 return PTR_ERR(tfm);
1572 }
1573
1574 if (desc->suite.cipher.enc.vecs) {
1575 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1576 desc->suite.cipher.enc.count);
1577 if (err)
1578 goto out;
1579 }
1580
1581 if (desc->suite.cipher.dec.vecs)
1582 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1583 desc->suite.cipher.dec.count);
1584
1585out:
Herbert Xuda7f0332008-07-31 17:08:25 +08001586 crypto_free_ablkcipher(tfm);
1587 return err;
1588}
1589
1590static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1591 u32 type, u32 mask)
1592{
1593 struct crypto_comp *tfm;
1594 int err;
1595
1596 tfm = crypto_alloc_comp(driver, type, mask);
1597 if (IS_ERR(tfm)) {
1598 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1599 "%ld\n", driver, PTR_ERR(tfm));
1600 return PTR_ERR(tfm);
1601 }
1602
1603 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1604 desc->suite.comp.decomp.vecs,
1605 desc->suite.comp.comp.count,
1606 desc->suite.comp.decomp.count);
1607
1608 crypto_free_comp(tfm);
1609 return err;
1610}
1611
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001612static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1613 u32 type, u32 mask)
1614{
1615 struct crypto_pcomp *tfm;
1616 int err;
1617
1618 tfm = crypto_alloc_pcomp(driver, type, mask);
1619 if (IS_ERR(tfm)) {
1620 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1621 driver, PTR_ERR(tfm));
1622 return PTR_ERR(tfm);
1623 }
1624
1625 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1626 desc->suite.pcomp.decomp.vecs,
1627 desc->suite.pcomp.comp.count,
1628 desc->suite.pcomp.decomp.count);
1629
1630 crypto_free_pcomp(tfm);
1631 return err;
1632}
1633
Herbert Xuda7f0332008-07-31 17:08:25 +08001634static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1635 u32 type, u32 mask)
1636{
1637 struct crypto_ahash *tfm;
1638 int err;
1639
Stephan Mueller425a8822015-03-30 21:56:31 +02001640 tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001641 if (IS_ERR(tfm)) {
1642 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1643 "%ld\n", driver, PTR_ERR(tfm));
1644 return PTR_ERR(tfm);
1645 }
1646
David S. Millera8f1a052010-05-19 14:12:03 +10001647 err = test_hash(tfm, desc->suite.hash.vecs,
1648 desc->suite.hash.count, true);
1649 if (!err)
1650 err = test_hash(tfm, desc->suite.hash.vecs,
1651 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001652
1653 crypto_free_ahash(tfm);
1654 return err;
1655}
1656
Herbert Xu8e3ee852008-11-07 14:58:52 +08001657static int alg_test_crc32c(const struct alg_test_desc *desc,
1658 const char *driver, u32 type, u32 mask)
1659{
1660 struct crypto_shash *tfm;
1661 u32 val;
1662 int err;
1663
1664 err = alg_test_hash(desc, driver, type, mask);
1665 if (err)
1666 goto out;
1667
Stephan Mueller425a8822015-03-30 21:56:31 +02001668 tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001669 if (IS_ERR(tfm)) {
1670 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1671 "%ld\n", driver, PTR_ERR(tfm));
1672 err = PTR_ERR(tfm);
1673 goto out;
1674 }
1675
1676 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001677 SHASH_DESC_ON_STACK(shash, tfm);
1678 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001679
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001680 shash->tfm = tfm;
1681 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001682
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001683 *ctx = le32_to_cpu(420553207);
1684 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001685 if (err) {
1686 printk(KERN_ERR "alg: crc32c: Operation failed for "
1687 "%s: %d\n", driver, err);
1688 break;
1689 }
1690
1691 if (val != ~420553207) {
1692 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1693 "%d\n", driver, val);
1694 err = -EINVAL;
1695 }
1696 } while (0);
1697
1698 crypto_free_shash(tfm);
1699
1700out:
1701 return err;
1702}
1703
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001704static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1705 u32 type, u32 mask)
1706{
1707 struct crypto_rng *rng;
1708 int err;
1709
Stephan Mueller425a8822015-03-30 21:56:31 +02001710 rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001711 if (IS_ERR(rng)) {
1712 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1713 "%ld\n", driver, PTR_ERR(rng));
1714 return PTR_ERR(rng);
1715 }
1716
1717 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1718
1719 crypto_free_rng(rng);
1720
1721 return err;
1722}
1723
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001724
1725static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1726 const char *driver, u32 type, u32 mask)
1727{
1728 int ret = -EAGAIN;
1729 struct crypto_rng *drng;
1730 struct drbg_test_data test_data;
1731 struct drbg_string addtl, pers, testentropy;
1732 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1733
1734 if (!buf)
1735 return -ENOMEM;
1736
Stephan Mueller425a8822015-03-30 21:56:31 +02001737 drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001738 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001739 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001740 "%s\n", driver);
1741 kzfree(buf);
1742 return -ENOMEM;
1743 }
1744
1745 test_data.testentropy = &testentropy;
1746 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1747 drbg_string_fill(&pers, test->pers, test->perslen);
1748 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1749 if (ret) {
1750 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1751 goto outbuf;
1752 }
1753
1754 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1755 if (pr) {
1756 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1757 ret = crypto_drbg_get_bytes_addtl_test(drng,
1758 buf, test->expectedlen, &addtl, &test_data);
1759 } else {
1760 ret = crypto_drbg_get_bytes_addtl(drng,
1761 buf, test->expectedlen, &addtl);
1762 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001763 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001764 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001765 "driver %s\n", driver);
1766 goto outbuf;
1767 }
1768
1769 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1770 if (pr) {
1771 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1772 ret = crypto_drbg_get_bytes_addtl_test(drng,
1773 buf, test->expectedlen, &addtl, &test_data);
1774 } else {
1775 ret = crypto_drbg_get_bytes_addtl(drng,
1776 buf, test->expectedlen, &addtl);
1777 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001778 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001779 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001780 "driver %s\n", driver);
1781 goto outbuf;
1782 }
1783
1784 ret = memcmp(test->expected, buf, test->expectedlen);
1785
1786outbuf:
1787 crypto_free_rng(drng);
1788 kzfree(buf);
1789 return ret;
1790}
1791
1792
1793static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1794 u32 type, u32 mask)
1795{
1796 int err = 0;
1797 int pr = 0;
1798 int i = 0;
1799 struct drbg_testvec *template = desc->suite.drbg.vecs;
1800 unsigned int tcount = desc->suite.drbg.count;
1801
1802 if (0 == memcmp(driver, "drbg_pr_", 8))
1803 pr = 1;
1804
1805 for (i = 0; i < tcount; i++) {
1806 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1807 if (err) {
1808 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1809 i, driver);
1810 err = -EINVAL;
1811 break;
1812 }
1813 }
1814 return err;
1815
1816}
1817
Youquan, Song863b5572009-12-23 19:45:20 +08001818static int alg_test_null(const struct alg_test_desc *desc,
1819 const char *driver, u32 type, u32 mask)
1820{
1821 return 0;
1822}
1823
Herbert Xuda7f0332008-07-31 17:08:25 +08001824/* Please keep this list sorted by algorithm name. */
1825static const struct alg_test_desc alg_test_descs[] = {
1826 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001827 .alg = "__cbc-cast5-avx",
1828 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001829 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001830 .alg = "__cbc-cast6-avx",
1831 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001832 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001833 .alg = "__cbc-serpent-avx",
1834 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001835 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001836 .alg = "__cbc-serpent-avx2",
1837 .test = alg_test_null,
1838 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001839 .alg = "__cbc-serpent-sse2",
1840 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001841 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001842 .alg = "__cbc-twofish-avx",
1843 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001844 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001845 .alg = "__driver-cbc-aes-aesni",
1846 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001847 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001848 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001849 .alg = "__driver-cbc-camellia-aesni",
1850 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001851 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001852 .alg = "__driver-cbc-camellia-aesni-avx2",
1853 .test = alg_test_null,
1854 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001855 .alg = "__driver-cbc-cast5-avx",
1856 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001857 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001858 .alg = "__driver-cbc-cast6-avx",
1859 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001860 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001861 .alg = "__driver-cbc-serpent-avx",
1862 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001863 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001864 .alg = "__driver-cbc-serpent-avx2",
1865 .test = alg_test_null,
1866 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001867 .alg = "__driver-cbc-serpent-sse2",
1868 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001869 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001870 .alg = "__driver-cbc-twofish-avx",
1871 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001872 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001873 .alg = "__driver-ecb-aes-aesni",
1874 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001875 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001876 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001877 .alg = "__driver-ecb-camellia-aesni",
1878 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001879 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001880 .alg = "__driver-ecb-camellia-aesni-avx2",
1881 .test = alg_test_null,
1882 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001883 .alg = "__driver-ecb-cast5-avx",
1884 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001885 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001886 .alg = "__driver-ecb-cast6-avx",
1887 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001888 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001889 .alg = "__driver-ecb-serpent-avx",
1890 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001891 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001892 .alg = "__driver-ecb-serpent-avx2",
1893 .test = alg_test_null,
1894 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001895 .alg = "__driver-ecb-serpent-sse2",
1896 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001897 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001898 .alg = "__driver-ecb-twofish-avx",
1899 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001900 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001901 .alg = "__ghash-pclmulqdqni",
1902 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001903 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001904 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001905 .alg = "ansi_cprng",
1906 .test = alg_test_cprng,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001907 .fips_allowed = 1,
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001908 .suite = {
1909 .cprng = {
1910 .vecs = ansi_cprng_aes_tv_template,
1911 .count = ANSI_CPRNG_AES_TEST_VECTORS
1912 }
1913 }
1914 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001915 .alg = "authenc(hmac(md5),ecb(cipher_null))",
1916 .test = alg_test_aead,
1917 .fips_allowed = 1,
1918 .suite = {
1919 .aead = {
1920 .enc = {
1921 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
1922 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1923 },
1924 .dec = {
1925 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
1926 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1927 }
1928 }
1929 }
1930 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03001931 .alg = "authenc(hmac(sha1),cbc(aes))",
1932 .test = alg_test_aead,
1933 .fips_allowed = 1,
1934 .suite = {
1935 .aead = {
1936 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301937 .vecs =
1938 hmac_sha1_aes_cbc_enc_tv_temp,
1939 .count =
1940 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1941 }
1942 }
1943 }
1944 }, {
1945 .alg = "authenc(hmac(sha1),cbc(des))",
1946 .test = alg_test_aead,
1947 .fips_allowed = 1,
1948 .suite = {
1949 .aead = {
1950 .enc = {
1951 .vecs =
1952 hmac_sha1_des_cbc_enc_tv_temp,
1953 .count =
1954 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1955 }
1956 }
1957 }
1958 }, {
1959 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
1960 .test = alg_test_aead,
1961 .fips_allowed = 1,
1962 .suite = {
1963 .aead = {
1964 .enc = {
1965 .vecs =
1966 hmac_sha1_des3_ede_cbc_enc_tv_temp,
1967 .count =
1968 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03001969 }
1970 }
1971 }
1972 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001973 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
1974 .test = alg_test_aead,
1975 .fips_allowed = 1,
1976 .suite = {
1977 .aead = {
1978 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301979 .vecs =
1980 hmac_sha1_ecb_cipher_null_enc_tv_temp,
1981 .count =
1982 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02001983 },
1984 .dec = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301985 .vecs =
1986 hmac_sha1_ecb_cipher_null_dec_tv_temp,
1987 .count =
1988 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
1989 }
1990 }
1991 }
1992 }, {
1993 .alg = "authenc(hmac(sha224),cbc(des))",
1994 .test = alg_test_aead,
1995 .fips_allowed = 1,
1996 .suite = {
1997 .aead = {
1998 .enc = {
1999 .vecs =
2000 hmac_sha224_des_cbc_enc_tv_temp,
2001 .count =
2002 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2003 }
2004 }
2005 }
2006 }, {
2007 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
2008 .test = alg_test_aead,
2009 .fips_allowed = 1,
2010 .suite = {
2011 .aead = {
2012 .enc = {
2013 .vecs =
2014 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2015 .count =
2016 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002017 }
2018 }
2019 }
2020 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03002021 .alg = "authenc(hmac(sha256),cbc(aes))",
2022 .test = alg_test_aead,
2023 .fips_allowed = 1,
2024 .suite = {
2025 .aead = {
2026 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302027 .vecs =
2028 hmac_sha256_aes_cbc_enc_tv_temp,
2029 .count =
2030 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2031 }
2032 }
2033 }
2034 }, {
2035 .alg = "authenc(hmac(sha256),cbc(des))",
2036 .test = alg_test_aead,
2037 .fips_allowed = 1,
2038 .suite = {
2039 .aead = {
2040 .enc = {
2041 .vecs =
2042 hmac_sha256_des_cbc_enc_tv_temp,
2043 .count =
2044 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2045 }
2046 }
2047 }
2048 }, {
2049 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
2050 .test = alg_test_aead,
2051 .fips_allowed = 1,
2052 .suite = {
2053 .aead = {
2054 .enc = {
2055 .vecs =
2056 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2057 .count =
2058 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2059 }
2060 }
2061 }
2062 }, {
2063 .alg = "authenc(hmac(sha384),cbc(des))",
2064 .test = alg_test_aead,
2065 .fips_allowed = 1,
2066 .suite = {
2067 .aead = {
2068 .enc = {
2069 .vecs =
2070 hmac_sha384_des_cbc_enc_tv_temp,
2071 .count =
2072 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2073 }
2074 }
2075 }
2076 }, {
2077 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
2078 .test = alg_test_aead,
2079 .fips_allowed = 1,
2080 .suite = {
2081 .aead = {
2082 .enc = {
2083 .vecs =
2084 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2085 .count =
2086 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002087 }
2088 }
2089 }
2090 }, {
2091 .alg = "authenc(hmac(sha512),cbc(aes))",
2092 .test = alg_test_aead,
2093 .fips_allowed = 1,
2094 .suite = {
2095 .aead = {
2096 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302097 .vecs =
2098 hmac_sha512_aes_cbc_enc_tv_temp,
2099 .count =
2100 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2101 }
2102 }
2103 }
2104 }, {
2105 .alg = "authenc(hmac(sha512),cbc(des))",
2106 .test = alg_test_aead,
2107 .fips_allowed = 1,
2108 .suite = {
2109 .aead = {
2110 .enc = {
2111 .vecs =
2112 hmac_sha512_des_cbc_enc_tv_temp,
2113 .count =
2114 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2115 }
2116 }
2117 }
2118 }, {
2119 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2120 .test = alg_test_aead,
2121 .fips_allowed = 1,
2122 .suite = {
2123 .aead = {
2124 .enc = {
2125 .vecs =
2126 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2127 .count =
2128 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002129 }
2130 }
2131 }
2132 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002133 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002134 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002135 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002136 .suite = {
2137 .cipher = {
2138 .enc = {
2139 .vecs = aes_cbc_enc_tv_template,
2140 .count = AES_CBC_ENC_TEST_VECTORS
2141 },
2142 .dec = {
2143 .vecs = aes_cbc_dec_tv_template,
2144 .count = AES_CBC_DEC_TEST_VECTORS
2145 }
2146 }
2147 }
2148 }, {
2149 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002150 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002151 .suite = {
2152 .cipher = {
2153 .enc = {
2154 .vecs = anubis_cbc_enc_tv_template,
2155 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2156 },
2157 .dec = {
2158 .vecs = anubis_cbc_dec_tv_template,
2159 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2160 }
2161 }
2162 }
2163 }, {
2164 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002165 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002166 .suite = {
2167 .cipher = {
2168 .enc = {
2169 .vecs = bf_cbc_enc_tv_template,
2170 .count = BF_CBC_ENC_TEST_VECTORS
2171 },
2172 .dec = {
2173 .vecs = bf_cbc_dec_tv_template,
2174 .count = BF_CBC_DEC_TEST_VECTORS
2175 }
2176 }
2177 }
2178 }, {
2179 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002180 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002181 .suite = {
2182 .cipher = {
2183 .enc = {
2184 .vecs = camellia_cbc_enc_tv_template,
2185 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2186 },
2187 .dec = {
2188 .vecs = camellia_cbc_dec_tv_template,
2189 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2190 }
2191 }
2192 }
2193 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002194 .alg = "cbc(cast5)",
2195 .test = alg_test_skcipher,
2196 .suite = {
2197 .cipher = {
2198 .enc = {
2199 .vecs = cast5_cbc_enc_tv_template,
2200 .count = CAST5_CBC_ENC_TEST_VECTORS
2201 },
2202 .dec = {
2203 .vecs = cast5_cbc_dec_tv_template,
2204 .count = CAST5_CBC_DEC_TEST_VECTORS
2205 }
2206 }
2207 }
2208 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002209 .alg = "cbc(cast6)",
2210 .test = alg_test_skcipher,
2211 .suite = {
2212 .cipher = {
2213 .enc = {
2214 .vecs = cast6_cbc_enc_tv_template,
2215 .count = CAST6_CBC_ENC_TEST_VECTORS
2216 },
2217 .dec = {
2218 .vecs = cast6_cbc_dec_tv_template,
2219 .count = CAST6_CBC_DEC_TEST_VECTORS
2220 }
2221 }
2222 }
2223 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002224 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002225 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002226 .suite = {
2227 .cipher = {
2228 .enc = {
2229 .vecs = des_cbc_enc_tv_template,
2230 .count = DES_CBC_ENC_TEST_VECTORS
2231 },
2232 .dec = {
2233 .vecs = des_cbc_dec_tv_template,
2234 .count = DES_CBC_DEC_TEST_VECTORS
2235 }
2236 }
2237 }
2238 }, {
2239 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002240 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002241 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002242 .suite = {
2243 .cipher = {
2244 .enc = {
2245 .vecs = des3_ede_cbc_enc_tv_template,
2246 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2247 },
2248 .dec = {
2249 .vecs = des3_ede_cbc_dec_tv_template,
2250 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2251 }
2252 }
2253 }
2254 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002255 .alg = "cbc(serpent)",
2256 .test = alg_test_skcipher,
2257 .suite = {
2258 .cipher = {
2259 .enc = {
2260 .vecs = serpent_cbc_enc_tv_template,
2261 .count = SERPENT_CBC_ENC_TEST_VECTORS
2262 },
2263 .dec = {
2264 .vecs = serpent_cbc_dec_tv_template,
2265 .count = SERPENT_CBC_DEC_TEST_VECTORS
2266 }
2267 }
2268 }
2269 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002270 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002271 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002272 .suite = {
2273 .cipher = {
2274 .enc = {
2275 .vecs = tf_cbc_enc_tv_template,
2276 .count = TF_CBC_ENC_TEST_VECTORS
2277 },
2278 .dec = {
2279 .vecs = tf_cbc_dec_tv_template,
2280 .count = TF_CBC_DEC_TEST_VECTORS
2281 }
2282 }
2283 }
2284 }, {
2285 .alg = "ccm(aes)",
2286 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002287 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002288 .suite = {
2289 .aead = {
2290 .enc = {
2291 .vecs = aes_ccm_enc_tv_template,
2292 .count = AES_CCM_ENC_TEST_VECTORS
2293 },
2294 .dec = {
2295 .vecs = aes_ccm_dec_tv_template,
2296 .count = AES_CCM_DEC_TEST_VECTORS
2297 }
2298 }
2299 }
2300 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002301 .alg = "cmac(aes)",
2302 .test = alg_test_hash,
2303 .suite = {
2304 .hash = {
2305 .vecs = aes_cmac128_tv_template,
2306 .count = CMAC_AES_TEST_VECTORS
2307 }
2308 }
2309 }, {
2310 .alg = "cmac(des3_ede)",
2311 .test = alg_test_hash,
2312 .suite = {
2313 .hash = {
2314 .vecs = des3_ede_cmac64_tv_template,
2315 .count = CMAC_DES3_EDE_TEST_VECTORS
2316 }
2317 }
2318 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002319 .alg = "compress_null",
2320 .test = alg_test_null,
2321 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002322 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002323 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002324 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002325 .suite = {
2326 .hash = {
2327 .vecs = crc32c_tv_template,
2328 .count = CRC32C_TEST_VECTORS
2329 }
2330 }
2331 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002332 .alg = "crct10dif",
2333 .test = alg_test_hash,
2334 .fips_allowed = 1,
2335 .suite = {
2336 .hash = {
2337 .vecs = crct10dif_tv_template,
2338 .count = CRCT10DIF_TEST_VECTORS
2339 }
2340 }
2341 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002342 .alg = "cryptd(__driver-cbc-aes-aesni)",
2343 .test = alg_test_null,
2344 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002345 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002346 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2347 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002348 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002349 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2350 .test = alg_test_null,
2351 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002352 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2353 .test = alg_test_null,
2354 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002355 .alg = "cryptd(__driver-ecb-aes-aesni)",
2356 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002357 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002358 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002359 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2360 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002361 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002362 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2363 .test = alg_test_null,
2364 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002365 .alg = "cryptd(__driver-ecb-cast5-avx)",
2366 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002367 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002368 .alg = "cryptd(__driver-ecb-cast6-avx)",
2369 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002370 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002371 .alg = "cryptd(__driver-ecb-serpent-avx)",
2372 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002373 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002374 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2375 .test = alg_test_null,
2376 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002377 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2378 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002379 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002380 .alg = "cryptd(__driver-ecb-twofish-avx)",
2381 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002382 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002383 .alg = "cryptd(__driver-gcm-aes-aesni)",
2384 .test = alg_test_null,
2385 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002386 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002387 .alg = "cryptd(__ghash-pclmulqdqni)",
2388 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002389 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002390 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002391 .alg = "ctr(aes)",
2392 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002393 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002394 .suite = {
2395 .cipher = {
2396 .enc = {
2397 .vecs = aes_ctr_enc_tv_template,
2398 .count = AES_CTR_ENC_TEST_VECTORS
2399 },
2400 .dec = {
2401 .vecs = aes_ctr_dec_tv_template,
2402 .count = AES_CTR_DEC_TEST_VECTORS
2403 }
2404 }
2405 }
2406 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002407 .alg = "ctr(blowfish)",
2408 .test = alg_test_skcipher,
2409 .suite = {
2410 .cipher = {
2411 .enc = {
2412 .vecs = bf_ctr_enc_tv_template,
2413 .count = BF_CTR_ENC_TEST_VECTORS
2414 },
2415 .dec = {
2416 .vecs = bf_ctr_dec_tv_template,
2417 .count = BF_CTR_DEC_TEST_VECTORS
2418 }
2419 }
2420 }
2421 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002422 .alg = "ctr(camellia)",
2423 .test = alg_test_skcipher,
2424 .suite = {
2425 .cipher = {
2426 .enc = {
2427 .vecs = camellia_ctr_enc_tv_template,
2428 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2429 },
2430 .dec = {
2431 .vecs = camellia_ctr_dec_tv_template,
2432 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2433 }
2434 }
2435 }
2436 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002437 .alg = "ctr(cast5)",
2438 .test = alg_test_skcipher,
2439 .suite = {
2440 .cipher = {
2441 .enc = {
2442 .vecs = cast5_ctr_enc_tv_template,
2443 .count = CAST5_CTR_ENC_TEST_VECTORS
2444 },
2445 .dec = {
2446 .vecs = cast5_ctr_dec_tv_template,
2447 .count = CAST5_CTR_DEC_TEST_VECTORS
2448 }
2449 }
2450 }
2451 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002452 .alg = "ctr(cast6)",
2453 .test = alg_test_skcipher,
2454 .suite = {
2455 .cipher = {
2456 .enc = {
2457 .vecs = cast6_ctr_enc_tv_template,
2458 .count = CAST6_CTR_ENC_TEST_VECTORS
2459 },
2460 .dec = {
2461 .vecs = cast6_ctr_dec_tv_template,
2462 .count = CAST6_CTR_DEC_TEST_VECTORS
2463 }
2464 }
2465 }
2466 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002467 .alg = "ctr(des)",
2468 .test = alg_test_skcipher,
2469 .suite = {
2470 .cipher = {
2471 .enc = {
2472 .vecs = des_ctr_enc_tv_template,
2473 .count = DES_CTR_ENC_TEST_VECTORS
2474 },
2475 .dec = {
2476 .vecs = des_ctr_dec_tv_template,
2477 .count = DES_CTR_DEC_TEST_VECTORS
2478 }
2479 }
2480 }
2481 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002482 .alg = "ctr(des3_ede)",
2483 .test = alg_test_skcipher,
2484 .suite = {
2485 .cipher = {
2486 .enc = {
2487 .vecs = des3_ede_ctr_enc_tv_template,
2488 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2489 },
2490 .dec = {
2491 .vecs = des3_ede_ctr_dec_tv_template,
2492 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2493 }
2494 }
2495 }
2496 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002497 .alg = "ctr(serpent)",
2498 .test = alg_test_skcipher,
2499 .suite = {
2500 .cipher = {
2501 .enc = {
2502 .vecs = serpent_ctr_enc_tv_template,
2503 .count = SERPENT_CTR_ENC_TEST_VECTORS
2504 },
2505 .dec = {
2506 .vecs = serpent_ctr_dec_tv_template,
2507 .count = SERPENT_CTR_DEC_TEST_VECTORS
2508 }
2509 }
2510 }
2511 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002512 .alg = "ctr(twofish)",
2513 .test = alg_test_skcipher,
2514 .suite = {
2515 .cipher = {
2516 .enc = {
2517 .vecs = tf_ctr_enc_tv_template,
2518 .count = TF_CTR_ENC_TEST_VECTORS
2519 },
2520 .dec = {
2521 .vecs = tf_ctr_dec_tv_template,
2522 .count = TF_CTR_DEC_TEST_VECTORS
2523 }
2524 }
2525 }
2526 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002527 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002528 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002529 .suite = {
2530 .cipher = {
2531 .enc = {
2532 .vecs = cts_mode_enc_tv_template,
2533 .count = CTS_MODE_ENC_TEST_VECTORS
2534 },
2535 .dec = {
2536 .vecs = cts_mode_dec_tv_template,
2537 .count = CTS_MODE_DEC_TEST_VECTORS
2538 }
2539 }
2540 }
2541 }, {
2542 .alg = "deflate",
2543 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002544 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002545 .suite = {
2546 .comp = {
2547 .comp = {
2548 .vecs = deflate_comp_tv_template,
2549 .count = DEFLATE_COMP_TEST_VECTORS
2550 },
2551 .decomp = {
2552 .vecs = deflate_decomp_tv_template,
2553 .count = DEFLATE_DECOMP_TEST_VECTORS
2554 }
2555 }
2556 }
2557 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002558 .alg = "digest_null",
2559 .test = alg_test_null,
2560 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002561 .alg = "drbg_nopr_ctr_aes128",
2562 .test = alg_test_drbg,
2563 .fips_allowed = 1,
2564 .suite = {
2565 .drbg = {
2566 .vecs = drbg_nopr_ctr_aes128_tv_template,
2567 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2568 }
2569 }
2570 }, {
2571 .alg = "drbg_nopr_ctr_aes192",
2572 .test = alg_test_drbg,
2573 .fips_allowed = 1,
2574 .suite = {
2575 .drbg = {
2576 .vecs = drbg_nopr_ctr_aes192_tv_template,
2577 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2578 }
2579 }
2580 }, {
2581 .alg = "drbg_nopr_ctr_aes256",
2582 .test = alg_test_drbg,
2583 .fips_allowed = 1,
2584 .suite = {
2585 .drbg = {
2586 .vecs = drbg_nopr_ctr_aes256_tv_template,
2587 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2588 }
2589 }
2590 }, {
2591 /*
2592 * There is no need to specifically test the DRBG with every
2593 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2594 */
2595 .alg = "drbg_nopr_hmac_sha1",
2596 .fips_allowed = 1,
2597 .test = alg_test_null,
2598 }, {
2599 .alg = "drbg_nopr_hmac_sha256",
2600 .test = alg_test_drbg,
2601 .fips_allowed = 1,
2602 .suite = {
2603 .drbg = {
2604 .vecs = drbg_nopr_hmac_sha256_tv_template,
2605 .count =
2606 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2607 }
2608 }
2609 }, {
2610 /* covered by drbg_nopr_hmac_sha256 test */
2611 .alg = "drbg_nopr_hmac_sha384",
2612 .fips_allowed = 1,
2613 .test = alg_test_null,
2614 }, {
2615 .alg = "drbg_nopr_hmac_sha512",
2616 .test = alg_test_null,
2617 .fips_allowed = 1,
2618 }, {
2619 .alg = "drbg_nopr_sha1",
2620 .fips_allowed = 1,
2621 .test = alg_test_null,
2622 }, {
2623 .alg = "drbg_nopr_sha256",
2624 .test = alg_test_drbg,
2625 .fips_allowed = 1,
2626 .suite = {
2627 .drbg = {
2628 .vecs = drbg_nopr_sha256_tv_template,
2629 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2630 }
2631 }
2632 }, {
2633 /* covered by drbg_nopr_sha256 test */
2634 .alg = "drbg_nopr_sha384",
2635 .fips_allowed = 1,
2636 .test = alg_test_null,
2637 }, {
2638 .alg = "drbg_nopr_sha512",
2639 .fips_allowed = 1,
2640 .test = alg_test_null,
2641 }, {
2642 .alg = "drbg_pr_ctr_aes128",
2643 .test = alg_test_drbg,
2644 .fips_allowed = 1,
2645 .suite = {
2646 .drbg = {
2647 .vecs = drbg_pr_ctr_aes128_tv_template,
2648 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2649 }
2650 }
2651 }, {
2652 /* covered by drbg_pr_ctr_aes128 test */
2653 .alg = "drbg_pr_ctr_aes192",
2654 .fips_allowed = 1,
2655 .test = alg_test_null,
2656 }, {
2657 .alg = "drbg_pr_ctr_aes256",
2658 .fips_allowed = 1,
2659 .test = alg_test_null,
2660 }, {
2661 .alg = "drbg_pr_hmac_sha1",
2662 .fips_allowed = 1,
2663 .test = alg_test_null,
2664 }, {
2665 .alg = "drbg_pr_hmac_sha256",
2666 .test = alg_test_drbg,
2667 .fips_allowed = 1,
2668 .suite = {
2669 .drbg = {
2670 .vecs = drbg_pr_hmac_sha256_tv_template,
2671 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2672 }
2673 }
2674 }, {
2675 /* covered by drbg_pr_hmac_sha256 test */
2676 .alg = "drbg_pr_hmac_sha384",
2677 .fips_allowed = 1,
2678 .test = alg_test_null,
2679 }, {
2680 .alg = "drbg_pr_hmac_sha512",
2681 .test = alg_test_null,
2682 .fips_allowed = 1,
2683 }, {
2684 .alg = "drbg_pr_sha1",
2685 .fips_allowed = 1,
2686 .test = alg_test_null,
2687 }, {
2688 .alg = "drbg_pr_sha256",
2689 .test = alg_test_drbg,
2690 .fips_allowed = 1,
2691 .suite = {
2692 .drbg = {
2693 .vecs = drbg_pr_sha256_tv_template,
2694 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2695 }
2696 }
2697 }, {
2698 /* covered by drbg_pr_sha256 test */
2699 .alg = "drbg_pr_sha384",
2700 .fips_allowed = 1,
2701 .test = alg_test_null,
2702 }, {
2703 .alg = "drbg_pr_sha512",
2704 .fips_allowed = 1,
2705 .test = alg_test_null,
2706 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002707 .alg = "ecb(__aes-aesni)",
2708 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002709 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002710 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002711 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002712 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002713 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002714 .suite = {
2715 .cipher = {
2716 .enc = {
2717 .vecs = aes_enc_tv_template,
2718 .count = AES_ENC_TEST_VECTORS
2719 },
2720 .dec = {
2721 .vecs = aes_dec_tv_template,
2722 .count = AES_DEC_TEST_VECTORS
2723 }
2724 }
2725 }
2726 }, {
2727 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002728 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002729 .suite = {
2730 .cipher = {
2731 .enc = {
2732 .vecs = anubis_enc_tv_template,
2733 .count = ANUBIS_ENC_TEST_VECTORS
2734 },
2735 .dec = {
2736 .vecs = anubis_dec_tv_template,
2737 .count = ANUBIS_DEC_TEST_VECTORS
2738 }
2739 }
2740 }
2741 }, {
2742 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002743 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002744 .suite = {
2745 .cipher = {
2746 .enc = {
2747 .vecs = arc4_enc_tv_template,
2748 .count = ARC4_ENC_TEST_VECTORS
2749 },
2750 .dec = {
2751 .vecs = arc4_dec_tv_template,
2752 .count = ARC4_DEC_TEST_VECTORS
2753 }
2754 }
2755 }
2756 }, {
2757 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002758 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002759 .suite = {
2760 .cipher = {
2761 .enc = {
2762 .vecs = bf_enc_tv_template,
2763 .count = BF_ENC_TEST_VECTORS
2764 },
2765 .dec = {
2766 .vecs = bf_dec_tv_template,
2767 .count = BF_DEC_TEST_VECTORS
2768 }
2769 }
2770 }
2771 }, {
2772 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002773 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002774 .suite = {
2775 .cipher = {
2776 .enc = {
2777 .vecs = camellia_enc_tv_template,
2778 .count = CAMELLIA_ENC_TEST_VECTORS
2779 },
2780 .dec = {
2781 .vecs = camellia_dec_tv_template,
2782 .count = CAMELLIA_DEC_TEST_VECTORS
2783 }
2784 }
2785 }
2786 }, {
2787 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002788 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002789 .suite = {
2790 .cipher = {
2791 .enc = {
2792 .vecs = cast5_enc_tv_template,
2793 .count = CAST5_ENC_TEST_VECTORS
2794 },
2795 .dec = {
2796 .vecs = cast5_dec_tv_template,
2797 .count = CAST5_DEC_TEST_VECTORS
2798 }
2799 }
2800 }
2801 }, {
2802 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002803 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002804 .suite = {
2805 .cipher = {
2806 .enc = {
2807 .vecs = cast6_enc_tv_template,
2808 .count = CAST6_ENC_TEST_VECTORS
2809 },
2810 .dec = {
2811 .vecs = cast6_dec_tv_template,
2812 .count = CAST6_DEC_TEST_VECTORS
2813 }
2814 }
2815 }
2816 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002817 .alg = "ecb(cipher_null)",
2818 .test = alg_test_null,
2819 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002820 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002821 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002822 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002823 .suite = {
2824 .cipher = {
2825 .enc = {
2826 .vecs = des_enc_tv_template,
2827 .count = DES_ENC_TEST_VECTORS
2828 },
2829 .dec = {
2830 .vecs = des_dec_tv_template,
2831 .count = DES_DEC_TEST_VECTORS
2832 }
2833 }
2834 }
2835 }, {
2836 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002837 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002838 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002839 .suite = {
2840 .cipher = {
2841 .enc = {
2842 .vecs = des3_ede_enc_tv_template,
2843 .count = DES3_EDE_ENC_TEST_VECTORS
2844 },
2845 .dec = {
2846 .vecs = des3_ede_dec_tv_template,
2847 .count = DES3_EDE_DEC_TEST_VECTORS
2848 }
2849 }
2850 }
2851 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002852 .alg = "ecb(fcrypt)",
2853 .test = alg_test_skcipher,
2854 .suite = {
2855 .cipher = {
2856 .enc = {
2857 .vecs = fcrypt_pcbc_enc_tv_template,
2858 .count = 1
2859 },
2860 .dec = {
2861 .vecs = fcrypt_pcbc_dec_tv_template,
2862 .count = 1
2863 }
2864 }
2865 }
2866 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002867 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002868 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002869 .suite = {
2870 .cipher = {
2871 .enc = {
2872 .vecs = khazad_enc_tv_template,
2873 .count = KHAZAD_ENC_TEST_VECTORS
2874 },
2875 .dec = {
2876 .vecs = khazad_dec_tv_template,
2877 .count = KHAZAD_DEC_TEST_VECTORS
2878 }
2879 }
2880 }
2881 }, {
2882 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002883 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002884 .suite = {
2885 .cipher = {
2886 .enc = {
2887 .vecs = seed_enc_tv_template,
2888 .count = SEED_ENC_TEST_VECTORS
2889 },
2890 .dec = {
2891 .vecs = seed_dec_tv_template,
2892 .count = SEED_DEC_TEST_VECTORS
2893 }
2894 }
2895 }
2896 }, {
2897 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002898 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002899 .suite = {
2900 .cipher = {
2901 .enc = {
2902 .vecs = serpent_enc_tv_template,
2903 .count = SERPENT_ENC_TEST_VECTORS
2904 },
2905 .dec = {
2906 .vecs = serpent_dec_tv_template,
2907 .count = SERPENT_DEC_TEST_VECTORS
2908 }
2909 }
2910 }
2911 }, {
2912 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002913 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002914 .suite = {
2915 .cipher = {
2916 .enc = {
2917 .vecs = tea_enc_tv_template,
2918 .count = TEA_ENC_TEST_VECTORS
2919 },
2920 .dec = {
2921 .vecs = tea_dec_tv_template,
2922 .count = TEA_DEC_TEST_VECTORS
2923 }
2924 }
2925 }
2926 }, {
2927 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002928 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002929 .suite = {
2930 .cipher = {
2931 .enc = {
2932 .vecs = tnepres_enc_tv_template,
2933 .count = TNEPRES_ENC_TEST_VECTORS
2934 },
2935 .dec = {
2936 .vecs = tnepres_dec_tv_template,
2937 .count = TNEPRES_DEC_TEST_VECTORS
2938 }
2939 }
2940 }
2941 }, {
2942 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002943 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002944 .suite = {
2945 .cipher = {
2946 .enc = {
2947 .vecs = tf_enc_tv_template,
2948 .count = TF_ENC_TEST_VECTORS
2949 },
2950 .dec = {
2951 .vecs = tf_dec_tv_template,
2952 .count = TF_DEC_TEST_VECTORS
2953 }
2954 }
2955 }
2956 }, {
2957 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002958 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002959 .suite = {
2960 .cipher = {
2961 .enc = {
2962 .vecs = xeta_enc_tv_template,
2963 .count = XETA_ENC_TEST_VECTORS
2964 },
2965 .dec = {
2966 .vecs = xeta_dec_tv_template,
2967 .count = XETA_DEC_TEST_VECTORS
2968 }
2969 }
2970 }
2971 }, {
2972 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002973 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002974 .suite = {
2975 .cipher = {
2976 .enc = {
2977 .vecs = xtea_enc_tv_template,
2978 .count = XTEA_ENC_TEST_VECTORS
2979 },
2980 .dec = {
2981 .vecs = xtea_dec_tv_template,
2982 .count = XTEA_DEC_TEST_VECTORS
2983 }
2984 }
2985 }
2986 }, {
2987 .alg = "gcm(aes)",
2988 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002989 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002990 .suite = {
2991 .aead = {
2992 .enc = {
2993 .vecs = aes_gcm_enc_tv_template,
2994 .count = AES_GCM_ENC_TEST_VECTORS
2995 },
2996 .dec = {
2997 .vecs = aes_gcm_dec_tv_template,
2998 .count = AES_GCM_DEC_TEST_VECTORS
2999 }
3000 }
3001 }
3002 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003003 .alg = "ghash",
3004 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003005 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003006 .suite = {
3007 .hash = {
3008 .vecs = ghash_tv_template,
3009 .count = GHASH_TEST_VECTORS
3010 }
3011 }
3012 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003013 .alg = "hmac(crc32)",
3014 .test = alg_test_hash,
3015 .suite = {
3016 .hash = {
3017 .vecs = bfin_crc_tv_template,
3018 .count = BFIN_CRC_TEST_VECTORS
3019 }
3020 }
3021 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003022 .alg = "hmac(md5)",
3023 .test = alg_test_hash,
3024 .suite = {
3025 .hash = {
3026 .vecs = hmac_md5_tv_template,
3027 .count = HMAC_MD5_TEST_VECTORS
3028 }
3029 }
3030 }, {
3031 .alg = "hmac(rmd128)",
3032 .test = alg_test_hash,
3033 .suite = {
3034 .hash = {
3035 .vecs = hmac_rmd128_tv_template,
3036 .count = HMAC_RMD128_TEST_VECTORS
3037 }
3038 }
3039 }, {
3040 .alg = "hmac(rmd160)",
3041 .test = alg_test_hash,
3042 .suite = {
3043 .hash = {
3044 .vecs = hmac_rmd160_tv_template,
3045 .count = HMAC_RMD160_TEST_VECTORS
3046 }
3047 }
3048 }, {
3049 .alg = "hmac(sha1)",
3050 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003051 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003052 .suite = {
3053 .hash = {
3054 .vecs = hmac_sha1_tv_template,
3055 .count = HMAC_SHA1_TEST_VECTORS
3056 }
3057 }
3058 }, {
3059 .alg = "hmac(sha224)",
3060 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003061 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003062 .suite = {
3063 .hash = {
3064 .vecs = hmac_sha224_tv_template,
3065 .count = HMAC_SHA224_TEST_VECTORS
3066 }
3067 }
3068 }, {
3069 .alg = "hmac(sha256)",
3070 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003071 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003072 .suite = {
3073 .hash = {
3074 .vecs = hmac_sha256_tv_template,
3075 .count = HMAC_SHA256_TEST_VECTORS
3076 }
3077 }
3078 }, {
3079 .alg = "hmac(sha384)",
3080 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003081 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003082 .suite = {
3083 .hash = {
3084 .vecs = hmac_sha384_tv_template,
3085 .count = HMAC_SHA384_TEST_VECTORS
3086 }
3087 }
3088 }, {
3089 .alg = "hmac(sha512)",
3090 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003091 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003092 .suite = {
3093 .hash = {
3094 .vecs = hmac_sha512_tv_template,
3095 .count = HMAC_SHA512_TEST_VECTORS
3096 }
3097 }
3098 }, {
3099 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003100 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003101 .suite = {
3102 .cipher = {
3103 .enc = {
3104 .vecs = aes_lrw_enc_tv_template,
3105 .count = AES_LRW_ENC_TEST_VECTORS
3106 },
3107 .dec = {
3108 .vecs = aes_lrw_dec_tv_template,
3109 .count = AES_LRW_DEC_TEST_VECTORS
3110 }
3111 }
3112 }
3113 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003114 .alg = "lrw(camellia)",
3115 .test = alg_test_skcipher,
3116 .suite = {
3117 .cipher = {
3118 .enc = {
3119 .vecs = camellia_lrw_enc_tv_template,
3120 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3121 },
3122 .dec = {
3123 .vecs = camellia_lrw_dec_tv_template,
3124 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3125 }
3126 }
3127 }
3128 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003129 .alg = "lrw(cast6)",
3130 .test = alg_test_skcipher,
3131 .suite = {
3132 .cipher = {
3133 .enc = {
3134 .vecs = cast6_lrw_enc_tv_template,
3135 .count = CAST6_LRW_ENC_TEST_VECTORS
3136 },
3137 .dec = {
3138 .vecs = cast6_lrw_dec_tv_template,
3139 .count = CAST6_LRW_DEC_TEST_VECTORS
3140 }
3141 }
3142 }
3143 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003144 .alg = "lrw(serpent)",
3145 .test = alg_test_skcipher,
3146 .suite = {
3147 .cipher = {
3148 .enc = {
3149 .vecs = serpent_lrw_enc_tv_template,
3150 .count = SERPENT_LRW_ENC_TEST_VECTORS
3151 },
3152 .dec = {
3153 .vecs = serpent_lrw_dec_tv_template,
3154 .count = SERPENT_LRW_DEC_TEST_VECTORS
3155 }
3156 }
3157 }
3158 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003159 .alg = "lrw(twofish)",
3160 .test = alg_test_skcipher,
3161 .suite = {
3162 .cipher = {
3163 .enc = {
3164 .vecs = tf_lrw_enc_tv_template,
3165 .count = TF_LRW_ENC_TEST_VECTORS
3166 },
3167 .dec = {
3168 .vecs = tf_lrw_dec_tv_template,
3169 .count = TF_LRW_DEC_TEST_VECTORS
3170 }
3171 }
3172 }
3173 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003174 .alg = "lz4",
3175 .test = alg_test_comp,
3176 .fips_allowed = 1,
3177 .suite = {
3178 .comp = {
3179 .comp = {
3180 .vecs = lz4_comp_tv_template,
3181 .count = LZ4_COMP_TEST_VECTORS
3182 },
3183 .decomp = {
3184 .vecs = lz4_decomp_tv_template,
3185 .count = LZ4_DECOMP_TEST_VECTORS
3186 }
3187 }
3188 }
3189 }, {
3190 .alg = "lz4hc",
3191 .test = alg_test_comp,
3192 .fips_allowed = 1,
3193 .suite = {
3194 .comp = {
3195 .comp = {
3196 .vecs = lz4hc_comp_tv_template,
3197 .count = LZ4HC_COMP_TEST_VECTORS
3198 },
3199 .decomp = {
3200 .vecs = lz4hc_decomp_tv_template,
3201 .count = LZ4HC_DECOMP_TEST_VECTORS
3202 }
3203 }
3204 }
3205 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003206 .alg = "lzo",
3207 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003208 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003209 .suite = {
3210 .comp = {
3211 .comp = {
3212 .vecs = lzo_comp_tv_template,
3213 .count = LZO_COMP_TEST_VECTORS
3214 },
3215 .decomp = {
3216 .vecs = lzo_decomp_tv_template,
3217 .count = LZO_DECOMP_TEST_VECTORS
3218 }
3219 }
3220 }
3221 }, {
3222 .alg = "md4",
3223 .test = alg_test_hash,
3224 .suite = {
3225 .hash = {
3226 .vecs = md4_tv_template,
3227 .count = MD4_TEST_VECTORS
3228 }
3229 }
3230 }, {
3231 .alg = "md5",
3232 .test = alg_test_hash,
3233 .suite = {
3234 .hash = {
3235 .vecs = md5_tv_template,
3236 .count = MD5_TEST_VECTORS
3237 }
3238 }
3239 }, {
3240 .alg = "michael_mic",
3241 .test = alg_test_hash,
3242 .suite = {
3243 .hash = {
3244 .vecs = michael_mic_tv_template,
3245 .count = MICHAEL_MIC_TEST_VECTORS
3246 }
3247 }
3248 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003249 .alg = "ofb(aes)",
3250 .test = alg_test_skcipher,
3251 .fips_allowed = 1,
3252 .suite = {
3253 .cipher = {
3254 .enc = {
3255 .vecs = aes_ofb_enc_tv_template,
3256 .count = AES_OFB_ENC_TEST_VECTORS
3257 },
3258 .dec = {
3259 .vecs = aes_ofb_dec_tv_template,
3260 .count = AES_OFB_DEC_TEST_VECTORS
3261 }
3262 }
3263 }
3264 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003265 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003266 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003267 .suite = {
3268 .cipher = {
3269 .enc = {
3270 .vecs = fcrypt_pcbc_enc_tv_template,
3271 .count = FCRYPT_ENC_TEST_VECTORS
3272 },
3273 .dec = {
3274 .vecs = fcrypt_pcbc_dec_tv_template,
3275 .count = FCRYPT_DEC_TEST_VECTORS
3276 }
3277 }
3278 }
3279 }, {
3280 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003281 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003282 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003283 .suite = {
3284 .cipher = {
3285 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003286 .vecs = aes_ctr_rfc3686_enc_tv_template,
3287 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003288 },
3289 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003290 .vecs = aes_ctr_rfc3686_dec_tv_template,
3291 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003292 }
3293 }
3294 }
3295 }, {
Adrian Hoban69435b92010-11-04 15:02:04 -04003296 .alg = "rfc4106(gcm(aes))",
3297 .test = alg_test_aead,
Jarod Wilsondb71f292015-01-23 12:42:15 -05003298 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003299 .suite = {
3300 .aead = {
3301 .enc = {
3302 .vecs = aes_gcm_rfc4106_enc_tv_template,
3303 .count = AES_GCM_4106_ENC_TEST_VECTORS
3304 },
3305 .dec = {
3306 .vecs = aes_gcm_rfc4106_dec_tv_template,
3307 .count = AES_GCM_4106_DEC_TEST_VECTORS
3308 }
3309 }
3310 }
3311 }, {
Jarod Wilson5d667322009-05-04 19:23:40 +08003312 .alg = "rfc4309(ccm(aes))",
3313 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003314 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003315 .suite = {
3316 .aead = {
3317 .enc = {
3318 .vecs = aes_ccm_rfc4309_enc_tv_template,
3319 .count = AES_CCM_4309_ENC_TEST_VECTORS
3320 },
3321 .dec = {
3322 .vecs = aes_ccm_rfc4309_dec_tv_template,
3323 .count = AES_CCM_4309_DEC_TEST_VECTORS
3324 }
3325 }
3326 }
3327 }, {
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003328 .alg = "rfc4543(gcm(aes))",
3329 .test = alg_test_aead,
3330 .suite = {
3331 .aead = {
3332 .enc = {
3333 .vecs = aes_gcm_rfc4543_enc_tv_template,
3334 .count = AES_GCM_4543_ENC_TEST_VECTORS
3335 },
3336 .dec = {
3337 .vecs = aes_gcm_rfc4543_dec_tv_template,
3338 .count = AES_GCM_4543_DEC_TEST_VECTORS
3339 },
3340 }
3341 }
3342 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003343 .alg = "rmd128",
3344 .test = alg_test_hash,
3345 .suite = {
3346 .hash = {
3347 .vecs = rmd128_tv_template,
3348 .count = RMD128_TEST_VECTORS
3349 }
3350 }
3351 }, {
3352 .alg = "rmd160",
3353 .test = alg_test_hash,
3354 .suite = {
3355 .hash = {
3356 .vecs = rmd160_tv_template,
3357 .count = RMD160_TEST_VECTORS
3358 }
3359 }
3360 }, {
3361 .alg = "rmd256",
3362 .test = alg_test_hash,
3363 .suite = {
3364 .hash = {
3365 .vecs = rmd256_tv_template,
3366 .count = RMD256_TEST_VECTORS
3367 }
3368 }
3369 }, {
3370 .alg = "rmd320",
3371 .test = alg_test_hash,
3372 .suite = {
3373 .hash = {
3374 .vecs = rmd320_tv_template,
3375 .count = RMD320_TEST_VECTORS
3376 }
3377 }
3378 }, {
3379 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003380 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003381 .suite = {
3382 .cipher = {
3383 .enc = {
3384 .vecs = salsa20_stream_enc_tv_template,
3385 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3386 }
3387 }
3388 }
3389 }, {
3390 .alg = "sha1",
3391 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003392 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003393 .suite = {
3394 .hash = {
3395 .vecs = sha1_tv_template,
3396 .count = SHA1_TEST_VECTORS
3397 }
3398 }
3399 }, {
3400 .alg = "sha224",
3401 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003402 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003403 .suite = {
3404 .hash = {
3405 .vecs = sha224_tv_template,
3406 .count = SHA224_TEST_VECTORS
3407 }
3408 }
3409 }, {
3410 .alg = "sha256",
3411 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003412 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003413 .suite = {
3414 .hash = {
3415 .vecs = sha256_tv_template,
3416 .count = SHA256_TEST_VECTORS
3417 }
3418 }
3419 }, {
3420 .alg = "sha384",
3421 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003422 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003423 .suite = {
3424 .hash = {
3425 .vecs = sha384_tv_template,
3426 .count = SHA384_TEST_VECTORS
3427 }
3428 }
3429 }, {
3430 .alg = "sha512",
3431 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003432 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003433 .suite = {
3434 .hash = {
3435 .vecs = sha512_tv_template,
3436 .count = SHA512_TEST_VECTORS
3437 }
3438 }
3439 }, {
3440 .alg = "tgr128",
3441 .test = alg_test_hash,
3442 .suite = {
3443 .hash = {
3444 .vecs = tgr128_tv_template,
3445 .count = TGR128_TEST_VECTORS
3446 }
3447 }
3448 }, {
3449 .alg = "tgr160",
3450 .test = alg_test_hash,
3451 .suite = {
3452 .hash = {
3453 .vecs = tgr160_tv_template,
3454 .count = TGR160_TEST_VECTORS
3455 }
3456 }
3457 }, {
3458 .alg = "tgr192",
3459 .test = alg_test_hash,
3460 .suite = {
3461 .hash = {
3462 .vecs = tgr192_tv_template,
3463 .count = TGR192_TEST_VECTORS
3464 }
3465 }
3466 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003467 .alg = "vmac(aes)",
3468 .test = alg_test_hash,
3469 .suite = {
3470 .hash = {
3471 .vecs = aes_vmac128_tv_template,
3472 .count = VMAC_AES_TEST_VECTORS
3473 }
3474 }
3475 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003476 .alg = "wp256",
3477 .test = alg_test_hash,
3478 .suite = {
3479 .hash = {
3480 .vecs = wp256_tv_template,
3481 .count = WP256_TEST_VECTORS
3482 }
3483 }
3484 }, {
3485 .alg = "wp384",
3486 .test = alg_test_hash,
3487 .suite = {
3488 .hash = {
3489 .vecs = wp384_tv_template,
3490 .count = WP384_TEST_VECTORS
3491 }
3492 }
3493 }, {
3494 .alg = "wp512",
3495 .test = alg_test_hash,
3496 .suite = {
3497 .hash = {
3498 .vecs = wp512_tv_template,
3499 .count = WP512_TEST_VECTORS
3500 }
3501 }
3502 }, {
3503 .alg = "xcbc(aes)",
3504 .test = alg_test_hash,
3505 .suite = {
3506 .hash = {
3507 .vecs = aes_xcbc128_tv_template,
3508 .count = XCBC_AES_TEST_VECTORS
3509 }
3510 }
3511 }, {
3512 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003513 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003514 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003515 .suite = {
3516 .cipher = {
3517 .enc = {
3518 .vecs = aes_xts_enc_tv_template,
3519 .count = AES_XTS_ENC_TEST_VECTORS
3520 },
3521 .dec = {
3522 .vecs = aes_xts_dec_tv_template,
3523 .count = AES_XTS_DEC_TEST_VECTORS
3524 }
3525 }
3526 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003527 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003528 .alg = "xts(camellia)",
3529 .test = alg_test_skcipher,
3530 .suite = {
3531 .cipher = {
3532 .enc = {
3533 .vecs = camellia_xts_enc_tv_template,
3534 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3535 },
3536 .dec = {
3537 .vecs = camellia_xts_dec_tv_template,
3538 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3539 }
3540 }
3541 }
3542 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003543 .alg = "xts(cast6)",
3544 .test = alg_test_skcipher,
3545 .suite = {
3546 .cipher = {
3547 .enc = {
3548 .vecs = cast6_xts_enc_tv_template,
3549 .count = CAST6_XTS_ENC_TEST_VECTORS
3550 },
3551 .dec = {
3552 .vecs = cast6_xts_dec_tv_template,
3553 .count = CAST6_XTS_DEC_TEST_VECTORS
3554 }
3555 }
3556 }
3557 }, {
Jussi Kivilinna18be20b2011-10-18 13:33:17 +03003558 .alg = "xts(serpent)",
3559 .test = alg_test_skcipher,
3560 .suite = {
3561 .cipher = {
3562 .enc = {
3563 .vecs = serpent_xts_enc_tv_template,
3564 .count = SERPENT_XTS_ENC_TEST_VECTORS
3565 },
3566 .dec = {
3567 .vecs = serpent_xts_dec_tv_template,
3568 .count = SERPENT_XTS_DEC_TEST_VECTORS
3569 }
3570 }
3571 }
3572 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003573 .alg = "xts(twofish)",
3574 .test = alg_test_skcipher,
3575 .suite = {
3576 .cipher = {
3577 .enc = {
3578 .vecs = tf_xts_enc_tv_template,
3579 .count = TF_XTS_ENC_TEST_VECTORS
3580 },
3581 .dec = {
3582 .vecs = tf_xts_dec_tv_template,
3583 .count = TF_XTS_DEC_TEST_VECTORS
3584 }
3585 }
3586 }
3587 }, {
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003588 .alg = "zlib",
3589 .test = alg_test_pcomp,
Milan Broz08189042012-12-06 17:16:28 +08003590 .fips_allowed = 1,
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003591 .suite = {
3592 .pcomp = {
3593 .comp = {
3594 .vecs = zlib_comp_tv_template,
3595 .count = ZLIB_COMP_TEST_VECTORS
3596 },
3597 .decomp = {
3598 .vecs = zlib_decomp_tv_template,
3599 .count = ZLIB_DECOMP_TEST_VECTORS
3600 }
3601 }
3602 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003603 }
3604};
3605
Jussi Kivilinna57147582013-06-13 17:37:40 +03003606static bool alg_test_descs_checked;
3607
3608static void alg_test_descs_check_order(void)
3609{
3610 int i;
3611
3612 /* only check once */
3613 if (alg_test_descs_checked)
3614 return;
3615
3616 alg_test_descs_checked = true;
3617
3618 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3619 int diff = strcmp(alg_test_descs[i - 1].alg,
3620 alg_test_descs[i].alg);
3621
3622 if (WARN_ON(diff > 0)) {
3623 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3624 alg_test_descs[i - 1].alg,
3625 alg_test_descs[i].alg);
3626 }
3627
3628 if (WARN_ON(diff == 0)) {
3629 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3630 alg_test_descs[i].alg);
3631 }
3632 }
3633}
3634
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003635static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003636{
3637 int start = 0;
3638 int end = ARRAY_SIZE(alg_test_descs);
3639
3640 while (start < end) {
3641 int i = (start + end) / 2;
3642 int diff = strcmp(alg_test_descs[i].alg, alg);
3643
3644 if (diff > 0) {
3645 end = i;
3646 continue;
3647 }
3648
3649 if (diff < 0) {
3650 start = i + 1;
3651 continue;
3652 }
3653
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003654 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003655 }
3656
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003657 return -1;
3658}
3659
3660int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3661{
3662 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003663 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003664 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003665
Jussi Kivilinna57147582013-06-13 17:37:40 +03003666 alg_test_descs_check_order();
3667
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003668 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3669 char nalg[CRYPTO_MAX_ALG_NAME];
3670
3671 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3672 sizeof(nalg))
3673 return -ENAMETOOLONG;
3674
3675 i = alg_find_test(nalg);
3676 if (i < 0)
3677 goto notest;
3678
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003679 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3680 goto non_fips_alg;
3681
Jarod Wilson941fb322009-05-04 19:49:23 +08003682 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3683 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003684 }
3685
3686 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003687 j = alg_find_test(driver);
3688 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003689 goto notest;
3690
Herbert Xua68f6612009-07-02 16:32:12 +08003691 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3692 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003693 goto non_fips_alg;
3694
Herbert Xua68f6612009-07-02 16:32:12 +08003695 rc = 0;
3696 if (i >= 0)
3697 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3698 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003699 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003700 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3701 type, mask);
3702
Jarod Wilson941fb322009-05-04 19:49:23 +08003703test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003704 if (fips_enabled && rc)
3705 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3706
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003707 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09003708 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003709
Neil Hormand12d6b62008-10-12 20:36:51 +08003710 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003711
3712notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003713 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3714 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003715non_fips_alg:
3716 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003717}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003718
Herbert Xu326a6342010-08-06 09:40:28 +08003719#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003720
Herbert Xuda7f0332008-07-31 17:08:25 +08003721EXPORT_SYMBOL_GPL(alg_test);