blob: 9459dfd7357f563de32d6abe487793cbc8ac6570 [file] [log] [blame]
Herbert Xuda7f0332008-07-31 17:08:25 +08001/*
2 * Algorithm testing framework and tests.
3 *
4 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
5 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
6 * Copyright (c) 2007 Nokia Siemens Networks
7 * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
8 *
Adrian Hoban69435b92010-11-04 15:02:04 -04009 * Updated RFC4106 AES-GCM testing.
10 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
11 * Adrian Hoban <adrian.hoban@intel.com>
12 * Gabriele Paoloni <gabriele.paoloni@intel.com>
13 * Tadeusz Struk (tadeusz.struk@intel.com)
14 * Copyright (c) 2010, Intel Corporation.
15 *
Herbert Xuda7f0332008-07-31 17:08:25 +080016 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the Free
18 * Software Foundation; either version 2 of the License, or (at your option)
19 * any later version.
20 *
21 */
22
23#include <crypto/hash.h>
24#include <linux/err.h>
25#include <linux/module.h>
26#include <linux/scatterlist.h>
27#include <linux/slab.h>
28#include <linux/string.h>
Jarod Wilson7647d6c2009-05-04 19:44:50 +080029#include <crypto/rng.h>
Stephan Mueller64d1cdf2014-05-31 17:25:36 +020030#include <crypto/drbg.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080031
32#include "internal.h"
Alexander Shishkin0b767f92010-06-03 20:53:43 +100033
Herbert Xu326a6342010-08-06 09:40:28 +080034#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
Alexander Shishkin0b767f92010-06-03 20:53:43 +100035
36/* a perfect nop */
37int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
38{
39 return 0;
40}
41
42#else
43
Herbert Xuda7f0332008-07-31 17:08:25 +080044#include "testmgr.h"
45
46/*
47 * Need slab memory for testing (size in number of pages).
48 */
49#define XBUFSIZE 8
50
51/*
52 * Indexes into the xbuf to simulate cross-page access.
53 */
54#define IDX1 32
55#define IDX2 32400
56#define IDX3 1
57#define IDX4 8193
58#define IDX5 22222
59#define IDX6 17101
60#define IDX7 27333
61#define IDX8 3000
62
63/*
64* Used by test_cipher()
65*/
66#define ENCRYPT 1
67#define DECRYPT 0
68
69struct tcrypt_result {
70 struct completion completion;
71 int err;
72};
73
74struct aead_test_suite {
75 struct {
76 struct aead_testvec *vecs;
77 unsigned int count;
78 } enc, dec;
79};
80
81struct cipher_test_suite {
82 struct {
83 struct cipher_testvec *vecs;
84 unsigned int count;
85 } enc, dec;
86};
87
88struct comp_test_suite {
89 struct {
90 struct comp_testvec *vecs;
91 unsigned int count;
92 } comp, decomp;
93};
94
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +080095struct pcomp_test_suite {
96 struct {
97 struct pcomp_testvec *vecs;
98 unsigned int count;
99 } comp, decomp;
100};
101
Herbert Xuda7f0332008-07-31 17:08:25 +0800102struct hash_test_suite {
103 struct hash_testvec *vecs;
104 unsigned int count;
105};
106
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800107struct cprng_test_suite {
108 struct cprng_testvec *vecs;
109 unsigned int count;
110};
111
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200112struct drbg_test_suite {
113 struct drbg_testvec *vecs;
114 unsigned int count;
115};
116
Herbert Xuda7f0332008-07-31 17:08:25 +0800117struct alg_test_desc {
118 const char *alg;
119 int (*test)(const struct alg_test_desc *desc, const char *driver,
120 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000121 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800122
123 union {
124 struct aead_test_suite aead;
125 struct cipher_test_suite cipher;
126 struct comp_test_suite comp;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +0800127 struct pcomp_test_suite pcomp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800128 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800129 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200130 struct drbg_test_suite drbg;
Herbert Xuda7f0332008-07-31 17:08:25 +0800131 } suite;
132};
133
134static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
135
Herbert Xuda7f0332008-07-31 17:08:25 +0800136static void hexdump(unsigned char *buf, unsigned int len)
137{
138 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
139 16, 1,
140 buf, len, false);
141}
142
143static void tcrypt_complete(struct crypto_async_request *req, int err)
144{
145 struct tcrypt_result *res = req->data;
146
147 if (err == -EINPROGRESS)
148 return;
149
150 res->err = err;
151 complete(&res->completion);
152}
153
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800154static int testmgr_alloc_buf(char *buf[XBUFSIZE])
155{
156 int i;
157
158 for (i = 0; i < XBUFSIZE; i++) {
159 buf[i] = (void *)__get_free_page(GFP_KERNEL);
160 if (!buf[i])
161 goto err_free_buf;
162 }
163
164 return 0;
165
166err_free_buf:
167 while (i-- > 0)
168 free_page((unsigned long)buf[i]);
169
170 return -ENOMEM;
171}
172
173static void testmgr_free_buf(char *buf[XBUFSIZE])
174{
175 int i;
176
177 for (i = 0; i < XBUFSIZE; i++)
178 free_page((unsigned long)buf[i]);
179}
180
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300181static int wait_async_op(struct tcrypt_result *tr, int ret)
David S. Millera8f1a052010-05-19 14:12:03 +1000182{
183 if (ret == -EINPROGRESS || ret == -EBUSY) {
184 ret = wait_for_completion_interruptible(&tr->completion);
185 if (!ret)
186 ret = tr->err;
Wolfram Sang16735d02013-11-14 14:32:02 -0800187 reinit_completion(&tr->completion);
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:
356 ret = wait_for_completion_interruptible(
357 &tresult.completion);
358 if (!ret && !(ret = tresult.err)) {
359 reinit_completion(&tresult.completion);
360 break;
361 }
362 /* fall through */
363 default:
364 printk(KERN_ERR "alg: hash: digest failed "
365 "on chunking test %d for %s: "
366 "ret=%d\n", j, algo, -ret);
367 goto out;
368 }
369
370 if (memcmp(result, template[i].digest,
371 crypto_ahash_digestsize(tfm))) {
372 printk(KERN_ERR "alg: hash: Chunking test %d "
373 "failed for %s\n", j, algo);
374 hexdump(result, crypto_ahash_digestsize(tfm));
375 ret = -EINVAL;
376 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800377 }
378 }
379
380 ret = 0;
381
382out:
383 ahash_request_free(req);
384out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800385 testmgr_free_buf(xbuf);
386out_nobuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300387 kfree(key);
388 kfree(result);
Herbert Xuda7f0332008-07-31 17:08:25 +0800389 return ret;
390}
391
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300392static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
393 unsigned int tcount, bool use_digest)
394{
395 unsigned int alignmask;
396 int ret;
397
398 ret = __test_hash(tfm, template, tcount, use_digest, 0);
399 if (ret)
400 return ret;
401
402 /* test unaligned buffers, check with one byte offset */
403 ret = __test_hash(tfm, template, tcount, use_digest, 1);
404 if (ret)
405 return ret;
406
407 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
408 if (alignmask) {
409 /* Check if alignment mask for tfm is correctly set. */
410 ret = __test_hash(tfm, template, tcount, use_digest,
411 alignmask + 1);
412 if (ret)
413 return ret;
414 }
415
416 return 0;
417}
418
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300419static int __test_aead(struct crypto_aead *tfm, int enc,
420 struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300421 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800422{
423 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
424 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800425 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800426 char *q;
427 char *key;
428 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300429 struct scatterlist *sg;
430 struct scatterlist *asg;
431 struct scatterlist *sgout;
432 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800433 struct tcrypt_result result;
434 unsigned int authsize;
435 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300436 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800437 void *assoc;
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700438 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800439 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300440 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800441 char *axbuf[XBUFSIZE];
442
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700443 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
444 if (!iv)
445 return ret;
Horia Geanta29b77e52014-07-23 11:59:38 +0300446 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
447 if (!key)
448 goto out_noxbuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800449 if (testmgr_alloc_buf(xbuf))
450 goto out_noxbuf;
451 if (testmgr_alloc_buf(axbuf))
452 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300453 if (diff_dst && testmgr_alloc_buf(xoutbuf))
454 goto out_nooutbuf;
455
456 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
457 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL);
458 if (!sg)
459 goto out_nosg;
460 asg = &sg[8];
461 sgout = &asg[8];
462
463 if (diff_dst)
464 d = "-ddst";
465 else
466 d = "";
467
Herbert Xuda7f0332008-07-31 17:08:25 +0800468 if (enc == ENCRYPT)
469 e = "encryption";
470 else
471 e = "decryption";
472
473 init_completion(&result.completion);
474
475 req = aead_request_alloc(tfm, GFP_KERNEL);
476 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300477 pr_err("alg: aead%s: Failed to allocate request for %s\n",
478 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800479 goto out;
480 }
481
482 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
483 tcrypt_complete, &result);
484
485 for (i = 0, j = 0; i < tcount; i++) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300486 if (template[i].np)
487 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800488
Cristian Stoica05b1d332014-07-28 13:11:23 +0300489 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800490
Cristian Stoica05b1d332014-07-28 13:11:23 +0300491 /* some templates have no input data but they will
492 * touch input
493 */
494 input = xbuf[0];
495 input += align_offset;
496 assoc = axbuf[0];
497
498 ret = -EINVAL;
499 if (WARN_ON(align_offset + template[i].ilen >
500 PAGE_SIZE || template[i].alen > PAGE_SIZE))
501 goto out;
502
503 memcpy(input, template[i].input, template[i].ilen);
504 memcpy(assoc, template[i].assoc, template[i].alen);
505 if (template[i].iv)
506 memcpy(iv, template[i].iv, MAX_IVLEN);
507 else
508 memset(iv, 0, MAX_IVLEN);
509
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:
572 ret = wait_for_completion_interruptible(
573 &result.completion);
574 if (!ret && !(ret = result.err)) {
575 reinit_completion(&result.completion);
Herbert Xuda7f0332008-07-31 17:08:25 +0800576 break;
Herbert Xuda7f0332008-07-31 17:08:25 +0800577 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300578 case -EBADMSG:
579 if (template[i].novrfy)
580 /* verification failure was expected */
581 continue;
582 /* fall through */
583 default:
584 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
585 d, e, j, algo, -ret);
586 goto out;
587 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800588
Cristian Stoica05b1d332014-07-28 13:11:23 +0300589 q = output;
590 if (memcmp(q, template[i].result, template[i].rlen)) {
591 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
592 d, j, e, algo);
593 hexdump(q, template[i].rlen);
594 ret = -EINVAL;
595 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800596 }
597 }
598
599 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300600 /* alignment tests are only done with continuous buffers */
601 if (align_offset != 0)
602 break;
603
Cristian Stoica05b1d332014-07-28 13:11:23 +0300604 if (!template[i].np)
605 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800606
Cristian Stoica05b1d332014-07-28 13:11:23 +0300607 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800608
Cristian Stoica05b1d332014-07-28 13:11:23 +0300609 if (template[i].iv)
610 memcpy(iv, template[i].iv, MAX_IVLEN);
611 else
612 memset(iv, 0, MAX_IVLEN);
613
614 crypto_aead_clear_flags(tfm, ~0);
615 if (template[i].wk)
616 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
617 if (template[i].klen > MAX_KEYLEN) {
618 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
619 d, j, algo, template[i].klen, MAX_KEYLEN);
620 ret = -EINVAL;
621 goto out;
622 }
623 memcpy(key, template[i].key, template[i].klen);
624
625 ret = crypto_aead_setkey(tfm, key, template[i].klen);
626 if (!ret == template[i].fail) {
627 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
628 d, j, algo, crypto_aead_get_flags(tfm));
629 goto out;
630 } else if (ret)
631 continue;
632
633 authsize = abs(template[i].rlen - template[i].ilen);
634
635 ret = -EINVAL;
636 sg_init_table(sg, template[i].np);
637 if (diff_dst)
638 sg_init_table(sgout, template[i].np);
639 for (k = 0, temp = 0; k < template[i].np; k++) {
640 if (WARN_ON(offset_in_page(IDX[k]) +
641 template[i].tap[k] > PAGE_SIZE))
642 goto out;
643
644 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
645 memcpy(q, template[i].input + temp, template[i].tap[k]);
646 sg_set_buf(&sg[k], q, template[i].tap[k]);
647
648 if (diff_dst) {
649 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
650 offset_in_page(IDX[k]);
651
652 memset(q, 0, template[i].tap[k]);
653
654 sg_set_buf(&sgout[k], q, template[i].tap[k]);
655 }
656
657 n = template[i].tap[k];
658 if (k == template[i].np - 1 && enc)
659 n += authsize;
660 if (offset_in_page(q) + n < PAGE_SIZE)
661 q[n] = 0;
662
663 temp += template[i].tap[k];
664 }
665
666 ret = crypto_aead_setauthsize(tfm, authsize);
667 if (ret) {
668 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
669 d, authsize, j, algo);
670 goto out;
671 }
672
673 if (enc) {
674 if (WARN_ON(sg[k - 1].offset +
675 sg[k - 1].length + authsize >
676 PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300677 ret = -EINVAL;
678 goto out;
679 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800680
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300681 if (diff_dst)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300682 sgout[k - 1].length += authsize;
683 else
684 sg[k - 1].length += authsize;
685 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800686
Cristian Stoica05b1d332014-07-28 13:11:23 +0300687 sg_init_table(asg, template[i].anp);
688 ret = -EINVAL;
689 for (k = 0, temp = 0; k < template[i].anp; k++) {
690 if (WARN_ON(offset_in_page(IDX[k]) +
691 template[i].atap[k] > PAGE_SIZE))
692 goto out;
693 sg_set_buf(&asg[k],
694 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
695 offset_in_page(IDX[k]),
696 template[i].assoc + temp,
697 template[i].atap[k]),
698 template[i].atap[k]);
699 temp += template[i].atap[k];
700 }
701
702 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
703 template[i].ilen,
704 iv);
705
706 aead_request_set_assoc(req, asg, template[i].alen);
707
708 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
709
710 switch (ret) {
711 case 0:
712 if (template[i].novrfy) {
713 /* verification was supposed to fail */
714 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
715 d, e, j, algo);
716 /* so really, we got a bad message */
717 ret = -EBADMSG;
718 goto out;
719 }
720 break;
721 case -EINPROGRESS:
722 case -EBUSY:
723 ret = wait_for_completion_interruptible(
724 &result.completion);
725 if (!ret && !(ret = result.err)) {
726 reinit_completion(&result.completion);
727 break;
728 }
729 case -EBADMSG:
730 if (template[i].novrfy)
731 /* verification failure was expected */
732 continue;
733 /* fall through */
734 default:
735 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
736 d, e, j, algo, -ret);
737 goto out;
738 }
739
740 ret = -EINVAL;
741 for (k = 0, temp = 0; k < template[i].np; k++) {
742 if (diff_dst)
743 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
744 offset_in_page(IDX[k]);
745 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800746 q = xbuf[IDX[k] >> PAGE_SHIFT] +
747 offset_in_page(IDX[k]);
748
Cristian Stoica05b1d332014-07-28 13:11:23 +0300749 n = template[i].tap[k];
750 if (k == template[i].np - 1)
751 n += enc ? authsize : -authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800752
Cristian Stoica05b1d332014-07-28 13:11:23 +0300753 if (memcmp(q, template[i].result + temp, n)) {
754 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
755 d, j, e, k, algo);
756 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800757 goto out;
758 }
759
Cristian Stoica05b1d332014-07-28 13:11:23 +0300760 q += n;
761 if (k == template[i].np - 1 && !enc) {
762 if (!diff_dst &&
763 memcmp(q, template[i].input +
764 temp + n, authsize))
765 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200766 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300767 n = 0;
768 } else {
769 for (n = 0; offset_in_page(q + n) && q[n]; n++)
770 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800771 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300772 if (n) {
773 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
774 d, j, e, k, algo, n);
775 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800776 goto out;
777 }
778
Cristian Stoica05b1d332014-07-28 13:11:23 +0300779 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800780 }
781 }
782
783 ret = 0;
784
785out:
786 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300787 kfree(sg);
788out_nosg:
789 if (diff_dst)
790 testmgr_free_buf(xoutbuf);
791out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800792 testmgr_free_buf(axbuf);
793out_noaxbuf:
794 testmgr_free_buf(xbuf);
795out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300796 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700797 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800798 return ret;
799}
800
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300801static int test_aead(struct crypto_aead *tfm, int enc,
802 struct aead_testvec *template, unsigned int tcount)
803{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300804 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300805 int ret;
806
807 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300808 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300809 if (ret)
810 return ret;
811
812 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300813 ret = __test_aead(tfm, enc, template, tcount, true, 0);
814 if (ret)
815 return ret;
816
817 /* test unaligned buffers, check with one byte offset */
818 ret = __test_aead(tfm, enc, template, tcount, true, 1);
819 if (ret)
820 return ret;
821
822 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
823 if (alignmask) {
824 /* Check if alignment mask for tfm is correctly set. */
825 ret = __test_aead(tfm, enc, template, tcount, true,
826 alignmask + 1);
827 if (ret)
828 return ret;
829 }
830
831 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300832}
833
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000834static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800835 struct cipher_testvec *template, unsigned int tcount)
836{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000837 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
838 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000839 char *q;
840 const char *e;
841 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800842 char *xbuf[XBUFSIZE];
843 int ret = -ENOMEM;
844
845 if (testmgr_alloc_buf(xbuf))
846 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000847
848 if (enc == ENCRYPT)
849 e = "encryption";
850 else
851 e = "decryption";
852
853 j = 0;
854 for (i = 0; i < tcount; i++) {
855 if (template[i].np)
856 continue;
857
858 j++;
859
Herbert Xufd57f222009-05-29 16:05:42 +1000860 ret = -EINVAL;
861 if (WARN_ON(template[i].ilen > PAGE_SIZE))
862 goto out;
863
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000864 data = xbuf[0];
865 memcpy(data, template[i].input, template[i].ilen);
866
867 crypto_cipher_clear_flags(tfm, ~0);
868 if (template[i].wk)
869 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
870
871 ret = crypto_cipher_setkey(tfm, template[i].key,
872 template[i].klen);
873 if (!ret == template[i].fail) {
874 printk(KERN_ERR "alg: cipher: setkey failed "
875 "on test %d for %s: flags=%x\n", j,
876 algo, crypto_cipher_get_flags(tfm));
877 goto out;
878 } else if (ret)
879 continue;
880
881 for (k = 0; k < template[i].ilen;
882 k += crypto_cipher_blocksize(tfm)) {
883 if (enc)
884 crypto_cipher_encrypt_one(tfm, data + k,
885 data + k);
886 else
887 crypto_cipher_decrypt_one(tfm, data + k,
888 data + k);
889 }
890
891 q = data;
892 if (memcmp(q, template[i].result, template[i].rlen)) {
893 printk(KERN_ERR "alg: cipher: Test %d failed "
894 "on %s for %s\n", j, e, algo);
895 hexdump(q, template[i].rlen);
896 ret = -EINVAL;
897 goto out;
898 }
899 }
900
901 ret = 0;
902
903out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800904 testmgr_free_buf(xbuf);
905out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000906 return ret;
907}
908
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300909static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
910 struct cipher_testvec *template, unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300911 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000912{
Herbert Xuda7f0332008-07-31 17:08:25 +0800913 const char *algo =
914 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
915 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800916 char *q;
917 struct ablkcipher_request *req;
918 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300919 struct scatterlist sgout[8];
920 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800921 struct tcrypt_result result;
922 void *data;
923 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800924 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300925 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800926 int ret = -ENOMEM;
927
928 if (testmgr_alloc_buf(xbuf))
929 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800930
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300931 if (diff_dst && testmgr_alloc_buf(xoutbuf))
932 goto out_nooutbuf;
933
934 if (diff_dst)
935 d = "-ddst";
936 else
937 d = "";
938
Herbert Xuda7f0332008-07-31 17:08:25 +0800939 if (enc == ENCRYPT)
940 e = "encryption";
941 else
942 e = "decryption";
943
944 init_completion(&result.completion);
945
946 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
947 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300948 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
949 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800950 goto out;
951 }
952
953 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
954 tcrypt_complete, &result);
955
956 j = 0;
957 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +0300958 if (template[i].np && !template[i].also_non_np)
959 continue;
960
Herbert Xuda7f0332008-07-31 17:08:25 +0800961 if (template[i].iv)
962 memcpy(iv, template[i].iv, MAX_IVLEN);
963 else
964 memset(iv, 0, MAX_IVLEN);
965
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300966 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300967 ret = -EINVAL;
968 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
969 goto out;
970
971 data = xbuf[0];
972 data += align_offset;
973 memcpy(data, template[i].input, template[i].ilen);
974
975 crypto_ablkcipher_clear_flags(tfm, ~0);
976 if (template[i].wk)
977 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
978
979 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
980 template[i].klen);
981 if (!ret == template[i].fail) {
982 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
983 d, j, algo, crypto_ablkcipher_get_flags(tfm));
984 goto out;
985 } else if (ret)
986 continue;
987
988 sg_init_one(&sg[0], data, template[i].ilen);
989 if (diff_dst) {
990 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300991 data += align_offset;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300992 sg_init_one(&sgout[0], data, template[i].ilen);
993 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800994
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300995 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
996 template[i].ilen, iv);
997 ret = enc ? crypto_ablkcipher_encrypt(req) :
998 crypto_ablkcipher_decrypt(req);
Herbert Xuda7f0332008-07-31 17:08:25 +0800999
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001000 switch (ret) {
1001 case 0:
1002 break;
1003 case -EINPROGRESS:
1004 case -EBUSY:
1005 ret = wait_for_completion_interruptible(
1006 &result.completion);
1007 if (!ret && !((ret = result.err))) {
1008 reinit_completion(&result.completion);
Herbert Xuda7f0332008-07-31 17:08:25 +08001009 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001010 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001011 /* fall through */
1012 default:
1013 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1014 d, e, j, algo, -ret);
1015 goto out;
1016 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001017
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001018 q = data;
1019 if (memcmp(q, template[i].result, template[i].rlen)) {
1020 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1021 d, j, e, algo);
1022 hexdump(q, template[i].rlen);
1023 ret = -EINVAL;
1024 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001025 }
1026 }
1027
1028 j = 0;
1029 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001030 /* alignment tests are only done with continuous buffers */
1031 if (align_offset != 0)
1032 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001033
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001034 if (!template[i].np)
1035 continue;
1036
Herbert Xuda7f0332008-07-31 17:08:25 +08001037 if (template[i].iv)
1038 memcpy(iv, template[i].iv, MAX_IVLEN);
1039 else
1040 memset(iv, 0, MAX_IVLEN);
1041
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001042 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001043 crypto_ablkcipher_clear_flags(tfm, ~0);
1044 if (template[i].wk)
1045 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1046
1047 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1048 template[i].klen);
1049 if (!ret == template[i].fail) {
1050 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1051 d, j, algo, crypto_ablkcipher_get_flags(tfm));
1052 goto out;
1053 } else if (ret)
1054 continue;
1055
1056 temp = 0;
1057 ret = -EINVAL;
1058 sg_init_table(sg, template[i].np);
1059 if (diff_dst)
1060 sg_init_table(sgout, template[i].np);
1061 for (k = 0; k < template[i].np; k++) {
1062 if (WARN_ON(offset_in_page(IDX[k]) +
1063 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001064 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001065
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001066 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1067
1068 memcpy(q, template[i].input + temp, template[i].tap[k]);
1069
1070 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1071 q[template[i].tap[k]] = 0;
1072
1073 sg_set_buf(&sg[k], q, template[i].tap[k]);
1074 if (diff_dst) {
1075 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1076 offset_in_page(IDX[k]);
1077
1078 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1079
1080 memset(q, 0, template[i].tap[k]);
1081 if (offset_in_page(q) +
1082 template[i].tap[k] < PAGE_SIZE)
1083 q[template[i].tap[k]] = 0;
1084 }
1085
1086 temp += template[i].tap[k];
1087 }
1088
1089 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1090 template[i].ilen, iv);
1091
1092 ret = enc ? crypto_ablkcipher_encrypt(req) :
1093 crypto_ablkcipher_decrypt(req);
1094
1095 switch (ret) {
1096 case 0:
1097 break;
1098 case -EINPROGRESS:
1099 case -EBUSY:
1100 ret = wait_for_completion_interruptible(
1101 &result.completion);
1102 if (!ret && !((ret = result.err))) {
1103 reinit_completion(&result.completion);
1104 break;
1105 }
1106 /* fall through */
1107 default:
1108 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1109 d, e, j, algo, -ret);
1110 goto out;
1111 }
1112
1113 temp = 0;
1114 ret = -EINVAL;
1115 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001116 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001117 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1118 offset_in_page(IDX[k]);
1119 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001120 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1121 offset_in_page(IDX[k]);
1122
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001123 if (memcmp(q, template[i].result + temp,
1124 template[i].tap[k])) {
1125 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1126 d, j, e, k, algo);
1127 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001128 goto out;
1129 }
1130
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001131 q += template[i].tap[k];
1132 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1133 ;
1134 if (n) {
1135 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1136 d, j, e, k, algo, n);
1137 hexdump(q, n);
1138 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001139 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001140 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001141 }
1142 }
1143
1144 ret = 0;
1145
1146out:
1147 ablkcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001148 if (diff_dst)
1149 testmgr_free_buf(xoutbuf);
1150out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001151 testmgr_free_buf(xbuf);
1152out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001153 return ret;
1154}
1155
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001156static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1157 struct cipher_testvec *template, unsigned int tcount)
1158{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001159 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001160 int ret;
1161
1162 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001163 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001164 if (ret)
1165 return ret;
1166
1167 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001168 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1169 if (ret)
1170 return ret;
1171
1172 /* test unaligned buffers, check with one byte offset */
1173 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1174 if (ret)
1175 return ret;
1176
1177 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1178 if (alignmask) {
1179 /* Check if alignment mask for tfm is correctly set. */
1180 ret = __test_skcipher(tfm, enc, template, tcount, true,
1181 alignmask + 1);
1182 if (ret)
1183 return ret;
1184 }
1185
1186 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001187}
1188
Herbert Xuda7f0332008-07-31 17:08:25 +08001189static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1190 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1191{
1192 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1193 unsigned int i;
1194 char result[COMP_BUF_SIZE];
1195 int ret;
1196
1197 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001198 int ilen;
1199 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001200
1201 memset(result, 0, sizeof (result));
1202
1203 ilen = ctemplate[i].inlen;
1204 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1205 ilen, result, &dlen);
1206 if (ret) {
1207 printk(KERN_ERR "alg: comp: compression failed "
1208 "on test %d for %s: ret=%d\n", i + 1, algo,
1209 -ret);
1210 goto out;
1211 }
1212
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001213 if (dlen != ctemplate[i].outlen) {
1214 printk(KERN_ERR "alg: comp: Compression test %d "
1215 "failed for %s: output len = %d\n", i + 1, algo,
1216 dlen);
1217 ret = -EINVAL;
1218 goto out;
1219 }
1220
Herbert Xuda7f0332008-07-31 17:08:25 +08001221 if (memcmp(result, ctemplate[i].output, dlen)) {
1222 printk(KERN_ERR "alg: comp: Compression test %d "
1223 "failed for %s\n", i + 1, algo);
1224 hexdump(result, dlen);
1225 ret = -EINVAL;
1226 goto out;
1227 }
1228 }
1229
1230 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001231 int ilen;
1232 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001233
1234 memset(result, 0, sizeof (result));
1235
1236 ilen = dtemplate[i].inlen;
1237 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1238 ilen, result, &dlen);
1239 if (ret) {
1240 printk(KERN_ERR "alg: comp: decompression failed "
1241 "on test %d for %s: ret=%d\n", i + 1, algo,
1242 -ret);
1243 goto out;
1244 }
1245
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001246 if (dlen != dtemplate[i].outlen) {
1247 printk(KERN_ERR "alg: comp: Decompression test %d "
1248 "failed for %s: output len = %d\n", i + 1, algo,
1249 dlen);
1250 ret = -EINVAL;
1251 goto out;
1252 }
1253
Herbert Xuda7f0332008-07-31 17:08:25 +08001254 if (memcmp(result, dtemplate[i].output, dlen)) {
1255 printk(KERN_ERR "alg: comp: Decompression test %d "
1256 "failed for %s\n", i + 1, algo);
1257 hexdump(result, dlen);
1258 ret = -EINVAL;
1259 goto out;
1260 }
1261 }
1262
1263 ret = 0;
1264
1265out:
1266 return ret;
1267}
1268
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001269static int test_pcomp(struct crypto_pcomp *tfm,
1270 struct pcomp_testvec *ctemplate,
1271 struct pcomp_testvec *dtemplate, int ctcount,
1272 int dtcount)
1273{
1274 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1275 unsigned int i;
1276 char result[COMP_BUF_SIZE];
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001277 int res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001278
1279 for (i = 0; i < ctcount; i++) {
1280 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001281 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001282
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001283 res = crypto_compress_setup(tfm, ctemplate[i].params,
1284 ctemplate[i].paramsize);
1285 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001286 pr_err("alg: pcomp: compression setup failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001287 "%d for %s: error=%d\n", i + 1, algo, res);
1288 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001289 }
1290
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001291 res = crypto_compress_init(tfm);
1292 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001293 pr_err("alg: pcomp: compression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001294 "%d for %s: error=%d\n", i + 1, algo, res);
1295 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001296 }
1297
1298 memset(result, 0, sizeof(result));
1299
1300 req.next_in = ctemplate[i].input;
1301 req.avail_in = ctemplate[i].inlen / 2;
1302 req.next_out = result;
1303 req.avail_out = ctemplate[i].outlen / 2;
1304
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001305 res = crypto_compress_update(tfm, &req);
1306 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001307 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001308 "%d for %s: error=%d\n", i + 1, algo, res);
1309 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001310 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001311 if (res > 0)
1312 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001313
1314 /* Add remaining input data */
1315 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1316
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001317 res = crypto_compress_update(tfm, &req);
1318 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001319 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001320 "%d for %s: error=%d\n", i + 1, algo, res);
1321 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001322 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001323 if (res > 0)
1324 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001325
1326 /* Provide remaining output space */
1327 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1328
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001329 res = crypto_compress_final(tfm, &req);
1330 if (res < 0) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001331 pr_err("alg: pcomp: compression final failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001332 "%d for %s: error=%d\n", i + 1, algo, res);
1333 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001334 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001335 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001336
1337 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1338 pr_err("alg: comp: Compression test %d failed for %s: "
1339 "output len = %d (expected %d)\n", i + 1, algo,
1340 COMP_BUF_SIZE - req.avail_out,
1341 ctemplate[i].outlen);
1342 return -EINVAL;
1343 }
1344
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001345 if (produced != ctemplate[i].outlen) {
1346 pr_err("alg: comp: Compression test %d failed for %s: "
1347 "returned len = %u (expected %d)\n", i + 1,
1348 algo, produced, ctemplate[i].outlen);
1349 return -EINVAL;
1350 }
1351
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001352 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1353 pr_err("alg: pcomp: Compression test %d failed for "
1354 "%s\n", i + 1, algo);
1355 hexdump(result, ctemplate[i].outlen);
1356 return -EINVAL;
1357 }
1358 }
1359
1360 for (i = 0; i < dtcount; i++) {
1361 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001362 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001363
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001364 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1365 dtemplate[i].paramsize);
1366 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001367 pr_err("alg: pcomp: decompression setup failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001368 "test %d for %s: error=%d\n", i + 1, algo, res);
1369 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001370 }
1371
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001372 res = crypto_decompress_init(tfm);
1373 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001374 pr_err("alg: pcomp: decompression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001375 "%d for %s: error=%d\n", i + 1, algo, res);
1376 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001377 }
1378
1379 memset(result, 0, sizeof(result));
1380
1381 req.next_in = dtemplate[i].input;
1382 req.avail_in = dtemplate[i].inlen / 2;
1383 req.next_out = result;
1384 req.avail_out = dtemplate[i].outlen / 2;
1385
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001386 res = crypto_decompress_update(tfm, &req);
1387 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001388 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001389 "test %d for %s: error=%d\n", i + 1, algo, res);
1390 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001391 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001392 if (res > 0)
1393 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001394
1395 /* Add remaining input data */
1396 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1397
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001398 res = crypto_decompress_update(tfm, &req);
1399 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001400 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001401 "test %d for %s: error=%d\n", i + 1, algo, res);
1402 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001403 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001404 if (res > 0)
1405 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001406
1407 /* Provide remaining output space */
1408 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1409
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001410 res = crypto_decompress_final(tfm, &req);
1411 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001412 pr_err("alg: pcomp: decompression final failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001413 "test %d for %s: error=%d\n", i + 1, algo, res);
1414 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001415 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001416 if (res > 0)
1417 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001418
1419 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1420 pr_err("alg: comp: Decompression test %d failed for "
1421 "%s: output len = %d (expected %d)\n", i + 1,
1422 algo, COMP_BUF_SIZE - req.avail_out,
1423 dtemplate[i].outlen);
1424 return -EINVAL;
1425 }
1426
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001427 if (produced != dtemplate[i].outlen) {
1428 pr_err("alg: comp: Decompression test %d failed for "
1429 "%s: returned len = %u (expected %d)\n", i + 1,
1430 algo, produced, dtemplate[i].outlen);
1431 return -EINVAL;
1432 }
1433
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001434 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1435 pr_err("alg: pcomp: Decompression test %d failed for "
1436 "%s\n", i + 1, algo);
1437 hexdump(result, dtemplate[i].outlen);
1438 return -EINVAL;
1439 }
1440 }
1441
1442 return 0;
1443}
1444
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001445
1446static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1447 unsigned int tcount)
1448{
1449 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001450 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001451 u8 *seed;
1452 char result[32];
1453
1454 seedsize = crypto_rng_seedsize(tfm);
1455
1456 seed = kmalloc(seedsize, GFP_KERNEL);
1457 if (!seed) {
1458 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1459 "for %s\n", algo);
1460 return -ENOMEM;
1461 }
1462
1463 for (i = 0; i < tcount; i++) {
1464 memset(result, 0, 32);
1465
1466 memcpy(seed, template[i].v, template[i].vlen);
1467 memcpy(seed + template[i].vlen, template[i].key,
1468 template[i].klen);
1469 memcpy(seed + template[i].vlen + template[i].klen,
1470 template[i].dt, template[i].dtlen);
1471
1472 err = crypto_rng_reset(tfm, seed, seedsize);
1473 if (err) {
1474 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1475 "for %s\n", algo);
1476 goto out;
1477 }
1478
1479 for (j = 0; j < template[i].loops; j++) {
1480 err = crypto_rng_get_bytes(tfm, result,
1481 template[i].rlen);
1482 if (err != template[i].rlen) {
1483 printk(KERN_ERR "alg: cprng: Failed to obtain "
1484 "the correct amount of random data for "
1485 "%s (requested %d, got %d)\n", algo,
1486 template[i].rlen, err);
1487 goto out;
1488 }
1489 }
1490
1491 err = memcmp(result, template[i].result,
1492 template[i].rlen);
1493 if (err) {
1494 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1495 i, algo);
1496 hexdump(result, template[i].rlen);
1497 err = -EINVAL;
1498 goto out;
1499 }
1500 }
1501
1502out:
1503 kfree(seed);
1504 return err;
1505}
1506
Herbert Xuda7f0332008-07-31 17:08:25 +08001507static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1508 u32 type, u32 mask)
1509{
1510 struct crypto_aead *tfm;
1511 int err = 0;
1512
1513 tfm = crypto_alloc_aead(driver, type, mask);
1514 if (IS_ERR(tfm)) {
1515 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1516 "%ld\n", driver, PTR_ERR(tfm));
1517 return PTR_ERR(tfm);
1518 }
1519
1520 if (desc->suite.aead.enc.vecs) {
1521 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1522 desc->suite.aead.enc.count);
1523 if (err)
1524 goto out;
1525 }
1526
1527 if (!err && desc->suite.aead.dec.vecs)
1528 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1529 desc->suite.aead.dec.count);
1530
1531out:
1532 crypto_free_aead(tfm);
1533 return err;
1534}
1535
1536static int alg_test_cipher(const struct alg_test_desc *desc,
1537 const char *driver, u32 type, u32 mask)
1538{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001539 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001540 int err = 0;
1541
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001542 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001543 if (IS_ERR(tfm)) {
1544 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1545 "%s: %ld\n", driver, PTR_ERR(tfm));
1546 return PTR_ERR(tfm);
1547 }
1548
1549 if (desc->suite.cipher.enc.vecs) {
1550 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1551 desc->suite.cipher.enc.count);
1552 if (err)
1553 goto out;
1554 }
1555
1556 if (desc->suite.cipher.dec.vecs)
1557 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1558 desc->suite.cipher.dec.count);
1559
1560out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001561 crypto_free_cipher(tfm);
1562 return err;
1563}
1564
1565static int alg_test_skcipher(const struct alg_test_desc *desc,
1566 const char *driver, u32 type, u32 mask)
1567{
1568 struct crypto_ablkcipher *tfm;
1569 int err = 0;
1570
1571 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1572 if (IS_ERR(tfm)) {
1573 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1574 "%s: %ld\n", driver, PTR_ERR(tfm));
1575 return PTR_ERR(tfm);
1576 }
1577
1578 if (desc->suite.cipher.enc.vecs) {
1579 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1580 desc->suite.cipher.enc.count);
1581 if (err)
1582 goto out;
1583 }
1584
1585 if (desc->suite.cipher.dec.vecs)
1586 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1587 desc->suite.cipher.dec.count);
1588
1589out:
Herbert Xuda7f0332008-07-31 17:08:25 +08001590 crypto_free_ablkcipher(tfm);
1591 return err;
1592}
1593
1594static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1595 u32 type, u32 mask)
1596{
1597 struct crypto_comp *tfm;
1598 int err;
1599
1600 tfm = crypto_alloc_comp(driver, type, mask);
1601 if (IS_ERR(tfm)) {
1602 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1603 "%ld\n", driver, PTR_ERR(tfm));
1604 return PTR_ERR(tfm);
1605 }
1606
1607 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1608 desc->suite.comp.decomp.vecs,
1609 desc->suite.comp.comp.count,
1610 desc->suite.comp.decomp.count);
1611
1612 crypto_free_comp(tfm);
1613 return err;
1614}
1615
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001616static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1617 u32 type, u32 mask)
1618{
1619 struct crypto_pcomp *tfm;
1620 int err;
1621
1622 tfm = crypto_alloc_pcomp(driver, type, mask);
1623 if (IS_ERR(tfm)) {
1624 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1625 driver, PTR_ERR(tfm));
1626 return PTR_ERR(tfm);
1627 }
1628
1629 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1630 desc->suite.pcomp.decomp.vecs,
1631 desc->suite.pcomp.comp.count,
1632 desc->suite.pcomp.decomp.count);
1633
1634 crypto_free_pcomp(tfm);
1635 return err;
1636}
1637
Herbert Xuda7f0332008-07-31 17:08:25 +08001638static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1639 u32 type, u32 mask)
1640{
1641 struct crypto_ahash *tfm;
1642 int err;
1643
1644 tfm = crypto_alloc_ahash(driver, type, mask);
1645 if (IS_ERR(tfm)) {
1646 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1647 "%ld\n", driver, PTR_ERR(tfm));
1648 return PTR_ERR(tfm);
1649 }
1650
David S. Millera8f1a052010-05-19 14:12:03 +10001651 err = test_hash(tfm, desc->suite.hash.vecs,
1652 desc->suite.hash.count, true);
1653 if (!err)
1654 err = test_hash(tfm, desc->suite.hash.vecs,
1655 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001656
1657 crypto_free_ahash(tfm);
1658 return err;
1659}
1660
Herbert Xu8e3ee852008-11-07 14:58:52 +08001661static int alg_test_crc32c(const struct alg_test_desc *desc,
1662 const char *driver, u32 type, u32 mask)
1663{
1664 struct crypto_shash *tfm;
1665 u32 val;
1666 int err;
1667
1668 err = alg_test_hash(desc, driver, type, mask);
1669 if (err)
1670 goto out;
1671
1672 tfm = crypto_alloc_shash(driver, type, mask);
1673 if (IS_ERR(tfm)) {
1674 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1675 "%ld\n", driver, PTR_ERR(tfm));
1676 err = PTR_ERR(tfm);
1677 goto out;
1678 }
1679
1680 do {
1681 struct {
1682 struct shash_desc shash;
1683 char ctx[crypto_shash_descsize(tfm)];
1684 } sdesc;
1685
1686 sdesc.shash.tfm = tfm;
1687 sdesc.shash.flags = 0;
1688
1689 *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1690 err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1691 if (err) {
1692 printk(KERN_ERR "alg: crc32c: Operation failed for "
1693 "%s: %d\n", driver, err);
1694 break;
1695 }
1696
1697 if (val != ~420553207) {
1698 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1699 "%d\n", driver, val);
1700 err = -EINVAL;
1701 }
1702 } while (0);
1703
1704 crypto_free_shash(tfm);
1705
1706out:
1707 return err;
1708}
1709
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001710static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1711 u32 type, u32 mask)
1712{
1713 struct crypto_rng *rng;
1714 int err;
1715
1716 rng = crypto_alloc_rng(driver, type, mask);
1717 if (IS_ERR(rng)) {
1718 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1719 "%ld\n", driver, PTR_ERR(rng));
1720 return PTR_ERR(rng);
1721 }
1722
1723 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1724
1725 crypto_free_rng(rng);
1726
1727 return err;
1728}
1729
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001730
1731static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1732 const char *driver, u32 type, u32 mask)
1733{
1734 int ret = -EAGAIN;
1735 struct crypto_rng *drng;
1736 struct drbg_test_data test_data;
1737 struct drbg_string addtl, pers, testentropy;
1738 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1739
1740 if (!buf)
1741 return -ENOMEM;
1742
1743 drng = crypto_alloc_rng(driver, type, mask);
1744 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001745 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001746 "%s\n", driver);
1747 kzfree(buf);
1748 return -ENOMEM;
1749 }
1750
1751 test_data.testentropy = &testentropy;
1752 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1753 drbg_string_fill(&pers, test->pers, test->perslen);
1754 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1755 if (ret) {
1756 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1757 goto outbuf;
1758 }
1759
1760 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1761 if (pr) {
1762 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1763 ret = crypto_drbg_get_bytes_addtl_test(drng,
1764 buf, test->expectedlen, &addtl, &test_data);
1765 } else {
1766 ret = crypto_drbg_get_bytes_addtl(drng,
1767 buf, test->expectedlen, &addtl);
1768 }
1769 if (ret <= 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001770 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001771 "driver %s\n", driver);
1772 goto outbuf;
1773 }
1774
1775 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1776 if (pr) {
1777 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1778 ret = crypto_drbg_get_bytes_addtl_test(drng,
1779 buf, test->expectedlen, &addtl, &test_data);
1780 } else {
1781 ret = crypto_drbg_get_bytes_addtl(drng,
1782 buf, test->expectedlen, &addtl);
1783 }
1784 if (ret <= 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001785 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001786 "driver %s\n", driver);
1787 goto outbuf;
1788 }
1789
1790 ret = memcmp(test->expected, buf, test->expectedlen);
1791
1792outbuf:
1793 crypto_free_rng(drng);
1794 kzfree(buf);
1795 return ret;
1796}
1797
1798
1799static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1800 u32 type, u32 mask)
1801{
1802 int err = 0;
1803 int pr = 0;
1804 int i = 0;
1805 struct drbg_testvec *template = desc->suite.drbg.vecs;
1806 unsigned int tcount = desc->suite.drbg.count;
1807
1808 if (0 == memcmp(driver, "drbg_pr_", 8))
1809 pr = 1;
1810
1811 for (i = 0; i < tcount; i++) {
1812 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1813 if (err) {
1814 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1815 i, driver);
1816 err = -EINVAL;
1817 break;
1818 }
1819 }
1820 return err;
1821
1822}
1823
Youquan, Song863b5572009-12-23 19:45:20 +08001824static int alg_test_null(const struct alg_test_desc *desc,
1825 const char *driver, u32 type, u32 mask)
1826{
1827 return 0;
1828}
1829
Herbert Xuda7f0332008-07-31 17:08:25 +08001830/* Please keep this list sorted by algorithm name. */
1831static const struct alg_test_desc alg_test_descs[] = {
1832 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001833 .alg = "__cbc-cast5-avx",
1834 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001835 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001836 .alg = "__cbc-cast6-avx",
1837 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001838 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001839 .alg = "__cbc-serpent-avx",
1840 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001841 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001842 .alg = "__cbc-serpent-avx2",
1843 .test = alg_test_null,
1844 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001845 .alg = "__cbc-serpent-sse2",
1846 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001847 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001848 .alg = "__cbc-twofish-avx",
1849 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001850 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001851 .alg = "__driver-cbc-aes-aesni",
1852 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001853 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001854 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001855 .alg = "__driver-cbc-camellia-aesni",
1856 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001857 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001858 .alg = "__driver-cbc-camellia-aesni-avx2",
1859 .test = alg_test_null,
1860 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001861 .alg = "__driver-cbc-cast5-avx",
1862 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001863 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001864 .alg = "__driver-cbc-cast6-avx",
1865 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001866 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001867 .alg = "__driver-cbc-serpent-avx",
1868 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001869 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001870 .alg = "__driver-cbc-serpent-avx2",
1871 .test = alg_test_null,
1872 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001873 .alg = "__driver-cbc-serpent-sse2",
1874 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001875 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001876 .alg = "__driver-cbc-twofish-avx",
1877 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001878 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001879 .alg = "__driver-ecb-aes-aesni",
1880 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001881 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001882 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001883 .alg = "__driver-ecb-camellia-aesni",
1884 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001885 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001886 .alg = "__driver-ecb-camellia-aesni-avx2",
1887 .test = alg_test_null,
1888 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001889 .alg = "__driver-ecb-cast5-avx",
1890 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001891 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001892 .alg = "__driver-ecb-cast6-avx",
1893 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001894 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001895 .alg = "__driver-ecb-serpent-avx",
1896 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001897 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001898 .alg = "__driver-ecb-serpent-avx2",
1899 .test = alg_test_null,
1900 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001901 .alg = "__driver-ecb-serpent-sse2",
1902 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001903 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001904 .alg = "__driver-ecb-twofish-avx",
1905 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001906 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001907 .alg = "__ghash-pclmulqdqni",
1908 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001909 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001910 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001911 .alg = "ansi_cprng",
1912 .test = alg_test_cprng,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001913 .fips_allowed = 1,
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001914 .suite = {
1915 .cprng = {
1916 .vecs = ansi_cprng_aes_tv_template,
1917 .count = ANSI_CPRNG_AES_TEST_VECTORS
1918 }
1919 }
1920 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001921 .alg = "authenc(hmac(md5),ecb(cipher_null))",
1922 .test = alg_test_aead,
1923 .fips_allowed = 1,
1924 .suite = {
1925 .aead = {
1926 .enc = {
1927 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
1928 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1929 },
1930 .dec = {
1931 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
1932 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1933 }
1934 }
1935 }
1936 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03001937 .alg = "authenc(hmac(sha1),cbc(aes))",
1938 .test = alg_test_aead,
1939 .fips_allowed = 1,
1940 .suite = {
1941 .aead = {
1942 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301943 .vecs =
1944 hmac_sha1_aes_cbc_enc_tv_temp,
1945 .count =
1946 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1947 }
1948 }
1949 }
1950 }, {
1951 .alg = "authenc(hmac(sha1),cbc(des))",
1952 .test = alg_test_aead,
1953 .fips_allowed = 1,
1954 .suite = {
1955 .aead = {
1956 .enc = {
1957 .vecs =
1958 hmac_sha1_des_cbc_enc_tv_temp,
1959 .count =
1960 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1961 }
1962 }
1963 }
1964 }, {
1965 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
1966 .test = alg_test_aead,
1967 .fips_allowed = 1,
1968 .suite = {
1969 .aead = {
1970 .enc = {
1971 .vecs =
1972 hmac_sha1_des3_ede_cbc_enc_tv_temp,
1973 .count =
1974 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03001975 }
1976 }
1977 }
1978 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001979 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
1980 .test = alg_test_aead,
1981 .fips_allowed = 1,
1982 .suite = {
1983 .aead = {
1984 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301985 .vecs =
1986 hmac_sha1_ecb_cipher_null_enc_tv_temp,
1987 .count =
1988 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02001989 },
1990 .dec = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301991 .vecs =
1992 hmac_sha1_ecb_cipher_null_dec_tv_temp,
1993 .count =
1994 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
1995 }
1996 }
1997 }
1998 }, {
1999 .alg = "authenc(hmac(sha224),cbc(des))",
2000 .test = alg_test_aead,
2001 .fips_allowed = 1,
2002 .suite = {
2003 .aead = {
2004 .enc = {
2005 .vecs =
2006 hmac_sha224_des_cbc_enc_tv_temp,
2007 .count =
2008 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2009 }
2010 }
2011 }
2012 }, {
2013 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
2014 .test = alg_test_aead,
2015 .fips_allowed = 1,
2016 .suite = {
2017 .aead = {
2018 .enc = {
2019 .vecs =
2020 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2021 .count =
2022 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002023 }
2024 }
2025 }
2026 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03002027 .alg = "authenc(hmac(sha256),cbc(aes))",
2028 .test = alg_test_aead,
2029 .fips_allowed = 1,
2030 .suite = {
2031 .aead = {
2032 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302033 .vecs =
2034 hmac_sha256_aes_cbc_enc_tv_temp,
2035 .count =
2036 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2037 }
2038 }
2039 }
2040 }, {
2041 .alg = "authenc(hmac(sha256),cbc(des))",
2042 .test = alg_test_aead,
2043 .fips_allowed = 1,
2044 .suite = {
2045 .aead = {
2046 .enc = {
2047 .vecs =
2048 hmac_sha256_des_cbc_enc_tv_temp,
2049 .count =
2050 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2051 }
2052 }
2053 }
2054 }, {
2055 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
2056 .test = alg_test_aead,
2057 .fips_allowed = 1,
2058 .suite = {
2059 .aead = {
2060 .enc = {
2061 .vecs =
2062 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2063 .count =
2064 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2065 }
2066 }
2067 }
2068 }, {
2069 .alg = "authenc(hmac(sha384),cbc(des))",
2070 .test = alg_test_aead,
2071 .fips_allowed = 1,
2072 .suite = {
2073 .aead = {
2074 .enc = {
2075 .vecs =
2076 hmac_sha384_des_cbc_enc_tv_temp,
2077 .count =
2078 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2079 }
2080 }
2081 }
2082 }, {
2083 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
2084 .test = alg_test_aead,
2085 .fips_allowed = 1,
2086 .suite = {
2087 .aead = {
2088 .enc = {
2089 .vecs =
2090 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2091 .count =
2092 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002093 }
2094 }
2095 }
2096 }, {
2097 .alg = "authenc(hmac(sha512),cbc(aes))",
2098 .test = alg_test_aead,
2099 .fips_allowed = 1,
2100 .suite = {
2101 .aead = {
2102 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302103 .vecs =
2104 hmac_sha512_aes_cbc_enc_tv_temp,
2105 .count =
2106 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2107 }
2108 }
2109 }
2110 }, {
2111 .alg = "authenc(hmac(sha512),cbc(des))",
2112 .test = alg_test_aead,
2113 .fips_allowed = 1,
2114 .suite = {
2115 .aead = {
2116 .enc = {
2117 .vecs =
2118 hmac_sha512_des_cbc_enc_tv_temp,
2119 .count =
2120 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2121 }
2122 }
2123 }
2124 }, {
2125 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2126 .test = alg_test_aead,
2127 .fips_allowed = 1,
2128 .suite = {
2129 .aead = {
2130 .enc = {
2131 .vecs =
2132 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2133 .count =
2134 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002135 }
2136 }
2137 }
2138 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002139 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002140 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002141 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002142 .suite = {
2143 .cipher = {
2144 .enc = {
2145 .vecs = aes_cbc_enc_tv_template,
2146 .count = AES_CBC_ENC_TEST_VECTORS
2147 },
2148 .dec = {
2149 .vecs = aes_cbc_dec_tv_template,
2150 .count = AES_CBC_DEC_TEST_VECTORS
2151 }
2152 }
2153 }
2154 }, {
2155 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002156 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002157 .suite = {
2158 .cipher = {
2159 .enc = {
2160 .vecs = anubis_cbc_enc_tv_template,
2161 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2162 },
2163 .dec = {
2164 .vecs = anubis_cbc_dec_tv_template,
2165 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2166 }
2167 }
2168 }
2169 }, {
2170 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002171 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002172 .suite = {
2173 .cipher = {
2174 .enc = {
2175 .vecs = bf_cbc_enc_tv_template,
2176 .count = BF_CBC_ENC_TEST_VECTORS
2177 },
2178 .dec = {
2179 .vecs = bf_cbc_dec_tv_template,
2180 .count = BF_CBC_DEC_TEST_VECTORS
2181 }
2182 }
2183 }
2184 }, {
2185 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002186 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002187 .suite = {
2188 .cipher = {
2189 .enc = {
2190 .vecs = camellia_cbc_enc_tv_template,
2191 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2192 },
2193 .dec = {
2194 .vecs = camellia_cbc_dec_tv_template,
2195 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2196 }
2197 }
2198 }
2199 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002200 .alg = "cbc(cast5)",
2201 .test = alg_test_skcipher,
2202 .suite = {
2203 .cipher = {
2204 .enc = {
2205 .vecs = cast5_cbc_enc_tv_template,
2206 .count = CAST5_CBC_ENC_TEST_VECTORS
2207 },
2208 .dec = {
2209 .vecs = cast5_cbc_dec_tv_template,
2210 .count = CAST5_CBC_DEC_TEST_VECTORS
2211 }
2212 }
2213 }
2214 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002215 .alg = "cbc(cast6)",
2216 .test = alg_test_skcipher,
2217 .suite = {
2218 .cipher = {
2219 .enc = {
2220 .vecs = cast6_cbc_enc_tv_template,
2221 .count = CAST6_CBC_ENC_TEST_VECTORS
2222 },
2223 .dec = {
2224 .vecs = cast6_cbc_dec_tv_template,
2225 .count = CAST6_CBC_DEC_TEST_VECTORS
2226 }
2227 }
2228 }
2229 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002230 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002231 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002232 .suite = {
2233 .cipher = {
2234 .enc = {
2235 .vecs = des_cbc_enc_tv_template,
2236 .count = DES_CBC_ENC_TEST_VECTORS
2237 },
2238 .dec = {
2239 .vecs = des_cbc_dec_tv_template,
2240 .count = DES_CBC_DEC_TEST_VECTORS
2241 }
2242 }
2243 }
2244 }, {
2245 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002246 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002247 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002248 .suite = {
2249 .cipher = {
2250 .enc = {
2251 .vecs = des3_ede_cbc_enc_tv_template,
2252 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2253 },
2254 .dec = {
2255 .vecs = des3_ede_cbc_dec_tv_template,
2256 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2257 }
2258 }
2259 }
2260 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002261 .alg = "cbc(serpent)",
2262 .test = alg_test_skcipher,
2263 .suite = {
2264 .cipher = {
2265 .enc = {
2266 .vecs = serpent_cbc_enc_tv_template,
2267 .count = SERPENT_CBC_ENC_TEST_VECTORS
2268 },
2269 .dec = {
2270 .vecs = serpent_cbc_dec_tv_template,
2271 .count = SERPENT_CBC_DEC_TEST_VECTORS
2272 }
2273 }
2274 }
2275 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002276 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002277 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002278 .suite = {
2279 .cipher = {
2280 .enc = {
2281 .vecs = tf_cbc_enc_tv_template,
2282 .count = TF_CBC_ENC_TEST_VECTORS
2283 },
2284 .dec = {
2285 .vecs = tf_cbc_dec_tv_template,
2286 .count = TF_CBC_DEC_TEST_VECTORS
2287 }
2288 }
2289 }
2290 }, {
2291 .alg = "ccm(aes)",
2292 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002293 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002294 .suite = {
2295 .aead = {
2296 .enc = {
2297 .vecs = aes_ccm_enc_tv_template,
2298 .count = AES_CCM_ENC_TEST_VECTORS
2299 },
2300 .dec = {
2301 .vecs = aes_ccm_dec_tv_template,
2302 .count = AES_CCM_DEC_TEST_VECTORS
2303 }
2304 }
2305 }
2306 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002307 .alg = "cmac(aes)",
2308 .test = alg_test_hash,
2309 .suite = {
2310 .hash = {
2311 .vecs = aes_cmac128_tv_template,
2312 .count = CMAC_AES_TEST_VECTORS
2313 }
2314 }
2315 }, {
2316 .alg = "cmac(des3_ede)",
2317 .test = alg_test_hash,
2318 .suite = {
2319 .hash = {
2320 .vecs = des3_ede_cmac64_tv_template,
2321 .count = CMAC_DES3_EDE_TEST_VECTORS
2322 }
2323 }
2324 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002325 .alg = "compress_null",
2326 .test = alg_test_null,
2327 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002328 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002329 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002330 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002331 .suite = {
2332 .hash = {
2333 .vecs = crc32c_tv_template,
2334 .count = CRC32C_TEST_VECTORS
2335 }
2336 }
2337 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002338 .alg = "crct10dif",
2339 .test = alg_test_hash,
2340 .fips_allowed = 1,
2341 .suite = {
2342 .hash = {
2343 .vecs = crct10dif_tv_template,
2344 .count = CRCT10DIF_TEST_VECTORS
2345 }
2346 }
2347 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002348 .alg = "cryptd(__driver-cbc-aes-aesni)",
2349 .test = alg_test_null,
2350 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002351 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002352 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2353 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002354 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002355 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2356 .test = alg_test_null,
2357 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002358 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2359 .test = alg_test_null,
2360 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002361 .alg = "cryptd(__driver-ecb-aes-aesni)",
2362 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002363 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002364 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002365 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2366 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002367 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002368 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2369 .test = alg_test_null,
2370 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002371 .alg = "cryptd(__driver-ecb-cast5-avx)",
2372 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002373 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002374 .alg = "cryptd(__driver-ecb-cast6-avx)",
2375 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002376 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002377 .alg = "cryptd(__driver-ecb-serpent-avx)",
2378 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002379 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002380 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2381 .test = alg_test_null,
2382 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002383 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2384 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002385 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002386 .alg = "cryptd(__driver-ecb-twofish-avx)",
2387 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002388 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002389 .alg = "cryptd(__driver-gcm-aes-aesni)",
2390 .test = alg_test_null,
2391 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002392 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002393 .alg = "cryptd(__ghash-pclmulqdqni)",
2394 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002395 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002396 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002397 .alg = "ctr(aes)",
2398 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002399 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002400 .suite = {
2401 .cipher = {
2402 .enc = {
2403 .vecs = aes_ctr_enc_tv_template,
2404 .count = AES_CTR_ENC_TEST_VECTORS
2405 },
2406 .dec = {
2407 .vecs = aes_ctr_dec_tv_template,
2408 .count = AES_CTR_DEC_TEST_VECTORS
2409 }
2410 }
2411 }
2412 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002413 .alg = "ctr(blowfish)",
2414 .test = alg_test_skcipher,
2415 .suite = {
2416 .cipher = {
2417 .enc = {
2418 .vecs = bf_ctr_enc_tv_template,
2419 .count = BF_CTR_ENC_TEST_VECTORS
2420 },
2421 .dec = {
2422 .vecs = bf_ctr_dec_tv_template,
2423 .count = BF_CTR_DEC_TEST_VECTORS
2424 }
2425 }
2426 }
2427 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002428 .alg = "ctr(camellia)",
2429 .test = alg_test_skcipher,
2430 .suite = {
2431 .cipher = {
2432 .enc = {
2433 .vecs = camellia_ctr_enc_tv_template,
2434 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2435 },
2436 .dec = {
2437 .vecs = camellia_ctr_dec_tv_template,
2438 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2439 }
2440 }
2441 }
2442 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002443 .alg = "ctr(cast5)",
2444 .test = alg_test_skcipher,
2445 .suite = {
2446 .cipher = {
2447 .enc = {
2448 .vecs = cast5_ctr_enc_tv_template,
2449 .count = CAST5_CTR_ENC_TEST_VECTORS
2450 },
2451 .dec = {
2452 .vecs = cast5_ctr_dec_tv_template,
2453 .count = CAST5_CTR_DEC_TEST_VECTORS
2454 }
2455 }
2456 }
2457 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002458 .alg = "ctr(cast6)",
2459 .test = alg_test_skcipher,
2460 .suite = {
2461 .cipher = {
2462 .enc = {
2463 .vecs = cast6_ctr_enc_tv_template,
2464 .count = CAST6_CTR_ENC_TEST_VECTORS
2465 },
2466 .dec = {
2467 .vecs = cast6_ctr_dec_tv_template,
2468 .count = CAST6_CTR_DEC_TEST_VECTORS
2469 }
2470 }
2471 }
2472 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002473 .alg = "ctr(des)",
2474 .test = alg_test_skcipher,
2475 .suite = {
2476 .cipher = {
2477 .enc = {
2478 .vecs = des_ctr_enc_tv_template,
2479 .count = DES_CTR_ENC_TEST_VECTORS
2480 },
2481 .dec = {
2482 .vecs = des_ctr_dec_tv_template,
2483 .count = DES_CTR_DEC_TEST_VECTORS
2484 }
2485 }
2486 }
2487 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002488 .alg = "ctr(des3_ede)",
2489 .test = alg_test_skcipher,
2490 .suite = {
2491 .cipher = {
2492 .enc = {
2493 .vecs = des3_ede_ctr_enc_tv_template,
2494 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2495 },
2496 .dec = {
2497 .vecs = des3_ede_ctr_dec_tv_template,
2498 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2499 }
2500 }
2501 }
2502 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002503 .alg = "ctr(serpent)",
2504 .test = alg_test_skcipher,
2505 .suite = {
2506 .cipher = {
2507 .enc = {
2508 .vecs = serpent_ctr_enc_tv_template,
2509 .count = SERPENT_CTR_ENC_TEST_VECTORS
2510 },
2511 .dec = {
2512 .vecs = serpent_ctr_dec_tv_template,
2513 .count = SERPENT_CTR_DEC_TEST_VECTORS
2514 }
2515 }
2516 }
2517 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002518 .alg = "ctr(twofish)",
2519 .test = alg_test_skcipher,
2520 .suite = {
2521 .cipher = {
2522 .enc = {
2523 .vecs = tf_ctr_enc_tv_template,
2524 .count = TF_CTR_ENC_TEST_VECTORS
2525 },
2526 .dec = {
2527 .vecs = tf_ctr_dec_tv_template,
2528 .count = TF_CTR_DEC_TEST_VECTORS
2529 }
2530 }
2531 }
2532 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002533 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002534 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002535 .suite = {
2536 .cipher = {
2537 .enc = {
2538 .vecs = cts_mode_enc_tv_template,
2539 .count = CTS_MODE_ENC_TEST_VECTORS
2540 },
2541 .dec = {
2542 .vecs = cts_mode_dec_tv_template,
2543 .count = CTS_MODE_DEC_TEST_VECTORS
2544 }
2545 }
2546 }
2547 }, {
2548 .alg = "deflate",
2549 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002550 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002551 .suite = {
2552 .comp = {
2553 .comp = {
2554 .vecs = deflate_comp_tv_template,
2555 .count = DEFLATE_COMP_TEST_VECTORS
2556 },
2557 .decomp = {
2558 .vecs = deflate_decomp_tv_template,
2559 .count = DEFLATE_DECOMP_TEST_VECTORS
2560 }
2561 }
2562 }
2563 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002564 .alg = "digest_null",
2565 .test = alg_test_null,
2566 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002567 .alg = "drbg_nopr_ctr_aes128",
2568 .test = alg_test_drbg,
2569 .fips_allowed = 1,
2570 .suite = {
2571 .drbg = {
2572 .vecs = drbg_nopr_ctr_aes128_tv_template,
2573 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2574 }
2575 }
2576 }, {
2577 .alg = "drbg_nopr_ctr_aes192",
2578 .test = alg_test_drbg,
2579 .fips_allowed = 1,
2580 .suite = {
2581 .drbg = {
2582 .vecs = drbg_nopr_ctr_aes192_tv_template,
2583 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2584 }
2585 }
2586 }, {
2587 .alg = "drbg_nopr_ctr_aes256",
2588 .test = alg_test_drbg,
2589 .fips_allowed = 1,
2590 .suite = {
2591 .drbg = {
2592 .vecs = drbg_nopr_ctr_aes256_tv_template,
2593 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2594 }
2595 }
2596 }, {
2597 /*
2598 * There is no need to specifically test the DRBG with every
2599 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2600 */
2601 .alg = "drbg_nopr_hmac_sha1",
2602 .fips_allowed = 1,
2603 .test = alg_test_null,
2604 }, {
2605 .alg = "drbg_nopr_hmac_sha256",
2606 .test = alg_test_drbg,
2607 .fips_allowed = 1,
2608 .suite = {
2609 .drbg = {
2610 .vecs = drbg_nopr_hmac_sha256_tv_template,
2611 .count =
2612 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2613 }
2614 }
2615 }, {
2616 /* covered by drbg_nopr_hmac_sha256 test */
2617 .alg = "drbg_nopr_hmac_sha384",
2618 .fips_allowed = 1,
2619 .test = alg_test_null,
2620 }, {
2621 .alg = "drbg_nopr_hmac_sha512",
2622 .test = alg_test_null,
2623 .fips_allowed = 1,
2624 }, {
2625 .alg = "drbg_nopr_sha1",
2626 .fips_allowed = 1,
2627 .test = alg_test_null,
2628 }, {
2629 .alg = "drbg_nopr_sha256",
2630 .test = alg_test_drbg,
2631 .fips_allowed = 1,
2632 .suite = {
2633 .drbg = {
2634 .vecs = drbg_nopr_sha256_tv_template,
2635 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2636 }
2637 }
2638 }, {
2639 /* covered by drbg_nopr_sha256 test */
2640 .alg = "drbg_nopr_sha384",
2641 .fips_allowed = 1,
2642 .test = alg_test_null,
2643 }, {
2644 .alg = "drbg_nopr_sha512",
2645 .fips_allowed = 1,
2646 .test = alg_test_null,
2647 }, {
2648 .alg = "drbg_pr_ctr_aes128",
2649 .test = alg_test_drbg,
2650 .fips_allowed = 1,
2651 .suite = {
2652 .drbg = {
2653 .vecs = drbg_pr_ctr_aes128_tv_template,
2654 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2655 }
2656 }
2657 }, {
2658 /* covered by drbg_pr_ctr_aes128 test */
2659 .alg = "drbg_pr_ctr_aes192",
2660 .fips_allowed = 1,
2661 .test = alg_test_null,
2662 }, {
2663 .alg = "drbg_pr_ctr_aes256",
2664 .fips_allowed = 1,
2665 .test = alg_test_null,
2666 }, {
2667 .alg = "drbg_pr_hmac_sha1",
2668 .fips_allowed = 1,
2669 .test = alg_test_null,
2670 }, {
2671 .alg = "drbg_pr_hmac_sha256",
2672 .test = alg_test_drbg,
2673 .fips_allowed = 1,
2674 .suite = {
2675 .drbg = {
2676 .vecs = drbg_pr_hmac_sha256_tv_template,
2677 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2678 }
2679 }
2680 }, {
2681 /* covered by drbg_pr_hmac_sha256 test */
2682 .alg = "drbg_pr_hmac_sha384",
2683 .fips_allowed = 1,
2684 .test = alg_test_null,
2685 }, {
2686 .alg = "drbg_pr_hmac_sha512",
2687 .test = alg_test_null,
2688 .fips_allowed = 1,
2689 }, {
2690 .alg = "drbg_pr_sha1",
2691 .fips_allowed = 1,
2692 .test = alg_test_null,
2693 }, {
2694 .alg = "drbg_pr_sha256",
2695 .test = alg_test_drbg,
2696 .fips_allowed = 1,
2697 .suite = {
2698 .drbg = {
2699 .vecs = drbg_pr_sha256_tv_template,
2700 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2701 }
2702 }
2703 }, {
2704 /* covered by drbg_pr_sha256 test */
2705 .alg = "drbg_pr_sha384",
2706 .fips_allowed = 1,
2707 .test = alg_test_null,
2708 }, {
2709 .alg = "drbg_pr_sha512",
2710 .fips_allowed = 1,
2711 .test = alg_test_null,
2712 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002713 .alg = "ecb(__aes-aesni)",
2714 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002715 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002716 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002717 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002718 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002719 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002720 .suite = {
2721 .cipher = {
2722 .enc = {
2723 .vecs = aes_enc_tv_template,
2724 .count = AES_ENC_TEST_VECTORS
2725 },
2726 .dec = {
2727 .vecs = aes_dec_tv_template,
2728 .count = AES_DEC_TEST_VECTORS
2729 }
2730 }
2731 }
2732 }, {
2733 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002734 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002735 .suite = {
2736 .cipher = {
2737 .enc = {
2738 .vecs = anubis_enc_tv_template,
2739 .count = ANUBIS_ENC_TEST_VECTORS
2740 },
2741 .dec = {
2742 .vecs = anubis_dec_tv_template,
2743 .count = ANUBIS_DEC_TEST_VECTORS
2744 }
2745 }
2746 }
2747 }, {
2748 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002749 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002750 .suite = {
2751 .cipher = {
2752 .enc = {
2753 .vecs = arc4_enc_tv_template,
2754 .count = ARC4_ENC_TEST_VECTORS
2755 },
2756 .dec = {
2757 .vecs = arc4_dec_tv_template,
2758 .count = ARC4_DEC_TEST_VECTORS
2759 }
2760 }
2761 }
2762 }, {
2763 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002764 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002765 .suite = {
2766 .cipher = {
2767 .enc = {
2768 .vecs = bf_enc_tv_template,
2769 .count = BF_ENC_TEST_VECTORS
2770 },
2771 .dec = {
2772 .vecs = bf_dec_tv_template,
2773 .count = BF_DEC_TEST_VECTORS
2774 }
2775 }
2776 }
2777 }, {
2778 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002779 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002780 .suite = {
2781 .cipher = {
2782 .enc = {
2783 .vecs = camellia_enc_tv_template,
2784 .count = CAMELLIA_ENC_TEST_VECTORS
2785 },
2786 .dec = {
2787 .vecs = camellia_dec_tv_template,
2788 .count = CAMELLIA_DEC_TEST_VECTORS
2789 }
2790 }
2791 }
2792 }, {
2793 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002794 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002795 .suite = {
2796 .cipher = {
2797 .enc = {
2798 .vecs = cast5_enc_tv_template,
2799 .count = CAST5_ENC_TEST_VECTORS
2800 },
2801 .dec = {
2802 .vecs = cast5_dec_tv_template,
2803 .count = CAST5_DEC_TEST_VECTORS
2804 }
2805 }
2806 }
2807 }, {
2808 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002809 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002810 .suite = {
2811 .cipher = {
2812 .enc = {
2813 .vecs = cast6_enc_tv_template,
2814 .count = CAST6_ENC_TEST_VECTORS
2815 },
2816 .dec = {
2817 .vecs = cast6_dec_tv_template,
2818 .count = CAST6_DEC_TEST_VECTORS
2819 }
2820 }
2821 }
2822 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002823 .alg = "ecb(cipher_null)",
2824 .test = alg_test_null,
2825 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002826 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002827 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002828 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002829 .suite = {
2830 .cipher = {
2831 .enc = {
2832 .vecs = des_enc_tv_template,
2833 .count = DES_ENC_TEST_VECTORS
2834 },
2835 .dec = {
2836 .vecs = des_dec_tv_template,
2837 .count = DES_DEC_TEST_VECTORS
2838 }
2839 }
2840 }
2841 }, {
2842 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002843 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002844 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002845 .suite = {
2846 .cipher = {
2847 .enc = {
2848 .vecs = des3_ede_enc_tv_template,
2849 .count = DES3_EDE_ENC_TEST_VECTORS
2850 },
2851 .dec = {
2852 .vecs = des3_ede_dec_tv_template,
2853 .count = DES3_EDE_DEC_TEST_VECTORS
2854 }
2855 }
2856 }
2857 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002858 .alg = "ecb(fcrypt)",
2859 .test = alg_test_skcipher,
2860 .suite = {
2861 .cipher = {
2862 .enc = {
2863 .vecs = fcrypt_pcbc_enc_tv_template,
2864 .count = 1
2865 },
2866 .dec = {
2867 .vecs = fcrypt_pcbc_dec_tv_template,
2868 .count = 1
2869 }
2870 }
2871 }
2872 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002873 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002874 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002875 .suite = {
2876 .cipher = {
2877 .enc = {
2878 .vecs = khazad_enc_tv_template,
2879 .count = KHAZAD_ENC_TEST_VECTORS
2880 },
2881 .dec = {
2882 .vecs = khazad_dec_tv_template,
2883 .count = KHAZAD_DEC_TEST_VECTORS
2884 }
2885 }
2886 }
2887 }, {
2888 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002889 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002890 .suite = {
2891 .cipher = {
2892 .enc = {
2893 .vecs = seed_enc_tv_template,
2894 .count = SEED_ENC_TEST_VECTORS
2895 },
2896 .dec = {
2897 .vecs = seed_dec_tv_template,
2898 .count = SEED_DEC_TEST_VECTORS
2899 }
2900 }
2901 }
2902 }, {
2903 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002904 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002905 .suite = {
2906 .cipher = {
2907 .enc = {
2908 .vecs = serpent_enc_tv_template,
2909 .count = SERPENT_ENC_TEST_VECTORS
2910 },
2911 .dec = {
2912 .vecs = serpent_dec_tv_template,
2913 .count = SERPENT_DEC_TEST_VECTORS
2914 }
2915 }
2916 }
2917 }, {
2918 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002919 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002920 .suite = {
2921 .cipher = {
2922 .enc = {
2923 .vecs = tea_enc_tv_template,
2924 .count = TEA_ENC_TEST_VECTORS
2925 },
2926 .dec = {
2927 .vecs = tea_dec_tv_template,
2928 .count = TEA_DEC_TEST_VECTORS
2929 }
2930 }
2931 }
2932 }, {
2933 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002934 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002935 .suite = {
2936 .cipher = {
2937 .enc = {
2938 .vecs = tnepres_enc_tv_template,
2939 .count = TNEPRES_ENC_TEST_VECTORS
2940 },
2941 .dec = {
2942 .vecs = tnepres_dec_tv_template,
2943 .count = TNEPRES_DEC_TEST_VECTORS
2944 }
2945 }
2946 }
2947 }, {
2948 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002949 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002950 .suite = {
2951 .cipher = {
2952 .enc = {
2953 .vecs = tf_enc_tv_template,
2954 .count = TF_ENC_TEST_VECTORS
2955 },
2956 .dec = {
2957 .vecs = tf_dec_tv_template,
2958 .count = TF_DEC_TEST_VECTORS
2959 }
2960 }
2961 }
2962 }, {
2963 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002964 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002965 .suite = {
2966 .cipher = {
2967 .enc = {
2968 .vecs = xeta_enc_tv_template,
2969 .count = XETA_ENC_TEST_VECTORS
2970 },
2971 .dec = {
2972 .vecs = xeta_dec_tv_template,
2973 .count = XETA_DEC_TEST_VECTORS
2974 }
2975 }
2976 }
2977 }, {
2978 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002979 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002980 .suite = {
2981 .cipher = {
2982 .enc = {
2983 .vecs = xtea_enc_tv_template,
2984 .count = XTEA_ENC_TEST_VECTORS
2985 },
2986 .dec = {
2987 .vecs = xtea_dec_tv_template,
2988 .count = XTEA_DEC_TEST_VECTORS
2989 }
2990 }
2991 }
2992 }, {
2993 .alg = "gcm(aes)",
2994 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002995 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002996 .suite = {
2997 .aead = {
2998 .enc = {
2999 .vecs = aes_gcm_enc_tv_template,
3000 .count = AES_GCM_ENC_TEST_VECTORS
3001 },
3002 .dec = {
3003 .vecs = aes_gcm_dec_tv_template,
3004 .count = AES_GCM_DEC_TEST_VECTORS
3005 }
3006 }
3007 }
3008 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003009 .alg = "ghash",
3010 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003011 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003012 .suite = {
3013 .hash = {
3014 .vecs = ghash_tv_template,
3015 .count = GHASH_TEST_VECTORS
3016 }
3017 }
3018 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003019 .alg = "hmac(crc32)",
3020 .test = alg_test_hash,
3021 .suite = {
3022 .hash = {
3023 .vecs = bfin_crc_tv_template,
3024 .count = BFIN_CRC_TEST_VECTORS
3025 }
3026 }
3027 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003028 .alg = "hmac(md5)",
3029 .test = alg_test_hash,
3030 .suite = {
3031 .hash = {
3032 .vecs = hmac_md5_tv_template,
3033 .count = HMAC_MD5_TEST_VECTORS
3034 }
3035 }
3036 }, {
3037 .alg = "hmac(rmd128)",
3038 .test = alg_test_hash,
3039 .suite = {
3040 .hash = {
3041 .vecs = hmac_rmd128_tv_template,
3042 .count = HMAC_RMD128_TEST_VECTORS
3043 }
3044 }
3045 }, {
3046 .alg = "hmac(rmd160)",
3047 .test = alg_test_hash,
3048 .suite = {
3049 .hash = {
3050 .vecs = hmac_rmd160_tv_template,
3051 .count = HMAC_RMD160_TEST_VECTORS
3052 }
3053 }
3054 }, {
3055 .alg = "hmac(sha1)",
3056 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003057 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003058 .suite = {
3059 .hash = {
3060 .vecs = hmac_sha1_tv_template,
3061 .count = HMAC_SHA1_TEST_VECTORS
3062 }
3063 }
3064 }, {
3065 .alg = "hmac(sha224)",
3066 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003067 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003068 .suite = {
3069 .hash = {
3070 .vecs = hmac_sha224_tv_template,
3071 .count = HMAC_SHA224_TEST_VECTORS
3072 }
3073 }
3074 }, {
3075 .alg = "hmac(sha256)",
3076 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003077 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003078 .suite = {
3079 .hash = {
3080 .vecs = hmac_sha256_tv_template,
3081 .count = HMAC_SHA256_TEST_VECTORS
3082 }
3083 }
3084 }, {
3085 .alg = "hmac(sha384)",
3086 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003087 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003088 .suite = {
3089 .hash = {
3090 .vecs = hmac_sha384_tv_template,
3091 .count = HMAC_SHA384_TEST_VECTORS
3092 }
3093 }
3094 }, {
3095 .alg = "hmac(sha512)",
3096 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003097 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003098 .suite = {
3099 .hash = {
3100 .vecs = hmac_sha512_tv_template,
3101 .count = HMAC_SHA512_TEST_VECTORS
3102 }
3103 }
3104 }, {
3105 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003106 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003107 .suite = {
3108 .cipher = {
3109 .enc = {
3110 .vecs = aes_lrw_enc_tv_template,
3111 .count = AES_LRW_ENC_TEST_VECTORS
3112 },
3113 .dec = {
3114 .vecs = aes_lrw_dec_tv_template,
3115 .count = AES_LRW_DEC_TEST_VECTORS
3116 }
3117 }
3118 }
3119 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003120 .alg = "lrw(camellia)",
3121 .test = alg_test_skcipher,
3122 .suite = {
3123 .cipher = {
3124 .enc = {
3125 .vecs = camellia_lrw_enc_tv_template,
3126 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3127 },
3128 .dec = {
3129 .vecs = camellia_lrw_dec_tv_template,
3130 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3131 }
3132 }
3133 }
3134 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003135 .alg = "lrw(cast6)",
3136 .test = alg_test_skcipher,
3137 .suite = {
3138 .cipher = {
3139 .enc = {
3140 .vecs = cast6_lrw_enc_tv_template,
3141 .count = CAST6_LRW_ENC_TEST_VECTORS
3142 },
3143 .dec = {
3144 .vecs = cast6_lrw_dec_tv_template,
3145 .count = CAST6_LRW_DEC_TEST_VECTORS
3146 }
3147 }
3148 }
3149 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003150 .alg = "lrw(serpent)",
3151 .test = alg_test_skcipher,
3152 .suite = {
3153 .cipher = {
3154 .enc = {
3155 .vecs = serpent_lrw_enc_tv_template,
3156 .count = SERPENT_LRW_ENC_TEST_VECTORS
3157 },
3158 .dec = {
3159 .vecs = serpent_lrw_dec_tv_template,
3160 .count = SERPENT_LRW_DEC_TEST_VECTORS
3161 }
3162 }
3163 }
3164 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003165 .alg = "lrw(twofish)",
3166 .test = alg_test_skcipher,
3167 .suite = {
3168 .cipher = {
3169 .enc = {
3170 .vecs = tf_lrw_enc_tv_template,
3171 .count = TF_LRW_ENC_TEST_VECTORS
3172 },
3173 .dec = {
3174 .vecs = tf_lrw_dec_tv_template,
3175 .count = TF_LRW_DEC_TEST_VECTORS
3176 }
3177 }
3178 }
3179 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003180 .alg = "lz4",
3181 .test = alg_test_comp,
3182 .fips_allowed = 1,
3183 .suite = {
3184 .comp = {
3185 .comp = {
3186 .vecs = lz4_comp_tv_template,
3187 .count = LZ4_COMP_TEST_VECTORS
3188 },
3189 .decomp = {
3190 .vecs = lz4_decomp_tv_template,
3191 .count = LZ4_DECOMP_TEST_VECTORS
3192 }
3193 }
3194 }
3195 }, {
3196 .alg = "lz4hc",
3197 .test = alg_test_comp,
3198 .fips_allowed = 1,
3199 .suite = {
3200 .comp = {
3201 .comp = {
3202 .vecs = lz4hc_comp_tv_template,
3203 .count = LZ4HC_COMP_TEST_VECTORS
3204 },
3205 .decomp = {
3206 .vecs = lz4hc_decomp_tv_template,
3207 .count = LZ4HC_DECOMP_TEST_VECTORS
3208 }
3209 }
3210 }
3211 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003212 .alg = "lzo",
3213 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003214 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003215 .suite = {
3216 .comp = {
3217 .comp = {
3218 .vecs = lzo_comp_tv_template,
3219 .count = LZO_COMP_TEST_VECTORS
3220 },
3221 .decomp = {
3222 .vecs = lzo_decomp_tv_template,
3223 .count = LZO_DECOMP_TEST_VECTORS
3224 }
3225 }
3226 }
3227 }, {
3228 .alg = "md4",
3229 .test = alg_test_hash,
3230 .suite = {
3231 .hash = {
3232 .vecs = md4_tv_template,
3233 .count = MD4_TEST_VECTORS
3234 }
3235 }
3236 }, {
3237 .alg = "md5",
3238 .test = alg_test_hash,
3239 .suite = {
3240 .hash = {
3241 .vecs = md5_tv_template,
3242 .count = MD5_TEST_VECTORS
3243 }
3244 }
3245 }, {
3246 .alg = "michael_mic",
3247 .test = alg_test_hash,
3248 .suite = {
3249 .hash = {
3250 .vecs = michael_mic_tv_template,
3251 .count = MICHAEL_MIC_TEST_VECTORS
3252 }
3253 }
3254 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003255 .alg = "ofb(aes)",
3256 .test = alg_test_skcipher,
3257 .fips_allowed = 1,
3258 .suite = {
3259 .cipher = {
3260 .enc = {
3261 .vecs = aes_ofb_enc_tv_template,
3262 .count = AES_OFB_ENC_TEST_VECTORS
3263 },
3264 .dec = {
3265 .vecs = aes_ofb_dec_tv_template,
3266 .count = AES_OFB_DEC_TEST_VECTORS
3267 }
3268 }
3269 }
3270 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003271 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003272 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003273 .suite = {
3274 .cipher = {
3275 .enc = {
3276 .vecs = fcrypt_pcbc_enc_tv_template,
3277 .count = FCRYPT_ENC_TEST_VECTORS
3278 },
3279 .dec = {
3280 .vecs = fcrypt_pcbc_dec_tv_template,
3281 .count = FCRYPT_DEC_TEST_VECTORS
3282 }
3283 }
3284 }
3285 }, {
3286 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003287 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003288 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003289 .suite = {
3290 .cipher = {
3291 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003292 .vecs = aes_ctr_rfc3686_enc_tv_template,
3293 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003294 },
3295 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003296 .vecs = aes_ctr_rfc3686_dec_tv_template,
3297 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003298 }
3299 }
3300 }
3301 }, {
Adrian Hoban69435b92010-11-04 15:02:04 -04003302 .alg = "rfc4106(gcm(aes))",
3303 .test = alg_test_aead,
3304 .suite = {
3305 .aead = {
3306 .enc = {
3307 .vecs = aes_gcm_rfc4106_enc_tv_template,
3308 .count = AES_GCM_4106_ENC_TEST_VECTORS
3309 },
3310 .dec = {
3311 .vecs = aes_gcm_rfc4106_dec_tv_template,
3312 .count = AES_GCM_4106_DEC_TEST_VECTORS
3313 }
3314 }
3315 }
3316 }, {
Jarod Wilson5d667322009-05-04 19:23:40 +08003317 .alg = "rfc4309(ccm(aes))",
3318 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003319 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003320 .suite = {
3321 .aead = {
3322 .enc = {
3323 .vecs = aes_ccm_rfc4309_enc_tv_template,
3324 .count = AES_CCM_4309_ENC_TEST_VECTORS
3325 },
3326 .dec = {
3327 .vecs = aes_ccm_rfc4309_dec_tv_template,
3328 .count = AES_CCM_4309_DEC_TEST_VECTORS
3329 }
3330 }
3331 }
3332 }, {
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003333 .alg = "rfc4543(gcm(aes))",
3334 .test = alg_test_aead,
3335 .suite = {
3336 .aead = {
3337 .enc = {
3338 .vecs = aes_gcm_rfc4543_enc_tv_template,
3339 .count = AES_GCM_4543_ENC_TEST_VECTORS
3340 },
3341 .dec = {
3342 .vecs = aes_gcm_rfc4543_dec_tv_template,
3343 .count = AES_GCM_4543_DEC_TEST_VECTORS
3344 },
3345 }
3346 }
3347 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003348 .alg = "rmd128",
3349 .test = alg_test_hash,
3350 .suite = {
3351 .hash = {
3352 .vecs = rmd128_tv_template,
3353 .count = RMD128_TEST_VECTORS
3354 }
3355 }
3356 }, {
3357 .alg = "rmd160",
3358 .test = alg_test_hash,
3359 .suite = {
3360 .hash = {
3361 .vecs = rmd160_tv_template,
3362 .count = RMD160_TEST_VECTORS
3363 }
3364 }
3365 }, {
3366 .alg = "rmd256",
3367 .test = alg_test_hash,
3368 .suite = {
3369 .hash = {
3370 .vecs = rmd256_tv_template,
3371 .count = RMD256_TEST_VECTORS
3372 }
3373 }
3374 }, {
3375 .alg = "rmd320",
3376 .test = alg_test_hash,
3377 .suite = {
3378 .hash = {
3379 .vecs = rmd320_tv_template,
3380 .count = RMD320_TEST_VECTORS
3381 }
3382 }
3383 }, {
3384 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003385 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003386 .suite = {
3387 .cipher = {
3388 .enc = {
3389 .vecs = salsa20_stream_enc_tv_template,
3390 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3391 }
3392 }
3393 }
3394 }, {
3395 .alg = "sha1",
3396 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003397 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003398 .suite = {
3399 .hash = {
3400 .vecs = sha1_tv_template,
3401 .count = SHA1_TEST_VECTORS
3402 }
3403 }
3404 }, {
3405 .alg = "sha224",
3406 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003407 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003408 .suite = {
3409 .hash = {
3410 .vecs = sha224_tv_template,
3411 .count = SHA224_TEST_VECTORS
3412 }
3413 }
3414 }, {
3415 .alg = "sha256",
3416 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003417 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003418 .suite = {
3419 .hash = {
3420 .vecs = sha256_tv_template,
3421 .count = SHA256_TEST_VECTORS
3422 }
3423 }
3424 }, {
3425 .alg = "sha384",
3426 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003427 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003428 .suite = {
3429 .hash = {
3430 .vecs = sha384_tv_template,
3431 .count = SHA384_TEST_VECTORS
3432 }
3433 }
3434 }, {
3435 .alg = "sha512",
3436 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003437 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003438 .suite = {
3439 .hash = {
3440 .vecs = sha512_tv_template,
3441 .count = SHA512_TEST_VECTORS
3442 }
3443 }
3444 }, {
3445 .alg = "tgr128",
3446 .test = alg_test_hash,
3447 .suite = {
3448 .hash = {
3449 .vecs = tgr128_tv_template,
3450 .count = TGR128_TEST_VECTORS
3451 }
3452 }
3453 }, {
3454 .alg = "tgr160",
3455 .test = alg_test_hash,
3456 .suite = {
3457 .hash = {
3458 .vecs = tgr160_tv_template,
3459 .count = TGR160_TEST_VECTORS
3460 }
3461 }
3462 }, {
3463 .alg = "tgr192",
3464 .test = alg_test_hash,
3465 .suite = {
3466 .hash = {
3467 .vecs = tgr192_tv_template,
3468 .count = TGR192_TEST_VECTORS
3469 }
3470 }
3471 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003472 .alg = "vmac(aes)",
3473 .test = alg_test_hash,
3474 .suite = {
3475 .hash = {
3476 .vecs = aes_vmac128_tv_template,
3477 .count = VMAC_AES_TEST_VECTORS
3478 }
3479 }
3480 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003481 .alg = "wp256",
3482 .test = alg_test_hash,
3483 .suite = {
3484 .hash = {
3485 .vecs = wp256_tv_template,
3486 .count = WP256_TEST_VECTORS
3487 }
3488 }
3489 }, {
3490 .alg = "wp384",
3491 .test = alg_test_hash,
3492 .suite = {
3493 .hash = {
3494 .vecs = wp384_tv_template,
3495 .count = WP384_TEST_VECTORS
3496 }
3497 }
3498 }, {
3499 .alg = "wp512",
3500 .test = alg_test_hash,
3501 .suite = {
3502 .hash = {
3503 .vecs = wp512_tv_template,
3504 .count = WP512_TEST_VECTORS
3505 }
3506 }
3507 }, {
3508 .alg = "xcbc(aes)",
3509 .test = alg_test_hash,
3510 .suite = {
3511 .hash = {
3512 .vecs = aes_xcbc128_tv_template,
3513 .count = XCBC_AES_TEST_VECTORS
3514 }
3515 }
3516 }, {
3517 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003518 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003519 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003520 .suite = {
3521 .cipher = {
3522 .enc = {
3523 .vecs = aes_xts_enc_tv_template,
3524 .count = AES_XTS_ENC_TEST_VECTORS
3525 },
3526 .dec = {
3527 .vecs = aes_xts_dec_tv_template,
3528 .count = AES_XTS_DEC_TEST_VECTORS
3529 }
3530 }
3531 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003532 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003533 .alg = "xts(camellia)",
3534 .test = alg_test_skcipher,
3535 .suite = {
3536 .cipher = {
3537 .enc = {
3538 .vecs = camellia_xts_enc_tv_template,
3539 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3540 },
3541 .dec = {
3542 .vecs = camellia_xts_dec_tv_template,
3543 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3544 }
3545 }
3546 }
3547 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003548 .alg = "xts(cast6)",
3549 .test = alg_test_skcipher,
3550 .suite = {
3551 .cipher = {
3552 .enc = {
3553 .vecs = cast6_xts_enc_tv_template,
3554 .count = CAST6_XTS_ENC_TEST_VECTORS
3555 },
3556 .dec = {
3557 .vecs = cast6_xts_dec_tv_template,
3558 .count = CAST6_XTS_DEC_TEST_VECTORS
3559 }
3560 }
3561 }
3562 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003563 .alg = "xts(serpent)",
3564 .test = alg_test_skcipher,
3565 .suite = {
3566 .cipher = {
3567 .enc = {
3568 .vecs = serpent_xts_enc_tv_template,
3569 .count = SERPENT_XTS_ENC_TEST_VECTORS
3570 },
3571 .dec = {
3572 .vecs = serpent_xts_dec_tv_template,
3573 .count = SERPENT_XTS_DEC_TEST_VECTORS
3574 }
3575 }
3576 }
3577 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003578 .alg = "xts(twofish)",
3579 .test = alg_test_skcipher,
3580 .suite = {
3581 .cipher = {
3582 .enc = {
3583 .vecs = tf_xts_enc_tv_template,
3584 .count = TF_XTS_ENC_TEST_VECTORS
3585 },
3586 .dec = {
3587 .vecs = tf_xts_dec_tv_template,
3588 .count = TF_XTS_DEC_TEST_VECTORS
3589 }
3590 }
3591 }
3592 }, {
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003593 .alg = "zlib",
3594 .test = alg_test_pcomp,
Milan Broz08189042012-12-06 17:16:28 +08003595 .fips_allowed = 1,
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003596 .suite = {
3597 .pcomp = {
3598 .comp = {
3599 .vecs = zlib_comp_tv_template,
3600 .count = ZLIB_COMP_TEST_VECTORS
3601 },
3602 .decomp = {
3603 .vecs = zlib_decomp_tv_template,
3604 .count = ZLIB_DECOMP_TEST_VECTORS
3605 }
3606 }
3607 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003608 }
3609};
3610
Jussi Kivilinna57147582013-06-13 17:37:40 +03003611static bool alg_test_descs_checked;
3612
3613static void alg_test_descs_check_order(void)
3614{
3615 int i;
3616
3617 /* only check once */
3618 if (alg_test_descs_checked)
3619 return;
3620
3621 alg_test_descs_checked = true;
3622
3623 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3624 int diff = strcmp(alg_test_descs[i - 1].alg,
3625 alg_test_descs[i].alg);
3626
3627 if (WARN_ON(diff > 0)) {
3628 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3629 alg_test_descs[i - 1].alg,
3630 alg_test_descs[i].alg);
3631 }
3632
3633 if (WARN_ON(diff == 0)) {
3634 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3635 alg_test_descs[i].alg);
3636 }
3637 }
3638}
3639
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003640static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003641{
3642 int start = 0;
3643 int end = ARRAY_SIZE(alg_test_descs);
3644
3645 while (start < end) {
3646 int i = (start + end) / 2;
3647 int diff = strcmp(alg_test_descs[i].alg, alg);
3648
3649 if (diff > 0) {
3650 end = i;
3651 continue;
3652 }
3653
3654 if (diff < 0) {
3655 start = i + 1;
3656 continue;
3657 }
3658
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003659 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003660 }
3661
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003662 return -1;
3663}
3664
3665int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3666{
3667 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003668 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003669 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003670
Jussi Kivilinna57147582013-06-13 17:37:40 +03003671 alg_test_descs_check_order();
3672
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003673 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3674 char nalg[CRYPTO_MAX_ALG_NAME];
3675
3676 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3677 sizeof(nalg))
3678 return -ENAMETOOLONG;
3679
3680 i = alg_find_test(nalg);
3681 if (i < 0)
3682 goto notest;
3683
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003684 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3685 goto non_fips_alg;
3686
Jarod Wilson941fb322009-05-04 19:49:23 +08003687 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3688 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003689 }
3690
3691 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003692 j = alg_find_test(driver);
3693 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003694 goto notest;
3695
Herbert Xua68f6612009-07-02 16:32:12 +08003696 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3697 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003698 goto non_fips_alg;
3699
Herbert Xua68f6612009-07-02 16:32:12 +08003700 rc = 0;
3701 if (i >= 0)
3702 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3703 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003704 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003705 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3706 type, mask);
3707
Jarod Wilson941fb322009-05-04 19:49:23 +08003708test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003709 if (fips_enabled && rc)
3710 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3711
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003712 if (fips_enabled && !rc)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303713 pr_info(KERN_INFO "alg: self-tests for %s (%s) passed\n",
3714 driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003715
Neil Hormand12d6b62008-10-12 20:36:51 +08003716 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003717
3718notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003719 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3720 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003721non_fips_alg:
3722 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003723}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003724
Herbert Xu326a6342010-08-06 09:40:28 +08003725#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003726
Herbert Xuda7f0332008-07-31 17:08:25 +08003727EXPORT_SYMBOL_GPL(alg_test);