blob: 009714da5b931cf72589af0fd48bba226281f7fe [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;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300430 struct scatterlist *sgout;
431 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800432 struct tcrypt_result result;
Cristian Stoica424a5da2015-01-28 11:03:05 +0200433 unsigned int authsize, iv_len;
Herbert Xuda7f0332008-07-31 17:08:25 +0800434 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300435 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800436 void *assoc;
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700437 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800438 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300439 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800440 char *axbuf[XBUFSIZE];
441
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700442 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
443 if (!iv)
444 return ret;
Horia Geanta29b77e52014-07-23 11:59:38 +0300445 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
446 if (!key)
447 goto out_noxbuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800448 if (testmgr_alloc_buf(xbuf))
449 goto out_noxbuf;
450 if (testmgr_alloc_buf(axbuf))
451 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300452 if (diff_dst && testmgr_alloc_buf(xoutbuf))
453 goto out_nooutbuf;
454
455 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
Herbert Xu8a525fc2015-05-27 16:03:43 +0800456 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 4 : 2), GFP_KERNEL);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300457 if (!sg)
458 goto out_nosg;
Herbert Xu8a525fc2015-05-27 16:03:43 +0800459 sgout = &sg[16];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300460
461 if (diff_dst)
462 d = "-ddst";
463 else
464 d = "";
465
Herbert Xuda7f0332008-07-31 17:08:25 +0800466 if (enc == ENCRYPT)
467 e = "encryption";
468 else
469 e = "decryption";
470
471 init_completion(&result.completion);
472
473 req = aead_request_alloc(tfm, GFP_KERNEL);
474 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300475 pr_err("alg: aead%s: Failed to allocate request for %s\n",
476 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800477 goto out;
478 }
479
480 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
481 tcrypt_complete, &result);
482
483 for (i = 0, j = 0; i < tcount; i++) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300484 if (template[i].np)
485 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800486
Cristian Stoica05b1d332014-07-28 13:11:23 +0300487 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800488
Cristian Stoica05b1d332014-07-28 13:11:23 +0300489 /* some templates have no input data but they will
490 * touch input
491 */
492 input = xbuf[0];
493 input += align_offset;
494 assoc = axbuf[0];
495
496 ret = -EINVAL;
497 if (WARN_ON(align_offset + template[i].ilen >
498 PAGE_SIZE || template[i].alen > PAGE_SIZE))
499 goto out;
500
501 memcpy(input, template[i].input, template[i].ilen);
502 memcpy(assoc, template[i].assoc, template[i].alen);
Cristian Stoica424a5da2015-01-28 11:03:05 +0200503 iv_len = crypto_aead_ivsize(tfm);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300504 if (template[i].iv)
Cristian Stoica424a5da2015-01-28 11:03:05 +0200505 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300506 else
Cristian Stoica424a5da2015-01-28 11:03:05 +0200507 memset(iv, 0, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300508
509 crypto_aead_clear_flags(tfm, ~0);
510 if (template[i].wk)
511 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
512
513 if (template[i].klen > MAX_KEYLEN) {
514 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
515 d, j, algo, template[i].klen,
516 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +1000517 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300518 goto out;
519 }
520 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +1000521
Cristian Stoica05b1d332014-07-28 13:11:23 +0300522 ret = crypto_aead_setkey(tfm, key, template[i].klen);
523 if (!ret == template[i].fail) {
524 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
525 d, j, algo, crypto_aead_get_flags(tfm));
526 goto out;
527 } else if (ret)
528 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800529
Cristian Stoica05b1d332014-07-28 13:11:23 +0300530 authsize = abs(template[i].rlen - template[i].ilen);
531 ret = crypto_aead_setauthsize(tfm, authsize);
532 if (ret) {
533 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
534 d, authsize, j, algo);
535 goto out;
536 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800537
Herbert Xu8a525fc2015-05-27 16:03:43 +0800538 k = !!template[i].alen;
539 sg_init_table(sg, k + 1);
540 sg_set_buf(&sg[0], assoc, template[i].alen);
541 sg_set_buf(&sg[k], input,
542 template[i].ilen + (enc ? authsize : 0));
543 output = input;
544
Cristian Stoica05b1d332014-07-28 13:11:23 +0300545 if (diff_dst) {
Herbert Xu8a525fc2015-05-27 16:03:43 +0800546 sg_init_table(sgout, k + 1);
547 sg_set_buf(&sgout[0], assoc, template[i].alen);
548
Cristian Stoica05b1d332014-07-28 13:11:23 +0300549 output = xoutbuf[0];
550 output += align_offset;
Herbert Xu8a525fc2015-05-27 16:03:43 +0800551 sg_set_buf(&sgout[k], output,
552 template[i].rlen + (enc ? 0 : authsize));
Cristian Stoica05b1d332014-07-28 13:11:23 +0300553 }
554
Cristian Stoica05b1d332014-07-28 13:11:23 +0300555 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
556 template[i].ilen, iv);
557
Herbert Xu8a525fc2015-05-27 16:03:43 +0800558 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300559
560 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
561
562 switch (ret) {
563 case 0:
564 if (template[i].novrfy) {
565 /* verification was supposed to fail */
566 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
567 d, e, j, algo);
568 /* so really, we got a bad message */
569 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +0300570 goto out;
571 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300572 break;
573 case -EINPROGRESS:
574 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100575 wait_for_completion(&result.completion);
576 reinit_completion(&result.completion);
577 ret = result.err;
578 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +0800579 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300580 case -EBADMSG:
581 if (template[i].novrfy)
582 /* verification failure was expected */
583 continue;
584 /* fall through */
585 default:
586 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
587 d, e, j, algo, -ret);
588 goto out;
589 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800590
Cristian Stoica05b1d332014-07-28 13:11:23 +0300591 q = output;
592 if (memcmp(q, template[i].result, template[i].rlen)) {
593 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
594 d, j, e, algo);
595 hexdump(q, template[i].rlen);
596 ret = -EINVAL;
597 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800598 }
599 }
600
601 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300602 /* alignment tests are only done with continuous buffers */
603 if (align_offset != 0)
604 break;
605
Cristian Stoica05b1d332014-07-28 13:11:23 +0300606 if (!template[i].np)
607 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800608
Cristian Stoica05b1d332014-07-28 13:11:23 +0300609 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800610
Cristian Stoica05b1d332014-07-28 13:11:23 +0300611 if (template[i].iv)
612 memcpy(iv, template[i].iv, MAX_IVLEN);
613 else
614 memset(iv, 0, MAX_IVLEN);
615
616 crypto_aead_clear_flags(tfm, ~0);
617 if (template[i].wk)
618 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
619 if (template[i].klen > MAX_KEYLEN) {
620 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
621 d, j, algo, template[i].klen, MAX_KEYLEN);
622 ret = -EINVAL;
623 goto out;
624 }
625 memcpy(key, template[i].key, template[i].klen);
626
627 ret = crypto_aead_setkey(tfm, key, template[i].klen);
628 if (!ret == template[i].fail) {
629 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
630 d, j, algo, crypto_aead_get_flags(tfm));
631 goto out;
632 } else if (ret)
633 continue;
634
635 authsize = abs(template[i].rlen - template[i].ilen);
636
637 ret = -EINVAL;
Herbert Xu8a525fc2015-05-27 16:03:43 +0800638 sg_init_table(sg, template[i].anp + template[i].np);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300639 if (diff_dst)
Herbert Xu8a525fc2015-05-27 16:03:43 +0800640 sg_init_table(sgout, template[i].anp + template[i].np);
641
642 ret = -EINVAL;
643 for (k = 0, temp = 0; k < template[i].anp; k++) {
644 if (WARN_ON(offset_in_page(IDX[k]) +
645 template[i].atap[k] > PAGE_SIZE))
646 goto out;
647 sg_set_buf(&sg[k],
648 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
649 offset_in_page(IDX[k]),
650 template[i].assoc + temp,
651 template[i].atap[k]),
652 template[i].atap[k]);
653 if (diff_dst)
654 sg_set_buf(&sgout[k],
655 axbuf[IDX[k] >> PAGE_SHIFT] +
656 offset_in_page(IDX[k]),
657 template[i].atap[k]);
658 temp += template[i].atap[k];
659 }
660
Cristian Stoica05b1d332014-07-28 13:11:23 +0300661 for (k = 0, temp = 0; k < template[i].np; k++) {
662 if (WARN_ON(offset_in_page(IDX[k]) +
663 template[i].tap[k] > PAGE_SIZE))
664 goto out;
665
666 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
667 memcpy(q, template[i].input + temp, template[i].tap[k]);
Herbert Xu8a525fc2015-05-27 16:03:43 +0800668 sg_set_buf(&sg[template[i].anp + k],
669 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300670
671 if (diff_dst) {
672 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
673 offset_in_page(IDX[k]);
674
675 memset(q, 0, template[i].tap[k]);
676
Herbert Xu8a525fc2015-05-27 16:03:43 +0800677 sg_set_buf(&sgout[template[i].anp + k],
678 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300679 }
680
681 n = template[i].tap[k];
682 if (k == template[i].np - 1 && enc)
683 n += authsize;
684 if (offset_in_page(q) + n < PAGE_SIZE)
685 q[n] = 0;
686
687 temp += template[i].tap[k];
688 }
689
690 ret = crypto_aead_setauthsize(tfm, authsize);
691 if (ret) {
692 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
693 d, authsize, j, algo);
694 goto out;
695 }
696
697 if (enc) {
Herbert Xu8a525fc2015-05-27 16:03:43 +0800698 if (WARN_ON(sg[template[i].anp + k - 1].offset +
699 sg[template[i].anp + k - 1].length +
700 authsize > PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300701 ret = -EINVAL;
702 goto out;
703 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800704
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300705 if (diff_dst)
Herbert Xu8a525fc2015-05-27 16:03:43 +0800706 sgout[template[i].anp + k - 1].length +=
707 authsize;
708 sg[template[i].anp + k - 1].length += authsize;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300709 }
710
711 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
712 template[i].ilen,
713 iv);
714
Herbert Xu8a525fc2015-05-27 16:03:43 +0800715 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300716
717 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
718
719 switch (ret) {
720 case 0:
721 if (template[i].novrfy) {
722 /* verification was supposed to fail */
723 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
724 d, e, j, algo);
725 /* so really, we got a bad message */
726 ret = -EBADMSG;
727 goto out;
728 }
729 break;
730 case -EINPROGRESS:
731 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100732 wait_for_completion(&result.completion);
733 reinit_completion(&result.completion);
734 ret = result.err;
735 if (!ret)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300736 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300737 case -EBADMSG:
738 if (template[i].novrfy)
739 /* verification failure was expected */
740 continue;
741 /* fall through */
742 default:
743 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
744 d, e, j, algo, -ret);
745 goto out;
746 }
747
748 ret = -EINVAL;
749 for (k = 0, temp = 0; k < template[i].np; k++) {
750 if (diff_dst)
751 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
752 offset_in_page(IDX[k]);
753 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800754 q = xbuf[IDX[k] >> PAGE_SHIFT] +
755 offset_in_page(IDX[k]);
756
Cristian Stoica05b1d332014-07-28 13:11:23 +0300757 n = template[i].tap[k];
758 if (k == template[i].np - 1)
759 n += enc ? authsize : -authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800760
Cristian Stoica05b1d332014-07-28 13:11:23 +0300761 if (memcmp(q, template[i].result + temp, n)) {
762 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
763 d, j, e, k, algo);
764 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800765 goto out;
766 }
767
Cristian Stoica05b1d332014-07-28 13:11:23 +0300768 q += n;
769 if (k == template[i].np - 1 && !enc) {
770 if (!diff_dst &&
771 memcmp(q, template[i].input +
772 temp + n, authsize))
773 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200774 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300775 n = 0;
776 } else {
777 for (n = 0; offset_in_page(q + n) && q[n]; n++)
778 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800779 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300780 if (n) {
781 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
782 d, j, e, k, algo, n);
783 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800784 goto out;
785 }
786
Cristian Stoica05b1d332014-07-28 13:11:23 +0300787 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800788 }
789 }
790
791 ret = 0;
792
793out:
794 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300795 kfree(sg);
796out_nosg:
797 if (diff_dst)
798 testmgr_free_buf(xoutbuf);
799out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800800 testmgr_free_buf(axbuf);
801out_noaxbuf:
802 testmgr_free_buf(xbuf);
803out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300804 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700805 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800806 return ret;
807}
808
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300809static int test_aead(struct crypto_aead *tfm, int enc,
810 struct aead_testvec *template, unsigned int tcount)
811{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300812 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300813 int ret;
814
815 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300816 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300817 if (ret)
818 return ret;
819
820 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300821 ret = __test_aead(tfm, enc, template, tcount, true, 0);
822 if (ret)
823 return ret;
824
825 /* test unaligned buffers, check with one byte offset */
826 ret = __test_aead(tfm, enc, template, tcount, true, 1);
827 if (ret)
828 return ret;
829
830 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
831 if (alignmask) {
832 /* Check if alignment mask for tfm is correctly set. */
833 ret = __test_aead(tfm, enc, template, tcount, true,
834 alignmask + 1);
835 if (ret)
836 return ret;
837 }
838
839 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300840}
841
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000842static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800843 struct cipher_testvec *template, unsigned int tcount)
844{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000845 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
846 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000847 char *q;
848 const char *e;
849 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800850 char *xbuf[XBUFSIZE];
851 int ret = -ENOMEM;
852
853 if (testmgr_alloc_buf(xbuf))
854 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000855
856 if (enc == ENCRYPT)
857 e = "encryption";
858 else
859 e = "decryption";
860
861 j = 0;
862 for (i = 0; i < tcount; i++) {
863 if (template[i].np)
864 continue;
865
866 j++;
867
Herbert Xufd57f222009-05-29 16:05:42 +1000868 ret = -EINVAL;
869 if (WARN_ON(template[i].ilen > PAGE_SIZE))
870 goto out;
871
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000872 data = xbuf[0];
873 memcpy(data, template[i].input, template[i].ilen);
874
875 crypto_cipher_clear_flags(tfm, ~0);
876 if (template[i].wk)
877 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
878
879 ret = crypto_cipher_setkey(tfm, template[i].key,
880 template[i].klen);
881 if (!ret == template[i].fail) {
882 printk(KERN_ERR "alg: cipher: setkey failed "
883 "on test %d for %s: flags=%x\n", j,
884 algo, crypto_cipher_get_flags(tfm));
885 goto out;
886 } else if (ret)
887 continue;
888
889 for (k = 0; k < template[i].ilen;
890 k += crypto_cipher_blocksize(tfm)) {
891 if (enc)
892 crypto_cipher_encrypt_one(tfm, data + k,
893 data + k);
894 else
895 crypto_cipher_decrypt_one(tfm, data + k,
896 data + k);
897 }
898
899 q = data;
900 if (memcmp(q, template[i].result, template[i].rlen)) {
901 printk(KERN_ERR "alg: cipher: Test %d failed "
902 "on %s for %s\n", j, e, algo);
903 hexdump(q, template[i].rlen);
904 ret = -EINVAL;
905 goto out;
906 }
907 }
908
909 ret = 0;
910
911out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800912 testmgr_free_buf(xbuf);
913out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000914 return ret;
915}
916
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300917static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
918 struct cipher_testvec *template, unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300919 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000920{
Herbert Xuda7f0332008-07-31 17:08:25 +0800921 const char *algo =
922 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
923 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800924 char *q;
925 struct ablkcipher_request *req;
926 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300927 struct scatterlist sgout[8];
928 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800929 struct tcrypt_result result;
930 void *data;
931 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800932 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300933 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800934 int ret = -ENOMEM;
935
936 if (testmgr_alloc_buf(xbuf))
937 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800938
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300939 if (diff_dst && testmgr_alloc_buf(xoutbuf))
940 goto out_nooutbuf;
941
942 if (diff_dst)
943 d = "-ddst";
944 else
945 d = "";
946
Herbert Xuda7f0332008-07-31 17:08:25 +0800947 if (enc == ENCRYPT)
948 e = "encryption";
949 else
950 e = "decryption";
951
952 init_completion(&result.completion);
953
954 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
955 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300956 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
957 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800958 goto out;
959 }
960
961 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
962 tcrypt_complete, &result);
963
964 j = 0;
965 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +0300966 if (template[i].np && !template[i].also_non_np)
967 continue;
968
Herbert Xuda7f0332008-07-31 17:08:25 +0800969 if (template[i].iv)
970 memcpy(iv, template[i].iv, MAX_IVLEN);
971 else
972 memset(iv, 0, MAX_IVLEN);
973
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300974 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300975 ret = -EINVAL;
976 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
977 goto out;
978
979 data = xbuf[0];
980 data += align_offset;
981 memcpy(data, template[i].input, template[i].ilen);
982
983 crypto_ablkcipher_clear_flags(tfm, ~0);
984 if (template[i].wk)
985 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
986
987 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
988 template[i].klen);
989 if (!ret == template[i].fail) {
990 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
991 d, j, algo, crypto_ablkcipher_get_flags(tfm));
992 goto out;
993 } else if (ret)
994 continue;
995
996 sg_init_one(&sg[0], data, template[i].ilen);
997 if (diff_dst) {
998 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300999 data += align_offset;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001000 sg_init_one(&sgout[0], data, template[i].ilen);
1001 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001002
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001003 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1004 template[i].ilen, iv);
1005 ret = enc ? crypto_ablkcipher_encrypt(req) :
1006 crypto_ablkcipher_decrypt(req);
Herbert Xuda7f0332008-07-31 17:08:25 +08001007
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001008 switch (ret) {
1009 case 0:
1010 break;
1011 case -EINPROGRESS:
1012 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001013 wait_for_completion(&result.completion);
1014 reinit_completion(&result.completion);
1015 ret = result.err;
1016 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +08001017 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001018 /* fall through */
1019 default:
1020 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1021 d, e, j, algo, -ret);
1022 goto out;
1023 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001024
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001025 q = data;
1026 if (memcmp(q, template[i].result, template[i].rlen)) {
1027 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1028 d, j, e, algo);
1029 hexdump(q, template[i].rlen);
1030 ret = -EINVAL;
1031 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001032 }
1033 }
1034
1035 j = 0;
1036 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001037 /* alignment tests are only done with continuous buffers */
1038 if (align_offset != 0)
1039 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001040
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001041 if (!template[i].np)
1042 continue;
1043
Herbert Xuda7f0332008-07-31 17:08:25 +08001044 if (template[i].iv)
1045 memcpy(iv, template[i].iv, MAX_IVLEN);
1046 else
1047 memset(iv, 0, MAX_IVLEN);
1048
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001049 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001050 crypto_ablkcipher_clear_flags(tfm, ~0);
1051 if (template[i].wk)
1052 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1053
1054 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1055 template[i].klen);
1056 if (!ret == template[i].fail) {
1057 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1058 d, j, algo, crypto_ablkcipher_get_flags(tfm));
1059 goto out;
1060 } else if (ret)
1061 continue;
1062
1063 temp = 0;
1064 ret = -EINVAL;
1065 sg_init_table(sg, template[i].np);
1066 if (diff_dst)
1067 sg_init_table(sgout, template[i].np);
1068 for (k = 0; k < template[i].np; k++) {
1069 if (WARN_ON(offset_in_page(IDX[k]) +
1070 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001071 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001072
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001073 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1074
1075 memcpy(q, template[i].input + temp, template[i].tap[k]);
1076
1077 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1078 q[template[i].tap[k]] = 0;
1079
1080 sg_set_buf(&sg[k], q, template[i].tap[k]);
1081 if (diff_dst) {
1082 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1083 offset_in_page(IDX[k]);
1084
1085 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1086
1087 memset(q, 0, template[i].tap[k]);
1088 if (offset_in_page(q) +
1089 template[i].tap[k] < PAGE_SIZE)
1090 q[template[i].tap[k]] = 0;
1091 }
1092
1093 temp += template[i].tap[k];
1094 }
1095
1096 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1097 template[i].ilen, iv);
1098
1099 ret = enc ? crypto_ablkcipher_encrypt(req) :
1100 crypto_ablkcipher_decrypt(req);
1101
1102 switch (ret) {
1103 case 0:
1104 break;
1105 case -EINPROGRESS:
1106 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001107 wait_for_completion(&result.completion);
1108 reinit_completion(&result.completion);
1109 ret = result.err;
1110 if (!ret)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001111 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001112 /* fall through */
1113 default:
1114 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1115 d, e, j, algo, -ret);
1116 goto out;
1117 }
1118
1119 temp = 0;
1120 ret = -EINVAL;
1121 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001122 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001123 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1124 offset_in_page(IDX[k]);
1125 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001126 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1127 offset_in_page(IDX[k]);
1128
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001129 if (memcmp(q, template[i].result + temp,
1130 template[i].tap[k])) {
1131 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1132 d, j, e, k, algo);
1133 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001134 goto out;
1135 }
1136
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001137 q += template[i].tap[k];
1138 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1139 ;
1140 if (n) {
1141 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1142 d, j, e, k, algo, n);
1143 hexdump(q, n);
1144 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001145 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001146 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001147 }
1148 }
1149
1150 ret = 0;
1151
1152out:
1153 ablkcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001154 if (diff_dst)
1155 testmgr_free_buf(xoutbuf);
1156out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001157 testmgr_free_buf(xbuf);
1158out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001159 return ret;
1160}
1161
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001162static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1163 struct cipher_testvec *template, unsigned int tcount)
1164{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001165 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001166 int ret;
1167
1168 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001169 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001170 if (ret)
1171 return ret;
1172
1173 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001174 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1175 if (ret)
1176 return ret;
1177
1178 /* test unaligned buffers, check with one byte offset */
1179 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1180 if (ret)
1181 return ret;
1182
1183 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1184 if (alignmask) {
1185 /* Check if alignment mask for tfm is correctly set. */
1186 ret = __test_skcipher(tfm, enc, template, tcount, true,
1187 alignmask + 1);
1188 if (ret)
1189 return ret;
1190 }
1191
1192 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001193}
1194
Herbert Xuda7f0332008-07-31 17:08:25 +08001195static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1196 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1197{
1198 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1199 unsigned int i;
1200 char result[COMP_BUF_SIZE];
1201 int ret;
1202
1203 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001204 int ilen;
1205 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001206
1207 memset(result, 0, sizeof (result));
1208
1209 ilen = ctemplate[i].inlen;
1210 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1211 ilen, result, &dlen);
1212 if (ret) {
1213 printk(KERN_ERR "alg: comp: compression failed "
1214 "on test %d for %s: ret=%d\n", i + 1, algo,
1215 -ret);
1216 goto out;
1217 }
1218
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001219 if (dlen != ctemplate[i].outlen) {
1220 printk(KERN_ERR "alg: comp: Compression test %d "
1221 "failed for %s: output len = %d\n", i + 1, algo,
1222 dlen);
1223 ret = -EINVAL;
1224 goto out;
1225 }
1226
Herbert Xuda7f0332008-07-31 17:08:25 +08001227 if (memcmp(result, ctemplate[i].output, dlen)) {
1228 printk(KERN_ERR "alg: comp: Compression test %d "
1229 "failed for %s\n", i + 1, algo);
1230 hexdump(result, dlen);
1231 ret = -EINVAL;
1232 goto out;
1233 }
1234 }
1235
1236 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001237 int ilen;
1238 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001239
1240 memset(result, 0, sizeof (result));
1241
1242 ilen = dtemplate[i].inlen;
1243 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1244 ilen, result, &dlen);
1245 if (ret) {
1246 printk(KERN_ERR "alg: comp: decompression failed "
1247 "on test %d for %s: ret=%d\n", i + 1, algo,
1248 -ret);
1249 goto out;
1250 }
1251
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001252 if (dlen != dtemplate[i].outlen) {
1253 printk(KERN_ERR "alg: comp: Decompression test %d "
1254 "failed for %s: output len = %d\n", i + 1, algo,
1255 dlen);
1256 ret = -EINVAL;
1257 goto out;
1258 }
1259
Herbert Xuda7f0332008-07-31 17:08:25 +08001260 if (memcmp(result, dtemplate[i].output, dlen)) {
1261 printk(KERN_ERR "alg: comp: Decompression test %d "
1262 "failed for %s\n", i + 1, algo);
1263 hexdump(result, dlen);
1264 ret = -EINVAL;
1265 goto out;
1266 }
1267 }
1268
1269 ret = 0;
1270
1271out:
1272 return ret;
1273}
1274
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001275static int test_pcomp(struct crypto_pcomp *tfm,
1276 struct pcomp_testvec *ctemplate,
1277 struct pcomp_testvec *dtemplate, int ctcount,
1278 int dtcount)
1279{
1280 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1281 unsigned int i;
1282 char result[COMP_BUF_SIZE];
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001283 int res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001284
1285 for (i = 0; i < ctcount; i++) {
1286 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001287 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001288
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001289 res = crypto_compress_setup(tfm, ctemplate[i].params,
1290 ctemplate[i].paramsize);
1291 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001292 pr_err("alg: pcomp: compression setup failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001293 "%d for %s: error=%d\n", i + 1, algo, res);
1294 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001295 }
1296
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001297 res = crypto_compress_init(tfm);
1298 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001299 pr_err("alg: pcomp: compression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001300 "%d for %s: error=%d\n", i + 1, algo, res);
1301 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001302 }
1303
1304 memset(result, 0, sizeof(result));
1305
1306 req.next_in = ctemplate[i].input;
1307 req.avail_in = ctemplate[i].inlen / 2;
1308 req.next_out = result;
1309 req.avail_out = ctemplate[i].outlen / 2;
1310
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001311 res = crypto_compress_update(tfm, &req);
1312 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001313 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001314 "%d for %s: error=%d\n", i + 1, algo, res);
1315 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001316 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001317 if (res > 0)
1318 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001319
1320 /* Add remaining input data */
1321 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1322
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001323 res = crypto_compress_update(tfm, &req);
1324 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001325 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001326 "%d for %s: error=%d\n", i + 1, algo, res);
1327 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001328 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001329 if (res > 0)
1330 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001331
1332 /* Provide remaining output space */
1333 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1334
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001335 res = crypto_compress_final(tfm, &req);
1336 if (res < 0) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001337 pr_err("alg: pcomp: compression final failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001338 "%d for %s: error=%d\n", i + 1, algo, res);
1339 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001340 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001341 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001342
1343 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1344 pr_err("alg: comp: Compression test %d failed for %s: "
1345 "output len = %d (expected %d)\n", i + 1, algo,
1346 COMP_BUF_SIZE - req.avail_out,
1347 ctemplate[i].outlen);
1348 return -EINVAL;
1349 }
1350
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001351 if (produced != ctemplate[i].outlen) {
1352 pr_err("alg: comp: Compression test %d failed for %s: "
1353 "returned len = %u (expected %d)\n", i + 1,
1354 algo, produced, ctemplate[i].outlen);
1355 return -EINVAL;
1356 }
1357
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001358 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1359 pr_err("alg: pcomp: Compression test %d failed for "
1360 "%s\n", i + 1, algo);
1361 hexdump(result, ctemplate[i].outlen);
1362 return -EINVAL;
1363 }
1364 }
1365
1366 for (i = 0; i < dtcount; i++) {
1367 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001368 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001369
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001370 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1371 dtemplate[i].paramsize);
1372 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001373 pr_err("alg: pcomp: decompression setup failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001374 "test %d for %s: error=%d\n", i + 1, algo, res);
1375 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001376 }
1377
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001378 res = crypto_decompress_init(tfm);
1379 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001380 pr_err("alg: pcomp: decompression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001381 "%d for %s: error=%d\n", i + 1, algo, res);
1382 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001383 }
1384
1385 memset(result, 0, sizeof(result));
1386
1387 req.next_in = dtemplate[i].input;
1388 req.avail_in = dtemplate[i].inlen / 2;
1389 req.next_out = result;
1390 req.avail_out = dtemplate[i].outlen / 2;
1391
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001392 res = crypto_decompress_update(tfm, &req);
1393 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001394 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001395 "test %d for %s: error=%d\n", i + 1, algo, res);
1396 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001397 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001398 if (res > 0)
1399 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001400
1401 /* Add remaining input data */
1402 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1403
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001404 res = crypto_decompress_update(tfm, &req);
1405 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001406 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001407 "test %d for %s: error=%d\n", i + 1, algo, res);
1408 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001409 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001410 if (res > 0)
1411 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001412
1413 /* Provide remaining output space */
1414 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1415
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001416 res = crypto_decompress_final(tfm, &req);
1417 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001418 pr_err("alg: pcomp: decompression final failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001419 "test %d for %s: error=%d\n", i + 1, algo, res);
1420 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001421 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001422 if (res > 0)
1423 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001424
1425 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1426 pr_err("alg: comp: Decompression test %d failed for "
1427 "%s: output len = %d (expected %d)\n", i + 1,
1428 algo, COMP_BUF_SIZE - req.avail_out,
1429 dtemplate[i].outlen);
1430 return -EINVAL;
1431 }
1432
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001433 if (produced != dtemplate[i].outlen) {
1434 pr_err("alg: comp: Decompression test %d failed for "
1435 "%s: returned len = %u (expected %d)\n", i + 1,
1436 algo, produced, dtemplate[i].outlen);
1437 return -EINVAL;
1438 }
1439
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001440 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1441 pr_err("alg: pcomp: Decompression test %d failed for "
1442 "%s\n", i + 1, algo);
1443 hexdump(result, dtemplate[i].outlen);
1444 return -EINVAL;
1445 }
1446 }
1447
1448 return 0;
1449}
1450
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001451
1452static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1453 unsigned int tcount)
1454{
1455 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001456 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001457 u8 *seed;
1458 char result[32];
1459
1460 seedsize = crypto_rng_seedsize(tfm);
1461
1462 seed = kmalloc(seedsize, GFP_KERNEL);
1463 if (!seed) {
1464 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1465 "for %s\n", algo);
1466 return -ENOMEM;
1467 }
1468
1469 for (i = 0; i < tcount; i++) {
1470 memset(result, 0, 32);
1471
1472 memcpy(seed, template[i].v, template[i].vlen);
1473 memcpy(seed + template[i].vlen, template[i].key,
1474 template[i].klen);
1475 memcpy(seed + template[i].vlen + template[i].klen,
1476 template[i].dt, template[i].dtlen);
1477
1478 err = crypto_rng_reset(tfm, seed, seedsize);
1479 if (err) {
1480 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1481 "for %s\n", algo);
1482 goto out;
1483 }
1484
1485 for (j = 0; j < template[i].loops; j++) {
1486 err = crypto_rng_get_bytes(tfm, result,
1487 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01001488 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001489 printk(KERN_ERR "alg: cprng: Failed to obtain "
1490 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01001491 "%s (requested %d)\n", algo,
1492 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001493 goto out;
1494 }
1495 }
1496
1497 err = memcmp(result, template[i].result,
1498 template[i].rlen);
1499 if (err) {
1500 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1501 i, algo);
1502 hexdump(result, template[i].rlen);
1503 err = -EINVAL;
1504 goto out;
1505 }
1506 }
1507
1508out:
1509 kfree(seed);
1510 return err;
1511}
1512
Herbert Xuda7f0332008-07-31 17:08:25 +08001513static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1514 u32 type, u32 mask)
1515{
1516 struct crypto_aead *tfm;
1517 int err = 0;
1518
Stephan Mueller425a8822015-03-30 21:56:31 +02001519 tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001520 if (IS_ERR(tfm)) {
1521 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1522 "%ld\n", driver, PTR_ERR(tfm));
1523 return PTR_ERR(tfm);
1524 }
1525
1526 if (desc->suite.aead.enc.vecs) {
1527 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1528 desc->suite.aead.enc.count);
1529 if (err)
1530 goto out;
1531 }
1532
1533 if (!err && desc->suite.aead.dec.vecs)
1534 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1535 desc->suite.aead.dec.count);
1536
1537out:
1538 crypto_free_aead(tfm);
1539 return err;
1540}
1541
1542static int alg_test_cipher(const struct alg_test_desc *desc,
1543 const char *driver, u32 type, u32 mask)
1544{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001545 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001546 int err = 0;
1547
Stephan Mueller425a8822015-03-30 21:56:31 +02001548 tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001549 if (IS_ERR(tfm)) {
1550 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1551 "%s: %ld\n", driver, PTR_ERR(tfm));
1552 return PTR_ERR(tfm);
1553 }
1554
1555 if (desc->suite.cipher.enc.vecs) {
1556 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1557 desc->suite.cipher.enc.count);
1558 if (err)
1559 goto out;
1560 }
1561
1562 if (desc->suite.cipher.dec.vecs)
1563 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1564 desc->suite.cipher.dec.count);
1565
1566out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001567 crypto_free_cipher(tfm);
1568 return err;
1569}
1570
1571static int alg_test_skcipher(const struct alg_test_desc *desc,
1572 const char *driver, u32 type, u32 mask)
1573{
1574 struct crypto_ablkcipher *tfm;
1575 int err = 0;
1576
Stephan Mueller425a8822015-03-30 21:56:31 +02001577 tfm = crypto_alloc_ablkcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001578 if (IS_ERR(tfm)) {
1579 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1580 "%s: %ld\n", driver, PTR_ERR(tfm));
1581 return PTR_ERR(tfm);
1582 }
1583
1584 if (desc->suite.cipher.enc.vecs) {
1585 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1586 desc->suite.cipher.enc.count);
1587 if (err)
1588 goto out;
1589 }
1590
1591 if (desc->suite.cipher.dec.vecs)
1592 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1593 desc->suite.cipher.dec.count);
1594
1595out:
Herbert Xuda7f0332008-07-31 17:08:25 +08001596 crypto_free_ablkcipher(tfm);
1597 return err;
1598}
1599
1600static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1601 u32 type, u32 mask)
1602{
1603 struct crypto_comp *tfm;
1604 int err;
1605
1606 tfm = crypto_alloc_comp(driver, type, mask);
1607 if (IS_ERR(tfm)) {
1608 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1609 "%ld\n", driver, PTR_ERR(tfm));
1610 return PTR_ERR(tfm);
1611 }
1612
1613 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1614 desc->suite.comp.decomp.vecs,
1615 desc->suite.comp.comp.count,
1616 desc->suite.comp.decomp.count);
1617
1618 crypto_free_comp(tfm);
1619 return err;
1620}
1621
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001622static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1623 u32 type, u32 mask)
1624{
1625 struct crypto_pcomp *tfm;
1626 int err;
1627
1628 tfm = crypto_alloc_pcomp(driver, type, mask);
1629 if (IS_ERR(tfm)) {
1630 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1631 driver, PTR_ERR(tfm));
1632 return PTR_ERR(tfm);
1633 }
1634
1635 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1636 desc->suite.pcomp.decomp.vecs,
1637 desc->suite.pcomp.comp.count,
1638 desc->suite.pcomp.decomp.count);
1639
1640 crypto_free_pcomp(tfm);
1641 return err;
1642}
1643
Herbert Xuda7f0332008-07-31 17:08:25 +08001644static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1645 u32 type, u32 mask)
1646{
1647 struct crypto_ahash *tfm;
1648 int err;
1649
Stephan Mueller425a8822015-03-30 21:56:31 +02001650 tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001651 if (IS_ERR(tfm)) {
1652 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1653 "%ld\n", driver, PTR_ERR(tfm));
1654 return PTR_ERR(tfm);
1655 }
1656
David S. Millera8f1a052010-05-19 14:12:03 +10001657 err = test_hash(tfm, desc->suite.hash.vecs,
1658 desc->suite.hash.count, true);
1659 if (!err)
1660 err = test_hash(tfm, desc->suite.hash.vecs,
1661 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001662
1663 crypto_free_ahash(tfm);
1664 return err;
1665}
1666
Herbert Xu8e3ee852008-11-07 14:58:52 +08001667static int alg_test_crc32c(const struct alg_test_desc *desc,
1668 const char *driver, u32 type, u32 mask)
1669{
1670 struct crypto_shash *tfm;
1671 u32 val;
1672 int err;
1673
1674 err = alg_test_hash(desc, driver, type, mask);
1675 if (err)
1676 goto out;
1677
Stephan Mueller425a8822015-03-30 21:56:31 +02001678 tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001679 if (IS_ERR(tfm)) {
1680 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1681 "%ld\n", driver, PTR_ERR(tfm));
1682 err = PTR_ERR(tfm);
1683 goto out;
1684 }
1685
1686 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001687 SHASH_DESC_ON_STACK(shash, tfm);
1688 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001689
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001690 shash->tfm = tfm;
1691 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001692
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001693 *ctx = le32_to_cpu(420553207);
1694 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001695 if (err) {
1696 printk(KERN_ERR "alg: crc32c: Operation failed for "
1697 "%s: %d\n", driver, err);
1698 break;
1699 }
1700
1701 if (val != ~420553207) {
1702 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1703 "%d\n", driver, val);
1704 err = -EINVAL;
1705 }
1706 } while (0);
1707
1708 crypto_free_shash(tfm);
1709
1710out:
1711 return err;
1712}
1713
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001714static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1715 u32 type, u32 mask)
1716{
1717 struct crypto_rng *rng;
1718 int err;
1719
Stephan Mueller425a8822015-03-30 21:56:31 +02001720 rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001721 if (IS_ERR(rng)) {
1722 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1723 "%ld\n", driver, PTR_ERR(rng));
1724 return PTR_ERR(rng);
1725 }
1726
1727 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1728
1729 crypto_free_rng(rng);
1730
1731 return err;
1732}
1733
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001734
1735static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1736 const char *driver, u32 type, u32 mask)
1737{
1738 int ret = -EAGAIN;
1739 struct crypto_rng *drng;
1740 struct drbg_test_data test_data;
1741 struct drbg_string addtl, pers, testentropy;
1742 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1743
1744 if (!buf)
1745 return -ENOMEM;
1746
Stephan Mueller425a8822015-03-30 21:56:31 +02001747 drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001748 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001749 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001750 "%s\n", driver);
1751 kzfree(buf);
1752 return -ENOMEM;
1753 }
1754
1755 test_data.testentropy = &testentropy;
1756 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1757 drbg_string_fill(&pers, test->pers, test->perslen);
1758 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1759 if (ret) {
1760 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1761 goto outbuf;
1762 }
1763
1764 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1765 if (pr) {
1766 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1767 ret = crypto_drbg_get_bytes_addtl_test(drng,
1768 buf, test->expectedlen, &addtl, &test_data);
1769 } else {
1770 ret = crypto_drbg_get_bytes_addtl(drng,
1771 buf, test->expectedlen, &addtl);
1772 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001773 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001774 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001775 "driver %s\n", driver);
1776 goto outbuf;
1777 }
1778
1779 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1780 if (pr) {
1781 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1782 ret = crypto_drbg_get_bytes_addtl_test(drng,
1783 buf, test->expectedlen, &addtl, &test_data);
1784 } else {
1785 ret = crypto_drbg_get_bytes_addtl(drng,
1786 buf, test->expectedlen, &addtl);
1787 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001788 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001789 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001790 "driver %s\n", driver);
1791 goto outbuf;
1792 }
1793
1794 ret = memcmp(test->expected, buf, test->expectedlen);
1795
1796outbuf:
1797 crypto_free_rng(drng);
1798 kzfree(buf);
1799 return ret;
1800}
1801
1802
1803static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1804 u32 type, u32 mask)
1805{
1806 int err = 0;
1807 int pr = 0;
1808 int i = 0;
1809 struct drbg_testvec *template = desc->suite.drbg.vecs;
1810 unsigned int tcount = desc->suite.drbg.count;
1811
1812 if (0 == memcmp(driver, "drbg_pr_", 8))
1813 pr = 1;
1814
1815 for (i = 0; i < tcount; i++) {
1816 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1817 if (err) {
1818 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1819 i, driver);
1820 err = -EINVAL;
1821 break;
1822 }
1823 }
1824 return err;
1825
1826}
1827
Youquan, Song863b5572009-12-23 19:45:20 +08001828static int alg_test_null(const struct alg_test_desc *desc,
1829 const char *driver, u32 type, u32 mask)
1830{
1831 return 0;
1832}
1833
Herbert Xuda7f0332008-07-31 17:08:25 +08001834/* Please keep this list sorted by algorithm name. */
1835static const struct alg_test_desc alg_test_descs[] = {
1836 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001837 .alg = "__cbc-cast5-avx",
1838 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001839 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001840 .alg = "__cbc-cast6-avx",
1841 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001842 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001843 .alg = "__cbc-serpent-avx",
1844 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001845 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001846 .alg = "__cbc-serpent-avx2",
1847 .test = alg_test_null,
1848 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001849 .alg = "__cbc-serpent-sse2",
1850 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001851 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001852 .alg = "__cbc-twofish-avx",
1853 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001854 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001855 .alg = "__driver-cbc-aes-aesni",
1856 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001857 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001858 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001859 .alg = "__driver-cbc-camellia-aesni",
1860 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001861 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001862 .alg = "__driver-cbc-camellia-aesni-avx2",
1863 .test = alg_test_null,
1864 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001865 .alg = "__driver-cbc-cast5-avx",
1866 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001867 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001868 .alg = "__driver-cbc-cast6-avx",
1869 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001870 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001871 .alg = "__driver-cbc-serpent-avx",
1872 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001873 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001874 .alg = "__driver-cbc-serpent-avx2",
1875 .test = alg_test_null,
1876 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001877 .alg = "__driver-cbc-serpent-sse2",
1878 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001879 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001880 .alg = "__driver-cbc-twofish-avx",
1881 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001882 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001883 .alg = "__driver-ecb-aes-aesni",
1884 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001885 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001886 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001887 .alg = "__driver-ecb-camellia-aesni",
1888 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001889 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001890 .alg = "__driver-ecb-camellia-aesni-avx2",
1891 .test = alg_test_null,
1892 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001893 .alg = "__driver-ecb-cast5-avx",
1894 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001895 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001896 .alg = "__driver-ecb-cast6-avx",
1897 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001898 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001899 .alg = "__driver-ecb-serpent-avx",
1900 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001901 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001902 .alg = "__driver-ecb-serpent-avx2",
1903 .test = alg_test_null,
1904 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001905 .alg = "__driver-ecb-serpent-sse2",
1906 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001907 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001908 .alg = "__driver-ecb-twofish-avx",
1909 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001910 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001911 .alg = "__ghash-pclmulqdqni",
1912 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001913 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001914 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001915 .alg = "ansi_cprng",
1916 .test = alg_test_cprng,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001917 .fips_allowed = 1,
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001918 .suite = {
1919 .cprng = {
1920 .vecs = ansi_cprng_aes_tv_template,
1921 .count = ANSI_CPRNG_AES_TEST_VECTORS
1922 }
1923 }
1924 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001925 .alg = "authenc(hmac(md5),ecb(cipher_null))",
1926 .test = alg_test_aead,
1927 .fips_allowed = 1,
1928 .suite = {
1929 .aead = {
1930 .enc = {
1931 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
1932 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1933 },
1934 .dec = {
1935 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
1936 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1937 }
1938 }
1939 }
1940 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03001941 .alg = "authenc(hmac(sha1),cbc(aes))",
1942 .test = alg_test_aead,
1943 .fips_allowed = 1,
1944 .suite = {
1945 .aead = {
1946 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301947 .vecs =
1948 hmac_sha1_aes_cbc_enc_tv_temp,
1949 .count =
1950 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1951 }
1952 }
1953 }
1954 }, {
1955 .alg = "authenc(hmac(sha1),cbc(des))",
1956 .test = alg_test_aead,
1957 .fips_allowed = 1,
1958 .suite = {
1959 .aead = {
1960 .enc = {
1961 .vecs =
1962 hmac_sha1_des_cbc_enc_tv_temp,
1963 .count =
1964 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1965 }
1966 }
1967 }
1968 }, {
1969 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
1970 .test = alg_test_aead,
1971 .fips_allowed = 1,
1972 .suite = {
1973 .aead = {
1974 .enc = {
1975 .vecs =
1976 hmac_sha1_des3_ede_cbc_enc_tv_temp,
1977 .count =
1978 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03001979 }
1980 }
1981 }
1982 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001983 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
1984 .test = alg_test_aead,
1985 .fips_allowed = 1,
1986 .suite = {
1987 .aead = {
1988 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301989 .vecs =
1990 hmac_sha1_ecb_cipher_null_enc_tv_temp,
1991 .count =
1992 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02001993 },
1994 .dec = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301995 .vecs =
1996 hmac_sha1_ecb_cipher_null_dec_tv_temp,
1997 .count =
1998 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
1999 }
2000 }
2001 }
2002 }, {
2003 .alg = "authenc(hmac(sha224),cbc(des))",
2004 .test = alg_test_aead,
2005 .fips_allowed = 1,
2006 .suite = {
2007 .aead = {
2008 .enc = {
2009 .vecs =
2010 hmac_sha224_des_cbc_enc_tv_temp,
2011 .count =
2012 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2013 }
2014 }
2015 }
2016 }, {
2017 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
2018 .test = alg_test_aead,
2019 .fips_allowed = 1,
2020 .suite = {
2021 .aead = {
2022 .enc = {
2023 .vecs =
2024 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2025 .count =
2026 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002027 }
2028 }
2029 }
2030 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03002031 .alg = "authenc(hmac(sha256),cbc(aes))",
2032 .test = alg_test_aead,
2033 .fips_allowed = 1,
2034 .suite = {
2035 .aead = {
2036 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302037 .vecs =
2038 hmac_sha256_aes_cbc_enc_tv_temp,
2039 .count =
2040 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2041 }
2042 }
2043 }
2044 }, {
2045 .alg = "authenc(hmac(sha256),cbc(des))",
2046 .test = alg_test_aead,
2047 .fips_allowed = 1,
2048 .suite = {
2049 .aead = {
2050 .enc = {
2051 .vecs =
2052 hmac_sha256_des_cbc_enc_tv_temp,
2053 .count =
2054 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2055 }
2056 }
2057 }
2058 }, {
2059 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
2060 .test = alg_test_aead,
2061 .fips_allowed = 1,
2062 .suite = {
2063 .aead = {
2064 .enc = {
2065 .vecs =
2066 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2067 .count =
2068 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2069 }
2070 }
2071 }
2072 }, {
2073 .alg = "authenc(hmac(sha384),cbc(des))",
2074 .test = alg_test_aead,
2075 .fips_allowed = 1,
2076 .suite = {
2077 .aead = {
2078 .enc = {
2079 .vecs =
2080 hmac_sha384_des_cbc_enc_tv_temp,
2081 .count =
2082 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2083 }
2084 }
2085 }
2086 }, {
2087 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
2088 .test = alg_test_aead,
2089 .fips_allowed = 1,
2090 .suite = {
2091 .aead = {
2092 .enc = {
2093 .vecs =
2094 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2095 .count =
2096 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002097 }
2098 }
2099 }
2100 }, {
2101 .alg = "authenc(hmac(sha512),cbc(aes))",
2102 .test = alg_test_aead,
2103 .fips_allowed = 1,
2104 .suite = {
2105 .aead = {
2106 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302107 .vecs =
2108 hmac_sha512_aes_cbc_enc_tv_temp,
2109 .count =
2110 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2111 }
2112 }
2113 }
2114 }, {
2115 .alg = "authenc(hmac(sha512),cbc(des))",
2116 .test = alg_test_aead,
2117 .fips_allowed = 1,
2118 .suite = {
2119 .aead = {
2120 .enc = {
2121 .vecs =
2122 hmac_sha512_des_cbc_enc_tv_temp,
2123 .count =
2124 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2125 }
2126 }
2127 }
2128 }, {
2129 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2130 .test = alg_test_aead,
2131 .fips_allowed = 1,
2132 .suite = {
2133 .aead = {
2134 .enc = {
2135 .vecs =
2136 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2137 .count =
2138 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002139 }
2140 }
2141 }
2142 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002143 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002144 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002145 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002146 .suite = {
2147 .cipher = {
2148 .enc = {
2149 .vecs = aes_cbc_enc_tv_template,
2150 .count = AES_CBC_ENC_TEST_VECTORS
2151 },
2152 .dec = {
2153 .vecs = aes_cbc_dec_tv_template,
2154 .count = AES_CBC_DEC_TEST_VECTORS
2155 }
2156 }
2157 }
2158 }, {
2159 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002160 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002161 .suite = {
2162 .cipher = {
2163 .enc = {
2164 .vecs = anubis_cbc_enc_tv_template,
2165 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2166 },
2167 .dec = {
2168 .vecs = anubis_cbc_dec_tv_template,
2169 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2170 }
2171 }
2172 }
2173 }, {
2174 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002175 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002176 .suite = {
2177 .cipher = {
2178 .enc = {
2179 .vecs = bf_cbc_enc_tv_template,
2180 .count = BF_CBC_ENC_TEST_VECTORS
2181 },
2182 .dec = {
2183 .vecs = bf_cbc_dec_tv_template,
2184 .count = BF_CBC_DEC_TEST_VECTORS
2185 }
2186 }
2187 }
2188 }, {
2189 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002190 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002191 .suite = {
2192 .cipher = {
2193 .enc = {
2194 .vecs = camellia_cbc_enc_tv_template,
2195 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2196 },
2197 .dec = {
2198 .vecs = camellia_cbc_dec_tv_template,
2199 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2200 }
2201 }
2202 }
2203 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002204 .alg = "cbc(cast5)",
2205 .test = alg_test_skcipher,
2206 .suite = {
2207 .cipher = {
2208 .enc = {
2209 .vecs = cast5_cbc_enc_tv_template,
2210 .count = CAST5_CBC_ENC_TEST_VECTORS
2211 },
2212 .dec = {
2213 .vecs = cast5_cbc_dec_tv_template,
2214 .count = CAST5_CBC_DEC_TEST_VECTORS
2215 }
2216 }
2217 }
2218 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002219 .alg = "cbc(cast6)",
2220 .test = alg_test_skcipher,
2221 .suite = {
2222 .cipher = {
2223 .enc = {
2224 .vecs = cast6_cbc_enc_tv_template,
2225 .count = CAST6_CBC_ENC_TEST_VECTORS
2226 },
2227 .dec = {
2228 .vecs = cast6_cbc_dec_tv_template,
2229 .count = CAST6_CBC_DEC_TEST_VECTORS
2230 }
2231 }
2232 }
2233 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002234 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002235 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002236 .suite = {
2237 .cipher = {
2238 .enc = {
2239 .vecs = des_cbc_enc_tv_template,
2240 .count = DES_CBC_ENC_TEST_VECTORS
2241 },
2242 .dec = {
2243 .vecs = des_cbc_dec_tv_template,
2244 .count = DES_CBC_DEC_TEST_VECTORS
2245 }
2246 }
2247 }
2248 }, {
2249 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002250 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002251 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002252 .suite = {
2253 .cipher = {
2254 .enc = {
2255 .vecs = des3_ede_cbc_enc_tv_template,
2256 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2257 },
2258 .dec = {
2259 .vecs = des3_ede_cbc_dec_tv_template,
2260 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2261 }
2262 }
2263 }
2264 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002265 .alg = "cbc(serpent)",
2266 .test = alg_test_skcipher,
2267 .suite = {
2268 .cipher = {
2269 .enc = {
2270 .vecs = serpent_cbc_enc_tv_template,
2271 .count = SERPENT_CBC_ENC_TEST_VECTORS
2272 },
2273 .dec = {
2274 .vecs = serpent_cbc_dec_tv_template,
2275 .count = SERPENT_CBC_DEC_TEST_VECTORS
2276 }
2277 }
2278 }
2279 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002280 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002281 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002282 .suite = {
2283 .cipher = {
2284 .enc = {
2285 .vecs = tf_cbc_enc_tv_template,
2286 .count = TF_CBC_ENC_TEST_VECTORS
2287 },
2288 .dec = {
2289 .vecs = tf_cbc_dec_tv_template,
2290 .count = TF_CBC_DEC_TEST_VECTORS
2291 }
2292 }
2293 }
2294 }, {
2295 .alg = "ccm(aes)",
2296 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002297 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002298 .suite = {
2299 .aead = {
2300 .enc = {
2301 .vecs = aes_ccm_enc_tv_template,
2302 .count = AES_CCM_ENC_TEST_VECTORS
2303 },
2304 .dec = {
2305 .vecs = aes_ccm_dec_tv_template,
2306 .count = AES_CCM_DEC_TEST_VECTORS
2307 }
2308 }
2309 }
2310 }, {
Martin Willi3590ebf2015-06-01 13:43:57 +02002311 .alg = "chacha20",
2312 .test = alg_test_skcipher,
2313 .suite = {
2314 .cipher = {
2315 .enc = {
2316 .vecs = chacha20_enc_tv_template,
2317 .count = CHACHA20_ENC_TEST_VECTORS
2318 },
2319 .dec = {
2320 .vecs = chacha20_enc_tv_template,
2321 .count = CHACHA20_ENC_TEST_VECTORS
2322 },
2323 }
2324 }
2325 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002326 .alg = "cmac(aes)",
2327 .test = alg_test_hash,
2328 .suite = {
2329 .hash = {
2330 .vecs = aes_cmac128_tv_template,
2331 .count = CMAC_AES_TEST_VECTORS
2332 }
2333 }
2334 }, {
2335 .alg = "cmac(des3_ede)",
2336 .test = alg_test_hash,
2337 .suite = {
2338 .hash = {
2339 .vecs = des3_ede_cmac64_tv_template,
2340 .count = CMAC_DES3_EDE_TEST_VECTORS
2341 }
2342 }
2343 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002344 .alg = "compress_null",
2345 .test = alg_test_null,
2346 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02002347 .alg = "crc32",
2348 .test = alg_test_hash,
2349 .suite = {
2350 .hash = {
2351 .vecs = crc32_tv_template,
2352 .count = CRC32_TEST_VECTORS
2353 }
2354 }
2355 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002356 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002357 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002358 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002359 .suite = {
2360 .hash = {
2361 .vecs = crc32c_tv_template,
2362 .count = CRC32C_TEST_VECTORS
2363 }
2364 }
2365 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002366 .alg = "crct10dif",
2367 .test = alg_test_hash,
2368 .fips_allowed = 1,
2369 .suite = {
2370 .hash = {
2371 .vecs = crct10dif_tv_template,
2372 .count = CRCT10DIF_TEST_VECTORS
2373 }
2374 }
2375 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002376 .alg = "cryptd(__driver-cbc-aes-aesni)",
2377 .test = alg_test_null,
2378 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002379 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002380 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2381 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002382 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002383 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2384 .test = alg_test_null,
2385 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002386 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2387 .test = alg_test_null,
2388 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002389 .alg = "cryptd(__driver-ecb-aes-aesni)",
2390 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002391 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002392 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002393 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2394 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002395 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002396 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2397 .test = alg_test_null,
2398 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002399 .alg = "cryptd(__driver-ecb-cast5-avx)",
2400 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002401 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002402 .alg = "cryptd(__driver-ecb-cast6-avx)",
2403 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002404 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002405 .alg = "cryptd(__driver-ecb-serpent-avx)",
2406 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002407 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002408 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2409 .test = alg_test_null,
2410 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002411 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2412 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002413 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002414 .alg = "cryptd(__driver-ecb-twofish-avx)",
2415 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002416 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002417 .alg = "cryptd(__driver-gcm-aes-aesni)",
2418 .test = alg_test_null,
2419 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002420 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002421 .alg = "cryptd(__ghash-pclmulqdqni)",
2422 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002423 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002424 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002425 .alg = "ctr(aes)",
2426 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002427 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002428 .suite = {
2429 .cipher = {
2430 .enc = {
2431 .vecs = aes_ctr_enc_tv_template,
2432 .count = AES_CTR_ENC_TEST_VECTORS
2433 },
2434 .dec = {
2435 .vecs = aes_ctr_dec_tv_template,
2436 .count = AES_CTR_DEC_TEST_VECTORS
2437 }
2438 }
2439 }
2440 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002441 .alg = "ctr(blowfish)",
2442 .test = alg_test_skcipher,
2443 .suite = {
2444 .cipher = {
2445 .enc = {
2446 .vecs = bf_ctr_enc_tv_template,
2447 .count = BF_CTR_ENC_TEST_VECTORS
2448 },
2449 .dec = {
2450 .vecs = bf_ctr_dec_tv_template,
2451 .count = BF_CTR_DEC_TEST_VECTORS
2452 }
2453 }
2454 }
2455 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002456 .alg = "ctr(camellia)",
2457 .test = alg_test_skcipher,
2458 .suite = {
2459 .cipher = {
2460 .enc = {
2461 .vecs = camellia_ctr_enc_tv_template,
2462 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2463 },
2464 .dec = {
2465 .vecs = camellia_ctr_dec_tv_template,
2466 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2467 }
2468 }
2469 }
2470 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002471 .alg = "ctr(cast5)",
2472 .test = alg_test_skcipher,
2473 .suite = {
2474 .cipher = {
2475 .enc = {
2476 .vecs = cast5_ctr_enc_tv_template,
2477 .count = CAST5_CTR_ENC_TEST_VECTORS
2478 },
2479 .dec = {
2480 .vecs = cast5_ctr_dec_tv_template,
2481 .count = CAST5_CTR_DEC_TEST_VECTORS
2482 }
2483 }
2484 }
2485 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002486 .alg = "ctr(cast6)",
2487 .test = alg_test_skcipher,
2488 .suite = {
2489 .cipher = {
2490 .enc = {
2491 .vecs = cast6_ctr_enc_tv_template,
2492 .count = CAST6_CTR_ENC_TEST_VECTORS
2493 },
2494 .dec = {
2495 .vecs = cast6_ctr_dec_tv_template,
2496 .count = CAST6_CTR_DEC_TEST_VECTORS
2497 }
2498 }
2499 }
2500 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002501 .alg = "ctr(des)",
2502 .test = alg_test_skcipher,
2503 .suite = {
2504 .cipher = {
2505 .enc = {
2506 .vecs = des_ctr_enc_tv_template,
2507 .count = DES_CTR_ENC_TEST_VECTORS
2508 },
2509 .dec = {
2510 .vecs = des_ctr_dec_tv_template,
2511 .count = DES_CTR_DEC_TEST_VECTORS
2512 }
2513 }
2514 }
2515 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002516 .alg = "ctr(des3_ede)",
2517 .test = alg_test_skcipher,
2518 .suite = {
2519 .cipher = {
2520 .enc = {
2521 .vecs = des3_ede_ctr_enc_tv_template,
2522 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2523 },
2524 .dec = {
2525 .vecs = des3_ede_ctr_dec_tv_template,
2526 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2527 }
2528 }
2529 }
2530 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002531 .alg = "ctr(serpent)",
2532 .test = alg_test_skcipher,
2533 .suite = {
2534 .cipher = {
2535 .enc = {
2536 .vecs = serpent_ctr_enc_tv_template,
2537 .count = SERPENT_CTR_ENC_TEST_VECTORS
2538 },
2539 .dec = {
2540 .vecs = serpent_ctr_dec_tv_template,
2541 .count = SERPENT_CTR_DEC_TEST_VECTORS
2542 }
2543 }
2544 }
2545 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002546 .alg = "ctr(twofish)",
2547 .test = alg_test_skcipher,
2548 .suite = {
2549 .cipher = {
2550 .enc = {
2551 .vecs = tf_ctr_enc_tv_template,
2552 .count = TF_CTR_ENC_TEST_VECTORS
2553 },
2554 .dec = {
2555 .vecs = tf_ctr_dec_tv_template,
2556 .count = TF_CTR_DEC_TEST_VECTORS
2557 }
2558 }
2559 }
2560 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002561 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002562 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002563 .suite = {
2564 .cipher = {
2565 .enc = {
2566 .vecs = cts_mode_enc_tv_template,
2567 .count = CTS_MODE_ENC_TEST_VECTORS
2568 },
2569 .dec = {
2570 .vecs = cts_mode_dec_tv_template,
2571 .count = CTS_MODE_DEC_TEST_VECTORS
2572 }
2573 }
2574 }
2575 }, {
2576 .alg = "deflate",
2577 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002578 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002579 .suite = {
2580 .comp = {
2581 .comp = {
2582 .vecs = deflate_comp_tv_template,
2583 .count = DEFLATE_COMP_TEST_VECTORS
2584 },
2585 .decomp = {
2586 .vecs = deflate_decomp_tv_template,
2587 .count = DEFLATE_DECOMP_TEST_VECTORS
2588 }
2589 }
2590 }
2591 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002592 .alg = "digest_null",
2593 .test = alg_test_null,
2594 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002595 .alg = "drbg_nopr_ctr_aes128",
2596 .test = alg_test_drbg,
2597 .fips_allowed = 1,
2598 .suite = {
2599 .drbg = {
2600 .vecs = drbg_nopr_ctr_aes128_tv_template,
2601 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2602 }
2603 }
2604 }, {
2605 .alg = "drbg_nopr_ctr_aes192",
2606 .test = alg_test_drbg,
2607 .fips_allowed = 1,
2608 .suite = {
2609 .drbg = {
2610 .vecs = drbg_nopr_ctr_aes192_tv_template,
2611 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2612 }
2613 }
2614 }, {
2615 .alg = "drbg_nopr_ctr_aes256",
2616 .test = alg_test_drbg,
2617 .fips_allowed = 1,
2618 .suite = {
2619 .drbg = {
2620 .vecs = drbg_nopr_ctr_aes256_tv_template,
2621 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2622 }
2623 }
2624 }, {
2625 /*
2626 * There is no need to specifically test the DRBG with every
2627 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2628 */
2629 .alg = "drbg_nopr_hmac_sha1",
2630 .fips_allowed = 1,
2631 .test = alg_test_null,
2632 }, {
2633 .alg = "drbg_nopr_hmac_sha256",
2634 .test = alg_test_drbg,
2635 .fips_allowed = 1,
2636 .suite = {
2637 .drbg = {
2638 .vecs = drbg_nopr_hmac_sha256_tv_template,
2639 .count =
2640 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2641 }
2642 }
2643 }, {
2644 /* covered by drbg_nopr_hmac_sha256 test */
2645 .alg = "drbg_nopr_hmac_sha384",
2646 .fips_allowed = 1,
2647 .test = alg_test_null,
2648 }, {
2649 .alg = "drbg_nopr_hmac_sha512",
2650 .test = alg_test_null,
2651 .fips_allowed = 1,
2652 }, {
2653 .alg = "drbg_nopr_sha1",
2654 .fips_allowed = 1,
2655 .test = alg_test_null,
2656 }, {
2657 .alg = "drbg_nopr_sha256",
2658 .test = alg_test_drbg,
2659 .fips_allowed = 1,
2660 .suite = {
2661 .drbg = {
2662 .vecs = drbg_nopr_sha256_tv_template,
2663 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2664 }
2665 }
2666 }, {
2667 /* covered by drbg_nopr_sha256 test */
2668 .alg = "drbg_nopr_sha384",
2669 .fips_allowed = 1,
2670 .test = alg_test_null,
2671 }, {
2672 .alg = "drbg_nopr_sha512",
2673 .fips_allowed = 1,
2674 .test = alg_test_null,
2675 }, {
2676 .alg = "drbg_pr_ctr_aes128",
2677 .test = alg_test_drbg,
2678 .fips_allowed = 1,
2679 .suite = {
2680 .drbg = {
2681 .vecs = drbg_pr_ctr_aes128_tv_template,
2682 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2683 }
2684 }
2685 }, {
2686 /* covered by drbg_pr_ctr_aes128 test */
2687 .alg = "drbg_pr_ctr_aes192",
2688 .fips_allowed = 1,
2689 .test = alg_test_null,
2690 }, {
2691 .alg = "drbg_pr_ctr_aes256",
2692 .fips_allowed = 1,
2693 .test = alg_test_null,
2694 }, {
2695 .alg = "drbg_pr_hmac_sha1",
2696 .fips_allowed = 1,
2697 .test = alg_test_null,
2698 }, {
2699 .alg = "drbg_pr_hmac_sha256",
2700 .test = alg_test_drbg,
2701 .fips_allowed = 1,
2702 .suite = {
2703 .drbg = {
2704 .vecs = drbg_pr_hmac_sha256_tv_template,
2705 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2706 }
2707 }
2708 }, {
2709 /* covered by drbg_pr_hmac_sha256 test */
2710 .alg = "drbg_pr_hmac_sha384",
2711 .fips_allowed = 1,
2712 .test = alg_test_null,
2713 }, {
2714 .alg = "drbg_pr_hmac_sha512",
2715 .test = alg_test_null,
2716 .fips_allowed = 1,
2717 }, {
2718 .alg = "drbg_pr_sha1",
2719 .fips_allowed = 1,
2720 .test = alg_test_null,
2721 }, {
2722 .alg = "drbg_pr_sha256",
2723 .test = alg_test_drbg,
2724 .fips_allowed = 1,
2725 .suite = {
2726 .drbg = {
2727 .vecs = drbg_pr_sha256_tv_template,
2728 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2729 }
2730 }
2731 }, {
2732 /* covered by drbg_pr_sha256 test */
2733 .alg = "drbg_pr_sha384",
2734 .fips_allowed = 1,
2735 .test = alg_test_null,
2736 }, {
2737 .alg = "drbg_pr_sha512",
2738 .fips_allowed = 1,
2739 .test = alg_test_null,
2740 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002741 .alg = "ecb(__aes-aesni)",
2742 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002743 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002744 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002745 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002746 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002747 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002748 .suite = {
2749 .cipher = {
2750 .enc = {
2751 .vecs = aes_enc_tv_template,
2752 .count = AES_ENC_TEST_VECTORS
2753 },
2754 .dec = {
2755 .vecs = aes_dec_tv_template,
2756 .count = AES_DEC_TEST_VECTORS
2757 }
2758 }
2759 }
2760 }, {
2761 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002762 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002763 .suite = {
2764 .cipher = {
2765 .enc = {
2766 .vecs = anubis_enc_tv_template,
2767 .count = ANUBIS_ENC_TEST_VECTORS
2768 },
2769 .dec = {
2770 .vecs = anubis_dec_tv_template,
2771 .count = ANUBIS_DEC_TEST_VECTORS
2772 }
2773 }
2774 }
2775 }, {
2776 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002777 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002778 .suite = {
2779 .cipher = {
2780 .enc = {
2781 .vecs = arc4_enc_tv_template,
2782 .count = ARC4_ENC_TEST_VECTORS
2783 },
2784 .dec = {
2785 .vecs = arc4_dec_tv_template,
2786 .count = ARC4_DEC_TEST_VECTORS
2787 }
2788 }
2789 }
2790 }, {
2791 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002792 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002793 .suite = {
2794 .cipher = {
2795 .enc = {
2796 .vecs = bf_enc_tv_template,
2797 .count = BF_ENC_TEST_VECTORS
2798 },
2799 .dec = {
2800 .vecs = bf_dec_tv_template,
2801 .count = BF_DEC_TEST_VECTORS
2802 }
2803 }
2804 }
2805 }, {
2806 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002807 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002808 .suite = {
2809 .cipher = {
2810 .enc = {
2811 .vecs = camellia_enc_tv_template,
2812 .count = CAMELLIA_ENC_TEST_VECTORS
2813 },
2814 .dec = {
2815 .vecs = camellia_dec_tv_template,
2816 .count = CAMELLIA_DEC_TEST_VECTORS
2817 }
2818 }
2819 }
2820 }, {
2821 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002822 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002823 .suite = {
2824 .cipher = {
2825 .enc = {
2826 .vecs = cast5_enc_tv_template,
2827 .count = CAST5_ENC_TEST_VECTORS
2828 },
2829 .dec = {
2830 .vecs = cast5_dec_tv_template,
2831 .count = CAST5_DEC_TEST_VECTORS
2832 }
2833 }
2834 }
2835 }, {
2836 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002837 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002838 .suite = {
2839 .cipher = {
2840 .enc = {
2841 .vecs = cast6_enc_tv_template,
2842 .count = CAST6_ENC_TEST_VECTORS
2843 },
2844 .dec = {
2845 .vecs = cast6_dec_tv_template,
2846 .count = CAST6_DEC_TEST_VECTORS
2847 }
2848 }
2849 }
2850 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002851 .alg = "ecb(cipher_null)",
2852 .test = alg_test_null,
2853 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002854 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002855 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002856 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002857 .suite = {
2858 .cipher = {
2859 .enc = {
2860 .vecs = des_enc_tv_template,
2861 .count = DES_ENC_TEST_VECTORS
2862 },
2863 .dec = {
2864 .vecs = des_dec_tv_template,
2865 .count = DES_DEC_TEST_VECTORS
2866 }
2867 }
2868 }
2869 }, {
2870 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002871 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002872 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002873 .suite = {
2874 .cipher = {
2875 .enc = {
2876 .vecs = des3_ede_enc_tv_template,
2877 .count = DES3_EDE_ENC_TEST_VECTORS
2878 },
2879 .dec = {
2880 .vecs = des3_ede_dec_tv_template,
2881 .count = DES3_EDE_DEC_TEST_VECTORS
2882 }
2883 }
2884 }
2885 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002886 .alg = "ecb(fcrypt)",
2887 .test = alg_test_skcipher,
2888 .suite = {
2889 .cipher = {
2890 .enc = {
2891 .vecs = fcrypt_pcbc_enc_tv_template,
2892 .count = 1
2893 },
2894 .dec = {
2895 .vecs = fcrypt_pcbc_dec_tv_template,
2896 .count = 1
2897 }
2898 }
2899 }
2900 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002901 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002902 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002903 .suite = {
2904 .cipher = {
2905 .enc = {
2906 .vecs = khazad_enc_tv_template,
2907 .count = KHAZAD_ENC_TEST_VECTORS
2908 },
2909 .dec = {
2910 .vecs = khazad_dec_tv_template,
2911 .count = KHAZAD_DEC_TEST_VECTORS
2912 }
2913 }
2914 }
2915 }, {
2916 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002917 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002918 .suite = {
2919 .cipher = {
2920 .enc = {
2921 .vecs = seed_enc_tv_template,
2922 .count = SEED_ENC_TEST_VECTORS
2923 },
2924 .dec = {
2925 .vecs = seed_dec_tv_template,
2926 .count = SEED_DEC_TEST_VECTORS
2927 }
2928 }
2929 }
2930 }, {
2931 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002932 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002933 .suite = {
2934 .cipher = {
2935 .enc = {
2936 .vecs = serpent_enc_tv_template,
2937 .count = SERPENT_ENC_TEST_VECTORS
2938 },
2939 .dec = {
2940 .vecs = serpent_dec_tv_template,
2941 .count = SERPENT_DEC_TEST_VECTORS
2942 }
2943 }
2944 }
2945 }, {
2946 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002947 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002948 .suite = {
2949 .cipher = {
2950 .enc = {
2951 .vecs = tea_enc_tv_template,
2952 .count = TEA_ENC_TEST_VECTORS
2953 },
2954 .dec = {
2955 .vecs = tea_dec_tv_template,
2956 .count = TEA_DEC_TEST_VECTORS
2957 }
2958 }
2959 }
2960 }, {
2961 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002962 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002963 .suite = {
2964 .cipher = {
2965 .enc = {
2966 .vecs = tnepres_enc_tv_template,
2967 .count = TNEPRES_ENC_TEST_VECTORS
2968 },
2969 .dec = {
2970 .vecs = tnepres_dec_tv_template,
2971 .count = TNEPRES_DEC_TEST_VECTORS
2972 }
2973 }
2974 }
2975 }, {
2976 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002977 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002978 .suite = {
2979 .cipher = {
2980 .enc = {
2981 .vecs = tf_enc_tv_template,
2982 .count = TF_ENC_TEST_VECTORS
2983 },
2984 .dec = {
2985 .vecs = tf_dec_tv_template,
2986 .count = TF_DEC_TEST_VECTORS
2987 }
2988 }
2989 }
2990 }, {
2991 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002992 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002993 .suite = {
2994 .cipher = {
2995 .enc = {
2996 .vecs = xeta_enc_tv_template,
2997 .count = XETA_ENC_TEST_VECTORS
2998 },
2999 .dec = {
3000 .vecs = xeta_dec_tv_template,
3001 .count = XETA_DEC_TEST_VECTORS
3002 }
3003 }
3004 }
3005 }, {
3006 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003007 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003008 .suite = {
3009 .cipher = {
3010 .enc = {
3011 .vecs = xtea_enc_tv_template,
3012 .count = XTEA_ENC_TEST_VECTORS
3013 },
3014 .dec = {
3015 .vecs = xtea_dec_tv_template,
3016 .count = XTEA_DEC_TEST_VECTORS
3017 }
3018 }
3019 }
3020 }, {
3021 .alg = "gcm(aes)",
3022 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003023 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003024 .suite = {
3025 .aead = {
3026 .enc = {
3027 .vecs = aes_gcm_enc_tv_template,
3028 .count = AES_GCM_ENC_TEST_VECTORS
3029 },
3030 .dec = {
3031 .vecs = aes_gcm_dec_tv_template,
3032 .count = AES_GCM_DEC_TEST_VECTORS
3033 }
3034 }
3035 }
3036 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003037 .alg = "ghash",
3038 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003039 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003040 .suite = {
3041 .hash = {
3042 .vecs = ghash_tv_template,
3043 .count = GHASH_TEST_VECTORS
3044 }
3045 }
3046 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003047 .alg = "hmac(crc32)",
3048 .test = alg_test_hash,
3049 .suite = {
3050 .hash = {
3051 .vecs = bfin_crc_tv_template,
3052 .count = BFIN_CRC_TEST_VECTORS
3053 }
3054 }
3055 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003056 .alg = "hmac(md5)",
3057 .test = alg_test_hash,
3058 .suite = {
3059 .hash = {
3060 .vecs = hmac_md5_tv_template,
3061 .count = HMAC_MD5_TEST_VECTORS
3062 }
3063 }
3064 }, {
3065 .alg = "hmac(rmd128)",
3066 .test = alg_test_hash,
3067 .suite = {
3068 .hash = {
3069 .vecs = hmac_rmd128_tv_template,
3070 .count = HMAC_RMD128_TEST_VECTORS
3071 }
3072 }
3073 }, {
3074 .alg = "hmac(rmd160)",
3075 .test = alg_test_hash,
3076 .suite = {
3077 .hash = {
3078 .vecs = hmac_rmd160_tv_template,
3079 .count = HMAC_RMD160_TEST_VECTORS
3080 }
3081 }
3082 }, {
3083 .alg = "hmac(sha1)",
3084 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003085 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003086 .suite = {
3087 .hash = {
3088 .vecs = hmac_sha1_tv_template,
3089 .count = HMAC_SHA1_TEST_VECTORS
3090 }
3091 }
3092 }, {
3093 .alg = "hmac(sha224)",
3094 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003095 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003096 .suite = {
3097 .hash = {
3098 .vecs = hmac_sha224_tv_template,
3099 .count = HMAC_SHA224_TEST_VECTORS
3100 }
3101 }
3102 }, {
3103 .alg = "hmac(sha256)",
3104 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003105 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003106 .suite = {
3107 .hash = {
3108 .vecs = hmac_sha256_tv_template,
3109 .count = HMAC_SHA256_TEST_VECTORS
3110 }
3111 }
3112 }, {
3113 .alg = "hmac(sha384)",
3114 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003115 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003116 .suite = {
3117 .hash = {
3118 .vecs = hmac_sha384_tv_template,
3119 .count = HMAC_SHA384_TEST_VECTORS
3120 }
3121 }
3122 }, {
3123 .alg = "hmac(sha512)",
3124 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003125 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003126 .suite = {
3127 .hash = {
3128 .vecs = hmac_sha512_tv_template,
3129 .count = HMAC_SHA512_TEST_VECTORS
3130 }
3131 }
3132 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003133 .alg = "jitterentropy_rng",
3134 .fips_allowed = 1,
3135 .test = alg_test_null,
3136 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003137 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003138 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003139 .suite = {
3140 .cipher = {
3141 .enc = {
3142 .vecs = aes_lrw_enc_tv_template,
3143 .count = AES_LRW_ENC_TEST_VECTORS
3144 },
3145 .dec = {
3146 .vecs = aes_lrw_dec_tv_template,
3147 .count = AES_LRW_DEC_TEST_VECTORS
3148 }
3149 }
3150 }
3151 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003152 .alg = "lrw(camellia)",
3153 .test = alg_test_skcipher,
3154 .suite = {
3155 .cipher = {
3156 .enc = {
3157 .vecs = camellia_lrw_enc_tv_template,
3158 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3159 },
3160 .dec = {
3161 .vecs = camellia_lrw_dec_tv_template,
3162 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3163 }
3164 }
3165 }
3166 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003167 .alg = "lrw(cast6)",
3168 .test = alg_test_skcipher,
3169 .suite = {
3170 .cipher = {
3171 .enc = {
3172 .vecs = cast6_lrw_enc_tv_template,
3173 .count = CAST6_LRW_ENC_TEST_VECTORS
3174 },
3175 .dec = {
3176 .vecs = cast6_lrw_dec_tv_template,
3177 .count = CAST6_LRW_DEC_TEST_VECTORS
3178 }
3179 }
3180 }
3181 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003182 .alg = "lrw(serpent)",
3183 .test = alg_test_skcipher,
3184 .suite = {
3185 .cipher = {
3186 .enc = {
3187 .vecs = serpent_lrw_enc_tv_template,
3188 .count = SERPENT_LRW_ENC_TEST_VECTORS
3189 },
3190 .dec = {
3191 .vecs = serpent_lrw_dec_tv_template,
3192 .count = SERPENT_LRW_DEC_TEST_VECTORS
3193 }
3194 }
3195 }
3196 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003197 .alg = "lrw(twofish)",
3198 .test = alg_test_skcipher,
3199 .suite = {
3200 .cipher = {
3201 .enc = {
3202 .vecs = tf_lrw_enc_tv_template,
3203 .count = TF_LRW_ENC_TEST_VECTORS
3204 },
3205 .dec = {
3206 .vecs = tf_lrw_dec_tv_template,
3207 .count = TF_LRW_DEC_TEST_VECTORS
3208 }
3209 }
3210 }
3211 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003212 .alg = "lz4",
3213 .test = alg_test_comp,
3214 .fips_allowed = 1,
3215 .suite = {
3216 .comp = {
3217 .comp = {
3218 .vecs = lz4_comp_tv_template,
3219 .count = LZ4_COMP_TEST_VECTORS
3220 },
3221 .decomp = {
3222 .vecs = lz4_decomp_tv_template,
3223 .count = LZ4_DECOMP_TEST_VECTORS
3224 }
3225 }
3226 }
3227 }, {
3228 .alg = "lz4hc",
3229 .test = alg_test_comp,
3230 .fips_allowed = 1,
3231 .suite = {
3232 .comp = {
3233 .comp = {
3234 .vecs = lz4hc_comp_tv_template,
3235 .count = LZ4HC_COMP_TEST_VECTORS
3236 },
3237 .decomp = {
3238 .vecs = lz4hc_decomp_tv_template,
3239 .count = LZ4HC_DECOMP_TEST_VECTORS
3240 }
3241 }
3242 }
3243 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003244 .alg = "lzo",
3245 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003246 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003247 .suite = {
3248 .comp = {
3249 .comp = {
3250 .vecs = lzo_comp_tv_template,
3251 .count = LZO_COMP_TEST_VECTORS
3252 },
3253 .decomp = {
3254 .vecs = lzo_decomp_tv_template,
3255 .count = LZO_DECOMP_TEST_VECTORS
3256 }
3257 }
3258 }
3259 }, {
3260 .alg = "md4",
3261 .test = alg_test_hash,
3262 .suite = {
3263 .hash = {
3264 .vecs = md4_tv_template,
3265 .count = MD4_TEST_VECTORS
3266 }
3267 }
3268 }, {
3269 .alg = "md5",
3270 .test = alg_test_hash,
3271 .suite = {
3272 .hash = {
3273 .vecs = md5_tv_template,
3274 .count = MD5_TEST_VECTORS
3275 }
3276 }
3277 }, {
3278 .alg = "michael_mic",
3279 .test = alg_test_hash,
3280 .suite = {
3281 .hash = {
3282 .vecs = michael_mic_tv_template,
3283 .count = MICHAEL_MIC_TEST_VECTORS
3284 }
3285 }
3286 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003287 .alg = "ofb(aes)",
3288 .test = alg_test_skcipher,
3289 .fips_allowed = 1,
3290 .suite = {
3291 .cipher = {
3292 .enc = {
3293 .vecs = aes_ofb_enc_tv_template,
3294 .count = AES_OFB_ENC_TEST_VECTORS
3295 },
3296 .dec = {
3297 .vecs = aes_ofb_dec_tv_template,
3298 .count = AES_OFB_DEC_TEST_VECTORS
3299 }
3300 }
3301 }
3302 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003303 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003304 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003305 .suite = {
3306 .cipher = {
3307 .enc = {
3308 .vecs = fcrypt_pcbc_enc_tv_template,
3309 .count = FCRYPT_ENC_TEST_VECTORS
3310 },
3311 .dec = {
3312 .vecs = fcrypt_pcbc_dec_tv_template,
3313 .count = FCRYPT_DEC_TEST_VECTORS
3314 }
3315 }
3316 }
3317 }, {
Martin Willieee9dc62015-06-01 13:43:59 +02003318 .alg = "poly1305",
3319 .test = alg_test_hash,
3320 .suite = {
3321 .hash = {
3322 .vecs = poly1305_tv_template,
3323 .count = POLY1305_TEST_VECTORS
3324 }
3325 }
3326 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003327 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003328 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003329 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003330 .suite = {
3331 .cipher = {
3332 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003333 .vecs = aes_ctr_rfc3686_enc_tv_template,
3334 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003335 },
3336 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003337 .vecs = aes_ctr_rfc3686_dec_tv_template,
3338 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003339 }
3340 }
3341 }
3342 }, {
Adrian Hoban69435b92010-11-04 15:02:04 -04003343 .alg = "rfc4106(gcm(aes))",
3344 .test = alg_test_aead,
Jarod Wilsondb71f292015-01-23 12:42:15 -05003345 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003346 .suite = {
3347 .aead = {
3348 .enc = {
3349 .vecs = aes_gcm_rfc4106_enc_tv_template,
3350 .count = AES_GCM_4106_ENC_TEST_VECTORS
3351 },
3352 .dec = {
3353 .vecs = aes_gcm_rfc4106_dec_tv_template,
3354 .count = AES_GCM_4106_DEC_TEST_VECTORS
3355 }
3356 }
3357 }
3358 }, {
Jarod Wilson5d667322009-05-04 19:23:40 +08003359 .alg = "rfc4309(ccm(aes))",
3360 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003361 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003362 .suite = {
3363 .aead = {
3364 .enc = {
3365 .vecs = aes_ccm_rfc4309_enc_tv_template,
3366 .count = AES_CCM_4309_ENC_TEST_VECTORS
3367 },
3368 .dec = {
3369 .vecs = aes_ccm_rfc4309_dec_tv_template,
3370 .count = AES_CCM_4309_DEC_TEST_VECTORS
3371 }
3372 }
3373 }
3374 }, {
Herbert Xu14f34062015-06-16 13:54:16 +08003375 .alg = "rfc4543(gcm(aes))-disabled",
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003376 .test = alg_test_aead,
3377 .suite = {
3378 .aead = {
3379 .enc = {
3380 .vecs = aes_gcm_rfc4543_enc_tv_template,
3381 .count = AES_GCM_4543_ENC_TEST_VECTORS
3382 },
3383 .dec = {
3384 .vecs = aes_gcm_rfc4543_dec_tv_template,
3385 .count = AES_GCM_4543_DEC_TEST_VECTORS
3386 },
3387 }
3388 }
3389 }, {
Martin Williaf2b76b2015-06-01 13:44:01 +02003390 .alg = "rfc7539(chacha20,poly1305)",
3391 .test = alg_test_aead,
3392 .suite = {
3393 .aead = {
3394 .enc = {
3395 .vecs = rfc7539_enc_tv_template,
3396 .count = RFC7539_ENC_TEST_VECTORS
3397 },
3398 .dec = {
3399 .vecs = rfc7539_dec_tv_template,
3400 .count = RFC7539_DEC_TEST_VECTORS
3401 },
3402 }
3403 }
3404 }, {
Martin Willi59007582015-06-01 13:44:03 +02003405 .alg = "rfc7539esp(chacha20,poly1305)",
3406 .test = alg_test_aead,
3407 .suite = {
3408 .aead = {
3409 .enc = {
3410 .vecs = rfc7539esp_enc_tv_template,
3411 .count = RFC7539ESP_ENC_TEST_VECTORS
3412 },
3413 .dec = {
3414 .vecs = rfc7539esp_dec_tv_template,
3415 .count = RFC7539ESP_DEC_TEST_VECTORS
3416 },
3417 }
3418 }
3419 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003420 .alg = "rmd128",
3421 .test = alg_test_hash,
3422 .suite = {
3423 .hash = {
3424 .vecs = rmd128_tv_template,
3425 .count = RMD128_TEST_VECTORS
3426 }
3427 }
3428 }, {
3429 .alg = "rmd160",
3430 .test = alg_test_hash,
3431 .suite = {
3432 .hash = {
3433 .vecs = rmd160_tv_template,
3434 .count = RMD160_TEST_VECTORS
3435 }
3436 }
3437 }, {
3438 .alg = "rmd256",
3439 .test = alg_test_hash,
3440 .suite = {
3441 .hash = {
3442 .vecs = rmd256_tv_template,
3443 .count = RMD256_TEST_VECTORS
3444 }
3445 }
3446 }, {
3447 .alg = "rmd320",
3448 .test = alg_test_hash,
3449 .suite = {
3450 .hash = {
3451 .vecs = rmd320_tv_template,
3452 .count = RMD320_TEST_VECTORS
3453 }
3454 }
3455 }, {
3456 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003457 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003458 .suite = {
3459 .cipher = {
3460 .enc = {
3461 .vecs = salsa20_stream_enc_tv_template,
3462 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3463 }
3464 }
3465 }
3466 }, {
3467 .alg = "sha1",
3468 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003469 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003470 .suite = {
3471 .hash = {
3472 .vecs = sha1_tv_template,
3473 .count = SHA1_TEST_VECTORS
3474 }
3475 }
3476 }, {
3477 .alg = "sha224",
3478 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003479 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003480 .suite = {
3481 .hash = {
3482 .vecs = sha224_tv_template,
3483 .count = SHA224_TEST_VECTORS
3484 }
3485 }
3486 }, {
3487 .alg = "sha256",
3488 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003489 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003490 .suite = {
3491 .hash = {
3492 .vecs = sha256_tv_template,
3493 .count = SHA256_TEST_VECTORS
3494 }
3495 }
3496 }, {
3497 .alg = "sha384",
3498 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003499 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003500 .suite = {
3501 .hash = {
3502 .vecs = sha384_tv_template,
3503 .count = SHA384_TEST_VECTORS
3504 }
3505 }
3506 }, {
3507 .alg = "sha512",
3508 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003509 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003510 .suite = {
3511 .hash = {
3512 .vecs = sha512_tv_template,
3513 .count = SHA512_TEST_VECTORS
3514 }
3515 }
3516 }, {
3517 .alg = "tgr128",
3518 .test = alg_test_hash,
3519 .suite = {
3520 .hash = {
3521 .vecs = tgr128_tv_template,
3522 .count = TGR128_TEST_VECTORS
3523 }
3524 }
3525 }, {
3526 .alg = "tgr160",
3527 .test = alg_test_hash,
3528 .suite = {
3529 .hash = {
3530 .vecs = tgr160_tv_template,
3531 .count = TGR160_TEST_VECTORS
3532 }
3533 }
3534 }, {
3535 .alg = "tgr192",
3536 .test = alg_test_hash,
3537 .suite = {
3538 .hash = {
3539 .vecs = tgr192_tv_template,
3540 .count = TGR192_TEST_VECTORS
3541 }
3542 }
3543 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003544 .alg = "vmac(aes)",
3545 .test = alg_test_hash,
3546 .suite = {
3547 .hash = {
3548 .vecs = aes_vmac128_tv_template,
3549 .count = VMAC_AES_TEST_VECTORS
3550 }
3551 }
3552 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003553 .alg = "wp256",
3554 .test = alg_test_hash,
3555 .suite = {
3556 .hash = {
3557 .vecs = wp256_tv_template,
3558 .count = WP256_TEST_VECTORS
3559 }
3560 }
3561 }, {
3562 .alg = "wp384",
3563 .test = alg_test_hash,
3564 .suite = {
3565 .hash = {
3566 .vecs = wp384_tv_template,
3567 .count = WP384_TEST_VECTORS
3568 }
3569 }
3570 }, {
3571 .alg = "wp512",
3572 .test = alg_test_hash,
3573 .suite = {
3574 .hash = {
3575 .vecs = wp512_tv_template,
3576 .count = WP512_TEST_VECTORS
3577 }
3578 }
3579 }, {
3580 .alg = "xcbc(aes)",
3581 .test = alg_test_hash,
3582 .suite = {
3583 .hash = {
3584 .vecs = aes_xcbc128_tv_template,
3585 .count = XCBC_AES_TEST_VECTORS
3586 }
3587 }
3588 }, {
3589 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003590 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003591 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003592 .suite = {
3593 .cipher = {
3594 .enc = {
3595 .vecs = aes_xts_enc_tv_template,
3596 .count = AES_XTS_ENC_TEST_VECTORS
3597 },
3598 .dec = {
3599 .vecs = aes_xts_dec_tv_template,
3600 .count = AES_XTS_DEC_TEST_VECTORS
3601 }
3602 }
3603 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003604 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003605 .alg = "xts(camellia)",
3606 .test = alg_test_skcipher,
3607 .suite = {
3608 .cipher = {
3609 .enc = {
3610 .vecs = camellia_xts_enc_tv_template,
3611 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3612 },
3613 .dec = {
3614 .vecs = camellia_xts_dec_tv_template,
3615 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3616 }
3617 }
3618 }
3619 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003620 .alg = "xts(cast6)",
3621 .test = alg_test_skcipher,
3622 .suite = {
3623 .cipher = {
3624 .enc = {
3625 .vecs = cast6_xts_enc_tv_template,
3626 .count = CAST6_XTS_ENC_TEST_VECTORS
3627 },
3628 .dec = {
3629 .vecs = cast6_xts_dec_tv_template,
3630 .count = CAST6_XTS_DEC_TEST_VECTORS
3631 }
3632 }
3633 }
3634 }, {
Jussi Kivilinna18be20b2011-10-18 13:33:17 +03003635 .alg = "xts(serpent)",
3636 .test = alg_test_skcipher,
3637 .suite = {
3638 .cipher = {
3639 .enc = {
3640 .vecs = serpent_xts_enc_tv_template,
3641 .count = SERPENT_XTS_ENC_TEST_VECTORS
3642 },
3643 .dec = {
3644 .vecs = serpent_xts_dec_tv_template,
3645 .count = SERPENT_XTS_DEC_TEST_VECTORS
3646 }
3647 }
3648 }
3649 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003650 .alg = "xts(twofish)",
3651 .test = alg_test_skcipher,
3652 .suite = {
3653 .cipher = {
3654 .enc = {
3655 .vecs = tf_xts_enc_tv_template,
3656 .count = TF_XTS_ENC_TEST_VECTORS
3657 },
3658 .dec = {
3659 .vecs = tf_xts_dec_tv_template,
3660 .count = TF_XTS_DEC_TEST_VECTORS
3661 }
3662 }
3663 }
3664 }, {
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003665 .alg = "zlib",
3666 .test = alg_test_pcomp,
Milan Broz08189042012-12-06 17:16:28 +08003667 .fips_allowed = 1,
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003668 .suite = {
3669 .pcomp = {
3670 .comp = {
3671 .vecs = zlib_comp_tv_template,
3672 .count = ZLIB_COMP_TEST_VECTORS
3673 },
3674 .decomp = {
3675 .vecs = zlib_decomp_tv_template,
3676 .count = ZLIB_DECOMP_TEST_VECTORS
3677 }
3678 }
3679 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003680 }
3681};
3682
Jussi Kivilinna57147582013-06-13 17:37:40 +03003683static bool alg_test_descs_checked;
3684
3685static void alg_test_descs_check_order(void)
3686{
3687 int i;
3688
3689 /* only check once */
3690 if (alg_test_descs_checked)
3691 return;
3692
3693 alg_test_descs_checked = true;
3694
3695 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3696 int diff = strcmp(alg_test_descs[i - 1].alg,
3697 alg_test_descs[i].alg);
3698
3699 if (WARN_ON(diff > 0)) {
3700 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3701 alg_test_descs[i - 1].alg,
3702 alg_test_descs[i].alg);
3703 }
3704
3705 if (WARN_ON(diff == 0)) {
3706 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3707 alg_test_descs[i].alg);
3708 }
3709 }
3710}
3711
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003712static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003713{
3714 int start = 0;
3715 int end = ARRAY_SIZE(alg_test_descs);
3716
3717 while (start < end) {
3718 int i = (start + end) / 2;
3719 int diff = strcmp(alg_test_descs[i].alg, alg);
3720
3721 if (diff > 0) {
3722 end = i;
3723 continue;
3724 }
3725
3726 if (diff < 0) {
3727 start = i + 1;
3728 continue;
3729 }
3730
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003731 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003732 }
3733
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003734 return -1;
3735}
3736
3737int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3738{
3739 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003740 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003741 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003742
Jussi Kivilinna57147582013-06-13 17:37:40 +03003743 alg_test_descs_check_order();
3744
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003745 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3746 char nalg[CRYPTO_MAX_ALG_NAME];
3747
3748 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3749 sizeof(nalg))
3750 return -ENAMETOOLONG;
3751
3752 i = alg_find_test(nalg);
3753 if (i < 0)
3754 goto notest;
3755
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003756 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3757 goto non_fips_alg;
3758
Jarod Wilson941fb322009-05-04 19:49:23 +08003759 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3760 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003761 }
3762
3763 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003764 j = alg_find_test(driver);
3765 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003766 goto notest;
3767
Herbert Xua68f6612009-07-02 16:32:12 +08003768 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3769 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003770 goto non_fips_alg;
3771
Herbert Xua68f6612009-07-02 16:32:12 +08003772 rc = 0;
3773 if (i >= 0)
3774 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3775 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003776 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003777 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3778 type, mask);
3779
Jarod Wilson941fb322009-05-04 19:49:23 +08003780test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003781 if (fips_enabled && rc)
3782 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3783
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003784 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09003785 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003786
Neil Hormand12d6b62008-10-12 20:36:51 +08003787 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003788
3789notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003790 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3791 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003792non_fips_alg:
3793 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003794}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003795
Herbert Xu326a6342010-08-06 09:40:28 +08003796#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003797
Herbert Xuda7f0332008-07-31 17:08:25 +08003798EXPORT_SYMBOL_GPL(alg_test);