blob: a865ea99a057d5c769b0a6c76ba51d6989be6049 [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
Herbert Xu1ce33112015-04-22 15:06:31 +080023#include <crypto/aead.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080024#include <crypto/hash.h>
25#include <linux/err.h>
Herbert Xu1c41b882015-04-22 13:25:58 +080026#include <linux/fips.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080027#include <linux/module.h>
28#include <linux/scatterlist.h>
29#include <linux/slab.h>
30#include <linux/string.h>
Jarod Wilson7647d6c2009-05-04 19:44:50 +080031#include <crypto/rng.h>
Stephan Mueller64d1cdf2014-05-31 17:25:36 +020032#include <crypto/drbg.h>
Tadeusz Struk946cc462015-06-16 10:31:06 -070033#include <crypto/akcipher.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080034
35#include "internal.h"
Alexander Shishkin0b767f92010-06-03 20:53:43 +100036
Herbert Xu326a6342010-08-06 09:40:28 +080037#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
Alexander Shishkin0b767f92010-06-03 20:53:43 +100038
39/* a perfect nop */
40int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
41{
42 return 0;
43}
44
45#else
46
Herbert Xuda7f0332008-07-31 17:08:25 +080047#include "testmgr.h"
48
49/*
50 * Need slab memory for testing (size in number of pages).
51 */
52#define XBUFSIZE 8
53
54/*
55 * Indexes into the xbuf to simulate cross-page access.
56 */
57#define IDX1 32
58#define IDX2 32400
59#define IDX3 1
60#define IDX4 8193
61#define IDX5 22222
62#define IDX6 17101
63#define IDX7 27333
64#define IDX8 3000
65
66/*
67* Used by test_cipher()
68*/
69#define ENCRYPT 1
70#define DECRYPT 0
71
72struct tcrypt_result {
73 struct completion completion;
74 int err;
75};
76
77struct aead_test_suite {
78 struct {
79 struct aead_testvec *vecs;
80 unsigned int count;
81 } enc, dec;
82};
83
84struct cipher_test_suite {
85 struct {
86 struct cipher_testvec *vecs;
87 unsigned int count;
88 } enc, dec;
89};
90
91struct comp_test_suite {
92 struct {
93 struct comp_testvec *vecs;
94 unsigned int count;
95 } comp, decomp;
96};
97
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +080098struct pcomp_test_suite {
99 struct {
100 struct pcomp_testvec *vecs;
101 unsigned int count;
102 } comp, decomp;
103};
104
Herbert Xuda7f0332008-07-31 17:08:25 +0800105struct hash_test_suite {
106 struct hash_testvec *vecs;
107 unsigned int count;
108};
109
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800110struct cprng_test_suite {
111 struct cprng_testvec *vecs;
112 unsigned int count;
113};
114
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200115struct drbg_test_suite {
116 struct drbg_testvec *vecs;
117 unsigned int count;
118};
119
Tadeusz Struk946cc462015-06-16 10:31:06 -0700120struct akcipher_test_suite {
121 struct akcipher_testvec *vecs;
122 unsigned int count;
123};
124
Herbert Xuda7f0332008-07-31 17:08:25 +0800125struct alg_test_desc {
126 const char *alg;
127 int (*test)(const struct alg_test_desc *desc, const char *driver,
128 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000129 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800130
131 union {
132 struct aead_test_suite aead;
133 struct cipher_test_suite cipher;
134 struct comp_test_suite comp;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +0800135 struct pcomp_test_suite pcomp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800136 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800137 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200138 struct drbg_test_suite drbg;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700139 struct akcipher_test_suite akcipher;
Herbert Xuda7f0332008-07-31 17:08:25 +0800140 } suite;
141};
142
143static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
144
Herbert Xuda7f0332008-07-31 17:08:25 +0800145static void hexdump(unsigned char *buf, unsigned int len)
146{
147 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
148 16, 1,
149 buf, len, false);
150}
151
152static void tcrypt_complete(struct crypto_async_request *req, int err)
153{
154 struct tcrypt_result *res = req->data;
155
156 if (err == -EINPROGRESS)
157 return;
158
159 res->err = err;
160 complete(&res->completion);
161}
162
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800163static int testmgr_alloc_buf(char *buf[XBUFSIZE])
164{
165 int i;
166
167 for (i = 0; i < XBUFSIZE; i++) {
168 buf[i] = (void *)__get_free_page(GFP_KERNEL);
169 if (!buf[i])
170 goto err_free_buf;
171 }
172
173 return 0;
174
175err_free_buf:
176 while (i-- > 0)
177 free_page((unsigned long)buf[i]);
178
179 return -ENOMEM;
180}
181
182static void testmgr_free_buf(char *buf[XBUFSIZE])
183{
184 int i;
185
186 for (i = 0; i < XBUFSIZE; i++)
187 free_page((unsigned long)buf[i]);
188}
189
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300190static int wait_async_op(struct tcrypt_result *tr, int ret)
David S. Millera8f1a052010-05-19 14:12:03 +1000191{
192 if (ret == -EINPROGRESS || ret == -EBUSY) {
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100193 wait_for_completion(&tr->completion);
Wolfram Sang16735d02013-11-14 14:32:02 -0800194 reinit_completion(&tr->completion);
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100195 ret = tr->err;
David S. Millera8f1a052010-05-19 14:12:03 +1000196 }
197 return ret;
198}
199
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300200static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
201 unsigned int tcount, bool use_digest,
202 const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800203{
204 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
205 unsigned int i, j, k, temp;
206 struct scatterlist sg[8];
Horia Geanta29b77e52014-07-23 11:59:38 +0300207 char *result;
208 char *key;
Herbert Xuda7f0332008-07-31 17:08:25 +0800209 struct ahash_request *req;
210 struct tcrypt_result tresult;
Herbert Xuda7f0332008-07-31 17:08:25 +0800211 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800212 char *xbuf[XBUFSIZE];
213 int ret = -ENOMEM;
214
Horia Geanta29b77e52014-07-23 11:59:38 +0300215 result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
216 if (!result)
217 return ret;
218 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
219 if (!key)
220 goto out_nobuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800221 if (testmgr_alloc_buf(xbuf))
222 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800223
224 init_completion(&tresult.completion);
225
226 req = ahash_request_alloc(tfm, GFP_KERNEL);
227 if (!req) {
228 printk(KERN_ERR "alg: hash: Failed to allocate request for "
229 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800230 goto out_noreq;
231 }
232 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
233 tcrypt_complete, &tresult);
234
Herbert Xua0cfae52009-05-29 16:23:12 +1000235 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800236 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000237 if (template[i].np)
238 continue;
239
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300240 ret = -EINVAL;
241 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
242 goto out;
243
Herbert Xua0cfae52009-05-29 16:23:12 +1000244 j++;
Horia Geanta29b77e52014-07-23 11:59:38 +0300245 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800246
247 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300248 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800249
250 memcpy(hash_buff, template[i].plaintext, template[i].psize);
251 sg_init_one(&sg[0], hash_buff, template[i].psize);
252
253 if (template[i].ksize) {
254 crypto_ahash_clear_flags(tfm, ~0);
Horia Geanta29b77e52014-07-23 11:59:38 +0300255 if (template[i].ksize > MAX_KEYLEN) {
256 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
257 j, algo, template[i].ksize, MAX_KEYLEN);
258 ret = -EINVAL;
259 goto out;
260 }
261 memcpy(key, template[i].key, template[i].ksize);
262 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
Herbert Xuda7f0332008-07-31 17:08:25 +0800263 if (ret) {
264 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000265 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800266 -ret);
267 goto out;
268 }
269 }
270
271 ahash_request_set_crypt(req, sg, result, template[i].psize);
David S. Millera8f1a052010-05-19 14:12:03 +1000272 if (use_digest) {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300273 ret = wait_async_op(&tresult, crypto_ahash_digest(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000274 if (ret) {
275 pr_err("alg: hash: digest failed on test %d "
276 "for %s: ret=%d\n", j, algo, -ret);
277 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800278 }
David S. Millera8f1a052010-05-19 14:12:03 +1000279 } else {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300280 ret = wait_async_op(&tresult, crypto_ahash_init(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000281 if (ret) {
282 pr_err("alt: hash: init failed on test %d "
283 "for %s: ret=%d\n", j, algo, -ret);
284 goto out;
285 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300286 ret = wait_async_op(&tresult, crypto_ahash_update(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000287 if (ret) {
288 pr_err("alt: hash: update failed on test %d "
289 "for %s: ret=%d\n", j, algo, -ret);
290 goto out;
291 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300292 ret = wait_async_op(&tresult, crypto_ahash_final(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000293 if (ret) {
294 pr_err("alt: hash: final failed on test %d "
295 "for %s: ret=%d\n", j, algo, -ret);
296 goto out;
297 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800298 }
299
300 if (memcmp(result, template[i].digest,
301 crypto_ahash_digestsize(tfm))) {
302 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000303 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800304 hexdump(result, crypto_ahash_digestsize(tfm));
305 ret = -EINVAL;
306 goto out;
307 }
308 }
309
310 j = 0;
311 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300312 /* alignment tests are only done with continuous buffers */
313 if (align_offset != 0)
314 break;
315
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300316 if (!template[i].np)
317 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800318
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300319 j++;
320 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800321
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300322 temp = 0;
323 sg_init_table(sg, template[i].np);
324 ret = -EINVAL;
325 for (k = 0; k < template[i].np; k++) {
326 if (WARN_ON(offset_in_page(IDX[k]) +
327 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +0800328 goto out;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300329 sg_set_buf(&sg[k],
330 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
331 offset_in_page(IDX[k]),
332 template[i].plaintext + temp,
333 template[i].tap[k]),
334 template[i].tap[k]);
335 temp += template[i].tap[k];
336 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800337
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300338 if (template[i].ksize) {
339 if (template[i].ksize > MAX_KEYLEN) {
340 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
341 j, algo, template[i].ksize, MAX_KEYLEN);
Herbert Xuda7f0332008-07-31 17:08:25 +0800342 ret = -EINVAL;
343 goto out;
344 }
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300345 crypto_ahash_clear_flags(tfm, ~0);
346 memcpy(key, template[i].key, template[i].ksize);
347 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
348
349 if (ret) {
350 printk(KERN_ERR "alg: hash: setkey "
351 "failed on chunking test %d "
352 "for %s: ret=%d\n", j, algo, -ret);
353 goto out;
354 }
355 }
356
357 ahash_request_set_crypt(req, sg, result, template[i].psize);
358 ret = crypto_ahash_digest(req);
359 switch (ret) {
360 case 0:
361 break;
362 case -EINPROGRESS:
363 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100364 wait_for_completion(&tresult.completion);
365 reinit_completion(&tresult.completion);
366 ret = tresult.err;
367 if (!ret)
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300368 break;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300369 /* fall through */
370 default:
371 printk(KERN_ERR "alg: hash: digest failed "
372 "on chunking test %d for %s: "
373 "ret=%d\n", j, algo, -ret);
374 goto out;
375 }
376
377 if (memcmp(result, template[i].digest,
378 crypto_ahash_digestsize(tfm))) {
379 printk(KERN_ERR "alg: hash: Chunking test %d "
380 "failed for %s\n", j, algo);
381 hexdump(result, crypto_ahash_digestsize(tfm));
382 ret = -EINVAL;
383 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800384 }
385 }
386
387 ret = 0;
388
389out:
390 ahash_request_free(req);
391out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800392 testmgr_free_buf(xbuf);
393out_nobuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300394 kfree(key);
395 kfree(result);
Herbert Xuda7f0332008-07-31 17:08:25 +0800396 return ret;
397}
398
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300399static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
400 unsigned int tcount, bool use_digest)
401{
402 unsigned int alignmask;
403 int ret;
404
405 ret = __test_hash(tfm, template, tcount, use_digest, 0);
406 if (ret)
407 return ret;
408
409 /* test unaligned buffers, check with one byte offset */
410 ret = __test_hash(tfm, template, tcount, use_digest, 1);
411 if (ret)
412 return ret;
413
414 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
415 if (alignmask) {
416 /* Check if alignment mask for tfm is correctly set. */
417 ret = __test_hash(tfm, template, tcount, use_digest,
418 alignmask + 1);
419 if (ret)
420 return ret;
421 }
422
423 return 0;
424}
425
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300426static int __test_aead(struct crypto_aead *tfm, int enc,
427 struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300428 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800429{
430 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
431 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800432 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800433 char *q;
434 char *key;
435 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300436 struct scatterlist *sg;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300437 struct scatterlist *sgout;
438 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800439 struct tcrypt_result result;
Cristian Stoica424a5da2015-01-28 11:03:05 +0200440 unsigned int authsize, iv_len;
Herbert Xuda7f0332008-07-31 17:08:25 +0800441 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300442 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800443 void *assoc;
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700444 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800445 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300446 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800447 char *axbuf[XBUFSIZE];
448
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700449 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
450 if (!iv)
451 return ret;
Horia Geanta29b77e52014-07-23 11:59:38 +0300452 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
453 if (!key)
454 goto out_noxbuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800455 if (testmgr_alloc_buf(xbuf))
456 goto out_noxbuf;
457 if (testmgr_alloc_buf(axbuf))
458 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300459 if (diff_dst && testmgr_alloc_buf(xoutbuf))
460 goto out_nooutbuf;
461
462 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800463 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 4 : 2), GFP_KERNEL);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300464 if (!sg)
465 goto out_nosg;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800466 sgout = &sg[16];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300467
468 if (diff_dst)
469 d = "-ddst";
470 else
471 d = "";
472
Herbert Xuda7f0332008-07-31 17:08:25 +0800473 if (enc == ENCRYPT)
474 e = "encryption";
475 else
476 e = "decryption";
477
478 init_completion(&result.completion);
479
480 req = aead_request_alloc(tfm, GFP_KERNEL);
481 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300482 pr_err("alg: aead%s: Failed to allocate request for %s\n",
483 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800484 goto out;
485 }
486
487 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
488 tcrypt_complete, &result);
489
490 for (i = 0, j = 0; i < tcount; i++) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300491 if (template[i].np)
492 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800493
Cristian Stoica05b1d332014-07-28 13:11:23 +0300494 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800495
Cristian Stoica05b1d332014-07-28 13:11:23 +0300496 /* some templates have no input data but they will
497 * touch input
498 */
499 input = xbuf[0];
500 input += align_offset;
501 assoc = axbuf[0];
502
503 ret = -EINVAL;
504 if (WARN_ON(align_offset + template[i].ilen >
505 PAGE_SIZE || template[i].alen > PAGE_SIZE))
506 goto out;
507
508 memcpy(input, template[i].input, template[i].ilen);
509 memcpy(assoc, template[i].assoc, template[i].alen);
Cristian Stoica424a5da2015-01-28 11:03:05 +0200510 iv_len = crypto_aead_ivsize(tfm);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300511 if (template[i].iv)
Cristian Stoica424a5da2015-01-28 11:03:05 +0200512 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300513 else
Cristian Stoica424a5da2015-01-28 11:03:05 +0200514 memset(iv, 0, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300515
516 crypto_aead_clear_flags(tfm, ~0);
517 if (template[i].wk)
518 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
519
520 if (template[i].klen > MAX_KEYLEN) {
521 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
522 d, j, algo, template[i].klen,
523 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +1000524 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300525 goto out;
526 }
527 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +1000528
Cristian Stoica05b1d332014-07-28 13:11:23 +0300529 ret = crypto_aead_setkey(tfm, key, template[i].klen);
530 if (!ret == template[i].fail) {
531 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
532 d, j, algo, crypto_aead_get_flags(tfm));
533 goto out;
534 } else if (ret)
535 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800536
Cristian Stoica05b1d332014-07-28 13:11:23 +0300537 authsize = abs(template[i].rlen - template[i].ilen);
538 ret = crypto_aead_setauthsize(tfm, authsize);
539 if (ret) {
540 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
541 d, authsize, j, algo);
542 goto out;
543 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800544
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800545 k = !!template[i].alen;
546 sg_init_table(sg, k + 1);
547 sg_set_buf(&sg[0], assoc, template[i].alen);
548 sg_set_buf(&sg[k], input,
549 template[i].ilen + (enc ? authsize : 0));
550 output = input;
551
Cristian Stoica05b1d332014-07-28 13:11:23 +0300552 if (diff_dst) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800553 sg_init_table(sgout, k + 1);
554 sg_set_buf(&sgout[0], assoc, template[i].alen);
555
Cristian Stoica05b1d332014-07-28 13:11:23 +0300556 output = xoutbuf[0];
557 output += align_offset;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800558 sg_set_buf(&sgout[k], output,
559 template[i].rlen + (enc ? 0 : authsize));
Cristian Stoica05b1d332014-07-28 13:11:23 +0300560 }
561
Cristian Stoica05b1d332014-07-28 13:11:23 +0300562 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
563 template[i].ilen, iv);
564
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800565 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300566
567 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
568
569 switch (ret) {
570 case 0:
571 if (template[i].novrfy) {
572 /* verification was supposed to fail */
573 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
574 d, e, j, algo);
575 /* so really, we got a bad message */
576 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +0300577 goto out;
578 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300579 break;
580 case -EINPROGRESS:
581 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100582 wait_for_completion(&result.completion);
583 reinit_completion(&result.completion);
584 ret = result.err;
585 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +0800586 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300587 case -EBADMSG:
588 if (template[i].novrfy)
589 /* verification failure was expected */
590 continue;
591 /* fall through */
592 default:
593 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
594 d, e, j, algo, -ret);
595 goto out;
596 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800597
Cristian Stoica05b1d332014-07-28 13:11:23 +0300598 q = output;
599 if (memcmp(q, template[i].result, template[i].rlen)) {
600 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
601 d, j, e, algo);
602 hexdump(q, template[i].rlen);
603 ret = -EINVAL;
604 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800605 }
606 }
607
608 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300609 /* alignment tests are only done with continuous buffers */
610 if (align_offset != 0)
611 break;
612
Cristian Stoica05b1d332014-07-28 13:11:23 +0300613 if (!template[i].np)
614 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800615
Cristian Stoica05b1d332014-07-28 13:11:23 +0300616 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800617
Cristian Stoica05b1d332014-07-28 13:11:23 +0300618 if (template[i].iv)
619 memcpy(iv, template[i].iv, MAX_IVLEN);
620 else
621 memset(iv, 0, MAX_IVLEN);
622
623 crypto_aead_clear_flags(tfm, ~0);
624 if (template[i].wk)
625 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
626 if (template[i].klen > MAX_KEYLEN) {
627 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
628 d, j, algo, template[i].klen, MAX_KEYLEN);
629 ret = -EINVAL;
630 goto out;
631 }
632 memcpy(key, template[i].key, template[i].klen);
633
634 ret = crypto_aead_setkey(tfm, key, template[i].klen);
635 if (!ret == template[i].fail) {
636 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
637 d, j, algo, crypto_aead_get_flags(tfm));
638 goto out;
639 } else if (ret)
640 continue;
641
642 authsize = abs(template[i].rlen - template[i].ilen);
643
644 ret = -EINVAL;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800645 sg_init_table(sg, template[i].anp + template[i].np);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300646 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800647 sg_init_table(sgout, template[i].anp + template[i].np);
648
649 ret = -EINVAL;
650 for (k = 0, temp = 0; k < template[i].anp; k++) {
651 if (WARN_ON(offset_in_page(IDX[k]) +
652 template[i].atap[k] > PAGE_SIZE))
653 goto out;
654 sg_set_buf(&sg[k],
655 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
656 offset_in_page(IDX[k]),
657 template[i].assoc + temp,
658 template[i].atap[k]),
659 template[i].atap[k]);
660 if (diff_dst)
661 sg_set_buf(&sgout[k],
662 axbuf[IDX[k] >> PAGE_SHIFT] +
663 offset_in_page(IDX[k]),
664 template[i].atap[k]);
665 temp += template[i].atap[k];
666 }
667
Cristian Stoica05b1d332014-07-28 13:11:23 +0300668 for (k = 0, temp = 0; k < template[i].np; k++) {
669 if (WARN_ON(offset_in_page(IDX[k]) +
670 template[i].tap[k] > PAGE_SIZE))
671 goto out;
672
673 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
674 memcpy(q, template[i].input + temp, template[i].tap[k]);
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800675 sg_set_buf(&sg[template[i].anp + k],
676 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300677
678 if (diff_dst) {
679 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
680 offset_in_page(IDX[k]);
681
682 memset(q, 0, template[i].tap[k]);
683
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800684 sg_set_buf(&sgout[template[i].anp + k],
685 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300686 }
687
688 n = template[i].tap[k];
689 if (k == template[i].np - 1 && enc)
690 n += authsize;
691 if (offset_in_page(q) + n < PAGE_SIZE)
692 q[n] = 0;
693
694 temp += template[i].tap[k];
695 }
696
697 ret = crypto_aead_setauthsize(tfm, authsize);
698 if (ret) {
699 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
700 d, authsize, j, algo);
701 goto out;
702 }
703
704 if (enc) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800705 if (WARN_ON(sg[template[i].anp + k - 1].offset +
706 sg[template[i].anp + k - 1].length +
707 authsize > PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300708 ret = -EINVAL;
709 goto out;
710 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800711
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300712 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800713 sgout[template[i].anp + k - 1].length +=
714 authsize;
715 sg[template[i].anp + k - 1].length += authsize;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300716 }
717
718 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
719 template[i].ilen,
720 iv);
721
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800722 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300723
724 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
725
726 switch (ret) {
727 case 0:
728 if (template[i].novrfy) {
729 /* verification was supposed to fail */
730 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
731 d, e, j, algo);
732 /* so really, we got a bad message */
733 ret = -EBADMSG;
734 goto out;
735 }
736 break;
737 case -EINPROGRESS:
738 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100739 wait_for_completion(&result.completion);
740 reinit_completion(&result.completion);
741 ret = result.err;
742 if (!ret)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300743 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300744 case -EBADMSG:
745 if (template[i].novrfy)
746 /* verification failure was expected */
747 continue;
748 /* fall through */
749 default:
750 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
751 d, e, j, algo, -ret);
752 goto out;
753 }
754
755 ret = -EINVAL;
756 for (k = 0, temp = 0; k < template[i].np; k++) {
757 if (diff_dst)
758 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
759 offset_in_page(IDX[k]);
760 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800761 q = xbuf[IDX[k] >> PAGE_SHIFT] +
762 offset_in_page(IDX[k]);
763
Cristian Stoica05b1d332014-07-28 13:11:23 +0300764 n = template[i].tap[k];
765 if (k == template[i].np - 1)
766 n += enc ? authsize : -authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800767
Cristian Stoica05b1d332014-07-28 13:11:23 +0300768 if (memcmp(q, template[i].result + temp, n)) {
769 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
770 d, j, e, k, algo);
771 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800772 goto out;
773 }
774
Cristian Stoica05b1d332014-07-28 13:11:23 +0300775 q += n;
776 if (k == template[i].np - 1 && !enc) {
777 if (!diff_dst &&
778 memcmp(q, template[i].input +
779 temp + n, authsize))
780 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200781 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300782 n = 0;
783 } else {
784 for (n = 0; offset_in_page(q + n) && q[n]; n++)
785 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800786 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300787 if (n) {
788 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
789 d, j, e, k, algo, n);
790 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800791 goto out;
792 }
793
Cristian Stoica05b1d332014-07-28 13:11:23 +0300794 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800795 }
796 }
797
798 ret = 0;
799
800out:
801 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300802 kfree(sg);
803out_nosg:
804 if (diff_dst)
805 testmgr_free_buf(xoutbuf);
806out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800807 testmgr_free_buf(axbuf);
808out_noaxbuf:
809 testmgr_free_buf(xbuf);
810out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300811 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700812 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800813 return ret;
814}
815
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300816static int test_aead(struct crypto_aead *tfm, int enc,
817 struct aead_testvec *template, unsigned int tcount)
818{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300819 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300820 int ret;
821
822 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300823 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300824 if (ret)
825 return ret;
826
827 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300828 ret = __test_aead(tfm, enc, template, tcount, true, 0);
829 if (ret)
830 return ret;
831
832 /* test unaligned buffers, check with one byte offset */
833 ret = __test_aead(tfm, enc, template, tcount, true, 1);
834 if (ret)
835 return ret;
836
837 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
838 if (alignmask) {
839 /* Check if alignment mask for tfm is correctly set. */
840 ret = __test_aead(tfm, enc, template, tcount, true,
841 alignmask + 1);
842 if (ret)
843 return ret;
844 }
845
846 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300847}
848
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000849static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800850 struct cipher_testvec *template, unsigned int tcount)
851{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000852 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
853 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000854 char *q;
855 const char *e;
856 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800857 char *xbuf[XBUFSIZE];
858 int ret = -ENOMEM;
859
860 if (testmgr_alloc_buf(xbuf))
861 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000862
863 if (enc == ENCRYPT)
864 e = "encryption";
865 else
866 e = "decryption";
867
868 j = 0;
869 for (i = 0; i < tcount; i++) {
870 if (template[i].np)
871 continue;
872
873 j++;
874
Herbert Xufd57f222009-05-29 16:05:42 +1000875 ret = -EINVAL;
876 if (WARN_ON(template[i].ilen > PAGE_SIZE))
877 goto out;
878
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000879 data = xbuf[0];
880 memcpy(data, template[i].input, template[i].ilen);
881
882 crypto_cipher_clear_flags(tfm, ~0);
883 if (template[i].wk)
884 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
885
886 ret = crypto_cipher_setkey(tfm, template[i].key,
887 template[i].klen);
888 if (!ret == template[i].fail) {
889 printk(KERN_ERR "alg: cipher: setkey failed "
890 "on test %d for %s: flags=%x\n", j,
891 algo, crypto_cipher_get_flags(tfm));
892 goto out;
893 } else if (ret)
894 continue;
895
896 for (k = 0; k < template[i].ilen;
897 k += crypto_cipher_blocksize(tfm)) {
898 if (enc)
899 crypto_cipher_encrypt_one(tfm, data + k,
900 data + k);
901 else
902 crypto_cipher_decrypt_one(tfm, data + k,
903 data + k);
904 }
905
906 q = data;
907 if (memcmp(q, template[i].result, template[i].rlen)) {
908 printk(KERN_ERR "alg: cipher: Test %d failed "
909 "on %s for %s\n", j, e, algo);
910 hexdump(q, template[i].rlen);
911 ret = -EINVAL;
912 goto out;
913 }
914 }
915
916 ret = 0;
917
918out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800919 testmgr_free_buf(xbuf);
920out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000921 return ret;
922}
923
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300924static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
925 struct cipher_testvec *template, unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300926 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000927{
Herbert Xuda7f0332008-07-31 17:08:25 +0800928 const char *algo =
929 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
930 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800931 char *q;
932 struct ablkcipher_request *req;
933 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300934 struct scatterlist sgout[8];
935 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800936 struct tcrypt_result result;
937 void *data;
938 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800939 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300940 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800941 int ret = -ENOMEM;
942
943 if (testmgr_alloc_buf(xbuf))
944 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800945
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300946 if (diff_dst && testmgr_alloc_buf(xoutbuf))
947 goto out_nooutbuf;
948
949 if (diff_dst)
950 d = "-ddst";
951 else
952 d = "";
953
Herbert Xuda7f0332008-07-31 17:08:25 +0800954 if (enc == ENCRYPT)
955 e = "encryption";
956 else
957 e = "decryption";
958
959 init_completion(&result.completion);
960
961 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
962 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300963 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
964 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800965 goto out;
966 }
967
968 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
969 tcrypt_complete, &result);
970
971 j = 0;
972 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +0300973 if (template[i].np && !template[i].also_non_np)
974 continue;
975
Herbert Xuda7f0332008-07-31 17:08:25 +0800976 if (template[i].iv)
977 memcpy(iv, template[i].iv, MAX_IVLEN);
978 else
979 memset(iv, 0, MAX_IVLEN);
980
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300981 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300982 ret = -EINVAL;
983 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
984 goto out;
985
986 data = xbuf[0];
987 data += align_offset;
988 memcpy(data, template[i].input, template[i].ilen);
989
990 crypto_ablkcipher_clear_flags(tfm, ~0);
991 if (template[i].wk)
992 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
993
994 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
995 template[i].klen);
996 if (!ret == template[i].fail) {
997 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
998 d, j, algo, crypto_ablkcipher_get_flags(tfm));
999 goto out;
1000 } else if (ret)
1001 continue;
1002
1003 sg_init_one(&sg[0], data, template[i].ilen);
1004 if (diff_dst) {
1005 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001006 data += align_offset;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001007 sg_init_one(&sgout[0], data, template[i].ilen);
1008 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001009
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001010 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1011 template[i].ilen, iv);
1012 ret = enc ? crypto_ablkcipher_encrypt(req) :
1013 crypto_ablkcipher_decrypt(req);
Herbert Xuda7f0332008-07-31 17:08:25 +08001014
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001015 switch (ret) {
1016 case 0:
1017 break;
1018 case -EINPROGRESS:
1019 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001020 wait_for_completion(&result.completion);
1021 reinit_completion(&result.completion);
1022 ret = result.err;
1023 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +08001024 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001025 /* fall through */
1026 default:
1027 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1028 d, e, j, algo, -ret);
1029 goto out;
1030 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001031
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001032 q = data;
1033 if (memcmp(q, template[i].result, template[i].rlen)) {
1034 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1035 d, j, e, algo);
1036 hexdump(q, template[i].rlen);
1037 ret = -EINVAL;
1038 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001039 }
1040 }
1041
1042 j = 0;
1043 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001044 /* alignment tests are only done with continuous buffers */
1045 if (align_offset != 0)
1046 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001047
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001048 if (!template[i].np)
1049 continue;
1050
Herbert Xuda7f0332008-07-31 17:08:25 +08001051 if (template[i].iv)
1052 memcpy(iv, template[i].iv, MAX_IVLEN);
1053 else
1054 memset(iv, 0, MAX_IVLEN);
1055
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001056 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001057 crypto_ablkcipher_clear_flags(tfm, ~0);
1058 if (template[i].wk)
1059 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1060
1061 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1062 template[i].klen);
1063 if (!ret == template[i].fail) {
1064 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1065 d, j, algo, crypto_ablkcipher_get_flags(tfm));
1066 goto out;
1067 } else if (ret)
1068 continue;
1069
1070 temp = 0;
1071 ret = -EINVAL;
1072 sg_init_table(sg, template[i].np);
1073 if (diff_dst)
1074 sg_init_table(sgout, template[i].np);
1075 for (k = 0; k < template[i].np; k++) {
1076 if (WARN_ON(offset_in_page(IDX[k]) +
1077 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001078 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001079
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001080 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1081
1082 memcpy(q, template[i].input + temp, template[i].tap[k]);
1083
1084 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1085 q[template[i].tap[k]] = 0;
1086
1087 sg_set_buf(&sg[k], q, template[i].tap[k]);
1088 if (diff_dst) {
1089 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1090 offset_in_page(IDX[k]);
1091
1092 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1093
1094 memset(q, 0, template[i].tap[k]);
1095 if (offset_in_page(q) +
1096 template[i].tap[k] < PAGE_SIZE)
1097 q[template[i].tap[k]] = 0;
1098 }
1099
1100 temp += template[i].tap[k];
1101 }
1102
1103 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1104 template[i].ilen, iv);
1105
1106 ret = enc ? crypto_ablkcipher_encrypt(req) :
1107 crypto_ablkcipher_decrypt(req);
1108
1109 switch (ret) {
1110 case 0:
1111 break;
1112 case -EINPROGRESS:
1113 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001114 wait_for_completion(&result.completion);
1115 reinit_completion(&result.completion);
1116 ret = result.err;
1117 if (!ret)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001118 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001119 /* fall through */
1120 default:
1121 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1122 d, e, j, algo, -ret);
1123 goto out;
1124 }
1125
1126 temp = 0;
1127 ret = -EINVAL;
1128 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001129 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001130 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1131 offset_in_page(IDX[k]);
1132 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001133 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1134 offset_in_page(IDX[k]);
1135
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001136 if (memcmp(q, template[i].result + temp,
1137 template[i].tap[k])) {
1138 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1139 d, j, e, k, algo);
1140 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001141 goto out;
1142 }
1143
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001144 q += template[i].tap[k];
1145 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1146 ;
1147 if (n) {
1148 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1149 d, j, e, k, algo, n);
1150 hexdump(q, n);
1151 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001152 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001153 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001154 }
1155 }
1156
1157 ret = 0;
1158
1159out:
1160 ablkcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001161 if (diff_dst)
1162 testmgr_free_buf(xoutbuf);
1163out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001164 testmgr_free_buf(xbuf);
1165out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001166 return ret;
1167}
1168
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001169static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1170 struct cipher_testvec *template, unsigned int tcount)
1171{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001172 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001173 int ret;
1174
1175 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001176 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001177 if (ret)
1178 return ret;
1179
1180 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001181 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1182 if (ret)
1183 return ret;
1184
1185 /* test unaligned buffers, check with one byte offset */
1186 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1187 if (ret)
1188 return ret;
1189
1190 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1191 if (alignmask) {
1192 /* Check if alignment mask for tfm is correctly set. */
1193 ret = __test_skcipher(tfm, enc, template, tcount, true,
1194 alignmask + 1);
1195 if (ret)
1196 return ret;
1197 }
1198
1199 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001200}
1201
Herbert Xuda7f0332008-07-31 17:08:25 +08001202static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1203 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1204{
1205 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1206 unsigned int i;
1207 char result[COMP_BUF_SIZE];
1208 int ret;
1209
1210 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001211 int ilen;
1212 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001213
1214 memset(result, 0, sizeof (result));
1215
1216 ilen = ctemplate[i].inlen;
1217 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1218 ilen, result, &dlen);
1219 if (ret) {
1220 printk(KERN_ERR "alg: comp: compression failed "
1221 "on test %d for %s: ret=%d\n", i + 1, algo,
1222 -ret);
1223 goto out;
1224 }
1225
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001226 if (dlen != ctemplate[i].outlen) {
1227 printk(KERN_ERR "alg: comp: Compression test %d "
1228 "failed for %s: output len = %d\n", i + 1, algo,
1229 dlen);
1230 ret = -EINVAL;
1231 goto out;
1232 }
1233
Herbert Xuda7f0332008-07-31 17:08:25 +08001234 if (memcmp(result, ctemplate[i].output, dlen)) {
1235 printk(KERN_ERR "alg: comp: Compression test %d "
1236 "failed for %s\n", i + 1, algo);
1237 hexdump(result, dlen);
1238 ret = -EINVAL;
1239 goto out;
1240 }
1241 }
1242
1243 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001244 int ilen;
1245 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001246
1247 memset(result, 0, sizeof (result));
1248
1249 ilen = dtemplate[i].inlen;
1250 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1251 ilen, result, &dlen);
1252 if (ret) {
1253 printk(KERN_ERR "alg: comp: decompression failed "
1254 "on test %d for %s: ret=%d\n", i + 1, algo,
1255 -ret);
1256 goto out;
1257 }
1258
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001259 if (dlen != dtemplate[i].outlen) {
1260 printk(KERN_ERR "alg: comp: Decompression test %d "
1261 "failed for %s: output len = %d\n", i + 1, algo,
1262 dlen);
1263 ret = -EINVAL;
1264 goto out;
1265 }
1266
Herbert Xuda7f0332008-07-31 17:08:25 +08001267 if (memcmp(result, dtemplate[i].output, dlen)) {
1268 printk(KERN_ERR "alg: comp: Decompression test %d "
1269 "failed for %s\n", i + 1, algo);
1270 hexdump(result, dlen);
1271 ret = -EINVAL;
1272 goto out;
1273 }
1274 }
1275
1276 ret = 0;
1277
1278out:
1279 return ret;
1280}
1281
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001282static int test_pcomp(struct crypto_pcomp *tfm,
1283 struct pcomp_testvec *ctemplate,
1284 struct pcomp_testvec *dtemplate, int ctcount,
1285 int dtcount)
1286{
1287 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1288 unsigned int i;
1289 char result[COMP_BUF_SIZE];
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001290 int res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001291
1292 for (i = 0; i < ctcount; i++) {
1293 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001294 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001295
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001296 res = crypto_compress_setup(tfm, ctemplate[i].params,
1297 ctemplate[i].paramsize);
1298 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001299 pr_err("alg: pcomp: compression setup failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001300 "%d for %s: error=%d\n", i + 1, algo, res);
1301 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001302 }
1303
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001304 res = crypto_compress_init(tfm);
1305 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001306 pr_err("alg: pcomp: compression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001307 "%d for %s: error=%d\n", i + 1, algo, res);
1308 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001309 }
1310
1311 memset(result, 0, sizeof(result));
1312
1313 req.next_in = ctemplate[i].input;
1314 req.avail_in = ctemplate[i].inlen / 2;
1315 req.next_out = result;
1316 req.avail_out = ctemplate[i].outlen / 2;
1317
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001318 res = crypto_compress_update(tfm, &req);
1319 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001320 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001321 "%d for %s: error=%d\n", i + 1, algo, res);
1322 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001323 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001324 if (res > 0)
1325 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001326
1327 /* Add remaining input data */
1328 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1329
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001330 res = crypto_compress_update(tfm, &req);
1331 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001332 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001333 "%d for %s: error=%d\n", i + 1, algo, res);
1334 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001335 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001336 if (res > 0)
1337 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001338
1339 /* Provide remaining output space */
1340 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1341
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001342 res = crypto_compress_final(tfm, &req);
1343 if (res < 0) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001344 pr_err("alg: pcomp: compression final failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001345 "%d for %s: error=%d\n", i + 1, algo, res);
1346 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001347 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001348 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001349
1350 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1351 pr_err("alg: comp: Compression test %d failed for %s: "
1352 "output len = %d (expected %d)\n", i + 1, algo,
1353 COMP_BUF_SIZE - req.avail_out,
1354 ctemplate[i].outlen);
1355 return -EINVAL;
1356 }
1357
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001358 if (produced != ctemplate[i].outlen) {
1359 pr_err("alg: comp: Compression test %d failed for %s: "
1360 "returned len = %u (expected %d)\n", i + 1,
1361 algo, produced, ctemplate[i].outlen);
1362 return -EINVAL;
1363 }
1364
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001365 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1366 pr_err("alg: pcomp: Compression test %d failed for "
1367 "%s\n", i + 1, algo);
1368 hexdump(result, ctemplate[i].outlen);
1369 return -EINVAL;
1370 }
1371 }
1372
1373 for (i = 0; i < dtcount; i++) {
1374 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001375 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001376
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001377 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1378 dtemplate[i].paramsize);
1379 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001380 pr_err("alg: pcomp: decompression setup failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001381 "test %d for %s: error=%d\n", i + 1, algo, res);
1382 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001383 }
1384
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001385 res = crypto_decompress_init(tfm);
1386 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001387 pr_err("alg: pcomp: decompression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001388 "%d for %s: error=%d\n", i + 1, algo, res);
1389 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001390 }
1391
1392 memset(result, 0, sizeof(result));
1393
1394 req.next_in = dtemplate[i].input;
1395 req.avail_in = dtemplate[i].inlen / 2;
1396 req.next_out = result;
1397 req.avail_out = dtemplate[i].outlen / 2;
1398
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001399 res = crypto_decompress_update(tfm, &req);
1400 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001401 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001402 "test %d for %s: error=%d\n", i + 1, algo, res);
1403 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001404 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001405 if (res > 0)
1406 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001407
1408 /* Add remaining input data */
1409 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1410
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001411 res = crypto_decompress_update(tfm, &req);
1412 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001413 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001414 "test %d for %s: error=%d\n", i + 1, algo, res);
1415 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001416 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001417 if (res > 0)
1418 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001419
1420 /* Provide remaining output space */
1421 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1422
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001423 res = crypto_decompress_final(tfm, &req);
1424 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001425 pr_err("alg: pcomp: decompression final failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001426 "test %d for %s: error=%d\n", i + 1, algo, res);
1427 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001428 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001429 if (res > 0)
1430 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001431
1432 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1433 pr_err("alg: comp: Decompression test %d failed for "
1434 "%s: output len = %d (expected %d)\n", i + 1,
1435 algo, COMP_BUF_SIZE - req.avail_out,
1436 dtemplate[i].outlen);
1437 return -EINVAL;
1438 }
1439
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001440 if (produced != dtemplate[i].outlen) {
1441 pr_err("alg: comp: Decompression test %d failed for "
1442 "%s: returned len = %u (expected %d)\n", i + 1,
1443 algo, produced, dtemplate[i].outlen);
1444 return -EINVAL;
1445 }
1446
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001447 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1448 pr_err("alg: pcomp: Decompression test %d failed for "
1449 "%s\n", i + 1, algo);
1450 hexdump(result, dtemplate[i].outlen);
1451 return -EINVAL;
1452 }
1453 }
1454
1455 return 0;
1456}
1457
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001458
1459static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1460 unsigned int tcount)
1461{
1462 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001463 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001464 u8 *seed;
1465 char result[32];
1466
1467 seedsize = crypto_rng_seedsize(tfm);
1468
1469 seed = kmalloc(seedsize, GFP_KERNEL);
1470 if (!seed) {
1471 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1472 "for %s\n", algo);
1473 return -ENOMEM;
1474 }
1475
1476 for (i = 0; i < tcount; i++) {
1477 memset(result, 0, 32);
1478
1479 memcpy(seed, template[i].v, template[i].vlen);
1480 memcpy(seed + template[i].vlen, template[i].key,
1481 template[i].klen);
1482 memcpy(seed + template[i].vlen + template[i].klen,
1483 template[i].dt, template[i].dtlen);
1484
1485 err = crypto_rng_reset(tfm, seed, seedsize);
1486 if (err) {
1487 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1488 "for %s\n", algo);
1489 goto out;
1490 }
1491
1492 for (j = 0; j < template[i].loops; j++) {
1493 err = crypto_rng_get_bytes(tfm, result,
1494 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01001495 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001496 printk(KERN_ERR "alg: cprng: Failed to obtain "
1497 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01001498 "%s (requested %d)\n", algo,
1499 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001500 goto out;
1501 }
1502 }
1503
1504 err = memcmp(result, template[i].result,
1505 template[i].rlen);
1506 if (err) {
1507 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1508 i, algo);
1509 hexdump(result, template[i].rlen);
1510 err = -EINVAL;
1511 goto out;
1512 }
1513 }
1514
1515out:
1516 kfree(seed);
1517 return err;
1518}
1519
Herbert Xuda7f0332008-07-31 17:08:25 +08001520static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1521 u32 type, u32 mask)
1522{
1523 struct crypto_aead *tfm;
1524 int err = 0;
1525
Stephan Mueller425a8822015-03-30 21:56:31 +02001526 tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001527 if (IS_ERR(tfm)) {
1528 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1529 "%ld\n", driver, PTR_ERR(tfm));
1530 return PTR_ERR(tfm);
1531 }
1532
1533 if (desc->suite.aead.enc.vecs) {
1534 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1535 desc->suite.aead.enc.count);
1536 if (err)
1537 goto out;
1538 }
1539
1540 if (!err && desc->suite.aead.dec.vecs)
1541 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1542 desc->suite.aead.dec.count);
1543
1544out:
1545 crypto_free_aead(tfm);
1546 return err;
1547}
1548
1549static int alg_test_cipher(const struct alg_test_desc *desc,
1550 const char *driver, u32 type, u32 mask)
1551{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001552 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001553 int err = 0;
1554
Stephan Mueller425a8822015-03-30 21:56:31 +02001555 tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001556 if (IS_ERR(tfm)) {
1557 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1558 "%s: %ld\n", driver, PTR_ERR(tfm));
1559 return PTR_ERR(tfm);
1560 }
1561
1562 if (desc->suite.cipher.enc.vecs) {
1563 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1564 desc->suite.cipher.enc.count);
1565 if (err)
1566 goto out;
1567 }
1568
1569 if (desc->suite.cipher.dec.vecs)
1570 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1571 desc->suite.cipher.dec.count);
1572
1573out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001574 crypto_free_cipher(tfm);
1575 return err;
1576}
1577
1578static int alg_test_skcipher(const struct alg_test_desc *desc,
1579 const char *driver, u32 type, u32 mask)
1580{
1581 struct crypto_ablkcipher *tfm;
1582 int err = 0;
1583
Stephan Mueller425a8822015-03-30 21:56:31 +02001584 tfm = crypto_alloc_ablkcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001585 if (IS_ERR(tfm)) {
1586 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1587 "%s: %ld\n", driver, PTR_ERR(tfm));
1588 return PTR_ERR(tfm);
1589 }
1590
1591 if (desc->suite.cipher.enc.vecs) {
1592 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1593 desc->suite.cipher.enc.count);
1594 if (err)
1595 goto out;
1596 }
1597
1598 if (desc->suite.cipher.dec.vecs)
1599 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1600 desc->suite.cipher.dec.count);
1601
1602out:
Herbert Xuda7f0332008-07-31 17:08:25 +08001603 crypto_free_ablkcipher(tfm);
1604 return err;
1605}
1606
1607static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1608 u32 type, u32 mask)
1609{
1610 struct crypto_comp *tfm;
1611 int err;
1612
1613 tfm = crypto_alloc_comp(driver, type, mask);
1614 if (IS_ERR(tfm)) {
1615 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1616 "%ld\n", driver, PTR_ERR(tfm));
1617 return PTR_ERR(tfm);
1618 }
1619
1620 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1621 desc->suite.comp.decomp.vecs,
1622 desc->suite.comp.comp.count,
1623 desc->suite.comp.decomp.count);
1624
1625 crypto_free_comp(tfm);
1626 return err;
1627}
1628
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001629static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1630 u32 type, u32 mask)
1631{
1632 struct crypto_pcomp *tfm;
1633 int err;
1634
1635 tfm = crypto_alloc_pcomp(driver, type, mask);
1636 if (IS_ERR(tfm)) {
1637 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1638 driver, PTR_ERR(tfm));
1639 return PTR_ERR(tfm);
1640 }
1641
1642 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1643 desc->suite.pcomp.decomp.vecs,
1644 desc->suite.pcomp.comp.count,
1645 desc->suite.pcomp.decomp.count);
1646
1647 crypto_free_pcomp(tfm);
1648 return err;
1649}
1650
Herbert Xuda7f0332008-07-31 17:08:25 +08001651static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1652 u32 type, u32 mask)
1653{
1654 struct crypto_ahash *tfm;
1655 int err;
1656
Stephan Mueller425a8822015-03-30 21:56:31 +02001657 tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001658 if (IS_ERR(tfm)) {
1659 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1660 "%ld\n", driver, PTR_ERR(tfm));
1661 return PTR_ERR(tfm);
1662 }
1663
David S. Millera8f1a052010-05-19 14:12:03 +10001664 err = test_hash(tfm, desc->suite.hash.vecs,
1665 desc->suite.hash.count, true);
1666 if (!err)
1667 err = test_hash(tfm, desc->suite.hash.vecs,
1668 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001669
1670 crypto_free_ahash(tfm);
1671 return err;
1672}
1673
Herbert Xu8e3ee852008-11-07 14:58:52 +08001674static int alg_test_crc32c(const struct alg_test_desc *desc,
1675 const char *driver, u32 type, u32 mask)
1676{
1677 struct crypto_shash *tfm;
1678 u32 val;
1679 int err;
1680
1681 err = alg_test_hash(desc, driver, type, mask);
1682 if (err)
1683 goto out;
1684
Stephan Mueller425a8822015-03-30 21:56:31 +02001685 tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001686 if (IS_ERR(tfm)) {
1687 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1688 "%ld\n", driver, PTR_ERR(tfm));
1689 err = PTR_ERR(tfm);
1690 goto out;
1691 }
1692
1693 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001694 SHASH_DESC_ON_STACK(shash, tfm);
1695 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001696
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001697 shash->tfm = tfm;
1698 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001699
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001700 *ctx = le32_to_cpu(420553207);
1701 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001702 if (err) {
1703 printk(KERN_ERR "alg: crc32c: Operation failed for "
1704 "%s: %d\n", driver, err);
1705 break;
1706 }
1707
1708 if (val != ~420553207) {
1709 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1710 "%d\n", driver, val);
1711 err = -EINVAL;
1712 }
1713 } while (0);
1714
1715 crypto_free_shash(tfm);
1716
1717out:
1718 return err;
1719}
1720
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001721static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1722 u32 type, u32 mask)
1723{
1724 struct crypto_rng *rng;
1725 int err;
1726
Stephan Mueller425a8822015-03-30 21:56:31 +02001727 rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001728 if (IS_ERR(rng)) {
1729 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1730 "%ld\n", driver, PTR_ERR(rng));
1731 return PTR_ERR(rng);
1732 }
1733
1734 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1735
1736 crypto_free_rng(rng);
1737
1738 return err;
1739}
1740
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001741
1742static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1743 const char *driver, u32 type, u32 mask)
1744{
1745 int ret = -EAGAIN;
1746 struct crypto_rng *drng;
1747 struct drbg_test_data test_data;
1748 struct drbg_string addtl, pers, testentropy;
1749 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1750
1751 if (!buf)
1752 return -ENOMEM;
1753
Stephan Mueller425a8822015-03-30 21:56:31 +02001754 drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001755 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001756 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001757 "%s\n", driver);
1758 kzfree(buf);
1759 return -ENOMEM;
1760 }
1761
1762 test_data.testentropy = &testentropy;
1763 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1764 drbg_string_fill(&pers, test->pers, test->perslen);
1765 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1766 if (ret) {
1767 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1768 goto outbuf;
1769 }
1770
1771 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1772 if (pr) {
1773 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1774 ret = crypto_drbg_get_bytes_addtl_test(drng,
1775 buf, test->expectedlen, &addtl, &test_data);
1776 } else {
1777 ret = crypto_drbg_get_bytes_addtl(drng,
1778 buf, test->expectedlen, &addtl);
1779 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001780 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001781 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001782 "driver %s\n", driver);
1783 goto outbuf;
1784 }
1785
1786 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1787 if (pr) {
1788 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1789 ret = crypto_drbg_get_bytes_addtl_test(drng,
1790 buf, test->expectedlen, &addtl, &test_data);
1791 } else {
1792 ret = crypto_drbg_get_bytes_addtl(drng,
1793 buf, test->expectedlen, &addtl);
1794 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001795 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001796 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001797 "driver %s\n", driver);
1798 goto outbuf;
1799 }
1800
1801 ret = memcmp(test->expected, buf, test->expectedlen);
1802
1803outbuf:
1804 crypto_free_rng(drng);
1805 kzfree(buf);
1806 return ret;
1807}
1808
1809
1810static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1811 u32 type, u32 mask)
1812{
1813 int err = 0;
1814 int pr = 0;
1815 int i = 0;
1816 struct drbg_testvec *template = desc->suite.drbg.vecs;
1817 unsigned int tcount = desc->suite.drbg.count;
1818
1819 if (0 == memcmp(driver, "drbg_pr_", 8))
1820 pr = 1;
1821
1822 for (i = 0; i < tcount; i++) {
1823 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1824 if (err) {
1825 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1826 i, driver);
1827 err = -EINVAL;
1828 break;
1829 }
1830 }
1831 return err;
1832
1833}
1834
Tadeusz Struk946cc462015-06-16 10:31:06 -07001835static int do_test_rsa(struct crypto_akcipher *tfm,
1836 struct akcipher_testvec *vecs)
1837{
1838 struct akcipher_request *req;
1839 void *outbuf_enc = NULL;
1840 void *outbuf_dec = NULL;
1841 struct tcrypt_result result;
1842 unsigned int out_len_max, out_len = 0;
1843 int err = -ENOMEM;
1844
1845 req = akcipher_request_alloc(tfm, GFP_KERNEL);
1846 if (!req)
1847 return err;
1848
1849 init_completion(&result.completion);
1850 err = crypto_akcipher_setkey(tfm, vecs->key, vecs->key_len);
1851 if (err)
1852 goto free_req;
1853
1854 akcipher_request_set_crypt(req, vecs->m, outbuf_enc, vecs->m_size,
1855 out_len);
1856 /* expect this to fail, and update the required buf len */
1857 crypto_akcipher_encrypt(req);
1858 out_len = req->dst_len;
1859 if (!out_len) {
1860 err = -EINVAL;
1861 goto free_req;
1862 }
1863
1864 out_len_max = out_len;
1865 err = -ENOMEM;
1866 outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
1867 if (!outbuf_enc)
1868 goto free_req;
1869
1870 akcipher_request_set_crypt(req, vecs->m, outbuf_enc, vecs->m_size,
1871 out_len);
1872 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1873 tcrypt_complete, &result);
1874
1875 /* Run RSA encrypt - c = m^e mod n;*/
1876 err = wait_async_op(&result, crypto_akcipher_encrypt(req));
1877 if (err) {
1878 pr_err("alg: rsa: encrypt test failed. err %d\n", err);
1879 goto free_all;
1880 }
1881 if (out_len != vecs->c_size) {
1882 pr_err("alg: rsa: encrypt test failed. Invalid output len\n");
1883 err = -EINVAL;
1884 goto free_all;
1885 }
1886 /* verify that encrypted message is equal to expected */
1887 if (memcmp(vecs->c, outbuf_enc, vecs->c_size)) {
1888 pr_err("alg: rsa: encrypt test failed. Invalid output\n");
1889 err = -EINVAL;
1890 goto free_all;
1891 }
1892 /* Don't invoke decrypt for vectors with public key */
1893 if (vecs->public_key_vec) {
1894 err = 0;
1895 goto free_all;
1896 }
1897 outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
1898 if (!outbuf_dec) {
1899 err = -ENOMEM;
1900 goto free_all;
1901 }
1902 init_completion(&result.completion);
1903 akcipher_request_set_crypt(req, outbuf_enc, outbuf_dec, vecs->c_size,
1904 out_len);
1905
1906 /* Run RSA decrypt - m = c^d mod n;*/
1907 err = wait_async_op(&result, crypto_akcipher_decrypt(req));
1908 if (err) {
1909 pr_err("alg: rsa: decrypt test failed. err %d\n", err);
1910 goto free_all;
1911 }
1912 out_len = req->dst_len;
1913 if (out_len != vecs->m_size) {
1914 pr_err("alg: rsa: decrypt test failed. Invalid output len\n");
1915 err = -EINVAL;
1916 goto free_all;
1917 }
1918 /* verify that decrypted message is equal to the original msg */
1919 if (memcmp(vecs->m, outbuf_dec, vecs->m_size)) {
1920 pr_err("alg: rsa: decrypt test failed. Invalid output\n");
1921 err = -EINVAL;
1922 }
1923free_all:
1924 kfree(outbuf_dec);
1925 kfree(outbuf_enc);
1926free_req:
1927 akcipher_request_free(req);
1928 return err;
1929}
1930
1931static int test_rsa(struct crypto_akcipher *tfm, struct akcipher_testvec *vecs,
1932 unsigned int tcount)
1933{
1934 int ret, i;
1935
1936 for (i = 0; i < tcount; i++) {
1937 ret = do_test_rsa(tfm, vecs++);
1938 if (ret) {
1939 pr_err("alg: rsa: test failed on vector %d, err=%d\n",
1940 i + 1, ret);
1941 return ret;
1942 }
1943 }
1944 return 0;
1945}
1946
1947static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
1948 struct akcipher_testvec *vecs, unsigned int tcount)
1949{
1950 if (strncmp(alg, "rsa", 3) == 0)
1951 return test_rsa(tfm, vecs, tcount);
1952
1953 return 0;
1954}
1955
1956static int alg_test_akcipher(const struct alg_test_desc *desc,
1957 const char *driver, u32 type, u32 mask)
1958{
1959 struct crypto_akcipher *tfm;
1960 int err = 0;
1961
1962 tfm = crypto_alloc_akcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
1963 if (IS_ERR(tfm)) {
1964 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
1965 driver, PTR_ERR(tfm));
1966 return PTR_ERR(tfm);
1967 }
1968 if (desc->suite.akcipher.vecs)
1969 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
1970 desc->suite.akcipher.count);
1971
1972 crypto_free_akcipher(tfm);
1973 return err;
1974}
1975
Youquan, Song863b5572009-12-23 19:45:20 +08001976static int alg_test_null(const struct alg_test_desc *desc,
1977 const char *driver, u32 type, u32 mask)
1978{
1979 return 0;
1980}
1981
Herbert Xuda7f0332008-07-31 17:08:25 +08001982/* Please keep this list sorted by algorithm name. */
1983static const struct alg_test_desc alg_test_descs[] = {
1984 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001985 .alg = "__cbc-cast5-avx",
1986 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001987 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001988 .alg = "__cbc-cast6-avx",
1989 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001990 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001991 .alg = "__cbc-serpent-avx",
1992 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001993 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001994 .alg = "__cbc-serpent-avx2",
1995 .test = alg_test_null,
1996 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001997 .alg = "__cbc-serpent-sse2",
1998 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001999 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002000 .alg = "__cbc-twofish-avx",
2001 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002002 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002003 .alg = "__driver-cbc-aes-aesni",
2004 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002005 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002006 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002007 .alg = "__driver-cbc-camellia-aesni",
2008 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002009 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002010 .alg = "__driver-cbc-camellia-aesni-avx2",
2011 .test = alg_test_null,
2012 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002013 .alg = "__driver-cbc-cast5-avx",
2014 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002015 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002016 .alg = "__driver-cbc-cast6-avx",
2017 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002018 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002019 .alg = "__driver-cbc-serpent-avx",
2020 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002021 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002022 .alg = "__driver-cbc-serpent-avx2",
2023 .test = alg_test_null,
2024 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002025 .alg = "__driver-cbc-serpent-sse2",
2026 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002027 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002028 .alg = "__driver-cbc-twofish-avx",
2029 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002030 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002031 .alg = "__driver-ecb-aes-aesni",
2032 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002033 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002034 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002035 .alg = "__driver-ecb-camellia-aesni",
2036 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002037 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002038 .alg = "__driver-ecb-camellia-aesni-avx2",
2039 .test = alg_test_null,
2040 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002041 .alg = "__driver-ecb-cast5-avx",
2042 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002043 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002044 .alg = "__driver-ecb-cast6-avx",
2045 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002046 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002047 .alg = "__driver-ecb-serpent-avx",
2048 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002049 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002050 .alg = "__driver-ecb-serpent-avx2",
2051 .test = alg_test_null,
2052 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002053 .alg = "__driver-ecb-serpent-sse2",
2054 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002055 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002056 .alg = "__driver-ecb-twofish-avx",
2057 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002058 }, {
Tadeusz Struk9d77b6c2015-06-24 09:01:30 -07002059 .alg = "__driver-gcm-aes-aesni",
2060 .test = alg_test_null,
2061 .fips_allowed = 1,
2062 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002063 .alg = "__ghash-pclmulqdqni",
2064 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002065 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002066 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002067 .alg = "ansi_cprng",
2068 .test = alg_test_cprng,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002069 .fips_allowed = 1,
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002070 .suite = {
2071 .cprng = {
2072 .vecs = ansi_cprng_aes_tv_template,
2073 .count = ANSI_CPRNG_AES_TEST_VECTORS
2074 }
2075 }
2076 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002077 .alg = "authenc(hmac(md5),ecb(cipher_null))",
2078 .test = alg_test_aead,
2079 .fips_allowed = 1,
2080 .suite = {
2081 .aead = {
2082 .enc = {
2083 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
2084 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
2085 },
2086 .dec = {
2087 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
2088 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
2089 }
2090 }
2091 }
2092 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002093 .alg = "authenc(hmac(sha1),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002094 .test = alg_test_aead,
2095 .fips_allowed = 1,
2096 .suite = {
2097 .aead = {
2098 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302099 .vecs =
2100 hmac_sha1_aes_cbc_enc_tv_temp,
2101 .count =
2102 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
2103 }
2104 }
2105 }
2106 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002107 .alg = "authenc(hmac(sha1),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302108 .test = alg_test_aead,
2109 .fips_allowed = 1,
2110 .suite = {
2111 .aead = {
2112 .enc = {
2113 .vecs =
2114 hmac_sha1_des_cbc_enc_tv_temp,
2115 .count =
2116 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
2117 }
2118 }
2119 }
2120 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002121 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302122 .test = alg_test_aead,
2123 .fips_allowed = 1,
2124 .suite = {
2125 .aead = {
2126 .enc = {
2127 .vecs =
2128 hmac_sha1_des3_ede_cbc_enc_tv_temp,
2129 .count =
2130 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002131 }
2132 }
2133 }
2134 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002135 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
2136 .test = alg_test_aead,
2137 .fips_allowed = 1,
2138 .suite = {
2139 .aead = {
2140 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302141 .vecs =
2142 hmac_sha1_ecb_cipher_null_enc_tv_temp,
2143 .count =
2144 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002145 },
2146 .dec = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302147 .vecs =
2148 hmac_sha1_ecb_cipher_null_dec_tv_temp,
2149 .count =
2150 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
2151 }
2152 }
2153 }
2154 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002155 .alg = "authenc(hmac(sha224),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302156 .test = alg_test_aead,
2157 .fips_allowed = 1,
2158 .suite = {
2159 .aead = {
2160 .enc = {
2161 .vecs =
2162 hmac_sha224_des_cbc_enc_tv_temp,
2163 .count =
2164 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2165 }
2166 }
2167 }
2168 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002169 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302170 .test = alg_test_aead,
2171 .fips_allowed = 1,
2172 .suite = {
2173 .aead = {
2174 .enc = {
2175 .vecs =
2176 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2177 .count =
2178 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002179 }
2180 }
2181 }
2182 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002183 .alg = "authenc(hmac(sha256),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002184 .test = alg_test_aead,
2185 .fips_allowed = 1,
2186 .suite = {
2187 .aead = {
2188 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302189 .vecs =
2190 hmac_sha256_aes_cbc_enc_tv_temp,
2191 .count =
2192 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2193 }
2194 }
2195 }
2196 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002197 .alg = "authenc(hmac(sha256),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302198 .test = alg_test_aead,
2199 .fips_allowed = 1,
2200 .suite = {
2201 .aead = {
2202 .enc = {
2203 .vecs =
2204 hmac_sha256_des_cbc_enc_tv_temp,
2205 .count =
2206 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2207 }
2208 }
2209 }
2210 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002211 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302212 .test = alg_test_aead,
2213 .fips_allowed = 1,
2214 .suite = {
2215 .aead = {
2216 .enc = {
2217 .vecs =
2218 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2219 .count =
2220 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2221 }
2222 }
2223 }
2224 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002225 .alg = "authenc(hmac(sha384),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302226 .test = alg_test_aead,
2227 .fips_allowed = 1,
2228 .suite = {
2229 .aead = {
2230 .enc = {
2231 .vecs =
2232 hmac_sha384_des_cbc_enc_tv_temp,
2233 .count =
2234 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2235 }
2236 }
2237 }
2238 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002239 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302240 .test = alg_test_aead,
2241 .fips_allowed = 1,
2242 .suite = {
2243 .aead = {
2244 .enc = {
2245 .vecs =
2246 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2247 .count =
2248 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002249 }
2250 }
2251 }
2252 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002253 .alg = "authenc(hmac(sha512),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002254 .test = alg_test_aead,
2255 .fips_allowed = 1,
2256 .suite = {
2257 .aead = {
2258 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302259 .vecs =
2260 hmac_sha512_aes_cbc_enc_tv_temp,
2261 .count =
2262 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2263 }
2264 }
2265 }
2266 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002267 .alg = "authenc(hmac(sha512),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302268 .test = alg_test_aead,
2269 .fips_allowed = 1,
2270 .suite = {
2271 .aead = {
2272 .enc = {
2273 .vecs =
2274 hmac_sha512_des_cbc_enc_tv_temp,
2275 .count =
2276 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2277 }
2278 }
2279 }
2280 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002281 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302282 .test = alg_test_aead,
2283 .fips_allowed = 1,
2284 .suite = {
2285 .aead = {
2286 .enc = {
2287 .vecs =
2288 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2289 .count =
2290 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002291 }
2292 }
2293 }
2294 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002295 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002296 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002297 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002298 .suite = {
2299 .cipher = {
2300 .enc = {
2301 .vecs = aes_cbc_enc_tv_template,
2302 .count = AES_CBC_ENC_TEST_VECTORS
2303 },
2304 .dec = {
2305 .vecs = aes_cbc_dec_tv_template,
2306 .count = AES_CBC_DEC_TEST_VECTORS
2307 }
2308 }
2309 }
2310 }, {
2311 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002312 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002313 .suite = {
2314 .cipher = {
2315 .enc = {
2316 .vecs = anubis_cbc_enc_tv_template,
2317 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2318 },
2319 .dec = {
2320 .vecs = anubis_cbc_dec_tv_template,
2321 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2322 }
2323 }
2324 }
2325 }, {
2326 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002327 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002328 .suite = {
2329 .cipher = {
2330 .enc = {
2331 .vecs = bf_cbc_enc_tv_template,
2332 .count = BF_CBC_ENC_TEST_VECTORS
2333 },
2334 .dec = {
2335 .vecs = bf_cbc_dec_tv_template,
2336 .count = BF_CBC_DEC_TEST_VECTORS
2337 }
2338 }
2339 }
2340 }, {
2341 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002342 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002343 .suite = {
2344 .cipher = {
2345 .enc = {
2346 .vecs = camellia_cbc_enc_tv_template,
2347 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2348 },
2349 .dec = {
2350 .vecs = camellia_cbc_dec_tv_template,
2351 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2352 }
2353 }
2354 }
2355 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002356 .alg = "cbc(cast5)",
2357 .test = alg_test_skcipher,
2358 .suite = {
2359 .cipher = {
2360 .enc = {
2361 .vecs = cast5_cbc_enc_tv_template,
2362 .count = CAST5_CBC_ENC_TEST_VECTORS
2363 },
2364 .dec = {
2365 .vecs = cast5_cbc_dec_tv_template,
2366 .count = CAST5_CBC_DEC_TEST_VECTORS
2367 }
2368 }
2369 }
2370 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002371 .alg = "cbc(cast6)",
2372 .test = alg_test_skcipher,
2373 .suite = {
2374 .cipher = {
2375 .enc = {
2376 .vecs = cast6_cbc_enc_tv_template,
2377 .count = CAST6_CBC_ENC_TEST_VECTORS
2378 },
2379 .dec = {
2380 .vecs = cast6_cbc_dec_tv_template,
2381 .count = CAST6_CBC_DEC_TEST_VECTORS
2382 }
2383 }
2384 }
2385 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002386 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002387 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002388 .suite = {
2389 .cipher = {
2390 .enc = {
2391 .vecs = des_cbc_enc_tv_template,
2392 .count = DES_CBC_ENC_TEST_VECTORS
2393 },
2394 .dec = {
2395 .vecs = des_cbc_dec_tv_template,
2396 .count = DES_CBC_DEC_TEST_VECTORS
2397 }
2398 }
2399 }
2400 }, {
2401 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002402 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002403 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002404 .suite = {
2405 .cipher = {
2406 .enc = {
2407 .vecs = des3_ede_cbc_enc_tv_template,
2408 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2409 },
2410 .dec = {
2411 .vecs = des3_ede_cbc_dec_tv_template,
2412 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2413 }
2414 }
2415 }
2416 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002417 .alg = "cbc(serpent)",
2418 .test = alg_test_skcipher,
2419 .suite = {
2420 .cipher = {
2421 .enc = {
2422 .vecs = serpent_cbc_enc_tv_template,
2423 .count = SERPENT_CBC_ENC_TEST_VECTORS
2424 },
2425 .dec = {
2426 .vecs = serpent_cbc_dec_tv_template,
2427 .count = SERPENT_CBC_DEC_TEST_VECTORS
2428 }
2429 }
2430 }
2431 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002432 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002433 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002434 .suite = {
2435 .cipher = {
2436 .enc = {
2437 .vecs = tf_cbc_enc_tv_template,
2438 .count = TF_CBC_ENC_TEST_VECTORS
2439 },
2440 .dec = {
2441 .vecs = tf_cbc_dec_tv_template,
2442 .count = TF_CBC_DEC_TEST_VECTORS
2443 }
2444 }
2445 }
2446 }, {
2447 .alg = "ccm(aes)",
2448 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002449 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002450 .suite = {
2451 .aead = {
2452 .enc = {
2453 .vecs = aes_ccm_enc_tv_template,
2454 .count = AES_CCM_ENC_TEST_VECTORS
2455 },
2456 .dec = {
2457 .vecs = aes_ccm_dec_tv_template,
2458 .count = AES_CCM_DEC_TEST_VECTORS
2459 }
2460 }
2461 }
2462 }, {
Martin Willi3590ebf2015-06-01 13:43:57 +02002463 .alg = "chacha20",
2464 .test = alg_test_skcipher,
2465 .suite = {
2466 .cipher = {
2467 .enc = {
2468 .vecs = chacha20_enc_tv_template,
2469 .count = CHACHA20_ENC_TEST_VECTORS
2470 },
2471 .dec = {
2472 .vecs = chacha20_enc_tv_template,
2473 .count = CHACHA20_ENC_TEST_VECTORS
2474 },
2475 }
2476 }
2477 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002478 .alg = "cmac(aes)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002479 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002480 .test = alg_test_hash,
2481 .suite = {
2482 .hash = {
2483 .vecs = aes_cmac128_tv_template,
2484 .count = CMAC_AES_TEST_VECTORS
2485 }
2486 }
2487 }, {
2488 .alg = "cmac(des3_ede)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002489 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002490 .test = alg_test_hash,
2491 .suite = {
2492 .hash = {
2493 .vecs = des3_ede_cmac64_tv_template,
2494 .count = CMAC_DES3_EDE_TEST_VECTORS
2495 }
2496 }
2497 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002498 .alg = "compress_null",
2499 .test = alg_test_null,
2500 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02002501 .alg = "crc32",
2502 .test = alg_test_hash,
2503 .suite = {
2504 .hash = {
2505 .vecs = crc32_tv_template,
2506 .count = CRC32_TEST_VECTORS
2507 }
2508 }
2509 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002510 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002511 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002512 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002513 .suite = {
2514 .hash = {
2515 .vecs = crc32c_tv_template,
2516 .count = CRC32C_TEST_VECTORS
2517 }
2518 }
2519 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002520 .alg = "crct10dif",
2521 .test = alg_test_hash,
2522 .fips_allowed = 1,
2523 .suite = {
2524 .hash = {
2525 .vecs = crct10dif_tv_template,
2526 .count = CRCT10DIF_TEST_VECTORS
2527 }
2528 }
2529 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002530 .alg = "cryptd(__driver-cbc-aes-aesni)",
2531 .test = alg_test_null,
2532 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002533 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002534 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2535 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002536 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002537 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2538 .test = alg_test_null,
2539 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002540 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2541 .test = alg_test_null,
2542 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002543 .alg = "cryptd(__driver-ecb-aes-aesni)",
2544 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002545 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002546 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002547 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2548 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002549 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002550 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2551 .test = alg_test_null,
2552 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002553 .alg = "cryptd(__driver-ecb-cast5-avx)",
2554 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002555 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002556 .alg = "cryptd(__driver-ecb-cast6-avx)",
2557 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002558 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002559 .alg = "cryptd(__driver-ecb-serpent-avx)",
2560 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002561 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002562 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2563 .test = alg_test_null,
2564 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002565 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2566 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002567 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002568 .alg = "cryptd(__driver-ecb-twofish-avx)",
2569 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002570 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002571 .alg = "cryptd(__driver-gcm-aes-aesni)",
2572 .test = alg_test_null,
2573 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002574 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002575 .alg = "cryptd(__ghash-pclmulqdqni)",
2576 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002577 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002578 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002579 .alg = "ctr(aes)",
2580 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002581 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002582 .suite = {
2583 .cipher = {
2584 .enc = {
2585 .vecs = aes_ctr_enc_tv_template,
2586 .count = AES_CTR_ENC_TEST_VECTORS
2587 },
2588 .dec = {
2589 .vecs = aes_ctr_dec_tv_template,
2590 .count = AES_CTR_DEC_TEST_VECTORS
2591 }
2592 }
2593 }
2594 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002595 .alg = "ctr(blowfish)",
2596 .test = alg_test_skcipher,
2597 .suite = {
2598 .cipher = {
2599 .enc = {
2600 .vecs = bf_ctr_enc_tv_template,
2601 .count = BF_CTR_ENC_TEST_VECTORS
2602 },
2603 .dec = {
2604 .vecs = bf_ctr_dec_tv_template,
2605 .count = BF_CTR_DEC_TEST_VECTORS
2606 }
2607 }
2608 }
2609 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002610 .alg = "ctr(camellia)",
2611 .test = alg_test_skcipher,
2612 .suite = {
2613 .cipher = {
2614 .enc = {
2615 .vecs = camellia_ctr_enc_tv_template,
2616 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2617 },
2618 .dec = {
2619 .vecs = camellia_ctr_dec_tv_template,
2620 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2621 }
2622 }
2623 }
2624 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002625 .alg = "ctr(cast5)",
2626 .test = alg_test_skcipher,
2627 .suite = {
2628 .cipher = {
2629 .enc = {
2630 .vecs = cast5_ctr_enc_tv_template,
2631 .count = CAST5_CTR_ENC_TEST_VECTORS
2632 },
2633 .dec = {
2634 .vecs = cast5_ctr_dec_tv_template,
2635 .count = CAST5_CTR_DEC_TEST_VECTORS
2636 }
2637 }
2638 }
2639 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002640 .alg = "ctr(cast6)",
2641 .test = alg_test_skcipher,
2642 .suite = {
2643 .cipher = {
2644 .enc = {
2645 .vecs = cast6_ctr_enc_tv_template,
2646 .count = CAST6_CTR_ENC_TEST_VECTORS
2647 },
2648 .dec = {
2649 .vecs = cast6_ctr_dec_tv_template,
2650 .count = CAST6_CTR_DEC_TEST_VECTORS
2651 }
2652 }
2653 }
2654 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002655 .alg = "ctr(des)",
2656 .test = alg_test_skcipher,
2657 .suite = {
2658 .cipher = {
2659 .enc = {
2660 .vecs = des_ctr_enc_tv_template,
2661 .count = DES_CTR_ENC_TEST_VECTORS
2662 },
2663 .dec = {
2664 .vecs = des_ctr_dec_tv_template,
2665 .count = DES_CTR_DEC_TEST_VECTORS
2666 }
2667 }
2668 }
2669 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002670 .alg = "ctr(des3_ede)",
2671 .test = alg_test_skcipher,
2672 .suite = {
2673 .cipher = {
2674 .enc = {
2675 .vecs = des3_ede_ctr_enc_tv_template,
2676 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2677 },
2678 .dec = {
2679 .vecs = des3_ede_ctr_dec_tv_template,
2680 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2681 }
2682 }
2683 }
2684 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002685 .alg = "ctr(serpent)",
2686 .test = alg_test_skcipher,
2687 .suite = {
2688 .cipher = {
2689 .enc = {
2690 .vecs = serpent_ctr_enc_tv_template,
2691 .count = SERPENT_CTR_ENC_TEST_VECTORS
2692 },
2693 .dec = {
2694 .vecs = serpent_ctr_dec_tv_template,
2695 .count = SERPENT_CTR_DEC_TEST_VECTORS
2696 }
2697 }
2698 }
2699 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002700 .alg = "ctr(twofish)",
2701 .test = alg_test_skcipher,
2702 .suite = {
2703 .cipher = {
2704 .enc = {
2705 .vecs = tf_ctr_enc_tv_template,
2706 .count = TF_CTR_ENC_TEST_VECTORS
2707 },
2708 .dec = {
2709 .vecs = tf_ctr_dec_tv_template,
2710 .count = TF_CTR_DEC_TEST_VECTORS
2711 }
2712 }
2713 }
2714 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002715 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002716 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002717 .suite = {
2718 .cipher = {
2719 .enc = {
2720 .vecs = cts_mode_enc_tv_template,
2721 .count = CTS_MODE_ENC_TEST_VECTORS
2722 },
2723 .dec = {
2724 .vecs = cts_mode_dec_tv_template,
2725 .count = CTS_MODE_DEC_TEST_VECTORS
2726 }
2727 }
2728 }
2729 }, {
2730 .alg = "deflate",
2731 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002732 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002733 .suite = {
2734 .comp = {
2735 .comp = {
2736 .vecs = deflate_comp_tv_template,
2737 .count = DEFLATE_COMP_TEST_VECTORS
2738 },
2739 .decomp = {
2740 .vecs = deflate_decomp_tv_template,
2741 .count = DEFLATE_DECOMP_TEST_VECTORS
2742 }
2743 }
2744 }
2745 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002746 .alg = "digest_null",
2747 .test = alg_test_null,
2748 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002749 .alg = "drbg_nopr_ctr_aes128",
2750 .test = alg_test_drbg,
2751 .fips_allowed = 1,
2752 .suite = {
2753 .drbg = {
2754 .vecs = drbg_nopr_ctr_aes128_tv_template,
2755 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2756 }
2757 }
2758 }, {
2759 .alg = "drbg_nopr_ctr_aes192",
2760 .test = alg_test_drbg,
2761 .fips_allowed = 1,
2762 .suite = {
2763 .drbg = {
2764 .vecs = drbg_nopr_ctr_aes192_tv_template,
2765 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2766 }
2767 }
2768 }, {
2769 .alg = "drbg_nopr_ctr_aes256",
2770 .test = alg_test_drbg,
2771 .fips_allowed = 1,
2772 .suite = {
2773 .drbg = {
2774 .vecs = drbg_nopr_ctr_aes256_tv_template,
2775 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2776 }
2777 }
2778 }, {
2779 /*
2780 * There is no need to specifically test the DRBG with every
2781 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2782 */
2783 .alg = "drbg_nopr_hmac_sha1",
2784 .fips_allowed = 1,
2785 .test = alg_test_null,
2786 }, {
2787 .alg = "drbg_nopr_hmac_sha256",
2788 .test = alg_test_drbg,
2789 .fips_allowed = 1,
2790 .suite = {
2791 .drbg = {
2792 .vecs = drbg_nopr_hmac_sha256_tv_template,
2793 .count =
2794 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2795 }
2796 }
2797 }, {
2798 /* covered by drbg_nopr_hmac_sha256 test */
2799 .alg = "drbg_nopr_hmac_sha384",
2800 .fips_allowed = 1,
2801 .test = alg_test_null,
2802 }, {
2803 .alg = "drbg_nopr_hmac_sha512",
2804 .test = alg_test_null,
2805 .fips_allowed = 1,
2806 }, {
2807 .alg = "drbg_nopr_sha1",
2808 .fips_allowed = 1,
2809 .test = alg_test_null,
2810 }, {
2811 .alg = "drbg_nopr_sha256",
2812 .test = alg_test_drbg,
2813 .fips_allowed = 1,
2814 .suite = {
2815 .drbg = {
2816 .vecs = drbg_nopr_sha256_tv_template,
2817 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2818 }
2819 }
2820 }, {
2821 /* covered by drbg_nopr_sha256 test */
2822 .alg = "drbg_nopr_sha384",
2823 .fips_allowed = 1,
2824 .test = alg_test_null,
2825 }, {
2826 .alg = "drbg_nopr_sha512",
2827 .fips_allowed = 1,
2828 .test = alg_test_null,
2829 }, {
2830 .alg = "drbg_pr_ctr_aes128",
2831 .test = alg_test_drbg,
2832 .fips_allowed = 1,
2833 .suite = {
2834 .drbg = {
2835 .vecs = drbg_pr_ctr_aes128_tv_template,
2836 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2837 }
2838 }
2839 }, {
2840 /* covered by drbg_pr_ctr_aes128 test */
2841 .alg = "drbg_pr_ctr_aes192",
2842 .fips_allowed = 1,
2843 .test = alg_test_null,
2844 }, {
2845 .alg = "drbg_pr_ctr_aes256",
2846 .fips_allowed = 1,
2847 .test = alg_test_null,
2848 }, {
2849 .alg = "drbg_pr_hmac_sha1",
2850 .fips_allowed = 1,
2851 .test = alg_test_null,
2852 }, {
2853 .alg = "drbg_pr_hmac_sha256",
2854 .test = alg_test_drbg,
2855 .fips_allowed = 1,
2856 .suite = {
2857 .drbg = {
2858 .vecs = drbg_pr_hmac_sha256_tv_template,
2859 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2860 }
2861 }
2862 }, {
2863 /* covered by drbg_pr_hmac_sha256 test */
2864 .alg = "drbg_pr_hmac_sha384",
2865 .fips_allowed = 1,
2866 .test = alg_test_null,
2867 }, {
2868 .alg = "drbg_pr_hmac_sha512",
2869 .test = alg_test_null,
2870 .fips_allowed = 1,
2871 }, {
2872 .alg = "drbg_pr_sha1",
2873 .fips_allowed = 1,
2874 .test = alg_test_null,
2875 }, {
2876 .alg = "drbg_pr_sha256",
2877 .test = alg_test_drbg,
2878 .fips_allowed = 1,
2879 .suite = {
2880 .drbg = {
2881 .vecs = drbg_pr_sha256_tv_template,
2882 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2883 }
2884 }
2885 }, {
2886 /* covered by drbg_pr_sha256 test */
2887 .alg = "drbg_pr_sha384",
2888 .fips_allowed = 1,
2889 .test = alg_test_null,
2890 }, {
2891 .alg = "drbg_pr_sha512",
2892 .fips_allowed = 1,
2893 .test = alg_test_null,
2894 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002895 .alg = "ecb(__aes-aesni)",
2896 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002897 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002898 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002899 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002900 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002901 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002902 .suite = {
2903 .cipher = {
2904 .enc = {
2905 .vecs = aes_enc_tv_template,
2906 .count = AES_ENC_TEST_VECTORS
2907 },
2908 .dec = {
2909 .vecs = aes_dec_tv_template,
2910 .count = AES_DEC_TEST_VECTORS
2911 }
2912 }
2913 }
2914 }, {
2915 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002916 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002917 .suite = {
2918 .cipher = {
2919 .enc = {
2920 .vecs = anubis_enc_tv_template,
2921 .count = ANUBIS_ENC_TEST_VECTORS
2922 },
2923 .dec = {
2924 .vecs = anubis_dec_tv_template,
2925 .count = ANUBIS_DEC_TEST_VECTORS
2926 }
2927 }
2928 }
2929 }, {
2930 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002931 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002932 .suite = {
2933 .cipher = {
2934 .enc = {
2935 .vecs = arc4_enc_tv_template,
2936 .count = ARC4_ENC_TEST_VECTORS
2937 },
2938 .dec = {
2939 .vecs = arc4_dec_tv_template,
2940 .count = ARC4_DEC_TEST_VECTORS
2941 }
2942 }
2943 }
2944 }, {
2945 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002946 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002947 .suite = {
2948 .cipher = {
2949 .enc = {
2950 .vecs = bf_enc_tv_template,
2951 .count = BF_ENC_TEST_VECTORS
2952 },
2953 .dec = {
2954 .vecs = bf_dec_tv_template,
2955 .count = BF_DEC_TEST_VECTORS
2956 }
2957 }
2958 }
2959 }, {
2960 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002961 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002962 .suite = {
2963 .cipher = {
2964 .enc = {
2965 .vecs = camellia_enc_tv_template,
2966 .count = CAMELLIA_ENC_TEST_VECTORS
2967 },
2968 .dec = {
2969 .vecs = camellia_dec_tv_template,
2970 .count = CAMELLIA_DEC_TEST_VECTORS
2971 }
2972 }
2973 }
2974 }, {
2975 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002976 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002977 .suite = {
2978 .cipher = {
2979 .enc = {
2980 .vecs = cast5_enc_tv_template,
2981 .count = CAST5_ENC_TEST_VECTORS
2982 },
2983 .dec = {
2984 .vecs = cast5_dec_tv_template,
2985 .count = CAST5_DEC_TEST_VECTORS
2986 }
2987 }
2988 }
2989 }, {
2990 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002991 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002992 .suite = {
2993 .cipher = {
2994 .enc = {
2995 .vecs = cast6_enc_tv_template,
2996 .count = CAST6_ENC_TEST_VECTORS
2997 },
2998 .dec = {
2999 .vecs = cast6_dec_tv_template,
3000 .count = CAST6_DEC_TEST_VECTORS
3001 }
3002 }
3003 }
3004 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003005 .alg = "ecb(cipher_null)",
3006 .test = alg_test_null,
3007 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003008 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003009 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003010 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003011 .suite = {
3012 .cipher = {
3013 .enc = {
3014 .vecs = des_enc_tv_template,
3015 .count = DES_ENC_TEST_VECTORS
3016 },
3017 .dec = {
3018 .vecs = des_dec_tv_template,
3019 .count = DES_DEC_TEST_VECTORS
3020 }
3021 }
3022 }
3023 }, {
3024 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003025 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003026 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003027 .suite = {
3028 .cipher = {
3029 .enc = {
3030 .vecs = des3_ede_enc_tv_template,
3031 .count = DES3_EDE_ENC_TEST_VECTORS
3032 },
3033 .dec = {
3034 .vecs = des3_ede_dec_tv_template,
3035 .count = DES3_EDE_DEC_TEST_VECTORS
3036 }
3037 }
3038 }
3039 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003040 .alg = "ecb(fcrypt)",
3041 .test = alg_test_skcipher,
3042 .suite = {
3043 .cipher = {
3044 .enc = {
3045 .vecs = fcrypt_pcbc_enc_tv_template,
3046 .count = 1
3047 },
3048 .dec = {
3049 .vecs = fcrypt_pcbc_dec_tv_template,
3050 .count = 1
3051 }
3052 }
3053 }
3054 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003055 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003056 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003057 .suite = {
3058 .cipher = {
3059 .enc = {
3060 .vecs = khazad_enc_tv_template,
3061 .count = KHAZAD_ENC_TEST_VECTORS
3062 },
3063 .dec = {
3064 .vecs = khazad_dec_tv_template,
3065 .count = KHAZAD_DEC_TEST_VECTORS
3066 }
3067 }
3068 }
3069 }, {
3070 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003071 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003072 .suite = {
3073 .cipher = {
3074 .enc = {
3075 .vecs = seed_enc_tv_template,
3076 .count = SEED_ENC_TEST_VECTORS
3077 },
3078 .dec = {
3079 .vecs = seed_dec_tv_template,
3080 .count = SEED_DEC_TEST_VECTORS
3081 }
3082 }
3083 }
3084 }, {
3085 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003086 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003087 .suite = {
3088 .cipher = {
3089 .enc = {
3090 .vecs = serpent_enc_tv_template,
3091 .count = SERPENT_ENC_TEST_VECTORS
3092 },
3093 .dec = {
3094 .vecs = serpent_dec_tv_template,
3095 .count = SERPENT_DEC_TEST_VECTORS
3096 }
3097 }
3098 }
3099 }, {
3100 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003101 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003102 .suite = {
3103 .cipher = {
3104 .enc = {
3105 .vecs = tea_enc_tv_template,
3106 .count = TEA_ENC_TEST_VECTORS
3107 },
3108 .dec = {
3109 .vecs = tea_dec_tv_template,
3110 .count = TEA_DEC_TEST_VECTORS
3111 }
3112 }
3113 }
3114 }, {
3115 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003116 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003117 .suite = {
3118 .cipher = {
3119 .enc = {
3120 .vecs = tnepres_enc_tv_template,
3121 .count = TNEPRES_ENC_TEST_VECTORS
3122 },
3123 .dec = {
3124 .vecs = tnepres_dec_tv_template,
3125 .count = TNEPRES_DEC_TEST_VECTORS
3126 }
3127 }
3128 }
3129 }, {
3130 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003131 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003132 .suite = {
3133 .cipher = {
3134 .enc = {
3135 .vecs = tf_enc_tv_template,
3136 .count = TF_ENC_TEST_VECTORS
3137 },
3138 .dec = {
3139 .vecs = tf_dec_tv_template,
3140 .count = TF_DEC_TEST_VECTORS
3141 }
3142 }
3143 }
3144 }, {
3145 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003146 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003147 .suite = {
3148 .cipher = {
3149 .enc = {
3150 .vecs = xeta_enc_tv_template,
3151 .count = XETA_ENC_TEST_VECTORS
3152 },
3153 .dec = {
3154 .vecs = xeta_dec_tv_template,
3155 .count = XETA_DEC_TEST_VECTORS
3156 }
3157 }
3158 }
3159 }, {
3160 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003161 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003162 .suite = {
3163 .cipher = {
3164 .enc = {
3165 .vecs = xtea_enc_tv_template,
3166 .count = XTEA_ENC_TEST_VECTORS
3167 },
3168 .dec = {
3169 .vecs = xtea_dec_tv_template,
3170 .count = XTEA_DEC_TEST_VECTORS
3171 }
3172 }
3173 }
3174 }, {
3175 .alg = "gcm(aes)",
3176 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003177 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003178 .suite = {
3179 .aead = {
3180 .enc = {
3181 .vecs = aes_gcm_enc_tv_template,
3182 .count = AES_GCM_ENC_TEST_VECTORS
3183 },
3184 .dec = {
3185 .vecs = aes_gcm_dec_tv_template,
3186 .count = AES_GCM_DEC_TEST_VECTORS
3187 }
3188 }
3189 }
3190 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003191 .alg = "ghash",
3192 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003193 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003194 .suite = {
3195 .hash = {
3196 .vecs = ghash_tv_template,
3197 .count = GHASH_TEST_VECTORS
3198 }
3199 }
3200 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003201 .alg = "hmac(crc32)",
3202 .test = alg_test_hash,
3203 .suite = {
3204 .hash = {
3205 .vecs = bfin_crc_tv_template,
3206 .count = BFIN_CRC_TEST_VECTORS
3207 }
3208 }
3209 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003210 .alg = "hmac(md5)",
3211 .test = alg_test_hash,
3212 .suite = {
3213 .hash = {
3214 .vecs = hmac_md5_tv_template,
3215 .count = HMAC_MD5_TEST_VECTORS
3216 }
3217 }
3218 }, {
3219 .alg = "hmac(rmd128)",
3220 .test = alg_test_hash,
3221 .suite = {
3222 .hash = {
3223 .vecs = hmac_rmd128_tv_template,
3224 .count = HMAC_RMD128_TEST_VECTORS
3225 }
3226 }
3227 }, {
3228 .alg = "hmac(rmd160)",
3229 .test = alg_test_hash,
3230 .suite = {
3231 .hash = {
3232 .vecs = hmac_rmd160_tv_template,
3233 .count = HMAC_RMD160_TEST_VECTORS
3234 }
3235 }
3236 }, {
3237 .alg = "hmac(sha1)",
3238 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003239 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003240 .suite = {
3241 .hash = {
3242 .vecs = hmac_sha1_tv_template,
3243 .count = HMAC_SHA1_TEST_VECTORS
3244 }
3245 }
3246 }, {
3247 .alg = "hmac(sha224)",
3248 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003249 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003250 .suite = {
3251 .hash = {
3252 .vecs = hmac_sha224_tv_template,
3253 .count = HMAC_SHA224_TEST_VECTORS
3254 }
3255 }
3256 }, {
3257 .alg = "hmac(sha256)",
3258 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003259 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003260 .suite = {
3261 .hash = {
3262 .vecs = hmac_sha256_tv_template,
3263 .count = HMAC_SHA256_TEST_VECTORS
3264 }
3265 }
3266 }, {
3267 .alg = "hmac(sha384)",
3268 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003269 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003270 .suite = {
3271 .hash = {
3272 .vecs = hmac_sha384_tv_template,
3273 .count = HMAC_SHA384_TEST_VECTORS
3274 }
3275 }
3276 }, {
3277 .alg = "hmac(sha512)",
3278 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003279 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003280 .suite = {
3281 .hash = {
3282 .vecs = hmac_sha512_tv_template,
3283 .count = HMAC_SHA512_TEST_VECTORS
3284 }
3285 }
3286 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003287 .alg = "jitterentropy_rng",
3288 .fips_allowed = 1,
3289 .test = alg_test_null,
3290 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003291 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003292 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003293 .suite = {
3294 .cipher = {
3295 .enc = {
3296 .vecs = aes_lrw_enc_tv_template,
3297 .count = AES_LRW_ENC_TEST_VECTORS
3298 },
3299 .dec = {
3300 .vecs = aes_lrw_dec_tv_template,
3301 .count = AES_LRW_DEC_TEST_VECTORS
3302 }
3303 }
3304 }
3305 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003306 .alg = "lrw(camellia)",
3307 .test = alg_test_skcipher,
3308 .suite = {
3309 .cipher = {
3310 .enc = {
3311 .vecs = camellia_lrw_enc_tv_template,
3312 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3313 },
3314 .dec = {
3315 .vecs = camellia_lrw_dec_tv_template,
3316 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3317 }
3318 }
3319 }
3320 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003321 .alg = "lrw(cast6)",
3322 .test = alg_test_skcipher,
3323 .suite = {
3324 .cipher = {
3325 .enc = {
3326 .vecs = cast6_lrw_enc_tv_template,
3327 .count = CAST6_LRW_ENC_TEST_VECTORS
3328 },
3329 .dec = {
3330 .vecs = cast6_lrw_dec_tv_template,
3331 .count = CAST6_LRW_DEC_TEST_VECTORS
3332 }
3333 }
3334 }
3335 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003336 .alg = "lrw(serpent)",
3337 .test = alg_test_skcipher,
3338 .suite = {
3339 .cipher = {
3340 .enc = {
3341 .vecs = serpent_lrw_enc_tv_template,
3342 .count = SERPENT_LRW_ENC_TEST_VECTORS
3343 },
3344 .dec = {
3345 .vecs = serpent_lrw_dec_tv_template,
3346 .count = SERPENT_LRW_DEC_TEST_VECTORS
3347 }
3348 }
3349 }
3350 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003351 .alg = "lrw(twofish)",
3352 .test = alg_test_skcipher,
3353 .suite = {
3354 .cipher = {
3355 .enc = {
3356 .vecs = tf_lrw_enc_tv_template,
3357 .count = TF_LRW_ENC_TEST_VECTORS
3358 },
3359 .dec = {
3360 .vecs = tf_lrw_dec_tv_template,
3361 .count = TF_LRW_DEC_TEST_VECTORS
3362 }
3363 }
3364 }
3365 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003366 .alg = "lz4",
3367 .test = alg_test_comp,
3368 .fips_allowed = 1,
3369 .suite = {
3370 .comp = {
3371 .comp = {
3372 .vecs = lz4_comp_tv_template,
3373 .count = LZ4_COMP_TEST_VECTORS
3374 },
3375 .decomp = {
3376 .vecs = lz4_decomp_tv_template,
3377 .count = LZ4_DECOMP_TEST_VECTORS
3378 }
3379 }
3380 }
3381 }, {
3382 .alg = "lz4hc",
3383 .test = alg_test_comp,
3384 .fips_allowed = 1,
3385 .suite = {
3386 .comp = {
3387 .comp = {
3388 .vecs = lz4hc_comp_tv_template,
3389 .count = LZ4HC_COMP_TEST_VECTORS
3390 },
3391 .decomp = {
3392 .vecs = lz4hc_decomp_tv_template,
3393 .count = LZ4HC_DECOMP_TEST_VECTORS
3394 }
3395 }
3396 }
3397 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003398 .alg = "lzo",
3399 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003400 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003401 .suite = {
3402 .comp = {
3403 .comp = {
3404 .vecs = lzo_comp_tv_template,
3405 .count = LZO_COMP_TEST_VECTORS
3406 },
3407 .decomp = {
3408 .vecs = lzo_decomp_tv_template,
3409 .count = LZO_DECOMP_TEST_VECTORS
3410 }
3411 }
3412 }
3413 }, {
3414 .alg = "md4",
3415 .test = alg_test_hash,
3416 .suite = {
3417 .hash = {
3418 .vecs = md4_tv_template,
3419 .count = MD4_TEST_VECTORS
3420 }
3421 }
3422 }, {
3423 .alg = "md5",
3424 .test = alg_test_hash,
3425 .suite = {
3426 .hash = {
3427 .vecs = md5_tv_template,
3428 .count = MD5_TEST_VECTORS
3429 }
3430 }
3431 }, {
3432 .alg = "michael_mic",
3433 .test = alg_test_hash,
3434 .suite = {
3435 .hash = {
3436 .vecs = michael_mic_tv_template,
3437 .count = MICHAEL_MIC_TEST_VECTORS
3438 }
3439 }
3440 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003441 .alg = "ofb(aes)",
3442 .test = alg_test_skcipher,
3443 .fips_allowed = 1,
3444 .suite = {
3445 .cipher = {
3446 .enc = {
3447 .vecs = aes_ofb_enc_tv_template,
3448 .count = AES_OFB_ENC_TEST_VECTORS
3449 },
3450 .dec = {
3451 .vecs = aes_ofb_dec_tv_template,
3452 .count = AES_OFB_DEC_TEST_VECTORS
3453 }
3454 }
3455 }
3456 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003457 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003458 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003459 .suite = {
3460 .cipher = {
3461 .enc = {
3462 .vecs = fcrypt_pcbc_enc_tv_template,
3463 .count = FCRYPT_ENC_TEST_VECTORS
3464 },
3465 .dec = {
3466 .vecs = fcrypt_pcbc_dec_tv_template,
3467 .count = FCRYPT_DEC_TEST_VECTORS
3468 }
3469 }
3470 }
3471 }, {
Martin Willieee9dc62015-06-01 13:43:59 +02003472 .alg = "poly1305",
3473 .test = alg_test_hash,
3474 .suite = {
3475 .hash = {
3476 .vecs = poly1305_tv_template,
3477 .count = POLY1305_TEST_VECTORS
3478 }
3479 }
3480 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003481 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003482 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003483 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003484 .suite = {
3485 .cipher = {
3486 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003487 .vecs = aes_ctr_rfc3686_enc_tv_template,
3488 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003489 },
3490 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003491 .vecs = aes_ctr_rfc3686_dec_tv_template,
3492 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003493 }
3494 }
3495 }
3496 }, {
Herbert Xu3f31a742015-07-09 07:17:34 +08003497 .alg = "rfc4106(gcm(aes))",
Adrian Hoban69435b92010-11-04 15:02:04 -04003498 .test = alg_test_aead,
Jarod Wilsondb71f29a2015-01-23 12:42:15 -05003499 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003500 .suite = {
3501 .aead = {
3502 .enc = {
3503 .vecs = aes_gcm_rfc4106_enc_tv_template,
3504 .count = AES_GCM_4106_ENC_TEST_VECTORS
3505 },
3506 .dec = {
3507 .vecs = aes_gcm_rfc4106_dec_tv_template,
3508 .count = AES_GCM_4106_DEC_TEST_VECTORS
3509 }
3510 }
3511 }
3512 }, {
Herbert Xu544c4362015-07-14 16:53:22 +08003513 .alg = "rfc4309(ccm(aes))",
Jarod Wilson5d667322009-05-04 19:23:40 +08003514 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003515 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003516 .suite = {
3517 .aead = {
3518 .enc = {
3519 .vecs = aes_ccm_rfc4309_enc_tv_template,
3520 .count = AES_CCM_4309_ENC_TEST_VECTORS
3521 },
3522 .dec = {
3523 .vecs = aes_ccm_rfc4309_dec_tv_template,
3524 .count = AES_CCM_4309_DEC_TEST_VECTORS
3525 }
3526 }
3527 }
3528 }, {
Herbert Xubb687452015-06-16 13:54:24 +08003529 .alg = "rfc4543(gcm(aes))",
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003530 .test = alg_test_aead,
3531 .suite = {
3532 .aead = {
3533 .enc = {
3534 .vecs = aes_gcm_rfc4543_enc_tv_template,
3535 .count = AES_GCM_4543_ENC_TEST_VECTORS
3536 },
3537 .dec = {
3538 .vecs = aes_gcm_rfc4543_dec_tv_template,
3539 .count = AES_GCM_4543_DEC_TEST_VECTORS
3540 },
3541 }
3542 }
3543 }, {
Martin Williaf2b76b2015-06-01 13:44:01 +02003544 .alg = "rfc7539(chacha20,poly1305)",
3545 .test = alg_test_aead,
3546 .suite = {
3547 .aead = {
3548 .enc = {
3549 .vecs = rfc7539_enc_tv_template,
3550 .count = RFC7539_ENC_TEST_VECTORS
3551 },
3552 .dec = {
3553 .vecs = rfc7539_dec_tv_template,
3554 .count = RFC7539_DEC_TEST_VECTORS
3555 },
3556 }
3557 }
3558 }, {
Martin Willi59007582015-06-01 13:44:03 +02003559 .alg = "rfc7539esp(chacha20,poly1305)",
3560 .test = alg_test_aead,
3561 .suite = {
3562 .aead = {
3563 .enc = {
3564 .vecs = rfc7539esp_enc_tv_template,
3565 .count = RFC7539ESP_ENC_TEST_VECTORS
3566 },
3567 .dec = {
3568 .vecs = rfc7539esp_dec_tv_template,
3569 .count = RFC7539ESP_DEC_TEST_VECTORS
3570 },
3571 }
3572 }
3573 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003574 .alg = "rmd128",
3575 .test = alg_test_hash,
3576 .suite = {
3577 .hash = {
3578 .vecs = rmd128_tv_template,
3579 .count = RMD128_TEST_VECTORS
3580 }
3581 }
3582 }, {
3583 .alg = "rmd160",
3584 .test = alg_test_hash,
3585 .suite = {
3586 .hash = {
3587 .vecs = rmd160_tv_template,
3588 .count = RMD160_TEST_VECTORS
3589 }
3590 }
3591 }, {
3592 .alg = "rmd256",
3593 .test = alg_test_hash,
3594 .suite = {
3595 .hash = {
3596 .vecs = rmd256_tv_template,
3597 .count = RMD256_TEST_VECTORS
3598 }
3599 }
3600 }, {
3601 .alg = "rmd320",
3602 .test = alg_test_hash,
3603 .suite = {
3604 .hash = {
3605 .vecs = rmd320_tv_template,
3606 .count = RMD320_TEST_VECTORS
3607 }
3608 }
3609 }, {
Tadeusz Struk946cc462015-06-16 10:31:06 -07003610 .alg = "rsa",
3611 .test = alg_test_akcipher,
3612 .fips_allowed = 1,
3613 .suite = {
3614 .akcipher = {
3615 .vecs = rsa_tv_template,
3616 .count = RSA_TEST_VECTORS
3617 }
3618 }
3619 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003620 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003621 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003622 .suite = {
3623 .cipher = {
3624 .enc = {
3625 .vecs = salsa20_stream_enc_tv_template,
3626 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3627 }
3628 }
3629 }
3630 }, {
3631 .alg = "sha1",
3632 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003633 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003634 .suite = {
3635 .hash = {
3636 .vecs = sha1_tv_template,
3637 .count = SHA1_TEST_VECTORS
3638 }
3639 }
3640 }, {
3641 .alg = "sha224",
3642 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003643 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003644 .suite = {
3645 .hash = {
3646 .vecs = sha224_tv_template,
3647 .count = SHA224_TEST_VECTORS
3648 }
3649 }
3650 }, {
3651 .alg = "sha256",
3652 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003653 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003654 .suite = {
3655 .hash = {
3656 .vecs = sha256_tv_template,
3657 .count = SHA256_TEST_VECTORS
3658 }
3659 }
3660 }, {
3661 .alg = "sha384",
3662 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003663 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003664 .suite = {
3665 .hash = {
3666 .vecs = sha384_tv_template,
3667 .count = SHA384_TEST_VECTORS
3668 }
3669 }
3670 }, {
3671 .alg = "sha512",
3672 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003673 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003674 .suite = {
3675 .hash = {
3676 .vecs = sha512_tv_template,
3677 .count = SHA512_TEST_VECTORS
3678 }
3679 }
3680 }, {
3681 .alg = "tgr128",
3682 .test = alg_test_hash,
3683 .suite = {
3684 .hash = {
3685 .vecs = tgr128_tv_template,
3686 .count = TGR128_TEST_VECTORS
3687 }
3688 }
3689 }, {
3690 .alg = "tgr160",
3691 .test = alg_test_hash,
3692 .suite = {
3693 .hash = {
3694 .vecs = tgr160_tv_template,
3695 .count = TGR160_TEST_VECTORS
3696 }
3697 }
3698 }, {
3699 .alg = "tgr192",
3700 .test = alg_test_hash,
3701 .suite = {
3702 .hash = {
3703 .vecs = tgr192_tv_template,
3704 .count = TGR192_TEST_VECTORS
3705 }
3706 }
3707 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003708 .alg = "vmac(aes)",
3709 .test = alg_test_hash,
3710 .suite = {
3711 .hash = {
3712 .vecs = aes_vmac128_tv_template,
3713 .count = VMAC_AES_TEST_VECTORS
3714 }
3715 }
3716 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003717 .alg = "wp256",
3718 .test = alg_test_hash,
3719 .suite = {
3720 .hash = {
3721 .vecs = wp256_tv_template,
3722 .count = WP256_TEST_VECTORS
3723 }
3724 }
3725 }, {
3726 .alg = "wp384",
3727 .test = alg_test_hash,
3728 .suite = {
3729 .hash = {
3730 .vecs = wp384_tv_template,
3731 .count = WP384_TEST_VECTORS
3732 }
3733 }
3734 }, {
3735 .alg = "wp512",
3736 .test = alg_test_hash,
3737 .suite = {
3738 .hash = {
3739 .vecs = wp512_tv_template,
3740 .count = WP512_TEST_VECTORS
3741 }
3742 }
3743 }, {
3744 .alg = "xcbc(aes)",
3745 .test = alg_test_hash,
3746 .suite = {
3747 .hash = {
3748 .vecs = aes_xcbc128_tv_template,
3749 .count = XCBC_AES_TEST_VECTORS
3750 }
3751 }
3752 }, {
3753 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003754 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003755 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003756 .suite = {
3757 .cipher = {
3758 .enc = {
3759 .vecs = aes_xts_enc_tv_template,
3760 .count = AES_XTS_ENC_TEST_VECTORS
3761 },
3762 .dec = {
3763 .vecs = aes_xts_dec_tv_template,
3764 .count = AES_XTS_DEC_TEST_VECTORS
3765 }
3766 }
3767 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003768 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003769 .alg = "xts(camellia)",
3770 .test = alg_test_skcipher,
3771 .suite = {
3772 .cipher = {
3773 .enc = {
3774 .vecs = camellia_xts_enc_tv_template,
3775 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3776 },
3777 .dec = {
3778 .vecs = camellia_xts_dec_tv_template,
3779 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3780 }
3781 }
3782 }
3783 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003784 .alg = "xts(cast6)",
3785 .test = alg_test_skcipher,
3786 .suite = {
3787 .cipher = {
3788 .enc = {
3789 .vecs = cast6_xts_enc_tv_template,
3790 .count = CAST6_XTS_ENC_TEST_VECTORS
3791 },
3792 .dec = {
3793 .vecs = cast6_xts_dec_tv_template,
3794 .count = CAST6_XTS_DEC_TEST_VECTORS
3795 }
3796 }
3797 }
3798 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003799 .alg = "xts(serpent)",
3800 .test = alg_test_skcipher,
3801 .suite = {
3802 .cipher = {
3803 .enc = {
3804 .vecs = serpent_xts_enc_tv_template,
3805 .count = SERPENT_XTS_ENC_TEST_VECTORS
3806 },
3807 .dec = {
3808 .vecs = serpent_xts_dec_tv_template,
3809 .count = SERPENT_XTS_DEC_TEST_VECTORS
3810 }
3811 }
3812 }
3813 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003814 .alg = "xts(twofish)",
3815 .test = alg_test_skcipher,
3816 .suite = {
3817 .cipher = {
3818 .enc = {
3819 .vecs = tf_xts_enc_tv_template,
3820 .count = TF_XTS_ENC_TEST_VECTORS
3821 },
3822 .dec = {
3823 .vecs = tf_xts_dec_tv_template,
3824 .count = TF_XTS_DEC_TEST_VECTORS
3825 }
3826 }
3827 }
3828 }, {
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003829 .alg = "zlib",
3830 .test = alg_test_pcomp,
Milan Broz08189042012-12-06 17:16:28 +08003831 .fips_allowed = 1,
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003832 .suite = {
3833 .pcomp = {
3834 .comp = {
3835 .vecs = zlib_comp_tv_template,
3836 .count = ZLIB_COMP_TEST_VECTORS
3837 },
3838 .decomp = {
3839 .vecs = zlib_decomp_tv_template,
3840 .count = ZLIB_DECOMP_TEST_VECTORS
3841 }
3842 }
3843 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003844 }
3845};
3846
Jussi Kivilinna57147582013-06-13 17:37:40 +03003847static bool alg_test_descs_checked;
3848
3849static void alg_test_descs_check_order(void)
3850{
3851 int i;
3852
3853 /* only check once */
3854 if (alg_test_descs_checked)
3855 return;
3856
3857 alg_test_descs_checked = true;
3858
3859 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3860 int diff = strcmp(alg_test_descs[i - 1].alg,
3861 alg_test_descs[i].alg);
3862
3863 if (WARN_ON(diff > 0)) {
3864 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3865 alg_test_descs[i - 1].alg,
3866 alg_test_descs[i].alg);
3867 }
3868
3869 if (WARN_ON(diff == 0)) {
3870 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3871 alg_test_descs[i].alg);
3872 }
3873 }
3874}
3875
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003876static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003877{
3878 int start = 0;
3879 int end = ARRAY_SIZE(alg_test_descs);
3880
3881 while (start < end) {
3882 int i = (start + end) / 2;
3883 int diff = strcmp(alg_test_descs[i].alg, alg);
3884
3885 if (diff > 0) {
3886 end = i;
3887 continue;
3888 }
3889
3890 if (diff < 0) {
3891 start = i + 1;
3892 continue;
3893 }
3894
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003895 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003896 }
3897
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003898 return -1;
3899}
3900
3901int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3902{
3903 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003904 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003905 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003906
Jussi Kivilinna57147582013-06-13 17:37:40 +03003907 alg_test_descs_check_order();
3908
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003909 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3910 char nalg[CRYPTO_MAX_ALG_NAME];
3911
3912 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3913 sizeof(nalg))
3914 return -ENAMETOOLONG;
3915
3916 i = alg_find_test(nalg);
3917 if (i < 0)
3918 goto notest;
3919
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003920 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3921 goto non_fips_alg;
3922
Jarod Wilson941fb322009-05-04 19:49:23 +08003923 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3924 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003925 }
3926
3927 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003928 j = alg_find_test(driver);
3929 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003930 goto notest;
3931
Herbert Xua68f6612009-07-02 16:32:12 +08003932 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3933 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003934 goto non_fips_alg;
3935
Herbert Xua68f6612009-07-02 16:32:12 +08003936 rc = 0;
3937 if (i >= 0)
3938 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3939 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003940 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003941 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3942 type, mask);
3943
Jarod Wilson941fb322009-05-04 19:49:23 +08003944test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003945 if (fips_enabled && rc)
3946 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3947
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003948 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09003949 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003950
Neil Hormand12d6b62008-10-12 20:36:51 +08003951 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003952
3953notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003954 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3955 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003956non_fips_alg:
3957 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003958}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003959
Herbert Xu326a6342010-08-06 09:40:28 +08003960#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003961
Herbert Xuda7f0332008-07-31 17:08:25 +08003962EXPORT_SYMBOL_GPL(alg_test);