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