blob: f9bce3d7ee7f840e55ea6bc4d5abb03ba7df72b0 [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;
Cristian Stoica424a5da2015-01-28 11:03:05 +0200432 unsigned int authsize, iv_len;
Herbert Xuda7f0332008-07-31 17:08:25 +0800433 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);
Cristian Stoica424a5da2015-01-28 11:03:05 +0200503 iv_len = crypto_aead_ivsize(tfm);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300504 if (template[i].iv)
Cristian Stoica424a5da2015-01-28 11:03:05 +0200505 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300506 else
Cristian Stoica424a5da2015-01-28 11:03:05 +0200507 memset(iv, 0, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300508
509 crypto_aead_clear_flags(tfm, ~0);
510 if (template[i].wk)
511 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
512
513 if (template[i].klen > MAX_KEYLEN) {
514 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
515 d, j, algo, template[i].klen,
516 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +1000517 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300518 goto out;
519 }
520 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +1000521
Cristian Stoica05b1d332014-07-28 13:11:23 +0300522 ret = crypto_aead_setkey(tfm, key, template[i].klen);
523 if (!ret == template[i].fail) {
524 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
525 d, j, algo, crypto_aead_get_flags(tfm));
526 goto out;
527 } else if (ret)
528 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800529
Cristian Stoica05b1d332014-07-28 13:11:23 +0300530 authsize = abs(template[i].rlen - template[i].ilen);
531 ret = crypto_aead_setauthsize(tfm, authsize);
532 if (ret) {
533 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
534 d, authsize, j, algo);
535 goto out;
536 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800537
Cristian Stoica05b1d332014-07-28 13:11:23 +0300538 if (diff_dst) {
539 output = xoutbuf[0];
540 output += align_offset;
541 sg_init_one(&sg[0], input, template[i].ilen);
542 sg_init_one(&sgout[0], output, template[i].rlen);
543 } else {
544 sg_init_one(&sg[0], input,
545 template[i].ilen + (enc ? authsize : 0));
546 output = input;
547 }
548
549 sg_init_one(&asg[0], assoc, template[i].alen);
550
551 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
552 template[i].ilen, iv);
553
554 aead_request_set_assoc(req, asg, template[i].alen);
555
556 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
557
558 switch (ret) {
559 case 0:
560 if (template[i].novrfy) {
561 /* verification was supposed to fail */
562 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
563 d, e, j, algo);
564 /* so really, we got a bad message */
565 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +0300566 goto out;
567 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300568 break;
569 case -EINPROGRESS:
570 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100571 wait_for_completion(&result.completion);
572 reinit_completion(&result.completion);
573 ret = result.err;
574 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +0800575 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300576 case -EBADMSG:
577 if (template[i].novrfy)
578 /* verification failure was expected */
579 continue;
580 /* fall through */
581 default:
582 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
583 d, e, j, algo, -ret);
584 goto out;
585 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800586
Cristian Stoica05b1d332014-07-28 13:11:23 +0300587 q = output;
588 if (memcmp(q, template[i].result, template[i].rlen)) {
589 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
590 d, j, e, algo);
591 hexdump(q, template[i].rlen);
592 ret = -EINVAL;
593 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800594 }
595 }
596
597 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300598 /* alignment tests are only done with continuous buffers */
599 if (align_offset != 0)
600 break;
601
Cristian Stoica05b1d332014-07-28 13:11:23 +0300602 if (!template[i].np)
603 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800604
Cristian Stoica05b1d332014-07-28 13:11:23 +0300605 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800606
Cristian Stoica05b1d332014-07-28 13:11:23 +0300607 if (template[i].iv)
608 memcpy(iv, template[i].iv, MAX_IVLEN);
609 else
610 memset(iv, 0, MAX_IVLEN);
611
612 crypto_aead_clear_flags(tfm, ~0);
613 if (template[i].wk)
614 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
615 if (template[i].klen > MAX_KEYLEN) {
616 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
617 d, j, algo, template[i].klen, MAX_KEYLEN);
618 ret = -EINVAL;
619 goto out;
620 }
621 memcpy(key, template[i].key, template[i].klen);
622
623 ret = crypto_aead_setkey(tfm, key, template[i].klen);
624 if (!ret == template[i].fail) {
625 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
626 d, j, algo, crypto_aead_get_flags(tfm));
627 goto out;
628 } else if (ret)
629 continue;
630
631 authsize = abs(template[i].rlen - template[i].ilen);
632
633 ret = -EINVAL;
634 sg_init_table(sg, template[i].np);
635 if (diff_dst)
636 sg_init_table(sgout, template[i].np);
637 for (k = 0, temp = 0; k < template[i].np; k++) {
638 if (WARN_ON(offset_in_page(IDX[k]) +
639 template[i].tap[k] > PAGE_SIZE))
640 goto out;
641
642 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
643 memcpy(q, template[i].input + temp, template[i].tap[k]);
644 sg_set_buf(&sg[k], q, template[i].tap[k]);
645
646 if (diff_dst) {
647 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
648 offset_in_page(IDX[k]);
649
650 memset(q, 0, template[i].tap[k]);
651
652 sg_set_buf(&sgout[k], q, template[i].tap[k]);
653 }
654
655 n = template[i].tap[k];
656 if (k == template[i].np - 1 && enc)
657 n += authsize;
658 if (offset_in_page(q) + n < PAGE_SIZE)
659 q[n] = 0;
660
661 temp += template[i].tap[k];
662 }
663
664 ret = crypto_aead_setauthsize(tfm, authsize);
665 if (ret) {
666 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
667 d, authsize, j, algo);
668 goto out;
669 }
670
671 if (enc) {
672 if (WARN_ON(sg[k - 1].offset +
673 sg[k - 1].length + authsize >
674 PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300675 ret = -EINVAL;
676 goto out;
677 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800678
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300679 if (diff_dst)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300680 sgout[k - 1].length += authsize;
681 else
682 sg[k - 1].length += authsize;
683 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800684
Cristian Stoica05b1d332014-07-28 13:11:23 +0300685 sg_init_table(asg, template[i].anp);
686 ret = -EINVAL;
687 for (k = 0, temp = 0; k < template[i].anp; k++) {
688 if (WARN_ON(offset_in_page(IDX[k]) +
689 template[i].atap[k] > PAGE_SIZE))
690 goto out;
691 sg_set_buf(&asg[k],
692 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
693 offset_in_page(IDX[k]),
694 template[i].assoc + temp,
695 template[i].atap[k]),
696 template[i].atap[k]);
697 temp += template[i].atap[k];
698 }
699
700 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
701 template[i].ilen,
702 iv);
703
704 aead_request_set_assoc(req, asg, template[i].alen);
705
706 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
707
708 switch (ret) {
709 case 0:
710 if (template[i].novrfy) {
711 /* verification was supposed to fail */
712 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
713 d, e, j, algo);
714 /* so really, we got a bad message */
715 ret = -EBADMSG;
716 goto out;
717 }
718 break;
719 case -EINPROGRESS:
720 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100721 wait_for_completion(&result.completion);
722 reinit_completion(&result.completion);
723 ret = result.err;
724 if (!ret)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300725 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300726 case -EBADMSG:
727 if (template[i].novrfy)
728 /* verification failure was expected */
729 continue;
730 /* fall through */
731 default:
732 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
733 d, e, j, algo, -ret);
734 goto out;
735 }
736
737 ret = -EINVAL;
738 for (k = 0, temp = 0; k < template[i].np; k++) {
739 if (diff_dst)
740 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
741 offset_in_page(IDX[k]);
742 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800743 q = xbuf[IDX[k] >> PAGE_SHIFT] +
744 offset_in_page(IDX[k]);
745
Cristian Stoica05b1d332014-07-28 13:11:23 +0300746 n = template[i].tap[k];
747 if (k == template[i].np - 1)
748 n += enc ? authsize : -authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800749
Cristian Stoica05b1d332014-07-28 13:11:23 +0300750 if (memcmp(q, template[i].result + temp, n)) {
751 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
752 d, j, e, k, algo);
753 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800754 goto out;
755 }
756
Cristian Stoica05b1d332014-07-28 13:11:23 +0300757 q += n;
758 if (k == template[i].np - 1 && !enc) {
759 if (!diff_dst &&
760 memcmp(q, template[i].input +
761 temp + n, authsize))
762 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200763 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300764 n = 0;
765 } else {
766 for (n = 0; offset_in_page(q + n) && q[n]; n++)
767 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800768 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300769 if (n) {
770 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
771 d, j, e, k, algo, n);
772 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800773 goto out;
774 }
775
Cristian Stoica05b1d332014-07-28 13:11:23 +0300776 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800777 }
778 }
779
780 ret = 0;
781
782out:
783 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300784 kfree(sg);
785out_nosg:
786 if (diff_dst)
787 testmgr_free_buf(xoutbuf);
788out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800789 testmgr_free_buf(axbuf);
790out_noaxbuf:
791 testmgr_free_buf(xbuf);
792out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300793 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700794 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800795 return ret;
796}
797
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300798static int test_aead(struct crypto_aead *tfm, int enc,
799 struct aead_testvec *template, unsigned int tcount)
800{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300801 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300802 int ret;
803
804 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300805 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300806 if (ret)
807 return ret;
808
809 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300810 ret = __test_aead(tfm, enc, template, tcount, true, 0);
811 if (ret)
812 return ret;
813
814 /* test unaligned buffers, check with one byte offset */
815 ret = __test_aead(tfm, enc, template, tcount, true, 1);
816 if (ret)
817 return ret;
818
819 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
820 if (alignmask) {
821 /* Check if alignment mask for tfm is correctly set. */
822 ret = __test_aead(tfm, enc, template, tcount, true,
823 alignmask + 1);
824 if (ret)
825 return ret;
826 }
827
828 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300829}
830
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000831static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800832 struct cipher_testvec *template, unsigned int tcount)
833{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000834 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
835 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000836 char *q;
837 const char *e;
838 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800839 char *xbuf[XBUFSIZE];
840 int ret = -ENOMEM;
841
842 if (testmgr_alloc_buf(xbuf))
843 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000844
845 if (enc == ENCRYPT)
846 e = "encryption";
847 else
848 e = "decryption";
849
850 j = 0;
851 for (i = 0; i < tcount; i++) {
852 if (template[i].np)
853 continue;
854
855 j++;
856
Herbert Xufd57f222009-05-29 16:05:42 +1000857 ret = -EINVAL;
858 if (WARN_ON(template[i].ilen > PAGE_SIZE))
859 goto out;
860
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000861 data = xbuf[0];
862 memcpy(data, template[i].input, template[i].ilen);
863
864 crypto_cipher_clear_flags(tfm, ~0);
865 if (template[i].wk)
866 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
867
868 ret = crypto_cipher_setkey(tfm, template[i].key,
869 template[i].klen);
870 if (!ret == template[i].fail) {
871 printk(KERN_ERR "alg: cipher: setkey failed "
872 "on test %d for %s: flags=%x\n", j,
873 algo, crypto_cipher_get_flags(tfm));
874 goto out;
875 } else if (ret)
876 continue;
877
878 for (k = 0; k < template[i].ilen;
879 k += crypto_cipher_blocksize(tfm)) {
880 if (enc)
881 crypto_cipher_encrypt_one(tfm, data + k,
882 data + k);
883 else
884 crypto_cipher_decrypt_one(tfm, data + k,
885 data + k);
886 }
887
888 q = data;
889 if (memcmp(q, template[i].result, template[i].rlen)) {
890 printk(KERN_ERR "alg: cipher: Test %d failed "
891 "on %s for %s\n", j, e, algo);
892 hexdump(q, template[i].rlen);
893 ret = -EINVAL;
894 goto out;
895 }
896 }
897
898 ret = 0;
899
900out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800901 testmgr_free_buf(xbuf);
902out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000903 return ret;
904}
905
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300906static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
907 struct cipher_testvec *template, unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300908 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000909{
Herbert Xuda7f0332008-07-31 17:08:25 +0800910 const char *algo =
911 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
912 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800913 char *q;
914 struct ablkcipher_request *req;
915 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300916 struct scatterlist sgout[8];
917 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800918 struct tcrypt_result result;
919 void *data;
920 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800921 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300922 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800923 int ret = -ENOMEM;
924
925 if (testmgr_alloc_buf(xbuf))
926 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800927
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300928 if (diff_dst && testmgr_alloc_buf(xoutbuf))
929 goto out_nooutbuf;
930
931 if (diff_dst)
932 d = "-ddst";
933 else
934 d = "";
935
Herbert Xuda7f0332008-07-31 17:08:25 +0800936 if (enc == ENCRYPT)
937 e = "encryption";
938 else
939 e = "decryption";
940
941 init_completion(&result.completion);
942
943 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
944 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300945 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
946 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800947 goto out;
948 }
949
950 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
951 tcrypt_complete, &result);
952
953 j = 0;
954 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +0300955 if (template[i].np && !template[i].also_non_np)
956 continue;
957
Herbert Xuda7f0332008-07-31 17:08:25 +0800958 if (template[i].iv)
959 memcpy(iv, template[i].iv, MAX_IVLEN);
960 else
961 memset(iv, 0, MAX_IVLEN);
962
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300963 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300964 ret = -EINVAL;
965 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
966 goto out;
967
968 data = xbuf[0];
969 data += align_offset;
970 memcpy(data, template[i].input, template[i].ilen);
971
972 crypto_ablkcipher_clear_flags(tfm, ~0);
973 if (template[i].wk)
974 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
975
976 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
977 template[i].klen);
978 if (!ret == template[i].fail) {
979 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
980 d, j, algo, crypto_ablkcipher_get_flags(tfm));
981 goto out;
982 } else if (ret)
983 continue;
984
985 sg_init_one(&sg[0], data, template[i].ilen);
986 if (diff_dst) {
987 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300988 data += align_offset;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300989 sg_init_one(&sgout[0], data, template[i].ilen);
990 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800991
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300992 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
993 template[i].ilen, iv);
994 ret = enc ? crypto_ablkcipher_encrypt(req) :
995 crypto_ablkcipher_decrypt(req);
Herbert Xuda7f0332008-07-31 17:08:25 +0800996
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300997 switch (ret) {
998 case 0:
999 break;
1000 case -EINPROGRESS:
1001 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001002 wait_for_completion(&result.completion);
1003 reinit_completion(&result.completion);
1004 ret = result.err;
1005 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +08001006 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001007 /* fall through */
1008 default:
1009 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1010 d, e, j, algo, -ret);
1011 goto out;
1012 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001013
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001014 q = data;
1015 if (memcmp(q, template[i].result, template[i].rlen)) {
1016 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1017 d, j, e, algo);
1018 hexdump(q, template[i].rlen);
1019 ret = -EINVAL;
1020 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001021 }
1022 }
1023
1024 j = 0;
1025 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001026 /* alignment tests are only done with continuous buffers */
1027 if (align_offset != 0)
1028 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001029
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001030 if (!template[i].np)
1031 continue;
1032
Herbert Xuda7f0332008-07-31 17:08:25 +08001033 if (template[i].iv)
1034 memcpy(iv, template[i].iv, MAX_IVLEN);
1035 else
1036 memset(iv, 0, MAX_IVLEN);
1037
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001038 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001039 crypto_ablkcipher_clear_flags(tfm, ~0);
1040 if (template[i].wk)
1041 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1042
1043 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1044 template[i].klen);
1045 if (!ret == template[i].fail) {
1046 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1047 d, j, algo, crypto_ablkcipher_get_flags(tfm));
1048 goto out;
1049 } else if (ret)
1050 continue;
1051
1052 temp = 0;
1053 ret = -EINVAL;
1054 sg_init_table(sg, template[i].np);
1055 if (diff_dst)
1056 sg_init_table(sgout, template[i].np);
1057 for (k = 0; k < template[i].np; k++) {
1058 if (WARN_ON(offset_in_page(IDX[k]) +
1059 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001060 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001061
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001062 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1063
1064 memcpy(q, template[i].input + temp, template[i].tap[k]);
1065
1066 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1067 q[template[i].tap[k]] = 0;
1068
1069 sg_set_buf(&sg[k], q, template[i].tap[k]);
1070 if (diff_dst) {
1071 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1072 offset_in_page(IDX[k]);
1073
1074 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1075
1076 memset(q, 0, template[i].tap[k]);
1077 if (offset_in_page(q) +
1078 template[i].tap[k] < PAGE_SIZE)
1079 q[template[i].tap[k]] = 0;
1080 }
1081
1082 temp += template[i].tap[k];
1083 }
1084
1085 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1086 template[i].ilen, iv);
1087
1088 ret = enc ? crypto_ablkcipher_encrypt(req) :
1089 crypto_ablkcipher_decrypt(req);
1090
1091 switch (ret) {
1092 case 0:
1093 break;
1094 case -EINPROGRESS:
1095 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001096 wait_for_completion(&result.completion);
1097 reinit_completion(&result.completion);
1098 ret = result.err;
1099 if (!ret)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001100 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001101 /* fall through */
1102 default:
1103 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1104 d, e, j, algo, -ret);
1105 goto out;
1106 }
1107
1108 temp = 0;
1109 ret = -EINVAL;
1110 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001111 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001112 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1113 offset_in_page(IDX[k]);
1114 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001115 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1116 offset_in_page(IDX[k]);
1117
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001118 if (memcmp(q, template[i].result + temp,
1119 template[i].tap[k])) {
1120 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1121 d, j, e, k, algo);
1122 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001123 goto out;
1124 }
1125
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001126 q += template[i].tap[k];
1127 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1128 ;
1129 if (n) {
1130 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1131 d, j, e, k, algo, n);
1132 hexdump(q, n);
1133 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001134 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001135 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001136 }
1137 }
1138
1139 ret = 0;
1140
1141out:
1142 ablkcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001143 if (diff_dst)
1144 testmgr_free_buf(xoutbuf);
1145out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001146 testmgr_free_buf(xbuf);
1147out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001148 return ret;
1149}
1150
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001151static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1152 struct cipher_testvec *template, unsigned int tcount)
1153{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001154 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001155 int ret;
1156
1157 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001158 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001159 if (ret)
1160 return ret;
1161
1162 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001163 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1164 if (ret)
1165 return ret;
1166
1167 /* test unaligned buffers, check with one byte offset */
1168 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1169 if (ret)
1170 return ret;
1171
1172 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1173 if (alignmask) {
1174 /* Check if alignment mask for tfm is correctly set. */
1175 ret = __test_skcipher(tfm, enc, template, tcount, true,
1176 alignmask + 1);
1177 if (ret)
1178 return ret;
1179 }
1180
1181 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001182}
1183
Herbert Xuda7f0332008-07-31 17:08:25 +08001184static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1185 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1186{
1187 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1188 unsigned int i;
1189 char result[COMP_BUF_SIZE];
1190 int ret;
1191
1192 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001193 int ilen;
1194 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001195
1196 memset(result, 0, sizeof (result));
1197
1198 ilen = ctemplate[i].inlen;
1199 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1200 ilen, result, &dlen);
1201 if (ret) {
1202 printk(KERN_ERR "alg: comp: compression failed "
1203 "on test %d for %s: ret=%d\n", i + 1, algo,
1204 -ret);
1205 goto out;
1206 }
1207
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001208 if (dlen != ctemplate[i].outlen) {
1209 printk(KERN_ERR "alg: comp: Compression test %d "
1210 "failed for %s: output len = %d\n", i + 1, algo,
1211 dlen);
1212 ret = -EINVAL;
1213 goto out;
1214 }
1215
Herbert Xuda7f0332008-07-31 17:08:25 +08001216 if (memcmp(result, ctemplate[i].output, dlen)) {
1217 printk(KERN_ERR "alg: comp: Compression test %d "
1218 "failed for %s\n", i + 1, algo);
1219 hexdump(result, dlen);
1220 ret = -EINVAL;
1221 goto out;
1222 }
1223 }
1224
1225 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001226 int ilen;
1227 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001228
1229 memset(result, 0, sizeof (result));
1230
1231 ilen = dtemplate[i].inlen;
1232 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1233 ilen, result, &dlen);
1234 if (ret) {
1235 printk(KERN_ERR "alg: comp: decompression failed "
1236 "on test %d for %s: ret=%d\n", i + 1, algo,
1237 -ret);
1238 goto out;
1239 }
1240
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001241 if (dlen != dtemplate[i].outlen) {
1242 printk(KERN_ERR "alg: comp: Decompression test %d "
1243 "failed for %s: output len = %d\n", i + 1, algo,
1244 dlen);
1245 ret = -EINVAL;
1246 goto out;
1247 }
1248
Herbert Xuda7f0332008-07-31 17:08:25 +08001249 if (memcmp(result, dtemplate[i].output, dlen)) {
1250 printk(KERN_ERR "alg: comp: Decompression test %d "
1251 "failed for %s\n", i + 1, algo);
1252 hexdump(result, dlen);
1253 ret = -EINVAL;
1254 goto out;
1255 }
1256 }
1257
1258 ret = 0;
1259
1260out:
1261 return ret;
1262}
1263
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001264static int test_pcomp(struct crypto_pcomp *tfm,
1265 struct pcomp_testvec *ctemplate,
1266 struct pcomp_testvec *dtemplate, int ctcount,
1267 int dtcount)
1268{
1269 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1270 unsigned int i;
1271 char result[COMP_BUF_SIZE];
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001272 int res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001273
1274 for (i = 0; i < ctcount; i++) {
1275 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001276 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001277
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001278 res = crypto_compress_setup(tfm, ctemplate[i].params,
1279 ctemplate[i].paramsize);
1280 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001281 pr_err("alg: pcomp: compression setup failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001282 "%d for %s: error=%d\n", i + 1, algo, res);
1283 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001284 }
1285
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001286 res = crypto_compress_init(tfm);
1287 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001288 pr_err("alg: pcomp: compression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001289 "%d for %s: error=%d\n", i + 1, algo, res);
1290 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001291 }
1292
1293 memset(result, 0, sizeof(result));
1294
1295 req.next_in = ctemplate[i].input;
1296 req.avail_in = ctemplate[i].inlen / 2;
1297 req.next_out = result;
1298 req.avail_out = ctemplate[i].outlen / 2;
1299
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001300 res = crypto_compress_update(tfm, &req);
1301 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001302 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001303 "%d for %s: error=%d\n", i + 1, algo, res);
1304 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001305 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001306 if (res > 0)
1307 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001308
1309 /* Add remaining input data */
1310 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1311
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001312 res = crypto_compress_update(tfm, &req);
1313 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001314 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001315 "%d for %s: error=%d\n", i + 1, algo, res);
1316 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001317 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001318 if (res > 0)
1319 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001320
1321 /* Provide remaining output space */
1322 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1323
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001324 res = crypto_compress_final(tfm, &req);
1325 if (res < 0) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001326 pr_err("alg: pcomp: compression final failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001327 "%d for %s: error=%d\n", i + 1, algo, res);
1328 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001329 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001330 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001331
1332 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1333 pr_err("alg: comp: Compression test %d failed for %s: "
1334 "output len = %d (expected %d)\n", i + 1, algo,
1335 COMP_BUF_SIZE - req.avail_out,
1336 ctemplate[i].outlen);
1337 return -EINVAL;
1338 }
1339
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001340 if (produced != ctemplate[i].outlen) {
1341 pr_err("alg: comp: Compression test %d failed for %s: "
1342 "returned len = %u (expected %d)\n", i + 1,
1343 algo, produced, ctemplate[i].outlen);
1344 return -EINVAL;
1345 }
1346
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001347 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1348 pr_err("alg: pcomp: Compression test %d failed for "
1349 "%s\n", i + 1, algo);
1350 hexdump(result, ctemplate[i].outlen);
1351 return -EINVAL;
1352 }
1353 }
1354
1355 for (i = 0; i < dtcount; i++) {
1356 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001357 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001358
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001359 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1360 dtemplate[i].paramsize);
1361 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001362 pr_err("alg: pcomp: decompression setup failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001363 "test %d for %s: error=%d\n", i + 1, algo, res);
1364 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001365 }
1366
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001367 res = crypto_decompress_init(tfm);
1368 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001369 pr_err("alg: pcomp: decompression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001370 "%d for %s: error=%d\n", i + 1, algo, res);
1371 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001372 }
1373
1374 memset(result, 0, sizeof(result));
1375
1376 req.next_in = dtemplate[i].input;
1377 req.avail_in = dtemplate[i].inlen / 2;
1378 req.next_out = result;
1379 req.avail_out = dtemplate[i].outlen / 2;
1380
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001381 res = crypto_decompress_update(tfm, &req);
1382 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001383 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001384 "test %d for %s: error=%d\n", i + 1, algo, res);
1385 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001386 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001387 if (res > 0)
1388 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001389
1390 /* Add remaining input data */
1391 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1392
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001393 res = crypto_decompress_update(tfm, &req);
1394 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001395 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001396 "test %d for %s: error=%d\n", i + 1, algo, res);
1397 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001398 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001399 if (res > 0)
1400 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001401
1402 /* Provide remaining output space */
1403 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1404
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001405 res = crypto_decompress_final(tfm, &req);
1406 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001407 pr_err("alg: pcomp: decompression final failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001408 "test %d for %s: error=%d\n", i + 1, algo, res);
1409 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001410 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001411 if (res > 0)
1412 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001413
1414 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1415 pr_err("alg: comp: Decompression test %d failed for "
1416 "%s: output len = %d (expected %d)\n", i + 1,
1417 algo, COMP_BUF_SIZE - req.avail_out,
1418 dtemplate[i].outlen);
1419 return -EINVAL;
1420 }
1421
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001422 if (produced != dtemplate[i].outlen) {
1423 pr_err("alg: comp: Decompression test %d failed for "
1424 "%s: returned len = %u (expected %d)\n", i + 1,
1425 algo, produced, dtemplate[i].outlen);
1426 return -EINVAL;
1427 }
1428
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001429 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1430 pr_err("alg: pcomp: Decompression test %d failed for "
1431 "%s\n", i + 1, algo);
1432 hexdump(result, dtemplate[i].outlen);
1433 return -EINVAL;
1434 }
1435 }
1436
1437 return 0;
1438}
1439
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001440
1441static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1442 unsigned int tcount)
1443{
1444 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001445 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001446 u8 *seed;
1447 char result[32];
1448
1449 seedsize = crypto_rng_seedsize(tfm);
1450
1451 seed = kmalloc(seedsize, GFP_KERNEL);
1452 if (!seed) {
1453 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1454 "for %s\n", algo);
1455 return -ENOMEM;
1456 }
1457
1458 for (i = 0; i < tcount; i++) {
1459 memset(result, 0, 32);
1460
1461 memcpy(seed, template[i].v, template[i].vlen);
1462 memcpy(seed + template[i].vlen, template[i].key,
1463 template[i].klen);
1464 memcpy(seed + template[i].vlen + template[i].klen,
1465 template[i].dt, template[i].dtlen);
1466
1467 err = crypto_rng_reset(tfm, seed, seedsize);
1468 if (err) {
1469 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1470 "for %s\n", algo);
1471 goto out;
1472 }
1473
1474 for (j = 0; j < template[i].loops; j++) {
1475 err = crypto_rng_get_bytes(tfm, result,
1476 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01001477 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001478 printk(KERN_ERR "alg: cprng: Failed to obtain "
1479 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01001480 "%s (requested %d)\n", algo,
1481 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001482 goto out;
1483 }
1484 }
1485
1486 err = memcmp(result, template[i].result,
1487 template[i].rlen);
1488 if (err) {
1489 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1490 i, algo);
1491 hexdump(result, template[i].rlen);
1492 err = -EINVAL;
1493 goto out;
1494 }
1495 }
1496
1497out:
1498 kfree(seed);
1499 return err;
1500}
1501
Herbert Xuda7f0332008-07-31 17:08:25 +08001502static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1503 u32 type, u32 mask)
1504{
1505 struct crypto_aead *tfm;
1506 int err = 0;
1507
Stephan Mueller425a8822015-03-30 21:56:31 +02001508 tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001509 if (IS_ERR(tfm)) {
1510 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1511 "%ld\n", driver, PTR_ERR(tfm));
1512 return PTR_ERR(tfm);
1513 }
1514
1515 if (desc->suite.aead.enc.vecs) {
1516 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1517 desc->suite.aead.enc.count);
1518 if (err)
1519 goto out;
1520 }
1521
1522 if (!err && desc->suite.aead.dec.vecs)
1523 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1524 desc->suite.aead.dec.count);
1525
1526out:
1527 crypto_free_aead(tfm);
1528 return err;
1529}
1530
1531static int alg_test_cipher(const struct alg_test_desc *desc,
1532 const char *driver, u32 type, u32 mask)
1533{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001534 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001535 int err = 0;
1536
Stephan Mueller425a8822015-03-30 21:56:31 +02001537 tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001538 if (IS_ERR(tfm)) {
1539 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1540 "%s: %ld\n", driver, PTR_ERR(tfm));
1541 return PTR_ERR(tfm);
1542 }
1543
1544 if (desc->suite.cipher.enc.vecs) {
1545 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1546 desc->suite.cipher.enc.count);
1547 if (err)
1548 goto out;
1549 }
1550
1551 if (desc->suite.cipher.dec.vecs)
1552 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1553 desc->suite.cipher.dec.count);
1554
1555out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001556 crypto_free_cipher(tfm);
1557 return err;
1558}
1559
1560static int alg_test_skcipher(const struct alg_test_desc *desc,
1561 const char *driver, u32 type, u32 mask)
1562{
1563 struct crypto_ablkcipher *tfm;
1564 int err = 0;
1565
Stephan Mueller425a8822015-03-30 21:56:31 +02001566 tfm = crypto_alloc_ablkcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001567 if (IS_ERR(tfm)) {
1568 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1569 "%s: %ld\n", driver, PTR_ERR(tfm));
1570 return PTR_ERR(tfm);
1571 }
1572
1573 if (desc->suite.cipher.enc.vecs) {
1574 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1575 desc->suite.cipher.enc.count);
1576 if (err)
1577 goto out;
1578 }
1579
1580 if (desc->suite.cipher.dec.vecs)
1581 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1582 desc->suite.cipher.dec.count);
1583
1584out:
Herbert Xuda7f0332008-07-31 17:08:25 +08001585 crypto_free_ablkcipher(tfm);
1586 return err;
1587}
1588
1589static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1590 u32 type, u32 mask)
1591{
1592 struct crypto_comp *tfm;
1593 int err;
1594
1595 tfm = crypto_alloc_comp(driver, type, mask);
1596 if (IS_ERR(tfm)) {
1597 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1598 "%ld\n", driver, PTR_ERR(tfm));
1599 return PTR_ERR(tfm);
1600 }
1601
1602 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1603 desc->suite.comp.decomp.vecs,
1604 desc->suite.comp.comp.count,
1605 desc->suite.comp.decomp.count);
1606
1607 crypto_free_comp(tfm);
1608 return err;
1609}
1610
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001611static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1612 u32 type, u32 mask)
1613{
1614 struct crypto_pcomp *tfm;
1615 int err;
1616
1617 tfm = crypto_alloc_pcomp(driver, type, mask);
1618 if (IS_ERR(tfm)) {
1619 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1620 driver, PTR_ERR(tfm));
1621 return PTR_ERR(tfm);
1622 }
1623
1624 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1625 desc->suite.pcomp.decomp.vecs,
1626 desc->suite.pcomp.comp.count,
1627 desc->suite.pcomp.decomp.count);
1628
1629 crypto_free_pcomp(tfm);
1630 return err;
1631}
1632
Herbert Xuda7f0332008-07-31 17:08:25 +08001633static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1634 u32 type, u32 mask)
1635{
1636 struct crypto_ahash *tfm;
1637 int err;
1638
Stephan Mueller425a8822015-03-30 21:56:31 +02001639 tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001640 if (IS_ERR(tfm)) {
1641 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1642 "%ld\n", driver, PTR_ERR(tfm));
1643 return PTR_ERR(tfm);
1644 }
1645
David S. Millera8f1a052010-05-19 14:12:03 +10001646 err = test_hash(tfm, desc->suite.hash.vecs,
1647 desc->suite.hash.count, true);
1648 if (!err)
1649 err = test_hash(tfm, desc->suite.hash.vecs,
1650 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001651
1652 crypto_free_ahash(tfm);
1653 return err;
1654}
1655
Herbert Xu8e3ee852008-11-07 14:58:52 +08001656static int alg_test_crc32c(const struct alg_test_desc *desc,
1657 const char *driver, u32 type, u32 mask)
1658{
1659 struct crypto_shash *tfm;
1660 u32 val;
1661 int err;
1662
1663 err = alg_test_hash(desc, driver, type, mask);
1664 if (err)
1665 goto out;
1666
Stephan Mueller425a8822015-03-30 21:56:31 +02001667 tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001668 if (IS_ERR(tfm)) {
1669 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1670 "%ld\n", driver, PTR_ERR(tfm));
1671 err = PTR_ERR(tfm);
1672 goto out;
1673 }
1674
1675 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001676 SHASH_DESC_ON_STACK(shash, tfm);
1677 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001678
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001679 shash->tfm = tfm;
1680 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001681
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001682 *ctx = le32_to_cpu(420553207);
1683 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001684 if (err) {
1685 printk(KERN_ERR "alg: crc32c: Operation failed for "
1686 "%s: %d\n", driver, err);
1687 break;
1688 }
1689
1690 if (val != ~420553207) {
1691 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1692 "%d\n", driver, val);
1693 err = -EINVAL;
1694 }
1695 } while (0);
1696
1697 crypto_free_shash(tfm);
1698
1699out:
1700 return err;
1701}
1702
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001703static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1704 u32 type, u32 mask)
1705{
1706 struct crypto_rng *rng;
1707 int err;
1708
Stephan Mueller425a8822015-03-30 21:56:31 +02001709 rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001710 if (IS_ERR(rng)) {
1711 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1712 "%ld\n", driver, PTR_ERR(rng));
1713 return PTR_ERR(rng);
1714 }
1715
1716 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1717
1718 crypto_free_rng(rng);
1719
1720 return err;
1721}
1722
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001723
1724static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1725 const char *driver, u32 type, u32 mask)
1726{
1727 int ret = -EAGAIN;
1728 struct crypto_rng *drng;
1729 struct drbg_test_data test_data;
1730 struct drbg_string addtl, pers, testentropy;
1731 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1732
1733 if (!buf)
1734 return -ENOMEM;
1735
Stephan Mueller425a8822015-03-30 21:56:31 +02001736 drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001737 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001738 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001739 "%s\n", driver);
1740 kzfree(buf);
1741 return -ENOMEM;
1742 }
1743
1744 test_data.testentropy = &testentropy;
1745 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1746 drbg_string_fill(&pers, test->pers, test->perslen);
1747 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1748 if (ret) {
1749 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1750 goto outbuf;
1751 }
1752
1753 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1754 if (pr) {
1755 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1756 ret = crypto_drbg_get_bytes_addtl_test(drng,
1757 buf, test->expectedlen, &addtl, &test_data);
1758 } else {
1759 ret = crypto_drbg_get_bytes_addtl(drng,
1760 buf, test->expectedlen, &addtl);
1761 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001762 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001763 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001764 "driver %s\n", driver);
1765 goto outbuf;
1766 }
1767
1768 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1769 if (pr) {
1770 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1771 ret = crypto_drbg_get_bytes_addtl_test(drng,
1772 buf, test->expectedlen, &addtl, &test_data);
1773 } else {
1774 ret = crypto_drbg_get_bytes_addtl(drng,
1775 buf, test->expectedlen, &addtl);
1776 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001777 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001778 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001779 "driver %s\n", driver);
1780 goto outbuf;
1781 }
1782
1783 ret = memcmp(test->expected, buf, test->expectedlen);
1784
1785outbuf:
1786 crypto_free_rng(drng);
1787 kzfree(buf);
1788 return ret;
1789}
1790
1791
1792static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1793 u32 type, u32 mask)
1794{
1795 int err = 0;
1796 int pr = 0;
1797 int i = 0;
1798 struct drbg_testvec *template = desc->suite.drbg.vecs;
1799 unsigned int tcount = desc->suite.drbg.count;
1800
1801 if (0 == memcmp(driver, "drbg_pr_", 8))
1802 pr = 1;
1803
1804 for (i = 0; i < tcount; i++) {
1805 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1806 if (err) {
1807 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1808 i, driver);
1809 err = -EINVAL;
1810 break;
1811 }
1812 }
1813 return err;
1814
1815}
1816
Youquan, Song863b5572009-12-23 19:45:20 +08001817static int alg_test_null(const struct alg_test_desc *desc,
1818 const char *driver, u32 type, u32 mask)
1819{
1820 return 0;
1821}
1822
Herbert Xuda7f0332008-07-31 17:08:25 +08001823/* Please keep this list sorted by algorithm name. */
1824static const struct alg_test_desc alg_test_descs[] = {
1825 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001826 .alg = "__cbc-cast5-avx",
1827 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001828 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001829 .alg = "__cbc-cast6-avx",
1830 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001831 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001832 .alg = "__cbc-serpent-avx",
1833 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001834 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001835 .alg = "__cbc-serpent-avx2",
1836 .test = alg_test_null,
1837 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001838 .alg = "__cbc-serpent-sse2",
1839 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001840 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001841 .alg = "__cbc-twofish-avx",
1842 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001843 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001844 .alg = "__driver-cbc-aes-aesni",
1845 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001846 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001847 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001848 .alg = "__driver-cbc-camellia-aesni",
1849 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001850 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001851 .alg = "__driver-cbc-camellia-aesni-avx2",
1852 .test = alg_test_null,
1853 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001854 .alg = "__driver-cbc-cast5-avx",
1855 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001856 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001857 .alg = "__driver-cbc-cast6-avx",
1858 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001859 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001860 .alg = "__driver-cbc-serpent-avx",
1861 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001862 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001863 .alg = "__driver-cbc-serpent-avx2",
1864 .test = alg_test_null,
1865 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001866 .alg = "__driver-cbc-serpent-sse2",
1867 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001868 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001869 .alg = "__driver-cbc-twofish-avx",
1870 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001871 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001872 .alg = "__driver-ecb-aes-aesni",
1873 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001874 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001875 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001876 .alg = "__driver-ecb-camellia-aesni",
1877 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001878 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001879 .alg = "__driver-ecb-camellia-aesni-avx2",
1880 .test = alg_test_null,
1881 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001882 .alg = "__driver-ecb-cast5-avx",
1883 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001884 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001885 .alg = "__driver-ecb-cast6-avx",
1886 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001887 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001888 .alg = "__driver-ecb-serpent-avx",
1889 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001890 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001891 .alg = "__driver-ecb-serpent-avx2",
1892 .test = alg_test_null,
1893 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001894 .alg = "__driver-ecb-serpent-sse2",
1895 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001896 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001897 .alg = "__driver-ecb-twofish-avx",
1898 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001899 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001900 .alg = "__ghash-pclmulqdqni",
1901 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001902 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001903 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001904 .alg = "ansi_cprng",
1905 .test = alg_test_cprng,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001906 .fips_allowed = 1,
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001907 .suite = {
1908 .cprng = {
1909 .vecs = ansi_cprng_aes_tv_template,
1910 .count = ANSI_CPRNG_AES_TEST_VECTORS
1911 }
1912 }
1913 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001914 .alg = "authenc(hmac(md5),ecb(cipher_null))",
1915 .test = alg_test_aead,
1916 .fips_allowed = 1,
1917 .suite = {
1918 .aead = {
1919 .enc = {
1920 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
1921 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1922 },
1923 .dec = {
1924 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
1925 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1926 }
1927 }
1928 }
1929 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03001930 .alg = "authenc(hmac(sha1),cbc(aes))",
1931 .test = alg_test_aead,
1932 .fips_allowed = 1,
1933 .suite = {
1934 .aead = {
1935 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301936 .vecs =
1937 hmac_sha1_aes_cbc_enc_tv_temp,
1938 .count =
1939 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1940 }
1941 }
1942 }
1943 }, {
1944 .alg = "authenc(hmac(sha1),cbc(des))",
1945 .test = alg_test_aead,
1946 .fips_allowed = 1,
1947 .suite = {
1948 .aead = {
1949 .enc = {
1950 .vecs =
1951 hmac_sha1_des_cbc_enc_tv_temp,
1952 .count =
1953 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1954 }
1955 }
1956 }
1957 }, {
1958 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
1959 .test = alg_test_aead,
1960 .fips_allowed = 1,
1961 .suite = {
1962 .aead = {
1963 .enc = {
1964 .vecs =
1965 hmac_sha1_des3_ede_cbc_enc_tv_temp,
1966 .count =
1967 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03001968 }
1969 }
1970 }
1971 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001972 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
1973 .test = alg_test_aead,
1974 .fips_allowed = 1,
1975 .suite = {
1976 .aead = {
1977 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301978 .vecs =
1979 hmac_sha1_ecb_cipher_null_enc_tv_temp,
1980 .count =
1981 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02001982 },
1983 .dec = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301984 .vecs =
1985 hmac_sha1_ecb_cipher_null_dec_tv_temp,
1986 .count =
1987 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
1988 }
1989 }
1990 }
1991 }, {
1992 .alg = "authenc(hmac(sha224),cbc(des))",
1993 .test = alg_test_aead,
1994 .fips_allowed = 1,
1995 .suite = {
1996 .aead = {
1997 .enc = {
1998 .vecs =
1999 hmac_sha224_des_cbc_enc_tv_temp,
2000 .count =
2001 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2002 }
2003 }
2004 }
2005 }, {
2006 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
2007 .test = alg_test_aead,
2008 .fips_allowed = 1,
2009 .suite = {
2010 .aead = {
2011 .enc = {
2012 .vecs =
2013 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2014 .count =
2015 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002016 }
2017 }
2018 }
2019 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03002020 .alg = "authenc(hmac(sha256),cbc(aes))",
2021 .test = alg_test_aead,
2022 .fips_allowed = 1,
2023 .suite = {
2024 .aead = {
2025 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302026 .vecs =
2027 hmac_sha256_aes_cbc_enc_tv_temp,
2028 .count =
2029 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2030 }
2031 }
2032 }
2033 }, {
2034 .alg = "authenc(hmac(sha256),cbc(des))",
2035 .test = alg_test_aead,
2036 .fips_allowed = 1,
2037 .suite = {
2038 .aead = {
2039 .enc = {
2040 .vecs =
2041 hmac_sha256_des_cbc_enc_tv_temp,
2042 .count =
2043 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2044 }
2045 }
2046 }
2047 }, {
2048 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
2049 .test = alg_test_aead,
2050 .fips_allowed = 1,
2051 .suite = {
2052 .aead = {
2053 .enc = {
2054 .vecs =
2055 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2056 .count =
2057 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2058 }
2059 }
2060 }
2061 }, {
2062 .alg = "authenc(hmac(sha384),cbc(des))",
2063 .test = alg_test_aead,
2064 .fips_allowed = 1,
2065 .suite = {
2066 .aead = {
2067 .enc = {
2068 .vecs =
2069 hmac_sha384_des_cbc_enc_tv_temp,
2070 .count =
2071 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2072 }
2073 }
2074 }
2075 }, {
2076 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
2077 .test = alg_test_aead,
2078 .fips_allowed = 1,
2079 .suite = {
2080 .aead = {
2081 .enc = {
2082 .vecs =
2083 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2084 .count =
2085 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002086 }
2087 }
2088 }
2089 }, {
2090 .alg = "authenc(hmac(sha512),cbc(aes))",
2091 .test = alg_test_aead,
2092 .fips_allowed = 1,
2093 .suite = {
2094 .aead = {
2095 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302096 .vecs =
2097 hmac_sha512_aes_cbc_enc_tv_temp,
2098 .count =
2099 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2100 }
2101 }
2102 }
2103 }, {
2104 .alg = "authenc(hmac(sha512),cbc(des))",
2105 .test = alg_test_aead,
2106 .fips_allowed = 1,
2107 .suite = {
2108 .aead = {
2109 .enc = {
2110 .vecs =
2111 hmac_sha512_des_cbc_enc_tv_temp,
2112 .count =
2113 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2114 }
2115 }
2116 }
2117 }, {
2118 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2119 .test = alg_test_aead,
2120 .fips_allowed = 1,
2121 .suite = {
2122 .aead = {
2123 .enc = {
2124 .vecs =
2125 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2126 .count =
2127 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002128 }
2129 }
2130 }
2131 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002132 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002133 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002134 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002135 .suite = {
2136 .cipher = {
2137 .enc = {
2138 .vecs = aes_cbc_enc_tv_template,
2139 .count = AES_CBC_ENC_TEST_VECTORS
2140 },
2141 .dec = {
2142 .vecs = aes_cbc_dec_tv_template,
2143 .count = AES_CBC_DEC_TEST_VECTORS
2144 }
2145 }
2146 }
2147 }, {
2148 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002149 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002150 .suite = {
2151 .cipher = {
2152 .enc = {
2153 .vecs = anubis_cbc_enc_tv_template,
2154 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2155 },
2156 .dec = {
2157 .vecs = anubis_cbc_dec_tv_template,
2158 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2159 }
2160 }
2161 }
2162 }, {
2163 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002164 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002165 .suite = {
2166 .cipher = {
2167 .enc = {
2168 .vecs = bf_cbc_enc_tv_template,
2169 .count = BF_CBC_ENC_TEST_VECTORS
2170 },
2171 .dec = {
2172 .vecs = bf_cbc_dec_tv_template,
2173 .count = BF_CBC_DEC_TEST_VECTORS
2174 }
2175 }
2176 }
2177 }, {
2178 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002179 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002180 .suite = {
2181 .cipher = {
2182 .enc = {
2183 .vecs = camellia_cbc_enc_tv_template,
2184 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2185 },
2186 .dec = {
2187 .vecs = camellia_cbc_dec_tv_template,
2188 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2189 }
2190 }
2191 }
2192 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002193 .alg = "cbc(cast5)",
2194 .test = alg_test_skcipher,
2195 .suite = {
2196 .cipher = {
2197 .enc = {
2198 .vecs = cast5_cbc_enc_tv_template,
2199 .count = CAST5_CBC_ENC_TEST_VECTORS
2200 },
2201 .dec = {
2202 .vecs = cast5_cbc_dec_tv_template,
2203 .count = CAST5_CBC_DEC_TEST_VECTORS
2204 }
2205 }
2206 }
2207 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002208 .alg = "cbc(cast6)",
2209 .test = alg_test_skcipher,
2210 .suite = {
2211 .cipher = {
2212 .enc = {
2213 .vecs = cast6_cbc_enc_tv_template,
2214 .count = CAST6_CBC_ENC_TEST_VECTORS
2215 },
2216 .dec = {
2217 .vecs = cast6_cbc_dec_tv_template,
2218 .count = CAST6_CBC_DEC_TEST_VECTORS
2219 }
2220 }
2221 }
2222 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002223 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002224 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002225 .suite = {
2226 .cipher = {
2227 .enc = {
2228 .vecs = des_cbc_enc_tv_template,
2229 .count = DES_CBC_ENC_TEST_VECTORS
2230 },
2231 .dec = {
2232 .vecs = des_cbc_dec_tv_template,
2233 .count = DES_CBC_DEC_TEST_VECTORS
2234 }
2235 }
2236 }
2237 }, {
2238 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002239 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002240 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002241 .suite = {
2242 .cipher = {
2243 .enc = {
2244 .vecs = des3_ede_cbc_enc_tv_template,
2245 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2246 },
2247 .dec = {
2248 .vecs = des3_ede_cbc_dec_tv_template,
2249 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2250 }
2251 }
2252 }
2253 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002254 .alg = "cbc(serpent)",
2255 .test = alg_test_skcipher,
2256 .suite = {
2257 .cipher = {
2258 .enc = {
2259 .vecs = serpent_cbc_enc_tv_template,
2260 .count = SERPENT_CBC_ENC_TEST_VECTORS
2261 },
2262 .dec = {
2263 .vecs = serpent_cbc_dec_tv_template,
2264 .count = SERPENT_CBC_DEC_TEST_VECTORS
2265 }
2266 }
2267 }
2268 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002269 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002270 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002271 .suite = {
2272 .cipher = {
2273 .enc = {
2274 .vecs = tf_cbc_enc_tv_template,
2275 .count = TF_CBC_ENC_TEST_VECTORS
2276 },
2277 .dec = {
2278 .vecs = tf_cbc_dec_tv_template,
2279 .count = TF_CBC_DEC_TEST_VECTORS
2280 }
2281 }
2282 }
2283 }, {
2284 .alg = "ccm(aes)",
2285 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002286 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002287 .suite = {
2288 .aead = {
2289 .enc = {
2290 .vecs = aes_ccm_enc_tv_template,
2291 .count = AES_CCM_ENC_TEST_VECTORS
2292 },
2293 .dec = {
2294 .vecs = aes_ccm_dec_tv_template,
2295 .count = AES_CCM_DEC_TEST_VECTORS
2296 }
2297 }
2298 }
2299 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002300 .alg = "cmac(aes)",
2301 .test = alg_test_hash,
2302 .suite = {
2303 .hash = {
2304 .vecs = aes_cmac128_tv_template,
2305 .count = CMAC_AES_TEST_VECTORS
2306 }
2307 }
2308 }, {
2309 .alg = "cmac(des3_ede)",
2310 .test = alg_test_hash,
2311 .suite = {
2312 .hash = {
2313 .vecs = des3_ede_cmac64_tv_template,
2314 .count = CMAC_DES3_EDE_TEST_VECTORS
2315 }
2316 }
2317 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002318 .alg = "compress_null",
2319 .test = alg_test_null,
2320 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002321 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002322 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002323 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002324 .suite = {
2325 .hash = {
2326 .vecs = crc32c_tv_template,
2327 .count = CRC32C_TEST_VECTORS
2328 }
2329 }
2330 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002331 .alg = "crct10dif",
2332 .test = alg_test_hash,
2333 .fips_allowed = 1,
2334 .suite = {
2335 .hash = {
2336 .vecs = crct10dif_tv_template,
2337 .count = CRCT10DIF_TEST_VECTORS
2338 }
2339 }
2340 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002341 .alg = "cryptd(__driver-cbc-aes-aesni)",
2342 .test = alg_test_null,
2343 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002344 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002345 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2346 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002347 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002348 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2349 .test = alg_test_null,
2350 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002351 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2352 .test = alg_test_null,
2353 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002354 .alg = "cryptd(__driver-ecb-aes-aesni)",
2355 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002356 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002357 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002358 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2359 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002360 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002361 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2362 .test = alg_test_null,
2363 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002364 .alg = "cryptd(__driver-ecb-cast5-avx)",
2365 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002366 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002367 .alg = "cryptd(__driver-ecb-cast6-avx)",
2368 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002369 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002370 .alg = "cryptd(__driver-ecb-serpent-avx)",
2371 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002372 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002373 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2374 .test = alg_test_null,
2375 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002376 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2377 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002378 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002379 .alg = "cryptd(__driver-ecb-twofish-avx)",
2380 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002381 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002382 .alg = "cryptd(__driver-gcm-aes-aesni)",
2383 .test = alg_test_null,
2384 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002385 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002386 .alg = "cryptd(__ghash-pclmulqdqni)",
2387 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002388 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002389 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002390 .alg = "ctr(aes)",
2391 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002392 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002393 .suite = {
2394 .cipher = {
2395 .enc = {
2396 .vecs = aes_ctr_enc_tv_template,
2397 .count = AES_CTR_ENC_TEST_VECTORS
2398 },
2399 .dec = {
2400 .vecs = aes_ctr_dec_tv_template,
2401 .count = AES_CTR_DEC_TEST_VECTORS
2402 }
2403 }
2404 }
2405 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002406 .alg = "ctr(blowfish)",
2407 .test = alg_test_skcipher,
2408 .suite = {
2409 .cipher = {
2410 .enc = {
2411 .vecs = bf_ctr_enc_tv_template,
2412 .count = BF_CTR_ENC_TEST_VECTORS
2413 },
2414 .dec = {
2415 .vecs = bf_ctr_dec_tv_template,
2416 .count = BF_CTR_DEC_TEST_VECTORS
2417 }
2418 }
2419 }
2420 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002421 .alg = "ctr(camellia)",
2422 .test = alg_test_skcipher,
2423 .suite = {
2424 .cipher = {
2425 .enc = {
2426 .vecs = camellia_ctr_enc_tv_template,
2427 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2428 },
2429 .dec = {
2430 .vecs = camellia_ctr_dec_tv_template,
2431 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2432 }
2433 }
2434 }
2435 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002436 .alg = "ctr(cast5)",
2437 .test = alg_test_skcipher,
2438 .suite = {
2439 .cipher = {
2440 .enc = {
2441 .vecs = cast5_ctr_enc_tv_template,
2442 .count = CAST5_CTR_ENC_TEST_VECTORS
2443 },
2444 .dec = {
2445 .vecs = cast5_ctr_dec_tv_template,
2446 .count = CAST5_CTR_DEC_TEST_VECTORS
2447 }
2448 }
2449 }
2450 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002451 .alg = "ctr(cast6)",
2452 .test = alg_test_skcipher,
2453 .suite = {
2454 .cipher = {
2455 .enc = {
2456 .vecs = cast6_ctr_enc_tv_template,
2457 .count = CAST6_CTR_ENC_TEST_VECTORS
2458 },
2459 .dec = {
2460 .vecs = cast6_ctr_dec_tv_template,
2461 .count = CAST6_CTR_DEC_TEST_VECTORS
2462 }
2463 }
2464 }
2465 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002466 .alg = "ctr(des)",
2467 .test = alg_test_skcipher,
2468 .suite = {
2469 .cipher = {
2470 .enc = {
2471 .vecs = des_ctr_enc_tv_template,
2472 .count = DES_CTR_ENC_TEST_VECTORS
2473 },
2474 .dec = {
2475 .vecs = des_ctr_dec_tv_template,
2476 .count = DES_CTR_DEC_TEST_VECTORS
2477 }
2478 }
2479 }
2480 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002481 .alg = "ctr(des3_ede)",
2482 .test = alg_test_skcipher,
2483 .suite = {
2484 .cipher = {
2485 .enc = {
2486 .vecs = des3_ede_ctr_enc_tv_template,
2487 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2488 },
2489 .dec = {
2490 .vecs = des3_ede_ctr_dec_tv_template,
2491 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2492 }
2493 }
2494 }
2495 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002496 .alg = "ctr(serpent)",
2497 .test = alg_test_skcipher,
2498 .suite = {
2499 .cipher = {
2500 .enc = {
2501 .vecs = serpent_ctr_enc_tv_template,
2502 .count = SERPENT_CTR_ENC_TEST_VECTORS
2503 },
2504 .dec = {
2505 .vecs = serpent_ctr_dec_tv_template,
2506 .count = SERPENT_CTR_DEC_TEST_VECTORS
2507 }
2508 }
2509 }
2510 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002511 .alg = "ctr(twofish)",
2512 .test = alg_test_skcipher,
2513 .suite = {
2514 .cipher = {
2515 .enc = {
2516 .vecs = tf_ctr_enc_tv_template,
2517 .count = TF_CTR_ENC_TEST_VECTORS
2518 },
2519 .dec = {
2520 .vecs = tf_ctr_dec_tv_template,
2521 .count = TF_CTR_DEC_TEST_VECTORS
2522 }
2523 }
2524 }
2525 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002526 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002527 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002528 .suite = {
2529 .cipher = {
2530 .enc = {
2531 .vecs = cts_mode_enc_tv_template,
2532 .count = CTS_MODE_ENC_TEST_VECTORS
2533 },
2534 .dec = {
2535 .vecs = cts_mode_dec_tv_template,
2536 .count = CTS_MODE_DEC_TEST_VECTORS
2537 }
2538 }
2539 }
2540 }, {
2541 .alg = "deflate",
2542 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002543 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002544 .suite = {
2545 .comp = {
2546 .comp = {
2547 .vecs = deflate_comp_tv_template,
2548 .count = DEFLATE_COMP_TEST_VECTORS
2549 },
2550 .decomp = {
2551 .vecs = deflate_decomp_tv_template,
2552 .count = DEFLATE_DECOMP_TEST_VECTORS
2553 }
2554 }
2555 }
2556 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002557 .alg = "digest_null",
2558 .test = alg_test_null,
2559 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002560 .alg = "drbg_nopr_ctr_aes128",
2561 .test = alg_test_drbg,
2562 .fips_allowed = 1,
2563 .suite = {
2564 .drbg = {
2565 .vecs = drbg_nopr_ctr_aes128_tv_template,
2566 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2567 }
2568 }
2569 }, {
2570 .alg = "drbg_nopr_ctr_aes192",
2571 .test = alg_test_drbg,
2572 .fips_allowed = 1,
2573 .suite = {
2574 .drbg = {
2575 .vecs = drbg_nopr_ctr_aes192_tv_template,
2576 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2577 }
2578 }
2579 }, {
2580 .alg = "drbg_nopr_ctr_aes256",
2581 .test = alg_test_drbg,
2582 .fips_allowed = 1,
2583 .suite = {
2584 .drbg = {
2585 .vecs = drbg_nopr_ctr_aes256_tv_template,
2586 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2587 }
2588 }
2589 }, {
2590 /*
2591 * There is no need to specifically test the DRBG with every
2592 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2593 */
2594 .alg = "drbg_nopr_hmac_sha1",
2595 .fips_allowed = 1,
2596 .test = alg_test_null,
2597 }, {
2598 .alg = "drbg_nopr_hmac_sha256",
2599 .test = alg_test_drbg,
2600 .fips_allowed = 1,
2601 .suite = {
2602 .drbg = {
2603 .vecs = drbg_nopr_hmac_sha256_tv_template,
2604 .count =
2605 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2606 }
2607 }
2608 }, {
2609 /* covered by drbg_nopr_hmac_sha256 test */
2610 .alg = "drbg_nopr_hmac_sha384",
2611 .fips_allowed = 1,
2612 .test = alg_test_null,
2613 }, {
2614 .alg = "drbg_nopr_hmac_sha512",
2615 .test = alg_test_null,
2616 .fips_allowed = 1,
2617 }, {
2618 .alg = "drbg_nopr_sha1",
2619 .fips_allowed = 1,
2620 .test = alg_test_null,
2621 }, {
2622 .alg = "drbg_nopr_sha256",
2623 .test = alg_test_drbg,
2624 .fips_allowed = 1,
2625 .suite = {
2626 .drbg = {
2627 .vecs = drbg_nopr_sha256_tv_template,
2628 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2629 }
2630 }
2631 }, {
2632 /* covered by drbg_nopr_sha256 test */
2633 .alg = "drbg_nopr_sha384",
2634 .fips_allowed = 1,
2635 .test = alg_test_null,
2636 }, {
2637 .alg = "drbg_nopr_sha512",
2638 .fips_allowed = 1,
2639 .test = alg_test_null,
2640 }, {
2641 .alg = "drbg_pr_ctr_aes128",
2642 .test = alg_test_drbg,
2643 .fips_allowed = 1,
2644 .suite = {
2645 .drbg = {
2646 .vecs = drbg_pr_ctr_aes128_tv_template,
2647 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2648 }
2649 }
2650 }, {
2651 /* covered by drbg_pr_ctr_aes128 test */
2652 .alg = "drbg_pr_ctr_aes192",
2653 .fips_allowed = 1,
2654 .test = alg_test_null,
2655 }, {
2656 .alg = "drbg_pr_ctr_aes256",
2657 .fips_allowed = 1,
2658 .test = alg_test_null,
2659 }, {
2660 .alg = "drbg_pr_hmac_sha1",
2661 .fips_allowed = 1,
2662 .test = alg_test_null,
2663 }, {
2664 .alg = "drbg_pr_hmac_sha256",
2665 .test = alg_test_drbg,
2666 .fips_allowed = 1,
2667 .suite = {
2668 .drbg = {
2669 .vecs = drbg_pr_hmac_sha256_tv_template,
2670 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2671 }
2672 }
2673 }, {
2674 /* covered by drbg_pr_hmac_sha256 test */
2675 .alg = "drbg_pr_hmac_sha384",
2676 .fips_allowed = 1,
2677 .test = alg_test_null,
2678 }, {
2679 .alg = "drbg_pr_hmac_sha512",
2680 .test = alg_test_null,
2681 .fips_allowed = 1,
2682 }, {
2683 .alg = "drbg_pr_sha1",
2684 .fips_allowed = 1,
2685 .test = alg_test_null,
2686 }, {
2687 .alg = "drbg_pr_sha256",
2688 .test = alg_test_drbg,
2689 .fips_allowed = 1,
2690 .suite = {
2691 .drbg = {
2692 .vecs = drbg_pr_sha256_tv_template,
2693 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2694 }
2695 }
2696 }, {
2697 /* covered by drbg_pr_sha256 test */
2698 .alg = "drbg_pr_sha384",
2699 .fips_allowed = 1,
2700 .test = alg_test_null,
2701 }, {
2702 .alg = "drbg_pr_sha512",
2703 .fips_allowed = 1,
2704 .test = alg_test_null,
2705 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002706 .alg = "ecb(__aes-aesni)",
2707 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002708 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002709 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002710 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002711 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002712 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002713 .suite = {
2714 .cipher = {
2715 .enc = {
2716 .vecs = aes_enc_tv_template,
2717 .count = AES_ENC_TEST_VECTORS
2718 },
2719 .dec = {
2720 .vecs = aes_dec_tv_template,
2721 .count = AES_DEC_TEST_VECTORS
2722 }
2723 }
2724 }
2725 }, {
2726 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002727 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002728 .suite = {
2729 .cipher = {
2730 .enc = {
2731 .vecs = anubis_enc_tv_template,
2732 .count = ANUBIS_ENC_TEST_VECTORS
2733 },
2734 .dec = {
2735 .vecs = anubis_dec_tv_template,
2736 .count = ANUBIS_DEC_TEST_VECTORS
2737 }
2738 }
2739 }
2740 }, {
2741 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002742 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002743 .suite = {
2744 .cipher = {
2745 .enc = {
2746 .vecs = arc4_enc_tv_template,
2747 .count = ARC4_ENC_TEST_VECTORS
2748 },
2749 .dec = {
2750 .vecs = arc4_dec_tv_template,
2751 .count = ARC4_DEC_TEST_VECTORS
2752 }
2753 }
2754 }
2755 }, {
2756 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002757 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002758 .suite = {
2759 .cipher = {
2760 .enc = {
2761 .vecs = bf_enc_tv_template,
2762 .count = BF_ENC_TEST_VECTORS
2763 },
2764 .dec = {
2765 .vecs = bf_dec_tv_template,
2766 .count = BF_DEC_TEST_VECTORS
2767 }
2768 }
2769 }
2770 }, {
2771 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002772 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002773 .suite = {
2774 .cipher = {
2775 .enc = {
2776 .vecs = camellia_enc_tv_template,
2777 .count = CAMELLIA_ENC_TEST_VECTORS
2778 },
2779 .dec = {
2780 .vecs = camellia_dec_tv_template,
2781 .count = CAMELLIA_DEC_TEST_VECTORS
2782 }
2783 }
2784 }
2785 }, {
2786 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002787 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002788 .suite = {
2789 .cipher = {
2790 .enc = {
2791 .vecs = cast5_enc_tv_template,
2792 .count = CAST5_ENC_TEST_VECTORS
2793 },
2794 .dec = {
2795 .vecs = cast5_dec_tv_template,
2796 .count = CAST5_DEC_TEST_VECTORS
2797 }
2798 }
2799 }
2800 }, {
2801 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002802 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002803 .suite = {
2804 .cipher = {
2805 .enc = {
2806 .vecs = cast6_enc_tv_template,
2807 .count = CAST6_ENC_TEST_VECTORS
2808 },
2809 .dec = {
2810 .vecs = cast6_dec_tv_template,
2811 .count = CAST6_DEC_TEST_VECTORS
2812 }
2813 }
2814 }
2815 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002816 .alg = "ecb(cipher_null)",
2817 .test = alg_test_null,
2818 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002819 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002820 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002821 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002822 .suite = {
2823 .cipher = {
2824 .enc = {
2825 .vecs = des_enc_tv_template,
2826 .count = DES_ENC_TEST_VECTORS
2827 },
2828 .dec = {
2829 .vecs = des_dec_tv_template,
2830 .count = DES_DEC_TEST_VECTORS
2831 }
2832 }
2833 }
2834 }, {
2835 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002836 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002837 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002838 .suite = {
2839 .cipher = {
2840 .enc = {
2841 .vecs = des3_ede_enc_tv_template,
2842 .count = DES3_EDE_ENC_TEST_VECTORS
2843 },
2844 .dec = {
2845 .vecs = des3_ede_dec_tv_template,
2846 .count = DES3_EDE_DEC_TEST_VECTORS
2847 }
2848 }
2849 }
2850 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002851 .alg = "ecb(fcrypt)",
2852 .test = alg_test_skcipher,
2853 .suite = {
2854 .cipher = {
2855 .enc = {
2856 .vecs = fcrypt_pcbc_enc_tv_template,
2857 .count = 1
2858 },
2859 .dec = {
2860 .vecs = fcrypt_pcbc_dec_tv_template,
2861 .count = 1
2862 }
2863 }
2864 }
2865 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002866 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002867 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002868 .suite = {
2869 .cipher = {
2870 .enc = {
2871 .vecs = khazad_enc_tv_template,
2872 .count = KHAZAD_ENC_TEST_VECTORS
2873 },
2874 .dec = {
2875 .vecs = khazad_dec_tv_template,
2876 .count = KHAZAD_DEC_TEST_VECTORS
2877 }
2878 }
2879 }
2880 }, {
2881 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002882 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002883 .suite = {
2884 .cipher = {
2885 .enc = {
2886 .vecs = seed_enc_tv_template,
2887 .count = SEED_ENC_TEST_VECTORS
2888 },
2889 .dec = {
2890 .vecs = seed_dec_tv_template,
2891 .count = SEED_DEC_TEST_VECTORS
2892 }
2893 }
2894 }
2895 }, {
2896 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002897 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002898 .suite = {
2899 .cipher = {
2900 .enc = {
2901 .vecs = serpent_enc_tv_template,
2902 .count = SERPENT_ENC_TEST_VECTORS
2903 },
2904 .dec = {
2905 .vecs = serpent_dec_tv_template,
2906 .count = SERPENT_DEC_TEST_VECTORS
2907 }
2908 }
2909 }
2910 }, {
2911 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002912 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002913 .suite = {
2914 .cipher = {
2915 .enc = {
2916 .vecs = tea_enc_tv_template,
2917 .count = TEA_ENC_TEST_VECTORS
2918 },
2919 .dec = {
2920 .vecs = tea_dec_tv_template,
2921 .count = TEA_DEC_TEST_VECTORS
2922 }
2923 }
2924 }
2925 }, {
2926 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002927 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002928 .suite = {
2929 .cipher = {
2930 .enc = {
2931 .vecs = tnepres_enc_tv_template,
2932 .count = TNEPRES_ENC_TEST_VECTORS
2933 },
2934 .dec = {
2935 .vecs = tnepres_dec_tv_template,
2936 .count = TNEPRES_DEC_TEST_VECTORS
2937 }
2938 }
2939 }
2940 }, {
2941 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002942 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002943 .suite = {
2944 .cipher = {
2945 .enc = {
2946 .vecs = tf_enc_tv_template,
2947 .count = TF_ENC_TEST_VECTORS
2948 },
2949 .dec = {
2950 .vecs = tf_dec_tv_template,
2951 .count = TF_DEC_TEST_VECTORS
2952 }
2953 }
2954 }
2955 }, {
2956 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002957 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002958 .suite = {
2959 .cipher = {
2960 .enc = {
2961 .vecs = xeta_enc_tv_template,
2962 .count = XETA_ENC_TEST_VECTORS
2963 },
2964 .dec = {
2965 .vecs = xeta_dec_tv_template,
2966 .count = XETA_DEC_TEST_VECTORS
2967 }
2968 }
2969 }
2970 }, {
2971 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002972 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002973 .suite = {
2974 .cipher = {
2975 .enc = {
2976 .vecs = xtea_enc_tv_template,
2977 .count = XTEA_ENC_TEST_VECTORS
2978 },
2979 .dec = {
2980 .vecs = xtea_dec_tv_template,
2981 .count = XTEA_DEC_TEST_VECTORS
2982 }
2983 }
2984 }
2985 }, {
2986 .alg = "gcm(aes)",
2987 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002988 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002989 .suite = {
2990 .aead = {
2991 .enc = {
2992 .vecs = aes_gcm_enc_tv_template,
2993 .count = AES_GCM_ENC_TEST_VECTORS
2994 },
2995 .dec = {
2996 .vecs = aes_gcm_dec_tv_template,
2997 .count = AES_GCM_DEC_TEST_VECTORS
2998 }
2999 }
3000 }
3001 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003002 .alg = "ghash",
3003 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003004 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003005 .suite = {
3006 .hash = {
3007 .vecs = ghash_tv_template,
3008 .count = GHASH_TEST_VECTORS
3009 }
3010 }
3011 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003012 .alg = "hmac(crc32)",
3013 .test = alg_test_hash,
3014 .suite = {
3015 .hash = {
3016 .vecs = bfin_crc_tv_template,
3017 .count = BFIN_CRC_TEST_VECTORS
3018 }
3019 }
3020 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003021 .alg = "hmac(md5)",
3022 .test = alg_test_hash,
3023 .suite = {
3024 .hash = {
3025 .vecs = hmac_md5_tv_template,
3026 .count = HMAC_MD5_TEST_VECTORS
3027 }
3028 }
3029 }, {
3030 .alg = "hmac(rmd128)",
3031 .test = alg_test_hash,
3032 .suite = {
3033 .hash = {
3034 .vecs = hmac_rmd128_tv_template,
3035 .count = HMAC_RMD128_TEST_VECTORS
3036 }
3037 }
3038 }, {
3039 .alg = "hmac(rmd160)",
3040 .test = alg_test_hash,
3041 .suite = {
3042 .hash = {
3043 .vecs = hmac_rmd160_tv_template,
3044 .count = HMAC_RMD160_TEST_VECTORS
3045 }
3046 }
3047 }, {
3048 .alg = "hmac(sha1)",
3049 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003050 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003051 .suite = {
3052 .hash = {
3053 .vecs = hmac_sha1_tv_template,
3054 .count = HMAC_SHA1_TEST_VECTORS
3055 }
3056 }
3057 }, {
3058 .alg = "hmac(sha224)",
3059 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003060 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003061 .suite = {
3062 .hash = {
3063 .vecs = hmac_sha224_tv_template,
3064 .count = HMAC_SHA224_TEST_VECTORS
3065 }
3066 }
3067 }, {
3068 .alg = "hmac(sha256)",
3069 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003070 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003071 .suite = {
3072 .hash = {
3073 .vecs = hmac_sha256_tv_template,
3074 .count = HMAC_SHA256_TEST_VECTORS
3075 }
3076 }
3077 }, {
3078 .alg = "hmac(sha384)",
3079 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003080 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003081 .suite = {
3082 .hash = {
3083 .vecs = hmac_sha384_tv_template,
3084 .count = HMAC_SHA384_TEST_VECTORS
3085 }
3086 }
3087 }, {
3088 .alg = "hmac(sha512)",
3089 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003090 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003091 .suite = {
3092 .hash = {
3093 .vecs = hmac_sha512_tv_template,
3094 .count = HMAC_SHA512_TEST_VECTORS
3095 }
3096 }
3097 }, {
3098 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003099 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003100 .suite = {
3101 .cipher = {
3102 .enc = {
3103 .vecs = aes_lrw_enc_tv_template,
3104 .count = AES_LRW_ENC_TEST_VECTORS
3105 },
3106 .dec = {
3107 .vecs = aes_lrw_dec_tv_template,
3108 .count = AES_LRW_DEC_TEST_VECTORS
3109 }
3110 }
3111 }
3112 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003113 .alg = "lrw(camellia)",
3114 .test = alg_test_skcipher,
3115 .suite = {
3116 .cipher = {
3117 .enc = {
3118 .vecs = camellia_lrw_enc_tv_template,
3119 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3120 },
3121 .dec = {
3122 .vecs = camellia_lrw_dec_tv_template,
3123 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3124 }
3125 }
3126 }
3127 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003128 .alg = "lrw(cast6)",
3129 .test = alg_test_skcipher,
3130 .suite = {
3131 .cipher = {
3132 .enc = {
3133 .vecs = cast6_lrw_enc_tv_template,
3134 .count = CAST6_LRW_ENC_TEST_VECTORS
3135 },
3136 .dec = {
3137 .vecs = cast6_lrw_dec_tv_template,
3138 .count = CAST6_LRW_DEC_TEST_VECTORS
3139 }
3140 }
3141 }
3142 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003143 .alg = "lrw(serpent)",
3144 .test = alg_test_skcipher,
3145 .suite = {
3146 .cipher = {
3147 .enc = {
3148 .vecs = serpent_lrw_enc_tv_template,
3149 .count = SERPENT_LRW_ENC_TEST_VECTORS
3150 },
3151 .dec = {
3152 .vecs = serpent_lrw_dec_tv_template,
3153 .count = SERPENT_LRW_DEC_TEST_VECTORS
3154 }
3155 }
3156 }
3157 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003158 .alg = "lrw(twofish)",
3159 .test = alg_test_skcipher,
3160 .suite = {
3161 .cipher = {
3162 .enc = {
3163 .vecs = tf_lrw_enc_tv_template,
3164 .count = TF_LRW_ENC_TEST_VECTORS
3165 },
3166 .dec = {
3167 .vecs = tf_lrw_dec_tv_template,
3168 .count = TF_LRW_DEC_TEST_VECTORS
3169 }
3170 }
3171 }
3172 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003173 .alg = "lz4",
3174 .test = alg_test_comp,
3175 .fips_allowed = 1,
3176 .suite = {
3177 .comp = {
3178 .comp = {
3179 .vecs = lz4_comp_tv_template,
3180 .count = LZ4_COMP_TEST_VECTORS
3181 },
3182 .decomp = {
3183 .vecs = lz4_decomp_tv_template,
3184 .count = LZ4_DECOMP_TEST_VECTORS
3185 }
3186 }
3187 }
3188 }, {
3189 .alg = "lz4hc",
3190 .test = alg_test_comp,
3191 .fips_allowed = 1,
3192 .suite = {
3193 .comp = {
3194 .comp = {
3195 .vecs = lz4hc_comp_tv_template,
3196 .count = LZ4HC_COMP_TEST_VECTORS
3197 },
3198 .decomp = {
3199 .vecs = lz4hc_decomp_tv_template,
3200 .count = LZ4HC_DECOMP_TEST_VECTORS
3201 }
3202 }
3203 }
3204 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003205 .alg = "lzo",
3206 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003207 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003208 .suite = {
3209 .comp = {
3210 .comp = {
3211 .vecs = lzo_comp_tv_template,
3212 .count = LZO_COMP_TEST_VECTORS
3213 },
3214 .decomp = {
3215 .vecs = lzo_decomp_tv_template,
3216 .count = LZO_DECOMP_TEST_VECTORS
3217 }
3218 }
3219 }
3220 }, {
3221 .alg = "md4",
3222 .test = alg_test_hash,
3223 .suite = {
3224 .hash = {
3225 .vecs = md4_tv_template,
3226 .count = MD4_TEST_VECTORS
3227 }
3228 }
3229 }, {
3230 .alg = "md5",
3231 .test = alg_test_hash,
3232 .suite = {
3233 .hash = {
3234 .vecs = md5_tv_template,
3235 .count = MD5_TEST_VECTORS
3236 }
3237 }
3238 }, {
3239 .alg = "michael_mic",
3240 .test = alg_test_hash,
3241 .suite = {
3242 .hash = {
3243 .vecs = michael_mic_tv_template,
3244 .count = MICHAEL_MIC_TEST_VECTORS
3245 }
3246 }
3247 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003248 .alg = "ofb(aes)",
3249 .test = alg_test_skcipher,
3250 .fips_allowed = 1,
3251 .suite = {
3252 .cipher = {
3253 .enc = {
3254 .vecs = aes_ofb_enc_tv_template,
3255 .count = AES_OFB_ENC_TEST_VECTORS
3256 },
3257 .dec = {
3258 .vecs = aes_ofb_dec_tv_template,
3259 .count = AES_OFB_DEC_TEST_VECTORS
3260 }
3261 }
3262 }
3263 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003264 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003265 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003266 .suite = {
3267 .cipher = {
3268 .enc = {
3269 .vecs = fcrypt_pcbc_enc_tv_template,
3270 .count = FCRYPT_ENC_TEST_VECTORS
3271 },
3272 .dec = {
3273 .vecs = fcrypt_pcbc_dec_tv_template,
3274 .count = FCRYPT_DEC_TEST_VECTORS
3275 }
3276 }
3277 }
3278 }, {
3279 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003280 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003281 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003282 .suite = {
3283 .cipher = {
3284 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003285 .vecs = aes_ctr_rfc3686_enc_tv_template,
3286 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003287 },
3288 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003289 .vecs = aes_ctr_rfc3686_dec_tv_template,
3290 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003291 }
3292 }
3293 }
3294 }, {
Adrian Hoban69435b92010-11-04 15:02:04 -04003295 .alg = "rfc4106(gcm(aes))",
3296 .test = alg_test_aead,
Jarod Wilsondb71f292015-01-23 12:42:15 -05003297 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003298 .suite = {
3299 .aead = {
3300 .enc = {
3301 .vecs = aes_gcm_rfc4106_enc_tv_template,
3302 .count = AES_GCM_4106_ENC_TEST_VECTORS
3303 },
3304 .dec = {
3305 .vecs = aes_gcm_rfc4106_dec_tv_template,
3306 .count = AES_GCM_4106_DEC_TEST_VECTORS
3307 }
3308 }
3309 }
3310 }, {
Jarod Wilson5d667322009-05-04 19:23:40 +08003311 .alg = "rfc4309(ccm(aes))",
3312 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003313 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003314 .suite = {
3315 .aead = {
3316 .enc = {
3317 .vecs = aes_ccm_rfc4309_enc_tv_template,
3318 .count = AES_CCM_4309_ENC_TEST_VECTORS
3319 },
3320 .dec = {
3321 .vecs = aes_ccm_rfc4309_dec_tv_template,
3322 .count = AES_CCM_4309_DEC_TEST_VECTORS
3323 }
3324 }
3325 }
3326 }, {
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003327 .alg = "rfc4543(gcm(aes))",
3328 .test = alg_test_aead,
3329 .suite = {
3330 .aead = {
3331 .enc = {
3332 .vecs = aes_gcm_rfc4543_enc_tv_template,
3333 .count = AES_GCM_4543_ENC_TEST_VECTORS
3334 },
3335 .dec = {
3336 .vecs = aes_gcm_rfc4543_dec_tv_template,
3337 .count = AES_GCM_4543_DEC_TEST_VECTORS
3338 },
3339 }
3340 }
3341 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003342 .alg = "rmd128",
3343 .test = alg_test_hash,
3344 .suite = {
3345 .hash = {
3346 .vecs = rmd128_tv_template,
3347 .count = RMD128_TEST_VECTORS
3348 }
3349 }
3350 }, {
3351 .alg = "rmd160",
3352 .test = alg_test_hash,
3353 .suite = {
3354 .hash = {
3355 .vecs = rmd160_tv_template,
3356 .count = RMD160_TEST_VECTORS
3357 }
3358 }
3359 }, {
3360 .alg = "rmd256",
3361 .test = alg_test_hash,
3362 .suite = {
3363 .hash = {
3364 .vecs = rmd256_tv_template,
3365 .count = RMD256_TEST_VECTORS
3366 }
3367 }
3368 }, {
3369 .alg = "rmd320",
3370 .test = alg_test_hash,
3371 .suite = {
3372 .hash = {
3373 .vecs = rmd320_tv_template,
3374 .count = RMD320_TEST_VECTORS
3375 }
3376 }
3377 }, {
3378 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003379 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003380 .suite = {
3381 .cipher = {
3382 .enc = {
3383 .vecs = salsa20_stream_enc_tv_template,
3384 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3385 }
3386 }
3387 }
3388 }, {
3389 .alg = "sha1",
3390 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003391 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003392 .suite = {
3393 .hash = {
3394 .vecs = sha1_tv_template,
3395 .count = SHA1_TEST_VECTORS
3396 }
3397 }
3398 }, {
3399 .alg = "sha224",
3400 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003401 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003402 .suite = {
3403 .hash = {
3404 .vecs = sha224_tv_template,
3405 .count = SHA224_TEST_VECTORS
3406 }
3407 }
3408 }, {
3409 .alg = "sha256",
3410 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003411 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003412 .suite = {
3413 .hash = {
3414 .vecs = sha256_tv_template,
3415 .count = SHA256_TEST_VECTORS
3416 }
3417 }
3418 }, {
3419 .alg = "sha384",
3420 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003421 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003422 .suite = {
3423 .hash = {
3424 .vecs = sha384_tv_template,
3425 .count = SHA384_TEST_VECTORS
3426 }
3427 }
3428 }, {
3429 .alg = "sha512",
3430 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003431 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003432 .suite = {
3433 .hash = {
3434 .vecs = sha512_tv_template,
3435 .count = SHA512_TEST_VECTORS
3436 }
3437 }
3438 }, {
3439 .alg = "tgr128",
3440 .test = alg_test_hash,
3441 .suite = {
3442 .hash = {
3443 .vecs = tgr128_tv_template,
3444 .count = TGR128_TEST_VECTORS
3445 }
3446 }
3447 }, {
3448 .alg = "tgr160",
3449 .test = alg_test_hash,
3450 .suite = {
3451 .hash = {
3452 .vecs = tgr160_tv_template,
3453 .count = TGR160_TEST_VECTORS
3454 }
3455 }
3456 }, {
3457 .alg = "tgr192",
3458 .test = alg_test_hash,
3459 .suite = {
3460 .hash = {
3461 .vecs = tgr192_tv_template,
3462 .count = TGR192_TEST_VECTORS
3463 }
3464 }
3465 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003466 .alg = "vmac(aes)",
3467 .test = alg_test_hash,
3468 .suite = {
3469 .hash = {
3470 .vecs = aes_vmac128_tv_template,
3471 .count = VMAC_AES_TEST_VECTORS
3472 }
3473 }
3474 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003475 .alg = "wp256",
3476 .test = alg_test_hash,
3477 .suite = {
3478 .hash = {
3479 .vecs = wp256_tv_template,
3480 .count = WP256_TEST_VECTORS
3481 }
3482 }
3483 }, {
3484 .alg = "wp384",
3485 .test = alg_test_hash,
3486 .suite = {
3487 .hash = {
3488 .vecs = wp384_tv_template,
3489 .count = WP384_TEST_VECTORS
3490 }
3491 }
3492 }, {
3493 .alg = "wp512",
3494 .test = alg_test_hash,
3495 .suite = {
3496 .hash = {
3497 .vecs = wp512_tv_template,
3498 .count = WP512_TEST_VECTORS
3499 }
3500 }
3501 }, {
3502 .alg = "xcbc(aes)",
3503 .test = alg_test_hash,
3504 .suite = {
3505 .hash = {
3506 .vecs = aes_xcbc128_tv_template,
3507 .count = XCBC_AES_TEST_VECTORS
3508 }
3509 }
3510 }, {
3511 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003512 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003513 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003514 .suite = {
3515 .cipher = {
3516 .enc = {
3517 .vecs = aes_xts_enc_tv_template,
3518 .count = AES_XTS_ENC_TEST_VECTORS
3519 },
3520 .dec = {
3521 .vecs = aes_xts_dec_tv_template,
3522 .count = AES_XTS_DEC_TEST_VECTORS
3523 }
3524 }
3525 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003526 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003527 .alg = "xts(camellia)",
3528 .test = alg_test_skcipher,
3529 .suite = {
3530 .cipher = {
3531 .enc = {
3532 .vecs = camellia_xts_enc_tv_template,
3533 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3534 },
3535 .dec = {
3536 .vecs = camellia_xts_dec_tv_template,
3537 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3538 }
3539 }
3540 }
3541 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003542 .alg = "xts(cast6)",
3543 .test = alg_test_skcipher,
3544 .suite = {
3545 .cipher = {
3546 .enc = {
3547 .vecs = cast6_xts_enc_tv_template,
3548 .count = CAST6_XTS_ENC_TEST_VECTORS
3549 },
3550 .dec = {
3551 .vecs = cast6_xts_dec_tv_template,
3552 .count = CAST6_XTS_DEC_TEST_VECTORS
3553 }
3554 }
3555 }
3556 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003557 .alg = "xts(serpent)",
3558 .test = alg_test_skcipher,
3559 .suite = {
3560 .cipher = {
3561 .enc = {
3562 .vecs = serpent_xts_enc_tv_template,
3563 .count = SERPENT_XTS_ENC_TEST_VECTORS
3564 },
3565 .dec = {
3566 .vecs = serpent_xts_dec_tv_template,
3567 .count = SERPENT_XTS_DEC_TEST_VECTORS
3568 }
3569 }
3570 }
3571 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003572 .alg = "xts(twofish)",
3573 .test = alg_test_skcipher,
3574 .suite = {
3575 .cipher = {
3576 .enc = {
3577 .vecs = tf_xts_enc_tv_template,
3578 .count = TF_XTS_ENC_TEST_VECTORS
3579 },
3580 .dec = {
3581 .vecs = tf_xts_dec_tv_template,
3582 .count = TF_XTS_DEC_TEST_VECTORS
3583 }
3584 }
3585 }
3586 }, {
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003587 .alg = "zlib",
3588 .test = alg_test_pcomp,
Milan Broz08189042012-12-06 17:16:28 +08003589 .fips_allowed = 1,
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003590 .suite = {
3591 .pcomp = {
3592 .comp = {
3593 .vecs = zlib_comp_tv_template,
3594 .count = ZLIB_COMP_TEST_VECTORS
3595 },
3596 .decomp = {
3597 .vecs = zlib_decomp_tv_template,
3598 .count = ZLIB_DECOMP_TEST_VECTORS
3599 }
3600 }
3601 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003602 }
3603};
3604
Jussi Kivilinna57147582013-06-13 17:37:40 +03003605static bool alg_test_descs_checked;
3606
3607static void alg_test_descs_check_order(void)
3608{
3609 int i;
3610
3611 /* only check once */
3612 if (alg_test_descs_checked)
3613 return;
3614
3615 alg_test_descs_checked = true;
3616
3617 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3618 int diff = strcmp(alg_test_descs[i - 1].alg,
3619 alg_test_descs[i].alg);
3620
3621 if (WARN_ON(diff > 0)) {
3622 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3623 alg_test_descs[i - 1].alg,
3624 alg_test_descs[i].alg);
3625 }
3626
3627 if (WARN_ON(diff == 0)) {
3628 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3629 alg_test_descs[i].alg);
3630 }
3631 }
3632}
3633
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003634static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003635{
3636 int start = 0;
3637 int end = ARRAY_SIZE(alg_test_descs);
3638
3639 while (start < end) {
3640 int i = (start + end) / 2;
3641 int diff = strcmp(alg_test_descs[i].alg, alg);
3642
3643 if (diff > 0) {
3644 end = i;
3645 continue;
3646 }
3647
3648 if (diff < 0) {
3649 start = i + 1;
3650 continue;
3651 }
3652
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003653 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003654 }
3655
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003656 return -1;
3657}
3658
3659int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3660{
3661 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003662 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003663 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003664
Jussi Kivilinna57147582013-06-13 17:37:40 +03003665 alg_test_descs_check_order();
3666
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003667 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3668 char nalg[CRYPTO_MAX_ALG_NAME];
3669
3670 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3671 sizeof(nalg))
3672 return -ENAMETOOLONG;
3673
3674 i = alg_find_test(nalg);
3675 if (i < 0)
3676 goto notest;
3677
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003678 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3679 goto non_fips_alg;
3680
Jarod Wilson941fb322009-05-04 19:49:23 +08003681 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3682 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003683 }
3684
3685 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003686 j = alg_find_test(driver);
3687 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003688 goto notest;
3689
Herbert Xua68f6612009-07-02 16:32:12 +08003690 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3691 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003692 goto non_fips_alg;
3693
Herbert Xua68f6612009-07-02 16:32:12 +08003694 rc = 0;
3695 if (i >= 0)
3696 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3697 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003698 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003699 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3700 type, mask);
3701
Jarod Wilson941fb322009-05-04 19:49:23 +08003702test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003703 if (fips_enabled && rc)
3704 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3705
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003706 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09003707 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003708
Neil Hormand12d6b62008-10-12 20:36:51 +08003709 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003710
3711notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003712 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3713 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003714non_fips_alg:
3715 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003716}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003717
Herbert Xu326a6342010-08-06 09:40:28 +08003718#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003719
Herbert Xuda7f0332008-07-31 17:08:25 +08003720EXPORT_SYMBOL_GPL(alg_test);