blob: 758d02847308bb41bc80e06df8f2672739b4bc5c [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) {
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100184 wait_for_completion(&tr->completion);
Wolfram Sang16735d02013-11-14 14:32:02 -0800185 reinit_completion(&tr->completion);
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100186 ret = tr->err;
David S. Millera8f1a052010-05-19 14:12:03 +1000187 }
188 return ret;
189}
190
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300191static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
192 unsigned int tcount, bool use_digest,
193 const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800194{
195 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
196 unsigned int i, j, k, temp;
197 struct scatterlist sg[8];
Horia Geanta29b77e52014-07-23 11:59:38 +0300198 char *result;
199 char *key;
Herbert Xuda7f0332008-07-31 17:08:25 +0800200 struct ahash_request *req;
201 struct tcrypt_result tresult;
Herbert Xuda7f0332008-07-31 17:08:25 +0800202 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800203 char *xbuf[XBUFSIZE];
204 int ret = -ENOMEM;
205
Horia Geanta29b77e52014-07-23 11:59:38 +0300206 result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
207 if (!result)
208 return ret;
209 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
210 if (!key)
211 goto out_nobuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800212 if (testmgr_alloc_buf(xbuf))
213 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800214
215 init_completion(&tresult.completion);
216
217 req = ahash_request_alloc(tfm, GFP_KERNEL);
218 if (!req) {
219 printk(KERN_ERR "alg: hash: Failed to allocate request for "
220 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800221 goto out_noreq;
222 }
223 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
224 tcrypt_complete, &tresult);
225
Herbert Xua0cfae52009-05-29 16:23:12 +1000226 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800227 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000228 if (template[i].np)
229 continue;
230
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300231 ret = -EINVAL;
232 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
233 goto out;
234
Herbert Xua0cfae52009-05-29 16:23:12 +1000235 j++;
Horia Geanta29b77e52014-07-23 11:59:38 +0300236 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800237
238 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300239 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800240
241 memcpy(hash_buff, template[i].plaintext, template[i].psize);
242 sg_init_one(&sg[0], hash_buff, template[i].psize);
243
244 if (template[i].ksize) {
245 crypto_ahash_clear_flags(tfm, ~0);
Horia Geanta29b77e52014-07-23 11:59:38 +0300246 if (template[i].ksize > MAX_KEYLEN) {
247 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
248 j, algo, template[i].ksize, MAX_KEYLEN);
249 ret = -EINVAL;
250 goto out;
251 }
252 memcpy(key, template[i].key, template[i].ksize);
253 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
Herbert Xuda7f0332008-07-31 17:08:25 +0800254 if (ret) {
255 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000256 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800257 -ret);
258 goto out;
259 }
260 }
261
262 ahash_request_set_crypt(req, sg, result, template[i].psize);
David S. Millera8f1a052010-05-19 14:12:03 +1000263 if (use_digest) {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300264 ret = wait_async_op(&tresult, crypto_ahash_digest(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000265 if (ret) {
266 pr_err("alg: hash: digest failed on test %d "
267 "for %s: ret=%d\n", j, algo, -ret);
268 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800269 }
David S. Millera8f1a052010-05-19 14:12:03 +1000270 } else {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300271 ret = wait_async_op(&tresult, crypto_ahash_init(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000272 if (ret) {
273 pr_err("alt: hash: init failed on test %d "
274 "for %s: ret=%d\n", j, algo, -ret);
275 goto out;
276 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300277 ret = wait_async_op(&tresult, crypto_ahash_update(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000278 if (ret) {
279 pr_err("alt: hash: update failed on test %d "
280 "for %s: ret=%d\n", j, algo, -ret);
281 goto out;
282 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300283 ret = wait_async_op(&tresult, crypto_ahash_final(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000284 if (ret) {
285 pr_err("alt: hash: final failed on test %d "
286 "for %s: ret=%d\n", j, algo, -ret);
287 goto out;
288 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800289 }
290
291 if (memcmp(result, template[i].digest,
292 crypto_ahash_digestsize(tfm))) {
293 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000294 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800295 hexdump(result, crypto_ahash_digestsize(tfm));
296 ret = -EINVAL;
297 goto out;
298 }
299 }
300
301 j = 0;
302 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300303 /* alignment tests are only done with continuous buffers */
304 if (align_offset != 0)
305 break;
306
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300307 if (!template[i].np)
308 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800309
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300310 j++;
311 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800312
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300313 temp = 0;
314 sg_init_table(sg, template[i].np);
315 ret = -EINVAL;
316 for (k = 0; k < template[i].np; k++) {
317 if (WARN_ON(offset_in_page(IDX[k]) +
318 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +0800319 goto out;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300320 sg_set_buf(&sg[k],
321 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
322 offset_in_page(IDX[k]),
323 template[i].plaintext + temp,
324 template[i].tap[k]),
325 template[i].tap[k]);
326 temp += template[i].tap[k];
327 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800328
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300329 if (template[i].ksize) {
330 if (template[i].ksize > MAX_KEYLEN) {
331 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
332 j, algo, template[i].ksize, MAX_KEYLEN);
Herbert Xuda7f0332008-07-31 17:08:25 +0800333 ret = -EINVAL;
334 goto out;
335 }
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300336 crypto_ahash_clear_flags(tfm, ~0);
337 memcpy(key, template[i].key, template[i].ksize);
338 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
339
340 if (ret) {
341 printk(KERN_ERR "alg: hash: setkey "
342 "failed on chunking test %d "
343 "for %s: ret=%d\n", j, algo, -ret);
344 goto out;
345 }
346 }
347
348 ahash_request_set_crypt(req, sg, result, template[i].psize);
349 ret = crypto_ahash_digest(req);
350 switch (ret) {
351 case 0:
352 break;
353 case -EINPROGRESS:
354 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100355 wait_for_completion(&tresult.completion);
356 reinit_completion(&tresult.completion);
357 ret = tresult.err;
358 if (!ret)
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300359 break;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300360 /* fall through */
361 default:
362 printk(KERN_ERR "alg: hash: digest failed "
363 "on chunking test %d for %s: "
364 "ret=%d\n", j, algo, -ret);
365 goto out;
366 }
367
368 if (memcmp(result, template[i].digest,
369 crypto_ahash_digestsize(tfm))) {
370 printk(KERN_ERR "alg: hash: Chunking test %d "
371 "failed for %s\n", j, algo);
372 hexdump(result, crypto_ahash_digestsize(tfm));
373 ret = -EINVAL;
374 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800375 }
376 }
377
378 ret = 0;
379
380out:
381 ahash_request_free(req);
382out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800383 testmgr_free_buf(xbuf);
384out_nobuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300385 kfree(key);
386 kfree(result);
Herbert Xuda7f0332008-07-31 17:08:25 +0800387 return ret;
388}
389
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300390static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
391 unsigned int tcount, bool use_digest)
392{
393 unsigned int alignmask;
394 int ret;
395
396 ret = __test_hash(tfm, template, tcount, use_digest, 0);
397 if (ret)
398 return ret;
399
400 /* test unaligned buffers, check with one byte offset */
401 ret = __test_hash(tfm, template, tcount, use_digest, 1);
402 if (ret)
403 return ret;
404
405 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
406 if (alignmask) {
407 /* Check if alignment mask for tfm is correctly set. */
408 ret = __test_hash(tfm, template, tcount, use_digest,
409 alignmask + 1);
410 if (ret)
411 return ret;
412 }
413
414 return 0;
415}
416
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300417static int __test_aead(struct crypto_aead *tfm, int enc,
418 struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300419 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800420{
421 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
422 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800423 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800424 char *q;
425 char *key;
426 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300427 struct scatterlist *sg;
428 struct scatterlist *asg;
429 struct scatterlist *sgout;
430 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800431 struct tcrypt_result result;
432 unsigned int authsize;
433 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300434 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800435 void *assoc;
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700436 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800437 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300438 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800439 char *axbuf[XBUFSIZE];
440
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700441 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
442 if (!iv)
443 return ret;
Horia Geanta29b77e52014-07-23 11:59:38 +0300444 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
445 if (!key)
446 goto out_noxbuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800447 if (testmgr_alloc_buf(xbuf))
448 goto out_noxbuf;
449 if (testmgr_alloc_buf(axbuf))
450 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300451 if (diff_dst && testmgr_alloc_buf(xoutbuf))
452 goto out_nooutbuf;
453
454 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
455 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL);
456 if (!sg)
457 goto out_nosg;
458 asg = &sg[8];
459 sgout = &asg[8];
460
461 if (diff_dst)
462 d = "-ddst";
463 else
464 d = "";
465
Herbert Xuda7f0332008-07-31 17:08:25 +0800466 if (enc == ENCRYPT)
467 e = "encryption";
468 else
469 e = "decryption";
470
471 init_completion(&result.completion);
472
473 req = aead_request_alloc(tfm, GFP_KERNEL);
474 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300475 pr_err("alg: aead%s: Failed to allocate request for %s\n",
476 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800477 goto out;
478 }
479
480 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
481 tcrypt_complete, &result);
482
483 for (i = 0, j = 0; i < tcount; i++) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300484 if (template[i].np)
485 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800486
Cristian Stoica05b1d332014-07-28 13:11:23 +0300487 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800488
Cristian Stoica05b1d332014-07-28 13:11:23 +0300489 /* some templates have no input data but they will
490 * touch input
491 */
492 input = xbuf[0];
493 input += align_offset;
494 assoc = axbuf[0];
495
496 ret = -EINVAL;
497 if (WARN_ON(align_offset + template[i].ilen >
498 PAGE_SIZE || template[i].alen > PAGE_SIZE))
499 goto out;
500
501 memcpy(input, template[i].input, template[i].ilen);
502 memcpy(assoc, template[i].assoc, template[i].alen);
503 if (template[i].iv)
504 memcpy(iv, template[i].iv, MAX_IVLEN);
505 else
506 memset(iv, 0, MAX_IVLEN);
507
508 crypto_aead_clear_flags(tfm, ~0);
509 if (template[i].wk)
510 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
511
512 if (template[i].klen > MAX_KEYLEN) {
513 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
514 d, j, algo, template[i].klen,
515 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +1000516 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300517 goto out;
518 }
519 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +1000520
Cristian Stoica05b1d332014-07-28 13:11:23 +0300521 ret = crypto_aead_setkey(tfm, key, template[i].klen);
522 if (!ret == template[i].fail) {
523 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
524 d, j, algo, crypto_aead_get_flags(tfm));
525 goto out;
526 } else if (ret)
527 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800528
Cristian Stoica05b1d332014-07-28 13:11:23 +0300529 authsize = abs(template[i].rlen - template[i].ilen);
530 ret = crypto_aead_setauthsize(tfm, authsize);
531 if (ret) {
532 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
533 d, authsize, j, algo);
534 goto out;
535 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800536
Cristian Stoica05b1d332014-07-28 13:11:23 +0300537 if (diff_dst) {
538 output = xoutbuf[0];
539 output += align_offset;
540 sg_init_one(&sg[0], input, template[i].ilen);
541 sg_init_one(&sgout[0], output, template[i].rlen);
542 } else {
543 sg_init_one(&sg[0], input,
544 template[i].ilen + (enc ? authsize : 0));
545 output = input;
546 }
547
548 sg_init_one(&asg[0], assoc, template[i].alen);
549
550 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
551 template[i].ilen, iv);
552
553 aead_request_set_assoc(req, asg, template[i].alen);
554
555 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
556
557 switch (ret) {
558 case 0:
559 if (template[i].novrfy) {
560 /* verification was supposed to fail */
561 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
562 d, e, j, algo);
563 /* so really, we got a bad message */
564 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +0300565 goto out;
566 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300567 break;
568 case -EINPROGRESS:
569 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100570 wait_for_completion(&result.completion);
571 reinit_completion(&result.completion);
572 ret = result.err;
573 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +0800574 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300575 case -EBADMSG:
576 if (template[i].novrfy)
577 /* verification failure was expected */
578 continue;
579 /* fall through */
580 default:
581 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
582 d, e, j, algo, -ret);
583 goto out;
584 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800585
Cristian Stoica05b1d332014-07-28 13:11:23 +0300586 q = output;
587 if (memcmp(q, template[i].result, template[i].rlen)) {
588 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
589 d, j, e, algo);
590 hexdump(q, template[i].rlen);
591 ret = -EINVAL;
592 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800593 }
594 }
595
596 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300597 /* alignment tests are only done with continuous buffers */
598 if (align_offset != 0)
599 break;
600
Cristian Stoica05b1d332014-07-28 13:11:23 +0300601 if (!template[i].np)
602 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800603
Cristian Stoica05b1d332014-07-28 13:11:23 +0300604 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800605
Cristian Stoica05b1d332014-07-28 13:11:23 +0300606 if (template[i].iv)
607 memcpy(iv, template[i].iv, MAX_IVLEN);
608 else
609 memset(iv, 0, MAX_IVLEN);
610
611 crypto_aead_clear_flags(tfm, ~0);
612 if (template[i].wk)
613 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
614 if (template[i].klen > MAX_KEYLEN) {
615 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
616 d, j, algo, template[i].klen, MAX_KEYLEN);
617 ret = -EINVAL;
618 goto out;
619 }
620 memcpy(key, template[i].key, template[i].klen);
621
622 ret = crypto_aead_setkey(tfm, key, template[i].klen);
623 if (!ret == template[i].fail) {
624 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
625 d, j, algo, crypto_aead_get_flags(tfm));
626 goto out;
627 } else if (ret)
628 continue;
629
630 authsize = abs(template[i].rlen - template[i].ilen);
631
632 ret = -EINVAL;
633 sg_init_table(sg, template[i].np);
634 if (diff_dst)
635 sg_init_table(sgout, template[i].np);
636 for (k = 0, temp = 0; k < template[i].np; k++) {
637 if (WARN_ON(offset_in_page(IDX[k]) +
638 template[i].tap[k] > PAGE_SIZE))
639 goto out;
640
641 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
642 memcpy(q, template[i].input + temp, template[i].tap[k]);
643 sg_set_buf(&sg[k], q, template[i].tap[k]);
644
645 if (diff_dst) {
646 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
647 offset_in_page(IDX[k]);
648
649 memset(q, 0, template[i].tap[k]);
650
651 sg_set_buf(&sgout[k], q, template[i].tap[k]);
652 }
653
654 n = template[i].tap[k];
655 if (k == template[i].np - 1 && enc)
656 n += authsize;
657 if (offset_in_page(q) + n < PAGE_SIZE)
658 q[n] = 0;
659
660 temp += template[i].tap[k];
661 }
662
663 ret = crypto_aead_setauthsize(tfm, authsize);
664 if (ret) {
665 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
666 d, authsize, j, algo);
667 goto out;
668 }
669
670 if (enc) {
671 if (WARN_ON(sg[k - 1].offset +
672 sg[k - 1].length + authsize >
673 PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300674 ret = -EINVAL;
675 goto out;
676 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800677
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300678 if (diff_dst)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300679 sgout[k - 1].length += authsize;
680 else
681 sg[k - 1].length += authsize;
682 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800683
Cristian Stoica05b1d332014-07-28 13:11:23 +0300684 sg_init_table(asg, template[i].anp);
685 ret = -EINVAL;
686 for (k = 0, temp = 0; k < template[i].anp; k++) {
687 if (WARN_ON(offset_in_page(IDX[k]) +
688 template[i].atap[k] > PAGE_SIZE))
689 goto out;
690 sg_set_buf(&asg[k],
691 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
692 offset_in_page(IDX[k]),
693 template[i].assoc + temp,
694 template[i].atap[k]),
695 template[i].atap[k]);
696 temp += template[i].atap[k];
697 }
698
699 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
700 template[i].ilen,
701 iv);
702
703 aead_request_set_assoc(req, asg, template[i].alen);
704
705 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
706
707 switch (ret) {
708 case 0:
709 if (template[i].novrfy) {
710 /* verification was supposed to fail */
711 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
712 d, e, j, algo);
713 /* so really, we got a bad message */
714 ret = -EBADMSG;
715 goto out;
716 }
717 break;
718 case -EINPROGRESS:
719 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100720 wait_for_completion(&result.completion);
721 reinit_completion(&result.completion);
722 ret = result.err;
723 if (!ret)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300724 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300725 case -EBADMSG:
726 if (template[i].novrfy)
727 /* verification failure was expected */
728 continue;
729 /* fall through */
730 default:
731 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
732 d, e, j, algo, -ret);
733 goto out;
734 }
735
736 ret = -EINVAL;
737 for (k = 0, temp = 0; k < template[i].np; k++) {
738 if (diff_dst)
739 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
740 offset_in_page(IDX[k]);
741 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800742 q = xbuf[IDX[k] >> PAGE_SHIFT] +
743 offset_in_page(IDX[k]);
744
Cristian Stoica05b1d332014-07-28 13:11:23 +0300745 n = template[i].tap[k];
746 if (k == template[i].np - 1)
747 n += enc ? authsize : -authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800748
Cristian Stoica05b1d332014-07-28 13:11:23 +0300749 if (memcmp(q, template[i].result + temp, n)) {
750 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
751 d, j, e, k, algo);
752 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800753 goto out;
754 }
755
Cristian Stoica05b1d332014-07-28 13:11:23 +0300756 q += n;
757 if (k == template[i].np - 1 && !enc) {
758 if (!diff_dst &&
759 memcmp(q, template[i].input +
760 temp + n, authsize))
761 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200762 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300763 n = 0;
764 } else {
765 for (n = 0; offset_in_page(q + n) && q[n]; n++)
766 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800767 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300768 if (n) {
769 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
770 d, j, e, k, algo, n);
771 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800772 goto out;
773 }
774
Cristian Stoica05b1d332014-07-28 13:11:23 +0300775 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800776 }
777 }
778
779 ret = 0;
780
781out:
782 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300783 kfree(sg);
784out_nosg:
785 if (diff_dst)
786 testmgr_free_buf(xoutbuf);
787out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800788 testmgr_free_buf(axbuf);
789out_noaxbuf:
790 testmgr_free_buf(xbuf);
791out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300792 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700793 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800794 return ret;
795}
796
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300797static int test_aead(struct crypto_aead *tfm, int enc,
798 struct aead_testvec *template, unsigned int tcount)
799{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300800 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300801 int ret;
802
803 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300804 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300805 if (ret)
806 return ret;
807
808 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300809 ret = __test_aead(tfm, enc, template, tcount, true, 0);
810 if (ret)
811 return ret;
812
813 /* test unaligned buffers, check with one byte offset */
814 ret = __test_aead(tfm, enc, template, tcount, true, 1);
815 if (ret)
816 return ret;
817
818 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
819 if (alignmask) {
820 /* Check if alignment mask for tfm is correctly set. */
821 ret = __test_aead(tfm, enc, template, tcount, true,
822 alignmask + 1);
823 if (ret)
824 return ret;
825 }
826
827 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300828}
829
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000830static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800831 struct cipher_testvec *template, unsigned int tcount)
832{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000833 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
834 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000835 char *q;
836 const char *e;
837 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800838 char *xbuf[XBUFSIZE];
839 int ret = -ENOMEM;
840
841 if (testmgr_alloc_buf(xbuf))
842 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000843
844 if (enc == ENCRYPT)
845 e = "encryption";
846 else
847 e = "decryption";
848
849 j = 0;
850 for (i = 0; i < tcount; i++) {
851 if (template[i].np)
852 continue;
853
854 j++;
855
Herbert Xufd57f222009-05-29 16:05:42 +1000856 ret = -EINVAL;
857 if (WARN_ON(template[i].ilen > PAGE_SIZE))
858 goto out;
859
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000860 data = xbuf[0];
861 memcpy(data, template[i].input, template[i].ilen);
862
863 crypto_cipher_clear_flags(tfm, ~0);
864 if (template[i].wk)
865 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
866
867 ret = crypto_cipher_setkey(tfm, template[i].key,
868 template[i].klen);
869 if (!ret == template[i].fail) {
870 printk(KERN_ERR "alg: cipher: setkey failed "
871 "on test %d for %s: flags=%x\n", j,
872 algo, crypto_cipher_get_flags(tfm));
873 goto out;
874 } else if (ret)
875 continue;
876
877 for (k = 0; k < template[i].ilen;
878 k += crypto_cipher_blocksize(tfm)) {
879 if (enc)
880 crypto_cipher_encrypt_one(tfm, data + k,
881 data + k);
882 else
883 crypto_cipher_decrypt_one(tfm, data + k,
884 data + k);
885 }
886
887 q = data;
888 if (memcmp(q, template[i].result, template[i].rlen)) {
889 printk(KERN_ERR "alg: cipher: Test %d failed "
890 "on %s for %s\n", j, e, algo);
891 hexdump(q, template[i].rlen);
892 ret = -EINVAL;
893 goto out;
894 }
895 }
896
897 ret = 0;
898
899out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800900 testmgr_free_buf(xbuf);
901out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000902 return ret;
903}
904
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300905static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
906 struct cipher_testvec *template, unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300907 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000908{
Herbert Xuda7f0332008-07-31 17:08:25 +0800909 const char *algo =
910 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
911 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800912 char *q;
913 struct ablkcipher_request *req;
914 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300915 struct scatterlist sgout[8];
916 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800917 struct tcrypt_result result;
918 void *data;
919 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800920 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300921 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800922 int ret = -ENOMEM;
923
924 if (testmgr_alloc_buf(xbuf))
925 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800926
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300927 if (diff_dst && testmgr_alloc_buf(xoutbuf))
928 goto out_nooutbuf;
929
930 if (diff_dst)
931 d = "-ddst";
932 else
933 d = "";
934
Herbert Xuda7f0332008-07-31 17:08:25 +0800935 if (enc == ENCRYPT)
936 e = "encryption";
937 else
938 e = "decryption";
939
940 init_completion(&result.completion);
941
942 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
943 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300944 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
945 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800946 goto out;
947 }
948
949 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
950 tcrypt_complete, &result);
951
952 j = 0;
953 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +0300954 if (template[i].np && !template[i].also_non_np)
955 continue;
956
Herbert Xuda7f0332008-07-31 17:08:25 +0800957 if (template[i].iv)
958 memcpy(iv, template[i].iv, MAX_IVLEN);
959 else
960 memset(iv, 0, MAX_IVLEN);
961
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300962 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300963 ret = -EINVAL;
964 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
965 goto out;
966
967 data = xbuf[0];
968 data += align_offset;
969 memcpy(data, template[i].input, template[i].ilen);
970
971 crypto_ablkcipher_clear_flags(tfm, ~0);
972 if (template[i].wk)
973 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
974
975 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
976 template[i].klen);
977 if (!ret == template[i].fail) {
978 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
979 d, j, algo, crypto_ablkcipher_get_flags(tfm));
980 goto out;
981 } else if (ret)
982 continue;
983
984 sg_init_one(&sg[0], data, template[i].ilen);
985 if (diff_dst) {
986 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300987 data += align_offset;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300988 sg_init_one(&sgout[0], data, template[i].ilen);
989 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800990
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300991 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
992 template[i].ilen, iv);
993 ret = enc ? crypto_ablkcipher_encrypt(req) :
994 crypto_ablkcipher_decrypt(req);
Herbert Xuda7f0332008-07-31 17:08:25 +0800995
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300996 switch (ret) {
997 case 0:
998 break;
999 case -EINPROGRESS:
1000 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001001 wait_for_completion(&result.completion);
1002 reinit_completion(&result.completion);
1003 ret = result.err;
1004 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +08001005 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001006 /* fall through */
1007 default:
1008 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1009 d, e, j, algo, -ret);
1010 goto out;
1011 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001012
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001013 q = data;
1014 if (memcmp(q, template[i].result, template[i].rlen)) {
1015 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1016 d, j, e, algo);
1017 hexdump(q, template[i].rlen);
1018 ret = -EINVAL;
1019 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001020 }
1021 }
1022
1023 j = 0;
1024 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001025 /* alignment tests are only done with continuous buffers */
1026 if (align_offset != 0)
1027 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001028
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001029 if (!template[i].np)
1030 continue;
1031
Herbert Xuda7f0332008-07-31 17:08:25 +08001032 if (template[i].iv)
1033 memcpy(iv, template[i].iv, MAX_IVLEN);
1034 else
1035 memset(iv, 0, MAX_IVLEN);
1036
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001037 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001038 crypto_ablkcipher_clear_flags(tfm, ~0);
1039 if (template[i].wk)
1040 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1041
1042 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1043 template[i].klen);
1044 if (!ret == template[i].fail) {
1045 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1046 d, j, algo, crypto_ablkcipher_get_flags(tfm));
1047 goto out;
1048 } else if (ret)
1049 continue;
1050
1051 temp = 0;
1052 ret = -EINVAL;
1053 sg_init_table(sg, template[i].np);
1054 if (diff_dst)
1055 sg_init_table(sgout, template[i].np);
1056 for (k = 0; k < template[i].np; k++) {
1057 if (WARN_ON(offset_in_page(IDX[k]) +
1058 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001059 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001060
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001061 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1062
1063 memcpy(q, template[i].input + temp, template[i].tap[k]);
1064
1065 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1066 q[template[i].tap[k]] = 0;
1067
1068 sg_set_buf(&sg[k], q, template[i].tap[k]);
1069 if (diff_dst) {
1070 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1071 offset_in_page(IDX[k]);
1072
1073 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1074
1075 memset(q, 0, template[i].tap[k]);
1076 if (offset_in_page(q) +
1077 template[i].tap[k] < PAGE_SIZE)
1078 q[template[i].tap[k]] = 0;
1079 }
1080
1081 temp += template[i].tap[k];
1082 }
1083
1084 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1085 template[i].ilen, iv);
1086
1087 ret = enc ? crypto_ablkcipher_encrypt(req) :
1088 crypto_ablkcipher_decrypt(req);
1089
1090 switch (ret) {
1091 case 0:
1092 break;
1093 case -EINPROGRESS:
1094 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001095 wait_for_completion(&result.completion);
1096 reinit_completion(&result.completion);
1097 ret = result.err;
1098 if (!ret)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001099 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001100 /* fall through */
1101 default:
1102 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1103 d, e, j, algo, -ret);
1104 goto out;
1105 }
1106
1107 temp = 0;
1108 ret = -EINVAL;
1109 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001110 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001111 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1112 offset_in_page(IDX[k]);
1113 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001114 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1115 offset_in_page(IDX[k]);
1116
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001117 if (memcmp(q, template[i].result + temp,
1118 template[i].tap[k])) {
1119 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1120 d, j, e, k, algo);
1121 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001122 goto out;
1123 }
1124
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001125 q += template[i].tap[k];
1126 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1127 ;
1128 if (n) {
1129 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1130 d, j, e, k, algo, n);
1131 hexdump(q, n);
1132 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001133 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001134 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001135 }
1136 }
1137
1138 ret = 0;
1139
1140out:
1141 ablkcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001142 if (diff_dst)
1143 testmgr_free_buf(xoutbuf);
1144out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001145 testmgr_free_buf(xbuf);
1146out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001147 return ret;
1148}
1149
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001150static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1151 struct cipher_testvec *template, unsigned int tcount)
1152{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001153 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001154 int ret;
1155
1156 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001157 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001158 if (ret)
1159 return ret;
1160
1161 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001162 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1163 if (ret)
1164 return ret;
1165
1166 /* test unaligned buffers, check with one byte offset */
1167 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1168 if (ret)
1169 return ret;
1170
1171 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1172 if (alignmask) {
1173 /* Check if alignment mask for tfm is correctly set. */
1174 ret = __test_skcipher(tfm, enc, template, tcount, true,
1175 alignmask + 1);
1176 if (ret)
1177 return ret;
1178 }
1179
1180 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001181}
1182
Herbert Xuda7f0332008-07-31 17:08:25 +08001183static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1184 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1185{
1186 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1187 unsigned int i;
1188 char result[COMP_BUF_SIZE];
1189 int ret;
1190
1191 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001192 int ilen;
1193 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001194
1195 memset(result, 0, sizeof (result));
1196
1197 ilen = ctemplate[i].inlen;
1198 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1199 ilen, result, &dlen);
1200 if (ret) {
1201 printk(KERN_ERR "alg: comp: compression failed "
1202 "on test %d for %s: ret=%d\n", i + 1, algo,
1203 -ret);
1204 goto out;
1205 }
1206
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001207 if (dlen != ctemplate[i].outlen) {
1208 printk(KERN_ERR "alg: comp: Compression test %d "
1209 "failed for %s: output len = %d\n", i + 1, algo,
1210 dlen);
1211 ret = -EINVAL;
1212 goto out;
1213 }
1214
Herbert Xuda7f0332008-07-31 17:08:25 +08001215 if (memcmp(result, ctemplate[i].output, dlen)) {
1216 printk(KERN_ERR "alg: comp: Compression test %d "
1217 "failed for %s\n", i + 1, algo);
1218 hexdump(result, dlen);
1219 ret = -EINVAL;
1220 goto out;
1221 }
1222 }
1223
1224 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001225 int ilen;
1226 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001227
1228 memset(result, 0, sizeof (result));
1229
1230 ilen = dtemplate[i].inlen;
1231 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1232 ilen, result, &dlen);
1233 if (ret) {
1234 printk(KERN_ERR "alg: comp: decompression failed "
1235 "on test %d for %s: ret=%d\n", i + 1, algo,
1236 -ret);
1237 goto out;
1238 }
1239
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001240 if (dlen != dtemplate[i].outlen) {
1241 printk(KERN_ERR "alg: comp: Decompression test %d "
1242 "failed for %s: output len = %d\n", i + 1, algo,
1243 dlen);
1244 ret = -EINVAL;
1245 goto out;
1246 }
1247
Herbert Xuda7f0332008-07-31 17:08:25 +08001248 if (memcmp(result, dtemplate[i].output, dlen)) {
1249 printk(KERN_ERR "alg: comp: Decompression test %d "
1250 "failed for %s\n", i + 1, algo);
1251 hexdump(result, dlen);
1252 ret = -EINVAL;
1253 goto out;
1254 }
1255 }
1256
1257 ret = 0;
1258
1259out:
1260 return ret;
1261}
1262
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001263static int test_pcomp(struct crypto_pcomp *tfm,
1264 struct pcomp_testvec *ctemplate,
1265 struct pcomp_testvec *dtemplate, int ctcount,
1266 int dtcount)
1267{
1268 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1269 unsigned int i;
1270 char result[COMP_BUF_SIZE];
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001271 int res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001272
1273 for (i = 0; i < ctcount; i++) {
1274 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001275 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001276
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001277 res = crypto_compress_setup(tfm, ctemplate[i].params,
1278 ctemplate[i].paramsize);
1279 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001280 pr_err("alg: pcomp: compression setup failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001281 "%d for %s: error=%d\n", i + 1, algo, res);
1282 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001283 }
1284
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001285 res = crypto_compress_init(tfm);
1286 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001287 pr_err("alg: pcomp: compression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001288 "%d for %s: error=%d\n", i + 1, algo, res);
1289 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001290 }
1291
1292 memset(result, 0, sizeof(result));
1293
1294 req.next_in = ctemplate[i].input;
1295 req.avail_in = ctemplate[i].inlen / 2;
1296 req.next_out = result;
1297 req.avail_out = ctemplate[i].outlen / 2;
1298
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001299 res = crypto_compress_update(tfm, &req);
1300 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001301 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001302 "%d for %s: error=%d\n", i + 1, algo, res);
1303 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001304 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001305 if (res > 0)
1306 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001307
1308 /* Add remaining input data */
1309 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1310
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001311 res = crypto_compress_update(tfm, &req);
1312 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001313 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001314 "%d for %s: error=%d\n", i + 1, algo, res);
1315 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001316 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001317 if (res > 0)
1318 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001319
1320 /* Provide remaining output space */
1321 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1322
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001323 res = crypto_compress_final(tfm, &req);
1324 if (res < 0) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001325 pr_err("alg: pcomp: compression final failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001326 "%d for %s: error=%d\n", i + 1, algo, res);
1327 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001328 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001329 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001330
1331 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1332 pr_err("alg: comp: Compression test %d failed for %s: "
1333 "output len = %d (expected %d)\n", i + 1, algo,
1334 COMP_BUF_SIZE - req.avail_out,
1335 ctemplate[i].outlen);
1336 return -EINVAL;
1337 }
1338
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001339 if (produced != ctemplate[i].outlen) {
1340 pr_err("alg: comp: Compression test %d failed for %s: "
1341 "returned len = %u (expected %d)\n", i + 1,
1342 algo, produced, ctemplate[i].outlen);
1343 return -EINVAL;
1344 }
1345
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001346 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1347 pr_err("alg: pcomp: Compression test %d failed for "
1348 "%s\n", i + 1, algo);
1349 hexdump(result, ctemplate[i].outlen);
1350 return -EINVAL;
1351 }
1352 }
1353
1354 for (i = 0; i < dtcount; i++) {
1355 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001356 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001357
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001358 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1359 dtemplate[i].paramsize);
1360 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001361 pr_err("alg: pcomp: decompression setup failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001362 "test %d for %s: error=%d\n", i + 1, algo, res);
1363 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001364 }
1365
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001366 res = crypto_decompress_init(tfm);
1367 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001368 pr_err("alg: pcomp: decompression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001369 "%d for %s: error=%d\n", i + 1, algo, res);
1370 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001371 }
1372
1373 memset(result, 0, sizeof(result));
1374
1375 req.next_in = dtemplate[i].input;
1376 req.avail_in = dtemplate[i].inlen / 2;
1377 req.next_out = result;
1378 req.avail_out = dtemplate[i].outlen / 2;
1379
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001380 res = crypto_decompress_update(tfm, &req);
1381 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001382 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001383 "test %d for %s: error=%d\n", i + 1, algo, res);
1384 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001385 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001386 if (res > 0)
1387 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001388
1389 /* Add remaining input data */
1390 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1391
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001392 res = crypto_decompress_update(tfm, &req);
1393 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001394 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001395 "test %d for %s: error=%d\n", i + 1, algo, res);
1396 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001397 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001398 if (res > 0)
1399 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001400
1401 /* Provide remaining output space */
1402 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1403
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001404 res = crypto_decompress_final(tfm, &req);
1405 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001406 pr_err("alg: pcomp: decompression final failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001407 "test %d for %s: error=%d\n", i + 1, algo, res);
1408 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001409 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001410 if (res > 0)
1411 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001412
1413 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1414 pr_err("alg: comp: Decompression test %d failed for "
1415 "%s: output len = %d (expected %d)\n", i + 1,
1416 algo, COMP_BUF_SIZE - req.avail_out,
1417 dtemplate[i].outlen);
1418 return -EINVAL;
1419 }
1420
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001421 if (produced != dtemplate[i].outlen) {
1422 pr_err("alg: comp: Decompression test %d failed for "
1423 "%s: returned len = %u (expected %d)\n", i + 1,
1424 algo, produced, dtemplate[i].outlen);
1425 return -EINVAL;
1426 }
1427
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001428 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1429 pr_err("alg: pcomp: Decompression test %d failed for "
1430 "%s\n", i + 1, algo);
1431 hexdump(result, dtemplate[i].outlen);
1432 return -EINVAL;
1433 }
1434 }
1435
1436 return 0;
1437}
1438
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001439
1440static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1441 unsigned int tcount)
1442{
1443 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001444 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001445 u8 *seed;
1446 char result[32];
1447
1448 seedsize = crypto_rng_seedsize(tfm);
1449
1450 seed = kmalloc(seedsize, GFP_KERNEL);
1451 if (!seed) {
1452 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1453 "for %s\n", algo);
1454 return -ENOMEM;
1455 }
1456
1457 for (i = 0; i < tcount; i++) {
1458 memset(result, 0, 32);
1459
1460 memcpy(seed, template[i].v, template[i].vlen);
1461 memcpy(seed + template[i].vlen, template[i].key,
1462 template[i].klen);
1463 memcpy(seed + template[i].vlen + template[i].klen,
1464 template[i].dt, template[i].dtlen);
1465
1466 err = crypto_rng_reset(tfm, seed, seedsize);
1467 if (err) {
1468 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1469 "for %s\n", algo);
1470 goto out;
1471 }
1472
1473 for (j = 0; j < template[i].loops; j++) {
1474 err = crypto_rng_get_bytes(tfm, result,
1475 template[i].rlen);
1476 if (err != template[i].rlen) {
1477 printk(KERN_ERR "alg: cprng: Failed to obtain "
1478 "the correct amount of random data for "
1479 "%s (requested %d, got %d)\n", algo,
1480 template[i].rlen, err);
1481 goto out;
1482 }
1483 }
1484
1485 err = memcmp(result, template[i].result,
1486 template[i].rlen);
1487 if (err) {
1488 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1489 i, algo);
1490 hexdump(result, template[i].rlen);
1491 err = -EINVAL;
1492 goto out;
1493 }
1494 }
1495
1496out:
1497 kfree(seed);
1498 return err;
1499}
1500
Herbert Xuda7f0332008-07-31 17:08:25 +08001501static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1502 u32 type, u32 mask)
1503{
1504 struct crypto_aead *tfm;
1505 int err = 0;
1506
1507 tfm = crypto_alloc_aead(driver, type, mask);
1508 if (IS_ERR(tfm)) {
1509 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1510 "%ld\n", driver, PTR_ERR(tfm));
1511 return PTR_ERR(tfm);
1512 }
1513
1514 if (desc->suite.aead.enc.vecs) {
1515 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1516 desc->suite.aead.enc.count);
1517 if (err)
1518 goto out;
1519 }
1520
1521 if (!err && desc->suite.aead.dec.vecs)
1522 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1523 desc->suite.aead.dec.count);
1524
1525out:
1526 crypto_free_aead(tfm);
1527 return err;
1528}
1529
1530static int alg_test_cipher(const struct alg_test_desc *desc,
1531 const char *driver, u32 type, u32 mask)
1532{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001533 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001534 int err = 0;
1535
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001536 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001537 if (IS_ERR(tfm)) {
1538 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1539 "%s: %ld\n", driver, PTR_ERR(tfm));
1540 return PTR_ERR(tfm);
1541 }
1542
1543 if (desc->suite.cipher.enc.vecs) {
1544 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1545 desc->suite.cipher.enc.count);
1546 if (err)
1547 goto out;
1548 }
1549
1550 if (desc->suite.cipher.dec.vecs)
1551 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1552 desc->suite.cipher.dec.count);
1553
1554out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001555 crypto_free_cipher(tfm);
1556 return err;
1557}
1558
1559static int alg_test_skcipher(const struct alg_test_desc *desc,
1560 const char *driver, u32 type, u32 mask)
1561{
1562 struct crypto_ablkcipher *tfm;
1563 int err = 0;
1564
1565 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1566 if (IS_ERR(tfm)) {
1567 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1568 "%s: %ld\n", driver, PTR_ERR(tfm));
1569 return PTR_ERR(tfm);
1570 }
1571
1572 if (desc->suite.cipher.enc.vecs) {
1573 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1574 desc->suite.cipher.enc.count);
1575 if (err)
1576 goto out;
1577 }
1578
1579 if (desc->suite.cipher.dec.vecs)
1580 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1581 desc->suite.cipher.dec.count);
1582
1583out:
Herbert Xuda7f0332008-07-31 17:08:25 +08001584 crypto_free_ablkcipher(tfm);
1585 return err;
1586}
1587
1588static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1589 u32 type, u32 mask)
1590{
1591 struct crypto_comp *tfm;
1592 int err;
1593
1594 tfm = crypto_alloc_comp(driver, type, mask);
1595 if (IS_ERR(tfm)) {
1596 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1597 "%ld\n", driver, PTR_ERR(tfm));
1598 return PTR_ERR(tfm);
1599 }
1600
1601 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1602 desc->suite.comp.decomp.vecs,
1603 desc->suite.comp.comp.count,
1604 desc->suite.comp.decomp.count);
1605
1606 crypto_free_comp(tfm);
1607 return err;
1608}
1609
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001610static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1611 u32 type, u32 mask)
1612{
1613 struct crypto_pcomp *tfm;
1614 int err;
1615
1616 tfm = crypto_alloc_pcomp(driver, type, mask);
1617 if (IS_ERR(tfm)) {
1618 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1619 driver, PTR_ERR(tfm));
1620 return PTR_ERR(tfm);
1621 }
1622
1623 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1624 desc->suite.pcomp.decomp.vecs,
1625 desc->suite.pcomp.comp.count,
1626 desc->suite.pcomp.decomp.count);
1627
1628 crypto_free_pcomp(tfm);
1629 return err;
1630}
1631
Herbert Xuda7f0332008-07-31 17:08:25 +08001632static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1633 u32 type, u32 mask)
1634{
1635 struct crypto_ahash *tfm;
1636 int err;
1637
1638 tfm = crypto_alloc_ahash(driver, type, mask);
1639 if (IS_ERR(tfm)) {
1640 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1641 "%ld\n", driver, PTR_ERR(tfm));
1642 return PTR_ERR(tfm);
1643 }
1644
David S. Millera8f1a052010-05-19 14:12:03 +10001645 err = test_hash(tfm, desc->suite.hash.vecs,
1646 desc->suite.hash.count, true);
1647 if (!err)
1648 err = test_hash(tfm, desc->suite.hash.vecs,
1649 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001650
1651 crypto_free_ahash(tfm);
1652 return err;
1653}
1654
Herbert Xu8e3ee852008-11-07 14:58:52 +08001655static int alg_test_crc32c(const struct alg_test_desc *desc,
1656 const char *driver, u32 type, u32 mask)
1657{
1658 struct crypto_shash *tfm;
1659 u32 val;
1660 int err;
1661
1662 err = alg_test_hash(desc, driver, type, mask);
1663 if (err)
1664 goto out;
1665
1666 tfm = crypto_alloc_shash(driver, type, mask);
1667 if (IS_ERR(tfm)) {
1668 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1669 "%ld\n", driver, PTR_ERR(tfm));
1670 err = PTR_ERR(tfm);
1671 goto out;
1672 }
1673
1674 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001675 SHASH_DESC_ON_STACK(shash, tfm);
1676 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001677
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001678 shash->tfm = tfm;
1679 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001680
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001681 *ctx = le32_to_cpu(420553207);
1682 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001683 if (err) {
1684 printk(KERN_ERR "alg: crc32c: Operation failed for "
1685 "%s: %d\n", driver, err);
1686 break;
1687 }
1688
1689 if (val != ~420553207) {
1690 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1691 "%d\n", driver, val);
1692 err = -EINVAL;
1693 }
1694 } while (0);
1695
1696 crypto_free_shash(tfm);
1697
1698out:
1699 return err;
1700}
1701
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001702static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1703 u32 type, u32 mask)
1704{
1705 struct crypto_rng *rng;
1706 int err;
1707
1708 rng = crypto_alloc_rng(driver, type, mask);
1709 if (IS_ERR(rng)) {
1710 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1711 "%ld\n", driver, PTR_ERR(rng));
1712 return PTR_ERR(rng);
1713 }
1714
1715 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1716
1717 crypto_free_rng(rng);
1718
1719 return err;
1720}
1721
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001722
1723static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1724 const char *driver, u32 type, u32 mask)
1725{
1726 int ret = -EAGAIN;
1727 struct crypto_rng *drng;
1728 struct drbg_test_data test_data;
1729 struct drbg_string addtl, pers, testentropy;
1730 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1731
1732 if (!buf)
1733 return -ENOMEM;
1734
1735 drng = crypto_alloc_rng(driver, type, mask);
1736 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001737 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001738 "%s\n", driver);
1739 kzfree(buf);
1740 return -ENOMEM;
1741 }
1742
1743 test_data.testentropy = &testentropy;
1744 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1745 drbg_string_fill(&pers, test->pers, test->perslen);
1746 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1747 if (ret) {
1748 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1749 goto outbuf;
1750 }
1751
1752 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1753 if (pr) {
1754 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1755 ret = crypto_drbg_get_bytes_addtl_test(drng,
1756 buf, test->expectedlen, &addtl, &test_data);
1757 } else {
1758 ret = crypto_drbg_get_bytes_addtl(drng,
1759 buf, test->expectedlen, &addtl);
1760 }
1761 if (ret <= 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001762 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001763 "driver %s\n", driver);
1764 goto outbuf;
1765 }
1766
1767 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1768 if (pr) {
1769 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1770 ret = crypto_drbg_get_bytes_addtl_test(drng,
1771 buf, test->expectedlen, &addtl, &test_data);
1772 } else {
1773 ret = crypto_drbg_get_bytes_addtl(drng,
1774 buf, test->expectedlen, &addtl);
1775 }
1776 if (ret <= 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001777 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001778 "driver %s\n", driver);
1779 goto outbuf;
1780 }
1781
1782 ret = memcmp(test->expected, buf, test->expectedlen);
1783
1784outbuf:
1785 crypto_free_rng(drng);
1786 kzfree(buf);
1787 return ret;
1788}
1789
1790
1791static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1792 u32 type, u32 mask)
1793{
1794 int err = 0;
1795 int pr = 0;
1796 int i = 0;
1797 struct drbg_testvec *template = desc->suite.drbg.vecs;
1798 unsigned int tcount = desc->suite.drbg.count;
1799
1800 if (0 == memcmp(driver, "drbg_pr_", 8))
1801 pr = 1;
1802
1803 for (i = 0; i < tcount; i++) {
1804 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1805 if (err) {
1806 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1807 i, driver);
1808 err = -EINVAL;
1809 break;
1810 }
1811 }
1812 return err;
1813
1814}
1815
Youquan, Song863b5572009-12-23 19:45:20 +08001816static int alg_test_null(const struct alg_test_desc *desc,
1817 const char *driver, u32 type, u32 mask)
1818{
1819 return 0;
1820}
1821
Herbert Xuda7f0332008-07-31 17:08:25 +08001822/* Please keep this list sorted by algorithm name. */
1823static const struct alg_test_desc alg_test_descs[] = {
1824 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001825 .alg = "__cbc-cast5-avx",
1826 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001827 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001828 .alg = "__cbc-cast6-avx",
1829 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001830 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001831 .alg = "__cbc-serpent-avx",
1832 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001833 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001834 .alg = "__cbc-serpent-avx2",
1835 .test = alg_test_null,
1836 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001837 .alg = "__cbc-serpent-sse2",
1838 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001839 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001840 .alg = "__cbc-twofish-avx",
1841 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001842 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001843 .alg = "__driver-cbc-aes-aesni",
1844 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001845 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001846 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001847 .alg = "__driver-cbc-camellia-aesni",
1848 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001849 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001850 .alg = "__driver-cbc-camellia-aesni-avx2",
1851 .test = alg_test_null,
1852 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001853 .alg = "__driver-cbc-cast5-avx",
1854 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001855 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001856 .alg = "__driver-cbc-cast6-avx",
1857 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001858 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001859 .alg = "__driver-cbc-serpent-avx",
1860 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001861 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001862 .alg = "__driver-cbc-serpent-avx2",
1863 .test = alg_test_null,
1864 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001865 .alg = "__driver-cbc-serpent-sse2",
1866 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001867 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001868 .alg = "__driver-cbc-twofish-avx",
1869 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001870 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001871 .alg = "__driver-ecb-aes-aesni",
1872 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001873 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001874 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001875 .alg = "__driver-ecb-camellia-aesni",
1876 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001877 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001878 .alg = "__driver-ecb-camellia-aesni-avx2",
1879 .test = alg_test_null,
1880 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001881 .alg = "__driver-ecb-cast5-avx",
1882 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001883 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001884 .alg = "__driver-ecb-cast6-avx",
1885 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001886 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001887 .alg = "__driver-ecb-serpent-avx",
1888 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001889 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001890 .alg = "__driver-ecb-serpent-avx2",
1891 .test = alg_test_null,
1892 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001893 .alg = "__driver-ecb-serpent-sse2",
1894 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001895 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001896 .alg = "__driver-ecb-twofish-avx",
1897 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001898 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001899 .alg = "__ghash-pclmulqdqni",
1900 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001901 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001902 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001903 .alg = "ansi_cprng",
1904 .test = alg_test_cprng,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001905 .fips_allowed = 1,
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001906 .suite = {
1907 .cprng = {
1908 .vecs = ansi_cprng_aes_tv_template,
1909 .count = ANSI_CPRNG_AES_TEST_VECTORS
1910 }
1911 }
1912 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001913 .alg = "authenc(hmac(md5),ecb(cipher_null))",
1914 .test = alg_test_aead,
1915 .fips_allowed = 1,
1916 .suite = {
1917 .aead = {
1918 .enc = {
1919 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
1920 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1921 },
1922 .dec = {
1923 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
1924 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1925 }
1926 }
1927 }
1928 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03001929 .alg = "authenc(hmac(sha1),cbc(aes))",
1930 .test = alg_test_aead,
1931 .fips_allowed = 1,
1932 .suite = {
1933 .aead = {
1934 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301935 .vecs =
1936 hmac_sha1_aes_cbc_enc_tv_temp,
1937 .count =
1938 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1939 }
1940 }
1941 }
1942 }, {
1943 .alg = "authenc(hmac(sha1),cbc(des))",
1944 .test = alg_test_aead,
1945 .fips_allowed = 1,
1946 .suite = {
1947 .aead = {
1948 .enc = {
1949 .vecs =
1950 hmac_sha1_des_cbc_enc_tv_temp,
1951 .count =
1952 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1953 }
1954 }
1955 }
1956 }, {
1957 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
1958 .test = alg_test_aead,
1959 .fips_allowed = 1,
1960 .suite = {
1961 .aead = {
1962 .enc = {
1963 .vecs =
1964 hmac_sha1_des3_ede_cbc_enc_tv_temp,
1965 .count =
1966 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03001967 }
1968 }
1969 }
1970 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001971 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
1972 .test = alg_test_aead,
1973 .fips_allowed = 1,
1974 .suite = {
1975 .aead = {
1976 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301977 .vecs =
1978 hmac_sha1_ecb_cipher_null_enc_tv_temp,
1979 .count =
1980 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02001981 },
1982 .dec = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301983 .vecs =
1984 hmac_sha1_ecb_cipher_null_dec_tv_temp,
1985 .count =
1986 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
1987 }
1988 }
1989 }
1990 }, {
1991 .alg = "authenc(hmac(sha224),cbc(des))",
1992 .test = alg_test_aead,
1993 .fips_allowed = 1,
1994 .suite = {
1995 .aead = {
1996 .enc = {
1997 .vecs =
1998 hmac_sha224_des_cbc_enc_tv_temp,
1999 .count =
2000 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2001 }
2002 }
2003 }
2004 }, {
2005 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
2006 .test = alg_test_aead,
2007 .fips_allowed = 1,
2008 .suite = {
2009 .aead = {
2010 .enc = {
2011 .vecs =
2012 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2013 .count =
2014 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002015 }
2016 }
2017 }
2018 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03002019 .alg = "authenc(hmac(sha256),cbc(aes))",
2020 .test = alg_test_aead,
2021 .fips_allowed = 1,
2022 .suite = {
2023 .aead = {
2024 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302025 .vecs =
2026 hmac_sha256_aes_cbc_enc_tv_temp,
2027 .count =
2028 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2029 }
2030 }
2031 }
2032 }, {
2033 .alg = "authenc(hmac(sha256),cbc(des))",
2034 .test = alg_test_aead,
2035 .fips_allowed = 1,
2036 .suite = {
2037 .aead = {
2038 .enc = {
2039 .vecs =
2040 hmac_sha256_des_cbc_enc_tv_temp,
2041 .count =
2042 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2043 }
2044 }
2045 }
2046 }, {
2047 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
2048 .test = alg_test_aead,
2049 .fips_allowed = 1,
2050 .suite = {
2051 .aead = {
2052 .enc = {
2053 .vecs =
2054 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2055 .count =
2056 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2057 }
2058 }
2059 }
2060 }, {
2061 .alg = "authenc(hmac(sha384),cbc(des))",
2062 .test = alg_test_aead,
2063 .fips_allowed = 1,
2064 .suite = {
2065 .aead = {
2066 .enc = {
2067 .vecs =
2068 hmac_sha384_des_cbc_enc_tv_temp,
2069 .count =
2070 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2071 }
2072 }
2073 }
2074 }, {
2075 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
2076 .test = alg_test_aead,
2077 .fips_allowed = 1,
2078 .suite = {
2079 .aead = {
2080 .enc = {
2081 .vecs =
2082 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2083 .count =
2084 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002085 }
2086 }
2087 }
2088 }, {
2089 .alg = "authenc(hmac(sha512),cbc(aes))",
2090 .test = alg_test_aead,
2091 .fips_allowed = 1,
2092 .suite = {
2093 .aead = {
2094 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302095 .vecs =
2096 hmac_sha512_aes_cbc_enc_tv_temp,
2097 .count =
2098 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2099 }
2100 }
2101 }
2102 }, {
2103 .alg = "authenc(hmac(sha512),cbc(des))",
2104 .test = alg_test_aead,
2105 .fips_allowed = 1,
2106 .suite = {
2107 .aead = {
2108 .enc = {
2109 .vecs =
2110 hmac_sha512_des_cbc_enc_tv_temp,
2111 .count =
2112 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2113 }
2114 }
2115 }
2116 }, {
2117 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2118 .test = alg_test_aead,
2119 .fips_allowed = 1,
2120 .suite = {
2121 .aead = {
2122 .enc = {
2123 .vecs =
2124 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2125 .count =
2126 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002127 }
2128 }
2129 }
2130 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002131 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002132 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002133 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002134 .suite = {
2135 .cipher = {
2136 .enc = {
2137 .vecs = aes_cbc_enc_tv_template,
2138 .count = AES_CBC_ENC_TEST_VECTORS
2139 },
2140 .dec = {
2141 .vecs = aes_cbc_dec_tv_template,
2142 .count = AES_CBC_DEC_TEST_VECTORS
2143 }
2144 }
2145 }
2146 }, {
2147 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002148 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002149 .suite = {
2150 .cipher = {
2151 .enc = {
2152 .vecs = anubis_cbc_enc_tv_template,
2153 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2154 },
2155 .dec = {
2156 .vecs = anubis_cbc_dec_tv_template,
2157 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2158 }
2159 }
2160 }
2161 }, {
2162 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002163 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002164 .suite = {
2165 .cipher = {
2166 .enc = {
2167 .vecs = bf_cbc_enc_tv_template,
2168 .count = BF_CBC_ENC_TEST_VECTORS
2169 },
2170 .dec = {
2171 .vecs = bf_cbc_dec_tv_template,
2172 .count = BF_CBC_DEC_TEST_VECTORS
2173 }
2174 }
2175 }
2176 }, {
2177 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002178 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002179 .suite = {
2180 .cipher = {
2181 .enc = {
2182 .vecs = camellia_cbc_enc_tv_template,
2183 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2184 },
2185 .dec = {
2186 .vecs = camellia_cbc_dec_tv_template,
2187 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2188 }
2189 }
2190 }
2191 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002192 .alg = "cbc(cast5)",
2193 .test = alg_test_skcipher,
2194 .suite = {
2195 .cipher = {
2196 .enc = {
2197 .vecs = cast5_cbc_enc_tv_template,
2198 .count = CAST5_CBC_ENC_TEST_VECTORS
2199 },
2200 .dec = {
2201 .vecs = cast5_cbc_dec_tv_template,
2202 .count = CAST5_CBC_DEC_TEST_VECTORS
2203 }
2204 }
2205 }
2206 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002207 .alg = "cbc(cast6)",
2208 .test = alg_test_skcipher,
2209 .suite = {
2210 .cipher = {
2211 .enc = {
2212 .vecs = cast6_cbc_enc_tv_template,
2213 .count = CAST6_CBC_ENC_TEST_VECTORS
2214 },
2215 .dec = {
2216 .vecs = cast6_cbc_dec_tv_template,
2217 .count = CAST6_CBC_DEC_TEST_VECTORS
2218 }
2219 }
2220 }
2221 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002222 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002223 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002224 .suite = {
2225 .cipher = {
2226 .enc = {
2227 .vecs = des_cbc_enc_tv_template,
2228 .count = DES_CBC_ENC_TEST_VECTORS
2229 },
2230 .dec = {
2231 .vecs = des_cbc_dec_tv_template,
2232 .count = DES_CBC_DEC_TEST_VECTORS
2233 }
2234 }
2235 }
2236 }, {
2237 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002238 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002239 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002240 .suite = {
2241 .cipher = {
2242 .enc = {
2243 .vecs = des3_ede_cbc_enc_tv_template,
2244 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2245 },
2246 .dec = {
2247 .vecs = des3_ede_cbc_dec_tv_template,
2248 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2249 }
2250 }
2251 }
2252 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002253 .alg = "cbc(serpent)",
2254 .test = alg_test_skcipher,
2255 .suite = {
2256 .cipher = {
2257 .enc = {
2258 .vecs = serpent_cbc_enc_tv_template,
2259 .count = SERPENT_CBC_ENC_TEST_VECTORS
2260 },
2261 .dec = {
2262 .vecs = serpent_cbc_dec_tv_template,
2263 .count = SERPENT_CBC_DEC_TEST_VECTORS
2264 }
2265 }
2266 }
2267 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002268 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002269 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002270 .suite = {
2271 .cipher = {
2272 .enc = {
2273 .vecs = tf_cbc_enc_tv_template,
2274 .count = TF_CBC_ENC_TEST_VECTORS
2275 },
2276 .dec = {
2277 .vecs = tf_cbc_dec_tv_template,
2278 .count = TF_CBC_DEC_TEST_VECTORS
2279 }
2280 }
2281 }
2282 }, {
2283 .alg = "ccm(aes)",
2284 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002285 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002286 .suite = {
2287 .aead = {
2288 .enc = {
2289 .vecs = aes_ccm_enc_tv_template,
2290 .count = AES_CCM_ENC_TEST_VECTORS
2291 },
2292 .dec = {
2293 .vecs = aes_ccm_dec_tv_template,
2294 .count = AES_CCM_DEC_TEST_VECTORS
2295 }
2296 }
2297 }
2298 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002299 .alg = "cmac(aes)",
2300 .test = alg_test_hash,
2301 .suite = {
2302 .hash = {
2303 .vecs = aes_cmac128_tv_template,
2304 .count = CMAC_AES_TEST_VECTORS
2305 }
2306 }
2307 }, {
2308 .alg = "cmac(des3_ede)",
2309 .test = alg_test_hash,
2310 .suite = {
2311 .hash = {
2312 .vecs = des3_ede_cmac64_tv_template,
2313 .count = CMAC_DES3_EDE_TEST_VECTORS
2314 }
2315 }
2316 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002317 .alg = "compress_null",
2318 .test = alg_test_null,
2319 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002320 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002321 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002322 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002323 .suite = {
2324 .hash = {
2325 .vecs = crc32c_tv_template,
2326 .count = CRC32C_TEST_VECTORS
2327 }
2328 }
2329 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002330 .alg = "crct10dif",
2331 .test = alg_test_hash,
2332 .fips_allowed = 1,
2333 .suite = {
2334 .hash = {
2335 .vecs = crct10dif_tv_template,
2336 .count = CRCT10DIF_TEST_VECTORS
2337 }
2338 }
2339 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002340 .alg = "cryptd(__driver-cbc-aes-aesni)",
2341 .test = alg_test_null,
2342 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002343 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002344 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2345 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002346 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002347 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2348 .test = alg_test_null,
2349 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002350 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2351 .test = alg_test_null,
2352 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002353 .alg = "cryptd(__driver-ecb-aes-aesni)",
2354 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002355 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002356 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002357 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2358 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002359 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002360 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2361 .test = alg_test_null,
2362 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002363 .alg = "cryptd(__driver-ecb-cast5-avx)",
2364 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002365 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002366 .alg = "cryptd(__driver-ecb-cast6-avx)",
2367 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002368 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002369 .alg = "cryptd(__driver-ecb-serpent-avx)",
2370 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002371 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002372 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2373 .test = alg_test_null,
2374 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002375 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2376 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002377 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002378 .alg = "cryptd(__driver-ecb-twofish-avx)",
2379 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002380 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002381 .alg = "cryptd(__driver-gcm-aes-aesni)",
2382 .test = alg_test_null,
2383 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002384 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002385 .alg = "cryptd(__ghash-pclmulqdqni)",
2386 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002387 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002388 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002389 .alg = "ctr(aes)",
2390 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002391 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002392 .suite = {
2393 .cipher = {
2394 .enc = {
2395 .vecs = aes_ctr_enc_tv_template,
2396 .count = AES_CTR_ENC_TEST_VECTORS
2397 },
2398 .dec = {
2399 .vecs = aes_ctr_dec_tv_template,
2400 .count = AES_CTR_DEC_TEST_VECTORS
2401 }
2402 }
2403 }
2404 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002405 .alg = "ctr(blowfish)",
2406 .test = alg_test_skcipher,
2407 .suite = {
2408 .cipher = {
2409 .enc = {
2410 .vecs = bf_ctr_enc_tv_template,
2411 .count = BF_CTR_ENC_TEST_VECTORS
2412 },
2413 .dec = {
2414 .vecs = bf_ctr_dec_tv_template,
2415 .count = BF_CTR_DEC_TEST_VECTORS
2416 }
2417 }
2418 }
2419 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002420 .alg = "ctr(camellia)",
2421 .test = alg_test_skcipher,
2422 .suite = {
2423 .cipher = {
2424 .enc = {
2425 .vecs = camellia_ctr_enc_tv_template,
2426 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2427 },
2428 .dec = {
2429 .vecs = camellia_ctr_dec_tv_template,
2430 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2431 }
2432 }
2433 }
2434 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002435 .alg = "ctr(cast5)",
2436 .test = alg_test_skcipher,
2437 .suite = {
2438 .cipher = {
2439 .enc = {
2440 .vecs = cast5_ctr_enc_tv_template,
2441 .count = CAST5_CTR_ENC_TEST_VECTORS
2442 },
2443 .dec = {
2444 .vecs = cast5_ctr_dec_tv_template,
2445 .count = CAST5_CTR_DEC_TEST_VECTORS
2446 }
2447 }
2448 }
2449 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002450 .alg = "ctr(cast6)",
2451 .test = alg_test_skcipher,
2452 .suite = {
2453 .cipher = {
2454 .enc = {
2455 .vecs = cast6_ctr_enc_tv_template,
2456 .count = CAST6_CTR_ENC_TEST_VECTORS
2457 },
2458 .dec = {
2459 .vecs = cast6_ctr_dec_tv_template,
2460 .count = CAST6_CTR_DEC_TEST_VECTORS
2461 }
2462 }
2463 }
2464 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002465 .alg = "ctr(des)",
2466 .test = alg_test_skcipher,
2467 .suite = {
2468 .cipher = {
2469 .enc = {
2470 .vecs = des_ctr_enc_tv_template,
2471 .count = DES_CTR_ENC_TEST_VECTORS
2472 },
2473 .dec = {
2474 .vecs = des_ctr_dec_tv_template,
2475 .count = DES_CTR_DEC_TEST_VECTORS
2476 }
2477 }
2478 }
2479 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002480 .alg = "ctr(des3_ede)",
2481 .test = alg_test_skcipher,
2482 .suite = {
2483 .cipher = {
2484 .enc = {
2485 .vecs = des3_ede_ctr_enc_tv_template,
2486 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2487 },
2488 .dec = {
2489 .vecs = des3_ede_ctr_dec_tv_template,
2490 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2491 }
2492 }
2493 }
2494 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002495 .alg = "ctr(serpent)",
2496 .test = alg_test_skcipher,
2497 .suite = {
2498 .cipher = {
2499 .enc = {
2500 .vecs = serpent_ctr_enc_tv_template,
2501 .count = SERPENT_CTR_ENC_TEST_VECTORS
2502 },
2503 .dec = {
2504 .vecs = serpent_ctr_dec_tv_template,
2505 .count = SERPENT_CTR_DEC_TEST_VECTORS
2506 }
2507 }
2508 }
2509 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002510 .alg = "ctr(twofish)",
2511 .test = alg_test_skcipher,
2512 .suite = {
2513 .cipher = {
2514 .enc = {
2515 .vecs = tf_ctr_enc_tv_template,
2516 .count = TF_CTR_ENC_TEST_VECTORS
2517 },
2518 .dec = {
2519 .vecs = tf_ctr_dec_tv_template,
2520 .count = TF_CTR_DEC_TEST_VECTORS
2521 }
2522 }
2523 }
2524 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002525 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002526 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002527 .suite = {
2528 .cipher = {
2529 .enc = {
2530 .vecs = cts_mode_enc_tv_template,
2531 .count = CTS_MODE_ENC_TEST_VECTORS
2532 },
2533 .dec = {
2534 .vecs = cts_mode_dec_tv_template,
2535 .count = CTS_MODE_DEC_TEST_VECTORS
2536 }
2537 }
2538 }
2539 }, {
2540 .alg = "deflate",
2541 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002542 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002543 .suite = {
2544 .comp = {
2545 .comp = {
2546 .vecs = deflate_comp_tv_template,
2547 .count = DEFLATE_COMP_TEST_VECTORS
2548 },
2549 .decomp = {
2550 .vecs = deflate_decomp_tv_template,
2551 .count = DEFLATE_DECOMP_TEST_VECTORS
2552 }
2553 }
2554 }
2555 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002556 .alg = "digest_null",
2557 .test = alg_test_null,
2558 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002559 .alg = "drbg_nopr_ctr_aes128",
2560 .test = alg_test_drbg,
2561 .fips_allowed = 1,
2562 .suite = {
2563 .drbg = {
2564 .vecs = drbg_nopr_ctr_aes128_tv_template,
2565 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2566 }
2567 }
2568 }, {
2569 .alg = "drbg_nopr_ctr_aes192",
2570 .test = alg_test_drbg,
2571 .fips_allowed = 1,
2572 .suite = {
2573 .drbg = {
2574 .vecs = drbg_nopr_ctr_aes192_tv_template,
2575 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2576 }
2577 }
2578 }, {
2579 .alg = "drbg_nopr_ctr_aes256",
2580 .test = alg_test_drbg,
2581 .fips_allowed = 1,
2582 .suite = {
2583 .drbg = {
2584 .vecs = drbg_nopr_ctr_aes256_tv_template,
2585 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2586 }
2587 }
2588 }, {
2589 /*
2590 * There is no need to specifically test the DRBG with every
2591 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2592 */
2593 .alg = "drbg_nopr_hmac_sha1",
2594 .fips_allowed = 1,
2595 .test = alg_test_null,
2596 }, {
2597 .alg = "drbg_nopr_hmac_sha256",
2598 .test = alg_test_drbg,
2599 .fips_allowed = 1,
2600 .suite = {
2601 .drbg = {
2602 .vecs = drbg_nopr_hmac_sha256_tv_template,
2603 .count =
2604 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2605 }
2606 }
2607 }, {
2608 /* covered by drbg_nopr_hmac_sha256 test */
2609 .alg = "drbg_nopr_hmac_sha384",
2610 .fips_allowed = 1,
2611 .test = alg_test_null,
2612 }, {
2613 .alg = "drbg_nopr_hmac_sha512",
2614 .test = alg_test_null,
2615 .fips_allowed = 1,
2616 }, {
2617 .alg = "drbg_nopr_sha1",
2618 .fips_allowed = 1,
2619 .test = alg_test_null,
2620 }, {
2621 .alg = "drbg_nopr_sha256",
2622 .test = alg_test_drbg,
2623 .fips_allowed = 1,
2624 .suite = {
2625 .drbg = {
2626 .vecs = drbg_nopr_sha256_tv_template,
2627 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2628 }
2629 }
2630 }, {
2631 /* covered by drbg_nopr_sha256 test */
2632 .alg = "drbg_nopr_sha384",
2633 .fips_allowed = 1,
2634 .test = alg_test_null,
2635 }, {
2636 .alg = "drbg_nopr_sha512",
2637 .fips_allowed = 1,
2638 .test = alg_test_null,
2639 }, {
2640 .alg = "drbg_pr_ctr_aes128",
2641 .test = alg_test_drbg,
2642 .fips_allowed = 1,
2643 .suite = {
2644 .drbg = {
2645 .vecs = drbg_pr_ctr_aes128_tv_template,
2646 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2647 }
2648 }
2649 }, {
2650 /* covered by drbg_pr_ctr_aes128 test */
2651 .alg = "drbg_pr_ctr_aes192",
2652 .fips_allowed = 1,
2653 .test = alg_test_null,
2654 }, {
2655 .alg = "drbg_pr_ctr_aes256",
2656 .fips_allowed = 1,
2657 .test = alg_test_null,
2658 }, {
2659 .alg = "drbg_pr_hmac_sha1",
2660 .fips_allowed = 1,
2661 .test = alg_test_null,
2662 }, {
2663 .alg = "drbg_pr_hmac_sha256",
2664 .test = alg_test_drbg,
2665 .fips_allowed = 1,
2666 .suite = {
2667 .drbg = {
2668 .vecs = drbg_pr_hmac_sha256_tv_template,
2669 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2670 }
2671 }
2672 }, {
2673 /* covered by drbg_pr_hmac_sha256 test */
2674 .alg = "drbg_pr_hmac_sha384",
2675 .fips_allowed = 1,
2676 .test = alg_test_null,
2677 }, {
2678 .alg = "drbg_pr_hmac_sha512",
2679 .test = alg_test_null,
2680 .fips_allowed = 1,
2681 }, {
2682 .alg = "drbg_pr_sha1",
2683 .fips_allowed = 1,
2684 .test = alg_test_null,
2685 }, {
2686 .alg = "drbg_pr_sha256",
2687 .test = alg_test_drbg,
2688 .fips_allowed = 1,
2689 .suite = {
2690 .drbg = {
2691 .vecs = drbg_pr_sha256_tv_template,
2692 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2693 }
2694 }
2695 }, {
2696 /* covered by drbg_pr_sha256 test */
2697 .alg = "drbg_pr_sha384",
2698 .fips_allowed = 1,
2699 .test = alg_test_null,
2700 }, {
2701 .alg = "drbg_pr_sha512",
2702 .fips_allowed = 1,
2703 .test = alg_test_null,
2704 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002705 .alg = "ecb(__aes-aesni)",
2706 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002707 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002708 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002709 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002710 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002711 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002712 .suite = {
2713 .cipher = {
2714 .enc = {
2715 .vecs = aes_enc_tv_template,
2716 .count = AES_ENC_TEST_VECTORS
2717 },
2718 .dec = {
2719 .vecs = aes_dec_tv_template,
2720 .count = AES_DEC_TEST_VECTORS
2721 }
2722 }
2723 }
2724 }, {
2725 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002726 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002727 .suite = {
2728 .cipher = {
2729 .enc = {
2730 .vecs = anubis_enc_tv_template,
2731 .count = ANUBIS_ENC_TEST_VECTORS
2732 },
2733 .dec = {
2734 .vecs = anubis_dec_tv_template,
2735 .count = ANUBIS_DEC_TEST_VECTORS
2736 }
2737 }
2738 }
2739 }, {
2740 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002741 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002742 .suite = {
2743 .cipher = {
2744 .enc = {
2745 .vecs = arc4_enc_tv_template,
2746 .count = ARC4_ENC_TEST_VECTORS
2747 },
2748 .dec = {
2749 .vecs = arc4_dec_tv_template,
2750 .count = ARC4_DEC_TEST_VECTORS
2751 }
2752 }
2753 }
2754 }, {
2755 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002756 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002757 .suite = {
2758 .cipher = {
2759 .enc = {
2760 .vecs = bf_enc_tv_template,
2761 .count = BF_ENC_TEST_VECTORS
2762 },
2763 .dec = {
2764 .vecs = bf_dec_tv_template,
2765 .count = BF_DEC_TEST_VECTORS
2766 }
2767 }
2768 }
2769 }, {
2770 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002771 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002772 .suite = {
2773 .cipher = {
2774 .enc = {
2775 .vecs = camellia_enc_tv_template,
2776 .count = CAMELLIA_ENC_TEST_VECTORS
2777 },
2778 .dec = {
2779 .vecs = camellia_dec_tv_template,
2780 .count = CAMELLIA_DEC_TEST_VECTORS
2781 }
2782 }
2783 }
2784 }, {
2785 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002786 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002787 .suite = {
2788 .cipher = {
2789 .enc = {
2790 .vecs = cast5_enc_tv_template,
2791 .count = CAST5_ENC_TEST_VECTORS
2792 },
2793 .dec = {
2794 .vecs = cast5_dec_tv_template,
2795 .count = CAST5_DEC_TEST_VECTORS
2796 }
2797 }
2798 }
2799 }, {
2800 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002801 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002802 .suite = {
2803 .cipher = {
2804 .enc = {
2805 .vecs = cast6_enc_tv_template,
2806 .count = CAST6_ENC_TEST_VECTORS
2807 },
2808 .dec = {
2809 .vecs = cast6_dec_tv_template,
2810 .count = CAST6_DEC_TEST_VECTORS
2811 }
2812 }
2813 }
2814 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002815 .alg = "ecb(cipher_null)",
2816 .test = alg_test_null,
2817 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002818 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002819 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002820 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002821 .suite = {
2822 .cipher = {
2823 .enc = {
2824 .vecs = des_enc_tv_template,
2825 .count = DES_ENC_TEST_VECTORS
2826 },
2827 .dec = {
2828 .vecs = des_dec_tv_template,
2829 .count = DES_DEC_TEST_VECTORS
2830 }
2831 }
2832 }
2833 }, {
2834 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002835 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002836 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002837 .suite = {
2838 .cipher = {
2839 .enc = {
2840 .vecs = des3_ede_enc_tv_template,
2841 .count = DES3_EDE_ENC_TEST_VECTORS
2842 },
2843 .dec = {
2844 .vecs = des3_ede_dec_tv_template,
2845 .count = DES3_EDE_DEC_TEST_VECTORS
2846 }
2847 }
2848 }
2849 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002850 .alg = "ecb(fcrypt)",
2851 .test = alg_test_skcipher,
2852 .suite = {
2853 .cipher = {
2854 .enc = {
2855 .vecs = fcrypt_pcbc_enc_tv_template,
2856 .count = 1
2857 },
2858 .dec = {
2859 .vecs = fcrypt_pcbc_dec_tv_template,
2860 .count = 1
2861 }
2862 }
2863 }
2864 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002865 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002866 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002867 .suite = {
2868 .cipher = {
2869 .enc = {
2870 .vecs = khazad_enc_tv_template,
2871 .count = KHAZAD_ENC_TEST_VECTORS
2872 },
2873 .dec = {
2874 .vecs = khazad_dec_tv_template,
2875 .count = KHAZAD_DEC_TEST_VECTORS
2876 }
2877 }
2878 }
2879 }, {
2880 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002881 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002882 .suite = {
2883 .cipher = {
2884 .enc = {
2885 .vecs = seed_enc_tv_template,
2886 .count = SEED_ENC_TEST_VECTORS
2887 },
2888 .dec = {
2889 .vecs = seed_dec_tv_template,
2890 .count = SEED_DEC_TEST_VECTORS
2891 }
2892 }
2893 }
2894 }, {
2895 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002896 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002897 .suite = {
2898 .cipher = {
2899 .enc = {
2900 .vecs = serpent_enc_tv_template,
2901 .count = SERPENT_ENC_TEST_VECTORS
2902 },
2903 .dec = {
2904 .vecs = serpent_dec_tv_template,
2905 .count = SERPENT_DEC_TEST_VECTORS
2906 }
2907 }
2908 }
2909 }, {
2910 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002911 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002912 .suite = {
2913 .cipher = {
2914 .enc = {
2915 .vecs = tea_enc_tv_template,
2916 .count = TEA_ENC_TEST_VECTORS
2917 },
2918 .dec = {
2919 .vecs = tea_dec_tv_template,
2920 .count = TEA_DEC_TEST_VECTORS
2921 }
2922 }
2923 }
2924 }, {
2925 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002926 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002927 .suite = {
2928 .cipher = {
2929 .enc = {
2930 .vecs = tnepres_enc_tv_template,
2931 .count = TNEPRES_ENC_TEST_VECTORS
2932 },
2933 .dec = {
2934 .vecs = tnepres_dec_tv_template,
2935 .count = TNEPRES_DEC_TEST_VECTORS
2936 }
2937 }
2938 }
2939 }, {
2940 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002941 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002942 .suite = {
2943 .cipher = {
2944 .enc = {
2945 .vecs = tf_enc_tv_template,
2946 .count = TF_ENC_TEST_VECTORS
2947 },
2948 .dec = {
2949 .vecs = tf_dec_tv_template,
2950 .count = TF_DEC_TEST_VECTORS
2951 }
2952 }
2953 }
2954 }, {
2955 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002956 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002957 .suite = {
2958 .cipher = {
2959 .enc = {
2960 .vecs = xeta_enc_tv_template,
2961 .count = XETA_ENC_TEST_VECTORS
2962 },
2963 .dec = {
2964 .vecs = xeta_dec_tv_template,
2965 .count = XETA_DEC_TEST_VECTORS
2966 }
2967 }
2968 }
2969 }, {
2970 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002971 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002972 .suite = {
2973 .cipher = {
2974 .enc = {
2975 .vecs = xtea_enc_tv_template,
2976 .count = XTEA_ENC_TEST_VECTORS
2977 },
2978 .dec = {
2979 .vecs = xtea_dec_tv_template,
2980 .count = XTEA_DEC_TEST_VECTORS
2981 }
2982 }
2983 }
2984 }, {
2985 .alg = "gcm(aes)",
2986 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002987 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002988 .suite = {
2989 .aead = {
2990 .enc = {
2991 .vecs = aes_gcm_enc_tv_template,
2992 .count = AES_GCM_ENC_TEST_VECTORS
2993 },
2994 .dec = {
2995 .vecs = aes_gcm_dec_tv_template,
2996 .count = AES_GCM_DEC_TEST_VECTORS
2997 }
2998 }
2999 }
3000 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003001 .alg = "ghash",
3002 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003003 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003004 .suite = {
3005 .hash = {
3006 .vecs = ghash_tv_template,
3007 .count = GHASH_TEST_VECTORS
3008 }
3009 }
3010 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003011 .alg = "hmac(crc32)",
3012 .test = alg_test_hash,
3013 .suite = {
3014 .hash = {
3015 .vecs = bfin_crc_tv_template,
3016 .count = BFIN_CRC_TEST_VECTORS
3017 }
3018 }
3019 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003020 .alg = "hmac(md5)",
3021 .test = alg_test_hash,
3022 .suite = {
3023 .hash = {
3024 .vecs = hmac_md5_tv_template,
3025 .count = HMAC_MD5_TEST_VECTORS
3026 }
3027 }
3028 }, {
3029 .alg = "hmac(rmd128)",
3030 .test = alg_test_hash,
3031 .suite = {
3032 .hash = {
3033 .vecs = hmac_rmd128_tv_template,
3034 .count = HMAC_RMD128_TEST_VECTORS
3035 }
3036 }
3037 }, {
3038 .alg = "hmac(rmd160)",
3039 .test = alg_test_hash,
3040 .suite = {
3041 .hash = {
3042 .vecs = hmac_rmd160_tv_template,
3043 .count = HMAC_RMD160_TEST_VECTORS
3044 }
3045 }
3046 }, {
3047 .alg = "hmac(sha1)",
3048 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003049 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003050 .suite = {
3051 .hash = {
3052 .vecs = hmac_sha1_tv_template,
3053 .count = HMAC_SHA1_TEST_VECTORS
3054 }
3055 }
3056 }, {
3057 .alg = "hmac(sha224)",
3058 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003059 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003060 .suite = {
3061 .hash = {
3062 .vecs = hmac_sha224_tv_template,
3063 .count = HMAC_SHA224_TEST_VECTORS
3064 }
3065 }
3066 }, {
3067 .alg = "hmac(sha256)",
3068 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003069 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003070 .suite = {
3071 .hash = {
3072 .vecs = hmac_sha256_tv_template,
3073 .count = HMAC_SHA256_TEST_VECTORS
3074 }
3075 }
3076 }, {
3077 .alg = "hmac(sha384)",
3078 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003079 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003080 .suite = {
3081 .hash = {
3082 .vecs = hmac_sha384_tv_template,
3083 .count = HMAC_SHA384_TEST_VECTORS
3084 }
3085 }
3086 }, {
3087 .alg = "hmac(sha512)",
3088 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003089 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003090 .suite = {
3091 .hash = {
3092 .vecs = hmac_sha512_tv_template,
3093 .count = HMAC_SHA512_TEST_VECTORS
3094 }
3095 }
3096 }, {
3097 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003098 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003099 .suite = {
3100 .cipher = {
3101 .enc = {
3102 .vecs = aes_lrw_enc_tv_template,
3103 .count = AES_LRW_ENC_TEST_VECTORS
3104 },
3105 .dec = {
3106 .vecs = aes_lrw_dec_tv_template,
3107 .count = AES_LRW_DEC_TEST_VECTORS
3108 }
3109 }
3110 }
3111 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003112 .alg = "lrw(camellia)",
3113 .test = alg_test_skcipher,
3114 .suite = {
3115 .cipher = {
3116 .enc = {
3117 .vecs = camellia_lrw_enc_tv_template,
3118 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3119 },
3120 .dec = {
3121 .vecs = camellia_lrw_dec_tv_template,
3122 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3123 }
3124 }
3125 }
3126 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003127 .alg = "lrw(cast6)",
3128 .test = alg_test_skcipher,
3129 .suite = {
3130 .cipher = {
3131 .enc = {
3132 .vecs = cast6_lrw_enc_tv_template,
3133 .count = CAST6_LRW_ENC_TEST_VECTORS
3134 },
3135 .dec = {
3136 .vecs = cast6_lrw_dec_tv_template,
3137 .count = CAST6_LRW_DEC_TEST_VECTORS
3138 }
3139 }
3140 }
3141 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003142 .alg = "lrw(serpent)",
3143 .test = alg_test_skcipher,
3144 .suite = {
3145 .cipher = {
3146 .enc = {
3147 .vecs = serpent_lrw_enc_tv_template,
3148 .count = SERPENT_LRW_ENC_TEST_VECTORS
3149 },
3150 .dec = {
3151 .vecs = serpent_lrw_dec_tv_template,
3152 .count = SERPENT_LRW_DEC_TEST_VECTORS
3153 }
3154 }
3155 }
3156 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003157 .alg = "lrw(twofish)",
3158 .test = alg_test_skcipher,
3159 .suite = {
3160 .cipher = {
3161 .enc = {
3162 .vecs = tf_lrw_enc_tv_template,
3163 .count = TF_LRW_ENC_TEST_VECTORS
3164 },
3165 .dec = {
3166 .vecs = tf_lrw_dec_tv_template,
3167 .count = TF_LRW_DEC_TEST_VECTORS
3168 }
3169 }
3170 }
3171 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003172 .alg = "lz4",
3173 .test = alg_test_comp,
3174 .fips_allowed = 1,
3175 .suite = {
3176 .comp = {
3177 .comp = {
3178 .vecs = lz4_comp_tv_template,
3179 .count = LZ4_COMP_TEST_VECTORS
3180 },
3181 .decomp = {
3182 .vecs = lz4_decomp_tv_template,
3183 .count = LZ4_DECOMP_TEST_VECTORS
3184 }
3185 }
3186 }
3187 }, {
3188 .alg = "lz4hc",
3189 .test = alg_test_comp,
3190 .fips_allowed = 1,
3191 .suite = {
3192 .comp = {
3193 .comp = {
3194 .vecs = lz4hc_comp_tv_template,
3195 .count = LZ4HC_COMP_TEST_VECTORS
3196 },
3197 .decomp = {
3198 .vecs = lz4hc_decomp_tv_template,
3199 .count = LZ4HC_DECOMP_TEST_VECTORS
3200 }
3201 }
3202 }
3203 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003204 .alg = "lzo",
3205 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003206 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003207 .suite = {
3208 .comp = {
3209 .comp = {
3210 .vecs = lzo_comp_tv_template,
3211 .count = LZO_COMP_TEST_VECTORS
3212 },
3213 .decomp = {
3214 .vecs = lzo_decomp_tv_template,
3215 .count = LZO_DECOMP_TEST_VECTORS
3216 }
3217 }
3218 }
3219 }, {
3220 .alg = "md4",
3221 .test = alg_test_hash,
3222 .suite = {
3223 .hash = {
3224 .vecs = md4_tv_template,
3225 .count = MD4_TEST_VECTORS
3226 }
3227 }
3228 }, {
3229 .alg = "md5",
3230 .test = alg_test_hash,
3231 .suite = {
3232 .hash = {
3233 .vecs = md5_tv_template,
3234 .count = MD5_TEST_VECTORS
3235 }
3236 }
3237 }, {
3238 .alg = "michael_mic",
3239 .test = alg_test_hash,
3240 .suite = {
3241 .hash = {
3242 .vecs = michael_mic_tv_template,
3243 .count = MICHAEL_MIC_TEST_VECTORS
3244 }
3245 }
3246 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003247 .alg = "ofb(aes)",
3248 .test = alg_test_skcipher,
3249 .fips_allowed = 1,
3250 .suite = {
3251 .cipher = {
3252 .enc = {
3253 .vecs = aes_ofb_enc_tv_template,
3254 .count = AES_OFB_ENC_TEST_VECTORS
3255 },
3256 .dec = {
3257 .vecs = aes_ofb_dec_tv_template,
3258 .count = AES_OFB_DEC_TEST_VECTORS
3259 }
3260 }
3261 }
3262 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003263 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003264 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003265 .suite = {
3266 .cipher = {
3267 .enc = {
3268 .vecs = fcrypt_pcbc_enc_tv_template,
3269 .count = FCRYPT_ENC_TEST_VECTORS
3270 },
3271 .dec = {
3272 .vecs = fcrypt_pcbc_dec_tv_template,
3273 .count = FCRYPT_DEC_TEST_VECTORS
3274 }
3275 }
3276 }
3277 }, {
3278 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003279 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003280 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003281 .suite = {
3282 .cipher = {
3283 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003284 .vecs = aes_ctr_rfc3686_enc_tv_template,
3285 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003286 },
3287 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003288 .vecs = aes_ctr_rfc3686_dec_tv_template,
3289 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003290 }
3291 }
3292 }
3293 }, {
Adrian Hoban69435b92010-11-04 15:02:04 -04003294 .alg = "rfc4106(gcm(aes))",
3295 .test = alg_test_aead,
Jarod Wilsondb71f292015-01-23 12:42:15 -05003296 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003297 .suite = {
3298 .aead = {
3299 .enc = {
3300 .vecs = aes_gcm_rfc4106_enc_tv_template,
3301 .count = AES_GCM_4106_ENC_TEST_VECTORS
3302 },
3303 .dec = {
3304 .vecs = aes_gcm_rfc4106_dec_tv_template,
3305 .count = AES_GCM_4106_DEC_TEST_VECTORS
3306 }
3307 }
3308 }
3309 }, {
Jarod Wilson5d667322009-05-04 19:23:40 +08003310 .alg = "rfc4309(ccm(aes))",
3311 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003312 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003313 .suite = {
3314 .aead = {
3315 .enc = {
3316 .vecs = aes_ccm_rfc4309_enc_tv_template,
3317 .count = AES_CCM_4309_ENC_TEST_VECTORS
3318 },
3319 .dec = {
3320 .vecs = aes_ccm_rfc4309_dec_tv_template,
3321 .count = AES_CCM_4309_DEC_TEST_VECTORS
3322 }
3323 }
3324 }
3325 }, {
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003326 .alg = "rfc4543(gcm(aes))",
3327 .test = alg_test_aead,
3328 .suite = {
3329 .aead = {
3330 .enc = {
3331 .vecs = aes_gcm_rfc4543_enc_tv_template,
3332 .count = AES_GCM_4543_ENC_TEST_VECTORS
3333 },
3334 .dec = {
3335 .vecs = aes_gcm_rfc4543_dec_tv_template,
3336 .count = AES_GCM_4543_DEC_TEST_VECTORS
3337 },
3338 }
3339 }
3340 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003341 .alg = "rmd128",
3342 .test = alg_test_hash,
3343 .suite = {
3344 .hash = {
3345 .vecs = rmd128_tv_template,
3346 .count = RMD128_TEST_VECTORS
3347 }
3348 }
3349 }, {
3350 .alg = "rmd160",
3351 .test = alg_test_hash,
3352 .suite = {
3353 .hash = {
3354 .vecs = rmd160_tv_template,
3355 .count = RMD160_TEST_VECTORS
3356 }
3357 }
3358 }, {
3359 .alg = "rmd256",
3360 .test = alg_test_hash,
3361 .suite = {
3362 .hash = {
3363 .vecs = rmd256_tv_template,
3364 .count = RMD256_TEST_VECTORS
3365 }
3366 }
3367 }, {
3368 .alg = "rmd320",
3369 .test = alg_test_hash,
3370 .suite = {
3371 .hash = {
3372 .vecs = rmd320_tv_template,
3373 .count = RMD320_TEST_VECTORS
3374 }
3375 }
3376 }, {
3377 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003378 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003379 .suite = {
3380 .cipher = {
3381 .enc = {
3382 .vecs = salsa20_stream_enc_tv_template,
3383 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3384 }
3385 }
3386 }
3387 }, {
3388 .alg = "sha1",
3389 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003390 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003391 .suite = {
3392 .hash = {
3393 .vecs = sha1_tv_template,
3394 .count = SHA1_TEST_VECTORS
3395 }
3396 }
3397 }, {
3398 .alg = "sha224",
3399 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003400 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003401 .suite = {
3402 .hash = {
3403 .vecs = sha224_tv_template,
3404 .count = SHA224_TEST_VECTORS
3405 }
3406 }
3407 }, {
3408 .alg = "sha256",
3409 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003410 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003411 .suite = {
3412 .hash = {
3413 .vecs = sha256_tv_template,
3414 .count = SHA256_TEST_VECTORS
3415 }
3416 }
3417 }, {
3418 .alg = "sha384",
3419 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003420 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003421 .suite = {
3422 .hash = {
3423 .vecs = sha384_tv_template,
3424 .count = SHA384_TEST_VECTORS
3425 }
3426 }
3427 }, {
3428 .alg = "sha512",
3429 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003430 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003431 .suite = {
3432 .hash = {
3433 .vecs = sha512_tv_template,
3434 .count = SHA512_TEST_VECTORS
3435 }
3436 }
3437 }, {
3438 .alg = "tgr128",
3439 .test = alg_test_hash,
3440 .suite = {
3441 .hash = {
3442 .vecs = tgr128_tv_template,
3443 .count = TGR128_TEST_VECTORS
3444 }
3445 }
3446 }, {
3447 .alg = "tgr160",
3448 .test = alg_test_hash,
3449 .suite = {
3450 .hash = {
3451 .vecs = tgr160_tv_template,
3452 .count = TGR160_TEST_VECTORS
3453 }
3454 }
3455 }, {
3456 .alg = "tgr192",
3457 .test = alg_test_hash,
3458 .suite = {
3459 .hash = {
3460 .vecs = tgr192_tv_template,
3461 .count = TGR192_TEST_VECTORS
3462 }
3463 }
3464 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003465 .alg = "vmac(aes)",
3466 .test = alg_test_hash,
3467 .suite = {
3468 .hash = {
3469 .vecs = aes_vmac128_tv_template,
3470 .count = VMAC_AES_TEST_VECTORS
3471 }
3472 }
3473 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003474 .alg = "wp256",
3475 .test = alg_test_hash,
3476 .suite = {
3477 .hash = {
3478 .vecs = wp256_tv_template,
3479 .count = WP256_TEST_VECTORS
3480 }
3481 }
3482 }, {
3483 .alg = "wp384",
3484 .test = alg_test_hash,
3485 .suite = {
3486 .hash = {
3487 .vecs = wp384_tv_template,
3488 .count = WP384_TEST_VECTORS
3489 }
3490 }
3491 }, {
3492 .alg = "wp512",
3493 .test = alg_test_hash,
3494 .suite = {
3495 .hash = {
3496 .vecs = wp512_tv_template,
3497 .count = WP512_TEST_VECTORS
3498 }
3499 }
3500 }, {
3501 .alg = "xcbc(aes)",
3502 .test = alg_test_hash,
3503 .suite = {
3504 .hash = {
3505 .vecs = aes_xcbc128_tv_template,
3506 .count = XCBC_AES_TEST_VECTORS
3507 }
3508 }
3509 }, {
3510 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003511 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003512 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003513 .suite = {
3514 .cipher = {
3515 .enc = {
3516 .vecs = aes_xts_enc_tv_template,
3517 .count = AES_XTS_ENC_TEST_VECTORS
3518 },
3519 .dec = {
3520 .vecs = aes_xts_dec_tv_template,
3521 .count = AES_XTS_DEC_TEST_VECTORS
3522 }
3523 }
3524 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003525 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003526 .alg = "xts(camellia)",
3527 .test = alg_test_skcipher,
3528 .suite = {
3529 .cipher = {
3530 .enc = {
3531 .vecs = camellia_xts_enc_tv_template,
3532 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3533 },
3534 .dec = {
3535 .vecs = camellia_xts_dec_tv_template,
3536 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3537 }
3538 }
3539 }
3540 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003541 .alg = "xts(cast6)",
3542 .test = alg_test_skcipher,
3543 .suite = {
3544 .cipher = {
3545 .enc = {
3546 .vecs = cast6_xts_enc_tv_template,
3547 .count = CAST6_XTS_ENC_TEST_VECTORS
3548 },
3549 .dec = {
3550 .vecs = cast6_xts_dec_tv_template,
3551 .count = CAST6_XTS_DEC_TEST_VECTORS
3552 }
3553 }
3554 }
3555 }, {
Jussi Kivilinna18be20b2011-10-18 13:33:17 +03003556 .alg = "xts(serpent)",
3557 .test = alg_test_skcipher,
3558 .suite = {
3559 .cipher = {
3560 .enc = {
3561 .vecs = serpent_xts_enc_tv_template,
3562 .count = SERPENT_XTS_ENC_TEST_VECTORS
3563 },
3564 .dec = {
3565 .vecs = serpent_xts_dec_tv_template,
3566 .count = SERPENT_XTS_DEC_TEST_VECTORS
3567 }
3568 }
3569 }
3570 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003571 .alg = "xts(twofish)",
3572 .test = alg_test_skcipher,
3573 .suite = {
3574 .cipher = {
3575 .enc = {
3576 .vecs = tf_xts_enc_tv_template,
3577 .count = TF_XTS_ENC_TEST_VECTORS
3578 },
3579 .dec = {
3580 .vecs = tf_xts_dec_tv_template,
3581 .count = TF_XTS_DEC_TEST_VECTORS
3582 }
3583 }
3584 }
3585 }, {
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003586 .alg = "zlib",
3587 .test = alg_test_pcomp,
Milan Broz08189042012-12-06 17:16:28 +08003588 .fips_allowed = 1,
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003589 .suite = {
3590 .pcomp = {
3591 .comp = {
3592 .vecs = zlib_comp_tv_template,
3593 .count = ZLIB_COMP_TEST_VECTORS
3594 },
3595 .decomp = {
3596 .vecs = zlib_decomp_tv_template,
3597 .count = ZLIB_DECOMP_TEST_VECTORS
3598 }
3599 }
3600 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003601 }
3602};
3603
Jussi Kivilinna57147582013-06-13 17:37:40 +03003604static bool alg_test_descs_checked;
3605
3606static void alg_test_descs_check_order(void)
3607{
3608 int i;
3609
3610 /* only check once */
3611 if (alg_test_descs_checked)
3612 return;
3613
3614 alg_test_descs_checked = true;
3615
3616 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3617 int diff = strcmp(alg_test_descs[i - 1].alg,
3618 alg_test_descs[i].alg);
3619
3620 if (WARN_ON(diff > 0)) {
3621 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3622 alg_test_descs[i - 1].alg,
3623 alg_test_descs[i].alg);
3624 }
3625
3626 if (WARN_ON(diff == 0)) {
3627 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3628 alg_test_descs[i].alg);
3629 }
3630 }
3631}
3632
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003633static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003634{
3635 int start = 0;
3636 int end = ARRAY_SIZE(alg_test_descs);
3637
3638 while (start < end) {
3639 int i = (start + end) / 2;
3640 int diff = strcmp(alg_test_descs[i].alg, alg);
3641
3642 if (diff > 0) {
3643 end = i;
3644 continue;
3645 }
3646
3647 if (diff < 0) {
3648 start = i + 1;
3649 continue;
3650 }
3651
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003652 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003653 }
3654
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003655 return -1;
3656}
3657
3658int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3659{
3660 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003661 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003662 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003663
Jussi Kivilinna57147582013-06-13 17:37:40 +03003664 alg_test_descs_check_order();
3665
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003666 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3667 char nalg[CRYPTO_MAX_ALG_NAME];
3668
3669 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3670 sizeof(nalg))
3671 return -ENAMETOOLONG;
3672
3673 i = alg_find_test(nalg);
3674 if (i < 0)
3675 goto notest;
3676
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003677 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3678 goto non_fips_alg;
3679
Jarod Wilson941fb322009-05-04 19:49:23 +08003680 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3681 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003682 }
3683
3684 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003685 j = alg_find_test(driver);
3686 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003687 goto notest;
3688
Herbert Xua68f6612009-07-02 16:32:12 +08003689 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3690 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003691 goto non_fips_alg;
3692
Herbert Xua68f6612009-07-02 16:32:12 +08003693 rc = 0;
3694 if (i >= 0)
3695 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3696 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003697 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003698 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3699 type, mask);
3700
Jarod Wilson941fb322009-05-04 19:49:23 +08003701test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003702 if (fips_enabled && rc)
3703 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3704
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003705 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09003706 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003707
Neil Hormand12d6b62008-10-12 20:36:51 +08003708 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003709
3710notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003711 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3712 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003713non_fips_alg:
3714 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003715}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003716
Herbert Xu326a6342010-08-06 09:40:28 +08003717#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003718
Herbert Xuda7f0332008-07-31 17:08:25 +08003719EXPORT_SYMBOL_GPL(alg_test);