blob: 500a5277cc22adbf7313362c7a9b2fabbdf49323 [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>
Salvatore Benedetto802c7f12016-06-22 17:49:14 +010035#include <crypto/kpp.h>
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +010036#include <crypto/acompress.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080037
38#include "internal.h"
Alexander Shishkin0b767f92010-06-03 20:53:43 +100039
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +010040static bool notests;
41module_param(notests, bool, 0644);
42MODULE_PARM_DESC(notests, "disable crypto self-tests");
43
Herbert Xu326a6342010-08-06 09:40:28 +080044#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
Alexander Shishkin0b767f92010-06-03 20:53:43 +100045
46/* a perfect nop */
47int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
48{
49 return 0;
50}
51
52#else
53
Herbert Xuda7f0332008-07-31 17:08:25 +080054#include "testmgr.h"
55
56/*
57 * Need slab memory for testing (size in number of pages).
58 */
59#define XBUFSIZE 8
60
61/*
62 * Indexes into the xbuf to simulate cross-page access.
63 */
64#define IDX1 32
65#define IDX2 32400
Ard Biesheuvel04b46fb2016-12-08 08:23:52 +000066#define IDX3 1511
Herbert Xuda7f0332008-07-31 17:08:25 +080067#define IDX4 8193
68#define IDX5 22222
69#define IDX6 17101
70#define IDX7 27333
71#define IDX8 3000
72
73/*
74* Used by test_cipher()
75*/
76#define ENCRYPT 1
77#define DECRYPT 0
78
79struct tcrypt_result {
80 struct completion completion;
81 int err;
82};
83
84struct aead_test_suite {
85 struct {
86 struct aead_testvec *vecs;
87 unsigned int count;
88 } enc, dec;
89};
90
91struct cipher_test_suite {
92 struct {
93 struct cipher_testvec *vecs;
94 unsigned int count;
95 } enc, dec;
96};
97
98struct comp_test_suite {
99 struct {
100 struct comp_testvec *vecs;
101 unsigned int count;
102 } comp, decomp;
103};
104
105struct hash_test_suite {
106 struct hash_testvec *vecs;
107 unsigned int count;
108};
109
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800110struct cprng_test_suite {
111 struct cprng_testvec *vecs;
112 unsigned int count;
113};
114
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200115struct drbg_test_suite {
116 struct drbg_testvec *vecs;
117 unsigned int count;
118};
119
Tadeusz Struk946cc462015-06-16 10:31:06 -0700120struct akcipher_test_suite {
121 struct akcipher_testvec *vecs;
122 unsigned int count;
123};
124
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100125struct kpp_test_suite {
126 struct kpp_testvec *vecs;
127 unsigned int count;
128};
129
Herbert Xuda7f0332008-07-31 17:08:25 +0800130struct alg_test_desc {
131 const char *alg;
132 int (*test)(const struct alg_test_desc *desc, const char *driver,
133 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000134 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800135
136 union {
137 struct aead_test_suite aead;
138 struct cipher_test_suite cipher;
139 struct comp_test_suite comp;
140 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800141 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200142 struct drbg_test_suite drbg;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700143 struct akcipher_test_suite akcipher;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100144 struct kpp_test_suite kpp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800145 } suite;
146};
147
148static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
149
Herbert Xuda7f0332008-07-31 17:08:25 +0800150static void hexdump(unsigned char *buf, unsigned int len)
151{
152 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
153 16, 1,
154 buf, len, false);
155}
156
157static void tcrypt_complete(struct crypto_async_request *req, int err)
158{
159 struct tcrypt_result *res = req->data;
160
161 if (err == -EINPROGRESS)
162 return;
163
164 res->err = err;
165 complete(&res->completion);
166}
167
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800168static int testmgr_alloc_buf(char *buf[XBUFSIZE])
169{
170 int i;
171
172 for (i = 0; i < XBUFSIZE; i++) {
173 buf[i] = (void *)__get_free_page(GFP_KERNEL);
174 if (!buf[i])
175 goto err_free_buf;
176 }
177
178 return 0;
179
180err_free_buf:
181 while (i-- > 0)
182 free_page((unsigned long)buf[i]);
183
184 return -ENOMEM;
185}
186
187static void testmgr_free_buf(char *buf[XBUFSIZE])
188{
189 int i;
190
191 for (i = 0; i < XBUFSIZE; i++)
192 free_page((unsigned long)buf[i]);
193}
194
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300195static int wait_async_op(struct tcrypt_result *tr, int ret)
David S. Millera8f1a052010-05-19 14:12:03 +1000196{
197 if (ret == -EINPROGRESS || ret == -EBUSY) {
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100198 wait_for_completion(&tr->completion);
Wolfram Sang16735d02013-11-14 14:32:02 -0800199 reinit_completion(&tr->completion);
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100200 ret = tr->err;
David S. Millera8f1a052010-05-19 14:12:03 +1000201 }
202 return ret;
203}
204
Wang, Rui Y018ba952016-02-03 18:26:57 +0800205static int ahash_partial_update(struct ahash_request **preq,
206 struct crypto_ahash *tfm, struct hash_testvec *template,
207 void *hash_buff, int k, int temp, struct scatterlist *sg,
208 const char *algo, char *result, struct tcrypt_result *tresult)
209{
210 char *state;
211 struct ahash_request *req;
212 int statesize, ret = -EINVAL;
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200213 const char guard[] = { 0x00, 0xba, 0xad, 0x00 };
Wang, Rui Y018ba952016-02-03 18:26:57 +0800214
215 req = *preq;
216 statesize = crypto_ahash_statesize(
217 crypto_ahash_reqtfm(req));
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200218 state = kmalloc(statesize + sizeof(guard), GFP_KERNEL);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800219 if (!state) {
220 pr_err("alt: hash: Failed to alloc state for %s\n", algo);
221 goto out_nostate;
222 }
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200223 memcpy(state + statesize, guard, sizeof(guard));
Wang, Rui Y018ba952016-02-03 18:26:57 +0800224 ret = crypto_ahash_export(req, state);
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200225 WARN_ON(memcmp(state + statesize, guard, sizeof(guard)));
Wang, Rui Y018ba952016-02-03 18:26:57 +0800226 if (ret) {
227 pr_err("alt: hash: Failed to export() for %s\n", algo);
228 goto out;
229 }
230 ahash_request_free(req);
231 req = ahash_request_alloc(tfm, GFP_KERNEL);
232 if (!req) {
233 pr_err("alg: hash: Failed to alloc request for %s\n", algo);
234 goto out_noreq;
235 }
236 ahash_request_set_callback(req,
237 CRYPTO_TFM_REQ_MAY_BACKLOG,
238 tcrypt_complete, tresult);
239
240 memcpy(hash_buff, template->plaintext + temp,
241 template->tap[k]);
242 sg_init_one(&sg[0], hash_buff, template->tap[k]);
243 ahash_request_set_crypt(req, sg, result, template->tap[k]);
244 ret = crypto_ahash_import(req, state);
245 if (ret) {
246 pr_err("alg: hash: Failed to import() for %s\n", algo);
247 goto out;
248 }
249 ret = wait_async_op(tresult, crypto_ahash_update(req));
250 if (ret)
251 goto out;
252 *preq = req;
253 ret = 0;
254 goto out_noreq;
255out:
256 ahash_request_free(req);
257out_noreq:
258 kfree(state);
259out_nostate:
260 return ret;
261}
262
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300263static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
264 unsigned int tcount, bool use_digest,
265 const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800266{
267 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800268 size_t digest_size = crypto_ahash_digestsize(tfm);
Herbert Xuda7f0332008-07-31 17:08:25 +0800269 unsigned int i, j, k, temp;
270 struct scatterlist sg[8];
Horia Geanta29b77e52014-07-23 11:59:38 +0300271 char *result;
272 char *key;
Herbert Xuda7f0332008-07-31 17:08:25 +0800273 struct ahash_request *req;
274 struct tcrypt_result tresult;
Herbert Xuda7f0332008-07-31 17:08:25 +0800275 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800276 char *xbuf[XBUFSIZE];
277 int ret = -ENOMEM;
278
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800279 result = kmalloc(digest_size, GFP_KERNEL);
Horia Geanta29b77e52014-07-23 11:59:38 +0300280 if (!result)
281 return ret;
282 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
283 if (!key)
284 goto out_nobuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800285 if (testmgr_alloc_buf(xbuf))
286 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800287
288 init_completion(&tresult.completion);
289
290 req = ahash_request_alloc(tfm, GFP_KERNEL);
291 if (!req) {
292 printk(KERN_ERR "alg: hash: Failed to allocate request for "
293 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800294 goto out_noreq;
295 }
296 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
297 tcrypt_complete, &tresult);
298
Herbert Xua0cfae52009-05-29 16:23:12 +1000299 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800300 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000301 if (template[i].np)
302 continue;
303
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300304 ret = -EINVAL;
305 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
306 goto out;
307
Herbert Xua0cfae52009-05-29 16:23:12 +1000308 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800309 memset(result, 0, digest_size);
Herbert Xuda7f0332008-07-31 17:08:25 +0800310
311 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300312 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800313
314 memcpy(hash_buff, template[i].plaintext, template[i].psize);
315 sg_init_one(&sg[0], hash_buff, template[i].psize);
316
317 if (template[i].ksize) {
318 crypto_ahash_clear_flags(tfm, ~0);
Horia Geanta29b77e52014-07-23 11:59:38 +0300319 if (template[i].ksize > MAX_KEYLEN) {
320 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
321 j, algo, template[i].ksize, MAX_KEYLEN);
322 ret = -EINVAL;
323 goto out;
324 }
325 memcpy(key, template[i].key, template[i].ksize);
326 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
Herbert Xuda7f0332008-07-31 17:08:25 +0800327 if (ret) {
328 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000329 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800330 -ret);
331 goto out;
332 }
333 }
334
335 ahash_request_set_crypt(req, sg, result, template[i].psize);
David S. Millera8f1a052010-05-19 14:12:03 +1000336 if (use_digest) {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300337 ret = wait_async_op(&tresult, crypto_ahash_digest(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000338 if (ret) {
339 pr_err("alg: hash: digest failed on test %d "
340 "for %s: ret=%d\n", j, algo, -ret);
341 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800342 }
David S. Millera8f1a052010-05-19 14:12:03 +1000343 } else {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300344 ret = wait_async_op(&tresult, crypto_ahash_init(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000345 if (ret) {
346 pr_err("alt: hash: init failed on test %d "
347 "for %s: ret=%d\n", j, algo, -ret);
348 goto out;
349 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300350 ret = wait_async_op(&tresult, crypto_ahash_update(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000351 if (ret) {
352 pr_err("alt: hash: update failed on test %d "
353 "for %s: ret=%d\n", j, algo, -ret);
354 goto out;
355 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300356 ret = wait_async_op(&tresult, crypto_ahash_final(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000357 if (ret) {
358 pr_err("alt: hash: final failed on test %d "
359 "for %s: ret=%d\n", j, algo, -ret);
360 goto out;
361 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800362 }
363
364 if (memcmp(result, template[i].digest,
365 crypto_ahash_digestsize(tfm))) {
366 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000367 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800368 hexdump(result, crypto_ahash_digestsize(tfm));
369 ret = -EINVAL;
370 goto out;
371 }
372 }
373
374 j = 0;
375 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300376 /* alignment tests are only done with continuous buffers */
377 if (align_offset != 0)
378 break;
379
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300380 if (!template[i].np)
381 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800382
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300383 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800384 memset(result, 0, digest_size);
Herbert Xuda7f0332008-07-31 17:08:25 +0800385
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300386 temp = 0;
387 sg_init_table(sg, template[i].np);
388 ret = -EINVAL;
389 for (k = 0; k < template[i].np; k++) {
390 if (WARN_ON(offset_in_page(IDX[k]) +
391 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +0800392 goto out;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300393 sg_set_buf(&sg[k],
394 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
395 offset_in_page(IDX[k]),
396 template[i].plaintext + temp,
397 template[i].tap[k]),
398 template[i].tap[k]);
399 temp += template[i].tap[k];
400 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800401
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300402 if (template[i].ksize) {
403 if (template[i].ksize > MAX_KEYLEN) {
404 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
405 j, algo, template[i].ksize, MAX_KEYLEN);
Herbert Xuda7f0332008-07-31 17:08:25 +0800406 ret = -EINVAL;
407 goto out;
408 }
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300409 crypto_ahash_clear_flags(tfm, ~0);
410 memcpy(key, template[i].key, template[i].ksize);
411 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
412
413 if (ret) {
414 printk(KERN_ERR "alg: hash: setkey "
415 "failed on chunking test %d "
416 "for %s: ret=%d\n", j, algo, -ret);
417 goto out;
418 }
419 }
420
421 ahash_request_set_crypt(req, sg, result, template[i].psize);
422 ret = crypto_ahash_digest(req);
423 switch (ret) {
424 case 0:
425 break;
426 case -EINPROGRESS:
427 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100428 wait_for_completion(&tresult.completion);
429 reinit_completion(&tresult.completion);
430 ret = tresult.err;
431 if (!ret)
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300432 break;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300433 /* fall through */
434 default:
435 printk(KERN_ERR "alg: hash: digest failed "
436 "on chunking test %d for %s: "
437 "ret=%d\n", j, algo, -ret);
438 goto out;
439 }
440
441 if (memcmp(result, template[i].digest,
442 crypto_ahash_digestsize(tfm))) {
443 printk(KERN_ERR "alg: hash: Chunking test %d "
444 "failed for %s\n", j, algo);
445 hexdump(result, crypto_ahash_digestsize(tfm));
446 ret = -EINVAL;
447 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800448 }
449 }
450
Wang, Rui Y018ba952016-02-03 18:26:57 +0800451 /* partial update exercise */
452 j = 0;
453 for (i = 0; i < tcount; i++) {
454 /* alignment tests are only done with continuous buffers */
455 if (align_offset != 0)
456 break;
457
458 if (template[i].np < 2)
459 continue;
460
461 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800462 memset(result, 0, digest_size);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800463
464 ret = -EINVAL;
465 hash_buff = xbuf[0];
466 memcpy(hash_buff, template[i].plaintext,
467 template[i].tap[0]);
468 sg_init_one(&sg[0], hash_buff, template[i].tap[0]);
469
470 if (template[i].ksize) {
471 crypto_ahash_clear_flags(tfm, ~0);
472 if (template[i].ksize > MAX_KEYLEN) {
473 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
474 j, algo, template[i].ksize, MAX_KEYLEN);
475 ret = -EINVAL;
476 goto out;
477 }
478 memcpy(key, template[i].key, template[i].ksize);
479 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
480 if (ret) {
481 pr_err("alg: hash: setkey failed on test %d for %s: ret=%d\n",
482 j, algo, -ret);
483 goto out;
484 }
485 }
486
487 ahash_request_set_crypt(req, sg, result, template[i].tap[0]);
488 ret = wait_async_op(&tresult, crypto_ahash_init(req));
489 if (ret) {
490 pr_err("alt: hash: init failed on test %d for %s: ret=%d\n",
491 j, algo, -ret);
492 goto out;
493 }
494 ret = wait_async_op(&tresult, crypto_ahash_update(req));
495 if (ret) {
496 pr_err("alt: hash: update failed on test %d for %s: ret=%d\n",
497 j, algo, -ret);
498 goto out;
499 }
500
501 temp = template[i].tap[0];
502 for (k = 1; k < template[i].np; k++) {
503 ret = ahash_partial_update(&req, tfm, &template[i],
504 hash_buff, k, temp, &sg[0], algo, result,
505 &tresult);
506 if (ret) {
507 pr_err("hash: partial update failed on test %d for %s: ret=%d\n",
508 j, algo, -ret);
509 goto out_noreq;
510 }
511 temp += template[i].tap[k];
512 }
513 ret = wait_async_op(&tresult, crypto_ahash_final(req));
514 if (ret) {
515 pr_err("alt: hash: final failed on test %d for %s: ret=%d\n",
516 j, algo, -ret);
517 goto out;
518 }
519 if (memcmp(result, template[i].digest,
520 crypto_ahash_digestsize(tfm))) {
521 pr_err("alg: hash: Partial Test %d failed for %s\n",
522 j, algo);
523 hexdump(result, crypto_ahash_digestsize(tfm));
524 ret = -EINVAL;
525 goto out;
526 }
527 }
528
Herbert Xuda7f0332008-07-31 17:08:25 +0800529 ret = 0;
530
531out:
532 ahash_request_free(req);
533out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800534 testmgr_free_buf(xbuf);
535out_nobuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300536 kfree(key);
537 kfree(result);
Herbert Xuda7f0332008-07-31 17:08:25 +0800538 return ret;
539}
540
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300541static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
542 unsigned int tcount, bool use_digest)
543{
544 unsigned int alignmask;
545 int ret;
546
547 ret = __test_hash(tfm, template, tcount, use_digest, 0);
548 if (ret)
549 return ret;
550
551 /* test unaligned buffers, check with one byte offset */
552 ret = __test_hash(tfm, template, tcount, use_digest, 1);
553 if (ret)
554 return ret;
555
556 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
557 if (alignmask) {
558 /* Check if alignment mask for tfm is correctly set. */
559 ret = __test_hash(tfm, template, tcount, use_digest,
560 alignmask + 1);
561 if (ret)
562 return ret;
563 }
564
565 return 0;
566}
567
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300568static int __test_aead(struct crypto_aead *tfm, int enc,
569 struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300570 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800571{
572 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
573 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800574 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800575 char *q;
576 char *key;
577 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300578 struct scatterlist *sg;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300579 struct scatterlist *sgout;
580 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800581 struct tcrypt_result result;
Cristian Stoica424a5da2015-01-28 11:03:05 +0200582 unsigned int authsize, iv_len;
Herbert Xuda7f0332008-07-31 17:08:25 +0800583 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300584 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800585 void *assoc;
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700586 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800587 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300588 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800589 char *axbuf[XBUFSIZE];
590
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700591 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
592 if (!iv)
593 return ret;
Horia Geanta29b77e52014-07-23 11:59:38 +0300594 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
595 if (!key)
596 goto out_noxbuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800597 if (testmgr_alloc_buf(xbuf))
598 goto out_noxbuf;
599 if (testmgr_alloc_buf(axbuf))
600 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300601 if (diff_dst && testmgr_alloc_buf(xoutbuf))
602 goto out_nooutbuf;
603
604 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800605 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 4 : 2), GFP_KERNEL);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300606 if (!sg)
607 goto out_nosg;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800608 sgout = &sg[16];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300609
610 if (diff_dst)
611 d = "-ddst";
612 else
613 d = "";
614
Herbert Xuda7f0332008-07-31 17:08:25 +0800615 if (enc == ENCRYPT)
616 e = "encryption";
617 else
618 e = "decryption";
619
620 init_completion(&result.completion);
621
622 req = aead_request_alloc(tfm, GFP_KERNEL);
623 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300624 pr_err("alg: aead%s: Failed to allocate request for %s\n",
625 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800626 goto out;
627 }
628
629 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
630 tcrypt_complete, &result);
631
Jerome Marchandabfa7f42016-02-03 13:58:12 +0100632 iv_len = crypto_aead_ivsize(tfm);
633
Herbert Xuda7f0332008-07-31 17:08:25 +0800634 for (i = 0, j = 0; i < tcount; i++) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300635 if (template[i].np)
636 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800637
Cristian Stoica05b1d332014-07-28 13:11:23 +0300638 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800639
Cristian Stoica05b1d332014-07-28 13:11:23 +0300640 /* some templates have no input data but they will
641 * touch input
642 */
643 input = xbuf[0];
644 input += align_offset;
645 assoc = axbuf[0];
646
647 ret = -EINVAL;
648 if (WARN_ON(align_offset + template[i].ilen >
649 PAGE_SIZE || template[i].alen > PAGE_SIZE))
650 goto out;
651
652 memcpy(input, template[i].input, template[i].ilen);
653 memcpy(assoc, template[i].assoc, template[i].alen);
654 if (template[i].iv)
Cristian Stoica424a5da2015-01-28 11:03:05 +0200655 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300656 else
Cristian Stoica424a5da2015-01-28 11:03:05 +0200657 memset(iv, 0, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300658
659 crypto_aead_clear_flags(tfm, ~0);
660 if (template[i].wk)
661 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
662
663 if (template[i].klen > MAX_KEYLEN) {
664 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
665 d, j, algo, template[i].klen,
666 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +1000667 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300668 goto out;
669 }
670 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +1000671
Cristian Stoica05b1d332014-07-28 13:11:23 +0300672 ret = crypto_aead_setkey(tfm, key, template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +0800673 if (template[i].fail == !ret) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300674 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
675 d, j, algo, crypto_aead_get_flags(tfm));
676 goto out;
677 } else if (ret)
678 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800679
Cristian Stoica05b1d332014-07-28 13:11:23 +0300680 authsize = abs(template[i].rlen - template[i].ilen);
681 ret = crypto_aead_setauthsize(tfm, authsize);
682 if (ret) {
683 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
684 d, authsize, j, algo);
685 goto out;
686 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800687
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800688 k = !!template[i].alen;
689 sg_init_table(sg, k + 1);
690 sg_set_buf(&sg[0], assoc, template[i].alen);
691 sg_set_buf(&sg[k], input,
692 template[i].ilen + (enc ? authsize : 0));
693 output = input;
694
Cristian Stoica05b1d332014-07-28 13:11:23 +0300695 if (diff_dst) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800696 sg_init_table(sgout, k + 1);
697 sg_set_buf(&sgout[0], assoc, template[i].alen);
698
Cristian Stoica05b1d332014-07-28 13:11:23 +0300699 output = xoutbuf[0];
700 output += align_offset;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800701 sg_set_buf(&sgout[k], output,
702 template[i].rlen + (enc ? 0 : authsize));
Cristian Stoica05b1d332014-07-28 13:11:23 +0300703 }
704
Cristian Stoica05b1d332014-07-28 13:11:23 +0300705 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
706 template[i].ilen, iv);
707
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800708 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300709
710 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
711
712 switch (ret) {
713 case 0:
714 if (template[i].novrfy) {
715 /* verification was supposed to fail */
716 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
717 d, e, j, algo);
718 /* so really, we got a bad message */
719 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +0300720 goto out;
721 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300722 break;
723 case -EINPROGRESS:
724 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100725 wait_for_completion(&result.completion);
726 reinit_completion(&result.completion);
727 ret = result.err;
728 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +0800729 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300730 case -EBADMSG:
731 if (template[i].novrfy)
732 /* verification failure was expected */
733 continue;
734 /* fall through */
735 default:
736 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
737 d, e, j, algo, -ret);
738 goto out;
739 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800740
Cristian Stoica05b1d332014-07-28 13:11:23 +0300741 q = output;
742 if (memcmp(q, template[i].result, template[i].rlen)) {
743 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
744 d, j, e, algo);
745 hexdump(q, template[i].rlen);
746 ret = -EINVAL;
747 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800748 }
749 }
750
751 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300752 /* alignment tests are only done with continuous buffers */
753 if (align_offset != 0)
754 break;
755
Cristian Stoica05b1d332014-07-28 13:11:23 +0300756 if (!template[i].np)
757 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800758
Cristian Stoica05b1d332014-07-28 13:11:23 +0300759 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800760
Cristian Stoica05b1d332014-07-28 13:11:23 +0300761 if (template[i].iv)
Jerome Marchandabfa7f42016-02-03 13:58:12 +0100762 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300763 else
764 memset(iv, 0, MAX_IVLEN);
765
766 crypto_aead_clear_flags(tfm, ~0);
767 if (template[i].wk)
768 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
769 if (template[i].klen > MAX_KEYLEN) {
770 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
771 d, j, algo, template[i].klen, MAX_KEYLEN);
772 ret = -EINVAL;
773 goto out;
774 }
775 memcpy(key, template[i].key, template[i].klen);
776
777 ret = crypto_aead_setkey(tfm, key, template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +0800778 if (template[i].fail == !ret) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300779 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
780 d, j, algo, crypto_aead_get_flags(tfm));
781 goto out;
782 } else if (ret)
783 continue;
784
785 authsize = abs(template[i].rlen - template[i].ilen);
786
787 ret = -EINVAL;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800788 sg_init_table(sg, template[i].anp + template[i].np);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300789 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800790 sg_init_table(sgout, template[i].anp + template[i].np);
791
792 ret = -EINVAL;
793 for (k = 0, temp = 0; k < template[i].anp; k++) {
794 if (WARN_ON(offset_in_page(IDX[k]) +
795 template[i].atap[k] > PAGE_SIZE))
796 goto out;
797 sg_set_buf(&sg[k],
798 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
799 offset_in_page(IDX[k]),
800 template[i].assoc + temp,
801 template[i].atap[k]),
802 template[i].atap[k]);
803 if (diff_dst)
804 sg_set_buf(&sgout[k],
805 axbuf[IDX[k] >> PAGE_SHIFT] +
806 offset_in_page(IDX[k]),
807 template[i].atap[k]);
808 temp += template[i].atap[k];
809 }
810
Cristian Stoica05b1d332014-07-28 13:11:23 +0300811 for (k = 0, temp = 0; k < template[i].np; k++) {
812 if (WARN_ON(offset_in_page(IDX[k]) +
813 template[i].tap[k] > PAGE_SIZE))
814 goto out;
815
816 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
817 memcpy(q, template[i].input + temp, template[i].tap[k]);
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800818 sg_set_buf(&sg[template[i].anp + k],
819 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300820
821 if (diff_dst) {
822 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
823 offset_in_page(IDX[k]);
824
825 memset(q, 0, template[i].tap[k]);
826
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800827 sg_set_buf(&sgout[template[i].anp + k],
828 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300829 }
830
831 n = template[i].tap[k];
832 if (k == template[i].np - 1 && enc)
833 n += authsize;
834 if (offset_in_page(q) + n < PAGE_SIZE)
835 q[n] = 0;
836
837 temp += template[i].tap[k];
838 }
839
840 ret = crypto_aead_setauthsize(tfm, authsize);
841 if (ret) {
842 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
843 d, authsize, j, algo);
844 goto out;
845 }
846
847 if (enc) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800848 if (WARN_ON(sg[template[i].anp + k - 1].offset +
849 sg[template[i].anp + k - 1].length +
850 authsize > PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300851 ret = -EINVAL;
852 goto out;
853 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800854
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300855 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800856 sgout[template[i].anp + k - 1].length +=
857 authsize;
858 sg[template[i].anp + k - 1].length += authsize;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300859 }
860
861 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
862 template[i].ilen,
863 iv);
864
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800865 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300866
867 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
868
869 switch (ret) {
870 case 0:
871 if (template[i].novrfy) {
872 /* verification was supposed to fail */
873 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
874 d, e, j, algo);
875 /* so really, we got a bad message */
876 ret = -EBADMSG;
877 goto out;
878 }
879 break;
880 case -EINPROGRESS:
881 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100882 wait_for_completion(&result.completion);
883 reinit_completion(&result.completion);
884 ret = result.err;
885 if (!ret)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300886 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300887 case -EBADMSG:
888 if (template[i].novrfy)
889 /* verification failure was expected */
890 continue;
891 /* fall through */
892 default:
893 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
894 d, e, j, algo, -ret);
895 goto out;
896 }
897
898 ret = -EINVAL;
899 for (k = 0, temp = 0; k < template[i].np; k++) {
900 if (diff_dst)
901 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
902 offset_in_page(IDX[k]);
903 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800904 q = xbuf[IDX[k] >> PAGE_SHIFT] +
905 offset_in_page(IDX[k]);
906
Cristian Stoica05b1d332014-07-28 13:11:23 +0300907 n = template[i].tap[k];
908 if (k == template[i].np - 1)
909 n += enc ? authsize : -authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800910
Cristian Stoica05b1d332014-07-28 13:11:23 +0300911 if (memcmp(q, template[i].result + temp, n)) {
912 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
913 d, j, e, k, algo);
914 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800915 goto out;
916 }
917
Cristian Stoica05b1d332014-07-28 13:11:23 +0300918 q += n;
919 if (k == template[i].np - 1 && !enc) {
920 if (!diff_dst &&
921 memcmp(q, template[i].input +
922 temp + n, authsize))
923 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200924 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300925 n = 0;
926 } else {
927 for (n = 0; offset_in_page(q + n) && q[n]; n++)
928 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800929 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300930 if (n) {
931 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
932 d, j, e, k, algo, n);
933 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800934 goto out;
935 }
936
Cristian Stoica05b1d332014-07-28 13:11:23 +0300937 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800938 }
939 }
940
941 ret = 0;
942
943out:
944 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300945 kfree(sg);
946out_nosg:
947 if (diff_dst)
948 testmgr_free_buf(xoutbuf);
949out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800950 testmgr_free_buf(axbuf);
951out_noaxbuf:
952 testmgr_free_buf(xbuf);
953out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300954 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700955 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800956 return ret;
957}
958
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300959static int test_aead(struct crypto_aead *tfm, int enc,
960 struct aead_testvec *template, unsigned int tcount)
961{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300962 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300963 int ret;
964
965 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300966 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300967 if (ret)
968 return ret;
969
970 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300971 ret = __test_aead(tfm, enc, template, tcount, true, 0);
972 if (ret)
973 return ret;
974
975 /* test unaligned buffers, check with one byte offset */
976 ret = __test_aead(tfm, enc, template, tcount, true, 1);
977 if (ret)
978 return ret;
979
980 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
981 if (alignmask) {
982 /* Check if alignment mask for tfm is correctly set. */
983 ret = __test_aead(tfm, enc, template, tcount, true,
984 alignmask + 1);
985 if (ret)
986 return ret;
987 }
988
989 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300990}
991
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000992static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800993 struct cipher_testvec *template, unsigned int tcount)
994{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000995 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
996 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000997 char *q;
998 const char *e;
999 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001000 char *xbuf[XBUFSIZE];
1001 int ret = -ENOMEM;
1002
1003 if (testmgr_alloc_buf(xbuf))
1004 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001005
1006 if (enc == ENCRYPT)
1007 e = "encryption";
1008 else
1009 e = "decryption";
1010
1011 j = 0;
1012 for (i = 0; i < tcount; i++) {
1013 if (template[i].np)
1014 continue;
1015
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001016 if (fips_enabled && template[i].fips_skip)
1017 continue;
1018
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001019 j++;
1020
Herbert Xufd57f222009-05-29 16:05:42 +10001021 ret = -EINVAL;
1022 if (WARN_ON(template[i].ilen > PAGE_SIZE))
1023 goto out;
1024
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001025 data = xbuf[0];
1026 memcpy(data, template[i].input, template[i].ilen);
1027
1028 crypto_cipher_clear_flags(tfm, ~0);
1029 if (template[i].wk)
1030 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1031
1032 ret = crypto_cipher_setkey(tfm, template[i].key,
1033 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001034 if (template[i].fail == !ret) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001035 printk(KERN_ERR "alg: cipher: setkey failed "
1036 "on test %d for %s: flags=%x\n", j,
1037 algo, crypto_cipher_get_flags(tfm));
1038 goto out;
1039 } else if (ret)
1040 continue;
1041
1042 for (k = 0; k < template[i].ilen;
1043 k += crypto_cipher_blocksize(tfm)) {
1044 if (enc)
1045 crypto_cipher_encrypt_one(tfm, data + k,
1046 data + k);
1047 else
1048 crypto_cipher_decrypt_one(tfm, data + k,
1049 data + k);
1050 }
1051
1052 q = data;
1053 if (memcmp(q, template[i].result, template[i].rlen)) {
1054 printk(KERN_ERR "alg: cipher: Test %d failed "
1055 "on %s for %s\n", j, e, algo);
1056 hexdump(q, template[i].rlen);
1057 ret = -EINVAL;
1058 goto out;
1059 }
1060 }
1061
1062 ret = 0;
1063
1064out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001065 testmgr_free_buf(xbuf);
1066out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001067 return ret;
1068}
1069
Herbert Xu12773d92015-08-20 15:21:46 +08001070static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001071 struct cipher_testvec *template, unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001072 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001073{
Herbert Xuda7f0332008-07-31 17:08:25 +08001074 const char *algo =
Herbert Xu12773d92015-08-20 15:21:46 +08001075 crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +08001076 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +08001077 char *q;
Herbert Xu12773d92015-08-20 15:21:46 +08001078 struct skcipher_request *req;
Herbert Xuda7f0332008-07-31 17:08:25 +08001079 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001080 struct scatterlist sgout[8];
1081 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +08001082 struct tcrypt_result result;
1083 void *data;
1084 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001085 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001086 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001087 int ret = -ENOMEM;
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001088 unsigned int ivsize = crypto_skcipher_ivsize(tfm);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001089
1090 if (testmgr_alloc_buf(xbuf))
1091 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +08001092
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001093 if (diff_dst && testmgr_alloc_buf(xoutbuf))
1094 goto out_nooutbuf;
1095
1096 if (diff_dst)
1097 d = "-ddst";
1098 else
1099 d = "";
1100
Herbert Xuda7f0332008-07-31 17:08:25 +08001101 if (enc == ENCRYPT)
1102 e = "encryption";
1103 else
1104 e = "decryption";
1105
1106 init_completion(&result.completion);
1107
Herbert Xu12773d92015-08-20 15:21:46 +08001108 req = skcipher_request_alloc(tfm, GFP_KERNEL);
Herbert Xuda7f0332008-07-31 17:08:25 +08001109 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001110 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
1111 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +08001112 goto out;
1113 }
1114
Herbert Xu12773d92015-08-20 15:21:46 +08001115 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1116 tcrypt_complete, &result);
Herbert Xuda7f0332008-07-31 17:08:25 +08001117
1118 j = 0;
1119 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001120 if (template[i].np && !template[i].also_non_np)
1121 continue;
1122
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001123 if (fips_enabled && template[i].fips_skip)
1124 continue;
1125
Herbert Xuda7f0332008-07-31 17:08:25 +08001126 if (template[i].iv)
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001127 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001128 else
1129 memset(iv, 0, MAX_IVLEN);
1130
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001131 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001132 ret = -EINVAL;
1133 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
1134 goto out;
1135
1136 data = xbuf[0];
1137 data += align_offset;
1138 memcpy(data, template[i].input, template[i].ilen);
1139
Herbert Xu12773d92015-08-20 15:21:46 +08001140 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001141 if (template[i].wk)
Herbert Xu12773d92015-08-20 15:21:46 +08001142 crypto_skcipher_set_flags(tfm,
1143 CRYPTO_TFM_REQ_WEAK_KEY);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001144
Herbert Xu12773d92015-08-20 15:21:46 +08001145 ret = crypto_skcipher_setkey(tfm, template[i].key,
1146 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001147 if (template[i].fail == !ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001148 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001149 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001150 goto out;
1151 } else if (ret)
1152 continue;
1153
1154 sg_init_one(&sg[0], data, template[i].ilen);
1155 if (diff_dst) {
1156 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001157 data += align_offset;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001158 sg_init_one(&sgout[0], data, template[i].ilen);
1159 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001160
Herbert Xu12773d92015-08-20 15:21:46 +08001161 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1162 template[i].ilen, iv);
1163 ret = enc ? crypto_skcipher_encrypt(req) :
1164 crypto_skcipher_decrypt(req);
Herbert Xuda7f0332008-07-31 17:08:25 +08001165
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001166 switch (ret) {
1167 case 0:
1168 break;
1169 case -EINPROGRESS:
1170 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001171 wait_for_completion(&result.completion);
1172 reinit_completion(&result.completion);
1173 ret = result.err;
1174 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +08001175 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001176 /* fall through */
1177 default:
1178 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1179 d, e, j, algo, -ret);
1180 goto out;
1181 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001182
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001183 q = data;
1184 if (memcmp(q, template[i].result, template[i].rlen)) {
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001185 pr_err("alg: skcipher%s: Test %d failed (invalid result) on %s for %s\n",
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001186 d, j, e, algo);
1187 hexdump(q, template[i].rlen);
1188 ret = -EINVAL;
1189 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001190 }
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001191
1192 if (template[i].iv_out &&
1193 memcmp(iv, template[i].iv_out,
1194 crypto_skcipher_ivsize(tfm))) {
1195 pr_err("alg: skcipher%s: Test %d failed (invalid output IV) on %s for %s\n",
1196 d, j, e, algo);
1197 hexdump(iv, crypto_skcipher_ivsize(tfm));
1198 ret = -EINVAL;
1199 goto out;
1200 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001201 }
1202
1203 j = 0;
1204 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001205 /* alignment tests are only done with continuous buffers */
1206 if (align_offset != 0)
1207 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001208
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001209 if (!template[i].np)
1210 continue;
1211
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001212 if (fips_enabled && template[i].fips_skip)
1213 continue;
1214
Herbert Xuda7f0332008-07-31 17:08:25 +08001215 if (template[i].iv)
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001216 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001217 else
1218 memset(iv, 0, MAX_IVLEN);
1219
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001220 j++;
Herbert Xu12773d92015-08-20 15:21:46 +08001221 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001222 if (template[i].wk)
Herbert Xu12773d92015-08-20 15:21:46 +08001223 crypto_skcipher_set_flags(tfm,
1224 CRYPTO_TFM_REQ_WEAK_KEY);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001225
Herbert Xu12773d92015-08-20 15:21:46 +08001226 ret = crypto_skcipher_setkey(tfm, template[i].key,
1227 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001228 if (template[i].fail == !ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001229 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001230 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001231 goto out;
1232 } else if (ret)
1233 continue;
1234
1235 temp = 0;
1236 ret = -EINVAL;
1237 sg_init_table(sg, template[i].np);
1238 if (diff_dst)
1239 sg_init_table(sgout, template[i].np);
1240 for (k = 0; k < template[i].np; k++) {
1241 if (WARN_ON(offset_in_page(IDX[k]) +
1242 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001243 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001244
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001245 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1246
1247 memcpy(q, template[i].input + temp, template[i].tap[k]);
1248
1249 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1250 q[template[i].tap[k]] = 0;
1251
1252 sg_set_buf(&sg[k], q, template[i].tap[k]);
1253 if (diff_dst) {
1254 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1255 offset_in_page(IDX[k]);
1256
1257 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1258
1259 memset(q, 0, template[i].tap[k]);
1260 if (offset_in_page(q) +
1261 template[i].tap[k] < PAGE_SIZE)
1262 q[template[i].tap[k]] = 0;
1263 }
1264
1265 temp += template[i].tap[k];
1266 }
1267
Herbert Xu12773d92015-08-20 15:21:46 +08001268 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1269 template[i].ilen, iv);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001270
Herbert Xu12773d92015-08-20 15:21:46 +08001271 ret = enc ? crypto_skcipher_encrypt(req) :
1272 crypto_skcipher_decrypt(req);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001273
1274 switch (ret) {
1275 case 0:
1276 break;
1277 case -EINPROGRESS:
1278 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001279 wait_for_completion(&result.completion);
1280 reinit_completion(&result.completion);
1281 ret = result.err;
1282 if (!ret)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001283 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001284 /* fall through */
1285 default:
1286 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1287 d, e, j, algo, -ret);
1288 goto out;
1289 }
1290
1291 temp = 0;
1292 ret = -EINVAL;
1293 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001294 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001295 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1296 offset_in_page(IDX[k]);
1297 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001298 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1299 offset_in_page(IDX[k]);
1300
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001301 if (memcmp(q, template[i].result + temp,
1302 template[i].tap[k])) {
1303 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1304 d, j, e, k, algo);
1305 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001306 goto out;
1307 }
1308
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001309 q += template[i].tap[k];
1310 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1311 ;
1312 if (n) {
1313 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1314 d, j, e, k, algo, n);
1315 hexdump(q, n);
1316 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001317 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001318 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001319 }
1320 }
1321
1322 ret = 0;
1323
1324out:
Herbert Xu12773d92015-08-20 15:21:46 +08001325 skcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001326 if (diff_dst)
1327 testmgr_free_buf(xoutbuf);
1328out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001329 testmgr_free_buf(xbuf);
1330out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001331 return ret;
1332}
1333
Herbert Xu12773d92015-08-20 15:21:46 +08001334static int test_skcipher(struct crypto_skcipher *tfm, int enc,
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001335 struct cipher_testvec *template, unsigned int tcount)
1336{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001337 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001338 int ret;
1339
1340 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001341 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001342 if (ret)
1343 return ret;
1344
1345 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001346 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1347 if (ret)
1348 return ret;
1349
1350 /* test unaligned buffers, check with one byte offset */
1351 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1352 if (ret)
1353 return ret;
1354
1355 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1356 if (alignmask) {
1357 /* Check if alignment mask for tfm is correctly set. */
1358 ret = __test_skcipher(tfm, enc, template, tcount, true,
1359 alignmask + 1);
1360 if (ret)
1361 return ret;
1362 }
1363
1364 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001365}
1366
Herbert Xuda7f0332008-07-31 17:08:25 +08001367static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1368 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1369{
1370 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1371 unsigned int i;
1372 char result[COMP_BUF_SIZE];
1373 int ret;
1374
1375 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001376 int ilen;
1377 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001378
1379 memset(result, 0, sizeof (result));
1380
1381 ilen = ctemplate[i].inlen;
1382 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1383 ilen, result, &dlen);
1384 if (ret) {
1385 printk(KERN_ERR "alg: comp: compression failed "
1386 "on test %d for %s: ret=%d\n", i + 1, algo,
1387 -ret);
1388 goto out;
1389 }
1390
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001391 if (dlen != ctemplate[i].outlen) {
1392 printk(KERN_ERR "alg: comp: Compression test %d "
1393 "failed for %s: output len = %d\n", i + 1, algo,
1394 dlen);
1395 ret = -EINVAL;
1396 goto out;
1397 }
1398
Herbert Xuda7f0332008-07-31 17:08:25 +08001399 if (memcmp(result, ctemplate[i].output, dlen)) {
1400 printk(KERN_ERR "alg: comp: Compression test %d "
1401 "failed for %s\n", i + 1, algo);
1402 hexdump(result, dlen);
1403 ret = -EINVAL;
1404 goto out;
1405 }
1406 }
1407
1408 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001409 int ilen;
1410 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001411
1412 memset(result, 0, sizeof (result));
1413
1414 ilen = dtemplate[i].inlen;
1415 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1416 ilen, result, &dlen);
1417 if (ret) {
1418 printk(KERN_ERR "alg: comp: decompression failed "
1419 "on test %d for %s: ret=%d\n", i + 1, algo,
1420 -ret);
1421 goto out;
1422 }
1423
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001424 if (dlen != dtemplate[i].outlen) {
1425 printk(KERN_ERR "alg: comp: Decompression test %d "
1426 "failed for %s: output len = %d\n", i + 1, algo,
1427 dlen);
1428 ret = -EINVAL;
1429 goto out;
1430 }
1431
Herbert Xuda7f0332008-07-31 17:08:25 +08001432 if (memcmp(result, dtemplate[i].output, dlen)) {
1433 printk(KERN_ERR "alg: comp: Decompression test %d "
1434 "failed for %s\n", i + 1, algo);
1435 hexdump(result, dlen);
1436 ret = -EINVAL;
1437 goto out;
1438 }
1439 }
1440
1441 ret = 0;
1442
1443out:
1444 return ret;
1445}
1446
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001447static int test_acomp(struct crypto_acomp *tfm, struct comp_testvec *ctemplate,
1448 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1449{
1450 const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
1451 unsigned int i;
Eric Biggerseb095592016-11-23 10:24:35 -08001452 char *output;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001453 int ret;
1454 struct scatterlist src, dst;
1455 struct acomp_req *req;
1456 struct tcrypt_result result;
1457
Eric Biggerseb095592016-11-23 10:24:35 -08001458 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1459 if (!output)
1460 return -ENOMEM;
1461
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001462 for (i = 0; i < ctcount; i++) {
1463 unsigned int dlen = COMP_BUF_SIZE;
1464 int ilen = ctemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08001465 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001466
Eric Biggersd2110222016-12-30 14:12:00 -06001467 input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08001468 if (!input_vec) {
1469 ret = -ENOMEM;
1470 goto out;
1471 }
1472
Eric Biggerseb095592016-11-23 10:24:35 -08001473 memset(output, 0, dlen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001474 init_completion(&result.completion);
Laura Abbott02608e02016-12-21 12:32:54 -08001475 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001476 sg_init_one(&dst, output, dlen);
1477
1478 req = acomp_request_alloc(tfm);
1479 if (!req) {
1480 pr_err("alg: acomp: request alloc failed for %s\n",
1481 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08001482 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001483 ret = -ENOMEM;
1484 goto out;
1485 }
1486
1487 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1488 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1489 tcrypt_complete, &result);
1490
1491 ret = wait_async_op(&result, crypto_acomp_compress(req));
1492 if (ret) {
1493 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
1494 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08001495 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001496 acomp_request_free(req);
1497 goto out;
1498 }
1499
1500 if (req->dlen != ctemplate[i].outlen) {
1501 pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
1502 i + 1, algo, req->dlen);
1503 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001504 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001505 acomp_request_free(req);
1506 goto out;
1507 }
1508
1509 if (memcmp(output, ctemplate[i].output, req->dlen)) {
1510 pr_err("alg: acomp: Compression test %d failed for %s\n",
1511 i + 1, algo);
1512 hexdump(output, req->dlen);
1513 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001514 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001515 acomp_request_free(req);
1516 goto out;
1517 }
1518
Laura Abbott02608e02016-12-21 12:32:54 -08001519 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001520 acomp_request_free(req);
1521 }
1522
1523 for (i = 0; i < dtcount; i++) {
1524 unsigned int dlen = COMP_BUF_SIZE;
1525 int ilen = dtemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08001526 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001527
Eric Biggersd2110222016-12-30 14:12:00 -06001528 input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08001529 if (!input_vec) {
1530 ret = -ENOMEM;
1531 goto out;
1532 }
1533
Eric Biggerseb095592016-11-23 10:24:35 -08001534 memset(output, 0, dlen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001535 init_completion(&result.completion);
Laura Abbott02608e02016-12-21 12:32:54 -08001536 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001537 sg_init_one(&dst, output, dlen);
1538
1539 req = acomp_request_alloc(tfm);
1540 if (!req) {
1541 pr_err("alg: acomp: request alloc failed for %s\n",
1542 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08001543 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001544 ret = -ENOMEM;
1545 goto out;
1546 }
1547
1548 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1549 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1550 tcrypt_complete, &result);
1551
1552 ret = wait_async_op(&result, crypto_acomp_decompress(req));
1553 if (ret) {
1554 pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
1555 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08001556 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001557 acomp_request_free(req);
1558 goto out;
1559 }
1560
1561 if (req->dlen != dtemplate[i].outlen) {
1562 pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
1563 i + 1, algo, req->dlen);
1564 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001565 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001566 acomp_request_free(req);
1567 goto out;
1568 }
1569
1570 if (memcmp(output, dtemplate[i].output, req->dlen)) {
1571 pr_err("alg: acomp: Decompression test %d failed for %s\n",
1572 i + 1, algo);
1573 hexdump(output, req->dlen);
1574 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001575 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001576 acomp_request_free(req);
1577 goto out;
1578 }
1579
Laura Abbott02608e02016-12-21 12:32:54 -08001580 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001581 acomp_request_free(req);
1582 }
1583
1584 ret = 0;
1585
1586out:
Eric Biggerseb095592016-11-23 10:24:35 -08001587 kfree(output);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001588 return ret;
1589}
1590
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001591static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1592 unsigned int tcount)
1593{
1594 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001595 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001596 u8 *seed;
1597 char result[32];
1598
1599 seedsize = crypto_rng_seedsize(tfm);
1600
1601 seed = kmalloc(seedsize, GFP_KERNEL);
1602 if (!seed) {
1603 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1604 "for %s\n", algo);
1605 return -ENOMEM;
1606 }
1607
1608 for (i = 0; i < tcount; i++) {
1609 memset(result, 0, 32);
1610
1611 memcpy(seed, template[i].v, template[i].vlen);
1612 memcpy(seed + template[i].vlen, template[i].key,
1613 template[i].klen);
1614 memcpy(seed + template[i].vlen + template[i].klen,
1615 template[i].dt, template[i].dtlen);
1616
1617 err = crypto_rng_reset(tfm, seed, seedsize);
1618 if (err) {
1619 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1620 "for %s\n", algo);
1621 goto out;
1622 }
1623
1624 for (j = 0; j < template[i].loops; j++) {
1625 err = crypto_rng_get_bytes(tfm, result,
1626 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01001627 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001628 printk(KERN_ERR "alg: cprng: Failed to obtain "
1629 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01001630 "%s (requested %d)\n", algo,
1631 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001632 goto out;
1633 }
1634 }
1635
1636 err = memcmp(result, template[i].result,
1637 template[i].rlen);
1638 if (err) {
1639 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1640 i, algo);
1641 hexdump(result, template[i].rlen);
1642 err = -EINVAL;
1643 goto out;
1644 }
1645 }
1646
1647out:
1648 kfree(seed);
1649 return err;
1650}
1651
Herbert Xuda7f0332008-07-31 17:08:25 +08001652static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1653 u32 type, u32 mask)
1654{
1655 struct crypto_aead *tfm;
1656 int err = 0;
1657
Herbert Xueed93e02016-11-22 20:08:31 +08001658 tfm = crypto_alloc_aead(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001659 if (IS_ERR(tfm)) {
1660 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1661 "%ld\n", driver, PTR_ERR(tfm));
1662 return PTR_ERR(tfm);
1663 }
1664
1665 if (desc->suite.aead.enc.vecs) {
1666 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1667 desc->suite.aead.enc.count);
1668 if (err)
1669 goto out;
1670 }
1671
1672 if (!err && desc->suite.aead.dec.vecs)
1673 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1674 desc->suite.aead.dec.count);
1675
1676out:
1677 crypto_free_aead(tfm);
1678 return err;
1679}
1680
1681static int alg_test_cipher(const struct alg_test_desc *desc,
1682 const char *driver, u32 type, u32 mask)
1683{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001684 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001685 int err = 0;
1686
Herbert Xueed93e02016-11-22 20:08:31 +08001687 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001688 if (IS_ERR(tfm)) {
1689 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1690 "%s: %ld\n", driver, PTR_ERR(tfm));
1691 return PTR_ERR(tfm);
1692 }
1693
1694 if (desc->suite.cipher.enc.vecs) {
1695 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1696 desc->suite.cipher.enc.count);
1697 if (err)
1698 goto out;
1699 }
1700
1701 if (desc->suite.cipher.dec.vecs)
1702 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1703 desc->suite.cipher.dec.count);
1704
1705out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001706 crypto_free_cipher(tfm);
1707 return err;
1708}
1709
1710static int alg_test_skcipher(const struct alg_test_desc *desc,
1711 const char *driver, u32 type, u32 mask)
1712{
Herbert Xu12773d92015-08-20 15:21:46 +08001713 struct crypto_skcipher *tfm;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001714 int err = 0;
1715
Herbert Xueed93e02016-11-22 20:08:31 +08001716 tfm = crypto_alloc_skcipher(driver, type, mask);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001717 if (IS_ERR(tfm)) {
1718 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1719 "%s: %ld\n", driver, PTR_ERR(tfm));
1720 return PTR_ERR(tfm);
1721 }
1722
1723 if (desc->suite.cipher.enc.vecs) {
1724 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1725 desc->suite.cipher.enc.count);
1726 if (err)
1727 goto out;
1728 }
1729
1730 if (desc->suite.cipher.dec.vecs)
1731 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1732 desc->suite.cipher.dec.count);
1733
1734out:
Herbert Xu12773d92015-08-20 15:21:46 +08001735 crypto_free_skcipher(tfm);
Herbert Xuda7f0332008-07-31 17:08:25 +08001736 return err;
1737}
1738
1739static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1740 u32 type, u32 mask)
1741{
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001742 struct crypto_comp *comp;
1743 struct crypto_acomp *acomp;
Herbert Xuda7f0332008-07-31 17:08:25 +08001744 int err;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001745 u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
Herbert Xuda7f0332008-07-31 17:08:25 +08001746
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001747 if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
1748 acomp = crypto_alloc_acomp(driver, type, mask);
1749 if (IS_ERR(acomp)) {
1750 pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
1751 driver, PTR_ERR(acomp));
1752 return PTR_ERR(acomp);
1753 }
1754 err = test_acomp(acomp, desc->suite.comp.comp.vecs,
1755 desc->suite.comp.decomp.vecs,
1756 desc->suite.comp.comp.count,
1757 desc->suite.comp.decomp.count);
1758 crypto_free_acomp(acomp);
1759 } else {
1760 comp = crypto_alloc_comp(driver, type, mask);
1761 if (IS_ERR(comp)) {
1762 pr_err("alg: comp: Failed to load transform for %s: %ld\n",
1763 driver, PTR_ERR(comp));
1764 return PTR_ERR(comp);
1765 }
1766
1767 err = test_comp(comp, desc->suite.comp.comp.vecs,
1768 desc->suite.comp.decomp.vecs,
1769 desc->suite.comp.comp.count,
1770 desc->suite.comp.decomp.count);
1771
1772 crypto_free_comp(comp);
Herbert Xuda7f0332008-07-31 17:08:25 +08001773 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001774 return err;
1775}
1776
1777static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1778 u32 type, u32 mask)
1779{
1780 struct crypto_ahash *tfm;
1781 int err;
1782
Herbert Xueed93e02016-11-22 20:08:31 +08001783 tfm = crypto_alloc_ahash(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001784 if (IS_ERR(tfm)) {
1785 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1786 "%ld\n", driver, PTR_ERR(tfm));
1787 return PTR_ERR(tfm);
1788 }
1789
David S. Millera8f1a052010-05-19 14:12:03 +10001790 err = test_hash(tfm, desc->suite.hash.vecs,
1791 desc->suite.hash.count, true);
1792 if (!err)
1793 err = test_hash(tfm, desc->suite.hash.vecs,
1794 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001795
1796 crypto_free_ahash(tfm);
1797 return err;
1798}
1799
Herbert Xu8e3ee852008-11-07 14:58:52 +08001800static int alg_test_crc32c(const struct alg_test_desc *desc,
1801 const char *driver, u32 type, u32 mask)
1802{
1803 struct crypto_shash *tfm;
1804 u32 val;
1805 int err;
1806
1807 err = alg_test_hash(desc, driver, type, mask);
1808 if (err)
1809 goto out;
1810
Herbert Xueed93e02016-11-22 20:08:31 +08001811 tfm = crypto_alloc_shash(driver, type, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001812 if (IS_ERR(tfm)) {
1813 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1814 "%ld\n", driver, PTR_ERR(tfm));
1815 err = PTR_ERR(tfm);
1816 goto out;
1817 }
1818
1819 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001820 SHASH_DESC_ON_STACK(shash, tfm);
1821 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001822
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001823 shash->tfm = tfm;
1824 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001825
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001826 *ctx = le32_to_cpu(420553207);
1827 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001828 if (err) {
1829 printk(KERN_ERR "alg: crc32c: Operation failed for "
1830 "%s: %d\n", driver, err);
1831 break;
1832 }
1833
1834 if (val != ~420553207) {
1835 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1836 "%d\n", driver, val);
1837 err = -EINVAL;
1838 }
1839 } while (0);
1840
1841 crypto_free_shash(tfm);
1842
1843out:
1844 return err;
1845}
1846
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001847static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1848 u32 type, u32 mask)
1849{
1850 struct crypto_rng *rng;
1851 int err;
1852
Herbert Xueed93e02016-11-22 20:08:31 +08001853 rng = crypto_alloc_rng(driver, type, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001854 if (IS_ERR(rng)) {
1855 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1856 "%ld\n", driver, PTR_ERR(rng));
1857 return PTR_ERR(rng);
1858 }
1859
1860 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1861
1862 crypto_free_rng(rng);
1863
1864 return err;
1865}
1866
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001867
1868static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1869 const char *driver, u32 type, u32 mask)
1870{
1871 int ret = -EAGAIN;
1872 struct crypto_rng *drng;
1873 struct drbg_test_data test_data;
1874 struct drbg_string addtl, pers, testentropy;
1875 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1876
1877 if (!buf)
1878 return -ENOMEM;
1879
Herbert Xueed93e02016-11-22 20:08:31 +08001880 drng = crypto_alloc_rng(driver, type, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001881 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001882 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001883 "%s\n", driver);
1884 kzfree(buf);
1885 return -ENOMEM;
1886 }
1887
1888 test_data.testentropy = &testentropy;
1889 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1890 drbg_string_fill(&pers, test->pers, test->perslen);
1891 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1892 if (ret) {
1893 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1894 goto outbuf;
1895 }
1896
1897 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1898 if (pr) {
1899 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1900 ret = crypto_drbg_get_bytes_addtl_test(drng,
1901 buf, test->expectedlen, &addtl, &test_data);
1902 } else {
1903 ret = crypto_drbg_get_bytes_addtl(drng,
1904 buf, test->expectedlen, &addtl);
1905 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001906 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001907 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001908 "driver %s\n", driver);
1909 goto outbuf;
1910 }
1911
1912 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1913 if (pr) {
1914 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1915 ret = crypto_drbg_get_bytes_addtl_test(drng,
1916 buf, test->expectedlen, &addtl, &test_data);
1917 } else {
1918 ret = crypto_drbg_get_bytes_addtl(drng,
1919 buf, test->expectedlen, &addtl);
1920 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001921 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001922 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001923 "driver %s\n", driver);
1924 goto outbuf;
1925 }
1926
1927 ret = memcmp(test->expected, buf, test->expectedlen);
1928
1929outbuf:
1930 crypto_free_rng(drng);
1931 kzfree(buf);
1932 return ret;
1933}
1934
1935
1936static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1937 u32 type, u32 mask)
1938{
1939 int err = 0;
1940 int pr = 0;
1941 int i = 0;
1942 struct drbg_testvec *template = desc->suite.drbg.vecs;
1943 unsigned int tcount = desc->suite.drbg.count;
1944
1945 if (0 == memcmp(driver, "drbg_pr_", 8))
1946 pr = 1;
1947
1948 for (i = 0; i < tcount; i++) {
1949 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1950 if (err) {
1951 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1952 i, driver);
1953 err = -EINVAL;
1954 break;
1955 }
1956 }
1957 return err;
1958
1959}
1960
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01001961static int do_test_kpp(struct crypto_kpp *tfm, struct kpp_testvec *vec,
1962 const char *alg)
1963{
1964 struct kpp_request *req;
1965 void *input_buf = NULL;
1966 void *output_buf = NULL;
1967 struct tcrypt_result result;
1968 unsigned int out_len_max;
1969 int err = -ENOMEM;
1970 struct scatterlist src, dst;
1971
1972 req = kpp_request_alloc(tfm, GFP_KERNEL);
1973 if (!req)
1974 return err;
1975
1976 init_completion(&result.completion);
1977
1978 err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
1979 if (err < 0)
1980 goto free_req;
1981
1982 out_len_max = crypto_kpp_maxsize(tfm);
1983 output_buf = kzalloc(out_len_max, GFP_KERNEL);
1984 if (!output_buf) {
1985 err = -ENOMEM;
1986 goto free_req;
1987 }
1988
1989 /* Use appropriate parameter as base */
1990 kpp_request_set_input(req, NULL, 0);
1991 sg_init_one(&dst, output_buf, out_len_max);
1992 kpp_request_set_output(req, &dst, out_len_max);
1993 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1994 tcrypt_complete, &result);
1995
1996 /* Compute public key */
1997 err = wait_async_op(&result, crypto_kpp_generate_public_key(req));
1998 if (err) {
1999 pr_err("alg: %s: generate public key test failed. err %d\n",
2000 alg, err);
2001 goto free_output;
2002 }
2003 /* Verify calculated public key */
2004 if (memcmp(vec->expected_a_public, sg_virt(req->dst),
2005 vec->expected_a_public_size)) {
2006 pr_err("alg: %s: generate public key test failed. Invalid output\n",
2007 alg);
2008 err = -EINVAL;
2009 goto free_output;
2010 }
2011
2012 /* Calculate shared secret key by using counter part (b) public key. */
2013 input_buf = kzalloc(vec->b_public_size, GFP_KERNEL);
2014 if (!input_buf) {
2015 err = -ENOMEM;
2016 goto free_output;
2017 }
2018
2019 memcpy(input_buf, vec->b_public, vec->b_public_size);
2020 sg_init_one(&src, input_buf, vec->b_public_size);
2021 sg_init_one(&dst, output_buf, out_len_max);
2022 kpp_request_set_input(req, &src, vec->b_public_size);
2023 kpp_request_set_output(req, &dst, out_len_max);
2024 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
2025 tcrypt_complete, &result);
2026 err = wait_async_op(&result, crypto_kpp_compute_shared_secret(req));
2027 if (err) {
2028 pr_err("alg: %s: compute shard secret test failed. err %d\n",
2029 alg, err);
2030 goto free_all;
2031 }
2032 /*
2033 * verify shared secret from which the user will derive
2034 * secret key by executing whatever hash it has chosen
2035 */
2036 if (memcmp(vec->expected_ss, sg_virt(req->dst),
2037 vec->expected_ss_size)) {
2038 pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
2039 alg);
2040 err = -EINVAL;
2041 }
2042
2043free_all:
2044 kfree(input_buf);
2045free_output:
2046 kfree(output_buf);
2047free_req:
2048 kpp_request_free(req);
2049 return err;
2050}
2051
2052static int test_kpp(struct crypto_kpp *tfm, const char *alg,
2053 struct kpp_testvec *vecs, unsigned int tcount)
2054{
2055 int ret, i;
2056
2057 for (i = 0; i < tcount; i++) {
2058 ret = do_test_kpp(tfm, vecs++, alg);
2059 if (ret) {
2060 pr_err("alg: %s: test failed on vector %d, err=%d\n",
2061 alg, i + 1, ret);
2062 return ret;
2063 }
2064 }
2065 return 0;
2066}
2067
2068static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
2069 u32 type, u32 mask)
2070{
2071 struct crypto_kpp *tfm;
2072 int err = 0;
2073
Herbert Xueed93e02016-11-22 20:08:31 +08002074 tfm = crypto_alloc_kpp(driver, type, mask);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002075 if (IS_ERR(tfm)) {
2076 pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
2077 driver, PTR_ERR(tfm));
2078 return PTR_ERR(tfm);
2079 }
2080 if (desc->suite.kpp.vecs)
2081 err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
2082 desc->suite.kpp.count);
2083
2084 crypto_free_kpp(tfm);
2085 return err;
2086}
2087
Herbert Xu50d2b6432016-06-29 19:32:20 +08002088static int test_akcipher_one(struct crypto_akcipher *tfm,
2089 struct akcipher_testvec *vecs)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002090{
Herbert Xudf27b262016-05-05 16:42:49 +08002091 char *xbuf[XBUFSIZE];
Tadeusz Struk946cc462015-06-16 10:31:06 -07002092 struct akcipher_request *req;
2093 void *outbuf_enc = NULL;
2094 void *outbuf_dec = NULL;
2095 struct tcrypt_result result;
2096 unsigned int out_len_max, out_len = 0;
2097 int err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002098 struct scatterlist src, dst, src_tab[2];
Tadeusz Struk946cc462015-06-16 10:31:06 -07002099
Herbert Xudf27b262016-05-05 16:42:49 +08002100 if (testmgr_alloc_buf(xbuf))
2101 return err;
2102
Tadeusz Struk946cc462015-06-16 10:31:06 -07002103 req = akcipher_request_alloc(tfm, GFP_KERNEL);
2104 if (!req)
Herbert Xudf27b262016-05-05 16:42:49 +08002105 goto free_xbuf;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002106
2107 init_completion(&result.completion);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002108
2109 if (vecs->public_key_vec)
2110 err = crypto_akcipher_set_pub_key(tfm, vecs->key,
2111 vecs->key_len);
2112 else
2113 err = crypto_akcipher_set_priv_key(tfm, vecs->key,
2114 vecs->key_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002115 if (err)
2116 goto free_req;
2117
Salvatore Benedetto57763f52016-07-04 10:52:34 +01002118 err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002119 out_len_max = crypto_akcipher_maxsize(tfm);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002120 outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
2121 if (!outbuf_enc)
2122 goto free_req;
2123
Herbert Xudf27b262016-05-05 16:42:49 +08002124 if (WARN_ON(vecs->m_size > PAGE_SIZE))
2125 goto free_all;
2126
2127 memcpy(xbuf[0], vecs->m, vecs->m_size);
2128
Tadeusz Struk22287b02015-10-08 09:26:55 -07002129 sg_init_table(src_tab, 2);
Herbert Xudf27b262016-05-05 16:42:49 +08002130 sg_set_buf(&src_tab[0], xbuf[0], 8);
2131 sg_set_buf(&src_tab[1], xbuf[0] + 8, vecs->m_size - 8);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002132 sg_init_one(&dst, outbuf_enc, out_len_max);
2133 akcipher_request_set_crypt(req, src_tab, &dst, vecs->m_size,
2134 out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002135 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
2136 tcrypt_complete, &result);
2137
2138 /* Run RSA encrypt - c = m^e mod n;*/
2139 err = wait_async_op(&result, crypto_akcipher_encrypt(req));
2140 if (err) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002141 pr_err("alg: akcipher: encrypt test failed. err %d\n", err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002142 goto free_all;
2143 }
Tadeusz Struk22287b02015-10-08 09:26:55 -07002144 if (req->dst_len != vecs->c_size) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002145 pr_err("alg: akcipher: encrypt test failed. Invalid output len\n");
Tadeusz Struk946cc462015-06-16 10:31:06 -07002146 err = -EINVAL;
2147 goto free_all;
2148 }
2149 /* verify that encrypted message is equal to expected */
Herbert Xudf27b262016-05-05 16:42:49 +08002150 if (memcmp(vecs->c, outbuf_enc, vecs->c_size)) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002151 pr_err("alg: akcipher: encrypt test failed. Invalid output\n");
2152 hexdump(outbuf_enc, vecs->c_size);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002153 err = -EINVAL;
2154 goto free_all;
2155 }
2156 /* Don't invoke decrypt for vectors with public key */
2157 if (vecs->public_key_vec) {
2158 err = 0;
2159 goto free_all;
2160 }
2161 outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
2162 if (!outbuf_dec) {
2163 err = -ENOMEM;
2164 goto free_all;
2165 }
Herbert Xudf27b262016-05-05 16:42:49 +08002166
2167 if (WARN_ON(vecs->c_size > PAGE_SIZE))
2168 goto free_all;
2169
2170 memcpy(xbuf[0], vecs->c, vecs->c_size);
2171
2172 sg_init_one(&src, xbuf[0], vecs->c_size);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002173 sg_init_one(&dst, outbuf_dec, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002174 init_completion(&result.completion);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002175 akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002176
2177 /* Run RSA decrypt - m = c^d mod n;*/
2178 err = wait_async_op(&result, crypto_akcipher_decrypt(req));
2179 if (err) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002180 pr_err("alg: akcipher: decrypt test failed. err %d\n", err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002181 goto free_all;
2182 }
2183 out_len = req->dst_len;
Herbert Xu50d2b6432016-06-29 19:32:20 +08002184 if (out_len < vecs->m_size) {
2185 pr_err("alg: akcipher: decrypt test failed. "
2186 "Invalid output len %u\n", out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002187 err = -EINVAL;
2188 goto free_all;
2189 }
2190 /* verify that decrypted message is equal to the original msg */
Herbert Xu50d2b6432016-06-29 19:32:20 +08002191 if (memchr_inv(outbuf_dec, 0, out_len - vecs->m_size) ||
2192 memcmp(vecs->m, outbuf_dec + out_len - vecs->m_size,
2193 vecs->m_size)) {
2194 pr_err("alg: akcipher: decrypt test failed. Invalid output\n");
2195 hexdump(outbuf_dec, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002196 err = -EINVAL;
2197 }
2198free_all:
2199 kfree(outbuf_dec);
2200 kfree(outbuf_enc);
2201free_req:
2202 akcipher_request_free(req);
Herbert Xudf27b262016-05-05 16:42:49 +08002203free_xbuf:
2204 testmgr_free_buf(xbuf);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002205 return err;
2206}
2207
Herbert Xu50d2b6432016-06-29 19:32:20 +08002208static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
2209 struct akcipher_testvec *vecs, unsigned int tcount)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002210{
Herbert Xu15226e42016-07-18 18:20:10 +08002211 const char *algo =
2212 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
Tadeusz Struk946cc462015-06-16 10:31:06 -07002213 int ret, i;
2214
2215 for (i = 0; i < tcount; i++) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002216 ret = test_akcipher_one(tfm, vecs++);
2217 if (!ret)
2218 continue;
2219
Herbert Xu15226e42016-07-18 18:20:10 +08002220 pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
2221 i + 1, algo, ret);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002222 return ret;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002223 }
2224 return 0;
2225}
2226
Tadeusz Struk946cc462015-06-16 10:31:06 -07002227static int alg_test_akcipher(const struct alg_test_desc *desc,
2228 const char *driver, u32 type, u32 mask)
2229{
2230 struct crypto_akcipher *tfm;
2231 int err = 0;
2232
Herbert Xueed93e02016-11-22 20:08:31 +08002233 tfm = crypto_alloc_akcipher(driver, type, mask);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002234 if (IS_ERR(tfm)) {
2235 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
2236 driver, PTR_ERR(tfm));
2237 return PTR_ERR(tfm);
2238 }
2239 if (desc->suite.akcipher.vecs)
2240 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
2241 desc->suite.akcipher.count);
2242
2243 crypto_free_akcipher(tfm);
2244 return err;
2245}
2246
Youquan, Song863b5572009-12-23 19:45:20 +08002247static int alg_test_null(const struct alg_test_desc *desc,
2248 const char *driver, u32 type, u32 mask)
2249{
2250 return 0;
2251}
2252
Herbert Xuda7f0332008-07-31 17:08:25 +08002253/* Please keep this list sorted by algorithm name. */
2254static const struct alg_test_desc alg_test_descs[] = {
2255 {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002256 .alg = "ansi_cprng",
2257 .test = alg_test_cprng,
2258 .suite = {
2259 .cprng = {
2260 .vecs = ansi_cprng_aes_tv_template,
2261 .count = ANSI_CPRNG_AES_TEST_VECTORS
2262 }
2263 }
2264 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002265 .alg = "authenc(hmac(md5),ecb(cipher_null))",
2266 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002267 .suite = {
2268 .aead = {
2269 .enc = {
2270 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
2271 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
2272 },
2273 .dec = {
2274 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
2275 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
2276 }
2277 }
2278 }
2279 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002280 .alg = "authenc(hmac(sha1),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002281 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002282 .suite = {
2283 .aead = {
2284 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302285 .vecs =
2286 hmac_sha1_aes_cbc_enc_tv_temp,
2287 .count =
2288 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
2289 }
2290 }
2291 }
2292 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002293 .alg = "authenc(hmac(sha1),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302294 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302295 .suite = {
2296 .aead = {
2297 .enc = {
2298 .vecs =
2299 hmac_sha1_des_cbc_enc_tv_temp,
2300 .count =
2301 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
2302 }
2303 }
2304 }
2305 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002306 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302307 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002308 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302309 .suite = {
2310 .aead = {
2311 .enc = {
2312 .vecs =
2313 hmac_sha1_des3_ede_cbc_enc_tv_temp,
2314 .count =
2315 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002316 }
2317 }
2318 }
2319 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002320 .alg = "authenc(hmac(sha1),ctr(aes))",
2321 .test = alg_test_null,
2322 .fips_allowed = 1,
2323 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002324 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
2325 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002326 .suite = {
2327 .aead = {
2328 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302329 .vecs =
2330 hmac_sha1_ecb_cipher_null_enc_tv_temp,
2331 .count =
2332 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002333 },
2334 .dec = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302335 .vecs =
2336 hmac_sha1_ecb_cipher_null_dec_tv_temp,
2337 .count =
2338 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
2339 }
2340 }
2341 }
2342 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002343 .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
2344 .test = alg_test_null,
2345 .fips_allowed = 1,
2346 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002347 .alg = "authenc(hmac(sha224),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302348 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302349 .suite = {
2350 .aead = {
2351 .enc = {
2352 .vecs =
2353 hmac_sha224_des_cbc_enc_tv_temp,
2354 .count =
2355 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2356 }
2357 }
2358 }
2359 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002360 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302361 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002362 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302363 .suite = {
2364 .aead = {
2365 .enc = {
2366 .vecs =
2367 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2368 .count =
2369 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002370 }
2371 }
2372 }
2373 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002374 .alg = "authenc(hmac(sha256),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002375 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002376 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002377 .suite = {
2378 .aead = {
2379 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302380 .vecs =
2381 hmac_sha256_aes_cbc_enc_tv_temp,
2382 .count =
2383 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2384 }
2385 }
2386 }
2387 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002388 .alg = "authenc(hmac(sha256),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302389 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302390 .suite = {
2391 .aead = {
2392 .enc = {
2393 .vecs =
2394 hmac_sha256_des_cbc_enc_tv_temp,
2395 .count =
2396 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2397 }
2398 }
2399 }
2400 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002401 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302402 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002403 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302404 .suite = {
2405 .aead = {
2406 .enc = {
2407 .vecs =
2408 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2409 .count =
2410 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2411 }
2412 }
2413 }
2414 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002415 .alg = "authenc(hmac(sha256),ctr(aes))",
2416 .test = alg_test_null,
2417 .fips_allowed = 1,
2418 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002419 .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
2420 .test = alg_test_null,
2421 .fips_allowed = 1,
2422 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002423 .alg = "authenc(hmac(sha384),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302424 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302425 .suite = {
2426 .aead = {
2427 .enc = {
2428 .vecs =
2429 hmac_sha384_des_cbc_enc_tv_temp,
2430 .count =
2431 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2432 }
2433 }
2434 }
2435 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002436 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302437 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002438 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302439 .suite = {
2440 .aead = {
2441 .enc = {
2442 .vecs =
2443 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2444 .count =
2445 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002446 }
2447 }
2448 }
2449 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002450 .alg = "authenc(hmac(sha384),ctr(aes))",
2451 .test = alg_test_null,
2452 .fips_allowed = 1,
2453 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002454 .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
2455 .test = alg_test_null,
2456 .fips_allowed = 1,
2457 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002458 .alg = "authenc(hmac(sha512),cbc(aes))",
Marcus Meissnered1afac2016-02-05 14:23:33 +01002459 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002460 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002461 .suite = {
2462 .aead = {
2463 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302464 .vecs =
2465 hmac_sha512_aes_cbc_enc_tv_temp,
2466 .count =
2467 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2468 }
2469 }
2470 }
2471 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002472 .alg = "authenc(hmac(sha512),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302473 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302474 .suite = {
2475 .aead = {
2476 .enc = {
2477 .vecs =
2478 hmac_sha512_des_cbc_enc_tv_temp,
2479 .count =
2480 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2481 }
2482 }
2483 }
2484 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002485 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302486 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002487 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302488 .suite = {
2489 .aead = {
2490 .enc = {
2491 .vecs =
2492 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2493 .count =
2494 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002495 }
2496 }
2497 }
2498 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002499 .alg = "authenc(hmac(sha512),ctr(aes))",
2500 .test = alg_test_null,
2501 .fips_allowed = 1,
2502 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002503 .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
2504 .test = alg_test_null,
2505 .fips_allowed = 1,
2506 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002507 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002508 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002509 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002510 .suite = {
2511 .cipher = {
2512 .enc = {
2513 .vecs = aes_cbc_enc_tv_template,
2514 .count = AES_CBC_ENC_TEST_VECTORS
2515 },
2516 .dec = {
2517 .vecs = aes_cbc_dec_tv_template,
2518 .count = AES_CBC_DEC_TEST_VECTORS
2519 }
2520 }
2521 }
2522 }, {
2523 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002524 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002525 .suite = {
2526 .cipher = {
2527 .enc = {
2528 .vecs = anubis_cbc_enc_tv_template,
2529 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2530 },
2531 .dec = {
2532 .vecs = anubis_cbc_dec_tv_template,
2533 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2534 }
2535 }
2536 }
2537 }, {
2538 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002539 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002540 .suite = {
2541 .cipher = {
2542 .enc = {
2543 .vecs = bf_cbc_enc_tv_template,
2544 .count = BF_CBC_ENC_TEST_VECTORS
2545 },
2546 .dec = {
2547 .vecs = bf_cbc_dec_tv_template,
2548 .count = BF_CBC_DEC_TEST_VECTORS
2549 }
2550 }
2551 }
2552 }, {
2553 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002554 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002555 .suite = {
2556 .cipher = {
2557 .enc = {
2558 .vecs = camellia_cbc_enc_tv_template,
2559 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2560 },
2561 .dec = {
2562 .vecs = camellia_cbc_dec_tv_template,
2563 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2564 }
2565 }
2566 }
2567 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002568 .alg = "cbc(cast5)",
2569 .test = alg_test_skcipher,
2570 .suite = {
2571 .cipher = {
2572 .enc = {
2573 .vecs = cast5_cbc_enc_tv_template,
2574 .count = CAST5_CBC_ENC_TEST_VECTORS
2575 },
2576 .dec = {
2577 .vecs = cast5_cbc_dec_tv_template,
2578 .count = CAST5_CBC_DEC_TEST_VECTORS
2579 }
2580 }
2581 }
2582 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002583 .alg = "cbc(cast6)",
2584 .test = alg_test_skcipher,
2585 .suite = {
2586 .cipher = {
2587 .enc = {
2588 .vecs = cast6_cbc_enc_tv_template,
2589 .count = CAST6_CBC_ENC_TEST_VECTORS
2590 },
2591 .dec = {
2592 .vecs = cast6_cbc_dec_tv_template,
2593 .count = CAST6_CBC_DEC_TEST_VECTORS
2594 }
2595 }
2596 }
2597 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002598 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002599 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002600 .suite = {
2601 .cipher = {
2602 .enc = {
2603 .vecs = des_cbc_enc_tv_template,
2604 .count = DES_CBC_ENC_TEST_VECTORS
2605 },
2606 .dec = {
2607 .vecs = des_cbc_dec_tv_template,
2608 .count = DES_CBC_DEC_TEST_VECTORS
2609 }
2610 }
2611 }
2612 }, {
2613 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002614 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002615 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002616 .suite = {
2617 .cipher = {
2618 .enc = {
2619 .vecs = des3_ede_cbc_enc_tv_template,
2620 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2621 },
2622 .dec = {
2623 .vecs = des3_ede_cbc_dec_tv_template,
2624 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2625 }
2626 }
2627 }
2628 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002629 .alg = "cbc(serpent)",
2630 .test = alg_test_skcipher,
2631 .suite = {
2632 .cipher = {
2633 .enc = {
2634 .vecs = serpent_cbc_enc_tv_template,
2635 .count = SERPENT_CBC_ENC_TEST_VECTORS
2636 },
2637 .dec = {
2638 .vecs = serpent_cbc_dec_tv_template,
2639 .count = SERPENT_CBC_DEC_TEST_VECTORS
2640 }
2641 }
2642 }
2643 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002644 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002645 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002646 .suite = {
2647 .cipher = {
2648 .enc = {
2649 .vecs = tf_cbc_enc_tv_template,
2650 .count = TF_CBC_ENC_TEST_VECTORS
2651 },
2652 .dec = {
2653 .vecs = tf_cbc_dec_tv_template,
2654 .count = TF_CBC_DEC_TEST_VECTORS
2655 }
2656 }
2657 }
2658 }, {
2659 .alg = "ccm(aes)",
2660 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002661 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002662 .suite = {
2663 .aead = {
2664 .enc = {
2665 .vecs = aes_ccm_enc_tv_template,
2666 .count = AES_CCM_ENC_TEST_VECTORS
2667 },
2668 .dec = {
2669 .vecs = aes_ccm_dec_tv_template,
2670 .count = AES_CCM_DEC_TEST_VECTORS
2671 }
2672 }
2673 }
2674 }, {
Martin Willi3590ebf2015-06-01 13:43:57 +02002675 .alg = "chacha20",
2676 .test = alg_test_skcipher,
2677 .suite = {
2678 .cipher = {
2679 .enc = {
2680 .vecs = chacha20_enc_tv_template,
2681 .count = CHACHA20_ENC_TEST_VECTORS
2682 },
2683 .dec = {
2684 .vecs = chacha20_enc_tv_template,
2685 .count = CHACHA20_ENC_TEST_VECTORS
2686 },
2687 }
2688 }
2689 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002690 .alg = "cmac(aes)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002691 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002692 .test = alg_test_hash,
2693 .suite = {
2694 .hash = {
2695 .vecs = aes_cmac128_tv_template,
2696 .count = CMAC_AES_TEST_VECTORS
2697 }
2698 }
2699 }, {
2700 .alg = "cmac(des3_ede)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002701 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002702 .test = alg_test_hash,
2703 .suite = {
2704 .hash = {
2705 .vecs = des3_ede_cmac64_tv_template,
2706 .count = CMAC_DES3_EDE_TEST_VECTORS
2707 }
2708 }
2709 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002710 .alg = "compress_null",
2711 .test = alg_test_null,
2712 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02002713 .alg = "crc32",
2714 .test = alg_test_hash,
2715 .suite = {
2716 .hash = {
2717 .vecs = crc32_tv_template,
2718 .count = CRC32_TEST_VECTORS
2719 }
2720 }
2721 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002722 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002723 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002724 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002725 .suite = {
2726 .hash = {
2727 .vecs = crc32c_tv_template,
2728 .count = CRC32C_TEST_VECTORS
2729 }
2730 }
2731 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002732 .alg = "crct10dif",
2733 .test = alg_test_hash,
2734 .fips_allowed = 1,
2735 .suite = {
2736 .hash = {
2737 .vecs = crct10dif_tv_template,
2738 .count = CRCT10DIF_TEST_VECTORS
2739 }
2740 }
2741 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002742 .alg = "ctr(aes)",
2743 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002744 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002745 .suite = {
2746 .cipher = {
2747 .enc = {
2748 .vecs = aes_ctr_enc_tv_template,
2749 .count = AES_CTR_ENC_TEST_VECTORS
2750 },
2751 .dec = {
2752 .vecs = aes_ctr_dec_tv_template,
2753 .count = AES_CTR_DEC_TEST_VECTORS
2754 }
2755 }
2756 }
2757 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002758 .alg = "ctr(blowfish)",
2759 .test = alg_test_skcipher,
2760 .suite = {
2761 .cipher = {
2762 .enc = {
2763 .vecs = bf_ctr_enc_tv_template,
2764 .count = BF_CTR_ENC_TEST_VECTORS
2765 },
2766 .dec = {
2767 .vecs = bf_ctr_dec_tv_template,
2768 .count = BF_CTR_DEC_TEST_VECTORS
2769 }
2770 }
2771 }
2772 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002773 .alg = "ctr(camellia)",
2774 .test = alg_test_skcipher,
2775 .suite = {
2776 .cipher = {
2777 .enc = {
2778 .vecs = camellia_ctr_enc_tv_template,
2779 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2780 },
2781 .dec = {
2782 .vecs = camellia_ctr_dec_tv_template,
2783 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2784 }
2785 }
2786 }
2787 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002788 .alg = "ctr(cast5)",
2789 .test = alg_test_skcipher,
2790 .suite = {
2791 .cipher = {
2792 .enc = {
2793 .vecs = cast5_ctr_enc_tv_template,
2794 .count = CAST5_CTR_ENC_TEST_VECTORS
2795 },
2796 .dec = {
2797 .vecs = cast5_ctr_dec_tv_template,
2798 .count = CAST5_CTR_DEC_TEST_VECTORS
2799 }
2800 }
2801 }
2802 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002803 .alg = "ctr(cast6)",
2804 .test = alg_test_skcipher,
2805 .suite = {
2806 .cipher = {
2807 .enc = {
2808 .vecs = cast6_ctr_enc_tv_template,
2809 .count = CAST6_CTR_ENC_TEST_VECTORS
2810 },
2811 .dec = {
2812 .vecs = cast6_ctr_dec_tv_template,
2813 .count = CAST6_CTR_DEC_TEST_VECTORS
2814 }
2815 }
2816 }
2817 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002818 .alg = "ctr(des)",
2819 .test = alg_test_skcipher,
2820 .suite = {
2821 .cipher = {
2822 .enc = {
2823 .vecs = des_ctr_enc_tv_template,
2824 .count = DES_CTR_ENC_TEST_VECTORS
2825 },
2826 .dec = {
2827 .vecs = des_ctr_dec_tv_template,
2828 .count = DES_CTR_DEC_TEST_VECTORS
2829 }
2830 }
2831 }
2832 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002833 .alg = "ctr(des3_ede)",
2834 .test = alg_test_skcipher,
2835 .suite = {
2836 .cipher = {
2837 .enc = {
2838 .vecs = des3_ede_ctr_enc_tv_template,
2839 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2840 },
2841 .dec = {
2842 .vecs = des3_ede_ctr_dec_tv_template,
2843 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2844 }
2845 }
2846 }
2847 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002848 .alg = "ctr(serpent)",
2849 .test = alg_test_skcipher,
2850 .suite = {
2851 .cipher = {
2852 .enc = {
2853 .vecs = serpent_ctr_enc_tv_template,
2854 .count = SERPENT_CTR_ENC_TEST_VECTORS
2855 },
2856 .dec = {
2857 .vecs = serpent_ctr_dec_tv_template,
2858 .count = SERPENT_CTR_DEC_TEST_VECTORS
2859 }
2860 }
2861 }
2862 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002863 .alg = "ctr(twofish)",
2864 .test = alg_test_skcipher,
2865 .suite = {
2866 .cipher = {
2867 .enc = {
2868 .vecs = tf_ctr_enc_tv_template,
2869 .count = TF_CTR_ENC_TEST_VECTORS
2870 },
2871 .dec = {
2872 .vecs = tf_ctr_dec_tv_template,
2873 .count = TF_CTR_DEC_TEST_VECTORS
2874 }
2875 }
2876 }
2877 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002878 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002879 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002880 .suite = {
2881 .cipher = {
2882 .enc = {
2883 .vecs = cts_mode_enc_tv_template,
2884 .count = CTS_MODE_ENC_TEST_VECTORS
2885 },
2886 .dec = {
2887 .vecs = cts_mode_dec_tv_template,
2888 .count = CTS_MODE_DEC_TEST_VECTORS
2889 }
2890 }
2891 }
2892 }, {
2893 .alg = "deflate",
2894 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002895 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002896 .suite = {
2897 .comp = {
2898 .comp = {
2899 .vecs = deflate_comp_tv_template,
2900 .count = DEFLATE_COMP_TEST_VECTORS
2901 },
2902 .decomp = {
2903 .vecs = deflate_decomp_tv_template,
2904 .count = DEFLATE_DECOMP_TEST_VECTORS
2905 }
2906 }
2907 }
2908 }, {
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002909 .alg = "dh",
2910 .test = alg_test_kpp,
2911 .fips_allowed = 1,
2912 .suite = {
2913 .kpp = {
2914 .vecs = dh_tv_template,
2915 .count = DH_TEST_VECTORS
2916 }
2917 }
2918 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002919 .alg = "digest_null",
2920 .test = alg_test_null,
2921 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002922 .alg = "drbg_nopr_ctr_aes128",
2923 .test = alg_test_drbg,
2924 .fips_allowed = 1,
2925 .suite = {
2926 .drbg = {
2927 .vecs = drbg_nopr_ctr_aes128_tv_template,
2928 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2929 }
2930 }
2931 }, {
2932 .alg = "drbg_nopr_ctr_aes192",
2933 .test = alg_test_drbg,
2934 .fips_allowed = 1,
2935 .suite = {
2936 .drbg = {
2937 .vecs = drbg_nopr_ctr_aes192_tv_template,
2938 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2939 }
2940 }
2941 }, {
2942 .alg = "drbg_nopr_ctr_aes256",
2943 .test = alg_test_drbg,
2944 .fips_allowed = 1,
2945 .suite = {
2946 .drbg = {
2947 .vecs = drbg_nopr_ctr_aes256_tv_template,
2948 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2949 }
2950 }
2951 }, {
2952 /*
2953 * There is no need to specifically test the DRBG with every
2954 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2955 */
2956 .alg = "drbg_nopr_hmac_sha1",
2957 .fips_allowed = 1,
2958 .test = alg_test_null,
2959 }, {
2960 .alg = "drbg_nopr_hmac_sha256",
2961 .test = alg_test_drbg,
2962 .fips_allowed = 1,
2963 .suite = {
2964 .drbg = {
2965 .vecs = drbg_nopr_hmac_sha256_tv_template,
2966 .count =
2967 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2968 }
2969 }
2970 }, {
2971 /* covered by drbg_nopr_hmac_sha256 test */
2972 .alg = "drbg_nopr_hmac_sha384",
2973 .fips_allowed = 1,
2974 .test = alg_test_null,
2975 }, {
2976 .alg = "drbg_nopr_hmac_sha512",
2977 .test = alg_test_null,
2978 .fips_allowed = 1,
2979 }, {
2980 .alg = "drbg_nopr_sha1",
2981 .fips_allowed = 1,
2982 .test = alg_test_null,
2983 }, {
2984 .alg = "drbg_nopr_sha256",
2985 .test = alg_test_drbg,
2986 .fips_allowed = 1,
2987 .suite = {
2988 .drbg = {
2989 .vecs = drbg_nopr_sha256_tv_template,
2990 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2991 }
2992 }
2993 }, {
2994 /* covered by drbg_nopr_sha256 test */
2995 .alg = "drbg_nopr_sha384",
2996 .fips_allowed = 1,
2997 .test = alg_test_null,
2998 }, {
2999 .alg = "drbg_nopr_sha512",
3000 .fips_allowed = 1,
3001 .test = alg_test_null,
3002 }, {
3003 .alg = "drbg_pr_ctr_aes128",
3004 .test = alg_test_drbg,
3005 .fips_allowed = 1,
3006 .suite = {
3007 .drbg = {
3008 .vecs = drbg_pr_ctr_aes128_tv_template,
3009 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
3010 }
3011 }
3012 }, {
3013 /* covered by drbg_pr_ctr_aes128 test */
3014 .alg = "drbg_pr_ctr_aes192",
3015 .fips_allowed = 1,
3016 .test = alg_test_null,
3017 }, {
3018 .alg = "drbg_pr_ctr_aes256",
3019 .fips_allowed = 1,
3020 .test = alg_test_null,
3021 }, {
3022 .alg = "drbg_pr_hmac_sha1",
3023 .fips_allowed = 1,
3024 .test = alg_test_null,
3025 }, {
3026 .alg = "drbg_pr_hmac_sha256",
3027 .test = alg_test_drbg,
3028 .fips_allowed = 1,
3029 .suite = {
3030 .drbg = {
3031 .vecs = drbg_pr_hmac_sha256_tv_template,
3032 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
3033 }
3034 }
3035 }, {
3036 /* covered by drbg_pr_hmac_sha256 test */
3037 .alg = "drbg_pr_hmac_sha384",
3038 .fips_allowed = 1,
3039 .test = alg_test_null,
3040 }, {
3041 .alg = "drbg_pr_hmac_sha512",
3042 .test = alg_test_null,
3043 .fips_allowed = 1,
3044 }, {
3045 .alg = "drbg_pr_sha1",
3046 .fips_allowed = 1,
3047 .test = alg_test_null,
3048 }, {
3049 .alg = "drbg_pr_sha256",
3050 .test = alg_test_drbg,
3051 .fips_allowed = 1,
3052 .suite = {
3053 .drbg = {
3054 .vecs = drbg_pr_sha256_tv_template,
3055 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
3056 }
3057 }
3058 }, {
3059 /* covered by drbg_pr_sha256 test */
3060 .alg = "drbg_pr_sha384",
3061 .fips_allowed = 1,
3062 .test = alg_test_null,
3063 }, {
3064 .alg = "drbg_pr_sha512",
3065 .fips_allowed = 1,
3066 .test = alg_test_null,
3067 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003068 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003069 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003070 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003071 .suite = {
3072 .cipher = {
3073 .enc = {
3074 .vecs = aes_enc_tv_template,
3075 .count = AES_ENC_TEST_VECTORS
3076 },
3077 .dec = {
3078 .vecs = aes_dec_tv_template,
3079 .count = AES_DEC_TEST_VECTORS
3080 }
3081 }
3082 }
3083 }, {
3084 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003085 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003086 .suite = {
3087 .cipher = {
3088 .enc = {
3089 .vecs = anubis_enc_tv_template,
3090 .count = ANUBIS_ENC_TEST_VECTORS
3091 },
3092 .dec = {
3093 .vecs = anubis_dec_tv_template,
3094 .count = ANUBIS_DEC_TEST_VECTORS
3095 }
3096 }
3097 }
3098 }, {
3099 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003100 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003101 .suite = {
3102 .cipher = {
3103 .enc = {
3104 .vecs = arc4_enc_tv_template,
3105 .count = ARC4_ENC_TEST_VECTORS
3106 },
3107 .dec = {
3108 .vecs = arc4_dec_tv_template,
3109 .count = ARC4_DEC_TEST_VECTORS
3110 }
3111 }
3112 }
3113 }, {
3114 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003115 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003116 .suite = {
3117 .cipher = {
3118 .enc = {
3119 .vecs = bf_enc_tv_template,
3120 .count = BF_ENC_TEST_VECTORS
3121 },
3122 .dec = {
3123 .vecs = bf_dec_tv_template,
3124 .count = BF_DEC_TEST_VECTORS
3125 }
3126 }
3127 }
3128 }, {
3129 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003130 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003131 .suite = {
3132 .cipher = {
3133 .enc = {
3134 .vecs = camellia_enc_tv_template,
3135 .count = CAMELLIA_ENC_TEST_VECTORS
3136 },
3137 .dec = {
3138 .vecs = camellia_dec_tv_template,
3139 .count = CAMELLIA_DEC_TEST_VECTORS
3140 }
3141 }
3142 }
3143 }, {
3144 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003145 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003146 .suite = {
3147 .cipher = {
3148 .enc = {
3149 .vecs = cast5_enc_tv_template,
3150 .count = CAST5_ENC_TEST_VECTORS
3151 },
3152 .dec = {
3153 .vecs = cast5_dec_tv_template,
3154 .count = CAST5_DEC_TEST_VECTORS
3155 }
3156 }
3157 }
3158 }, {
3159 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003160 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003161 .suite = {
3162 .cipher = {
3163 .enc = {
3164 .vecs = cast6_enc_tv_template,
3165 .count = CAST6_ENC_TEST_VECTORS
3166 },
3167 .dec = {
3168 .vecs = cast6_dec_tv_template,
3169 .count = CAST6_DEC_TEST_VECTORS
3170 }
3171 }
3172 }
3173 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003174 .alg = "ecb(cipher_null)",
3175 .test = alg_test_null,
3176 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003177 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003178 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003179 .suite = {
3180 .cipher = {
3181 .enc = {
3182 .vecs = des_enc_tv_template,
3183 .count = DES_ENC_TEST_VECTORS
3184 },
3185 .dec = {
3186 .vecs = des_dec_tv_template,
3187 .count = DES_DEC_TEST_VECTORS
3188 }
3189 }
3190 }
3191 }, {
3192 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003193 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003194 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003195 .suite = {
3196 .cipher = {
3197 .enc = {
3198 .vecs = des3_ede_enc_tv_template,
3199 .count = DES3_EDE_ENC_TEST_VECTORS
3200 },
3201 .dec = {
3202 .vecs = des3_ede_dec_tv_template,
3203 .count = DES3_EDE_DEC_TEST_VECTORS
3204 }
3205 }
3206 }
3207 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003208 .alg = "ecb(fcrypt)",
3209 .test = alg_test_skcipher,
3210 .suite = {
3211 .cipher = {
3212 .enc = {
3213 .vecs = fcrypt_pcbc_enc_tv_template,
3214 .count = 1
3215 },
3216 .dec = {
3217 .vecs = fcrypt_pcbc_dec_tv_template,
3218 .count = 1
3219 }
3220 }
3221 }
3222 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003223 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003224 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003225 .suite = {
3226 .cipher = {
3227 .enc = {
3228 .vecs = khazad_enc_tv_template,
3229 .count = KHAZAD_ENC_TEST_VECTORS
3230 },
3231 .dec = {
3232 .vecs = khazad_dec_tv_template,
3233 .count = KHAZAD_DEC_TEST_VECTORS
3234 }
3235 }
3236 }
3237 }, {
3238 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003239 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003240 .suite = {
3241 .cipher = {
3242 .enc = {
3243 .vecs = seed_enc_tv_template,
3244 .count = SEED_ENC_TEST_VECTORS
3245 },
3246 .dec = {
3247 .vecs = seed_dec_tv_template,
3248 .count = SEED_DEC_TEST_VECTORS
3249 }
3250 }
3251 }
3252 }, {
3253 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003254 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003255 .suite = {
3256 .cipher = {
3257 .enc = {
3258 .vecs = serpent_enc_tv_template,
3259 .count = SERPENT_ENC_TEST_VECTORS
3260 },
3261 .dec = {
3262 .vecs = serpent_dec_tv_template,
3263 .count = SERPENT_DEC_TEST_VECTORS
3264 }
3265 }
3266 }
3267 }, {
3268 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003269 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003270 .suite = {
3271 .cipher = {
3272 .enc = {
3273 .vecs = tea_enc_tv_template,
3274 .count = TEA_ENC_TEST_VECTORS
3275 },
3276 .dec = {
3277 .vecs = tea_dec_tv_template,
3278 .count = TEA_DEC_TEST_VECTORS
3279 }
3280 }
3281 }
3282 }, {
3283 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003284 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003285 .suite = {
3286 .cipher = {
3287 .enc = {
3288 .vecs = tnepres_enc_tv_template,
3289 .count = TNEPRES_ENC_TEST_VECTORS
3290 },
3291 .dec = {
3292 .vecs = tnepres_dec_tv_template,
3293 .count = TNEPRES_DEC_TEST_VECTORS
3294 }
3295 }
3296 }
3297 }, {
3298 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003299 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003300 .suite = {
3301 .cipher = {
3302 .enc = {
3303 .vecs = tf_enc_tv_template,
3304 .count = TF_ENC_TEST_VECTORS
3305 },
3306 .dec = {
3307 .vecs = tf_dec_tv_template,
3308 .count = TF_DEC_TEST_VECTORS
3309 }
3310 }
3311 }
3312 }, {
3313 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003314 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003315 .suite = {
3316 .cipher = {
3317 .enc = {
3318 .vecs = xeta_enc_tv_template,
3319 .count = XETA_ENC_TEST_VECTORS
3320 },
3321 .dec = {
3322 .vecs = xeta_dec_tv_template,
3323 .count = XETA_DEC_TEST_VECTORS
3324 }
3325 }
3326 }
3327 }, {
3328 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003329 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003330 .suite = {
3331 .cipher = {
3332 .enc = {
3333 .vecs = xtea_enc_tv_template,
3334 .count = XTEA_ENC_TEST_VECTORS
3335 },
3336 .dec = {
3337 .vecs = xtea_dec_tv_template,
3338 .count = XTEA_DEC_TEST_VECTORS
3339 }
3340 }
3341 }
3342 }, {
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003343 .alg = "ecdh",
3344 .test = alg_test_kpp,
3345 .fips_allowed = 1,
3346 .suite = {
3347 .kpp = {
3348 .vecs = ecdh_tv_template,
3349 .count = ECDH_TEST_VECTORS
3350 }
3351 }
3352 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003353 .alg = "gcm(aes)",
3354 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003355 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003356 .suite = {
3357 .aead = {
3358 .enc = {
3359 .vecs = aes_gcm_enc_tv_template,
3360 .count = AES_GCM_ENC_TEST_VECTORS
3361 },
3362 .dec = {
3363 .vecs = aes_gcm_dec_tv_template,
3364 .count = AES_GCM_DEC_TEST_VECTORS
3365 }
3366 }
3367 }
3368 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003369 .alg = "ghash",
3370 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003371 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003372 .suite = {
3373 .hash = {
3374 .vecs = ghash_tv_template,
3375 .count = GHASH_TEST_VECTORS
3376 }
3377 }
3378 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003379 .alg = "hmac(crc32)",
3380 .test = alg_test_hash,
3381 .suite = {
3382 .hash = {
3383 .vecs = bfin_crc_tv_template,
3384 .count = BFIN_CRC_TEST_VECTORS
3385 }
3386 }
3387 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003388 .alg = "hmac(md5)",
3389 .test = alg_test_hash,
3390 .suite = {
3391 .hash = {
3392 .vecs = hmac_md5_tv_template,
3393 .count = HMAC_MD5_TEST_VECTORS
3394 }
3395 }
3396 }, {
3397 .alg = "hmac(rmd128)",
3398 .test = alg_test_hash,
3399 .suite = {
3400 .hash = {
3401 .vecs = hmac_rmd128_tv_template,
3402 .count = HMAC_RMD128_TEST_VECTORS
3403 }
3404 }
3405 }, {
3406 .alg = "hmac(rmd160)",
3407 .test = alg_test_hash,
3408 .suite = {
3409 .hash = {
3410 .vecs = hmac_rmd160_tv_template,
3411 .count = HMAC_RMD160_TEST_VECTORS
3412 }
3413 }
3414 }, {
3415 .alg = "hmac(sha1)",
3416 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003417 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003418 .suite = {
3419 .hash = {
3420 .vecs = hmac_sha1_tv_template,
3421 .count = HMAC_SHA1_TEST_VECTORS
3422 }
3423 }
3424 }, {
3425 .alg = "hmac(sha224)",
3426 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003427 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003428 .suite = {
3429 .hash = {
3430 .vecs = hmac_sha224_tv_template,
3431 .count = HMAC_SHA224_TEST_VECTORS
3432 }
3433 }
3434 }, {
3435 .alg = "hmac(sha256)",
3436 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003437 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003438 .suite = {
3439 .hash = {
3440 .vecs = hmac_sha256_tv_template,
3441 .count = HMAC_SHA256_TEST_VECTORS
3442 }
3443 }
3444 }, {
raveendra padasalagi98eca722016-07-01 11:16:54 +05303445 .alg = "hmac(sha3-224)",
3446 .test = alg_test_hash,
3447 .fips_allowed = 1,
3448 .suite = {
3449 .hash = {
3450 .vecs = hmac_sha3_224_tv_template,
3451 .count = HMAC_SHA3_224_TEST_VECTORS
3452 }
3453 }
3454 }, {
3455 .alg = "hmac(sha3-256)",
3456 .test = alg_test_hash,
3457 .fips_allowed = 1,
3458 .suite = {
3459 .hash = {
3460 .vecs = hmac_sha3_256_tv_template,
3461 .count = HMAC_SHA3_256_TEST_VECTORS
3462 }
3463 }
3464 }, {
3465 .alg = "hmac(sha3-384)",
3466 .test = alg_test_hash,
3467 .fips_allowed = 1,
3468 .suite = {
3469 .hash = {
3470 .vecs = hmac_sha3_384_tv_template,
3471 .count = HMAC_SHA3_384_TEST_VECTORS
3472 }
3473 }
3474 }, {
3475 .alg = "hmac(sha3-512)",
3476 .test = alg_test_hash,
3477 .fips_allowed = 1,
3478 .suite = {
3479 .hash = {
3480 .vecs = hmac_sha3_512_tv_template,
3481 .count = HMAC_SHA3_512_TEST_VECTORS
3482 }
3483 }
3484 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003485 .alg = "hmac(sha384)",
3486 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003487 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003488 .suite = {
3489 .hash = {
3490 .vecs = hmac_sha384_tv_template,
3491 .count = HMAC_SHA384_TEST_VECTORS
3492 }
3493 }
3494 }, {
3495 .alg = "hmac(sha512)",
3496 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003497 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003498 .suite = {
3499 .hash = {
3500 .vecs = hmac_sha512_tv_template,
3501 .count = HMAC_SHA512_TEST_VECTORS
3502 }
3503 }
3504 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003505 .alg = "jitterentropy_rng",
3506 .fips_allowed = 1,
3507 .test = alg_test_null,
3508 }, {
Stephan Mueller35351982015-09-21 20:59:56 +02003509 .alg = "kw(aes)",
3510 .test = alg_test_skcipher,
3511 .fips_allowed = 1,
3512 .suite = {
3513 .cipher = {
3514 .enc = {
3515 .vecs = aes_kw_enc_tv_template,
3516 .count = ARRAY_SIZE(aes_kw_enc_tv_template)
3517 },
3518 .dec = {
3519 .vecs = aes_kw_dec_tv_template,
3520 .count = ARRAY_SIZE(aes_kw_dec_tv_template)
3521 }
3522 }
3523 }
3524 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003525 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003526 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003527 .suite = {
3528 .cipher = {
3529 .enc = {
3530 .vecs = aes_lrw_enc_tv_template,
3531 .count = AES_LRW_ENC_TEST_VECTORS
3532 },
3533 .dec = {
3534 .vecs = aes_lrw_dec_tv_template,
3535 .count = AES_LRW_DEC_TEST_VECTORS
3536 }
3537 }
3538 }
3539 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003540 .alg = "lrw(camellia)",
3541 .test = alg_test_skcipher,
3542 .suite = {
3543 .cipher = {
3544 .enc = {
3545 .vecs = camellia_lrw_enc_tv_template,
3546 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3547 },
3548 .dec = {
3549 .vecs = camellia_lrw_dec_tv_template,
3550 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3551 }
3552 }
3553 }
3554 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003555 .alg = "lrw(cast6)",
3556 .test = alg_test_skcipher,
3557 .suite = {
3558 .cipher = {
3559 .enc = {
3560 .vecs = cast6_lrw_enc_tv_template,
3561 .count = CAST6_LRW_ENC_TEST_VECTORS
3562 },
3563 .dec = {
3564 .vecs = cast6_lrw_dec_tv_template,
3565 .count = CAST6_LRW_DEC_TEST_VECTORS
3566 }
3567 }
3568 }
3569 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003570 .alg = "lrw(serpent)",
3571 .test = alg_test_skcipher,
3572 .suite = {
3573 .cipher = {
3574 .enc = {
3575 .vecs = serpent_lrw_enc_tv_template,
3576 .count = SERPENT_LRW_ENC_TEST_VECTORS
3577 },
3578 .dec = {
3579 .vecs = serpent_lrw_dec_tv_template,
3580 .count = SERPENT_LRW_DEC_TEST_VECTORS
3581 }
3582 }
3583 }
3584 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003585 .alg = "lrw(twofish)",
3586 .test = alg_test_skcipher,
3587 .suite = {
3588 .cipher = {
3589 .enc = {
3590 .vecs = tf_lrw_enc_tv_template,
3591 .count = TF_LRW_ENC_TEST_VECTORS
3592 },
3593 .dec = {
3594 .vecs = tf_lrw_dec_tv_template,
3595 .count = TF_LRW_DEC_TEST_VECTORS
3596 }
3597 }
3598 }
3599 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003600 .alg = "lz4",
3601 .test = alg_test_comp,
3602 .fips_allowed = 1,
3603 .suite = {
3604 .comp = {
3605 .comp = {
3606 .vecs = lz4_comp_tv_template,
3607 .count = LZ4_COMP_TEST_VECTORS
3608 },
3609 .decomp = {
3610 .vecs = lz4_decomp_tv_template,
3611 .count = LZ4_DECOMP_TEST_VECTORS
3612 }
3613 }
3614 }
3615 }, {
3616 .alg = "lz4hc",
3617 .test = alg_test_comp,
3618 .fips_allowed = 1,
3619 .suite = {
3620 .comp = {
3621 .comp = {
3622 .vecs = lz4hc_comp_tv_template,
3623 .count = LZ4HC_COMP_TEST_VECTORS
3624 },
3625 .decomp = {
3626 .vecs = lz4hc_decomp_tv_template,
3627 .count = LZ4HC_DECOMP_TEST_VECTORS
3628 }
3629 }
3630 }
3631 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003632 .alg = "lzo",
3633 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003634 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003635 .suite = {
3636 .comp = {
3637 .comp = {
3638 .vecs = lzo_comp_tv_template,
3639 .count = LZO_COMP_TEST_VECTORS
3640 },
3641 .decomp = {
3642 .vecs = lzo_decomp_tv_template,
3643 .count = LZO_DECOMP_TEST_VECTORS
3644 }
3645 }
3646 }
3647 }, {
3648 .alg = "md4",
3649 .test = alg_test_hash,
3650 .suite = {
3651 .hash = {
3652 .vecs = md4_tv_template,
3653 .count = MD4_TEST_VECTORS
3654 }
3655 }
3656 }, {
3657 .alg = "md5",
3658 .test = alg_test_hash,
3659 .suite = {
3660 .hash = {
3661 .vecs = md5_tv_template,
3662 .count = MD5_TEST_VECTORS
3663 }
3664 }
3665 }, {
3666 .alg = "michael_mic",
3667 .test = alg_test_hash,
3668 .suite = {
3669 .hash = {
3670 .vecs = michael_mic_tv_template,
3671 .count = MICHAEL_MIC_TEST_VECTORS
3672 }
3673 }
3674 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003675 .alg = "ofb(aes)",
3676 .test = alg_test_skcipher,
3677 .fips_allowed = 1,
3678 .suite = {
3679 .cipher = {
3680 .enc = {
3681 .vecs = aes_ofb_enc_tv_template,
3682 .count = AES_OFB_ENC_TEST_VECTORS
3683 },
3684 .dec = {
3685 .vecs = aes_ofb_dec_tv_template,
3686 .count = AES_OFB_DEC_TEST_VECTORS
3687 }
3688 }
3689 }
3690 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003691 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003692 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003693 .suite = {
3694 .cipher = {
3695 .enc = {
3696 .vecs = fcrypt_pcbc_enc_tv_template,
3697 .count = FCRYPT_ENC_TEST_VECTORS
3698 },
3699 .dec = {
3700 .vecs = fcrypt_pcbc_dec_tv_template,
3701 .count = FCRYPT_DEC_TEST_VECTORS
3702 }
3703 }
3704 }
3705 }, {
Martin Willieee9dc62015-06-01 13:43:59 +02003706 .alg = "poly1305",
3707 .test = alg_test_hash,
3708 .suite = {
3709 .hash = {
3710 .vecs = poly1305_tv_template,
3711 .count = POLY1305_TEST_VECTORS
3712 }
3713 }
3714 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003715 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003716 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003717 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003718 .suite = {
3719 .cipher = {
3720 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003721 .vecs = aes_ctr_rfc3686_enc_tv_template,
3722 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003723 },
3724 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003725 .vecs = aes_ctr_rfc3686_dec_tv_template,
3726 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003727 }
3728 }
3729 }
3730 }, {
Herbert Xu3f31a742015-07-09 07:17:34 +08003731 .alg = "rfc4106(gcm(aes))",
Adrian Hoban69435b92010-11-04 15:02:04 -04003732 .test = alg_test_aead,
Jarod Wilsondb71f29a2015-01-23 12:42:15 -05003733 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003734 .suite = {
3735 .aead = {
3736 .enc = {
3737 .vecs = aes_gcm_rfc4106_enc_tv_template,
3738 .count = AES_GCM_4106_ENC_TEST_VECTORS
3739 },
3740 .dec = {
3741 .vecs = aes_gcm_rfc4106_dec_tv_template,
3742 .count = AES_GCM_4106_DEC_TEST_VECTORS
3743 }
3744 }
3745 }
3746 }, {
Herbert Xu544c4362015-07-14 16:53:22 +08003747 .alg = "rfc4309(ccm(aes))",
Jarod Wilson5d667322009-05-04 19:23:40 +08003748 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003749 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003750 .suite = {
3751 .aead = {
3752 .enc = {
3753 .vecs = aes_ccm_rfc4309_enc_tv_template,
3754 .count = AES_CCM_4309_ENC_TEST_VECTORS
3755 },
3756 .dec = {
3757 .vecs = aes_ccm_rfc4309_dec_tv_template,
3758 .count = AES_CCM_4309_DEC_TEST_VECTORS
3759 }
3760 }
3761 }
3762 }, {
Herbert Xubb687452015-06-16 13:54:24 +08003763 .alg = "rfc4543(gcm(aes))",
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003764 .test = alg_test_aead,
3765 .suite = {
3766 .aead = {
3767 .enc = {
3768 .vecs = aes_gcm_rfc4543_enc_tv_template,
3769 .count = AES_GCM_4543_ENC_TEST_VECTORS
3770 },
3771 .dec = {
3772 .vecs = aes_gcm_rfc4543_dec_tv_template,
3773 .count = AES_GCM_4543_DEC_TEST_VECTORS
3774 },
3775 }
3776 }
3777 }, {
Martin Williaf2b76b2015-06-01 13:44:01 +02003778 .alg = "rfc7539(chacha20,poly1305)",
3779 .test = alg_test_aead,
3780 .suite = {
3781 .aead = {
3782 .enc = {
3783 .vecs = rfc7539_enc_tv_template,
3784 .count = RFC7539_ENC_TEST_VECTORS
3785 },
3786 .dec = {
3787 .vecs = rfc7539_dec_tv_template,
3788 .count = RFC7539_DEC_TEST_VECTORS
3789 },
3790 }
3791 }
3792 }, {
Martin Willi59007582015-06-01 13:44:03 +02003793 .alg = "rfc7539esp(chacha20,poly1305)",
3794 .test = alg_test_aead,
3795 .suite = {
3796 .aead = {
3797 .enc = {
3798 .vecs = rfc7539esp_enc_tv_template,
3799 .count = RFC7539ESP_ENC_TEST_VECTORS
3800 },
3801 .dec = {
3802 .vecs = rfc7539esp_dec_tv_template,
3803 .count = RFC7539ESP_DEC_TEST_VECTORS
3804 },
3805 }
3806 }
3807 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003808 .alg = "rmd128",
3809 .test = alg_test_hash,
3810 .suite = {
3811 .hash = {
3812 .vecs = rmd128_tv_template,
3813 .count = RMD128_TEST_VECTORS
3814 }
3815 }
3816 }, {
3817 .alg = "rmd160",
3818 .test = alg_test_hash,
3819 .suite = {
3820 .hash = {
3821 .vecs = rmd160_tv_template,
3822 .count = RMD160_TEST_VECTORS
3823 }
3824 }
3825 }, {
3826 .alg = "rmd256",
3827 .test = alg_test_hash,
3828 .suite = {
3829 .hash = {
3830 .vecs = rmd256_tv_template,
3831 .count = RMD256_TEST_VECTORS
3832 }
3833 }
3834 }, {
3835 .alg = "rmd320",
3836 .test = alg_test_hash,
3837 .suite = {
3838 .hash = {
3839 .vecs = rmd320_tv_template,
3840 .count = RMD320_TEST_VECTORS
3841 }
3842 }
3843 }, {
Tadeusz Struk946cc462015-06-16 10:31:06 -07003844 .alg = "rsa",
3845 .test = alg_test_akcipher,
3846 .fips_allowed = 1,
3847 .suite = {
3848 .akcipher = {
3849 .vecs = rsa_tv_template,
3850 .count = RSA_TEST_VECTORS
3851 }
3852 }
3853 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003854 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003855 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003856 .suite = {
3857 .cipher = {
3858 .enc = {
3859 .vecs = salsa20_stream_enc_tv_template,
3860 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3861 }
3862 }
3863 }
3864 }, {
3865 .alg = "sha1",
3866 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003867 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003868 .suite = {
3869 .hash = {
3870 .vecs = sha1_tv_template,
3871 .count = SHA1_TEST_VECTORS
3872 }
3873 }
3874 }, {
3875 .alg = "sha224",
3876 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003877 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003878 .suite = {
3879 .hash = {
3880 .vecs = sha224_tv_template,
3881 .count = SHA224_TEST_VECTORS
3882 }
3883 }
3884 }, {
3885 .alg = "sha256",
3886 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003887 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003888 .suite = {
3889 .hash = {
3890 .vecs = sha256_tv_template,
3891 .count = SHA256_TEST_VECTORS
3892 }
3893 }
3894 }, {
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303895 .alg = "sha3-224",
3896 .test = alg_test_hash,
3897 .fips_allowed = 1,
3898 .suite = {
3899 .hash = {
3900 .vecs = sha3_224_tv_template,
3901 .count = SHA3_224_TEST_VECTORS
3902 }
3903 }
3904 }, {
3905 .alg = "sha3-256",
3906 .test = alg_test_hash,
3907 .fips_allowed = 1,
3908 .suite = {
3909 .hash = {
3910 .vecs = sha3_256_tv_template,
3911 .count = SHA3_256_TEST_VECTORS
3912 }
3913 }
3914 }, {
3915 .alg = "sha3-384",
3916 .test = alg_test_hash,
3917 .fips_allowed = 1,
3918 .suite = {
3919 .hash = {
3920 .vecs = sha3_384_tv_template,
3921 .count = SHA3_384_TEST_VECTORS
3922 }
3923 }
3924 }, {
3925 .alg = "sha3-512",
3926 .test = alg_test_hash,
3927 .fips_allowed = 1,
3928 .suite = {
3929 .hash = {
3930 .vecs = sha3_512_tv_template,
3931 .count = SHA3_512_TEST_VECTORS
3932 }
3933 }
3934 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003935 .alg = "sha384",
3936 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003937 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003938 .suite = {
3939 .hash = {
3940 .vecs = sha384_tv_template,
3941 .count = SHA384_TEST_VECTORS
3942 }
3943 }
3944 }, {
3945 .alg = "sha512",
3946 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003947 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003948 .suite = {
3949 .hash = {
3950 .vecs = sha512_tv_template,
3951 .count = SHA512_TEST_VECTORS
3952 }
3953 }
3954 }, {
3955 .alg = "tgr128",
3956 .test = alg_test_hash,
3957 .suite = {
3958 .hash = {
3959 .vecs = tgr128_tv_template,
3960 .count = TGR128_TEST_VECTORS
3961 }
3962 }
3963 }, {
3964 .alg = "tgr160",
3965 .test = alg_test_hash,
3966 .suite = {
3967 .hash = {
3968 .vecs = tgr160_tv_template,
3969 .count = TGR160_TEST_VECTORS
3970 }
3971 }
3972 }, {
3973 .alg = "tgr192",
3974 .test = alg_test_hash,
3975 .suite = {
3976 .hash = {
3977 .vecs = tgr192_tv_template,
3978 .count = TGR192_TEST_VECTORS
3979 }
3980 }
3981 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003982 .alg = "vmac(aes)",
3983 .test = alg_test_hash,
3984 .suite = {
3985 .hash = {
3986 .vecs = aes_vmac128_tv_template,
3987 .count = VMAC_AES_TEST_VECTORS
3988 }
3989 }
3990 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003991 .alg = "wp256",
3992 .test = alg_test_hash,
3993 .suite = {
3994 .hash = {
3995 .vecs = wp256_tv_template,
3996 .count = WP256_TEST_VECTORS
3997 }
3998 }
3999 }, {
4000 .alg = "wp384",
4001 .test = alg_test_hash,
4002 .suite = {
4003 .hash = {
4004 .vecs = wp384_tv_template,
4005 .count = WP384_TEST_VECTORS
4006 }
4007 }
4008 }, {
4009 .alg = "wp512",
4010 .test = alg_test_hash,
4011 .suite = {
4012 .hash = {
4013 .vecs = wp512_tv_template,
4014 .count = WP512_TEST_VECTORS
4015 }
4016 }
4017 }, {
4018 .alg = "xcbc(aes)",
4019 .test = alg_test_hash,
4020 .suite = {
4021 .hash = {
4022 .vecs = aes_xcbc128_tv_template,
4023 .count = XCBC_AES_TEST_VECTORS
4024 }
4025 }
4026 }, {
4027 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004028 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11004029 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004030 .suite = {
4031 .cipher = {
4032 .enc = {
4033 .vecs = aes_xts_enc_tv_template,
4034 .count = AES_XTS_ENC_TEST_VECTORS
4035 },
4036 .dec = {
4037 .vecs = aes_xts_dec_tv_template,
4038 .count = AES_XTS_DEC_TEST_VECTORS
4039 }
4040 }
4041 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08004042 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02004043 .alg = "xts(camellia)",
4044 .test = alg_test_skcipher,
4045 .suite = {
4046 .cipher = {
4047 .enc = {
4048 .vecs = camellia_xts_enc_tv_template,
4049 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
4050 },
4051 .dec = {
4052 .vecs = camellia_xts_dec_tv_template,
4053 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
4054 }
4055 }
4056 }
4057 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02004058 .alg = "xts(cast6)",
4059 .test = alg_test_skcipher,
4060 .suite = {
4061 .cipher = {
4062 .enc = {
4063 .vecs = cast6_xts_enc_tv_template,
4064 .count = CAST6_XTS_ENC_TEST_VECTORS
4065 },
4066 .dec = {
4067 .vecs = cast6_xts_dec_tv_template,
4068 .count = CAST6_XTS_DEC_TEST_VECTORS
4069 }
4070 }
4071 }
4072 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03004073 .alg = "xts(serpent)",
4074 .test = alg_test_skcipher,
4075 .suite = {
4076 .cipher = {
4077 .enc = {
4078 .vecs = serpent_xts_enc_tv_template,
4079 .count = SERPENT_XTS_ENC_TEST_VECTORS
4080 },
4081 .dec = {
4082 .vecs = serpent_xts_dec_tv_template,
4083 .count = SERPENT_XTS_DEC_TEST_VECTORS
4084 }
4085 }
4086 }
4087 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03004088 .alg = "xts(twofish)",
4089 .test = alg_test_skcipher,
4090 .suite = {
4091 .cipher = {
4092 .enc = {
4093 .vecs = tf_xts_enc_tv_template,
4094 .count = TF_XTS_ENC_TEST_VECTORS
4095 },
4096 .dec = {
4097 .vecs = tf_xts_dec_tv_template,
4098 .count = TF_XTS_DEC_TEST_VECTORS
4099 }
4100 }
4101 }
Herbert Xuda7f0332008-07-31 17:08:25 +08004102 }
4103};
4104
Jussi Kivilinna57147582013-06-13 17:37:40 +03004105static bool alg_test_descs_checked;
4106
4107static void alg_test_descs_check_order(void)
4108{
4109 int i;
4110
4111 /* only check once */
4112 if (alg_test_descs_checked)
4113 return;
4114
4115 alg_test_descs_checked = true;
4116
4117 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
4118 int diff = strcmp(alg_test_descs[i - 1].alg,
4119 alg_test_descs[i].alg);
4120
4121 if (WARN_ON(diff > 0)) {
4122 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
4123 alg_test_descs[i - 1].alg,
4124 alg_test_descs[i].alg);
4125 }
4126
4127 if (WARN_ON(diff == 0)) {
4128 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
4129 alg_test_descs[i].alg);
4130 }
4131 }
4132}
4133
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004134static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08004135{
4136 int start = 0;
4137 int end = ARRAY_SIZE(alg_test_descs);
4138
4139 while (start < end) {
4140 int i = (start + end) / 2;
4141 int diff = strcmp(alg_test_descs[i].alg, alg);
4142
4143 if (diff > 0) {
4144 end = i;
4145 continue;
4146 }
4147
4148 if (diff < 0) {
4149 start = i + 1;
4150 continue;
4151 }
4152
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004153 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08004154 }
4155
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004156 return -1;
4157}
4158
4159int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
4160{
4161 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08004162 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08004163 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004164
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +01004165 if (!fips_enabled && notests) {
4166 printk_once(KERN_INFO "alg: self-tests disabled\n");
4167 return 0;
4168 }
4169
Jussi Kivilinna57147582013-06-13 17:37:40 +03004170 alg_test_descs_check_order();
4171
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004172 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
4173 char nalg[CRYPTO_MAX_ALG_NAME];
4174
4175 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
4176 sizeof(nalg))
4177 return -ENAMETOOLONG;
4178
4179 i = alg_find_test(nalg);
4180 if (i < 0)
4181 goto notest;
4182
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004183 if (fips_enabled && !alg_test_descs[i].fips_allowed)
4184 goto non_fips_alg;
4185
Jarod Wilson941fb322009-05-04 19:49:23 +08004186 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
4187 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004188 }
4189
4190 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08004191 j = alg_find_test(driver);
4192 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004193 goto notest;
4194
Herbert Xua68f6612009-07-02 16:32:12 +08004195 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
4196 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004197 goto non_fips_alg;
4198
Herbert Xua68f6612009-07-02 16:32:12 +08004199 rc = 0;
4200 if (i >= 0)
4201 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
4202 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03004203 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08004204 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
4205 type, mask);
4206
Jarod Wilson941fb322009-05-04 19:49:23 +08004207test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08004208 if (fips_enabled && rc)
4209 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
4210
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004211 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09004212 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004213
Neil Hormand12d6b62008-10-12 20:36:51 +08004214 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004215
4216notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08004217 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
4218 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004219non_fips_alg:
4220 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08004221}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004222
Herbert Xu326a6342010-08-06 09:40:28 +08004223#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004224
Herbert Xuda7f0332008-07-31 17:08:25 +08004225EXPORT_SYMBOL_GPL(alg_test);