blob: 037368d34586706e69275e1319f4514ad32d05a4 [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 {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001681 SHASH_DESC_ON_STACK(shash, tfm);
1682 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001683
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001684 shash->tfm = tfm;
1685 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001686
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001687 *ctx = le32_to_cpu(420553207);
1688 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001689 if (err) {
1690 printk(KERN_ERR "alg: crc32c: Operation failed for "
1691 "%s: %d\n", driver, err);
1692 break;
1693 }
1694
1695 if (val != ~420553207) {
1696 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1697 "%d\n", driver, val);
1698 err = -EINVAL;
1699 }
1700 } while (0);
1701
1702 crypto_free_shash(tfm);
1703
1704out:
1705 return err;
1706}
1707
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001708static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1709 u32 type, u32 mask)
1710{
1711 struct crypto_rng *rng;
1712 int err;
1713
1714 rng = crypto_alloc_rng(driver, type, mask);
1715 if (IS_ERR(rng)) {
1716 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1717 "%ld\n", driver, PTR_ERR(rng));
1718 return PTR_ERR(rng);
1719 }
1720
1721 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1722
1723 crypto_free_rng(rng);
1724
1725 return err;
1726}
1727
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001728
1729static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1730 const char *driver, u32 type, u32 mask)
1731{
1732 int ret = -EAGAIN;
1733 struct crypto_rng *drng;
1734 struct drbg_test_data test_data;
1735 struct drbg_string addtl, pers, testentropy;
1736 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1737
1738 if (!buf)
1739 return -ENOMEM;
1740
1741 drng = crypto_alloc_rng(driver, type, mask);
1742 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001743 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001744 "%s\n", driver);
1745 kzfree(buf);
1746 return -ENOMEM;
1747 }
1748
1749 test_data.testentropy = &testentropy;
1750 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1751 drbg_string_fill(&pers, test->pers, test->perslen);
1752 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1753 if (ret) {
1754 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1755 goto outbuf;
1756 }
1757
1758 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1759 if (pr) {
1760 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1761 ret = crypto_drbg_get_bytes_addtl_test(drng,
1762 buf, test->expectedlen, &addtl, &test_data);
1763 } else {
1764 ret = crypto_drbg_get_bytes_addtl(drng,
1765 buf, test->expectedlen, &addtl);
1766 }
1767 if (ret <= 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001768 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001769 "driver %s\n", driver);
1770 goto outbuf;
1771 }
1772
1773 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1774 if (pr) {
1775 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1776 ret = crypto_drbg_get_bytes_addtl_test(drng,
1777 buf, test->expectedlen, &addtl, &test_data);
1778 } else {
1779 ret = crypto_drbg_get_bytes_addtl(drng,
1780 buf, test->expectedlen, &addtl);
1781 }
1782 if (ret <= 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001783 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001784 "driver %s\n", driver);
1785 goto outbuf;
1786 }
1787
1788 ret = memcmp(test->expected, buf, test->expectedlen);
1789
1790outbuf:
1791 crypto_free_rng(drng);
1792 kzfree(buf);
1793 return ret;
1794}
1795
1796
1797static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1798 u32 type, u32 mask)
1799{
1800 int err = 0;
1801 int pr = 0;
1802 int i = 0;
1803 struct drbg_testvec *template = desc->suite.drbg.vecs;
1804 unsigned int tcount = desc->suite.drbg.count;
1805
1806 if (0 == memcmp(driver, "drbg_pr_", 8))
1807 pr = 1;
1808
1809 for (i = 0; i < tcount; i++) {
1810 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1811 if (err) {
1812 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1813 i, driver);
1814 err = -EINVAL;
1815 break;
1816 }
1817 }
1818 return err;
1819
1820}
1821
Youquan, Song863b5572009-12-23 19:45:20 +08001822static int alg_test_null(const struct alg_test_desc *desc,
1823 const char *driver, u32 type, u32 mask)
1824{
1825 return 0;
1826}
1827
Herbert Xuda7f0332008-07-31 17:08:25 +08001828/* Please keep this list sorted by algorithm name. */
1829static const struct alg_test_desc alg_test_descs[] = {
1830 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001831 .alg = "__cbc-cast5-avx",
1832 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001833 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001834 .alg = "__cbc-cast6-avx",
1835 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001836 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001837 .alg = "__cbc-serpent-avx",
1838 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001839 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001840 .alg = "__cbc-serpent-avx2",
1841 .test = alg_test_null,
1842 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001843 .alg = "__cbc-serpent-sse2",
1844 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001845 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001846 .alg = "__cbc-twofish-avx",
1847 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001848 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001849 .alg = "__driver-cbc-aes-aesni",
1850 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001851 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001852 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001853 .alg = "__driver-cbc-camellia-aesni",
1854 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001855 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001856 .alg = "__driver-cbc-camellia-aesni-avx2",
1857 .test = alg_test_null,
1858 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001859 .alg = "__driver-cbc-cast5-avx",
1860 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001861 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001862 .alg = "__driver-cbc-cast6-avx",
1863 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001864 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001865 .alg = "__driver-cbc-serpent-avx",
1866 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001867 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001868 .alg = "__driver-cbc-serpent-avx2",
1869 .test = alg_test_null,
1870 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001871 .alg = "__driver-cbc-serpent-sse2",
1872 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001873 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001874 .alg = "__driver-cbc-twofish-avx",
1875 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001876 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001877 .alg = "__driver-ecb-aes-aesni",
1878 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001879 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001880 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001881 .alg = "__driver-ecb-camellia-aesni",
1882 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001883 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001884 .alg = "__driver-ecb-camellia-aesni-avx2",
1885 .test = alg_test_null,
1886 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001887 .alg = "__driver-ecb-cast5-avx",
1888 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001889 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001890 .alg = "__driver-ecb-cast6-avx",
1891 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001892 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001893 .alg = "__driver-ecb-serpent-avx",
1894 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001895 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001896 .alg = "__driver-ecb-serpent-avx2",
1897 .test = alg_test_null,
1898 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001899 .alg = "__driver-ecb-serpent-sse2",
1900 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001901 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001902 .alg = "__driver-ecb-twofish-avx",
1903 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001904 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001905 .alg = "__ghash-pclmulqdqni",
1906 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001907 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001908 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001909 .alg = "ansi_cprng",
1910 .test = alg_test_cprng,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001911 .fips_allowed = 1,
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001912 .suite = {
1913 .cprng = {
1914 .vecs = ansi_cprng_aes_tv_template,
1915 .count = ANSI_CPRNG_AES_TEST_VECTORS
1916 }
1917 }
1918 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001919 .alg = "authenc(hmac(md5),ecb(cipher_null))",
1920 .test = alg_test_aead,
1921 .fips_allowed = 1,
1922 .suite = {
1923 .aead = {
1924 .enc = {
1925 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
1926 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1927 },
1928 .dec = {
1929 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
1930 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1931 }
1932 }
1933 }
1934 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03001935 .alg = "authenc(hmac(sha1),cbc(aes))",
1936 .test = alg_test_aead,
1937 .fips_allowed = 1,
1938 .suite = {
1939 .aead = {
1940 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301941 .vecs =
1942 hmac_sha1_aes_cbc_enc_tv_temp,
1943 .count =
1944 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1945 }
1946 }
1947 }
1948 }, {
1949 .alg = "authenc(hmac(sha1),cbc(des))",
1950 .test = alg_test_aead,
1951 .fips_allowed = 1,
1952 .suite = {
1953 .aead = {
1954 .enc = {
1955 .vecs =
1956 hmac_sha1_des_cbc_enc_tv_temp,
1957 .count =
1958 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1959 }
1960 }
1961 }
1962 }, {
1963 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
1964 .test = alg_test_aead,
1965 .fips_allowed = 1,
1966 .suite = {
1967 .aead = {
1968 .enc = {
1969 .vecs =
1970 hmac_sha1_des3_ede_cbc_enc_tv_temp,
1971 .count =
1972 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03001973 }
1974 }
1975 }
1976 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001977 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
1978 .test = alg_test_aead,
1979 .fips_allowed = 1,
1980 .suite = {
1981 .aead = {
1982 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301983 .vecs =
1984 hmac_sha1_ecb_cipher_null_enc_tv_temp,
1985 .count =
1986 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02001987 },
1988 .dec = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301989 .vecs =
1990 hmac_sha1_ecb_cipher_null_dec_tv_temp,
1991 .count =
1992 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
1993 }
1994 }
1995 }
1996 }, {
1997 .alg = "authenc(hmac(sha224),cbc(des))",
1998 .test = alg_test_aead,
1999 .fips_allowed = 1,
2000 .suite = {
2001 .aead = {
2002 .enc = {
2003 .vecs =
2004 hmac_sha224_des_cbc_enc_tv_temp,
2005 .count =
2006 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2007 }
2008 }
2009 }
2010 }, {
2011 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
2012 .test = alg_test_aead,
2013 .fips_allowed = 1,
2014 .suite = {
2015 .aead = {
2016 .enc = {
2017 .vecs =
2018 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2019 .count =
2020 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002021 }
2022 }
2023 }
2024 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03002025 .alg = "authenc(hmac(sha256),cbc(aes))",
2026 .test = alg_test_aead,
2027 .fips_allowed = 1,
2028 .suite = {
2029 .aead = {
2030 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302031 .vecs =
2032 hmac_sha256_aes_cbc_enc_tv_temp,
2033 .count =
2034 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2035 }
2036 }
2037 }
2038 }, {
2039 .alg = "authenc(hmac(sha256),cbc(des))",
2040 .test = alg_test_aead,
2041 .fips_allowed = 1,
2042 .suite = {
2043 .aead = {
2044 .enc = {
2045 .vecs =
2046 hmac_sha256_des_cbc_enc_tv_temp,
2047 .count =
2048 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2049 }
2050 }
2051 }
2052 }, {
2053 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
2054 .test = alg_test_aead,
2055 .fips_allowed = 1,
2056 .suite = {
2057 .aead = {
2058 .enc = {
2059 .vecs =
2060 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2061 .count =
2062 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2063 }
2064 }
2065 }
2066 }, {
2067 .alg = "authenc(hmac(sha384),cbc(des))",
2068 .test = alg_test_aead,
2069 .fips_allowed = 1,
2070 .suite = {
2071 .aead = {
2072 .enc = {
2073 .vecs =
2074 hmac_sha384_des_cbc_enc_tv_temp,
2075 .count =
2076 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2077 }
2078 }
2079 }
2080 }, {
2081 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
2082 .test = alg_test_aead,
2083 .fips_allowed = 1,
2084 .suite = {
2085 .aead = {
2086 .enc = {
2087 .vecs =
2088 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2089 .count =
2090 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002091 }
2092 }
2093 }
2094 }, {
2095 .alg = "authenc(hmac(sha512),cbc(aes))",
2096 .test = alg_test_aead,
2097 .fips_allowed = 1,
2098 .suite = {
2099 .aead = {
2100 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302101 .vecs =
2102 hmac_sha512_aes_cbc_enc_tv_temp,
2103 .count =
2104 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2105 }
2106 }
2107 }
2108 }, {
2109 .alg = "authenc(hmac(sha512),cbc(des))",
2110 .test = alg_test_aead,
2111 .fips_allowed = 1,
2112 .suite = {
2113 .aead = {
2114 .enc = {
2115 .vecs =
2116 hmac_sha512_des_cbc_enc_tv_temp,
2117 .count =
2118 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2119 }
2120 }
2121 }
2122 }, {
2123 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2124 .test = alg_test_aead,
2125 .fips_allowed = 1,
2126 .suite = {
2127 .aead = {
2128 .enc = {
2129 .vecs =
2130 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2131 .count =
2132 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002133 }
2134 }
2135 }
2136 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002137 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002138 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002139 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002140 .suite = {
2141 .cipher = {
2142 .enc = {
2143 .vecs = aes_cbc_enc_tv_template,
2144 .count = AES_CBC_ENC_TEST_VECTORS
2145 },
2146 .dec = {
2147 .vecs = aes_cbc_dec_tv_template,
2148 .count = AES_CBC_DEC_TEST_VECTORS
2149 }
2150 }
2151 }
2152 }, {
2153 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002154 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002155 .suite = {
2156 .cipher = {
2157 .enc = {
2158 .vecs = anubis_cbc_enc_tv_template,
2159 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2160 },
2161 .dec = {
2162 .vecs = anubis_cbc_dec_tv_template,
2163 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2164 }
2165 }
2166 }
2167 }, {
2168 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002169 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002170 .suite = {
2171 .cipher = {
2172 .enc = {
2173 .vecs = bf_cbc_enc_tv_template,
2174 .count = BF_CBC_ENC_TEST_VECTORS
2175 },
2176 .dec = {
2177 .vecs = bf_cbc_dec_tv_template,
2178 .count = BF_CBC_DEC_TEST_VECTORS
2179 }
2180 }
2181 }
2182 }, {
2183 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002184 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002185 .suite = {
2186 .cipher = {
2187 .enc = {
2188 .vecs = camellia_cbc_enc_tv_template,
2189 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2190 },
2191 .dec = {
2192 .vecs = camellia_cbc_dec_tv_template,
2193 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2194 }
2195 }
2196 }
2197 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002198 .alg = "cbc(cast5)",
2199 .test = alg_test_skcipher,
2200 .suite = {
2201 .cipher = {
2202 .enc = {
2203 .vecs = cast5_cbc_enc_tv_template,
2204 .count = CAST5_CBC_ENC_TEST_VECTORS
2205 },
2206 .dec = {
2207 .vecs = cast5_cbc_dec_tv_template,
2208 .count = CAST5_CBC_DEC_TEST_VECTORS
2209 }
2210 }
2211 }
2212 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002213 .alg = "cbc(cast6)",
2214 .test = alg_test_skcipher,
2215 .suite = {
2216 .cipher = {
2217 .enc = {
2218 .vecs = cast6_cbc_enc_tv_template,
2219 .count = CAST6_CBC_ENC_TEST_VECTORS
2220 },
2221 .dec = {
2222 .vecs = cast6_cbc_dec_tv_template,
2223 .count = CAST6_CBC_DEC_TEST_VECTORS
2224 }
2225 }
2226 }
2227 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002228 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002229 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002230 .suite = {
2231 .cipher = {
2232 .enc = {
2233 .vecs = des_cbc_enc_tv_template,
2234 .count = DES_CBC_ENC_TEST_VECTORS
2235 },
2236 .dec = {
2237 .vecs = des_cbc_dec_tv_template,
2238 .count = DES_CBC_DEC_TEST_VECTORS
2239 }
2240 }
2241 }
2242 }, {
2243 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002244 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002245 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002246 .suite = {
2247 .cipher = {
2248 .enc = {
2249 .vecs = des3_ede_cbc_enc_tv_template,
2250 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2251 },
2252 .dec = {
2253 .vecs = des3_ede_cbc_dec_tv_template,
2254 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2255 }
2256 }
2257 }
2258 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002259 .alg = "cbc(serpent)",
2260 .test = alg_test_skcipher,
2261 .suite = {
2262 .cipher = {
2263 .enc = {
2264 .vecs = serpent_cbc_enc_tv_template,
2265 .count = SERPENT_CBC_ENC_TEST_VECTORS
2266 },
2267 .dec = {
2268 .vecs = serpent_cbc_dec_tv_template,
2269 .count = SERPENT_CBC_DEC_TEST_VECTORS
2270 }
2271 }
2272 }
2273 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002274 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002275 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002276 .suite = {
2277 .cipher = {
2278 .enc = {
2279 .vecs = tf_cbc_enc_tv_template,
2280 .count = TF_CBC_ENC_TEST_VECTORS
2281 },
2282 .dec = {
2283 .vecs = tf_cbc_dec_tv_template,
2284 .count = TF_CBC_DEC_TEST_VECTORS
2285 }
2286 }
2287 }
2288 }, {
2289 .alg = "ccm(aes)",
2290 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002291 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002292 .suite = {
2293 .aead = {
2294 .enc = {
2295 .vecs = aes_ccm_enc_tv_template,
2296 .count = AES_CCM_ENC_TEST_VECTORS
2297 },
2298 .dec = {
2299 .vecs = aes_ccm_dec_tv_template,
2300 .count = AES_CCM_DEC_TEST_VECTORS
2301 }
2302 }
2303 }
2304 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002305 .alg = "cmac(aes)",
2306 .test = alg_test_hash,
2307 .suite = {
2308 .hash = {
2309 .vecs = aes_cmac128_tv_template,
2310 .count = CMAC_AES_TEST_VECTORS
2311 }
2312 }
2313 }, {
2314 .alg = "cmac(des3_ede)",
2315 .test = alg_test_hash,
2316 .suite = {
2317 .hash = {
2318 .vecs = des3_ede_cmac64_tv_template,
2319 .count = CMAC_DES3_EDE_TEST_VECTORS
2320 }
2321 }
2322 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002323 .alg = "compress_null",
2324 .test = alg_test_null,
2325 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002326 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002327 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002328 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002329 .suite = {
2330 .hash = {
2331 .vecs = crc32c_tv_template,
2332 .count = CRC32C_TEST_VECTORS
2333 }
2334 }
2335 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002336 .alg = "crct10dif",
2337 .test = alg_test_hash,
2338 .fips_allowed = 1,
2339 .suite = {
2340 .hash = {
2341 .vecs = crct10dif_tv_template,
2342 .count = CRCT10DIF_TEST_VECTORS
2343 }
2344 }
2345 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002346 .alg = "cryptd(__driver-cbc-aes-aesni)",
2347 .test = alg_test_null,
2348 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002349 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002350 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2351 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002352 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002353 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2354 .test = alg_test_null,
2355 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002356 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2357 .test = alg_test_null,
2358 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002359 .alg = "cryptd(__driver-ecb-aes-aesni)",
2360 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002361 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002362 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002363 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2364 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002365 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002366 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2367 .test = alg_test_null,
2368 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002369 .alg = "cryptd(__driver-ecb-cast5-avx)",
2370 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002371 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002372 .alg = "cryptd(__driver-ecb-cast6-avx)",
2373 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002374 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002375 .alg = "cryptd(__driver-ecb-serpent-avx)",
2376 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002377 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002378 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2379 .test = alg_test_null,
2380 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002381 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2382 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002383 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002384 .alg = "cryptd(__driver-ecb-twofish-avx)",
2385 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002386 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002387 .alg = "cryptd(__driver-gcm-aes-aesni)",
2388 .test = alg_test_null,
2389 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002390 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002391 .alg = "cryptd(__ghash-pclmulqdqni)",
2392 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002393 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002394 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002395 .alg = "ctr(aes)",
2396 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002397 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002398 .suite = {
2399 .cipher = {
2400 .enc = {
2401 .vecs = aes_ctr_enc_tv_template,
2402 .count = AES_CTR_ENC_TEST_VECTORS
2403 },
2404 .dec = {
2405 .vecs = aes_ctr_dec_tv_template,
2406 .count = AES_CTR_DEC_TEST_VECTORS
2407 }
2408 }
2409 }
2410 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002411 .alg = "ctr(blowfish)",
2412 .test = alg_test_skcipher,
2413 .suite = {
2414 .cipher = {
2415 .enc = {
2416 .vecs = bf_ctr_enc_tv_template,
2417 .count = BF_CTR_ENC_TEST_VECTORS
2418 },
2419 .dec = {
2420 .vecs = bf_ctr_dec_tv_template,
2421 .count = BF_CTR_DEC_TEST_VECTORS
2422 }
2423 }
2424 }
2425 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002426 .alg = "ctr(camellia)",
2427 .test = alg_test_skcipher,
2428 .suite = {
2429 .cipher = {
2430 .enc = {
2431 .vecs = camellia_ctr_enc_tv_template,
2432 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2433 },
2434 .dec = {
2435 .vecs = camellia_ctr_dec_tv_template,
2436 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2437 }
2438 }
2439 }
2440 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002441 .alg = "ctr(cast5)",
2442 .test = alg_test_skcipher,
2443 .suite = {
2444 .cipher = {
2445 .enc = {
2446 .vecs = cast5_ctr_enc_tv_template,
2447 .count = CAST5_CTR_ENC_TEST_VECTORS
2448 },
2449 .dec = {
2450 .vecs = cast5_ctr_dec_tv_template,
2451 .count = CAST5_CTR_DEC_TEST_VECTORS
2452 }
2453 }
2454 }
2455 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002456 .alg = "ctr(cast6)",
2457 .test = alg_test_skcipher,
2458 .suite = {
2459 .cipher = {
2460 .enc = {
2461 .vecs = cast6_ctr_enc_tv_template,
2462 .count = CAST6_CTR_ENC_TEST_VECTORS
2463 },
2464 .dec = {
2465 .vecs = cast6_ctr_dec_tv_template,
2466 .count = CAST6_CTR_DEC_TEST_VECTORS
2467 }
2468 }
2469 }
2470 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002471 .alg = "ctr(des)",
2472 .test = alg_test_skcipher,
2473 .suite = {
2474 .cipher = {
2475 .enc = {
2476 .vecs = des_ctr_enc_tv_template,
2477 .count = DES_CTR_ENC_TEST_VECTORS
2478 },
2479 .dec = {
2480 .vecs = des_ctr_dec_tv_template,
2481 .count = DES_CTR_DEC_TEST_VECTORS
2482 }
2483 }
2484 }
2485 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002486 .alg = "ctr(des3_ede)",
2487 .test = alg_test_skcipher,
2488 .suite = {
2489 .cipher = {
2490 .enc = {
2491 .vecs = des3_ede_ctr_enc_tv_template,
2492 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2493 },
2494 .dec = {
2495 .vecs = des3_ede_ctr_dec_tv_template,
2496 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2497 }
2498 }
2499 }
2500 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002501 .alg = "ctr(serpent)",
2502 .test = alg_test_skcipher,
2503 .suite = {
2504 .cipher = {
2505 .enc = {
2506 .vecs = serpent_ctr_enc_tv_template,
2507 .count = SERPENT_CTR_ENC_TEST_VECTORS
2508 },
2509 .dec = {
2510 .vecs = serpent_ctr_dec_tv_template,
2511 .count = SERPENT_CTR_DEC_TEST_VECTORS
2512 }
2513 }
2514 }
2515 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002516 .alg = "ctr(twofish)",
2517 .test = alg_test_skcipher,
2518 .suite = {
2519 .cipher = {
2520 .enc = {
2521 .vecs = tf_ctr_enc_tv_template,
2522 .count = TF_CTR_ENC_TEST_VECTORS
2523 },
2524 .dec = {
2525 .vecs = tf_ctr_dec_tv_template,
2526 .count = TF_CTR_DEC_TEST_VECTORS
2527 }
2528 }
2529 }
2530 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002531 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002532 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002533 .suite = {
2534 .cipher = {
2535 .enc = {
2536 .vecs = cts_mode_enc_tv_template,
2537 .count = CTS_MODE_ENC_TEST_VECTORS
2538 },
2539 .dec = {
2540 .vecs = cts_mode_dec_tv_template,
2541 .count = CTS_MODE_DEC_TEST_VECTORS
2542 }
2543 }
2544 }
2545 }, {
2546 .alg = "deflate",
2547 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002548 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002549 .suite = {
2550 .comp = {
2551 .comp = {
2552 .vecs = deflate_comp_tv_template,
2553 .count = DEFLATE_COMP_TEST_VECTORS
2554 },
2555 .decomp = {
2556 .vecs = deflate_decomp_tv_template,
2557 .count = DEFLATE_DECOMP_TEST_VECTORS
2558 }
2559 }
2560 }
2561 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002562 .alg = "digest_null",
2563 .test = alg_test_null,
2564 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002565 .alg = "drbg_nopr_ctr_aes128",
2566 .test = alg_test_drbg,
2567 .fips_allowed = 1,
2568 .suite = {
2569 .drbg = {
2570 .vecs = drbg_nopr_ctr_aes128_tv_template,
2571 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2572 }
2573 }
2574 }, {
2575 .alg = "drbg_nopr_ctr_aes192",
2576 .test = alg_test_drbg,
2577 .fips_allowed = 1,
2578 .suite = {
2579 .drbg = {
2580 .vecs = drbg_nopr_ctr_aes192_tv_template,
2581 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2582 }
2583 }
2584 }, {
2585 .alg = "drbg_nopr_ctr_aes256",
2586 .test = alg_test_drbg,
2587 .fips_allowed = 1,
2588 .suite = {
2589 .drbg = {
2590 .vecs = drbg_nopr_ctr_aes256_tv_template,
2591 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2592 }
2593 }
2594 }, {
2595 /*
2596 * There is no need to specifically test the DRBG with every
2597 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2598 */
2599 .alg = "drbg_nopr_hmac_sha1",
2600 .fips_allowed = 1,
2601 .test = alg_test_null,
2602 }, {
2603 .alg = "drbg_nopr_hmac_sha256",
2604 .test = alg_test_drbg,
2605 .fips_allowed = 1,
2606 .suite = {
2607 .drbg = {
2608 .vecs = drbg_nopr_hmac_sha256_tv_template,
2609 .count =
2610 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2611 }
2612 }
2613 }, {
2614 /* covered by drbg_nopr_hmac_sha256 test */
2615 .alg = "drbg_nopr_hmac_sha384",
2616 .fips_allowed = 1,
2617 .test = alg_test_null,
2618 }, {
2619 .alg = "drbg_nopr_hmac_sha512",
2620 .test = alg_test_null,
2621 .fips_allowed = 1,
2622 }, {
2623 .alg = "drbg_nopr_sha1",
2624 .fips_allowed = 1,
2625 .test = alg_test_null,
2626 }, {
2627 .alg = "drbg_nopr_sha256",
2628 .test = alg_test_drbg,
2629 .fips_allowed = 1,
2630 .suite = {
2631 .drbg = {
2632 .vecs = drbg_nopr_sha256_tv_template,
2633 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2634 }
2635 }
2636 }, {
2637 /* covered by drbg_nopr_sha256 test */
2638 .alg = "drbg_nopr_sha384",
2639 .fips_allowed = 1,
2640 .test = alg_test_null,
2641 }, {
2642 .alg = "drbg_nopr_sha512",
2643 .fips_allowed = 1,
2644 .test = alg_test_null,
2645 }, {
2646 .alg = "drbg_pr_ctr_aes128",
2647 .test = alg_test_drbg,
2648 .fips_allowed = 1,
2649 .suite = {
2650 .drbg = {
2651 .vecs = drbg_pr_ctr_aes128_tv_template,
2652 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2653 }
2654 }
2655 }, {
2656 /* covered by drbg_pr_ctr_aes128 test */
2657 .alg = "drbg_pr_ctr_aes192",
2658 .fips_allowed = 1,
2659 .test = alg_test_null,
2660 }, {
2661 .alg = "drbg_pr_ctr_aes256",
2662 .fips_allowed = 1,
2663 .test = alg_test_null,
2664 }, {
2665 .alg = "drbg_pr_hmac_sha1",
2666 .fips_allowed = 1,
2667 .test = alg_test_null,
2668 }, {
2669 .alg = "drbg_pr_hmac_sha256",
2670 .test = alg_test_drbg,
2671 .fips_allowed = 1,
2672 .suite = {
2673 .drbg = {
2674 .vecs = drbg_pr_hmac_sha256_tv_template,
2675 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2676 }
2677 }
2678 }, {
2679 /* covered by drbg_pr_hmac_sha256 test */
2680 .alg = "drbg_pr_hmac_sha384",
2681 .fips_allowed = 1,
2682 .test = alg_test_null,
2683 }, {
2684 .alg = "drbg_pr_hmac_sha512",
2685 .test = alg_test_null,
2686 .fips_allowed = 1,
2687 }, {
2688 .alg = "drbg_pr_sha1",
2689 .fips_allowed = 1,
2690 .test = alg_test_null,
2691 }, {
2692 .alg = "drbg_pr_sha256",
2693 .test = alg_test_drbg,
2694 .fips_allowed = 1,
2695 .suite = {
2696 .drbg = {
2697 .vecs = drbg_pr_sha256_tv_template,
2698 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2699 }
2700 }
2701 }, {
2702 /* covered by drbg_pr_sha256 test */
2703 .alg = "drbg_pr_sha384",
2704 .fips_allowed = 1,
2705 .test = alg_test_null,
2706 }, {
2707 .alg = "drbg_pr_sha512",
2708 .fips_allowed = 1,
2709 .test = alg_test_null,
2710 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002711 .alg = "ecb(__aes-aesni)",
2712 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002713 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002714 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002715 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002716 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002717 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002718 .suite = {
2719 .cipher = {
2720 .enc = {
2721 .vecs = aes_enc_tv_template,
2722 .count = AES_ENC_TEST_VECTORS
2723 },
2724 .dec = {
2725 .vecs = aes_dec_tv_template,
2726 .count = AES_DEC_TEST_VECTORS
2727 }
2728 }
2729 }
2730 }, {
2731 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002732 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002733 .suite = {
2734 .cipher = {
2735 .enc = {
2736 .vecs = anubis_enc_tv_template,
2737 .count = ANUBIS_ENC_TEST_VECTORS
2738 },
2739 .dec = {
2740 .vecs = anubis_dec_tv_template,
2741 .count = ANUBIS_DEC_TEST_VECTORS
2742 }
2743 }
2744 }
2745 }, {
2746 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002747 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002748 .suite = {
2749 .cipher = {
2750 .enc = {
2751 .vecs = arc4_enc_tv_template,
2752 .count = ARC4_ENC_TEST_VECTORS
2753 },
2754 .dec = {
2755 .vecs = arc4_dec_tv_template,
2756 .count = ARC4_DEC_TEST_VECTORS
2757 }
2758 }
2759 }
2760 }, {
2761 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002762 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002763 .suite = {
2764 .cipher = {
2765 .enc = {
2766 .vecs = bf_enc_tv_template,
2767 .count = BF_ENC_TEST_VECTORS
2768 },
2769 .dec = {
2770 .vecs = bf_dec_tv_template,
2771 .count = BF_DEC_TEST_VECTORS
2772 }
2773 }
2774 }
2775 }, {
2776 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002777 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002778 .suite = {
2779 .cipher = {
2780 .enc = {
2781 .vecs = camellia_enc_tv_template,
2782 .count = CAMELLIA_ENC_TEST_VECTORS
2783 },
2784 .dec = {
2785 .vecs = camellia_dec_tv_template,
2786 .count = CAMELLIA_DEC_TEST_VECTORS
2787 }
2788 }
2789 }
2790 }, {
2791 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002792 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002793 .suite = {
2794 .cipher = {
2795 .enc = {
2796 .vecs = cast5_enc_tv_template,
2797 .count = CAST5_ENC_TEST_VECTORS
2798 },
2799 .dec = {
2800 .vecs = cast5_dec_tv_template,
2801 .count = CAST5_DEC_TEST_VECTORS
2802 }
2803 }
2804 }
2805 }, {
2806 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002807 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002808 .suite = {
2809 .cipher = {
2810 .enc = {
2811 .vecs = cast6_enc_tv_template,
2812 .count = CAST6_ENC_TEST_VECTORS
2813 },
2814 .dec = {
2815 .vecs = cast6_dec_tv_template,
2816 .count = CAST6_DEC_TEST_VECTORS
2817 }
2818 }
2819 }
2820 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002821 .alg = "ecb(cipher_null)",
2822 .test = alg_test_null,
2823 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002824 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002825 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002826 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002827 .suite = {
2828 .cipher = {
2829 .enc = {
2830 .vecs = des_enc_tv_template,
2831 .count = DES_ENC_TEST_VECTORS
2832 },
2833 .dec = {
2834 .vecs = des_dec_tv_template,
2835 .count = DES_DEC_TEST_VECTORS
2836 }
2837 }
2838 }
2839 }, {
2840 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002841 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002842 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002843 .suite = {
2844 .cipher = {
2845 .enc = {
2846 .vecs = des3_ede_enc_tv_template,
2847 .count = DES3_EDE_ENC_TEST_VECTORS
2848 },
2849 .dec = {
2850 .vecs = des3_ede_dec_tv_template,
2851 .count = DES3_EDE_DEC_TEST_VECTORS
2852 }
2853 }
2854 }
2855 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002856 .alg = "ecb(fcrypt)",
2857 .test = alg_test_skcipher,
2858 .suite = {
2859 .cipher = {
2860 .enc = {
2861 .vecs = fcrypt_pcbc_enc_tv_template,
2862 .count = 1
2863 },
2864 .dec = {
2865 .vecs = fcrypt_pcbc_dec_tv_template,
2866 .count = 1
2867 }
2868 }
2869 }
2870 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002871 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002872 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002873 .suite = {
2874 .cipher = {
2875 .enc = {
2876 .vecs = khazad_enc_tv_template,
2877 .count = KHAZAD_ENC_TEST_VECTORS
2878 },
2879 .dec = {
2880 .vecs = khazad_dec_tv_template,
2881 .count = KHAZAD_DEC_TEST_VECTORS
2882 }
2883 }
2884 }
2885 }, {
2886 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002887 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002888 .suite = {
2889 .cipher = {
2890 .enc = {
2891 .vecs = seed_enc_tv_template,
2892 .count = SEED_ENC_TEST_VECTORS
2893 },
2894 .dec = {
2895 .vecs = seed_dec_tv_template,
2896 .count = SEED_DEC_TEST_VECTORS
2897 }
2898 }
2899 }
2900 }, {
2901 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002902 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002903 .suite = {
2904 .cipher = {
2905 .enc = {
2906 .vecs = serpent_enc_tv_template,
2907 .count = SERPENT_ENC_TEST_VECTORS
2908 },
2909 .dec = {
2910 .vecs = serpent_dec_tv_template,
2911 .count = SERPENT_DEC_TEST_VECTORS
2912 }
2913 }
2914 }
2915 }, {
2916 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002917 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002918 .suite = {
2919 .cipher = {
2920 .enc = {
2921 .vecs = tea_enc_tv_template,
2922 .count = TEA_ENC_TEST_VECTORS
2923 },
2924 .dec = {
2925 .vecs = tea_dec_tv_template,
2926 .count = TEA_DEC_TEST_VECTORS
2927 }
2928 }
2929 }
2930 }, {
2931 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002932 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002933 .suite = {
2934 .cipher = {
2935 .enc = {
2936 .vecs = tnepres_enc_tv_template,
2937 .count = TNEPRES_ENC_TEST_VECTORS
2938 },
2939 .dec = {
2940 .vecs = tnepres_dec_tv_template,
2941 .count = TNEPRES_DEC_TEST_VECTORS
2942 }
2943 }
2944 }
2945 }, {
2946 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002947 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002948 .suite = {
2949 .cipher = {
2950 .enc = {
2951 .vecs = tf_enc_tv_template,
2952 .count = TF_ENC_TEST_VECTORS
2953 },
2954 .dec = {
2955 .vecs = tf_dec_tv_template,
2956 .count = TF_DEC_TEST_VECTORS
2957 }
2958 }
2959 }
2960 }, {
2961 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002962 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002963 .suite = {
2964 .cipher = {
2965 .enc = {
2966 .vecs = xeta_enc_tv_template,
2967 .count = XETA_ENC_TEST_VECTORS
2968 },
2969 .dec = {
2970 .vecs = xeta_dec_tv_template,
2971 .count = XETA_DEC_TEST_VECTORS
2972 }
2973 }
2974 }
2975 }, {
2976 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002977 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002978 .suite = {
2979 .cipher = {
2980 .enc = {
2981 .vecs = xtea_enc_tv_template,
2982 .count = XTEA_ENC_TEST_VECTORS
2983 },
2984 .dec = {
2985 .vecs = xtea_dec_tv_template,
2986 .count = XTEA_DEC_TEST_VECTORS
2987 }
2988 }
2989 }
2990 }, {
2991 .alg = "gcm(aes)",
2992 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002993 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002994 .suite = {
2995 .aead = {
2996 .enc = {
2997 .vecs = aes_gcm_enc_tv_template,
2998 .count = AES_GCM_ENC_TEST_VECTORS
2999 },
3000 .dec = {
3001 .vecs = aes_gcm_dec_tv_template,
3002 .count = AES_GCM_DEC_TEST_VECTORS
3003 }
3004 }
3005 }
3006 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003007 .alg = "ghash",
3008 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003009 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003010 .suite = {
3011 .hash = {
3012 .vecs = ghash_tv_template,
3013 .count = GHASH_TEST_VECTORS
3014 }
3015 }
3016 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003017 .alg = "hmac(crc32)",
3018 .test = alg_test_hash,
3019 .suite = {
3020 .hash = {
3021 .vecs = bfin_crc_tv_template,
3022 .count = BFIN_CRC_TEST_VECTORS
3023 }
3024 }
3025 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003026 .alg = "hmac(md5)",
3027 .test = alg_test_hash,
3028 .suite = {
3029 .hash = {
3030 .vecs = hmac_md5_tv_template,
3031 .count = HMAC_MD5_TEST_VECTORS
3032 }
3033 }
3034 }, {
3035 .alg = "hmac(rmd128)",
3036 .test = alg_test_hash,
3037 .suite = {
3038 .hash = {
3039 .vecs = hmac_rmd128_tv_template,
3040 .count = HMAC_RMD128_TEST_VECTORS
3041 }
3042 }
3043 }, {
3044 .alg = "hmac(rmd160)",
3045 .test = alg_test_hash,
3046 .suite = {
3047 .hash = {
3048 .vecs = hmac_rmd160_tv_template,
3049 .count = HMAC_RMD160_TEST_VECTORS
3050 }
3051 }
3052 }, {
3053 .alg = "hmac(sha1)",
3054 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003055 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003056 .suite = {
3057 .hash = {
3058 .vecs = hmac_sha1_tv_template,
3059 .count = HMAC_SHA1_TEST_VECTORS
3060 }
3061 }
3062 }, {
3063 .alg = "hmac(sha224)",
3064 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003065 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003066 .suite = {
3067 .hash = {
3068 .vecs = hmac_sha224_tv_template,
3069 .count = HMAC_SHA224_TEST_VECTORS
3070 }
3071 }
3072 }, {
3073 .alg = "hmac(sha256)",
3074 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003075 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003076 .suite = {
3077 .hash = {
3078 .vecs = hmac_sha256_tv_template,
3079 .count = HMAC_SHA256_TEST_VECTORS
3080 }
3081 }
3082 }, {
3083 .alg = "hmac(sha384)",
3084 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003085 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003086 .suite = {
3087 .hash = {
3088 .vecs = hmac_sha384_tv_template,
3089 .count = HMAC_SHA384_TEST_VECTORS
3090 }
3091 }
3092 }, {
3093 .alg = "hmac(sha512)",
3094 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003095 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003096 .suite = {
3097 .hash = {
3098 .vecs = hmac_sha512_tv_template,
3099 .count = HMAC_SHA512_TEST_VECTORS
3100 }
3101 }
3102 }, {
3103 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003104 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003105 .suite = {
3106 .cipher = {
3107 .enc = {
3108 .vecs = aes_lrw_enc_tv_template,
3109 .count = AES_LRW_ENC_TEST_VECTORS
3110 },
3111 .dec = {
3112 .vecs = aes_lrw_dec_tv_template,
3113 .count = AES_LRW_DEC_TEST_VECTORS
3114 }
3115 }
3116 }
3117 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003118 .alg = "lrw(camellia)",
3119 .test = alg_test_skcipher,
3120 .suite = {
3121 .cipher = {
3122 .enc = {
3123 .vecs = camellia_lrw_enc_tv_template,
3124 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3125 },
3126 .dec = {
3127 .vecs = camellia_lrw_dec_tv_template,
3128 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3129 }
3130 }
3131 }
3132 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003133 .alg = "lrw(cast6)",
3134 .test = alg_test_skcipher,
3135 .suite = {
3136 .cipher = {
3137 .enc = {
3138 .vecs = cast6_lrw_enc_tv_template,
3139 .count = CAST6_LRW_ENC_TEST_VECTORS
3140 },
3141 .dec = {
3142 .vecs = cast6_lrw_dec_tv_template,
3143 .count = CAST6_LRW_DEC_TEST_VECTORS
3144 }
3145 }
3146 }
3147 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003148 .alg = "lrw(serpent)",
3149 .test = alg_test_skcipher,
3150 .suite = {
3151 .cipher = {
3152 .enc = {
3153 .vecs = serpent_lrw_enc_tv_template,
3154 .count = SERPENT_LRW_ENC_TEST_VECTORS
3155 },
3156 .dec = {
3157 .vecs = serpent_lrw_dec_tv_template,
3158 .count = SERPENT_LRW_DEC_TEST_VECTORS
3159 }
3160 }
3161 }
3162 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003163 .alg = "lrw(twofish)",
3164 .test = alg_test_skcipher,
3165 .suite = {
3166 .cipher = {
3167 .enc = {
3168 .vecs = tf_lrw_enc_tv_template,
3169 .count = TF_LRW_ENC_TEST_VECTORS
3170 },
3171 .dec = {
3172 .vecs = tf_lrw_dec_tv_template,
3173 .count = TF_LRW_DEC_TEST_VECTORS
3174 }
3175 }
3176 }
3177 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003178 .alg = "lz4",
3179 .test = alg_test_comp,
3180 .fips_allowed = 1,
3181 .suite = {
3182 .comp = {
3183 .comp = {
3184 .vecs = lz4_comp_tv_template,
3185 .count = LZ4_COMP_TEST_VECTORS
3186 },
3187 .decomp = {
3188 .vecs = lz4_decomp_tv_template,
3189 .count = LZ4_DECOMP_TEST_VECTORS
3190 }
3191 }
3192 }
3193 }, {
3194 .alg = "lz4hc",
3195 .test = alg_test_comp,
3196 .fips_allowed = 1,
3197 .suite = {
3198 .comp = {
3199 .comp = {
3200 .vecs = lz4hc_comp_tv_template,
3201 .count = LZ4HC_COMP_TEST_VECTORS
3202 },
3203 .decomp = {
3204 .vecs = lz4hc_decomp_tv_template,
3205 .count = LZ4HC_DECOMP_TEST_VECTORS
3206 }
3207 }
3208 }
3209 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003210 .alg = "lzo",
3211 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003212 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003213 .suite = {
3214 .comp = {
3215 .comp = {
3216 .vecs = lzo_comp_tv_template,
3217 .count = LZO_COMP_TEST_VECTORS
3218 },
3219 .decomp = {
3220 .vecs = lzo_decomp_tv_template,
3221 .count = LZO_DECOMP_TEST_VECTORS
3222 }
3223 }
3224 }
3225 }, {
3226 .alg = "md4",
3227 .test = alg_test_hash,
3228 .suite = {
3229 .hash = {
3230 .vecs = md4_tv_template,
3231 .count = MD4_TEST_VECTORS
3232 }
3233 }
3234 }, {
3235 .alg = "md5",
3236 .test = alg_test_hash,
3237 .suite = {
3238 .hash = {
3239 .vecs = md5_tv_template,
3240 .count = MD5_TEST_VECTORS
3241 }
3242 }
3243 }, {
3244 .alg = "michael_mic",
3245 .test = alg_test_hash,
3246 .suite = {
3247 .hash = {
3248 .vecs = michael_mic_tv_template,
3249 .count = MICHAEL_MIC_TEST_VECTORS
3250 }
3251 }
3252 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003253 .alg = "ofb(aes)",
3254 .test = alg_test_skcipher,
3255 .fips_allowed = 1,
3256 .suite = {
3257 .cipher = {
3258 .enc = {
3259 .vecs = aes_ofb_enc_tv_template,
3260 .count = AES_OFB_ENC_TEST_VECTORS
3261 },
3262 .dec = {
3263 .vecs = aes_ofb_dec_tv_template,
3264 .count = AES_OFB_DEC_TEST_VECTORS
3265 }
3266 }
3267 }
3268 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003269 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003270 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003271 .suite = {
3272 .cipher = {
3273 .enc = {
3274 .vecs = fcrypt_pcbc_enc_tv_template,
3275 .count = FCRYPT_ENC_TEST_VECTORS
3276 },
3277 .dec = {
3278 .vecs = fcrypt_pcbc_dec_tv_template,
3279 .count = FCRYPT_DEC_TEST_VECTORS
3280 }
3281 }
3282 }
3283 }, {
3284 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003285 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003286 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003287 .suite = {
3288 .cipher = {
3289 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003290 .vecs = aes_ctr_rfc3686_enc_tv_template,
3291 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003292 },
3293 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003294 .vecs = aes_ctr_rfc3686_dec_tv_template,
3295 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003296 }
3297 }
3298 }
3299 }, {
Adrian Hoban69435b92010-11-04 15:02:04 -04003300 .alg = "rfc4106(gcm(aes))",
3301 .test = alg_test_aead,
3302 .suite = {
3303 .aead = {
3304 .enc = {
3305 .vecs = aes_gcm_rfc4106_enc_tv_template,
3306 .count = AES_GCM_4106_ENC_TEST_VECTORS
3307 },
3308 .dec = {
3309 .vecs = aes_gcm_rfc4106_dec_tv_template,
3310 .count = AES_GCM_4106_DEC_TEST_VECTORS
3311 }
3312 }
3313 }
3314 }, {
Jarod Wilson5d667322009-05-04 19:23:40 +08003315 .alg = "rfc4309(ccm(aes))",
3316 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003317 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003318 .suite = {
3319 .aead = {
3320 .enc = {
3321 .vecs = aes_ccm_rfc4309_enc_tv_template,
3322 .count = AES_CCM_4309_ENC_TEST_VECTORS
3323 },
3324 .dec = {
3325 .vecs = aes_ccm_rfc4309_dec_tv_template,
3326 .count = AES_CCM_4309_DEC_TEST_VECTORS
3327 }
3328 }
3329 }
3330 }, {
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003331 .alg = "rfc4543(gcm(aes))",
3332 .test = alg_test_aead,
3333 .suite = {
3334 .aead = {
3335 .enc = {
3336 .vecs = aes_gcm_rfc4543_enc_tv_template,
3337 .count = AES_GCM_4543_ENC_TEST_VECTORS
3338 },
3339 .dec = {
3340 .vecs = aes_gcm_rfc4543_dec_tv_template,
3341 .count = AES_GCM_4543_DEC_TEST_VECTORS
3342 },
3343 }
3344 }
3345 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003346 .alg = "rmd128",
3347 .test = alg_test_hash,
3348 .suite = {
3349 .hash = {
3350 .vecs = rmd128_tv_template,
3351 .count = RMD128_TEST_VECTORS
3352 }
3353 }
3354 }, {
3355 .alg = "rmd160",
3356 .test = alg_test_hash,
3357 .suite = {
3358 .hash = {
3359 .vecs = rmd160_tv_template,
3360 .count = RMD160_TEST_VECTORS
3361 }
3362 }
3363 }, {
3364 .alg = "rmd256",
3365 .test = alg_test_hash,
3366 .suite = {
3367 .hash = {
3368 .vecs = rmd256_tv_template,
3369 .count = RMD256_TEST_VECTORS
3370 }
3371 }
3372 }, {
3373 .alg = "rmd320",
3374 .test = alg_test_hash,
3375 .suite = {
3376 .hash = {
3377 .vecs = rmd320_tv_template,
3378 .count = RMD320_TEST_VECTORS
3379 }
3380 }
3381 }, {
3382 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003383 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003384 .suite = {
3385 .cipher = {
3386 .enc = {
3387 .vecs = salsa20_stream_enc_tv_template,
3388 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3389 }
3390 }
3391 }
3392 }, {
3393 .alg = "sha1",
3394 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003395 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003396 .suite = {
3397 .hash = {
3398 .vecs = sha1_tv_template,
3399 .count = SHA1_TEST_VECTORS
3400 }
3401 }
3402 }, {
3403 .alg = "sha224",
3404 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003405 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003406 .suite = {
3407 .hash = {
3408 .vecs = sha224_tv_template,
3409 .count = SHA224_TEST_VECTORS
3410 }
3411 }
3412 }, {
3413 .alg = "sha256",
3414 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003415 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003416 .suite = {
3417 .hash = {
3418 .vecs = sha256_tv_template,
3419 .count = SHA256_TEST_VECTORS
3420 }
3421 }
3422 }, {
3423 .alg = "sha384",
3424 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003425 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003426 .suite = {
3427 .hash = {
3428 .vecs = sha384_tv_template,
3429 .count = SHA384_TEST_VECTORS
3430 }
3431 }
3432 }, {
3433 .alg = "sha512",
3434 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003435 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003436 .suite = {
3437 .hash = {
3438 .vecs = sha512_tv_template,
3439 .count = SHA512_TEST_VECTORS
3440 }
3441 }
3442 }, {
3443 .alg = "tgr128",
3444 .test = alg_test_hash,
3445 .suite = {
3446 .hash = {
3447 .vecs = tgr128_tv_template,
3448 .count = TGR128_TEST_VECTORS
3449 }
3450 }
3451 }, {
3452 .alg = "tgr160",
3453 .test = alg_test_hash,
3454 .suite = {
3455 .hash = {
3456 .vecs = tgr160_tv_template,
3457 .count = TGR160_TEST_VECTORS
3458 }
3459 }
3460 }, {
3461 .alg = "tgr192",
3462 .test = alg_test_hash,
3463 .suite = {
3464 .hash = {
3465 .vecs = tgr192_tv_template,
3466 .count = TGR192_TEST_VECTORS
3467 }
3468 }
3469 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003470 .alg = "vmac(aes)",
3471 .test = alg_test_hash,
3472 .suite = {
3473 .hash = {
3474 .vecs = aes_vmac128_tv_template,
3475 .count = VMAC_AES_TEST_VECTORS
3476 }
3477 }
3478 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003479 .alg = "wp256",
3480 .test = alg_test_hash,
3481 .suite = {
3482 .hash = {
3483 .vecs = wp256_tv_template,
3484 .count = WP256_TEST_VECTORS
3485 }
3486 }
3487 }, {
3488 .alg = "wp384",
3489 .test = alg_test_hash,
3490 .suite = {
3491 .hash = {
3492 .vecs = wp384_tv_template,
3493 .count = WP384_TEST_VECTORS
3494 }
3495 }
3496 }, {
3497 .alg = "wp512",
3498 .test = alg_test_hash,
3499 .suite = {
3500 .hash = {
3501 .vecs = wp512_tv_template,
3502 .count = WP512_TEST_VECTORS
3503 }
3504 }
3505 }, {
3506 .alg = "xcbc(aes)",
3507 .test = alg_test_hash,
3508 .suite = {
3509 .hash = {
3510 .vecs = aes_xcbc128_tv_template,
3511 .count = XCBC_AES_TEST_VECTORS
3512 }
3513 }
3514 }, {
3515 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003516 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003517 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003518 .suite = {
3519 .cipher = {
3520 .enc = {
3521 .vecs = aes_xts_enc_tv_template,
3522 .count = AES_XTS_ENC_TEST_VECTORS
3523 },
3524 .dec = {
3525 .vecs = aes_xts_dec_tv_template,
3526 .count = AES_XTS_DEC_TEST_VECTORS
3527 }
3528 }
3529 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003530 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003531 .alg = "xts(camellia)",
3532 .test = alg_test_skcipher,
3533 .suite = {
3534 .cipher = {
3535 .enc = {
3536 .vecs = camellia_xts_enc_tv_template,
3537 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3538 },
3539 .dec = {
3540 .vecs = camellia_xts_dec_tv_template,
3541 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3542 }
3543 }
3544 }
3545 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003546 .alg = "xts(cast6)",
3547 .test = alg_test_skcipher,
3548 .suite = {
3549 .cipher = {
3550 .enc = {
3551 .vecs = cast6_xts_enc_tv_template,
3552 .count = CAST6_XTS_ENC_TEST_VECTORS
3553 },
3554 .dec = {
3555 .vecs = cast6_xts_dec_tv_template,
3556 .count = CAST6_XTS_DEC_TEST_VECTORS
3557 }
3558 }
3559 }
3560 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003561 .alg = "xts(serpent)",
3562 .test = alg_test_skcipher,
3563 .suite = {
3564 .cipher = {
3565 .enc = {
3566 .vecs = serpent_xts_enc_tv_template,
3567 .count = SERPENT_XTS_ENC_TEST_VECTORS
3568 },
3569 .dec = {
3570 .vecs = serpent_xts_dec_tv_template,
3571 .count = SERPENT_XTS_DEC_TEST_VECTORS
3572 }
3573 }
3574 }
3575 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003576 .alg = "xts(twofish)",
3577 .test = alg_test_skcipher,
3578 .suite = {
3579 .cipher = {
3580 .enc = {
3581 .vecs = tf_xts_enc_tv_template,
3582 .count = TF_XTS_ENC_TEST_VECTORS
3583 },
3584 .dec = {
3585 .vecs = tf_xts_dec_tv_template,
3586 .count = TF_XTS_DEC_TEST_VECTORS
3587 }
3588 }
3589 }
3590 }, {
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003591 .alg = "zlib",
3592 .test = alg_test_pcomp,
Milan Broz08189042012-12-06 17:16:28 +08003593 .fips_allowed = 1,
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003594 .suite = {
3595 .pcomp = {
3596 .comp = {
3597 .vecs = zlib_comp_tv_template,
3598 .count = ZLIB_COMP_TEST_VECTORS
3599 },
3600 .decomp = {
3601 .vecs = zlib_decomp_tv_template,
3602 .count = ZLIB_DECOMP_TEST_VECTORS
3603 }
3604 }
3605 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003606 }
3607};
3608
Jussi Kivilinna57147582013-06-13 17:37:40 +03003609static bool alg_test_descs_checked;
3610
3611static void alg_test_descs_check_order(void)
3612{
3613 int i;
3614
3615 /* only check once */
3616 if (alg_test_descs_checked)
3617 return;
3618
3619 alg_test_descs_checked = true;
3620
3621 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3622 int diff = strcmp(alg_test_descs[i - 1].alg,
3623 alg_test_descs[i].alg);
3624
3625 if (WARN_ON(diff > 0)) {
3626 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3627 alg_test_descs[i - 1].alg,
3628 alg_test_descs[i].alg);
3629 }
3630
3631 if (WARN_ON(diff == 0)) {
3632 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3633 alg_test_descs[i].alg);
3634 }
3635 }
3636}
3637
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003638static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003639{
3640 int start = 0;
3641 int end = ARRAY_SIZE(alg_test_descs);
3642
3643 while (start < end) {
3644 int i = (start + end) / 2;
3645 int diff = strcmp(alg_test_descs[i].alg, alg);
3646
3647 if (diff > 0) {
3648 end = i;
3649 continue;
3650 }
3651
3652 if (diff < 0) {
3653 start = i + 1;
3654 continue;
3655 }
3656
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003657 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003658 }
3659
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003660 return -1;
3661}
3662
3663int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3664{
3665 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003666 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003667 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003668
Jussi Kivilinna57147582013-06-13 17:37:40 +03003669 alg_test_descs_check_order();
3670
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003671 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3672 char nalg[CRYPTO_MAX_ALG_NAME];
3673
3674 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3675 sizeof(nalg))
3676 return -ENAMETOOLONG;
3677
3678 i = alg_find_test(nalg);
3679 if (i < 0)
3680 goto notest;
3681
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003682 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3683 goto non_fips_alg;
3684
Jarod Wilson941fb322009-05-04 19:49:23 +08003685 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3686 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003687 }
3688
3689 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003690 j = alg_find_test(driver);
3691 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003692 goto notest;
3693
Herbert Xua68f6612009-07-02 16:32:12 +08003694 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3695 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003696 goto non_fips_alg;
3697
Herbert Xua68f6612009-07-02 16:32:12 +08003698 rc = 0;
3699 if (i >= 0)
3700 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3701 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003702 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003703 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3704 type, mask);
3705
Jarod Wilson941fb322009-05-04 19:49:23 +08003706test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003707 if (fips_enabled && rc)
3708 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3709
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003710 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09003711 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003712
Neil Hormand12d6b62008-10-12 20:36:51 +08003713 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003714
3715notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003716 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3717 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003718non_fips_alg:
3719 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003720}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003721
Herbert Xu326a6342010-08-06 09:40:28 +08003722#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003723
Herbert Xuda7f0332008-07-31 17:08:25 +08003724EXPORT_SYMBOL_GPL(alg_test);