blob: 25032b0fd9ed226890752d1cb68ddf3f32b0766b [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>
Herbert Xu12773d92015-08-20 15:21:46 +080025#include <crypto/skcipher.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080026#include <linux/err.h>
Herbert Xu1c41b882015-04-22 13:25:58 +080027#include <linux/fips.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080028#include <linux/module.h>
29#include <linux/scatterlist.h>
30#include <linux/slab.h>
31#include <linux/string.h>
Jarod Wilson7647d6c2009-05-04 19:44:50 +080032#include <crypto/rng.h>
Stephan Mueller64d1cdf2014-05-31 17:25:36 +020033#include <crypto/drbg.h>
Tadeusz Struk946cc462015-06-16 10:31:06 -070034#include <crypto/akcipher.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080035
36#include "internal.h"
Alexander Shishkin0b767f92010-06-03 20:53:43 +100037
Herbert Xu326a6342010-08-06 09:40:28 +080038#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
Alexander Shishkin0b767f92010-06-03 20:53:43 +100039
40/* a perfect nop */
41int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
42{
43 return 0;
44}
45
46#else
47
Herbert Xuda7f0332008-07-31 17:08:25 +080048#include "testmgr.h"
49
50/*
51 * Need slab memory for testing (size in number of pages).
52 */
53#define XBUFSIZE 8
54
55/*
56 * Indexes into the xbuf to simulate cross-page access.
57 */
58#define IDX1 32
59#define IDX2 32400
60#define IDX3 1
61#define IDX4 8193
62#define IDX5 22222
63#define IDX6 17101
64#define IDX7 27333
65#define IDX8 3000
66
67/*
68* Used by test_cipher()
69*/
70#define ENCRYPT 1
71#define DECRYPT 0
72
73struct tcrypt_result {
74 struct completion completion;
75 int err;
76};
77
78struct aead_test_suite {
79 struct {
80 struct aead_testvec *vecs;
81 unsigned int count;
82 } enc, dec;
83};
84
85struct cipher_test_suite {
86 struct {
87 struct cipher_testvec *vecs;
88 unsigned int count;
89 } enc, dec;
90};
91
92struct comp_test_suite {
93 struct {
94 struct comp_testvec *vecs;
95 unsigned int count;
96 } comp, decomp;
97};
98
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +080099struct pcomp_test_suite {
100 struct {
101 struct pcomp_testvec *vecs;
102 unsigned int count;
103 } comp, decomp;
104};
105
Herbert Xuda7f0332008-07-31 17:08:25 +0800106struct hash_test_suite {
107 struct hash_testvec *vecs;
108 unsigned int count;
109};
110
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800111struct cprng_test_suite {
112 struct cprng_testvec *vecs;
113 unsigned int count;
114};
115
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200116struct drbg_test_suite {
117 struct drbg_testvec *vecs;
118 unsigned int count;
119};
120
Tadeusz Struk946cc462015-06-16 10:31:06 -0700121struct akcipher_test_suite {
122 struct akcipher_testvec *vecs;
123 unsigned int count;
124};
125
Herbert Xuda7f0332008-07-31 17:08:25 +0800126struct alg_test_desc {
127 const char *alg;
128 int (*test)(const struct alg_test_desc *desc, const char *driver,
129 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000130 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800131
132 union {
133 struct aead_test_suite aead;
134 struct cipher_test_suite cipher;
135 struct comp_test_suite comp;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +0800136 struct pcomp_test_suite pcomp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800137 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800138 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200139 struct drbg_test_suite drbg;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700140 struct akcipher_test_suite akcipher;
Herbert Xuda7f0332008-07-31 17:08:25 +0800141 } suite;
142};
143
144static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
145
Herbert Xuda7f0332008-07-31 17:08:25 +0800146static void hexdump(unsigned char *buf, unsigned int len)
147{
148 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
149 16, 1,
150 buf, len, false);
151}
152
153static void tcrypt_complete(struct crypto_async_request *req, int err)
154{
155 struct tcrypt_result *res = req->data;
156
157 if (err == -EINPROGRESS)
158 return;
159
160 res->err = err;
161 complete(&res->completion);
162}
163
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800164static int testmgr_alloc_buf(char *buf[XBUFSIZE])
165{
166 int i;
167
168 for (i = 0; i < XBUFSIZE; i++) {
169 buf[i] = (void *)__get_free_page(GFP_KERNEL);
170 if (!buf[i])
171 goto err_free_buf;
172 }
173
174 return 0;
175
176err_free_buf:
177 while (i-- > 0)
178 free_page((unsigned long)buf[i]);
179
180 return -ENOMEM;
181}
182
183static void testmgr_free_buf(char *buf[XBUFSIZE])
184{
185 int i;
186
187 for (i = 0; i < XBUFSIZE; i++)
188 free_page((unsigned long)buf[i]);
189}
190
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300191static int wait_async_op(struct tcrypt_result *tr, int ret)
David S. Millera8f1a052010-05-19 14:12:03 +1000192{
193 if (ret == -EINPROGRESS || ret == -EBUSY) {
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100194 wait_for_completion(&tr->completion);
Wolfram Sang16735d02013-11-14 14:32:02 -0800195 reinit_completion(&tr->completion);
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100196 ret = tr->err;
David S. Millera8f1a052010-05-19 14:12:03 +1000197 }
198 return ret;
199}
200
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300201static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
202 unsigned int tcount, bool use_digest,
203 const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800204{
205 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
206 unsigned int i, j, k, temp;
207 struct scatterlist sg[8];
Horia Geanta29b77e52014-07-23 11:59:38 +0300208 char *result;
209 char *key;
Herbert Xuda7f0332008-07-31 17:08:25 +0800210 struct ahash_request *req;
211 struct tcrypt_result tresult;
Herbert Xuda7f0332008-07-31 17:08:25 +0800212 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800213 char *xbuf[XBUFSIZE];
214 int ret = -ENOMEM;
215
Horia Geanta29b77e52014-07-23 11:59:38 +0300216 result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
217 if (!result)
218 return ret;
219 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
220 if (!key)
221 goto out_nobuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800222 if (testmgr_alloc_buf(xbuf))
223 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800224
225 init_completion(&tresult.completion);
226
227 req = ahash_request_alloc(tfm, GFP_KERNEL);
228 if (!req) {
229 printk(KERN_ERR "alg: hash: Failed to allocate request for "
230 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800231 goto out_noreq;
232 }
233 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
234 tcrypt_complete, &tresult);
235
Herbert Xua0cfae52009-05-29 16:23:12 +1000236 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800237 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000238 if (template[i].np)
239 continue;
240
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300241 ret = -EINVAL;
242 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
243 goto out;
244
Herbert Xua0cfae52009-05-29 16:23:12 +1000245 j++;
Horia Geanta29b77e52014-07-23 11:59:38 +0300246 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800247
248 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300249 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800250
251 memcpy(hash_buff, template[i].plaintext, template[i].psize);
252 sg_init_one(&sg[0], hash_buff, template[i].psize);
253
254 if (template[i].ksize) {
255 crypto_ahash_clear_flags(tfm, ~0);
Horia Geanta29b77e52014-07-23 11:59:38 +0300256 if (template[i].ksize > MAX_KEYLEN) {
257 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
258 j, algo, template[i].ksize, MAX_KEYLEN);
259 ret = -EINVAL;
260 goto out;
261 }
262 memcpy(key, template[i].key, template[i].ksize);
263 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
Herbert Xuda7f0332008-07-31 17:08:25 +0800264 if (ret) {
265 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000266 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800267 -ret);
268 goto out;
269 }
270 }
271
272 ahash_request_set_crypt(req, sg, result, template[i].psize);
David S. Millera8f1a052010-05-19 14:12:03 +1000273 if (use_digest) {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300274 ret = wait_async_op(&tresult, crypto_ahash_digest(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000275 if (ret) {
276 pr_err("alg: hash: digest failed on test %d "
277 "for %s: ret=%d\n", j, algo, -ret);
278 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800279 }
David S. Millera8f1a052010-05-19 14:12:03 +1000280 } else {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300281 ret = wait_async_op(&tresult, crypto_ahash_init(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000282 if (ret) {
283 pr_err("alt: hash: init failed on test %d "
284 "for %s: ret=%d\n", j, algo, -ret);
285 goto out;
286 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300287 ret = wait_async_op(&tresult, crypto_ahash_update(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000288 if (ret) {
289 pr_err("alt: hash: update failed on test %d "
290 "for %s: ret=%d\n", j, algo, -ret);
291 goto out;
292 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300293 ret = wait_async_op(&tresult, crypto_ahash_final(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000294 if (ret) {
295 pr_err("alt: hash: final failed on test %d "
296 "for %s: ret=%d\n", j, algo, -ret);
297 goto out;
298 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800299 }
300
301 if (memcmp(result, template[i].digest,
302 crypto_ahash_digestsize(tfm))) {
303 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000304 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800305 hexdump(result, crypto_ahash_digestsize(tfm));
306 ret = -EINVAL;
307 goto out;
308 }
309 }
310
311 j = 0;
312 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300313 /* alignment tests are only done with continuous buffers */
314 if (align_offset != 0)
315 break;
316
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300317 if (!template[i].np)
318 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800319
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300320 j++;
321 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800322
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300323 temp = 0;
324 sg_init_table(sg, template[i].np);
325 ret = -EINVAL;
326 for (k = 0; k < template[i].np; k++) {
327 if (WARN_ON(offset_in_page(IDX[k]) +
328 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +0800329 goto out;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300330 sg_set_buf(&sg[k],
331 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
332 offset_in_page(IDX[k]),
333 template[i].plaintext + temp,
334 template[i].tap[k]),
335 template[i].tap[k]);
336 temp += template[i].tap[k];
337 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800338
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300339 if (template[i].ksize) {
340 if (template[i].ksize > MAX_KEYLEN) {
341 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
342 j, algo, template[i].ksize, MAX_KEYLEN);
Herbert Xuda7f0332008-07-31 17:08:25 +0800343 ret = -EINVAL;
344 goto out;
345 }
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300346 crypto_ahash_clear_flags(tfm, ~0);
347 memcpy(key, template[i].key, template[i].ksize);
348 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
349
350 if (ret) {
351 printk(KERN_ERR "alg: hash: setkey "
352 "failed on chunking test %d "
353 "for %s: ret=%d\n", j, algo, -ret);
354 goto out;
355 }
356 }
357
358 ahash_request_set_crypt(req, sg, result, template[i].psize);
359 ret = crypto_ahash_digest(req);
360 switch (ret) {
361 case 0:
362 break;
363 case -EINPROGRESS:
364 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100365 wait_for_completion(&tresult.completion);
366 reinit_completion(&tresult.completion);
367 ret = tresult.err;
368 if (!ret)
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300369 break;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300370 /* fall through */
371 default:
372 printk(KERN_ERR "alg: hash: digest failed "
373 "on chunking test %d for %s: "
374 "ret=%d\n", j, algo, -ret);
375 goto out;
376 }
377
378 if (memcmp(result, template[i].digest,
379 crypto_ahash_digestsize(tfm))) {
380 printk(KERN_ERR "alg: hash: Chunking test %d "
381 "failed for %s\n", j, algo);
382 hexdump(result, crypto_ahash_digestsize(tfm));
383 ret = -EINVAL;
384 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800385 }
386 }
387
388 ret = 0;
389
390out:
391 ahash_request_free(req);
392out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800393 testmgr_free_buf(xbuf);
394out_nobuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300395 kfree(key);
396 kfree(result);
Herbert Xuda7f0332008-07-31 17:08:25 +0800397 return ret;
398}
399
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300400static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
401 unsigned int tcount, bool use_digest)
402{
403 unsigned int alignmask;
404 int ret;
405
406 ret = __test_hash(tfm, template, tcount, use_digest, 0);
407 if (ret)
408 return ret;
409
410 /* test unaligned buffers, check with one byte offset */
411 ret = __test_hash(tfm, template, tcount, use_digest, 1);
412 if (ret)
413 return ret;
414
415 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
416 if (alignmask) {
417 /* Check if alignment mask for tfm is correctly set. */
418 ret = __test_hash(tfm, template, tcount, use_digest,
419 alignmask + 1);
420 if (ret)
421 return ret;
422 }
423
424 return 0;
425}
426
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300427static int __test_aead(struct crypto_aead *tfm, int enc,
428 struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300429 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800430{
431 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
432 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800433 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800434 char *q;
435 char *key;
436 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300437 struct scatterlist *sg;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300438 struct scatterlist *sgout;
439 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800440 struct tcrypt_result result;
Cristian Stoica424a5da2015-01-28 11:03:05 +0200441 unsigned int authsize, iv_len;
Herbert Xuda7f0332008-07-31 17:08:25 +0800442 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300443 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800444 void *assoc;
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700445 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800446 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300447 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800448 char *axbuf[XBUFSIZE];
449
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700450 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
451 if (!iv)
452 return ret;
Horia Geanta29b77e52014-07-23 11:59:38 +0300453 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
454 if (!key)
455 goto out_noxbuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800456 if (testmgr_alloc_buf(xbuf))
457 goto out_noxbuf;
458 if (testmgr_alloc_buf(axbuf))
459 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300460 if (diff_dst && testmgr_alloc_buf(xoutbuf))
461 goto out_nooutbuf;
462
463 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
Herbert Xu8a525fc2015-05-27 16:03:43 +0800464 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 4 : 2), GFP_KERNEL);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300465 if (!sg)
466 goto out_nosg;
Herbert Xu8a525fc2015-05-27 16:03:43 +0800467 sgout = &sg[16];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300468
469 if (diff_dst)
470 d = "-ddst";
471 else
472 d = "";
473
Herbert Xuda7f0332008-07-31 17:08:25 +0800474 if (enc == ENCRYPT)
475 e = "encryption";
476 else
477 e = "decryption";
478
479 init_completion(&result.completion);
480
481 req = aead_request_alloc(tfm, GFP_KERNEL);
482 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300483 pr_err("alg: aead%s: Failed to allocate request for %s\n",
484 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800485 goto out;
486 }
487
488 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
489 tcrypt_complete, &result);
490
491 for (i = 0, j = 0; i < tcount; i++) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300492 if (template[i].np)
493 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800494
Cristian Stoica05b1d332014-07-28 13:11:23 +0300495 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800496
Cristian Stoica05b1d332014-07-28 13:11:23 +0300497 /* some templates have no input data but they will
498 * touch input
499 */
500 input = xbuf[0];
501 input += align_offset;
502 assoc = axbuf[0];
503
504 ret = -EINVAL;
505 if (WARN_ON(align_offset + template[i].ilen >
506 PAGE_SIZE || template[i].alen > PAGE_SIZE))
507 goto out;
508
509 memcpy(input, template[i].input, template[i].ilen);
510 memcpy(assoc, template[i].assoc, template[i].alen);
Cristian Stoica424a5da2015-01-28 11:03:05 +0200511 iv_len = crypto_aead_ivsize(tfm);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300512 if (template[i].iv)
Cristian Stoica424a5da2015-01-28 11:03:05 +0200513 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300514 else
Cristian Stoica424a5da2015-01-28 11:03:05 +0200515 memset(iv, 0, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300516
517 crypto_aead_clear_flags(tfm, ~0);
518 if (template[i].wk)
519 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
520
521 if (template[i].klen > MAX_KEYLEN) {
522 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
523 d, j, algo, template[i].klen,
524 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +1000525 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300526 goto out;
527 }
528 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +1000529
Cristian Stoica05b1d332014-07-28 13:11:23 +0300530 ret = crypto_aead_setkey(tfm, key, template[i].klen);
531 if (!ret == template[i].fail) {
532 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
533 d, j, algo, crypto_aead_get_flags(tfm));
534 goto out;
535 } else if (ret)
536 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800537
Cristian Stoica05b1d332014-07-28 13:11:23 +0300538 authsize = abs(template[i].rlen - template[i].ilen);
539 ret = crypto_aead_setauthsize(tfm, authsize);
540 if (ret) {
541 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
542 d, authsize, j, algo);
543 goto out;
544 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800545
Herbert Xu8a525fc2015-05-27 16:03:43 +0800546 k = !!template[i].alen;
547 sg_init_table(sg, k + 1);
548 sg_set_buf(&sg[0], assoc, template[i].alen);
549 sg_set_buf(&sg[k], input,
550 template[i].ilen + (enc ? authsize : 0));
551 output = input;
552
Cristian Stoica05b1d332014-07-28 13:11:23 +0300553 if (diff_dst) {
Herbert Xu8a525fc2015-05-27 16:03:43 +0800554 sg_init_table(sgout, k + 1);
555 sg_set_buf(&sgout[0], assoc, template[i].alen);
556
Cristian Stoica05b1d332014-07-28 13:11:23 +0300557 output = xoutbuf[0];
558 output += align_offset;
Herbert Xu8a525fc2015-05-27 16:03:43 +0800559 sg_set_buf(&sgout[k], output,
560 template[i].rlen + (enc ? 0 : authsize));
Cristian Stoica05b1d332014-07-28 13:11:23 +0300561 }
562
Cristian Stoica05b1d332014-07-28 13:11:23 +0300563 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
564 template[i].ilen, iv);
565
Herbert Xu8a525fc2015-05-27 16:03:43 +0800566 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300567
568 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
569
570 switch (ret) {
571 case 0:
572 if (template[i].novrfy) {
573 /* verification was supposed to fail */
574 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
575 d, e, j, algo);
576 /* so really, we got a bad message */
577 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +0300578 goto out;
579 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300580 break;
581 case -EINPROGRESS:
582 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100583 wait_for_completion(&result.completion);
584 reinit_completion(&result.completion);
585 ret = result.err;
586 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +0800587 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300588 case -EBADMSG:
589 if (template[i].novrfy)
590 /* verification failure was expected */
591 continue;
592 /* fall through */
593 default:
594 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
595 d, e, j, algo, -ret);
596 goto out;
597 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800598
Cristian Stoica05b1d332014-07-28 13:11:23 +0300599 q = output;
600 if (memcmp(q, template[i].result, template[i].rlen)) {
601 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
602 d, j, e, algo);
603 hexdump(q, template[i].rlen);
604 ret = -EINVAL;
605 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800606 }
607 }
608
609 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300610 /* alignment tests are only done with continuous buffers */
611 if (align_offset != 0)
612 break;
613
Cristian Stoica05b1d332014-07-28 13:11:23 +0300614 if (!template[i].np)
615 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800616
Cristian Stoica05b1d332014-07-28 13:11:23 +0300617 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800618
Cristian Stoica05b1d332014-07-28 13:11:23 +0300619 if (template[i].iv)
620 memcpy(iv, template[i].iv, MAX_IVLEN);
621 else
622 memset(iv, 0, MAX_IVLEN);
623
624 crypto_aead_clear_flags(tfm, ~0);
625 if (template[i].wk)
626 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
627 if (template[i].klen > MAX_KEYLEN) {
628 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
629 d, j, algo, template[i].klen, MAX_KEYLEN);
630 ret = -EINVAL;
631 goto out;
632 }
633 memcpy(key, template[i].key, template[i].klen);
634
635 ret = crypto_aead_setkey(tfm, key, template[i].klen);
636 if (!ret == template[i].fail) {
637 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
638 d, j, algo, crypto_aead_get_flags(tfm));
639 goto out;
640 } else if (ret)
641 continue;
642
643 authsize = abs(template[i].rlen - template[i].ilen);
644
645 ret = -EINVAL;
Herbert Xu8a525fc2015-05-27 16:03:43 +0800646 sg_init_table(sg, template[i].anp + template[i].np);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300647 if (diff_dst)
Herbert Xu8a525fc2015-05-27 16:03:43 +0800648 sg_init_table(sgout, template[i].anp + template[i].np);
649
650 ret = -EINVAL;
651 for (k = 0, temp = 0; k < template[i].anp; k++) {
652 if (WARN_ON(offset_in_page(IDX[k]) +
653 template[i].atap[k] > PAGE_SIZE))
654 goto out;
655 sg_set_buf(&sg[k],
656 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
657 offset_in_page(IDX[k]),
658 template[i].assoc + temp,
659 template[i].atap[k]),
660 template[i].atap[k]);
661 if (diff_dst)
662 sg_set_buf(&sgout[k],
663 axbuf[IDX[k] >> PAGE_SHIFT] +
664 offset_in_page(IDX[k]),
665 template[i].atap[k]);
666 temp += template[i].atap[k];
667 }
668
Cristian Stoica05b1d332014-07-28 13:11:23 +0300669 for (k = 0, temp = 0; k < template[i].np; k++) {
670 if (WARN_ON(offset_in_page(IDX[k]) +
671 template[i].tap[k] > PAGE_SIZE))
672 goto out;
673
674 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
675 memcpy(q, template[i].input + temp, template[i].tap[k]);
Herbert Xu8a525fc2015-05-27 16:03:43 +0800676 sg_set_buf(&sg[template[i].anp + k],
677 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300678
679 if (diff_dst) {
680 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
681 offset_in_page(IDX[k]);
682
683 memset(q, 0, template[i].tap[k]);
684
Herbert Xu8a525fc2015-05-27 16:03:43 +0800685 sg_set_buf(&sgout[template[i].anp + k],
686 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300687 }
688
689 n = template[i].tap[k];
690 if (k == template[i].np - 1 && enc)
691 n += authsize;
692 if (offset_in_page(q) + n < PAGE_SIZE)
693 q[n] = 0;
694
695 temp += template[i].tap[k];
696 }
697
698 ret = crypto_aead_setauthsize(tfm, authsize);
699 if (ret) {
700 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
701 d, authsize, j, algo);
702 goto out;
703 }
704
705 if (enc) {
Herbert Xu8a525fc2015-05-27 16:03:43 +0800706 if (WARN_ON(sg[template[i].anp + k - 1].offset +
707 sg[template[i].anp + k - 1].length +
708 authsize > PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300709 ret = -EINVAL;
710 goto out;
711 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800712
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300713 if (diff_dst)
Herbert Xu8a525fc2015-05-27 16:03:43 +0800714 sgout[template[i].anp + k - 1].length +=
715 authsize;
716 sg[template[i].anp + k - 1].length += authsize;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300717 }
718
719 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
720 template[i].ilen,
721 iv);
722
Herbert Xu8a525fc2015-05-27 16:03:43 +0800723 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300724
725 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
726
727 switch (ret) {
728 case 0:
729 if (template[i].novrfy) {
730 /* verification was supposed to fail */
731 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
732 d, e, j, algo);
733 /* so really, we got a bad message */
734 ret = -EBADMSG;
735 goto out;
736 }
737 break;
738 case -EINPROGRESS:
739 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100740 wait_for_completion(&result.completion);
741 reinit_completion(&result.completion);
742 ret = result.err;
743 if (!ret)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300744 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300745 case -EBADMSG:
746 if (template[i].novrfy)
747 /* verification failure was expected */
748 continue;
749 /* fall through */
750 default:
751 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
752 d, e, j, algo, -ret);
753 goto out;
754 }
755
756 ret = -EINVAL;
757 for (k = 0, temp = 0; k < template[i].np; k++) {
758 if (diff_dst)
759 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
760 offset_in_page(IDX[k]);
761 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800762 q = xbuf[IDX[k] >> PAGE_SHIFT] +
763 offset_in_page(IDX[k]);
764
Cristian Stoica05b1d332014-07-28 13:11:23 +0300765 n = template[i].tap[k];
766 if (k == template[i].np - 1)
767 n += enc ? authsize : -authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800768
Cristian Stoica05b1d332014-07-28 13:11:23 +0300769 if (memcmp(q, template[i].result + temp, n)) {
770 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
771 d, j, e, k, algo);
772 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800773 goto out;
774 }
775
Cristian Stoica05b1d332014-07-28 13:11:23 +0300776 q += n;
777 if (k == template[i].np - 1 && !enc) {
778 if (!diff_dst &&
779 memcmp(q, template[i].input +
780 temp + n, authsize))
781 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200782 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300783 n = 0;
784 } else {
785 for (n = 0; offset_in_page(q + n) && q[n]; n++)
786 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800787 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300788 if (n) {
789 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
790 d, j, e, k, algo, n);
791 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800792 goto out;
793 }
794
Cristian Stoica05b1d332014-07-28 13:11:23 +0300795 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800796 }
797 }
798
799 ret = 0;
800
801out:
802 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300803 kfree(sg);
804out_nosg:
805 if (diff_dst)
806 testmgr_free_buf(xoutbuf);
807out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800808 testmgr_free_buf(axbuf);
809out_noaxbuf:
810 testmgr_free_buf(xbuf);
811out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300812 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700813 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800814 return ret;
815}
816
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300817static int test_aead(struct crypto_aead *tfm, int enc,
818 struct aead_testvec *template, unsigned int tcount)
819{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300820 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300821 int ret;
822
823 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300824 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300825 if (ret)
826 return ret;
827
828 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300829 ret = __test_aead(tfm, enc, template, tcount, true, 0);
830 if (ret)
831 return ret;
832
833 /* test unaligned buffers, check with one byte offset */
834 ret = __test_aead(tfm, enc, template, tcount, true, 1);
835 if (ret)
836 return ret;
837
838 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
839 if (alignmask) {
840 /* Check if alignment mask for tfm is correctly set. */
841 ret = __test_aead(tfm, enc, template, tcount, true,
842 alignmask + 1);
843 if (ret)
844 return ret;
845 }
846
847 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300848}
849
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000850static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800851 struct cipher_testvec *template, unsigned int tcount)
852{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000853 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
854 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000855 char *q;
856 const char *e;
857 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800858 char *xbuf[XBUFSIZE];
859 int ret = -ENOMEM;
860
861 if (testmgr_alloc_buf(xbuf))
862 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000863
864 if (enc == ENCRYPT)
865 e = "encryption";
866 else
867 e = "decryption";
868
869 j = 0;
870 for (i = 0; i < tcount; i++) {
871 if (template[i].np)
872 continue;
873
874 j++;
875
Herbert Xufd57f222009-05-29 16:05:42 +1000876 ret = -EINVAL;
877 if (WARN_ON(template[i].ilen > PAGE_SIZE))
878 goto out;
879
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000880 data = xbuf[0];
881 memcpy(data, template[i].input, template[i].ilen);
882
883 crypto_cipher_clear_flags(tfm, ~0);
884 if (template[i].wk)
885 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
886
887 ret = crypto_cipher_setkey(tfm, template[i].key,
888 template[i].klen);
889 if (!ret == template[i].fail) {
890 printk(KERN_ERR "alg: cipher: setkey failed "
891 "on test %d for %s: flags=%x\n", j,
892 algo, crypto_cipher_get_flags(tfm));
893 goto out;
894 } else if (ret)
895 continue;
896
897 for (k = 0; k < template[i].ilen;
898 k += crypto_cipher_blocksize(tfm)) {
899 if (enc)
900 crypto_cipher_encrypt_one(tfm, data + k,
901 data + k);
902 else
903 crypto_cipher_decrypt_one(tfm, data + k,
904 data + k);
905 }
906
907 q = data;
908 if (memcmp(q, template[i].result, template[i].rlen)) {
909 printk(KERN_ERR "alg: cipher: Test %d failed "
910 "on %s for %s\n", j, e, algo);
911 hexdump(q, template[i].rlen);
912 ret = -EINVAL;
913 goto out;
914 }
915 }
916
917 ret = 0;
918
919out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800920 testmgr_free_buf(xbuf);
921out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000922 return ret;
923}
924
Herbert Xu12773d92015-08-20 15:21:46 +0800925static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300926 struct cipher_testvec *template, unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300927 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000928{
Herbert Xuda7f0332008-07-31 17:08:25 +0800929 const char *algo =
Herbert Xu12773d92015-08-20 15:21:46 +0800930 crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +0800931 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800932 char *q;
Herbert Xu12773d92015-08-20 15:21:46 +0800933 struct skcipher_request *req;
Herbert Xuda7f0332008-07-31 17:08:25 +0800934 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300935 struct scatterlist sgout[8];
936 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800937 struct tcrypt_result result;
938 void *data;
939 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800940 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300941 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800942 int ret = -ENOMEM;
Andrey Ryabinin84cba172015-09-10 13:11:55 +0300943 unsigned int ivsize = crypto_skcipher_ivsize(tfm);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800944
945 if (testmgr_alloc_buf(xbuf))
946 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800947
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300948 if (diff_dst && testmgr_alloc_buf(xoutbuf))
949 goto out_nooutbuf;
950
951 if (diff_dst)
952 d = "-ddst";
953 else
954 d = "";
955
Herbert Xuda7f0332008-07-31 17:08:25 +0800956 if (enc == ENCRYPT)
957 e = "encryption";
958 else
959 e = "decryption";
960
961 init_completion(&result.completion);
962
Herbert Xu12773d92015-08-20 15:21:46 +0800963 req = skcipher_request_alloc(tfm, GFP_KERNEL);
Herbert Xuda7f0332008-07-31 17:08:25 +0800964 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300965 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
966 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800967 goto out;
968 }
969
Herbert Xu12773d92015-08-20 15:21:46 +0800970 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
971 tcrypt_complete, &result);
Herbert Xuda7f0332008-07-31 17:08:25 +0800972
973 j = 0;
974 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +0300975 if (template[i].np && !template[i].also_non_np)
976 continue;
977
Herbert Xuda7f0332008-07-31 17:08:25 +0800978 if (template[i].iv)
Andrey Ryabinin84cba172015-09-10 13:11:55 +0300979 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +0800980 else
981 memset(iv, 0, MAX_IVLEN);
982
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300983 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300984 ret = -EINVAL;
985 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
986 goto out;
987
988 data = xbuf[0];
989 data += align_offset;
990 memcpy(data, template[i].input, template[i].ilen);
991
Herbert Xu12773d92015-08-20 15:21:46 +0800992 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300993 if (template[i].wk)
Herbert Xu12773d92015-08-20 15:21:46 +0800994 crypto_skcipher_set_flags(tfm,
995 CRYPTO_TFM_REQ_WEAK_KEY);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300996
Herbert Xu12773d92015-08-20 15:21:46 +0800997 ret = crypto_skcipher_setkey(tfm, template[i].key,
998 template[i].klen);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300999 if (!ret == template[i].fail) {
1000 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001001 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001002 goto out;
1003 } else if (ret)
1004 continue;
1005
1006 sg_init_one(&sg[0], data, template[i].ilen);
1007 if (diff_dst) {
1008 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001009 data += align_offset;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001010 sg_init_one(&sgout[0], data, template[i].ilen);
1011 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001012
Herbert Xu12773d92015-08-20 15:21:46 +08001013 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1014 template[i].ilen, iv);
1015 ret = enc ? crypto_skcipher_encrypt(req) :
1016 crypto_skcipher_decrypt(req);
Herbert Xuda7f0332008-07-31 17:08:25 +08001017
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001018 switch (ret) {
1019 case 0:
1020 break;
1021 case -EINPROGRESS:
1022 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001023 wait_for_completion(&result.completion);
1024 reinit_completion(&result.completion);
1025 ret = result.err;
1026 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +08001027 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001028 /* fall through */
1029 default:
1030 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1031 d, e, j, algo, -ret);
1032 goto out;
1033 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001034
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001035 q = data;
1036 if (memcmp(q, template[i].result, template[i].rlen)) {
1037 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1038 d, j, e, algo);
1039 hexdump(q, template[i].rlen);
1040 ret = -EINVAL;
1041 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001042 }
1043 }
1044
1045 j = 0;
1046 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001047 /* alignment tests are only done with continuous buffers */
1048 if (align_offset != 0)
1049 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001050
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001051 if (!template[i].np)
1052 continue;
1053
Herbert Xuda7f0332008-07-31 17:08:25 +08001054 if (template[i].iv)
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001055 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001056 else
1057 memset(iv, 0, MAX_IVLEN);
1058
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001059 j++;
Herbert Xu12773d92015-08-20 15:21:46 +08001060 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001061 if (template[i].wk)
Herbert Xu12773d92015-08-20 15:21:46 +08001062 crypto_skcipher_set_flags(tfm,
1063 CRYPTO_TFM_REQ_WEAK_KEY);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001064
Herbert Xu12773d92015-08-20 15:21:46 +08001065 ret = crypto_skcipher_setkey(tfm, template[i].key,
1066 template[i].klen);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001067 if (!ret == template[i].fail) {
1068 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001069 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001070 goto out;
1071 } else if (ret)
1072 continue;
1073
1074 temp = 0;
1075 ret = -EINVAL;
1076 sg_init_table(sg, template[i].np);
1077 if (diff_dst)
1078 sg_init_table(sgout, template[i].np);
1079 for (k = 0; k < template[i].np; k++) {
1080 if (WARN_ON(offset_in_page(IDX[k]) +
1081 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001082 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001083
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001084 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1085
1086 memcpy(q, template[i].input + temp, template[i].tap[k]);
1087
1088 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1089 q[template[i].tap[k]] = 0;
1090
1091 sg_set_buf(&sg[k], q, template[i].tap[k]);
1092 if (diff_dst) {
1093 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1094 offset_in_page(IDX[k]);
1095
1096 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1097
1098 memset(q, 0, template[i].tap[k]);
1099 if (offset_in_page(q) +
1100 template[i].tap[k] < PAGE_SIZE)
1101 q[template[i].tap[k]] = 0;
1102 }
1103
1104 temp += template[i].tap[k];
1105 }
1106
Herbert Xu12773d92015-08-20 15:21:46 +08001107 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1108 template[i].ilen, iv);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001109
Herbert Xu12773d92015-08-20 15:21:46 +08001110 ret = enc ? crypto_skcipher_encrypt(req) :
1111 crypto_skcipher_decrypt(req);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001112
1113 switch (ret) {
1114 case 0:
1115 break;
1116 case -EINPROGRESS:
1117 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001118 wait_for_completion(&result.completion);
1119 reinit_completion(&result.completion);
1120 ret = result.err;
1121 if (!ret)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001122 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001123 /* fall through */
1124 default:
1125 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1126 d, e, j, algo, -ret);
1127 goto out;
1128 }
1129
1130 temp = 0;
1131 ret = -EINVAL;
1132 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001133 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001134 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1135 offset_in_page(IDX[k]);
1136 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001137 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1138 offset_in_page(IDX[k]);
1139
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001140 if (memcmp(q, template[i].result + temp,
1141 template[i].tap[k])) {
1142 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1143 d, j, e, k, algo);
1144 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001145 goto out;
1146 }
1147
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001148 q += template[i].tap[k];
1149 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1150 ;
1151 if (n) {
1152 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1153 d, j, e, k, algo, n);
1154 hexdump(q, n);
1155 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001156 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001157 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001158 }
1159 }
1160
1161 ret = 0;
1162
1163out:
Herbert Xu12773d92015-08-20 15:21:46 +08001164 skcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001165 if (diff_dst)
1166 testmgr_free_buf(xoutbuf);
1167out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001168 testmgr_free_buf(xbuf);
1169out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001170 return ret;
1171}
1172
Herbert Xu12773d92015-08-20 15:21:46 +08001173static int test_skcipher(struct crypto_skcipher *tfm, int enc,
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001174 struct cipher_testvec *template, unsigned int tcount)
1175{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001176 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001177 int ret;
1178
1179 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001180 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001181 if (ret)
1182 return ret;
1183
1184 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001185 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1186 if (ret)
1187 return ret;
1188
1189 /* test unaligned buffers, check with one byte offset */
1190 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1191 if (ret)
1192 return ret;
1193
1194 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1195 if (alignmask) {
1196 /* Check if alignment mask for tfm is correctly set. */
1197 ret = __test_skcipher(tfm, enc, template, tcount, true,
1198 alignmask + 1);
1199 if (ret)
1200 return ret;
1201 }
1202
1203 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001204}
1205
Herbert Xuda7f0332008-07-31 17:08:25 +08001206static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1207 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1208{
1209 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1210 unsigned int i;
1211 char result[COMP_BUF_SIZE];
1212 int ret;
1213
1214 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001215 int ilen;
1216 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001217
1218 memset(result, 0, sizeof (result));
1219
1220 ilen = ctemplate[i].inlen;
1221 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1222 ilen, result, &dlen);
1223 if (ret) {
1224 printk(KERN_ERR "alg: comp: compression failed "
1225 "on test %d for %s: ret=%d\n", i + 1, algo,
1226 -ret);
1227 goto out;
1228 }
1229
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001230 if (dlen != ctemplate[i].outlen) {
1231 printk(KERN_ERR "alg: comp: Compression test %d "
1232 "failed for %s: output len = %d\n", i + 1, algo,
1233 dlen);
1234 ret = -EINVAL;
1235 goto out;
1236 }
1237
Herbert Xuda7f0332008-07-31 17:08:25 +08001238 if (memcmp(result, ctemplate[i].output, dlen)) {
1239 printk(KERN_ERR "alg: comp: Compression test %d "
1240 "failed for %s\n", i + 1, algo);
1241 hexdump(result, dlen);
1242 ret = -EINVAL;
1243 goto out;
1244 }
1245 }
1246
1247 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001248 int ilen;
1249 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001250
1251 memset(result, 0, sizeof (result));
1252
1253 ilen = dtemplate[i].inlen;
1254 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1255 ilen, result, &dlen);
1256 if (ret) {
1257 printk(KERN_ERR "alg: comp: decompression failed "
1258 "on test %d for %s: ret=%d\n", i + 1, algo,
1259 -ret);
1260 goto out;
1261 }
1262
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001263 if (dlen != dtemplate[i].outlen) {
1264 printk(KERN_ERR "alg: comp: Decompression test %d "
1265 "failed for %s: output len = %d\n", i + 1, algo,
1266 dlen);
1267 ret = -EINVAL;
1268 goto out;
1269 }
1270
Herbert Xuda7f0332008-07-31 17:08:25 +08001271 if (memcmp(result, dtemplate[i].output, dlen)) {
1272 printk(KERN_ERR "alg: comp: Decompression test %d "
1273 "failed for %s\n", i + 1, algo);
1274 hexdump(result, dlen);
1275 ret = -EINVAL;
1276 goto out;
1277 }
1278 }
1279
1280 ret = 0;
1281
1282out:
1283 return ret;
1284}
1285
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001286static int test_pcomp(struct crypto_pcomp *tfm,
1287 struct pcomp_testvec *ctemplate,
1288 struct pcomp_testvec *dtemplate, int ctcount,
1289 int dtcount)
1290{
1291 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1292 unsigned int i;
1293 char result[COMP_BUF_SIZE];
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001294 int res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001295
1296 for (i = 0; i < ctcount; i++) {
1297 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001298 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001299
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001300 res = crypto_compress_setup(tfm, ctemplate[i].params,
1301 ctemplate[i].paramsize);
1302 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001303 pr_err("alg: pcomp: compression setup failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001304 "%d for %s: error=%d\n", i + 1, algo, res);
1305 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001306 }
1307
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001308 res = crypto_compress_init(tfm);
1309 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001310 pr_err("alg: pcomp: compression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001311 "%d for %s: error=%d\n", i + 1, algo, res);
1312 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001313 }
1314
1315 memset(result, 0, sizeof(result));
1316
1317 req.next_in = ctemplate[i].input;
1318 req.avail_in = ctemplate[i].inlen / 2;
1319 req.next_out = result;
1320 req.avail_out = ctemplate[i].outlen / 2;
1321
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001322 res = crypto_compress_update(tfm, &req);
1323 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001324 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001325 "%d for %s: error=%d\n", i + 1, algo, res);
1326 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001327 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001328 if (res > 0)
1329 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001330
1331 /* Add remaining input data */
1332 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1333
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001334 res = crypto_compress_update(tfm, &req);
1335 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001336 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001337 "%d for %s: error=%d\n", i + 1, algo, res);
1338 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001339 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001340 if (res > 0)
1341 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001342
1343 /* Provide remaining output space */
1344 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1345
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001346 res = crypto_compress_final(tfm, &req);
1347 if (res < 0) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001348 pr_err("alg: pcomp: compression final failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001349 "%d for %s: error=%d\n", i + 1, algo, res);
1350 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001351 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001352 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001353
1354 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1355 pr_err("alg: comp: Compression test %d failed for %s: "
1356 "output len = %d (expected %d)\n", i + 1, algo,
1357 COMP_BUF_SIZE - req.avail_out,
1358 ctemplate[i].outlen);
1359 return -EINVAL;
1360 }
1361
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001362 if (produced != ctemplate[i].outlen) {
1363 pr_err("alg: comp: Compression test %d failed for %s: "
1364 "returned len = %u (expected %d)\n", i + 1,
1365 algo, produced, ctemplate[i].outlen);
1366 return -EINVAL;
1367 }
1368
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001369 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1370 pr_err("alg: pcomp: Compression test %d failed for "
1371 "%s\n", i + 1, algo);
1372 hexdump(result, ctemplate[i].outlen);
1373 return -EINVAL;
1374 }
1375 }
1376
1377 for (i = 0; i < dtcount; i++) {
1378 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001379 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001380
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001381 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1382 dtemplate[i].paramsize);
1383 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001384 pr_err("alg: pcomp: decompression setup failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001385 "test %d for %s: error=%d\n", i + 1, algo, res);
1386 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001387 }
1388
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001389 res = crypto_decompress_init(tfm);
1390 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001391 pr_err("alg: pcomp: decompression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001392 "%d for %s: error=%d\n", i + 1, algo, res);
1393 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001394 }
1395
1396 memset(result, 0, sizeof(result));
1397
1398 req.next_in = dtemplate[i].input;
1399 req.avail_in = dtemplate[i].inlen / 2;
1400 req.next_out = result;
1401 req.avail_out = dtemplate[i].outlen / 2;
1402
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001403 res = crypto_decompress_update(tfm, &req);
1404 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001405 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001406 "test %d for %s: error=%d\n", i + 1, algo, res);
1407 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001408 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001409 if (res > 0)
1410 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001411
1412 /* Add remaining input data */
1413 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1414
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001415 res = crypto_decompress_update(tfm, &req);
1416 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001417 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001418 "test %d for %s: error=%d\n", i + 1, algo, res);
1419 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001420 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001421 if (res > 0)
1422 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001423
1424 /* Provide remaining output space */
1425 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1426
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001427 res = crypto_decompress_final(tfm, &req);
1428 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001429 pr_err("alg: pcomp: decompression final failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001430 "test %d for %s: error=%d\n", i + 1, algo, res);
1431 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001432 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001433 if (res > 0)
1434 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001435
1436 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1437 pr_err("alg: comp: Decompression test %d failed for "
1438 "%s: output len = %d (expected %d)\n", i + 1,
1439 algo, COMP_BUF_SIZE - req.avail_out,
1440 dtemplate[i].outlen);
1441 return -EINVAL;
1442 }
1443
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001444 if (produced != dtemplate[i].outlen) {
1445 pr_err("alg: comp: Decompression test %d failed for "
1446 "%s: returned len = %u (expected %d)\n", i + 1,
1447 algo, produced, dtemplate[i].outlen);
1448 return -EINVAL;
1449 }
1450
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001451 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1452 pr_err("alg: pcomp: Decompression test %d failed for "
1453 "%s\n", i + 1, algo);
1454 hexdump(result, dtemplate[i].outlen);
1455 return -EINVAL;
1456 }
1457 }
1458
1459 return 0;
1460}
1461
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001462
1463static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1464 unsigned int tcount)
1465{
1466 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001467 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001468 u8 *seed;
1469 char result[32];
1470
1471 seedsize = crypto_rng_seedsize(tfm);
1472
1473 seed = kmalloc(seedsize, GFP_KERNEL);
1474 if (!seed) {
1475 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1476 "for %s\n", algo);
1477 return -ENOMEM;
1478 }
1479
1480 for (i = 0; i < tcount; i++) {
1481 memset(result, 0, 32);
1482
1483 memcpy(seed, template[i].v, template[i].vlen);
1484 memcpy(seed + template[i].vlen, template[i].key,
1485 template[i].klen);
1486 memcpy(seed + template[i].vlen + template[i].klen,
1487 template[i].dt, template[i].dtlen);
1488
1489 err = crypto_rng_reset(tfm, seed, seedsize);
1490 if (err) {
1491 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1492 "for %s\n", algo);
1493 goto out;
1494 }
1495
1496 for (j = 0; j < template[i].loops; j++) {
1497 err = crypto_rng_get_bytes(tfm, result,
1498 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01001499 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001500 printk(KERN_ERR "alg: cprng: Failed to obtain "
1501 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01001502 "%s (requested %d)\n", algo,
1503 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001504 goto out;
1505 }
1506 }
1507
1508 err = memcmp(result, template[i].result,
1509 template[i].rlen);
1510 if (err) {
1511 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1512 i, algo);
1513 hexdump(result, template[i].rlen);
1514 err = -EINVAL;
1515 goto out;
1516 }
1517 }
1518
1519out:
1520 kfree(seed);
1521 return err;
1522}
1523
Herbert Xuda7f0332008-07-31 17:08:25 +08001524static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1525 u32 type, u32 mask)
1526{
1527 struct crypto_aead *tfm;
1528 int err = 0;
1529
Stephan Mueller425a8822015-03-30 21:56:31 +02001530 tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001531 if (IS_ERR(tfm)) {
1532 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1533 "%ld\n", driver, PTR_ERR(tfm));
1534 return PTR_ERR(tfm);
1535 }
1536
1537 if (desc->suite.aead.enc.vecs) {
1538 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1539 desc->suite.aead.enc.count);
1540 if (err)
1541 goto out;
1542 }
1543
1544 if (!err && desc->suite.aead.dec.vecs)
1545 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1546 desc->suite.aead.dec.count);
1547
1548out:
1549 crypto_free_aead(tfm);
1550 return err;
1551}
1552
1553static int alg_test_cipher(const struct alg_test_desc *desc,
1554 const char *driver, u32 type, u32 mask)
1555{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001556 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001557 int err = 0;
1558
Stephan Mueller425a8822015-03-30 21:56:31 +02001559 tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001560 if (IS_ERR(tfm)) {
1561 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1562 "%s: %ld\n", driver, PTR_ERR(tfm));
1563 return PTR_ERR(tfm);
1564 }
1565
1566 if (desc->suite.cipher.enc.vecs) {
1567 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1568 desc->suite.cipher.enc.count);
1569 if (err)
1570 goto out;
1571 }
1572
1573 if (desc->suite.cipher.dec.vecs)
1574 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1575 desc->suite.cipher.dec.count);
1576
1577out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001578 crypto_free_cipher(tfm);
1579 return err;
1580}
1581
1582static int alg_test_skcipher(const struct alg_test_desc *desc,
1583 const char *driver, u32 type, u32 mask)
1584{
Herbert Xu12773d92015-08-20 15:21:46 +08001585 struct crypto_skcipher *tfm;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001586 int err = 0;
1587
Herbert Xu12773d92015-08-20 15:21:46 +08001588 tfm = crypto_alloc_skcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001589 if (IS_ERR(tfm)) {
1590 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1591 "%s: %ld\n", driver, PTR_ERR(tfm));
1592 return PTR_ERR(tfm);
1593 }
1594
1595 if (desc->suite.cipher.enc.vecs) {
1596 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1597 desc->suite.cipher.enc.count);
1598 if (err)
1599 goto out;
1600 }
1601
1602 if (desc->suite.cipher.dec.vecs)
1603 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1604 desc->suite.cipher.dec.count);
1605
1606out:
Herbert Xu12773d92015-08-20 15:21:46 +08001607 crypto_free_skcipher(tfm);
Herbert Xuda7f0332008-07-31 17:08:25 +08001608 return err;
1609}
1610
1611static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1612 u32 type, u32 mask)
1613{
1614 struct crypto_comp *tfm;
1615 int err;
1616
1617 tfm = crypto_alloc_comp(driver, type, mask);
1618 if (IS_ERR(tfm)) {
1619 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1620 "%ld\n", driver, PTR_ERR(tfm));
1621 return PTR_ERR(tfm);
1622 }
1623
1624 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1625 desc->suite.comp.decomp.vecs,
1626 desc->suite.comp.comp.count,
1627 desc->suite.comp.decomp.count);
1628
1629 crypto_free_comp(tfm);
1630 return err;
1631}
1632
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001633static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1634 u32 type, u32 mask)
1635{
1636 struct crypto_pcomp *tfm;
1637 int err;
1638
1639 tfm = crypto_alloc_pcomp(driver, type, mask);
1640 if (IS_ERR(tfm)) {
1641 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1642 driver, PTR_ERR(tfm));
1643 return PTR_ERR(tfm);
1644 }
1645
1646 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1647 desc->suite.pcomp.decomp.vecs,
1648 desc->suite.pcomp.comp.count,
1649 desc->suite.pcomp.decomp.count);
1650
1651 crypto_free_pcomp(tfm);
1652 return err;
1653}
1654
Herbert Xuda7f0332008-07-31 17:08:25 +08001655static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1656 u32 type, u32 mask)
1657{
1658 struct crypto_ahash *tfm;
1659 int err;
1660
Stephan Mueller425a8822015-03-30 21:56:31 +02001661 tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001662 if (IS_ERR(tfm)) {
1663 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1664 "%ld\n", driver, PTR_ERR(tfm));
1665 return PTR_ERR(tfm);
1666 }
1667
David S. Millera8f1a052010-05-19 14:12:03 +10001668 err = test_hash(tfm, desc->suite.hash.vecs,
1669 desc->suite.hash.count, true);
1670 if (!err)
1671 err = test_hash(tfm, desc->suite.hash.vecs,
1672 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001673
1674 crypto_free_ahash(tfm);
1675 return err;
1676}
1677
Herbert Xu8e3ee852008-11-07 14:58:52 +08001678static int alg_test_crc32c(const struct alg_test_desc *desc,
1679 const char *driver, u32 type, u32 mask)
1680{
1681 struct crypto_shash *tfm;
1682 u32 val;
1683 int err;
1684
1685 err = alg_test_hash(desc, driver, type, mask);
1686 if (err)
1687 goto out;
1688
Stephan Mueller425a8822015-03-30 21:56:31 +02001689 tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001690 if (IS_ERR(tfm)) {
1691 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1692 "%ld\n", driver, PTR_ERR(tfm));
1693 err = PTR_ERR(tfm);
1694 goto out;
1695 }
1696
1697 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001698 SHASH_DESC_ON_STACK(shash, tfm);
1699 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001700
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001701 shash->tfm = tfm;
1702 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001703
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001704 *ctx = le32_to_cpu(420553207);
1705 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001706 if (err) {
1707 printk(KERN_ERR "alg: crc32c: Operation failed for "
1708 "%s: %d\n", driver, err);
1709 break;
1710 }
1711
1712 if (val != ~420553207) {
1713 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1714 "%d\n", driver, val);
1715 err = -EINVAL;
1716 }
1717 } while (0);
1718
1719 crypto_free_shash(tfm);
1720
1721out:
1722 return err;
1723}
1724
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001725static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1726 u32 type, u32 mask)
1727{
1728 struct crypto_rng *rng;
1729 int err;
1730
Stephan Mueller425a8822015-03-30 21:56:31 +02001731 rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001732 if (IS_ERR(rng)) {
1733 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1734 "%ld\n", driver, PTR_ERR(rng));
1735 return PTR_ERR(rng);
1736 }
1737
1738 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1739
1740 crypto_free_rng(rng);
1741
1742 return err;
1743}
1744
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001745
1746static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1747 const char *driver, u32 type, u32 mask)
1748{
1749 int ret = -EAGAIN;
1750 struct crypto_rng *drng;
1751 struct drbg_test_data test_data;
1752 struct drbg_string addtl, pers, testentropy;
1753 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1754
1755 if (!buf)
1756 return -ENOMEM;
1757
Stephan Mueller425a8822015-03-30 21:56:31 +02001758 drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001759 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001760 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001761 "%s\n", driver);
1762 kzfree(buf);
1763 return -ENOMEM;
1764 }
1765
1766 test_data.testentropy = &testentropy;
1767 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1768 drbg_string_fill(&pers, test->pers, test->perslen);
1769 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1770 if (ret) {
1771 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1772 goto outbuf;
1773 }
1774
1775 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1776 if (pr) {
1777 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1778 ret = crypto_drbg_get_bytes_addtl_test(drng,
1779 buf, test->expectedlen, &addtl, &test_data);
1780 } else {
1781 ret = crypto_drbg_get_bytes_addtl(drng,
1782 buf, test->expectedlen, &addtl);
1783 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001784 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001785 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001786 "driver %s\n", driver);
1787 goto outbuf;
1788 }
1789
1790 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1791 if (pr) {
1792 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1793 ret = crypto_drbg_get_bytes_addtl_test(drng,
1794 buf, test->expectedlen, &addtl, &test_data);
1795 } else {
1796 ret = crypto_drbg_get_bytes_addtl(drng,
1797 buf, test->expectedlen, &addtl);
1798 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001799 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001800 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001801 "driver %s\n", driver);
1802 goto outbuf;
1803 }
1804
1805 ret = memcmp(test->expected, buf, test->expectedlen);
1806
1807outbuf:
1808 crypto_free_rng(drng);
1809 kzfree(buf);
1810 return ret;
1811}
1812
1813
1814static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1815 u32 type, u32 mask)
1816{
1817 int err = 0;
1818 int pr = 0;
1819 int i = 0;
1820 struct drbg_testvec *template = desc->suite.drbg.vecs;
1821 unsigned int tcount = desc->suite.drbg.count;
1822
1823 if (0 == memcmp(driver, "drbg_pr_", 8))
1824 pr = 1;
1825
1826 for (i = 0; i < tcount; i++) {
1827 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1828 if (err) {
1829 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1830 i, driver);
1831 err = -EINVAL;
1832 break;
1833 }
1834 }
1835 return err;
1836
1837}
1838
Tadeusz Struk946cc462015-06-16 10:31:06 -07001839static int do_test_rsa(struct crypto_akcipher *tfm,
1840 struct akcipher_testvec *vecs)
1841{
1842 struct akcipher_request *req;
1843 void *outbuf_enc = NULL;
1844 void *outbuf_dec = NULL;
1845 struct tcrypt_result result;
1846 unsigned int out_len_max, out_len = 0;
1847 int err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07001848 struct scatterlist src, dst, src_tab[2];
Tadeusz Struk946cc462015-06-16 10:31:06 -07001849
1850 req = akcipher_request_alloc(tfm, GFP_KERNEL);
1851 if (!req)
1852 return err;
1853
1854 init_completion(&result.completion);
Tadeusz Struk22287b02015-10-08 09:26:55 -07001855
1856 if (vecs->public_key_vec)
1857 err = crypto_akcipher_set_pub_key(tfm, vecs->key,
1858 vecs->key_len);
1859 else
1860 err = crypto_akcipher_set_priv_key(tfm, vecs->key,
1861 vecs->key_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07001862 if (err)
1863 goto free_req;
1864
Tadeusz Struk22287b02015-10-08 09:26:55 -07001865 out_len_max = crypto_akcipher_maxsize(tfm);
Tadeusz Struk946cc462015-06-16 10:31:06 -07001866 outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
1867 if (!outbuf_enc)
1868 goto free_req;
1869
Tadeusz Struk22287b02015-10-08 09:26:55 -07001870 sg_init_table(src_tab, 2);
1871 sg_set_buf(&src_tab[0], vecs->m, 8);
1872 sg_set_buf(&src_tab[1], vecs->m + 8, vecs->m_size - 8);
1873 sg_init_one(&dst, outbuf_enc, out_len_max);
1874 akcipher_request_set_crypt(req, src_tab, &dst, vecs->m_size,
1875 out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07001876 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1877 tcrypt_complete, &result);
1878
1879 /* Run RSA encrypt - c = m^e mod n;*/
1880 err = wait_async_op(&result, crypto_akcipher_encrypt(req));
1881 if (err) {
1882 pr_err("alg: rsa: encrypt test failed. err %d\n", err);
1883 goto free_all;
1884 }
Tadeusz Struk22287b02015-10-08 09:26:55 -07001885 if (req->dst_len != vecs->c_size) {
Tadeusz Struk946cc462015-06-16 10:31:06 -07001886 pr_err("alg: rsa: encrypt test failed. Invalid output len\n");
1887 err = -EINVAL;
1888 goto free_all;
1889 }
1890 /* verify that encrypted message is equal to expected */
Tadeusz Struk22287b02015-10-08 09:26:55 -07001891 if (memcmp(vecs->c, sg_virt(req->dst), vecs->c_size)) {
Tadeusz Struk946cc462015-06-16 10:31:06 -07001892 pr_err("alg: rsa: encrypt test failed. Invalid output\n");
1893 err = -EINVAL;
1894 goto free_all;
1895 }
1896 /* Don't invoke decrypt for vectors with public key */
1897 if (vecs->public_key_vec) {
1898 err = 0;
1899 goto free_all;
1900 }
1901 outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
1902 if (!outbuf_dec) {
1903 err = -ENOMEM;
1904 goto free_all;
1905 }
Tadeusz Struk22287b02015-10-08 09:26:55 -07001906 sg_init_one(&src, vecs->c, vecs->c_size);
1907 sg_init_one(&dst, outbuf_dec, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07001908 init_completion(&result.completion);
Tadeusz Struk22287b02015-10-08 09:26:55 -07001909 akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07001910
1911 /* Run RSA decrypt - m = c^d mod n;*/
1912 err = wait_async_op(&result, crypto_akcipher_decrypt(req));
1913 if (err) {
1914 pr_err("alg: rsa: decrypt test failed. err %d\n", err);
1915 goto free_all;
1916 }
1917 out_len = req->dst_len;
1918 if (out_len != vecs->m_size) {
1919 pr_err("alg: rsa: decrypt test failed. Invalid output len\n");
1920 err = -EINVAL;
1921 goto free_all;
1922 }
1923 /* verify that decrypted message is equal to the original msg */
1924 if (memcmp(vecs->m, outbuf_dec, vecs->m_size)) {
1925 pr_err("alg: rsa: decrypt test failed. Invalid output\n");
1926 err = -EINVAL;
1927 }
1928free_all:
1929 kfree(outbuf_dec);
1930 kfree(outbuf_enc);
1931free_req:
1932 akcipher_request_free(req);
1933 return err;
1934}
1935
1936static int test_rsa(struct crypto_akcipher *tfm, struct akcipher_testvec *vecs,
1937 unsigned int tcount)
1938{
1939 int ret, i;
1940
1941 for (i = 0; i < tcount; i++) {
1942 ret = do_test_rsa(tfm, vecs++);
1943 if (ret) {
1944 pr_err("alg: rsa: test failed on vector %d, err=%d\n",
1945 i + 1, ret);
1946 return ret;
1947 }
1948 }
1949 return 0;
1950}
1951
1952static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
1953 struct akcipher_testvec *vecs, unsigned int tcount)
1954{
1955 if (strncmp(alg, "rsa", 3) == 0)
1956 return test_rsa(tfm, vecs, tcount);
1957
1958 return 0;
1959}
1960
1961static int alg_test_akcipher(const struct alg_test_desc *desc,
1962 const char *driver, u32 type, u32 mask)
1963{
1964 struct crypto_akcipher *tfm;
1965 int err = 0;
1966
1967 tfm = crypto_alloc_akcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
1968 if (IS_ERR(tfm)) {
1969 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
1970 driver, PTR_ERR(tfm));
1971 return PTR_ERR(tfm);
1972 }
1973 if (desc->suite.akcipher.vecs)
1974 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
1975 desc->suite.akcipher.count);
1976
1977 crypto_free_akcipher(tfm);
1978 return err;
1979}
1980
Youquan, Song863b5572009-12-23 19:45:20 +08001981static int alg_test_null(const struct alg_test_desc *desc,
1982 const char *driver, u32 type, u32 mask)
1983{
1984 return 0;
1985}
1986
Herbert Xuda7f0332008-07-31 17:08:25 +08001987/* Please keep this list sorted by algorithm name. */
1988static const struct alg_test_desc alg_test_descs[] = {
1989 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001990 .alg = "__cbc-cast5-avx",
1991 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001992 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001993 .alg = "__cbc-cast6-avx",
1994 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001995 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001996 .alg = "__cbc-serpent-avx",
1997 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001998 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001999 .alg = "__cbc-serpent-avx2",
2000 .test = alg_test_null,
2001 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002002 .alg = "__cbc-serpent-sse2",
2003 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002004 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002005 .alg = "__cbc-twofish-avx",
2006 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002007 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002008 .alg = "__driver-cbc-aes-aesni",
2009 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002010 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002011 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002012 .alg = "__driver-cbc-camellia-aesni",
2013 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002014 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002015 .alg = "__driver-cbc-camellia-aesni-avx2",
2016 .test = alg_test_null,
2017 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002018 .alg = "__driver-cbc-cast5-avx",
2019 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002020 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002021 .alg = "__driver-cbc-cast6-avx",
2022 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002023 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002024 .alg = "__driver-cbc-serpent-avx",
2025 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002026 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002027 .alg = "__driver-cbc-serpent-avx2",
2028 .test = alg_test_null,
2029 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002030 .alg = "__driver-cbc-serpent-sse2",
2031 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002032 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002033 .alg = "__driver-cbc-twofish-avx",
2034 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002035 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002036 .alg = "__driver-ecb-aes-aesni",
2037 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002038 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002039 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002040 .alg = "__driver-ecb-camellia-aesni",
2041 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002042 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002043 .alg = "__driver-ecb-camellia-aesni-avx2",
2044 .test = alg_test_null,
2045 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002046 .alg = "__driver-ecb-cast5-avx",
2047 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002048 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002049 .alg = "__driver-ecb-cast6-avx",
2050 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002051 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002052 .alg = "__driver-ecb-serpent-avx",
2053 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002054 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002055 .alg = "__driver-ecb-serpent-avx2",
2056 .test = alg_test_null,
2057 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002058 .alg = "__driver-ecb-serpent-sse2",
2059 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002060 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002061 .alg = "__driver-ecb-twofish-avx",
2062 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002063 }, {
Tadeusz Struk9d77b6c2015-06-24 09:01:30 -07002064 .alg = "__driver-gcm-aes-aesni",
2065 .test = alg_test_null,
2066 .fips_allowed = 1,
2067 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002068 .alg = "__ghash-pclmulqdqni",
2069 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002070 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002071 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002072 .alg = "ansi_cprng",
2073 .test = alg_test_cprng,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002074 .fips_allowed = 1,
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002075 .suite = {
2076 .cprng = {
2077 .vecs = ansi_cprng_aes_tv_template,
2078 .count = ANSI_CPRNG_AES_TEST_VECTORS
2079 }
2080 }
2081 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002082 .alg = "authenc(hmac(md5),ecb(cipher_null))",
2083 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002084 .suite = {
2085 .aead = {
2086 .enc = {
2087 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
2088 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
2089 },
2090 .dec = {
2091 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
2092 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
2093 }
2094 }
2095 }
2096 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002097 .alg = "authenc(hmac(sha1),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002098 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002099 .suite = {
2100 .aead = {
2101 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302102 .vecs =
2103 hmac_sha1_aes_cbc_enc_tv_temp,
2104 .count =
2105 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
2106 }
2107 }
2108 }
2109 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002110 .alg = "authenc(hmac(sha1),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302111 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302112 .suite = {
2113 .aead = {
2114 .enc = {
2115 .vecs =
2116 hmac_sha1_des_cbc_enc_tv_temp,
2117 .count =
2118 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
2119 }
2120 }
2121 }
2122 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002123 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302124 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302125 .suite = {
2126 .aead = {
2127 .enc = {
2128 .vecs =
2129 hmac_sha1_des3_ede_cbc_enc_tv_temp,
2130 .count =
2131 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002132 }
2133 }
2134 }
2135 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002136 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
2137 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002138 .suite = {
2139 .aead = {
2140 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302141 .vecs =
2142 hmac_sha1_ecb_cipher_null_enc_tv_temp,
2143 .count =
2144 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002145 },
2146 .dec = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302147 .vecs =
2148 hmac_sha1_ecb_cipher_null_dec_tv_temp,
2149 .count =
2150 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
2151 }
2152 }
2153 }
2154 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002155 .alg = "authenc(hmac(sha224),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302156 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302157 .suite = {
2158 .aead = {
2159 .enc = {
2160 .vecs =
2161 hmac_sha224_des_cbc_enc_tv_temp,
2162 .count =
2163 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2164 }
2165 }
2166 }
2167 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002168 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302169 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302170 .suite = {
2171 .aead = {
2172 .enc = {
2173 .vecs =
2174 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2175 .count =
2176 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002177 }
2178 }
2179 }
2180 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002181 .alg = "authenc(hmac(sha256),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002182 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002183 .suite = {
2184 .aead = {
2185 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302186 .vecs =
2187 hmac_sha256_aes_cbc_enc_tv_temp,
2188 .count =
2189 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2190 }
2191 }
2192 }
2193 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002194 .alg = "authenc(hmac(sha256),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302195 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302196 .suite = {
2197 .aead = {
2198 .enc = {
2199 .vecs =
2200 hmac_sha256_des_cbc_enc_tv_temp,
2201 .count =
2202 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2203 }
2204 }
2205 }
2206 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002207 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302208 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302209 .suite = {
2210 .aead = {
2211 .enc = {
2212 .vecs =
2213 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2214 .count =
2215 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2216 }
2217 }
2218 }
2219 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002220 .alg = "authenc(hmac(sha384),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302221 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302222 .suite = {
2223 .aead = {
2224 .enc = {
2225 .vecs =
2226 hmac_sha384_des_cbc_enc_tv_temp,
2227 .count =
2228 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2229 }
2230 }
2231 }
2232 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002233 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302234 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302235 .suite = {
2236 .aead = {
2237 .enc = {
2238 .vecs =
2239 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2240 .count =
2241 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002242 }
2243 }
2244 }
2245 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002246 .alg = "authenc(hmac(sha512),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002247 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002248 .suite = {
2249 .aead = {
2250 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302251 .vecs =
2252 hmac_sha512_aes_cbc_enc_tv_temp,
2253 .count =
2254 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2255 }
2256 }
2257 }
2258 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002259 .alg = "authenc(hmac(sha512),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302260 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302261 .suite = {
2262 .aead = {
2263 .enc = {
2264 .vecs =
2265 hmac_sha512_des_cbc_enc_tv_temp,
2266 .count =
2267 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2268 }
2269 }
2270 }
2271 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002272 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302273 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302274 .suite = {
2275 .aead = {
2276 .enc = {
2277 .vecs =
2278 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2279 .count =
2280 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002281 }
2282 }
2283 }
2284 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002285 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002286 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002287 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002288 .suite = {
2289 .cipher = {
2290 .enc = {
2291 .vecs = aes_cbc_enc_tv_template,
2292 .count = AES_CBC_ENC_TEST_VECTORS
2293 },
2294 .dec = {
2295 .vecs = aes_cbc_dec_tv_template,
2296 .count = AES_CBC_DEC_TEST_VECTORS
2297 }
2298 }
2299 }
2300 }, {
2301 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002302 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002303 .suite = {
2304 .cipher = {
2305 .enc = {
2306 .vecs = anubis_cbc_enc_tv_template,
2307 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2308 },
2309 .dec = {
2310 .vecs = anubis_cbc_dec_tv_template,
2311 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2312 }
2313 }
2314 }
2315 }, {
2316 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002317 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002318 .suite = {
2319 .cipher = {
2320 .enc = {
2321 .vecs = bf_cbc_enc_tv_template,
2322 .count = BF_CBC_ENC_TEST_VECTORS
2323 },
2324 .dec = {
2325 .vecs = bf_cbc_dec_tv_template,
2326 .count = BF_CBC_DEC_TEST_VECTORS
2327 }
2328 }
2329 }
2330 }, {
2331 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002332 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002333 .suite = {
2334 .cipher = {
2335 .enc = {
2336 .vecs = camellia_cbc_enc_tv_template,
2337 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2338 },
2339 .dec = {
2340 .vecs = camellia_cbc_dec_tv_template,
2341 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2342 }
2343 }
2344 }
2345 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002346 .alg = "cbc(cast5)",
2347 .test = alg_test_skcipher,
2348 .suite = {
2349 .cipher = {
2350 .enc = {
2351 .vecs = cast5_cbc_enc_tv_template,
2352 .count = CAST5_CBC_ENC_TEST_VECTORS
2353 },
2354 .dec = {
2355 .vecs = cast5_cbc_dec_tv_template,
2356 .count = CAST5_CBC_DEC_TEST_VECTORS
2357 }
2358 }
2359 }
2360 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002361 .alg = "cbc(cast6)",
2362 .test = alg_test_skcipher,
2363 .suite = {
2364 .cipher = {
2365 .enc = {
2366 .vecs = cast6_cbc_enc_tv_template,
2367 .count = CAST6_CBC_ENC_TEST_VECTORS
2368 },
2369 .dec = {
2370 .vecs = cast6_cbc_dec_tv_template,
2371 .count = CAST6_CBC_DEC_TEST_VECTORS
2372 }
2373 }
2374 }
2375 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002376 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002377 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002378 .suite = {
2379 .cipher = {
2380 .enc = {
2381 .vecs = des_cbc_enc_tv_template,
2382 .count = DES_CBC_ENC_TEST_VECTORS
2383 },
2384 .dec = {
2385 .vecs = des_cbc_dec_tv_template,
2386 .count = DES_CBC_DEC_TEST_VECTORS
2387 }
2388 }
2389 }
2390 }, {
2391 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002392 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002393 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002394 .suite = {
2395 .cipher = {
2396 .enc = {
2397 .vecs = des3_ede_cbc_enc_tv_template,
2398 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2399 },
2400 .dec = {
2401 .vecs = des3_ede_cbc_dec_tv_template,
2402 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2403 }
2404 }
2405 }
2406 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002407 .alg = "cbc(serpent)",
2408 .test = alg_test_skcipher,
2409 .suite = {
2410 .cipher = {
2411 .enc = {
2412 .vecs = serpent_cbc_enc_tv_template,
2413 .count = SERPENT_CBC_ENC_TEST_VECTORS
2414 },
2415 .dec = {
2416 .vecs = serpent_cbc_dec_tv_template,
2417 .count = SERPENT_CBC_DEC_TEST_VECTORS
2418 }
2419 }
2420 }
2421 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002422 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002423 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002424 .suite = {
2425 .cipher = {
2426 .enc = {
2427 .vecs = tf_cbc_enc_tv_template,
2428 .count = TF_CBC_ENC_TEST_VECTORS
2429 },
2430 .dec = {
2431 .vecs = tf_cbc_dec_tv_template,
2432 .count = TF_CBC_DEC_TEST_VECTORS
2433 }
2434 }
2435 }
2436 }, {
2437 .alg = "ccm(aes)",
2438 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002439 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002440 .suite = {
2441 .aead = {
2442 .enc = {
2443 .vecs = aes_ccm_enc_tv_template,
2444 .count = AES_CCM_ENC_TEST_VECTORS
2445 },
2446 .dec = {
2447 .vecs = aes_ccm_dec_tv_template,
2448 .count = AES_CCM_DEC_TEST_VECTORS
2449 }
2450 }
2451 }
2452 }, {
Martin Willi3590ebf2015-06-01 13:43:57 +02002453 .alg = "chacha20",
2454 .test = alg_test_skcipher,
2455 .suite = {
2456 .cipher = {
2457 .enc = {
2458 .vecs = chacha20_enc_tv_template,
2459 .count = CHACHA20_ENC_TEST_VECTORS
2460 },
2461 .dec = {
2462 .vecs = chacha20_enc_tv_template,
2463 .count = CHACHA20_ENC_TEST_VECTORS
2464 },
2465 }
2466 }
2467 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002468 .alg = "cmac(aes)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002469 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002470 .test = alg_test_hash,
2471 .suite = {
2472 .hash = {
2473 .vecs = aes_cmac128_tv_template,
2474 .count = CMAC_AES_TEST_VECTORS
2475 }
2476 }
2477 }, {
2478 .alg = "cmac(des3_ede)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002479 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002480 .test = alg_test_hash,
2481 .suite = {
2482 .hash = {
2483 .vecs = des3_ede_cmac64_tv_template,
2484 .count = CMAC_DES3_EDE_TEST_VECTORS
2485 }
2486 }
2487 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002488 .alg = "compress_null",
2489 .test = alg_test_null,
2490 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02002491 .alg = "crc32",
2492 .test = alg_test_hash,
2493 .suite = {
2494 .hash = {
2495 .vecs = crc32_tv_template,
2496 .count = CRC32_TEST_VECTORS
2497 }
2498 }
2499 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002500 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002501 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002502 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002503 .suite = {
2504 .hash = {
2505 .vecs = crc32c_tv_template,
2506 .count = CRC32C_TEST_VECTORS
2507 }
2508 }
2509 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002510 .alg = "crct10dif",
2511 .test = alg_test_hash,
2512 .fips_allowed = 1,
2513 .suite = {
2514 .hash = {
2515 .vecs = crct10dif_tv_template,
2516 .count = CRCT10DIF_TEST_VECTORS
2517 }
2518 }
2519 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002520 .alg = "cryptd(__driver-cbc-aes-aesni)",
2521 .test = alg_test_null,
2522 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002523 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002524 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2525 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002526 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002527 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2528 .test = alg_test_null,
2529 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002530 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2531 .test = alg_test_null,
2532 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002533 .alg = "cryptd(__driver-ecb-aes-aesni)",
2534 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002535 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002536 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002537 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2538 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002539 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002540 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2541 .test = alg_test_null,
2542 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002543 .alg = "cryptd(__driver-ecb-cast5-avx)",
2544 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002545 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002546 .alg = "cryptd(__driver-ecb-cast6-avx)",
2547 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002548 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002549 .alg = "cryptd(__driver-ecb-serpent-avx)",
2550 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002551 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002552 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2553 .test = alg_test_null,
2554 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002555 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2556 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002557 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002558 .alg = "cryptd(__driver-ecb-twofish-avx)",
2559 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002560 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002561 .alg = "cryptd(__driver-gcm-aes-aesni)",
2562 .test = alg_test_null,
2563 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002564 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002565 .alg = "cryptd(__ghash-pclmulqdqni)",
2566 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002567 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002568 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002569 .alg = "ctr(aes)",
2570 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002571 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002572 .suite = {
2573 .cipher = {
2574 .enc = {
2575 .vecs = aes_ctr_enc_tv_template,
2576 .count = AES_CTR_ENC_TEST_VECTORS
2577 },
2578 .dec = {
2579 .vecs = aes_ctr_dec_tv_template,
2580 .count = AES_CTR_DEC_TEST_VECTORS
2581 }
2582 }
2583 }
2584 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002585 .alg = "ctr(blowfish)",
2586 .test = alg_test_skcipher,
2587 .suite = {
2588 .cipher = {
2589 .enc = {
2590 .vecs = bf_ctr_enc_tv_template,
2591 .count = BF_CTR_ENC_TEST_VECTORS
2592 },
2593 .dec = {
2594 .vecs = bf_ctr_dec_tv_template,
2595 .count = BF_CTR_DEC_TEST_VECTORS
2596 }
2597 }
2598 }
2599 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002600 .alg = "ctr(camellia)",
2601 .test = alg_test_skcipher,
2602 .suite = {
2603 .cipher = {
2604 .enc = {
2605 .vecs = camellia_ctr_enc_tv_template,
2606 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2607 },
2608 .dec = {
2609 .vecs = camellia_ctr_dec_tv_template,
2610 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2611 }
2612 }
2613 }
2614 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002615 .alg = "ctr(cast5)",
2616 .test = alg_test_skcipher,
2617 .suite = {
2618 .cipher = {
2619 .enc = {
2620 .vecs = cast5_ctr_enc_tv_template,
2621 .count = CAST5_CTR_ENC_TEST_VECTORS
2622 },
2623 .dec = {
2624 .vecs = cast5_ctr_dec_tv_template,
2625 .count = CAST5_CTR_DEC_TEST_VECTORS
2626 }
2627 }
2628 }
2629 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002630 .alg = "ctr(cast6)",
2631 .test = alg_test_skcipher,
2632 .suite = {
2633 .cipher = {
2634 .enc = {
2635 .vecs = cast6_ctr_enc_tv_template,
2636 .count = CAST6_CTR_ENC_TEST_VECTORS
2637 },
2638 .dec = {
2639 .vecs = cast6_ctr_dec_tv_template,
2640 .count = CAST6_CTR_DEC_TEST_VECTORS
2641 }
2642 }
2643 }
2644 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002645 .alg = "ctr(des)",
2646 .test = alg_test_skcipher,
2647 .suite = {
2648 .cipher = {
2649 .enc = {
2650 .vecs = des_ctr_enc_tv_template,
2651 .count = DES_CTR_ENC_TEST_VECTORS
2652 },
2653 .dec = {
2654 .vecs = des_ctr_dec_tv_template,
2655 .count = DES_CTR_DEC_TEST_VECTORS
2656 }
2657 }
2658 }
2659 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002660 .alg = "ctr(des3_ede)",
2661 .test = alg_test_skcipher,
2662 .suite = {
2663 .cipher = {
2664 .enc = {
2665 .vecs = des3_ede_ctr_enc_tv_template,
2666 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2667 },
2668 .dec = {
2669 .vecs = des3_ede_ctr_dec_tv_template,
2670 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2671 }
2672 }
2673 }
2674 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002675 .alg = "ctr(serpent)",
2676 .test = alg_test_skcipher,
2677 .suite = {
2678 .cipher = {
2679 .enc = {
2680 .vecs = serpent_ctr_enc_tv_template,
2681 .count = SERPENT_CTR_ENC_TEST_VECTORS
2682 },
2683 .dec = {
2684 .vecs = serpent_ctr_dec_tv_template,
2685 .count = SERPENT_CTR_DEC_TEST_VECTORS
2686 }
2687 }
2688 }
2689 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002690 .alg = "ctr(twofish)",
2691 .test = alg_test_skcipher,
2692 .suite = {
2693 .cipher = {
2694 .enc = {
2695 .vecs = tf_ctr_enc_tv_template,
2696 .count = TF_CTR_ENC_TEST_VECTORS
2697 },
2698 .dec = {
2699 .vecs = tf_ctr_dec_tv_template,
2700 .count = TF_CTR_DEC_TEST_VECTORS
2701 }
2702 }
2703 }
2704 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002705 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002706 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002707 .suite = {
2708 .cipher = {
2709 .enc = {
2710 .vecs = cts_mode_enc_tv_template,
2711 .count = CTS_MODE_ENC_TEST_VECTORS
2712 },
2713 .dec = {
2714 .vecs = cts_mode_dec_tv_template,
2715 .count = CTS_MODE_DEC_TEST_VECTORS
2716 }
2717 }
2718 }
2719 }, {
2720 .alg = "deflate",
2721 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002722 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002723 .suite = {
2724 .comp = {
2725 .comp = {
2726 .vecs = deflate_comp_tv_template,
2727 .count = DEFLATE_COMP_TEST_VECTORS
2728 },
2729 .decomp = {
2730 .vecs = deflate_decomp_tv_template,
2731 .count = DEFLATE_DECOMP_TEST_VECTORS
2732 }
2733 }
2734 }
2735 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002736 .alg = "digest_null",
2737 .test = alg_test_null,
2738 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002739 .alg = "drbg_nopr_ctr_aes128",
2740 .test = alg_test_drbg,
2741 .fips_allowed = 1,
2742 .suite = {
2743 .drbg = {
2744 .vecs = drbg_nopr_ctr_aes128_tv_template,
2745 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2746 }
2747 }
2748 }, {
2749 .alg = "drbg_nopr_ctr_aes192",
2750 .test = alg_test_drbg,
2751 .fips_allowed = 1,
2752 .suite = {
2753 .drbg = {
2754 .vecs = drbg_nopr_ctr_aes192_tv_template,
2755 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2756 }
2757 }
2758 }, {
2759 .alg = "drbg_nopr_ctr_aes256",
2760 .test = alg_test_drbg,
2761 .fips_allowed = 1,
2762 .suite = {
2763 .drbg = {
2764 .vecs = drbg_nopr_ctr_aes256_tv_template,
2765 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2766 }
2767 }
2768 }, {
2769 /*
2770 * There is no need to specifically test the DRBG with every
2771 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2772 */
2773 .alg = "drbg_nopr_hmac_sha1",
2774 .fips_allowed = 1,
2775 .test = alg_test_null,
2776 }, {
2777 .alg = "drbg_nopr_hmac_sha256",
2778 .test = alg_test_drbg,
2779 .fips_allowed = 1,
2780 .suite = {
2781 .drbg = {
2782 .vecs = drbg_nopr_hmac_sha256_tv_template,
2783 .count =
2784 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2785 }
2786 }
2787 }, {
2788 /* covered by drbg_nopr_hmac_sha256 test */
2789 .alg = "drbg_nopr_hmac_sha384",
2790 .fips_allowed = 1,
2791 .test = alg_test_null,
2792 }, {
2793 .alg = "drbg_nopr_hmac_sha512",
2794 .test = alg_test_null,
2795 .fips_allowed = 1,
2796 }, {
2797 .alg = "drbg_nopr_sha1",
2798 .fips_allowed = 1,
2799 .test = alg_test_null,
2800 }, {
2801 .alg = "drbg_nopr_sha256",
2802 .test = alg_test_drbg,
2803 .fips_allowed = 1,
2804 .suite = {
2805 .drbg = {
2806 .vecs = drbg_nopr_sha256_tv_template,
2807 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2808 }
2809 }
2810 }, {
2811 /* covered by drbg_nopr_sha256 test */
2812 .alg = "drbg_nopr_sha384",
2813 .fips_allowed = 1,
2814 .test = alg_test_null,
2815 }, {
2816 .alg = "drbg_nopr_sha512",
2817 .fips_allowed = 1,
2818 .test = alg_test_null,
2819 }, {
2820 .alg = "drbg_pr_ctr_aes128",
2821 .test = alg_test_drbg,
2822 .fips_allowed = 1,
2823 .suite = {
2824 .drbg = {
2825 .vecs = drbg_pr_ctr_aes128_tv_template,
2826 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2827 }
2828 }
2829 }, {
2830 /* covered by drbg_pr_ctr_aes128 test */
2831 .alg = "drbg_pr_ctr_aes192",
2832 .fips_allowed = 1,
2833 .test = alg_test_null,
2834 }, {
2835 .alg = "drbg_pr_ctr_aes256",
2836 .fips_allowed = 1,
2837 .test = alg_test_null,
2838 }, {
2839 .alg = "drbg_pr_hmac_sha1",
2840 .fips_allowed = 1,
2841 .test = alg_test_null,
2842 }, {
2843 .alg = "drbg_pr_hmac_sha256",
2844 .test = alg_test_drbg,
2845 .fips_allowed = 1,
2846 .suite = {
2847 .drbg = {
2848 .vecs = drbg_pr_hmac_sha256_tv_template,
2849 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2850 }
2851 }
2852 }, {
2853 /* covered by drbg_pr_hmac_sha256 test */
2854 .alg = "drbg_pr_hmac_sha384",
2855 .fips_allowed = 1,
2856 .test = alg_test_null,
2857 }, {
2858 .alg = "drbg_pr_hmac_sha512",
2859 .test = alg_test_null,
2860 .fips_allowed = 1,
2861 }, {
2862 .alg = "drbg_pr_sha1",
2863 .fips_allowed = 1,
2864 .test = alg_test_null,
2865 }, {
2866 .alg = "drbg_pr_sha256",
2867 .test = alg_test_drbg,
2868 .fips_allowed = 1,
2869 .suite = {
2870 .drbg = {
2871 .vecs = drbg_pr_sha256_tv_template,
2872 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2873 }
2874 }
2875 }, {
2876 /* covered by drbg_pr_sha256 test */
2877 .alg = "drbg_pr_sha384",
2878 .fips_allowed = 1,
2879 .test = alg_test_null,
2880 }, {
2881 .alg = "drbg_pr_sha512",
2882 .fips_allowed = 1,
2883 .test = alg_test_null,
2884 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002885 .alg = "ecb(__aes-aesni)",
2886 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002887 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002888 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002889 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002890 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002891 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002892 .suite = {
2893 .cipher = {
2894 .enc = {
2895 .vecs = aes_enc_tv_template,
2896 .count = AES_ENC_TEST_VECTORS
2897 },
2898 .dec = {
2899 .vecs = aes_dec_tv_template,
2900 .count = AES_DEC_TEST_VECTORS
2901 }
2902 }
2903 }
2904 }, {
2905 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002906 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002907 .suite = {
2908 .cipher = {
2909 .enc = {
2910 .vecs = anubis_enc_tv_template,
2911 .count = ANUBIS_ENC_TEST_VECTORS
2912 },
2913 .dec = {
2914 .vecs = anubis_dec_tv_template,
2915 .count = ANUBIS_DEC_TEST_VECTORS
2916 }
2917 }
2918 }
2919 }, {
2920 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002921 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002922 .suite = {
2923 .cipher = {
2924 .enc = {
2925 .vecs = arc4_enc_tv_template,
2926 .count = ARC4_ENC_TEST_VECTORS
2927 },
2928 .dec = {
2929 .vecs = arc4_dec_tv_template,
2930 .count = ARC4_DEC_TEST_VECTORS
2931 }
2932 }
2933 }
2934 }, {
2935 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002936 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002937 .suite = {
2938 .cipher = {
2939 .enc = {
2940 .vecs = bf_enc_tv_template,
2941 .count = BF_ENC_TEST_VECTORS
2942 },
2943 .dec = {
2944 .vecs = bf_dec_tv_template,
2945 .count = BF_DEC_TEST_VECTORS
2946 }
2947 }
2948 }
2949 }, {
2950 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002951 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002952 .suite = {
2953 .cipher = {
2954 .enc = {
2955 .vecs = camellia_enc_tv_template,
2956 .count = CAMELLIA_ENC_TEST_VECTORS
2957 },
2958 .dec = {
2959 .vecs = camellia_dec_tv_template,
2960 .count = CAMELLIA_DEC_TEST_VECTORS
2961 }
2962 }
2963 }
2964 }, {
2965 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002966 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002967 .suite = {
2968 .cipher = {
2969 .enc = {
2970 .vecs = cast5_enc_tv_template,
2971 .count = CAST5_ENC_TEST_VECTORS
2972 },
2973 .dec = {
2974 .vecs = cast5_dec_tv_template,
2975 .count = CAST5_DEC_TEST_VECTORS
2976 }
2977 }
2978 }
2979 }, {
2980 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002981 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002982 .suite = {
2983 .cipher = {
2984 .enc = {
2985 .vecs = cast6_enc_tv_template,
2986 .count = CAST6_ENC_TEST_VECTORS
2987 },
2988 .dec = {
2989 .vecs = cast6_dec_tv_template,
2990 .count = CAST6_DEC_TEST_VECTORS
2991 }
2992 }
2993 }
2994 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002995 .alg = "ecb(cipher_null)",
2996 .test = alg_test_null,
2997 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002998 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002999 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003000 .suite = {
3001 .cipher = {
3002 .enc = {
3003 .vecs = des_enc_tv_template,
3004 .count = DES_ENC_TEST_VECTORS
3005 },
3006 .dec = {
3007 .vecs = des_dec_tv_template,
3008 .count = DES_DEC_TEST_VECTORS
3009 }
3010 }
3011 }
3012 }, {
3013 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003014 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003015 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003016 .suite = {
3017 .cipher = {
3018 .enc = {
3019 .vecs = des3_ede_enc_tv_template,
3020 .count = DES3_EDE_ENC_TEST_VECTORS
3021 },
3022 .dec = {
3023 .vecs = des3_ede_dec_tv_template,
3024 .count = DES3_EDE_DEC_TEST_VECTORS
3025 }
3026 }
3027 }
3028 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003029 .alg = "ecb(fcrypt)",
3030 .test = alg_test_skcipher,
3031 .suite = {
3032 .cipher = {
3033 .enc = {
3034 .vecs = fcrypt_pcbc_enc_tv_template,
3035 .count = 1
3036 },
3037 .dec = {
3038 .vecs = fcrypt_pcbc_dec_tv_template,
3039 .count = 1
3040 }
3041 }
3042 }
3043 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003044 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003045 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003046 .suite = {
3047 .cipher = {
3048 .enc = {
3049 .vecs = khazad_enc_tv_template,
3050 .count = KHAZAD_ENC_TEST_VECTORS
3051 },
3052 .dec = {
3053 .vecs = khazad_dec_tv_template,
3054 .count = KHAZAD_DEC_TEST_VECTORS
3055 }
3056 }
3057 }
3058 }, {
3059 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003060 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003061 .suite = {
3062 .cipher = {
3063 .enc = {
3064 .vecs = seed_enc_tv_template,
3065 .count = SEED_ENC_TEST_VECTORS
3066 },
3067 .dec = {
3068 .vecs = seed_dec_tv_template,
3069 .count = SEED_DEC_TEST_VECTORS
3070 }
3071 }
3072 }
3073 }, {
3074 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003075 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003076 .suite = {
3077 .cipher = {
3078 .enc = {
3079 .vecs = serpent_enc_tv_template,
3080 .count = SERPENT_ENC_TEST_VECTORS
3081 },
3082 .dec = {
3083 .vecs = serpent_dec_tv_template,
3084 .count = SERPENT_DEC_TEST_VECTORS
3085 }
3086 }
3087 }
3088 }, {
3089 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003090 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003091 .suite = {
3092 .cipher = {
3093 .enc = {
3094 .vecs = tea_enc_tv_template,
3095 .count = TEA_ENC_TEST_VECTORS
3096 },
3097 .dec = {
3098 .vecs = tea_dec_tv_template,
3099 .count = TEA_DEC_TEST_VECTORS
3100 }
3101 }
3102 }
3103 }, {
3104 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003105 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003106 .suite = {
3107 .cipher = {
3108 .enc = {
3109 .vecs = tnepres_enc_tv_template,
3110 .count = TNEPRES_ENC_TEST_VECTORS
3111 },
3112 .dec = {
3113 .vecs = tnepres_dec_tv_template,
3114 .count = TNEPRES_DEC_TEST_VECTORS
3115 }
3116 }
3117 }
3118 }, {
3119 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003120 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003121 .suite = {
3122 .cipher = {
3123 .enc = {
3124 .vecs = tf_enc_tv_template,
3125 .count = TF_ENC_TEST_VECTORS
3126 },
3127 .dec = {
3128 .vecs = tf_dec_tv_template,
3129 .count = TF_DEC_TEST_VECTORS
3130 }
3131 }
3132 }
3133 }, {
3134 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003135 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003136 .suite = {
3137 .cipher = {
3138 .enc = {
3139 .vecs = xeta_enc_tv_template,
3140 .count = XETA_ENC_TEST_VECTORS
3141 },
3142 .dec = {
3143 .vecs = xeta_dec_tv_template,
3144 .count = XETA_DEC_TEST_VECTORS
3145 }
3146 }
3147 }
3148 }, {
3149 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003150 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003151 .suite = {
3152 .cipher = {
3153 .enc = {
3154 .vecs = xtea_enc_tv_template,
3155 .count = XTEA_ENC_TEST_VECTORS
3156 },
3157 .dec = {
3158 .vecs = xtea_dec_tv_template,
3159 .count = XTEA_DEC_TEST_VECTORS
3160 }
3161 }
3162 }
3163 }, {
3164 .alg = "gcm(aes)",
3165 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003166 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003167 .suite = {
3168 .aead = {
3169 .enc = {
3170 .vecs = aes_gcm_enc_tv_template,
3171 .count = AES_GCM_ENC_TEST_VECTORS
3172 },
3173 .dec = {
3174 .vecs = aes_gcm_dec_tv_template,
3175 .count = AES_GCM_DEC_TEST_VECTORS
3176 }
3177 }
3178 }
3179 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003180 .alg = "ghash",
3181 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003182 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003183 .suite = {
3184 .hash = {
3185 .vecs = ghash_tv_template,
3186 .count = GHASH_TEST_VECTORS
3187 }
3188 }
3189 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003190 .alg = "hmac(crc32)",
3191 .test = alg_test_hash,
3192 .suite = {
3193 .hash = {
3194 .vecs = bfin_crc_tv_template,
3195 .count = BFIN_CRC_TEST_VECTORS
3196 }
3197 }
3198 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003199 .alg = "hmac(md5)",
3200 .test = alg_test_hash,
3201 .suite = {
3202 .hash = {
3203 .vecs = hmac_md5_tv_template,
3204 .count = HMAC_MD5_TEST_VECTORS
3205 }
3206 }
3207 }, {
3208 .alg = "hmac(rmd128)",
3209 .test = alg_test_hash,
3210 .suite = {
3211 .hash = {
3212 .vecs = hmac_rmd128_tv_template,
3213 .count = HMAC_RMD128_TEST_VECTORS
3214 }
3215 }
3216 }, {
3217 .alg = "hmac(rmd160)",
3218 .test = alg_test_hash,
3219 .suite = {
3220 .hash = {
3221 .vecs = hmac_rmd160_tv_template,
3222 .count = HMAC_RMD160_TEST_VECTORS
3223 }
3224 }
3225 }, {
3226 .alg = "hmac(sha1)",
3227 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003228 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003229 .suite = {
3230 .hash = {
3231 .vecs = hmac_sha1_tv_template,
3232 .count = HMAC_SHA1_TEST_VECTORS
3233 }
3234 }
3235 }, {
3236 .alg = "hmac(sha224)",
3237 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003238 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003239 .suite = {
3240 .hash = {
3241 .vecs = hmac_sha224_tv_template,
3242 .count = HMAC_SHA224_TEST_VECTORS
3243 }
3244 }
3245 }, {
3246 .alg = "hmac(sha256)",
3247 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003248 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003249 .suite = {
3250 .hash = {
3251 .vecs = hmac_sha256_tv_template,
3252 .count = HMAC_SHA256_TEST_VECTORS
3253 }
3254 }
3255 }, {
3256 .alg = "hmac(sha384)",
3257 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003258 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003259 .suite = {
3260 .hash = {
3261 .vecs = hmac_sha384_tv_template,
3262 .count = HMAC_SHA384_TEST_VECTORS
3263 }
3264 }
3265 }, {
3266 .alg = "hmac(sha512)",
3267 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003268 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003269 .suite = {
3270 .hash = {
3271 .vecs = hmac_sha512_tv_template,
3272 .count = HMAC_SHA512_TEST_VECTORS
3273 }
3274 }
3275 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003276 .alg = "jitterentropy_rng",
3277 .fips_allowed = 1,
3278 .test = alg_test_null,
3279 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003280 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003281 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003282 .suite = {
3283 .cipher = {
3284 .enc = {
3285 .vecs = aes_lrw_enc_tv_template,
3286 .count = AES_LRW_ENC_TEST_VECTORS
3287 },
3288 .dec = {
3289 .vecs = aes_lrw_dec_tv_template,
3290 .count = AES_LRW_DEC_TEST_VECTORS
3291 }
3292 }
3293 }
3294 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003295 .alg = "lrw(camellia)",
3296 .test = alg_test_skcipher,
3297 .suite = {
3298 .cipher = {
3299 .enc = {
3300 .vecs = camellia_lrw_enc_tv_template,
3301 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3302 },
3303 .dec = {
3304 .vecs = camellia_lrw_dec_tv_template,
3305 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3306 }
3307 }
3308 }
3309 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003310 .alg = "lrw(cast6)",
3311 .test = alg_test_skcipher,
3312 .suite = {
3313 .cipher = {
3314 .enc = {
3315 .vecs = cast6_lrw_enc_tv_template,
3316 .count = CAST6_LRW_ENC_TEST_VECTORS
3317 },
3318 .dec = {
3319 .vecs = cast6_lrw_dec_tv_template,
3320 .count = CAST6_LRW_DEC_TEST_VECTORS
3321 }
3322 }
3323 }
3324 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003325 .alg = "lrw(serpent)",
3326 .test = alg_test_skcipher,
3327 .suite = {
3328 .cipher = {
3329 .enc = {
3330 .vecs = serpent_lrw_enc_tv_template,
3331 .count = SERPENT_LRW_ENC_TEST_VECTORS
3332 },
3333 .dec = {
3334 .vecs = serpent_lrw_dec_tv_template,
3335 .count = SERPENT_LRW_DEC_TEST_VECTORS
3336 }
3337 }
3338 }
3339 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003340 .alg = "lrw(twofish)",
3341 .test = alg_test_skcipher,
3342 .suite = {
3343 .cipher = {
3344 .enc = {
3345 .vecs = tf_lrw_enc_tv_template,
3346 .count = TF_LRW_ENC_TEST_VECTORS
3347 },
3348 .dec = {
3349 .vecs = tf_lrw_dec_tv_template,
3350 .count = TF_LRW_DEC_TEST_VECTORS
3351 }
3352 }
3353 }
3354 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003355 .alg = "lz4",
3356 .test = alg_test_comp,
3357 .fips_allowed = 1,
3358 .suite = {
3359 .comp = {
3360 .comp = {
3361 .vecs = lz4_comp_tv_template,
3362 .count = LZ4_COMP_TEST_VECTORS
3363 },
3364 .decomp = {
3365 .vecs = lz4_decomp_tv_template,
3366 .count = LZ4_DECOMP_TEST_VECTORS
3367 }
3368 }
3369 }
3370 }, {
3371 .alg = "lz4hc",
3372 .test = alg_test_comp,
3373 .fips_allowed = 1,
3374 .suite = {
3375 .comp = {
3376 .comp = {
3377 .vecs = lz4hc_comp_tv_template,
3378 .count = LZ4HC_COMP_TEST_VECTORS
3379 },
3380 .decomp = {
3381 .vecs = lz4hc_decomp_tv_template,
3382 .count = LZ4HC_DECOMP_TEST_VECTORS
3383 }
3384 }
3385 }
3386 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003387 .alg = "lzo",
3388 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003389 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003390 .suite = {
3391 .comp = {
3392 .comp = {
3393 .vecs = lzo_comp_tv_template,
3394 .count = LZO_COMP_TEST_VECTORS
3395 },
3396 .decomp = {
3397 .vecs = lzo_decomp_tv_template,
3398 .count = LZO_DECOMP_TEST_VECTORS
3399 }
3400 }
3401 }
3402 }, {
3403 .alg = "md4",
3404 .test = alg_test_hash,
3405 .suite = {
3406 .hash = {
3407 .vecs = md4_tv_template,
3408 .count = MD4_TEST_VECTORS
3409 }
3410 }
3411 }, {
3412 .alg = "md5",
3413 .test = alg_test_hash,
3414 .suite = {
3415 .hash = {
3416 .vecs = md5_tv_template,
3417 .count = MD5_TEST_VECTORS
3418 }
3419 }
3420 }, {
3421 .alg = "michael_mic",
3422 .test = alg_test_hash,
3423 .suite = {
3424 .hash = {
3425 .vecs = michael_mic_tv_template,
3426 .count = MICHAEL_MIC_TEST_VECTORS
3427 }
3428 }
3429 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003430 .alg = "ofb(aes)",
3431 .test = alg_test_skcipher,
3432 .fips_allowed = 1,
3433 .suite = {
3434 .cipher = {
3435 .enc = {
3436 .vecs = aes_ofb_enc_tv_template,
3437 .count = AES_OFB_ENC_TEST_VECTORS
3438 },
3439 .dec = {
3440 .vecs = aes_ofb_dec_tv_template,
3441 .count = AES_OFB_DEC_TEST_VECTORS
3442 }
3443 }
3444 }
3445 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003446 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003447 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003448 .suite = {
3449 .cipher = {
3450 .enc = {
3451 .vecs = fcrypt_pcbc_enc_tv_template,
3452 .count = FCRYPT_ENC_TEST_VECTORS
3453 },
3454 .dec = {
3455 .vecs = fcrypt_pcbc_dec_tv_template,
3456 .count = FCRYPT_DEC_TEST_VECTORS
3457 }
3458 }
3459 }
3460 }, {
Martin Willieee9dc62015-06-01 13:43:59 +02003461 .alg = "poly1305",
3462 .test = alg_test_hash,
3463 .suite = {
3464 .hash = {
3465 .vecs = poly1305_tv_template,
3466 .count = POLY1305_TEST_VECTORS
3467 }
3468 }
3469 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003470 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003471 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003472 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003473 .suite = {
3474 .cipher = {
3475 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003476 .vecs = aes_ctr_rfc3686_enc_tv_template,
3477 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003478 },
3479 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003480 .vecs = aes_ctr_rfc3686_dec_tv_template,
3481 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003482 }
3483 }
3484 }
3485 }, {
Herbert Xu3f31a742015-07-09 07:17:34 +08003486 .alg = "rfc4106(gcm(aes))",
Adrian Hoban69435b92010-11-04 15:02:04 -04003487 .test = alg_test_aead,
Jarod Wilsondb71f292015-01-23 12:42:15 -05003488 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003489 .suite = {
3490 .aead = {
3491 .enc = {
3492 .vecs = aes_gcm_rfc4106_enc_tv_template,
3493 .count = AES_GCM_4106_ENC_TEST_VECTORS
3494 },
3495 .dec = {
3496 .vecs = aes_gcm_rfc4106_dec_tv_template,
3497 .count = AES_GCM_4106_DEC_TEST_VECTORS
3498 }
3499 }
3500 }
3501 }, {
Herbert Xu544c4362015-07-14 16:53:22 +08003502 .alg = "rfc4309(ccm(aes))",
Jarod Wilson5d667322009-05-04 19:23:40 +08003503 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003504 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003505 .suite = {
3506 .aead = {
3507 .enc = {
3508 .vecs = aes_ccm_rfc4309_enc_tv_template,
3509 .count = AES_CCM_4309_ENC_TEST_VECTORS
3510 },
3511 .dec = {
3512 .vecs = aes_ccm_rfc4309_dec_tv_template,
3513 .count = AES_CCM_4309_DEC_TEST_VECTORS
3514 }
3515 }
3516 }
3517 }, {
Herbert Xubb687452015-06-16 13:54:24 +08003518 .alg = "rfc4543(gcm(aes))",
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003519 .test = alg_test_aead,
3520 .suite = {
3521 .aead = {
3522 .enc = {
3523 .vecs = aes_gcm_rfc4543_enc_tv_template,
3524 .count = AES_GCM_4543_ENC_TEST_VECTORS
3525 },
3526 .dec = {
3527 .vecs = aes_gcm_rfc4543_dec_tv_template,
3528 .count = AES_GCM_4543_DEC_TEST_VECTORS
3529 },
3530 }
3531 }
3532 }, {
Martin Williaf2b76b2015-06-01 13:44:01 +02003533 .alg = "rfc7539(chacha20,poly1305)",
3534 .test = alg_test_aead,
3535 .suite = {
3536 .aead = {
3537 .enc = {
3538 .vecs = rfc7539_enc_tv_template,
3539 .count = RFC7539_ENC_TEST_VECTORS
3540 },
3541 .dec = {
3542 .vecs = rfc7539_dec_tv_template,
3543 .count = RFC7539_DEC_TEST_VECTORS
3544 },
3545 }
3546 }
3547 }, {
Martin Willi59007582015-06-01 13:44:03 +02003548 .alg = "rfc7539esp(chacha20,poly1305)",
3549 .test = alg_test_aead,
3550 .suite = {
3551 .aead = {
3552 .enc = {
3553 .vecs = rfc7539esp_enc_tv_template,
3554 .count = RFC7539ESP_ENC_TEST_VECTORS
3555 },
3556 .dec = {
3557 .vecs = rfc7539esp_dec_tv_template,
3558 .count = RFC7539ESP_DEC_TEST_VECTORS
3559 },
3560 }
3561 }
3562 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003563 .alg = "rmd128",
3564 .test = alg_test_hash,
3565 .suite = {
3566 .hash = {
3567 .vecs = rmd128_tv_template,
3568 .count = RMD128_TEST_VECTORS
3569 }
3570 }
3571 }, {
3572 .alg = "rmd160",
3573 .test = alg_test_hash,
3574 .suite = {
3575 .hash = {
3576 .vecs = rmd160_tv_template,
3577 .count = RMD160_TEST_VECTORS
3578 }
3579 }
3580 }, {
3581 .alg = "rmd256",
3582 .test = alg_test_hash,
3583 .suite = {
3584 .hash = {
3585 .vecs = rmd256_tv_template,
3586 .count = RMD256_TEST_VECTORS
3587 }
3588 }
3589 }, {
3590 .alg = "rmd320",
3591 .test = alg_test_hash,
3592 .suite = {
3593 .hash = {
3594 .vecs = rmd320_tv_template,
3595 .count = RMD320_TEST_VECTORS
3596 }
3597 }
3598 }, {
Tadeusz Struk946cc462015-06-16 10:31:06 -07003599 .alg = "rsa",
3600 .test = alg_test_akcipher,
3601 .fips_allowed = 1,
3602 .suite = {
3603 .akcipher = {
3604 .vecs = rsa_tv_template,
3605 .count = RSA_TEST_VECTORS
3606 }
3607 }
3608 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003609 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003610 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003611 .suite = {
3612 .cipher = {
3613 .enc = {
3614 .vecs = salsa20_stream_enc_tv_template,
3615 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3616 }
3617 }
3618 }
3619 }, {
3620 .alg = "sha1",
3621 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003622 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003623 .suite = {
3624 .hash = {
3625 .vecs = sha1_tv_template,
3626 .count = SHA1_TEST_VECTORS
3627 }
3628 }
3629 }, {
3630 .alg = "sha224",
3631 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003632 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003633 .suite = {
3634 .hash = {
3635 .vecs = sha224_tv_template,
3636 .count = SHA224_TEST_VECTORS
3637 }
3638 }
3639 }, {
3640 .alg = "sha256",
3641 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003642 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003643 .suite = {
3644 .hash = {
3645 .vecs = sha256_tv_template,
3646 .count = SHA256_TEST_VECTORS
3647 }
3648 }
3649 }, {
3650 .alg = "sha384",
3651 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003652 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003653 .suite = {
3654 .hash = {
3655 .vecs = sha384_tv_template,
3656 .count = SHA384_TEST_VECTORS
3657 }
3658 }
3659 }, {
3660 .alg = "sha512",
3661 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003662 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003663 .suite = {
3664 .hash = {
3665 .vecs = sha512_tv_template,
3666 .count = SHA512_TEST_VECTORS
3667 }
3668 }
3669 }, {
3670 .alg = "tgr128",
3671 .test = alg_test_hash,
3672 .suite = {
3673 .hash = {
3674 .vecs = tgr128_tv_template,
3675 .count = TGR128_TEST_VECTORS
3676 }
3677 }
3678 }, {
3679 .alg = "tgr160",
3680 .test = alg_test_hash,
3681 .suite = {
3682 .hash = {
3683 .vecs = tgr160_tv_template,
3684 .count = TGR160_TEST_VECTORS
3685 }
3686 }
3687 }, {
3688 .alg = "tgr192",
3689 .test = alg_test_hash,
3690 .suite = {
3691 .hash = {
3692 .vecs = tgr192_tv_template,
3693 .count = TGR192_TEST_VECTORS
3694 }
3695 }
3696 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003697 .alg = "vmac(aes)",
3698 .test = alg_test_hash,
3699 .suite = {
3700 .hash = {
3701 .vecs = aes_vmac128_tv_template,
3702 .count = VMAC_AES_TEST_VECTORS
3703 }
3704 }
3705 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003706 .alg = "wp256",
3707 .test = alg_test_hash,
3708 .suite = {
3709 .hash = {
3710 .vecs = wp256_tv_template,
3711 .count = WP256_TEST_VECTORS
3712 }
3713 }
3714 }, {
3715 .alg = "wp384",
3716 .test = alg_test_hash,
3717 .suite = {
3718 .hash = {
3719 .vecs = wp384_tv_template,
3720 .count = WP384_TEST_VECTORS
3721 }
3722 }
3723 }, {
3724 .alg = "wp512",
3725 .test = alg_test_hash,
3726 .suite = {
3727 .hash = {
3728 .vecs = wp512_tv_template,
3729 .count = WP512_TEST_VECTORS
3730 }
3731 }
3732 }, {
3733 .alg = "xcbc(aes)",
3734 .test = alg_test_hash,
3735 .suite = {
3736 .hash = {
3737 .vecs = aes_xcbc128_tv_template,
3738 .count = XCBC_AES_TEST_VECTORS
3739 }
3740 }
3741 }, {
3742 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003743 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003744 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003745 .suite = {
3746 .cipher = {
3747 .enc = {
3748 .vecs = aes_xts_enc_tv_template,
3749 .count = AES_XTS_ENC_TEST_VECTORS
3750 },
3751 .dec = {
3752 .vecs = aes_xts_dec_tv_template,
3753 .count = AES_XTS_DEC_TEST_VECTORS
3754 }
3755 }
3756 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003757 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003758 .alg = "xts(camellia)",
3759 .test = alg_test_skcipher,
3760 .suite = {
3761 .cipher = {
3762 .enc = {
3763 .vecs = camellia_xts_enc_tv_template,
3764 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3765 },
3766 .dec = {
3767 .vecs = camellia_xts_dec_tv_template,
3768 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3769 }
3770 }
3771 }
3772 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003773 .alg = "xts(cast6)",
3774 .test = alg_test_skcipher,
3775 .suite = {
3776 .cipher = {
3777 .enc = {
3778 .vecs = cast6_xts_enc_tv_template,
3779 .count = CAST6_XTS_ENC_TEST_VECTORS
3780 },
3781 .dec = {
3782 .vecs = cast6_xts_dec_tv_template,
3783 .count = CAST6_XTS_DEC_TEST_VECTORS
3784 }
3785 }
3786 }
3787 }, {
Jussi Kivilinna18be20b2011-10-18 13:33:17 +03003788 .alg = "xts(serpent)",
3789 .test = alg_test_skcipher,
3790 .suite = {
3791 .cipher = {
3792 .enc = {
3793 .vecs = serpent_xts_enc_tv_template,
3794 .count = SERPENT_XTS_ENC_TEST_VECTORS
3795 },
3796 .dec = {
3797 .vecs = serpent_xts_dec_tv_template,
3798 .count = SERPENT_XTS_DEC_TEST_VECTORS
3799 }
3800 }
3801 }
3802 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003803 .alg = "xts(twofish)",
3804 .test = alg_test_skcipher,
3805 .suite = {
3806 .cipher = {
3807 .enc = {
3808 .vecs = tf_xts_enc_tv_template,
3809 .count = TF_XTS_ENC_TEST_VECTORS
3810 },
3811 .dec = {
3812 .vecs = tf_xts_dec_tv_template,
3813 .count = TF_XTS_DEC_TEST_VECTORS
3814 }
3815 }
3816 }
3817 }, {
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003818 .alg = "zlib",
3819 .test = alg_test_pcomp,
Milan Broz08189042012-12-06 17:16:28 +08003820 .fips_allowed = 1,
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003821 .suite = {
3822 .pcomp = {
3823 .comp = {
3824 .vecs = zlib_comp_tv_template,
3825 .count = ZLIB_COMP_TEST_VECTORS
3826 },
3827 .decomp = {
3828 .vecs = zlib_decomp_tv_template,
3829 .count = ZLIB_DECOMP_TEST_VECTORS
3830 }
3831 }
3832 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003833 }
3834};
3835
Jussi Kivilinna57147582013-06-13 17:37:40 +03003836static bool alg_test_descs_checked;
3837
3838static void alg_test_descs_check_order(void)
3839{
3840 int i;
3841
3842 /* only check once */
3843 if (alg_test_descs_checked)
3844 return;
3845
3846 alg_test_descs_checked = true;
3847
3848 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3849 int diff = strcmp(alg_test_descs[i - 1].alg,
3850 alg_test_descs[i].alg);
3851
3852 if (WARN_ON(diff > 0)) {
3853 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3854 alg_test_descs[i - 1].alg,
3855 alg_test_descs[i].alg);
3856 }
3857
3858 if (WARN_ON(diff == 0)) {
3859 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3860 alg_test_descs[i].alg);
3861 }
3862 }
3863}
3864
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003865static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003866{
3867 int start = 0;
3868 int end = ARRAY_SIZE(alg_test_descs);
3869
3870 while (start < end) {
3871 int i = (start + end) / 2;
3872 int diff = strcmp(alg_test_descs[i].alg, alg);
3873
3874 if (diff > 0) {
3875 end = i;
3876 continue;
3877 }
3878
3879 if (diff < 0) {
3880 start = i + 1;
3881 continue;
3882 }
3883
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003884 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003885 }
3886
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003887 return -1;
3888}
3889
3890int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3891{
3892 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003893 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003894 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003895
Jussi Kivilinna57147582013-06-13 17:37:40 +03003896 alg_test_descs_check_order();
3897
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003898 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3899 char nalg[CRYPTO_MAX_ALG_NAME];
3900
3901 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3902 sizeof(nalg))
3903 return -ENAMETOOLONG;
3904
3905 i = alg_find_test(nalg);
3906 if (i < 0)
3907 goto notest;
3908
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003909 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3910 goto non_fips_alg;
3911
Jarod Wilson941fb322009-05-04 19:49:23 +08003912 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3913 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003914 }
3915
3916 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003917 j = alg_find_test(driver);
3918 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003919 goto notest;
3920
Herbert Xua68f6612009-07-02 16:32:12 +08003921 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3922 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003923 goto non_fips_alg;
3924
Herbert Xua68f6612009-07-02 16:32:12 +08003925 rc = 0;
3926 if (i >= 0)
3927 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3928 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003929 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003930 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3931 type, mask);
3932
Jarod Wilson941fb322009-05-04 19:49:23 +08003933test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003934 if (fips_enabled && rc)
3935 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3936
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003937 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09003938 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003939
Neil Hormand12d6b62008-10-12 20:36:51 +08003940 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003941
3942notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003943 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3944 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003945non_fips_alg:
3946 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003947}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003948
Herbert Xu326a6342010-08-06 09:40:28 +08003949#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003950
Herbert Xuda7f0332008-07-31 17:08:25 +08003951EXPORT_SYMBOL_GPL(alg_test);