blob: 277b3ac0ca1a1e71324a1d7346d20daadbec4e7b [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>
Herbert Xuda7f0332008-07-31 17:08:25 +080033
34#include "internal.h"
Alexander Shishkin0b767f92010-06-03 20:53:43 +100035
Herbert Xu326a6342010-08-06 09:40:28 +080036#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
Alexander Shishkin0b767f92010-06-03 20:53:43 +100037
38/* a perfect nop */
39int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
40{
41 return 0;
42}
43
44#else
45
Herbert Xuda7f0332008-07-31 17:08:25 +080046#include "testmgr.h"
47
48/*
49 * Need slab memory for testing (size in number of pages).
50 */
51#define XBUFSIZE 8
52
53/*
54 * Indexes into the xbuf to simulate cross-page access.
55 */
56#define IDX1 32
57#define IDX2 32400
58#define IDX3 1
59#define IDX4 8193
60#define IDX5 22222
61#define IDX6 17101
62#define IDX7 27333
63#define IDX8 3000
64
65/*
66* Used by test_cipher()
67*/
68#define ENCRYPT 1
69#define DECRYPT 0
70
71struct tcrypt_result {
72 struct completion completion;
73 int err;
74};
75
76struct aead_test_suite {
77 struct {
78 struct aead_testvec *vecs;
79 unsigned int count;
80 } enc, dec;
81};
82
83struct cipher_test_suite {
84 struct {
85 struct cipher_testvec *vecs;
86 unsigned int count;
87 } enc, dec;
88};
89
90struct comp_test_suite {
91 struct {
92 struct comp_testvec *vecs;
93 unsigned int count;
94 } comp, decomp;
95};
96
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +080097struct pcomp_test_suite {
98 struct {
99 struct pcomp_testvec *vecs;
100 unsigned int count;
101 } comp, decomp;
102};
103
Herbert Xuda7f0332008-07-31 17:08:25 +0800104struct hash_test_suite {
105 struct hash_testvec *vecs;
106 unsigned int count;
107};
108
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800109struct cprng_test_suite {
110 struct cprng_testvec *vecs;
111 unsigned int count;
112};
113
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200114struct drbg_test_suite {
115 struct drbg_testvec *vecs;
116 unsigned int count;
117};
118
Herbert Xuda7f0332008-07-31 17:08:25 +0800119struct alg_test_desc {
120 const char *alg;
121 int (*test)(const struct alg_test_desc *desc, const char *driver,
122 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000123 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800124
125 union {
126 struct aead_test_suite aead;
127 struct cipher_test_suite cipher;
128 struct comp_test_suite comp;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +0800129 struct pcomp_test_suite pcomp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800130 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800131 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200132 struct drbg_test_suite drbg;
Herbert Xuda7f0332008-07-31 17:08:25 +0800133 } suite;
134};
135
136static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
137
Herbert Xuda7f0332008-07-31 17:08:25 +0800138static void hexdump(unsigned char *buf, unsigned int len)
139{
140 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
141 16, 1,
142 buf, len, false);
143}
144
145static void tcrypt_complete(struct crypto_async_request *req, int err)
146{
147 struct tcrypt_result *res = req->data;
148
149 if (err == -EINPROGRESS)
150 return;
151
152 res->err = err;
153 complete(&res->completion);
154}
155
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800156static int testmgr_alloc_buf(char *buf[XBUFSIZE])
157{
158 int i;
159
160 for (i = 0; i < XBUFSIZE; i++) {
161 buf[i] = (void *)__get_free_page(GFP_KERNEL);
162 if (!buf[i])
163 goto err_free_buf;
164 }
165
166 return 0;
167
168err_free_buf:
169 while (i-- > 0)
170 free_page((unsigned long)buf[i]);
171
172 return -ENOMEM;
173}
174
175static void testmgr_free_buf(char *buf[XBUFSIZE])
176{
177 int i;
178
179 for (i = 0; i < XBUFSIZE; i++)
180 free_page((unsigned long)buf[i]);
181}
182
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300183static int wait_async_op(struct tcrypt_result *tr, int ret)
David S. Millera8f1a052010-05-19 14:12:03 +1000184{
185 if (ret == -EINPROGRESS || ret == -EBUSY) {
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100186 wait_for_completion(&tr->completion);
Wolfram Sang16735d02013-11-14 14:32:02 -0800187 reinit_completion(&tr->completion);
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100188 ret = tr->err;
David S. Millera8f1a052010-05-19 14:12:03 +1000189 }
190 return ret;
191}
192
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300193static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
194 unsigned int tcount, bool use_digest,
195 const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800196{
197 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
198 unsigned int i, j, k, temp;
199 struct scatterlist sg[8];
Horia Geanta29b77e52014-07-23 11:59:38 +0300200 char *result;
201 char *key;
Herbert Xuda7f0332008-07-31 17:08:25 +0800202 struct ahash_request *req;
203 struct tcrypt_result tresult;
Herbert Xuda7f0332008-07-31 17:08:25 +0800204 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800205 char *xbuf[XBUFSIZE];
206 int ret = -ENOMEM;
207
Horia Geanta29b77e52014-07-23 11:59:38 +0300208 result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
209 if (!result)
210 return ret;
211 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
212 if (!key)
213 goto out_nobuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800214 if (testmgr_alloc_buf(xbuf))
215 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800216
217 init_completion(&tresult.completion);
218
219 req = ahash_request_alloc(tfm, GFP_KERNEL);
220 if (!req) {
221 printk(KERN_ERR "alg: hash: Failed to allocate request for "
222 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800223 goto out_noreq;
224 }
225 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
226 tcrypt_complete, &tresult);
227
Herbert Xua0cfae52009-05-29 16:23:12 +1000228 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800229 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000230 if (template[i].np)
231 continue;
232
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300233 ret = -EINVAL;
234 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
235 goto out;
236
Herbert Xua0cfae52009-05-29 16:23:12 +1000237 j++;
Horia Geanta29b77e52014-07-23 11:59:38 +0300238 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800239
240 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300241 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800242
243 memcpy(hash_buff, template[i].plaintext, template[i].psize);
244 sg_init_one(&sg[0], hash_buff, template[i].psize);
245
246 if (template[i].ksize) {
247 crypto_ahash_clear_flags(tfm, ~0);
Horia Geanta29b77e52014-07-23 11:59:38 +0300248 if (template[i].ksize > MAX_KEYLEN) {
249 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
250 j, algo, template[i].ksize, MAX_KEYLEN);
251 ret = -EINVAL;
252 goto out;
253 }
254 memcpy(key, template[i].key, template[i].ksize);
255 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
Herbert Xuda7f0332008-07-31 17:08:25 +0800256 if (ret) {
257 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000258 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800259 -ret);
260 goto out;
261 }
262 }
263
264 ahash_request_set_crypt(req, sg, result, template[i].psize);
David S. Millera8f1a052010-05-19 14:12:03 +1000265 if (use_digest) {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300266 ret = wait_async_op(&tresult, crypto_ahash_digest(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000267 if (ret) {
268 pr_err("alg: hash: digest failed on test %d "
269 "for %s: ret=%d\n", j, algo, -ret);
270 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800271 }
David S. Millera8f1a052010-05-19 14:12:03 +1000272 } else {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300273 ret = wait_async_op(&tresult, crypto_ahash_init(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000274 if (ret) {
275 pr_err("alt: hash: init failed on test %d "
276 "for %s: ret=%d\n", j, algo, -ret);
277 goto out;
278 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300279 ret = wait_async_op(&tresult, crypto_ahash_update(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000280 if (ret) {
281 pr_err("alt: hash: update failed on test %d "
282 "for %s: ret=%d\n", j, algo, -ret);
283 goto out;
284 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300285 ret = wait_async_op(&tresult, crypto_ahash_final(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000286 if (ret) {
287 pr_err("alt: hash: final failed on test %d "
288 "for %s: ret=%d\n", j, algo, -ret);
289 goto out;
290 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800291 }
292
293 if (memcmp(result, template[i].digest,
294 crypto_ahash_digestsize(tfm))) {
295 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000296 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800297 hexdump(result, crypto_ahash_digestsize(tfm));
298 ret = -EINVAL;
299 goto out;
300 }
301 }
302
303 j = 0;
304 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300305 /* alignment tests are only done with continuous buffers */
306 if (align_offset != 0)
307 break;
308
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300309 if (!template[i].np)
310 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800311
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300312 j++;
313 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800314
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300315 temp = 0;
316 sg_init_table(sg, template[i].np);
317 ret = -EINVAL;
318 for (k = 0; k < template[i].np; k++) {
319 if (WARN_ON(offset_in_page(IDX[k]) +
320 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +0800321 goto out;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300322 sg_set_buf(&sg[k],
323 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
324 offset_in_page(IDX[k]),
325 template[i].plaintext + temp,
326 template[i].tap[k]),
327 template[i].tap[k]);
328 temp += template[i].tap[k];
329 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800330
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300331 if (template[i].ksize) {
332 if (template[i].ksize > MAX_KEYLEN) {
333 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
334 j, algo, template[i].ksize, MAX_KEYLEN);
Herbert Xuda7f0332008-07-31 17:08:25 +0800335 ret = -EINVAL;
336 goto out;
337 }
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300338 crypto_ahash_clear_flags(tfm, ~0);
339 memcpy(key, template[i].key, template[i].ksize);
340 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
341
342 if (ret) {
343 printk(KERN_ERR "alg: hash: setkey "
344 "failed on chunking test %d "
345 "for %s: ret=%d\n", j, algo, -ret);
346 goto out;
347 }
348 }
349
350 ahash_request_set_crypt(req, sg, result, template[i].psize);
351 ret = crypto_ahash_digest(req);
352 switch (ret) {
353 case 0:
354 break;
355 case -EINPROGRESS:
356 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100357 wait_for_completion(&tresult.completion);
358 reinit_completion(&tresult.completion);
359 ret = tresult.err;
360 if (!ret)
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300361 break;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300362 /* fall through */
363 default:
364 printk(KERN_ERR "alg: hash: digest failed "
365 "on chunking test %d for %s: "
366 "ret=%d\n", j, algo, -ret);
367 goto out;
368 }
369
370 if (memcmp(result, template[i].digest,
371 crypto_ahash_digestsize(tfm))) {
372 printk(KERN_ERR "alg: hash: Chunking test %d "
373 "failed for %s\n", j, algo);
374 hexdump(result, crypto_ahash_digestsize(tfm));
375 ret = -EINVAL;
376 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800377 }
378 }
379
380 ret = 0;
381
382out:
383 ahash_request_free(req);
384out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800385 testmgr_free_buf(xbuf);
386out_nobuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300387 kfree(key);
388 kfree(result);
Herbert Xuda7f0332008-07-31 17:08:25 +0800389 return ret;
390}
391
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300392static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
393 unsigned int tcount, bool use_digest)
394{
395 unsigned int alignmask;
396 int ret;
397
398 ret = __test_hash(tfm, template, tcount, use_digest, 0);
399 if (ret)
400 return ret;
401
402 /* test unaligned buffers, check with one byte offset */
403 ret = __test_hash(tfm, template, tcount, use_digest, 1);
404 if (ret)
405 return ret;
406
407 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
408 if (alignmask) {
409 /* Check if alignment mask for tfm is correctly set. */
410 ret = __test_hash(tfm, template, tcount, use_digest,
411 alignmask + 1);
412 if (ret)
413 return ret;
414 }
415
416 return 0;
417}
418
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300419static int __test_aead(struct crypto_aead *tfm, int enc,
420 struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300421 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800422{
423 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
424 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800425 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800426 char *q;
427 char *key;
428 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300429 struct scatterlist *sg;
430 struct scatterlist *asg;
431 struct scatterlist *sgout;
432 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800433 struct tcrypt_result result;
Cristian Stoica424a5da2015-01-28 11:03:05 +0200434 unsigned int authsize, iv_len;
Herbert Xuda7f0332008-07-31 17:08:25 +0800435 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300436 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800437 void *assoc;
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700438 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800439 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300440 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800441 char *axbuf[XBUFSIZE];
442
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700443 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
444 if (!iv)
445 return ret;
Horia Geanta29b77e52014-07-23 11:59:38 +0300446 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
447 if (!key)
448 goto out_noxbuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800449 if (testmgr_alloc_buf(xbuf))
450 goto out_noxbuf;
451 if (testmgr_alloc_buf(axbuf))
452 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300453 if (diff_dst && testmgr_alloc_buf(xoutbuf))
454 goto out_nooutbuf;
455
456 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
457 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL);
458 if (!sg)
459 goto out_nosg;
460 asg = &sg[8];
461 sgout = &asg[8];
462
463 if (diff_dst)
464 d = "-ddst";
465 else
466 d = "";
467
Herbert Xuda7f0332008-07-31 17:08:25 +0800468 if (enc == ENCRYPT)
469 e = "encryption";
470 else
471 e = "decryption";
472
473 init_completion(&result.completion);
474
475 req = aead_request_alloc(tfm, GFP_KERNEL);
476 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300477 pr_err("alg: aead%s: Failed to allocate request for %s\n",
478 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800479 goto out;
480 }
481
482 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
483 tcrypt_complete, &result);
484
485 for (i = 0, j = 0; i < tcount; i++) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300486 if (template[i].np)
487 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800488
Cristian Stoica05b1d332014-07-28 13:11:23 +0300489 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800490
Cristian Stoica05b1d332014-07-28 13:11:23 +0300491 /* some templates have no input data but they will
492 * touch input
493 */
494 input = xbuf[0];
495 input += align_offset;
496 assoc = axbuf[0];
497
498 ret = -EINVAL;
499 if (WARN_ON(align_offset + template[i].ilen >
500 PAGE_SIZE || template[i].alen > PAGE_SIZE))
501 goto out;
502
503 memcpy(input, template[i].input, template[i].ilen);
504 memcpy(assoc, template[i].assoc, template[i].alen);
Cristian Stoica424a5da2015-01-28 11:03:05 +0200505 iv_len = crypto_aead_ivsize(tfm);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300506 if (template[i].iv)
Cristian Stoica424a5da2015-01-28 11:03:05 +0200507 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300508 else
Cristian Stoica424a5da2015-01-28 11:03:05 +0200509 memset(iv, 0, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300510
511 crypto_aead_clear_flags(tfm, ~0);
512 if (template[i].wk)
513 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
514
515 if (template[i].klen > MAX_KEYLEN) {
516 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
517 d, j, algo, template[i].klen,
518 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +1000519 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300520 goto out;
521 }
522 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +1000523
Cristian Stoica05b1d332014-07-28 13:11:23 +0300524 ret = crypto_aead_setkey(tfm, key, template[i].klen);
525 if (!ret == template[i].fail) {
526 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
527 d, j, algo, crypto_aead_get_flags(tfm));
528 goto out;
529 } else if (ret)
530 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800531
Cristian Stoica05b1d332014-07-28 13:11:23 +0300532 authsize = abs(template[i].rlen - template[i].ilen);
533 ret = crypto_aead_setauthsize(tfm, authsize);
534 if (ret) {
535 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
536 d, authsize, j, algo);
537 goto out;
538 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800539
Cristian Stoica05b1d332014-07-28 13:11:23 +0300540 if (diff_dst) {
541 output = xoutbuf[0];
542 output += align_offset;
543 sg_init_one(&sg[0], input, template[i].ilen);
544 sg_init_one(&sgout[0], output, template[i].rlen);
545 } else {
546 sg_init_one(&sg[0], input,
547 template[i].ilen + (enc ? authsize : 0));
548 output = input;
549 }
550
551 sg_init_one(&asg[0], assoc, template[i].alen);
552
553 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
554 template[i].ilen, iv);
555
556 aead_request_set_assoc(req, asg, template[i].alen);
557
558 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
559
560 switch (ret) {
561 case 0:
562 if (template[i].novrfy) {
563 /* verification was supposed to fail */
564 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
565 d, e, j, algo);
566 /* so really, we got a bad message */
567 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +0300568 goto out;
569 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300570 break;
571 case -EINPROGRESS:
572 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100573 wait_for_completion(&result.completion);
574 reinit_completion(&result.completion);
575 ret = result.err;
576 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +0800577 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300578 case -EBADMSG:
579 if (template[i].novrfy)
580 /* verification failure was expected */
581 continue;
582 /* fall through */
583 default:
584 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
585 d, e, j, algo, -ret);
586 goto out;
587 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800588
Cristian Stoica05b1d332014-07-28 13:11:23 +0300589 q = output;
590 if (memcmp(q, template[i].result, template[i].rlen)) {
591 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
592 d, j, e, algo);
593 hexdump(q, template[i].rlen);
594 ret = -EINVAL;
595 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800596 }
597 }
598
599 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300600 /* alignment tests are only done with continuous buffers */
601 if (align_offset != 0)
602 break;
603
Cristian Stoica05b1d332014-07-28 13:11:23 +0300604 if (!template[i].np)
605 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800606
Cristian Stoica05b1d332014-07-28 13:11:23 +0300607 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800608
Cristian Stoica05b1d332014-07-28 13:11:23 +0300609 if (template[i].iv)
610 memcpy(iv, template[i].iv, MAX_IVLEN);
611 else
612 memset(iv, 0, MAX_IVLEN);
613
614 crypto_aead_clear_flags(tfm, ~0);
615 if (template[i].wk)
616 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
617 if (template[i].klen > MAX_KEYLEN) {
618 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
619 d, j, algo, template[i].klen, MAX_KEYLEN);
620 ret = -EINVAL;
621 goto out;
622 }
623 memcpy(key, template[i].key, template[i].klen);
624
625 ret = crypto_aead_setkey(tfm, key, template[i].klen);
626 if (!ret == template[i].fail) {
627 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
628 d, j, algo, crypto_aead_get_flags(tfm));
629 goto out;
630 } else if (ret)
631 continue;
632
633 authsize = abs(template[i].rlen - template[i].ilen);
634
635 ret = -EINVAL;
636 sg_init_table(sg, template[i].np);
637 if (diff_dst)
638 sg_init_table(sgout, template[i].np);
639 for (k = 0, temp = 0; k < template[i].np; k++) {
640 if (WARN_ON(offset_in_page(IDX[k]) +
641 template[i].tap[k] > PAGE_SIZE))
642 goto out;
643
644 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
645 memcpy(q, template[i].input + temp, template[i].tap[k]);
646 sg_set_buf(&sg[k], q, template[i].tap[k]);
647
648 if (diff_dst) {
649 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
650 offset_in_page(IDX[k]);
651
652 memset(q, 0, template[i].tap[k]);
653
654 sg_set_buf(&sgout[k], q, template[i].tap[k]);
655 }
656
657 n = template[i].tap[k];
658 if (k == template[i].np - 1 && enc)
659 n += authsize;
660 if (offset_in_page(q) + n < PAGE_SIZE)
661 q[n] = 0;
662
663 temp += template[i].tap[k];
664 }
665
666 ret = crypto_aead_setauthsize(tfm, authsize);
667 if (ret) {
668 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
669 d, authsize, j, algo);
670 goto out;
671 }
672
673 if (enc) {
674 if (WARN_ON(sg[k - 1].offset +
675 sg[k - 1].length + authsize >
676 PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300677 ret = -EINVAL;
678 goto out;
679 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800680
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300681 if (diff_dst)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300682 sgout[k - 1].length += authsize;
683 else
684 sg[k - 1].length += authsize;
685 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800686
Cristian Stoica05b1d332014-07-28 13:11:23 +0300687 sg_init_table(asg, template[i].anp);
688 ret = -EINVAL;
689 for (k = 0, temp = 0; k < template[i].anp; k++) {
690 if (WARN_ON(offset_in_page(IDX[k]) +
691 template[i].atap[k] > PAGE_SIZE))
692 goto out;
693 sg_set_buf(&asg[k],
694 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
695 offset_in_page(IDX[k]),
696 template[i].assoc + temp,
697 template[i].atap[k]),
698 template[i].atap[k]);
699 temp += template[i].atap[k];
700 }
701
702 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
703 template[i].ilen,
704 iv);
705
706 aead_request_set_assoc(req, asg, template[i].alen);
707
708 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
709
710 switch (ret) {
711 case 0:
712 if (template[i].novrfy) {
713 /* verification was supposed to fail */
714 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
715 d, e, j, algo);
716 /* so really, we got a bad message */
717 ret = -EBADMSG;
718 goto out;
719 }
720 break;
721 case -EINPROGRESS:
722 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100723 wait_for_completion(&result.completion);
724 reinit_completion(&result.completion);
725 ret = result.err;
726 if (!ret)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300727 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300728 case -EBADMSG:
729 if (template[i].novrfy)
730 /* verification failure was expected */
731 continue;
732 /* fall through */
733 default:
734 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
735 d, e, j, algo, -ret);
736 goto out;
737 }
738
739 ret = -EINVAL;
740 for (k = 0, temp = 0; k < template[i].np; k++) {
741 if (diff_dst)
742 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
743 offset_in_page(IDX[k]);
744 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800745 q = xbuf[IDX[k] >> PAGE_SHIFT] +
746 offset_in_page(IDX[k]);
747
Cristian Stoica05b1d332014-07-28 13:11:23 +0300748 n = template[i].tap[k];
749 if (k == template[i].np - 1)
750 n += enc ? authsize : -authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800751
Cristian Stoica05b1d332014-07-28 13:11:23 +0300752 if (memcmp(q, template[i].result + temp, n)) {
753 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
754 d, j, e, k, algo);
755 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800756 goto out;
757 }
758
Cristian Stoica05b1d332014-07-28 13:11:23 +0300759 q += n;
760 if (k == template[i].np - 1 && !enc) {
761 if (!diff_dst &&
762 memcmp(q, template[i].input +
763 temp + n, authsize))
764 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200765 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300766 n = 0;
767 } else {
768 for (n = 0; offset_in_page(q + n) && q[n]; n++)
769 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800770 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300771 if (n) {
772 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
773 d, j, e, k, algo, n);
774 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800775 goto out;
776 }
777
Cristian Stoica05b1d332014-07-28 13:11:23 +0300778 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800779 }
780 }
781
782 ret = 0;
783
784out:
785 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300786 kfree(sg);
787out_nosg:
788 if (diff_dst)
789 testmgr_free_buf(xoutbuf);
790out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800791 testmgr_free_buf(axbuf);
792out_noaxbuf:
793 testmgr_free_buf(xbuf);
794out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300795 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700796 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800797 return ret;
798}
799
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300800static int test_aead(struct crypto_aead *tfm, int enc,
801 struct aead_testvec *template, unsigned int tcount)
802{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300803 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300804 int ret;
805
806 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300807 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300808 if (ret)
809 return ret;
810
811 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300812 ret = __test_aead(tfm, enc, template, tcount, true, 0);
813 if (ret)
814 return ret;
815
816 /* test unaligned buffers, check with one byte offset */
817 ret = __test_aead(tfm, enc, template, tcount, true, 1);
818 if (ret)
819 return ret;
820
821 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
822 if (alignmask) {
823 /* Check if alignment mask for tfm is correctly set. */
824 ret = __test_aead(tfm, enc, template, tcount, true,
825 alignmask + 1);
826 if (ret)
827 return ret;
828 }
829
830 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300831}
832
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000833static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800834 struct cipher_testvec *template, unsigned int tcount)
835{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000836 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
837 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000838 char *q;
839 const char *e;
840 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800841 char *xbuf[XBUFSIZE];
842 int ret = -ENOMEM;
843
844 if (testmgr_alloc_buf(xbuf))
845 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000846
847 if (enc == ENCRYPT)
848 e = "encryption";
849 else
850 e = "decryption";
851
852 j = 0;
853 for (i = 0; i < tcount; i++) {
854 if (template[i].np)
855 continue;
856
857 j++;
858
Herbert Xufd57f222009-05-29 16:05:42 +1000859 ret = -EINVAL;
860 if (WARN_ON(template[i].ilen > PAGE_SIZE))
861 goto out;
862
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000863 data = xbuf[0];
864 memcpy(data, template[i].input, template[i].ilen);
865
866 crypto_cipher_clear_flags(tfm, ~0);
867 if (template[i].wk)
868 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
869
870 ret = crypto_cipher_setkey(tfm, template[i].key,
871 template[i].klen);
872 if (!ret == template[i].fail) {
873 printk(KERN_ERR "alg: cipher: setkey failed "
874 "on test %d for %s: flags=%x\n", j,
875 algo, crypto_cipher_get_flags(tfm));
876 goto out;
877 } else if (ret)
878 continue;
879
880 for (k = 0; k < template[i].ilen;
881 k += crypto_cipher_blocksize(tfm)) {
882 if (enc)
883 crypto_cipher_encrypt_one(tfm, data + k,
884 data + k);
885 else
886 crypto_cipher_decrypt_one(tfm, data + k,
887 data + k);
888 }
889
890 q = data;
891 if (memcmp(q, template[i].result, template[i].rlen)) {
892 printk(KERN_ERR "alg: cipher: Test %d failed "
893 "on %s for %s\n", j, e, algo);
894 hexdump(q, template[i].rlen);
895 ret = -EINVAL;
896 goto out;
897 }
898 }
899
900 ret = 0;
901
902out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800903 testmgr_free_buf(xbuf);
904out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000905 return ret;
906}
907
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300908static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
909 struct cipher_testvec *template, unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300910 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000911{
Herbert Xuda7f0332008-07-31 17:08:25 +0800912 const char *algo =
913 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
914 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800915 char *q;
916 struct ablkcipher_request *req;
917 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300918 struct scatterlist sgout[8];
919 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800920 struct tcrypt_result result;
921 void *data;
922 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800923 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300924 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800925 int ret = -ENOMEM;
926
927 if (testmgr_alloc_buf(xbuf))
928 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800929
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300930 if (diff_dst && testmgr_alloc_buf(xoutbuf))
931 goto out_nooutbuf;
932
933 if (diff_dst)
934 d = "-ddst";
935 else
936 d = "";
937
Herbert Xuda7f0332008-07-31 17:08:25 +0800938 if (enc == ENCRYPT)
939 e = "encryption";
940 else
941 e = "decryption";
942
943 init_completion(&result.completion);
944
945 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
946 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300947 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
948 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800949 goto out;
950 }
951
952 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
953 tcrypt_complete, &result);
954
955 j = 0;
956 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +0300957 if (template[i].np && !template[i].also_non_np)
958 continue;
959
Herbert Xuda7f0332008-07-31 17:08:25 +0800960 if (template[i].iv)
961 memcpy(iv, template[i].iv, MAX_IVLEN);
962 else
963 memset(iv, 0, MAX_IVLEN);
964
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300965 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300966 ret = -EINVAL;
967 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
968 goto out;
969
970 data = xbuf[0];
971 data += align_offset;
972 memcpy(data, template[i].input, template[i].ilen);
973
974 crypto_ablkcipher_clear_flags(tfm, ~0);
975 if (template[i].wk)
976 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
977
978 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
979 template[i].klen);
980 if (!ret == template[i].fail) {
981 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
982 d, j, algo, crypto_ablkcipher_get_flags(tfm));
983 goto out;
984 } else if (ret)
985 continue;
986
987 sg_init_one(&sg[0], data, template[i].ilen);
988 if (diff_dst) {
989 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300990 data += align_offset;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300991 sg_init_one(&sgout[0], data, template[i].ilen);
992 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800993
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300994 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
995 template[i].ilen, iv);
996 ret = enc ? crypto_ablkcipher_encrypt(req) :
997 crypto_ablkcipher_decrypt(req);
Herbert Xuda7f0332008-07-31 17:08:25 +0800998
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300999 switch (ret) {
1000 case 0:
1001 break;
1002 case -EINPROGRESS:
1003 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001004 wait_for_completion(&result.completion);
1005 reinit_completion(&result.completion);
1006 ret = result.err;
1007 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +08001008 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001009 /* fall through */
1010 default:
1011 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1012 d, e, j, algo, -ret);
1013 goto out;
1014 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001015
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001016 q = data;
1017 if (memcmp(q, template[i].result, template[i].rlen)) {
1018 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1019 d, j, e, algo);
1020 hexdump(q, template[i].rlen);
1021 ret = -EINVAL;
1022 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001023 }
1024 }
1025
1026 j = 0;
1027 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001028 /* alignment tests are only done with continuous buffers */
1029 if (align_offset != 0)
1030 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001031
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001032 if (!template[i].np)
1033 continue;
1034
Herbert Xuda7f0332008-07-31 17:08:25 +08001035 if (template[i].iv)
1036 memcpy(iv, template[i].iv, MAX_IVLEN);
1037 else
1038 memset(iv, 0, MAX_IVLEN);
1039
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001040 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001041 crypto_ablkcipher_clear_flags(tfm, ~0);
1042 if (template[i].wk)
1043 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1044
1045 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1046 template[i].klen);
1047 if (!ret == template[i].fail) {
1048 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1049 d, j, algo, crypto_ablkcipher_get_flags(tfm));
1050 goto out;
1051 } else if (ret)
1052 continue;
1053
1054 temp = 0;
1055 ret = -EINVAL;
1056 sg_init_table(sg, template[i].np);
1057 if (diff_dst)
1058 sg_init_table(sgout, template[i].np);
1059 for (k = 0; k < template[i].np; k++) {
1060 if (WARN_ON(offset_in_page(IDX[k]) +
1061 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001062 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001063
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001064 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1065
1066 memcpy(q, template[i].input + temp, template[i].tap[k]);
1067
1068 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1069 q[template[i].tap[k]] = 0;
1070
1071 sg_set_buf(&sg[k], q, template[i].tap[k]);
1072 if (diff_dst) {
1073 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1074 offset_in_page(IDX[k]);
1075
1076 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1077
1078 memset(q, 0, template[i].tap[k]);
1079 if (offset_in_page(q) +
1080 template[i].tap[k] < PAGE_SIZE)
1081 q[template[i].tap[k]] = 0;
1082 }
1083
1084 temp += template[i].tap[k];
1085 }
1086
1087 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1088 template[i].ilen, iv);
1089
1090 ret = enc ? crypto_ablkcipher_encrypt(req) :
1091 crypto_ablkcipher_decrypt(req);
1092
1093 switch (ret) {
1094 case 0:
1095 break;
1096 case -EINPROGRESS:
1097 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001098 wait_for_completion(&result.completion);
1099 reinit_completion(&result.completion);
1100 ret = result.err;
1101 if (!ret)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001102 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001103 /* fall through */
1104 default:
1105 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1106 d, e, j, algo, -ret);
1107 goto out;
1108 }
1109
1110 temp = 0;
1111 ret = -EINVAL;
1112 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001113 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001114 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1115 offset_in_page(IDX[k]);
1116 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001117 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1118 offset_in_page(IDX[k]);
1119
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001120 if (memcmp(q, template[i].result + temp,
1121 template[i].tap[k])) {
1122 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1123 d, j, e, k, algo);
1124 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001125 goto out;
1126 }
1127
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001128 q += template[i].tap[k];
1129 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1130 ;
1131 if (n) {
1132 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1133 d, j, e, k, algo, n);
1134 hexdump(q, n);
1135 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001136 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001137 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001138 }
1139 }
1140
1141 ret = 0;
1142
1143out:
1144 ablkcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001145 if (diff_dst)
1146 testmgr_free_buf(xoutbuf);
1147out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001148 testmgr_free_buf(xbuf);
1149out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001150 return ret;
1151}
1152
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001153static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1154 struct cipher_testvec *template, unsigned int tcount)
1155{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001156 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001157 int ret;
1158
1159 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001160 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001161 if (ret)
1162 return ret;
1163
1164 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001165 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1166 if (ret)
1167 return ret;
1168
1169 /* test unaligned buffers, check with one byte offset */
1170 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1171 if (ret)
1172 return ret;
1173
1174 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1175 if (alignmask) {
1176 /* Check if alignment mask for tfm is correctly set. */
1177 ret = __test_skcipher(tfm, enc, template, tcount, true,
1178 alignmask + 1);
1179 if (ret)
1180 return ret;
1181 }
1182
1183 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001184}
1185
Herbert Xuda7f0332008-07-31 17:08:25 +08001186static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1187 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1188{
1189 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1190 unsigned int i;
1191 char result[COMP_BUF_SIZE];
1192 int ret;
1193
1194 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001195 int ilen;
1196 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001197
1198 memset(result, 0, sizeof (result));
1199
1200 ilen = ctemplate[i].inlen;
1201 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1202 ilen, result, &dlen);
1203 if (ret) {
1204 printk(KERN_ERR "alg: comp: compression failed "
1205 "on test %d for %s: ret=%d\n", i + 1, algo,
1206 -ret);
1207 goto out;
1208 }
1209
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001210 if (dlen != ctemplate[i].outlen) {
1211 printk(KERN_ERR "alg: comp: Compression test %d "
1212 "failed for %s: output len = %d\n", i + 1, algo,
1213 dlen);
1214 ret = -EINVAL;
1215 goto out;
1216 }
1217
Herbert Xuda7f0332008-07-31 17:08:25 +08001218 if (memcmp(result, ctemplate[i].output, dlen)) {
1219 printk(KERN_ERR "alg: comp: Compression test %d "
1220 "failed for %s\n", i + 1, algo);
1221 hexdump(result, dlen);
1222 ret = -EINVAL;
1223 goto out;
1224 }
1225 }
1226
1227 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001228 int ilen;
1229 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001230
1231 memset(result, 0, sizeof (result));
1232
1233 ilen = dtemplate[i].inlen;
1234 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1235 ilen, result, &dlen);
1236 if (ret) {
1237 printk(KERN_ERR "alg: comp: decompression failed "
1238 "on test %d for %s: ret=%d\n", i + 1, algo,
1239 -ret);
1240 goto out;
1241 }
1242
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001243 if (dlen != dtemplate[i].outlen) {
1244 printk(KERN_ERR "alg: comp: Decompression test %d "
1245 "failed for %s: output len = %d\n", i + 1, algo,
1246 dlen);
1247 ret = -EINVAL;
1248 goto out;
1249 }
1250
Herbert Xuda7f0332008-07-31 17:08:25 +08001251 if (memcmp(result, dtemplate[i].output, dlen)) {
1252 printk(KERN_ERR "alg: comp: Decompression test %d "
1253 "failed for %s\n", i + 1, algo);
1254 hexdump(result, dlen);
1255 ret = -EINVAL;
1256 goto out;
1257 }
1258 }
1259
1260 ret = 0;
1261
1262out:
1263 return ret;
1264}
1265
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001266static int test_pcomp(struct crypto_pcomp *tfm,
1267 struct pcomp_testvec *ctemplate,
1268 struct pcomp_testvec *dtemplate, int ctcount,
1269 int dtcount)
1270{
1271 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1272 unsigned int i;
1273 char result[COMP_BUF_SIZE];
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001274 int res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001275
1276 for (i = 0; i < ctcount; i++) {
1277 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001278 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001279
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001280 res = crypto_compress_setup(tfm, ctemplate[i].params,
1281 ctemplate[i].paramsize);
1282 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001283 pr_err("alg: pcomp: compression setup failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001284 "%d for %s: error=%d\n", i + 1, algo, res);
1285 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001286 }
1287
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001288 res = crypto_compress_init(tfm);
1289 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001290 pr_err("alg: pcomp: compression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001291 "%d for %s: error=%d\n", i + 1, algo, res);
1292 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001293 }
1294
1295 memset(result, 0, sizeof(result));
1296
1297 req.next_in = ctemplate[i].input;
1298 req.avail_in = ctemplate[i].inlen / 2;
1299 req.next_out = result;
1300 req.avail_out = ctemplate[i].outlen / 2;
1301
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001302 res = crypto_compress_update(tfm, &req);
1303 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001304 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001305 "%d for %s: error=%d\n", i + 1, algo, res);
1306 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001307 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001308 if (res > 0)
1309 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001310
1311 /* Add remaining input data */
1312 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1313
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001314 res = crypto_compress_update(tfm, &req);
1315 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001316 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001317 "%d for %s: error=%d\n", i + 1, algo, res);
1318 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001319 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001320 if (res > 0)
1321 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001322
1323 /* Provide remaining output space */
1324 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1325
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001326 res = crypto_compress_final(tfm, &req);
1327 if (res < 0) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001328 pr_err("alg: pcomp: compression final failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001329 "%d for %s: error=%d\n", i + 1, algo, res);
1330 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001331 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001332 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001333
1334 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1335 pr_err("alg: comp: Compression test %d failed for %s: "
1336 "output len = %d (expected %d)\n", i + 1, algo,
1337 COMP_BUF_SIZE - req.avail_out,
1338 ctemplate[i].outlen);
1339 return -EINVAL;
1340 }
1341
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001342 if (produced != ctemplate[i].outlen) {
1343 pr_err("alg: comp: Compression test %d failed for %s: "
1344 "returned len = %u (expected %d)\n", i + 1,
1345 algo, produced, ctemplate[i].outlen);
1346 return -EINVAL;
1347 }
1348
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001349 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1350 pr_err("alg: pcomp: Compression test %d failed for "
1351 "%s\n", i + 1, algo);
1352 hexdump(result, ctemplate[i].outlen);
1353 return -EINVAL;
1354 }
1355 }
1356
1357 for (i = 0; i < dtcount; i++) {
1358 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001359 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001360
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001361 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1362 dtemplate[i].paramsize);
1363 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001364 pr_err("alg: pcomp: decompression setup failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001365 "test %d for %s: error=%d\n", i + 1, algo, res);
1366 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001367 }
1368
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001369 res = crypto_decompress_init(tfm);
1370 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001371 pr_err("alg: pcomp: decompression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001372 "%d for %s: error=%d\n", i + 1, algo, res);
1373 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001374 }
1375
1376 memset(result, 0, sizeof(result));
1377
1378 req.next_in = dtemplate[i].input;
1379 req.avail_in = dtemplate[i].inlen / 2;
1380 req.next_out = result;
1381 req.avail_out = dtemplate[i].outlen / 2;
1382
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001383 res = crypto_decompress_update(tfm, &req);
1384 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001385 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001386 "test %d for %s: error=%d\n", i + 1, algo, res);
1387 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001388 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001389 if (res > 0)
1390 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001391
1392 /* Add remaining input data */
1393 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1394
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001395 res = crypto_decompress_update(tfm, &req);
1396 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001397 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001398 "test %d for %s: error=%d\n", i + 1, algo, res);
1399 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001400 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001401 if (res > 0)
1402 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001403
1404 /* Provide remaining output space */
1405 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1406
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001407 res = crypto_decompress_final(tfm, &req);
1408 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001409 pr_err("alg: pcomp: decompression final failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001410 "test %d for %s: error=%d\n", i + 1, algo, res);
1411 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001412 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001413 if (res > 0)
1414 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001415
1416 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1417 pr_err("alg: comp: Decompression test %d failed for "
1418 "%s: output len = %d (expected %d)\n", i + 1,
1419 algo, COMP_BUF_SIZE - req.avail_out,
1420 dtemplate[i].outlen);
1421 return -EINVAL;
1422 }
1423
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001424 if (produced != dtemplate[i].outlen) {
1425 pr_err("alg: comp: Decompression test %d failed for "
1426 "%s: returned len = %u (expected %d)\n", i + 1,
1427 algo, produced, dtemplate[i].outlen);
1428 return -EINVAL;
1429 }
1430
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001431 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1432 pr_err("alg: pcomp: Decompression test %d failed for "
1433 "%s\n", i + 1, algo);
1434 hexdump(result, dtemplate[i].outlen);
1435 return -EINVAL;
1436 }
1437 }
1438
1439 return 0;
1440}
1441
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001442
1443static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1444 unsigned int tcount)
1445{
1446 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001447 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001448 u8 *seed;
1449 char result[32];
1450
1451 seedsize = crypto_rng_seedsize(tfm);
1452
1453 seed = kmalloc(seedsize, GFP_KERNEL);
1454 if (!seed) {
1455 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1456 "for %s\n", algo);
1457 return -ENOMEM;
1458 }
1459
1460 for (i = 0; i < tcount; i++) {
1461 memset(result, 0, 32);
1462
1463 memcpy(seed, template[i].v, template[i].vlen);
1464 memcpy(seed + template[i].vlen, template[i].key,
1465 template[i].klen);
1466 memcpy(seed + template[i].vlen + template[i].klen,
1467 template[i].dt, template[i].dtlen);
1468
1469 err = crypto_rng_reset(tfm, seed, seedsize);
1470 if (err) {
1471 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1472 "for %s\n", algo);
1473 goto out;
1474 }
1475
1476 for (j = 0; j < template[i].loops; j++) {
1477 err = crypto_rng_get_bytes(tfm, result,
1478 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01001479 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001480 printk(KERN_ERR "alg: cprng: Failed to obtain "
1481 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01001482 "%s (requested %d)\n", algo,
1483 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001484 goto out;
1485 }
1486 }
1487
1488 err = memcmp(result, template[i].result,
1489 template[i].rlen);
1490 if (err) {
1491 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1492 i, algo);
1493 hexdump(result, template[i].rlen);
1494 err = -EINVAL;
1495 goto out;
1496 }
1497 }
1498
1499out:
1500 kfree(seed);
1501 return err;
1502}
1503
Herbert Xuda7f0332008-07-31 17:08:25 +08001504static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1505 u32 type, u32 mask)
1506{
1507 struct crypto_aead *tfm;
1508 int err = 0;
1509
Stephan Mueller425a8822015-03-30 21:56:31 +02001510 tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001511 if (IS_ERR(tfm)) {
1512 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1513 "%ld\n", driver, PTR_ERR(tfm));
1514 return PTR_ERR(tfm);
1515 }
1516
1517 if (desc->suite.aead.enc.vecs) {
1518 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1519 desc->suite.aead.enc.count);
1520 if (err)
1521 goto out;
1522 }
1523
1524 if (!err && desc->suite.aead.dec.vecs)
1525 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1526 desc->suite.aead.dec.count);
1527
1528out:
1529 crypto_free_aead(tfm);
1530 return err;
1531}
1532
1533static int alg_test_cipher(const struct alg_test_desc *desc,
1534 const char *driver, u32 type, u32 mask)
1535{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001536 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001537 int err = 0;
1538
Stephan Mueller425a8822015-03-30 21:56:31 +02001539 tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001540 if (IS_ERR(tfm)) {
1541 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1542 "%s: %ld\n", driver, PTR_ERR(tfm));
1543 return PTR_ERR(tfm);
1544 }
1545
1546 if (desc->suite.cipher.enc.vecs) {
1547 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1548 desc->suite.cipher.enc.count);
1549 if (err)
1550 goto out;
1551 }
1552
1553 if (desc->suite.cipher.dec.vecs)
1554 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1555 desc->suite.cipher.dec.count);
1556
1557out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001558 crypto_free_cipher(tfm);
1559 return err;
1560}
1561
1562static int alg_test_skcipher(const struct alg_test_desc *desc,
1563 const char *driver, u32 type, u32 mask)
1564{
1565 struct crypto_ablkcipher *tfm;
1566 int err = 0;
1567
Stephan Mueller425a8822015-03-30 21:56:31 +02001568 tfm = crypto_alloc_ablkcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001569 if (IS_ERR(tfm)) {
1570 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1571 "%s: %ld\n", driver, PTR_ERR(tfm));
1572 return PTR_ERR(tfm);
1573 }
1574
1575 if (desc->suite.cipher.enc.vecs) {
1576 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1577 desc->suite.cipher.enc.count);
1578 if (err)
1579 goto out;
1580 }
1581
1582 if (desc->suite.cipher.dec.vecs)
1583 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1584 desc->suite.cipher.dec.count);
1585
1586out:
Herbert Xuda7f0332008-07-31 17:08:25 +08001587 crypto_free_ablkcipher(tfm);
1588 return err;
1589}
1590
1591static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1592 u32 type, u32 mask)
1593{
1594 struct crypto_comp *tfm;
1595 int err;
1596
1597 tfm = crypto_alloc_comp(driver, type, mask);
1598 if (IS_ERR(tfm)) {
1599 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1600 "%ld\n", driver, PTR_ERR(tfm));
1601 return PTR_ERR(tfm);
1602 }
1603
1604 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1605 desc->suite.comp.decomp.vecs,
1606 desc->suite.comp.comp.count,
1607 desc->suite.comp.decomp.count);
1608
1609 crypto_free_comp(tfm);
1610 return err;
1611}
1612
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001613static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1614 u32 type, u32 mask)
1615{
1616 struct crypto_pcomp *tfm;
1617 int err;
1618
1619 tfm = crypto_alloc_pcomp(driver, type, mask);
1620 if (IS_ERR(tfm)) {
1621 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1622 driver, PTR_ERR(tfm));
1623 return PTR_ERR(tfm);
1624 }
1625
1626 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1627 desc->suite.pcomp.decomp.vecs,
1628 desc->suite.pcomp.comp.count,
1629 desc->suite.pcomp.decomp.count);
1630
1631 crypto_free_pcomp(tfm);
1632 return err;
1633}
1634
Herbert Xuda7f0332008-07-31 17:08:25 +08001635static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1636 u32 type, u32 mask)
1637{
1638 struct crypto_ahash *tfm;
1639 int err;
1640
Stephan Mueller425a8822015-03-30 21:56:31 +02001641 tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001642 if (IS_ERR(tfm)) {
1643 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1644 "%ld\n", driver, PTR_ERR(tfm));
1645 return PTR_ERR(tfm);
1646 }
1647
David S. Millera8f1a052010-05-19 14:12:03 +10001648 err = test_hash(tfm, desc->suite.hash.vecs,
1649 desc->suite.hash.count, true);
1650 if (!err)
1651 err = test_hash(tfm, desc->suite.hash.vecs,
1652 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001653
1654 crypto_free_ahash(tfm);
1655 return err;
1656}
1657
Herbert Xu8e3ee852008-11-07 14:58:52 +08001658static int alg_test_crc32c(const struct alg_test_desc *desc,
1659 const char *driver, u32 type, u32 mask)
1660{
1661 struct crypto_shash *tfm;
1662 u32 val;
1663 int err;
1664
1665 err = alg_test_hash(desc, driver, type, mask);
1666 if (err)
1667 goto out;
1668
Stephan Mueller425a8822015-03-30 21:56:31 +02001669 tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001670 if (IS_ERR(tfm)) {
1671 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1672 "%ld\n", driver, PTR_ERR(tfm));
1673 err = PTR_ERR(tfm);
1674 goto out;
1675 }
1676
1677 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001678 SHASH_DESC_ON_STACK(shash, tfm);
1679 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001680
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001681 shash->tfm = tfm;
1682 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001683
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001684 *ctx = le32_to_cpu(420553207);
1685 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001686 if (err) {
1687 printk(KERN_ERR "alg: crc32c: Operation failed for "
1688 "%s: %d\n", driver, err);
1689 break;
1690 }
1691
1692 if (val != ~420553207) {
1693 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1694 "%d\n", driver, val);
1695 err = -EINVAL;
1696 }
1697 } while (0);
1698
1699 crypto_free_shash(tfm);
1700
1701out:
1702 return err;
1703}
1704
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001705static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1706 u32 type, u32 mask)
1707{
1708 struct crypto_rng *rng;
1709 int err;
1710
Stephan Mueller425a8822015-03-30 21:56:31 +02001711 rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001712 if (IS_ERR(rng)) {
1713 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1714 "%ld\n", driver, PTR_ERR(rng));
1715 return PTR_ERR(rng);
1716 }
1717
1718 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1719
1720 crypto_free_rng(rng);
1721
1722 return err;
1723}
1724
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001725
1726static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1727 const char *driver, u32 type, u32 mask)
1728{
1729 int ret = -EAGAIN;
1730 struct crypto_rng *drng;
1731 struct drbg_test_data test_data;
1732 struct drbg_string addtl, pers, testentropy;
1733 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1734
1735 if (!buf)
1736 return -ENOMEM;
1737
Stephan Mueller425a8822015-03-30 21:56:31 +02001738 drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001739 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001740 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001741 "%s\n", driver);
1742 kzfree(buf);
1743 return -ENOMEM;
1744 }
1745
1746 test_data.testentropy = &testentropy;
1747 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1748 drbg_string_fill(&pers, test->pers, test->perslen);
1749 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1750 if (ret) {
1751 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1752 goto outbuf;
1753 }
1754
1755 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1756 if (pr) {
1757 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1758 ret = crypto_drbg_get_bytes_addtl_test(drng,
1759 buf, test->expectedlen, &addtl, &test_data);
1760 } else {
1761 ret = crypto_drbg_get_bytes_addtl(drng,
1762 buf, test->expectedlen, &addtl);
1763 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001764 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001765 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001766 "driver %s\n", driver);
1767 goto outbuf;
1768 }
1769
1770 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1771 if (pr) {
1772 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1773 ret = crypto_drbg_get_bytes_addtl_test(drng,
1774 buf, test->expectedlen, &addtl, &test_data);
1775 } else {
1776 ret = crypto_drbg_get_bytes_addtl(drng,
1777 buf, test->expectedlen, &addtl);
1778 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001779 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001780 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001781 "driver %s\n", driver);
1782 goto outbuf;
1783 }
1784
1785 ret = memcmp(test->expected, buf, test->expectedlen);
1786
1787outbuf:
1788 crypto_free_rng(drng);
1789 kzfree(buf);
1790 return ret;
1791}
1792
1793
1794static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1795 u32 type, u32 mask)
1796{
1797 int err = 0;
1798 int pr = 0;
1799 int i = 0;
1800 struct drbg_testvec *template = desc->suite.drbg.vecs;
1801 unsigned int tcount = desc->suite.drbg.count;
1802
1803 if (0 == memcmp(driver, "drbg_pr_", 8))
1804 pr = 1;
1805
1806 for (i = 0; i < tcount; i++) {
1807 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1808 if (err) {
1809 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1810 i, driver);
1811 err = -EINVAL;
1812 break;
1813 }
1814 }
1815 return err;
1816
1817}
1818
Youquan, Song863b5572009-12-23 19:45:20 +08001819static int alg_test_null(const struct alg_test_desc *desc,
1820 const char *driver, u32 type, u32 mask)
1821{
1822 return 0;
1823}
1824
Herbert Xuda7f0332008-07-31 17:08:25 +08001825/* Please keep this list sorted by algorithm name. */
1826static const struct alg_test_desc alg_test_descs[] = {
1827 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001828 .alg = "__cbc-cast5-avx",
1829 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001830 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001831 .alg = "__cbc-cast6-avx",
1832 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001833 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001834 .alg = "__cbc-serpent-avx",
1835 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001836 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001837 .alg = "__cbc-serpent-avx2",
1838 .test = alg_test_null,
1839 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001840 .alg = "__cbc-serpent-sse2",
1841 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001842 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001843 .alg = "__cbc-twofish-avx",
1844 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001845 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001846 .alg = "__driver-cbc-aes-aesni",
1847 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001848 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001849 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001850 .alg = "__driver-cbc-camellia-aesni",
1851 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001852 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001853 .alg = "__driver-cbc-camellia-aesni-avx2",
1854 .test = alg_test_null,
1855 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001856 .alg = "__driver-cbc-cast5-avx",
1857 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001858 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001859 .alg = "__driver-cbc-cast6-avx",
1860 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001861 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001862 .alg = "__driver-cbc-serpent-avx",
1863 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001864 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001865 .alg = "__driver-cbc-serpent-avx2",
1866 .test = alg_test_null,
1867 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001868 .alg = "__driver-cbc-serpent-sse2",
1869 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001870 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001871 .alg = "__driver-cbc-twofish-avx",
1872 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001873 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001874 .alg = "__driver-ecb-aes-aesni",
1875 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001876 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001877 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001878 .alg = "__driver-ecb-camellia-aesni",
1879 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001880 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001881 .alg = "__driver-ecb-camellia-aesni-avx2",
1882 .test = alg_test_null,
1883 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001884 .alg = "__driver-ecb-cast5-avx",
1885 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001886 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001887 .alg = "__driver-ecb-cast6-avx",
1888 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001889 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001890 .alg = "__driver-ecb-serpent-avx",
1891 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001892 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001893 .alg = "__driver-ecb-serpent-avx2",
1894 .test = alg_test_null,
1895 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001896 .alg = "__driver-ecb-serpent-sse2",
1897 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001898 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001899 .alg = "__driver-ecb-twofish-avx",
1900 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001901 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001902 .alg = "__ghash-pclmulqdqni",
1903 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001904 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001905 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001906 .alg = "ansi_cprng",
1907 .test = alg_test_cprng,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001908 .fips_allowed = 1,
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001909 .suite = {
1910 .cprng = {
1911 .vecs = ansi_cprng_aes_tv_template,
1912 .count = ANSI_CPRNG_AES_TEST_VECTORS
1913 }
1914 }
1915 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001916 .alg = "authenc(hmac(md5),ecb(cipher_null))",
1917 .test = alg_test_aead,
1918 .fips_allowed = 1,
1919 .suite = {
1920 .aead = {
1921 .enc = {
1922 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
1923 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1924 },
1925 .dec = {
1926 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
1927 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1928 }
1929 }
1930 }
1931 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03001932 .alg = "authenc(hmac(sha1),cbc(aes))",
1933 .test = alg_test_aead,
1934 .fips_allowed = 1,
1935 .suite = {
1936 .aead = {
1937 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301938 .vecs =
1939 hmac_sha1_aes_cbc_enc_tv_temp,
1940 .count =
1941 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1942 }
1943 }
1944 }
1945 }, {
1946 .alg = "authenc(hmac(sha1),cbc(des))",
1947 .test = alg_test_aead,
1948 .fips_allowed = 1,
1949 .suite = {
1950 .aead = {
1951 .enc = {
1952 .vecs =
1953 hmac_sha1_des_cbc_enc_tv_temp,
1954 .count =
1955 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1956 }
1957 }
1958 }
1959 }, {
1960 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
1961 .test = alg_test_aead,
1962 .fips_allowed = 1,
1963 .suite = {
1964 .aead = {
1965 .enc = {
1966 .vecs =
1967 hmac_sha1_des3_ede_cbc_enc_tv_temp,
1968 .count =
1969 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03001970 }
1971 }
1972 }
1973 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001974 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
1975 .test = alg_test_aead,
1976 .fips_allowed = 1,
1977 .suite = {
1978 .aead = {
1979 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301980 .vecs =
1981 hmac_sha1_ecb_cipher_null_enc_tv_temp,
1982 .count =
1983 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02001984 },
1985 .dec = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301986 .vecs =
1987 hmac_sha1_ecb_cipher_null_dec_tv_temp,
1988 .count =
1989 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
1990 }
1991 }
1992 }
1993 }, {
1994 .alg = "authenc(hmac(sha224),cbc(des))",
1995 .test = alg_test_aead,
1996 .fips_allowed = 1,
1997 .suite = {
1998 .aead = {
1999 .enc = {
2000 .vecs =
2001 hmac_sha224_des_cbc_enc_tv_temp,
2002 .count =
2003 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2004 }
2005 }
2006 }
2007 }, {
2008 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
2009 .test = alg_test_aead,
2010 .fips_allowed = 1,
2011 .suite = {
2012 .aead = {
2013 .enc = {
2014 .vecs =
2015 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2016 .count =
2017 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002018 }
2019 }
2020 }
2021 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03002022 .alg = "authenc(hmac(sha256),cbc(aes))",
2023 .test = alg_test_aead,
2024 .fips_allowed = 1,
2025 .suite = {
2026 .aead = {
2027 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302028 .vecs =
2029 hmac_sha256_aes_cbc_enc_tv_temp,
2030 .count =
2031 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2032 }
2033 }
2034 }
2035 }, {
2036 .alg = "authenc(hmac(sha256),cbc(des))",
2037 .test = alg_test_aead,
2038 .fips_allowed = 1,
2039 .suite = {
2040 .aead = {
2041 .enc = {
2042 .vecs =
2043 hmac_sha256_des_cbc_enc_tv_temp,
2044 .count =
2045 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2046 }
2047 }
2048 }
2049 }, {
2050 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
2051 .test = alg_test_aead,
2052 .fips_allowed = 1,
2053 .suite = {
2054 .aead = {
2055 .enc = {
2056 .vecs =
2057 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2058 .count =
2059 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2060 }
2061 }
2062 }
2063 }, {
2064 .alg = "authenc(hmac(sha384),cbc(des))",
2065 .test = alg_test_aead,
2066 .fips_allowed = 1,
2067 .suite = {
2068 .aead = {
2069 .enc = {
2070 .vecs =
2071 hmac_sha384_des_cbc_enc_tv_temp,
2072 .count =
2073 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2074 }
2075 }
2076 }
2077 }, {
2078 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
2079 .test = alg_test_aead,
2080 .fips_allowed = 1,
2081 .suite = {
2082 .aead = {
2083 .enc = {
2084 .vecs =
2085 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2086 .count =
2087 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002088 }
2089 }
2090 }
2091 }, {
2092 .alg = "authenc(hmac(sha512),cbc(aes))",
2093 .test = alg_test_aead,
2094 .fips_allowed = 1,
2095 .suite = {
2096 .aead = {
2097 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302098 .vecs =
2099 hmac_sha512_aes_cbc_enc_tv_temp,
2100 .count =
2101 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2102 }
2103 }
2104 }
2105 }, {
2106 .alg = "authenc(hmac(sha512),cbc(des))",
2107 .test = alg_test_aead,
2108 .fips_allowed = 1,
2109 .suite = {
2110 .aead = {
2111 .enc = {
2112 .vecs =
2113 hmac_sha512_des_cbc_enc_tv_temp,
2114 .count =
2115 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2116 }
2117 }
2118 }
2119 }, {
2120 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2121 .test = alg_test_aead,
2122 .fips_allowed = 1,
2123 .suite = {
2124 .aead = {
2125 .enc = {
2126 .vecs =
2127 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2128 .count =
2129 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002130 }
2131 }
2132 }
2133 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002134 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002135 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002136 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002137 .suite = {
2138 .cipher = {
2139 .enc = {
2140 .vecs = aes_cbc_enc_tv_template,
2141 .count = AES_CBC_ENC_TEST_VECTORS
2142 },
2143 .dec = {
2144 .vecs = aes_cbc_dec_tv_template,
2145 .count = AES_CBC_DEC_TEST_VECTORS
2146 }
2147 }
2148 }
2149 }, {
2150 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002151 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002152 .suite = {
2153 .cipher = {
2154 .enc = {
2155 .vecs = anubis_cbc_enc_tv_template,
2156 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2157 },
2158 .dec = {
2159 .vecs = anubis_cbc_dec_tv_template,
2160 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2161 }
2162 }
2163 }
2164 }, {
2165 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002166 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002167 .suite = {
2168 .cipher = {
2169 .enc = {
2170 .vecs = bf_cbc_enc_tv_template,
2171 .count = BF_CBC_ENC_TEST_VECTORS
2172 },
2173 .dec = {
2174 .vecs = bf_cbc_dec_tv_template,
2175 .count = BF_CBC_DEC_TEST_VECTORS
2176 }
2177 }
2178 }
2179 }, {
2180 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002181 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002182 .suite = {
2183 .cipher = {
2184 .enc = {
2185 .vecs = camellia_cbc_enc_tv_template,
2186 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2187 },
2188 .dec = {
2189 .vecs = camellia_cbc_dec_tv_template,
2190 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2191 }
2192 }
2193 }
2194 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002195 .alg = "cbc(cast5)",
2196 .test = alg_test_skcipher,
2197 .suite = {
2198 .cipher = {
2199 .enc = {
2200 .vecs = cast5_cbc_enc_tv_template,
2201 .count = CAST5_CBC_ENC_TEST_VECTORS
2202 },
2203 .dec = {
2204 .vecs = cast5_cbc_dec_tv_template,
2205 .count = CAST5_CBC_DEC_TEST_VECTORS
2206 }
2207 }
2208 }
2209 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002210 .alg = "cbc(cast6)",
2211 .test = alg_test_skcipher,
2212 .suite = {
2213 .cipher = {
2214 .enc = {
2215 .vecs = cast6_cbc_enc_tv_template,
2216 .count = CAST6_CBC_ENC_TEST_VECTORS
2217 },
2218 .dec = {
2219 .vecs = cast6_cbc_dec_tv_template,
2220 .count = CAST6_CBC_DEC_TEST_VECTORS
2221 }
2222 }
2223 }
2224 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002225 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002226 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002227 .suite = {
2228 .cipher = {
2229 .enc = {
2230 .vecs = des_cbc_enc_tv_template,
2231 .count = DES_CBC_ENC_TEST_VECTORS
2232 },
2233 .dec = {
2234 .vecs = des_cbc_dec_tv_template,
2235 .count = DES_CBC_DEC_TEST_VECTORS
2236 }
2237 }
2238 }
2239 }, {
2240 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002241 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002242 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002243 .suite = {
2244 .cipher = {
2245 .enc = {
2246 .vecs = des3_ede_cbc_enc_tv_template,
2247 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2248 },
2249 .dec = {
2250 .vecs = des3_ede_cbc_dec_tv_template,
2251 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2252 }
2253 }
2254 }
2255 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002256 .alg = "cbc(serpent)",
2257 .test = alg_test_skcipher,
2258 .suite = {
2259 .cipher = {
2260 .enc = {
2261 .vecs = serpent_cbc_enc_tv_template,
2262 .count = SERPENT_CBC_ENC_TEST_VECTORS
2263 },
2264 .dec = {
2265 .vecs = serpent_cbc_dec_tv_template,
2266 .count = SERPENT_CBC_DEC_TEST_VECTORS
2267 }
2268 }
2269 }
2270 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002271 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002272 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002273 .suite = {
2274 .cipher = {
2275 .enc = {
2276 .vecs = tf_cbc_enc_tv_template,
2277 .count = TF_CBC_ENC_TEST_VECTORS
2278 },
2279 .dec = {
2280 .vecs = tf_cbc_dec_tv_template,
2281 .count = TF_CBC_DEC_TEST_VECTORS
2282 }
2283 }
2284 }
2285 }, {
2286 .alg = "ccm(aes)",
2287 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002288 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002289 .suite = {
2290 .aead = {
2291 .enc = {
2292 .vecs = aes_ccm_enc_tv_template,
2293 .count = AES_CCM_ENC_TEST_VECTORS
2294 },
2295 .dec = {
2296 .vecs = aes_ccm_dec_tv_template,
2297 .count = AES_CCM_DEC_TEST_VECTORS
2298 }
2299 }
2300 }
2301 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002302 .alg = "cmac(aes)",
2303 .test = alg_test_hash,
2304 .suite = {
2305 .hash = {
2306 .vecs = aes_cmac128_tv_template,
2307 .count = CMAC_AES_TEST_VECTORS
2308 }
2309 }
2310 }, {
2311 .alg = "cmac(des3_ede)",
2312 .test = alg_test_hash,
2313 .suite = {
2314 .hash = {
2315 .vecs = des3_ede_cmac64_tv_template,
2316 .count = CMAC_DES3_EDE_TEST_VECTORS
2317 }
2318 }
2319 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002320 .alg = "compress_null",
2321 .test = alg_test_null,
2322 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02002323 .alg = "crc32",
2324 .test = alg_test_hash,
2325 .suite = {
2326 .hash = {
2327 .vecs = crc32_tv_template,
2328 .count = CRC32_TEST_VECTORS
2329 }
2330 }
2331 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002332 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002333 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002334 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002335 .suite = {
2336 .hash = {
2337 .vecs = crc32c_tv_template,
2338 .count = CRC32C_TEST_VECTORS
2339 }
2340 }
2341 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002342 .alg = "crct10dif",
2343 .test = alg_test_hash,
2344 .fips_allowed = 1,
2345 .suite = {
2346 .hash = {
2347 .vecs = crct10dif_tv_template,
2348 .count = CRCT10DIF_TEST_VECTORS
2349 }
2350 }
2351 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002352 .alg = "cryptd(__driver-cbc-aes-aesni)",
2353 .test = alg_test_null,
2354 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002355 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002356 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2357 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002358 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002359 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2360 .test = alg_test_null,
2361 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002362 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2363 .test = alg_test_null,
2364 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002365 .alg = "cryptd(__driver-ecb-aes-aesni)",
2366 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002367 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002368 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002369 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2370 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002371 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002372 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2373 .test = alg_test_null,
2374 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002375 .alg = "cryptd(__driver-ecb-cast5-avx)",
2376 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002377 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002378 .alg = "cryptd(__driver-ecb-cast6-avx)",
2379 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002380 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002381 .alg = "cryptd(__driver-ecb-serpent-avx)",
2382 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002383 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002384 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2385 .test = alg_test_null,
2386 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002387 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2388 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002389 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002390 .alg = "cryptd(__driver-ecb-twofish-avx)",
2391 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002392 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002393 .alg = "cryptd(__driver-gcm-aes-aesni)",
2394 .test = alg_test_null,
2395 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002396 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002397 .alg = "cryptd(__ghash-pclmulqdqni)",
2398 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002399 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002400 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002401 .alg = "ctr(aes)",
2402 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002403 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002404 .suite = {
2405 .cipher = {
2406 .enc = {
2407 .vecs = aes_ctr_enc_tv_template,
2408 .count = AES_CTR_ENC_TEST_VECTORS
2409 },
2410 .dec = {
2411 .vecs = aes_ctr_dec_tv_template,
2412 .count = AES_CTR_DEC_TEST_VECTORS
2413 }
2414 }
2415 }
2416 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002417 .alg = "ctr(blowfish)",
2418 .test = alg_test_skcipher,
2419 .suite = {
2420 .cipher = {
2421 .enc = {
2422 .vecs = bf_ctr_enc_tv_template,
2423 .count = BF_CTR_ENC_TEST_VECTORS
2424 },
2425 .dec = {
2426 .vecs = bf_ctr_dec_tv_template,
2427 .count = BF_CTR_DEC_TEST_VECTORS
2428 }
2429 }
2430 }
2431 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002432 .alg = "ctr(camellia)",
2433 .test = alg_test_skcipher,
2434 .suite = {
2435 .cipher = {
2436 .enc = {
2437 .vecs = camellia_ctr_enc_tv_template,
2438 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2439 },
2440 .dec = {
2441 .vecs = camellia_ctr_dec_tv_template,
2442 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2443 }
2444 }
2445 }
2446 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002447 .alg = "ctr(cast5)",
2448 .test = alg_test_skcipher,
2449 .suite = {
2450 .cipher = {
2451 .enc = {
2452 .vecs = cast5_ctr_enc_tv_template,
2453 .count = CAST5_CTR_ENC_TEST_VECTORS
2454 },
2455 .dec = {
2456 .vecs = cast5_ctr_dec_tv_template,
2457 .count = CAST5_CTR_DEC_TEST_VECTORS
2458 }
2459 }
2460 }
2461 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002462 .alg = "ctr(cast6)",
2463 .test = alg_test_skcipher,
2464 .suite = {
2465 .cipher = {
2466 .enc = {
2467 .vecs = cast6_ctr_enc_tv_template,
2468 .count = CAST6_CTR_ENC_TEST_VECTORS
2469 },
2470 .dec = {
2471 .vecs = cast6_ctr_dec_tv_template,
2472 .count = CAST6_CTR_DEC_TEST_VECTORS
2473 }
2474 }
2475 }
2476 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002477 .alg = "ctr(des)",
2478 .test = alg_test_skcipher,
2479 .suite = {
2480 .cipher = {
2481 .enc = {
2482 .vecs = des_ctr_enc_tv_template,
2483 .count = DES_CTR_ENC_TEST_VECTORS
2484 },
2485 .dec = {
2486 .vecs = des_ctr_dec_tv_template,
2487 .count = DES_CTR_DEC_TEST_VECTORS
2488 }
2489 }
2490 }
2491 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002492 .alg = "ctr(des3_ede)",
2493 .test = alg_test_skcipher,
2494 .suite = {
2495 .cipher = {
2496 .enc = {
2497 .vecs = des3_ede_ctr_enc_tv_template,
2498 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2499 },
2500 .dec = {
2501 .vecs = des3_ede_ctr_dec_tv_template,
2502 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2503 }
2504 }
2505 }
2506 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002507 .alg = "ctr(serpent)",
2508 .test = alg_test_skcipher,
2509 .suite = {
2510 .cipher = {
2511 .enc = {
2512 .vecs = serpent_ctr_enc_tv_template,
2513 .count = SERPENT_CTR_ENC_TEST_VECTORS
2514 },
2515 .dec = {
2516 .vecs = serpent_ctr_dec_tv_template,
2517 .count = SERPENT_CTR_DEC_TEST_VECTORS
2518 }
2519 }
2520 }
2521 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002522 .alg = "ctr(twofish)",
2523 .test = alg_test_skcipher,
2524 .suite = {
2525 .cipher = {
2526 .enc = {
2527 .vecs = tf_ctr_enc_tv_template,
2528 .count = TF_CTR_ENC_TEST_VECTORS
2529 },
2530 .dec = {
2531 .vecs = tf_ctr_dec_tv_template,
2532 .count = TF_CTR_DEC_TEST_VECTORS
2533 }
2534 }
2535 }
2536 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002537 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002538 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002539 .suite = {
2540 .cipher = {
2541 .enc = {
2542 .vecs = cts_mode_enc_tv_template,
2543 .count = CTS_MODE_ENC_TEST_VECTORS
2544 },
2545 .dec = {
2546 .vecs = cts_mode_dec_tv_template,
2547 .count = CTS_MODE_DEC_TEST_VECTORS
2548 }
2549 }
2550 }
2551 }, {
2552 .alg = "deflate",
2553 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002554 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002555 .suite = {
2556 .comp = {
2557 .comp = {
2558 .vecs = deflate_comp_tv_template,
2559 .count = DEFLATE_COMP_TEST_VECTORS
2560 },
2561 .decomp = {
2562 .vecs = deflate_decomp_tv_template,
2563 .count = DEFLATE_DECOMP_TEST_VECTORS
2564 }
2565 }
2566 }
2567 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002568 .alg = "digest_null",
2569 .test = alg_test_null,
2570 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002571 .alg = "drbg_nopr_ctr_aes128",
2572 .test = alg_test_drbg,
2573 .fips_allowed = 1,
2574 .suite = {
2575 .drbg = {
2576 .vecs = drbg_nopr_ctr_aes128_tv_template,
2577 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2578 }
2579 }
2580 }, {
2581 .alg = "drbg_nopr_ctr_aes192",
2582 .test = alg_test_drbg,
2583 .fips_allowed = 1,
2584 .suite = {
2585 .drbg = {
2586 .vecs = drbg_nopr_ctr_aes192_tv_template,
2587 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2588 }
2589 }
2590 }, {
2591 .alg = "drbg_nopr_ctr_aes256",
2592 .test = alg_test_drbg,
2593 .fips_allowed = 1,
2594 .suite = {
2595 .drbg = {
2596 .vecs = drbg_nopr_ctr_aes256_tv_template,
2597 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2598 }
2599 }
2600 }, {
2601 /*
2602 * There is no need to specifically test the DRBG with every
2603 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2604 */
2605 .alg = "drbg_nopr_hmac_sha1",
2606 .fips_allowed = 1,
2607 .test = alg_test_null,
2608 }, {
2609 .alg = "drbg_nopr_hmac_sha256",
2610 .test = alg_test_drbg,
2611 .fips_allowed = 1,
2612 .suite = {
2613 .drbg = {
2614 .vecs = drbg_nopr_hmac_sha256_tv_template,
2615 .count =
2616 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2617 }
2618 }
2619 }, {
2620 /* covered by drbg_nopr_hmac_sha256 test */
2621 .alg = "drbg_nopr_hmac_sha384",
2622 .fips_allowed = 1,
2623 .test = alg_test_null,
2624 }, {
2625 .alg = "drbg_nopr_hmac_sha512",
2626 .test = alg_test_null,
2627 .fips_allowed = 1,
2628 }, {
2629 .alg = "drbg_nopr_sha1",
2630 .fips_allowed = 1,
2631 .test = alg_test_null,
2632 }, {
2633 .alg = "drbg_nopr_sha256",
2634 .test = alg_test_drbg,
2635 .fips_allowed = 1,
2636 .suite = {
2637 .drbg = {
2638 .vecs = drbg_nopr_sha256_tv_template,
2639 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2640 }
2641 }
2642 }, {
2643 /* covered by drbg_nopr_sha256 test */
2644 .alg = "drbg_nopr_sha384",
2645 .fips_allowed = 1,
2646 .test = alg_test_null,
2647 }, {
2648 .alg = "drbg_nopr_sha512",
2649 .fips_allowed = 1,
2650 .test = alg_test_null,
2651 }, {
2652 .alg = "drbg_pr_ctr_aes128",
2653 .test = alg_test_drbg,
2654 .fips_allowed = 1,
2655 .suite = {
2656 .drbg = {
2657 .vecs = drbg_pr_ctr_aes128_tv_template,
2658 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2659 }
2660 }
2661 }, {
2662 /* covered by drbg_pr_ctr_aes128 test */
2663 .alg = "drbg_pr_ctr_aes192",
2664 .fips_allowed = 1,
2665 .test = alg_test_null,
2666 }, {
2667 .alg = "drbg_pr_ctr_aes256",
2668 .fips_allowed = 1,
2669 .test = alg_test_null,
2670 }, {
2671 .alg = "drbg_pr_hmac_sha1",
2672 .fips_allowed = 1,
2673 .test = alg_test_null,
2674 }, {
2675 .alg = "drbg_pr_hmac_sha256",
2676 .test = alg_test_drbg,
2677 .fips_allowed = 1,
2678 .suite = {
2679 .drbg = {
2680 .vecs = drbg_pr_hmac_sha256_tv_template,
2681 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2682 }
2683 }
2684 }, {
2685 /* covered by drbg_pr_hmac_sha256 test */
2686 .alg = "drbg_pr_hmac_sha384",
2687 .fips_allowed = 1,
2688 .test = alg_test_null,
2689 }, {
2690 .alg = "drbg_pr_hmac_sha512",
2691 .test = alg_test_null,
2692 .fips_allowed = 1,
2693 }, {
2694 .alg = "drbg_pr_sha1",
2695 .fips_allowed = 1,
2696 .test = alg_test_null,
2697 }, {
2698 .alg = "drbg_pr_sha256",
2699 .test = alg_test_drbg,
2700 .fips_allowed = 1,
2701 .suite = {
2702 .drbg = {
2703 .vecs = drbg_pr_sha256_tv_template,
2704 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2705 }
2706 }
2707 }, {
2708 /* covered by drbg_pr_sha256 test */
2709 .alg = "drbg_pr_sha384",
2710 .fips_allowed = 1,
2711 .test = alg_test_null,
2712 }, {
2713 .alg = "drbg_pr_sha512",
2714 .fips_allowed = 1,
2715 .test = alg_test_null,
2716 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002717 .alg = "ecb(__aes-aesni)",
2718 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002719 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002720 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002721 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002722 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002723 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002724 .suite = {
2725 .cipher = {
2726 .enc = {
2727 .vecs = aes_enc_tv_template,
2728 .count = AES_ENC_TEST_VECTORS
2729 },
2730 .dec = {
2731 .vecs = aes_dec_tv_template,
2732 .count = AES_DEC_TEST_VECTORS
2733 }
2734 }
2735 }
2736 }, {
2737 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002738 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002739 .suite = {
2740 .cipher = {
2741 .enc = {
2742 .vecs = anubis_enc_tv_template,
2743 .count = ANUBIS_ENC_TEST_VECTORS
2744 },
2745 .dec = {
2746 .vecs = anubis_dec_tv_template,
2747 .count = ANUBIS_DEC_TEST_VECTORS
2748 }
2749 }
2750 }
2751 }, {
2752 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002753 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002754 .suite = {
2755 .cipher = {
2756 .enc = {
2757 .vecs = arc4_enc_tv_template,
2758 .count = ARC4_ENC_TEST_VECTORS
2759 },
2760 .dec = {
2761 .vecs = arc4_dec_tv_template,
2762 .count = ARC4_DEC_TEST_VECTORS
2763 }
2764 }
2765 }
2766 }, {
2767 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002768 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002769 .suite = {
2770 .cipher = {
2771 .enc = {
2772 .vecs = bf_enc_tv_template,
2773 .count = BF_ENC_TEST_VECTORS
2774 },
2775 .dec = {
2776 .vecs = bf_dec_tv_template,
2777 .count = BF_DEC_TEST_VECTORS
2778 }
2779 }
2780 }
2781 }, {
2782 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002783 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002784 .suite = {
2785 .cipher = {
2786 .enc = {
2787 .vecs = camellia_enc_tv_template,
2788 .count = CAMELLIA_ENC_TEST_VECTORS
2789 },
2790 .dec = {
2791 .vecs = camellia_dec_tv_template,
2792 .count = CAMELLIA_DEC_TEST_VECTORS
2793 }
2794 }
2795 }
2796 }, {
2797 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002798 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002799 .suite = {
2800 .cipher = {
2801 .enc = {
2802 .vecs = cast5_enc_tv_template,
2803 .count = CAST5_ENC_TEST_VECTORS
2804 },
2805 .dec = {
2806 .vecs = cast5_dec_tv_template,
2807 .count = CAST5_DEC_TEST_VECTORS
2808 }
2809 }
2810 }
2811 }, {
2812 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002813 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002814 .suite = {
2815 .cipher = {
2816 .enc = {
2817 .vecs = cast6_enc_tv_template,
2818 .count = CAST6_ENC_TEST_VECTORS
2819 },
2820 .dec = {
2821 .vecs = cast6_dec_tv_template,
2822 .count = CAST6_DEC_TEST_VECTORS
2823 }
2824 }
2825 }
2826 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002827 .alg = "ecb(cipher_null)",
2828 .test = alg_test_null,
2829 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002830 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002831 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002832 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002833 .suite = {
2834 .cipher = {
2835 .enc = {
2836 .vecs = des_enc_tv_template,
2837 .count = DES_ENC_TEST_VECTORS
2838 },
2839 .dec = {
2840 .vecs = des_dec_tv_template,
2841 .count = DES_DEC_TEST_VECTORS
2842 }
2843 }
2844 }
2845 }, {
2846 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002847 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002848 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002849 .suite = {
2850 .cipher = {
2851 .enc = {
2852 .vecs = des3_ede_enc_tv_template,
2853 .count = DES3_EDE_ENC_TEST_VECTORS
2854 },
2855 .dec = {
2856 .vecs = des3_ede_dec_tv_template,
2857 .count = DES3_EDE_DEC_TEST_VECTORS
2858 }
2859 }
2860 }
2861 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002862 .alg = "ecb(fcrypt)",
2863 .test = alg_test_skcipher,
2864 .suite = {
2865 .cipher = {
2866 .enc = {
2867 .vecs = fcrypt_pcbc_enc_tv_template,
2868 .count = 1
2869 },
2870 .dec = {
2871 .vecs = fcrypt_pcbc_dec_tv_template,
2872 .count = 1
2873 }
2874 }
2875 }
2876 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002877 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002878 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002879 .suite = {
2880 .cipher = {
2881 .enc = {
2882 .vecs = khazad_enc_tv_template,
2883 .count = KHAZAD_ENC_TEST_VECTORS
2884 },
2885 .dec = {
2886 .vecs = khazad_dec_tv_template,
2887 .count = KHAZAD_DEC_TEST_VECTORS
2888 }
2889 }
2890 }
2891 }, {
2892 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002893 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002894 .suite = {
2895 .cipher = {
2896 .enc = {
2897 .vecs = seed_enc_tv_template,
2898 .count = SEED_ENC_TEST_VECTORS
2899 },
2900 .dec = {
2901 .vecs = seed_dec_tv_template,
2902 .count = SEED_DEC_TEST_VECTORS
2903 }
2904 }
2905 }
2906 }, {
2907 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002908 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002909 .suite = {
2910 .cipher = {
2911 .enc = {
2912 .vecs = serpent_enc_tv_template,
2913 .count = SERPENT_ENC_TEST_VECTORS
2914 },
2915 .dec = {
2916 .vecs = serpent_dec_tv_template,
2917 .count = SERPENT_DEC_TEST_VECTORS
2918 }
2919 }
2920 }
2921 }, {
2922 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002923 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002924 .suite = {
2925 .cipher = {
2926 .enc = {
2927 .vecs = tea_enc_tv_template,
2928 .count = TEA_ENC_TEST_VECTORS
2929 },
2930 .dec = {
2931 .vecs = tea_dec_tv_template,
2932 .count = TEA_DEC_TEST_VECTORS
2933 }
2934 }
2935 }
2936 }, {
2937 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002938 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002939 .suite = {
2940 .cipher = {
2941 .enc = {
2942 .vecs = tnepres_enc_tv_template,
2943 .count = TNEPRES_ENC_TEST_VECTORS
2944 },
2945 .dec = {
2946 .vecs = tnepres_dec_tv_template,
2947 .count = TNEPRES_DEC_TEST_VECTORS
2948 }
2949 }
2950 }
2951 }, {
2952 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002953 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002954 .suite = {
2955 .cipher = {
2956 .enc = {
2957 .vecs = tf_enc_tv_template,
2958 .count = TF_ENC_TEST_VECTORS
2959 },
2960 .dec = {
2961 .vecs = tf_dec_tv_template,
2962 .count = TF_DEC_TEST_VECTORS
2963 }
2964 }
2965 }
2966 }, {
2967 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002968 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002969 .suite = {
2970 .cipher = {
2971 .enc = {
2972 .vecs = xeta_enc_tv_template,
2973 .count = XETA_ENC_TEST_VECTORS
2974 },
2975 .dec = {
2976 .vecs = xeta_dec_tv_template,
2977 .count = XETA_DEC_TEST_VECTORS
2978 }
2979 }
2980 }
2981 }, {
2982 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002983 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002984 .suite = {
2985 .cipher = {
2986 .enc = {
2987 .vecs = xtea_enc_tv_template,
2988 .count = XTEA_ENC_TEST_VECTORS
2989 },
2990 .dec = {
2991 .vecs = xtea_dec_tv_template,
2992 .count = XTEA_DEC_TEST_VECTORS
2993 }
2994 }
2995 }
2996 }, {
2997 .alg = "gcm(aes)",
2998 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002999 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003000 .suite = {
3001 .aead = {
3002 .enc = {
3003 .vecs = aes_gcm_enc_tv_template,
3004 .count = AES_GCM_ENC_TEST_VECTORS
3005 },
3006 .dec = {
3007 .vecs = aes_gcm_dec_tv_template,
3008 .count = AES_GCM_DEC_TEST_VECTORS
3009 }
3010 }
3011 }
3012 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003013 .alg = "ghash",
3014 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003015 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003016 .suite = {
3017 .hash = {
3018 .vecs = ghash_tv_template,
3019 .count = GHASH_TEST_VECTORS
3020 }
3021 }
3022 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003023 .alg = "hmac(crc32)",
3024 .test = alg_test_hash,
3025 .suite = {
3026 .hash = {
3027 .vecs = bfin_crc_tv_template,
3028 .count = BFIN_CRC_TEST_VECTORS
3029 }
3030 }
3031 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003032 .alg = "hmac(md5)",
3033 .test = alg_test_hash,
3034 .suite = {
3035 .hash = {
3036 .vecs = hmac_md5_tv_template,
3037 .count = HMAC_MD5_TEST_VECTORS
3038 }
3039 }
3040 }, {
3041 .alg = "hmac(rmd128)",
3042 .test = alg_test_hash,
3043 .suite = {
3044 .hash = {
3045 .vecs = hmac_rmd128_tv_template,
3046 .count = HMAC_RMD128_TEST_VECTORS
3047 }
3048 }
3049 }, {
3050 .alg = "hmac(rmd160)",
3051 .test = alg_test_hash,
3052 .suite = {
3053 .hash = {
3054 .vecs = hmac_rmd160_tv_template,
3055 .count = HMAC_RMD160_TEST_VECTORS
3056 }
3057 }
3058 }, {
3059 .alg = "hmac(sha1)",
3060 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003061 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003062 .suite = {
3063 .hash = {
3064 .vecs = hmac_sha1_tv_template,
3065 .count = HMAC_SHA1_TEST_VECTORS
3066 }
3067 }
3068 }, {
3069 .alg = "hmac(sha224)",
3070 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003071 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003072 .suite = {
3073 .hash = {
3074 .vecs = hmac_sha224_tv_template,
3075 .count = HMAC_SHA224_TEST_VECTORS
3076 }
3077 }
3078 }, {
3079 .alg = "hmac(sha256)",
3080 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003081 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003082 .suite = {
3083 .hash = {
3084 .vecs = hmac_sha256_tv_template,
3085 .count = HMAC_SHA256_TEST_VECTORS
3086 }
3087 }
3088 }, {
3089 .alg = "hmac(sha384)",
3090 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003091 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003092 .suite = {
3093 .hash = {
3094 .vecs = hmac_sha384_tv_template,
3095 .count = HMAC_SHA384_TEST_VECTORS
3096 }
3097 }
3098 }, {
3099 .alg = "hmac(sha512)",
3100 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003101 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003102 .suite = {
3103 .hash = {
3104 .vecs = hmac_sha512_tv_template,
3105 .count = HMAC_SHA512_TEST_VECTORS
3106 }
3107 }
3108 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003109 .alg = "jitterentropy_rng",
3110 .fips_allowed = 1,
3111 .test = alg_test_null,
3112 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003113 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003114 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003115 .suite = {
3116 .cipher = {
3117 .enc = {
3118 .vecs = aes_lrw_enc_tv_template,
3119 .count = AES_LRW_ENC_TEST_VECTORS
3120 },
3121 .dec = {
3122 .vecs = aes_lrw_dec_tv_template,
3123 .count = AES_LRW_DEC_TEST_VECTORS
3124 }
3125 }
3126 }
3127 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003128 .alg = "lrw(camellia)",
3129 .test = alg_test_skcipher,
3130 .suite = {
3131 .cipher = {
3132 .enc = {
3133 .vecs = camellia_lrw_enc_tv_template,
3134 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3135 },
3136 .dec = {
3137 .vecs = camellia_lrw_dec_tv_template,
3138 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3139 }
3140 }
3141 }
3142 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003143 .alg = "lrw(cast6)",
3144 .test = alg_test_skcipher,
3145 .suite = {
3146 .cipher = {
3147 .enc = {
3148 .vecs = cast6_lrw_enc_tv_template,
3149 .count = CAST6_LRW_ENC_TEST_VECTORS
3150 },
3151 .dec = {
3152 .vecs = cast6_lrw_dec_tv_template,
3153 .count = CAST6_LRW_DEC_TEST_VECTORS
3154 }
3155 }
3156 }
3157 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003158 .alg = "lrw(serpent)",
3159 .test = alg_test_skcipher,
3160 .suite = {
3161 .cipher = {
3162 .enc = {
3163 .vecs = serpent_lrw_enc_tv_template,
3164 .count = SERPENT_LRW_ENC_TEST_VECTORS
3165 },
3166 .dec = {
3167 .vecs = serpent_lrw_dec_tv_template,
3168 .count = SERPENT_LRW_DEC_TEST_VECTORS
3169 }
3170 }
3171 }
3172 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003173 .alg = "lrw(twofish)",
3174 .test = alg_test_skcipher,
3175 .suite = {
3176 .cipher = {
3177 .enc = {
3178 .vecs = tf_lrw_enc_tv_template,
3179 .count = TF_LRW_ENC_TEST_VECTORS
3180 },
3181 .dec = {
3182 .vecs = tf_lrw_dec_tv_template,
3183 .count = TF_LRW_DEC_TEST_VECTORS
3184 }
3185 }
3186 }
3187 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003188 .alg = "lz4",
3189 .test = alg_test_comp,
3190 .fips_allowed = 1,
3191 .suite = {
3192 .comp = {
3193 .comp = {
3194 .vecs = lz4_comp_tv_template,
3195 .count = LZ4_COMP_TEST_VECTORS
3196 },
3197 .decomp = {
3198 .vecs = lz4_decomp_tv_template,
3199 .count = LZ4_DECOMP_TEST_VECTORS
3200 }
3201 }
3202 }
3203 }, {
3204 .alg = "lz4hc",
3205 .test = alg_test_comp,
3206 .fips_allowed = 1,
3207 .suite = {
3208 .comp = {
3209 .comp = {
3210 .vecs = lz4hc_comp_tv_template,
3211 .count = LZ4HC_COMP_TEST_VECTORS
3212 },
3213 .decomp = {
3214 .vecs = lz4hc_decomp_tv_template,
3215 .count = LZ4HC_DECOMP_TEST_VECTORS
3216 }
3217 }
3218 }
3219 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003220 .alg = "lzo",
3221 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003222 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003223 .suite = {
3224 .comp = {
3225 .comp = {
3226 .vecs = lzo_comp_tv_template,
3227 .count = LZO_COMP_TEST_VECTORS
3228 },
3229 .decomp = {
3230 .vecs = lzo_decomp_tv_template,
3231 .count = LZO_DECOMP_TEST_VECTORS
3232 }
3233 }
3234 }
3235 }, {
3236 .alg = "md4",
3237 .test = alg_test_hash,
3238 .suite = {
3239 .hash = {
3240 .vecs = md4_tv_template,
3241 .count = MD4_TEST_VECTORS
3242 }
3243 }
3244 }, {
3245 .alg = "md5",
3246 .test = alg_test_hash,
3247 .suite = {
3248 .hash = {
3249 .vecs = md5_tv_template,
3250 .count = MD5_TEST_VECTORS
3251 }
3252 }
3253 }, {
3254 .alg = "michael_mic",
3255 .test = alg_test_hash,
3256 .suite = {
3257 .hash = {
3258 .vecs = michael_mic_tv_template,
3259 .count = MICHAEL_MIC_TEST_VECTORS
3260 }
3261 }
3262 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003263 .alg = "ofb(aes)",
3264 .test = alg_test_skcipher,
3265 .fips_allowed = 1,
3266 .suite = {
3267 .cipher = {
3268 .enc = {
3269 .vecs = aes_ofb_enc_tv_template,
3270 .count = AES_OFB_ENC_TEST_VECTORS
3271 },
3272 .dec = {
3273 .vecs = aes_ofb_dec_tv_template,
3274 .count = AES_OFB_DEC_TEST_VECTORS
3275 }
3276 }
3277 }
3278 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003279 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003280 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003281 .suite = {
3282 .cipher = {
3283 .enc = {
3284 .vecs = fcrypt_pcbc_enc_tv_template,
3285 .count = FCRYPT_ENC_TEST_VECTORS
3286 },
3287 .dec = {
3288 .vecs = fcrypt_pcbc_dec_tv_template,
3289 .count = FCRYPT_DEC_TEST_VECTORS
3290 }
3291 }
3292 }
3293 }, {
3294 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003295 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003296 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003297 .suite = {
3298 .cipher = {
3299 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003300 .vecs = aes_ctr_rfc3686_enc_tv_template,
3301 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003302 },
3303 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003304 .vecs = aes_ctr_rfc3686_dec_tv_template,
3305 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003306 }
3307 }
3308 }
3309 }, {
Adrian Hoban69435b92010-11-04 15:02:04 -04003310 .alg = "rfc4106(gcm(aes))",
3311 .test = alg_test_aead,
Jarod Wilsondb71f29a2015-01-23 12:42:15 -05003312 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003313 .suite = {
3314 .aead = {
3315 .enc = {
3316 .vecs = aes_gcm_rfc4106_enc_tv_template,
3317 .count = AES_GCM_4106_ENC_TEST_VECTORS
3318 },
3319 .dec = {
3320 .vecs = aes_gcm_rfc4106_dec_tv_template,
3321 .count = AES_GCM_4106_DEC_TEST_VECTORS
3322 }
3323 }
3324 }
3325 }, {
Jarod Wilson5d667322009-05-04 19:23:40 +08003326 .alg = "rfc4309(ccm(aes))",
3327 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003328 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003329 .suite = {
3330 .aead = {
3331 .enc = {
3332 .vecs = aes_ccm_rfc4309_enc_tv_template,
3333 .count = AES_CCM_4309_ENC_TEST_VECTORS
3334 },
3335 .dec = {
3336 .vecs = aes_ccm_rfc4309_dec_tv_template,
3337 .count = AES_CCM_4309_DEC_TEST_VECTORS
3338 }
3339 }
3340 }
3341 }, {
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003342 .alg = "rfc4543(gcm(aes))",
3343 .test = alg_test_aead,
3344 .suite = {
3345 .aead = {
3346 .enc = {
3347 .vecs = aes_gcm_rfc4543_enc_tv_template,
3348 .count = AES_GCM_4543_ENC_TEST_VECTORS
3349 },
3350 .dec = {
3351 .vecs = aes_gcm_rfc4543_dec_tv_template,
3352 .count = AES_GCM_4543_DEC_TEST_VECTORS
3353 },
3354 }
3355 }
3356 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003357 .alg = "rmd128",
3358 .test = alg_test_hash,
3359 .suite = {
3360 .hash = {
3361 .vecs = rmd128_tv_template,
3362 .count = RMD128_TEST_VECTORS
3363 }
3364 }
3365 }, {
3366 .alg = "rmd160",
3367 .test = alg_test_hash,
3368 .suite = {
3369 .hash = {
3370 .vecs = rmd160_tv_template,
3371 .count = RMD160_TEST_VECTORS
3372 }
3373 }
3374 }, {
3375 .alg = "rmd256",
3376 .test = alg_test_hash,
3377 .suite = {
3378 .hash = {
3379 .vecs = rmd256_tv_template,
3380 .count = RMD256_TEST_VECTORS
3381 }
3382 }
3383 }, {
3384 .alg = "rmd320",
3385 .test = alg_test_hash,
3386 .suite = {
3387 .hash = {
3388 .vecs = rmd320_tv_template,
3389 .count = RMD320_TEST_VECTORS
3390 }
3391 }
3392 }, {
3393 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003394 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003395 .suite = {
3396 .cipher = {
3397 .enc = {
3398 .vecs = salsa20_stream_enc_tv_template,
3399 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3400 }
3401 }
3402 }
3403 }, {
3404 .alg = "sha1",
3405 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003406 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003407 .suite = {
3408 .hash = {
3409 .vecs = sha1_tv_template,
3410 .count = SHA1_TEST_VECTORS
3411 }
3412 }
3413 }, {
3414 .alg = "sha224",
3415 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003416 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003417 .suite = {
3418 .hash = {
3419 .vecs = sha224_tv_template,
3420 .count = SHA224_TEST_VECTORS
3421 }
3422 }
3423 }, {
3424 .alg = "sha256",
3425 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003426 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003427 .suite = {
3428 .hash = {
3429 .vecs = sha256_tv_template,
3430 .count = SHA256_TEST_VECTORS
3431 }
3432 }
3433 }, {
3434 .alg = "sha384",
3435 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003436 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003437 .suite = {
3438 .hash = {
3439 .vecs = sha384_tv_template,
3440 .count = SHA384_TEST_VECTORS
3441 }
3442 }
3443 }, {
3444 .alg = "sha512",
3445 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003446 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003447 .suite = {
3448 .hash = {
3449 .vecs = sha512_tv_template,
3450 .count = SHA512_TEST_VECTORS
3451 }
3452 }
3453 }, {
3454 .alg = "tgr128",
3455 .test = alg_test_hash,
3456 .suite = {
3457 .hash = {
3458 .vecs = tgr128_tv_template,
3459 .count = TGR128_TEST_VECTORS
3460 }
3461 }
3462 }, {
3463 .alg = "tgr160",
3464 .test = alg_test_hash,
3465 .suite = {
3466 .hash = {
3467 .vecs = tgr160_tv_template,
3468 .count = TGR160_TEST_VECTORS
3469 }
3470 }
3471 }, {
3472 .alg = "tgr192",
3473 .test = alg_test_hash,
3474 .suite = {
3475 .hash = {
3476 .vecs = tgr192_tv_template,
3477 .count = TGR192_TEST_VECTORS
3478 }
3479 }
3480 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003481 .alg = "vmac(aes)",
3482 .test = alg_test_hash,
3483 .suite = {
3484 .hash = {
3485 .vecs = aes_vmac128_tv_template,
3486 .count = VMAC_AES_TEST_VECTORS
3487 }
3488 }
3489 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003490 .alg = "wp256",
3491 .test = alg_test_hash,
3492 .suite = {
3493 .hash = {
3494 .vecs = wp256_tv_template,
3495 .count = WP256_TEST_VECTORS
3496 }
3497 }
3498 }, {
3499 .alg = "wp384",
3500 .test = alg_test_hash,
3501 .suite = {
3502 .hash = {
3503 .vecs = wp384_tv_template,
3504 .count = WP384_TEST_VECTORS
3505 }
3506 }
3507 }, {
3508 .alg = "wp512",
3509 .test = alg_test_hash,
3510 .suite = {
3511 .hash = {
3512 .vecs = wp512_tv_template,
3513 .count = WP512_TEST_VECTORS
3514 }
3515 }
3516 }, {
3517 .alg = "xcbc(aes)",
3518 .test = alg_test_hash,
3519 .suite = {
3520 .hash = {
3521 .vecs = aes_xcbc128_tv_template,
3522 .count = XCBC_AES_TEST_VECTORS
3523 }
3524 }
3525 }, {
3526 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003527 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003528 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003529 .suite = {
3530 .cipher = {
3531 .enc = {
3532 .vecs = aes_xts_enc_tv_template,
3533 .count = AES_XTS_ENC_TEST_VECTORS
3534 },
3535 .dec = {
3536 .vecs = aes_xts_dec_tv_template,
3537 .count = AES_XTS_DEC_TEST_VECTORS
3538 }
3539 }
3540 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003541 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003542 .alg = "xts(camellia)",
3543 .test = alg_test_skcipher,
3544 .suite = {
3545 .cipher = {
3546 .enc = {
3547 .vecs = camellia_xts_enc_tv_template,
3548 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3549 },
3550 .dec = {
3551 .vecs = camellia_xts_dec_tv_template,
3552 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3553 }
3554 }
3555 }
3556 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003557 .alg = "xts(cast6)",
3558 .test = alg_test_skcipher,
3559 .suite = {
3560 .cipher = {
3561 .enc = {
3562 .vecs = cast6_xts_enc_tv_template,
3563 .count = CAST6_XTS_ENC_TEST_VECTORS
3564 },
3565 .dec = {
3566 .vecs = cast6_xts_dec_tv_template,
3567 .count = CAST6_XTS_DEC_TEST_VECTORS
3568 }
3569 }
3570 }
3571 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003572 .alg = "xts(serpent)",
3573 .test = alg_test_skcipher,
3574 .suite = {
3575 .cipher = {
3576 .enc = {
3577 .vecs = serpent_xts_enc_tv_template,
3578 .count = SERPENT_XTS_ENC_TEST_VECTORS
3579 },
3580 .dec = {
3581 .vecs = serpent_xts_dec_tv_template,
3582 .count = SERPENT_XTS_DEC_TEST_VECTORS
3583 }
3584 }
3585 }
3586 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003587 .alg = "xts(twofish)",
3588 .test = alg_test_skcipher,
3589 .suite = {
3590 .cipher = {
3591 .enc = {
3592 .vecs = tf_xts_enc_tv_template,
3593 .count = TF_XTS_ENC_TEST_VECTORS
3594 },
3595 .dec = {
3596 .vecs = tf_xts_dec_tv_template,
3597 .count = TF_XTS_DEC_TEST_VECTORS
3598 }
3599 }
3600 }
3601 }, {
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003602 .alg = "zlib",
3603 .test = alg_test_pcomp,
Milan Broz08189042012-12-06 17:16:28 +08003604 .fips_allowed = 1,
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003605 .suite = {
3606 .pcomp = {
3607 .comp = {
3608 .vecs = zlib_comp_tv_template,
3609 .count = ZLIB_COMP_TEST_VECTORS
3610 },
3611 .decomp = {
3612 .vecs = zlib_decomp_tv_template,
3613 .count = ZLIB_DECOMP_TEST_VECTORS
3614 }
3615 }
3616 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003617 }
3618};
3619
Jussi Kivilinna57147582013-06-13 17:37:40 +03003620static bool alg_test_descs_checked;
3621
3622static void alg_test_descs_check_order(void)
3623{
3624 int i;
3625
3626 /* only check once */
3627 if (alg_test_descs_checked)
3628 return;
3629
3630 alg_test_descs_checked = true;
3631
3632 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3633 int diff = strcmp(alg_test_descs[i - 1].alg,
3634 alg_test_descs[i].alg);
3635
3636 if (WARN_ON(diff > 0)) {
3637 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3638 alg_test_descs[i - 1].alg,
3639 alg_test_descs[i].alg);
3640 }
3641
3642 if (WARN_ON(diff == 0)) {
3643 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3644 alg_test_descs[i].alg);
3645 }
3646 }
3647}
3648
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003649static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003650{
3651 int start = 0;
3652 int end = ARRAY_SIZE(alg_test_descs);
3653
3654 while (start < end) {
3655 int i = (start + end) / 2;
3656 int diff = strcmp(alg_test_descs[i].alg, alg);
3657
3658 if (diff > 0) {
3659 end = i;
3660 continue;
3661 }
3662
3663 if (diff < 0) {
3664 start = i + 1;
3665 continue;
3666 }
3667
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003668 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003669 }
3670
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003671 return -1;
3672}
3673
3674int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3675{
3676 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003677 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003678 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003679
Jussi Kivilinna57147582013-06-13 17:37:40 +03003680 alg_test_descs_check_order();
3681
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003682 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3683 char nalg[CRYPTO_MAX_ALG_NAME];
3684
3685 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3686 sizeof(nalg))
3687 return -ENAMETOOLONG;
3688
3689 i = alg_find_test(nalg);
3690 if (i < 0)
3691 goto notest;
3692
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003693 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3694 goto non_fips_alg;
3695
Jarod Wilson941fb322009-05-04 19:49:23 +08003696 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3697 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003698 }
3699
3700 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003701 j = alg_find_test(driver);
3702 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003703 goto notest;
3704
Herbert Xua68f6612009-07-02 16:32:12 +08003705 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3706 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003707 goto non_fips_alg;
3708
Herbert Xua68f6612009-07-02 16:32:12 +08003709 rc = 0;
3710 if (i >= 0)
3711 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3712 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003713 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003714 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3715 type, mask);
3716
Jarod Wilson941fb322009-05-04 19:49:23 +08003717test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003718 if (fips_enabled && rc)
3719 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3720
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003721 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09003722 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003723
Neil Hormand12d6b62008-10-12 20:36:51 +08003724 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003725
3726notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003727 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3728 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003729non_fips_alg:
3730 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003731}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003732
Herbert Xu326a6342010-08-06 09:40:28 +08003733#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003734
Herbert Xuda7f0332008-07-31 17:08:25 +08003735EXPORT_SYMBOL_GPL(alg_test);