blob: 89f1dd1f4b13d82466013d612039b8b3ac61013a [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 {
Eric Biggersb13b1e02017-02-24 15:46:59 -080086 const struct aead_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +080087 unsigned int count;
88 } enc, dec;
89};
90
91struct cipher_test_suite {
92 struct {
Eric Biggersb13b1e02017-02-24 15:46:59 -080093 const struct cipher_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +080094 unsigned int count;
95 } enc, dec;
96};
97
98struct comp_test_suite {
99 struct {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800100 const struct comp_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +0800101 unsigned int count;
102 } comp, decomp;
103};
104
105struct hash_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800106 const struct hash_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +0800107 unsigned int count;
108};
109
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800110struct cprng_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800111 const struct cprng_testvec *vecs;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800112 unsigned int count;
113};
114
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200115struct drbg_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800116 const struct drbg_testvec *vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200117 unsigned int count;
118};
119
Tadeusz Struk946cc462015-06-16 10:31:06 -0700120struct akcipher_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800121 const struct akcipher_testvec *vecs;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700122 unsigned int count;
123};
124
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100125struct kpp_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800126 const struct kpp_testvec *vecs;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100127 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
Eric Biggersb13b1e02017-02-24 15:46:59 -0800148static const unsigned int IDX[8] = {
149 IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
Herbert Xuda7f0332008-07-31 17:08:25 +0800150
Herbert Xuda7f0332008-07-31 17:08:25 +0800151static void hexdump(unsigned char *buf, unsigned int len)
152{
153 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
154 16, 1,
155 buf, len, false);
156}
157
158static void tcrypt_complete(struct crypto_async_request *req, int err)
159{
160 struct tcrypt_result *res = req->data;
161
162 if (err == -EINPROGRESS)
163 return;
164
165 res->err = err;
166 complete(&res->completion);
167}
168
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800169static int testmgr_alloc_buf(char *buf[XBUFSIZE])
170{
171 int i;
172
173 for (i = 0; i < XBUFSIZE; i++) {
174 buf[i] = (void *)__get_free_page(GFP_KERNEL);
175 if (!buf[i])
176 goto err_free_buf;
177 }
178
179 return 0;
180
181err_free_buf:
182 while (i-- > 0)
183 free_page((unsigned long)buf[i]);
184
185 return -ENOMEM;
186}
187
188static void testmgr_free_buf(char *buf[XBUFSIZE])
189{
190 int i;
191
192 for (i = 0; i < XBUFSIZE; i++)
193 free_page((unsigned long)buf[i]);
194}
195
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300196static int wait_async_op(struct tcrypt_result *tr, int ret)
David S. Millera8f1a052010-05-19 14:12:03 +1000197{
198 if (ret == -EINPROGRESS || ret == -EBUSY) {
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100199 wait_for_completion(&tr->completion);
Wolfram Sang16735d02013-11-14 14:32:02 -0800200 reinit_completion(&tr->completion);
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100201 ret = tr->err;
David S. Millera8f1a052010-05-19 14:12:03 +1000202 }
203 return ret;
204}
205
Wang, Rui Y018ba952016-02-03 18:26:57 +0800206static int ahash_partial_update(struct ahash_request **preq,
Eric Biggersb13b1e02017-02-24 15:46:59 -0800207 struct crypto_ahash *tfm, const struct hash_testvec *template,
Wang, Rui Y018ba952016-02-03 18:26:57 +0800208 void *hash_buff, int k, int temp, struct scatterlist *sg,
209 const char *algo, char *result, struct tcrypt_result *tresult)
210{
211 char *state;
212 struct ahash_request *req;
213 int statesize, ret = -EINVAL;
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200214 const char guard[] = { 0x00, 0xba, 0xad, 0x00 };
Wang, Rui Y018ba952016-02-03 18:26:57 +0800215
216 req = *preq;
217 statesize = crypto_ahash_statesize(
218 crypto_ahash_reqtfm(req));
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200219 state = kmalloc(statesize + sizeof(guard), GFP_KERNEL);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800220 if (!state) {
221 pr_err("alt: hash: Failed to alloc state for %s\n", algo);
222 goto out_nostate;
223 }
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200224 memcpy(state + statesize, guard, sizeof(guard));
Wang, Rui Y018ba952016-02-03 18:26:57 +0800225 ret = crypto_ahash_export(req, state);
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200226 WARN_ON(memcmp(state + statesize, guard, sizeof(guard)));
Wang, Rui Y018ba952016-02-03 18:26:57 +0800227 if (ret) {
228 pr_err("alt: hash: Failed to export() for %s\n", algo);
229 goto out;
230 }
231 ahash_request_free(req);
232 req = ahash_request_alloc(tfm, GFP_KERNEL);
233 if (!req) {
234 pr_err("alg: hash: Failed to alloc request for %s\n", algo);
235 goto out_noreq;
236 }
237 ahash_request_set_callback(req,
238 CRYPTO_TFM_REQ_MAY_BACKLOG,
239 tcrypt_complete, tresult);
240
241 memcpy(hash_buff, template->plaintext + temp,
242 template->tap[k]);
243 sg_init_one(&sg[0], hash_buff, template->tap[k]);
244 ahash_request_set_crypt(req, sg, result, template->tap[k]);
245 ret = crypto_ahash_import(req, state);
246 if (ret) {
247 pr_err("alg: hash: Failed to import() for %s\n", algo);
248 goto out;
249 }
250 ret = wait_async_op(tresult, crypto_ahash_update(req));
251 if (ret)
252 goto out;
253 *preq = req;
254 ret = 0;
255 goto out_noreq;
256out:
257 ahash_request_free(req);
258out_noreq:
259 kfree(state);
260out_nostate:
261 return ret;
262}
263
Eric Biggersb13b1e02017-02-24 15:46:59 -0800264static int __test_hash(struct crypto_ahash *tfm,
265 const struct hash_testvec *template, unsigned int tcount,
266 bool use_digest, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800267{
268 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800269 size_t digest_size = crypto_ahash_digestsize(tfm);
Herbert Xuda7f0332008-07-31 17:08:25 +0800270 unsigned int i, j, k, temp;
271 struct scatterlist sg[8];
Horia Geanta29b77e52014-07-23 11:59:38 +0300272 char *result;
273 char *key;
Herbert Xuda7f0332008-07-31 17:08:25 +0800274 struct ahash_request *req;
275 struct tcrypt_result tresult;
Herbert Xuda7f0332008-07-31 17:08:25 +0800276 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800277 char *xbuf[XBUFSIZE];
278 int ret = -ENOMEM;
279
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800280 result = kmalloc(digest_size, GFP_KERNEL);
Horia Geanta29b77e52014-07-23 11:59:38 +0300281 if (!result)
282 return ret;
283 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
284 if (!key)
285 goto out_nobuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800286 if (testmgr_alloc_buf(xbuf))
287 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800288
289 init_completion(&tresult.completion);
290
291 req = ahash_request_alloc(tfm, GFP_KERNEL);
292 if (!req) {
293 printk(KERN_ERR "alg: hash: Failed to allocate request for "
294 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800295 goto out_noreq;
296 }
297 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
298 tcrypt_complete, &tresult);
299
Herbert Xua0cfae52009-05-29 16:23:12 +1000300 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800301 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000302 if (template[i].np)
303 continue;
304
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300305 ret = -EINVAL;
306 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
307 goto out;
308
Herbert Xua0cfae52009-05-29 16:23:12 +1000309 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800310 memset(result, 0, digest_size);
Herbert Xuda7f0332008-07-31 17:08:25 +0800311
312 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300313 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800314
315 memcpy(hash_buff, template[i].plaintext, template[i].psize);
316 sg_init_one(&sg[0], hash_buff, template[i].psize);
317
318 if (template[i].ksize) {
319 crypto_ahash_clear_flags(tfm, ~0);
Horia Geanta29b77e52014-07-23 11:59:38 +0300320 if (template[i].ksize > MAX_KEYLEN) {
321 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
322 j, algo, template[i].ksize, MAX_KEYLEN);
323 ret = -EINVAL;
324 goto out;
325 }
326 memcpy(key, template[i].key, template[i].ksize);
327 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
Herbert Xuda7f0332008-07-31 17:08:25 +0800328 if (ret) {
329 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000330 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800331 -ret);
332 goto out;
333 }
334 }
335
336 ahash_request_set_crypt(req, sg, result, template[i].psize);
David S. Millera8f1a052010-05-19 14:12:03 +1000337 if (use_digest) {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300338 ret = wait_async_op(&tresult, crypto_ahash_digest(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000339 if (ret) {
340 pr_err("alg: hash: digest failed on test %d "
341 "for %s: ret=%d\n", j, algo, -ret);
342 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800343 }
David S. Millera8f1a052010-05-19 14:12:03 +1000344 } else {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300345 ret = wait_async_op(&tresult, crypto_ahash_init(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000346 if (ret) {
347 pr_err("alt: hash: init failed on test %d "
348 "for %s: ret=%d\n", j, algo, -ret);
349 goto out;
350 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300351 ret = wait_async_op(&tresult, crypto_ahash_update(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000352 if (ret) {
353 pr_err("alt: hash: update failed on test %d "
354 "for %s: ret=%d\n", j, algo, -ret);
355 goto out;
356 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300357 ret = wait_async_op(&tresult, crypto_ahash_final(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000358 if (ret) {
359 pr_err("alt: hash: final failed on test %d "
360 "for %s: ret=%d\n", j, algo, -ret);
361 goto out;
362 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800363 }
364
365 if (memcmp(result, template[i].digest,
366 crypto_ahash_digestsize(tfm))) {
367 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000368 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800369 hexdump(result, crypto_ahash_digestsize(tfm));
370 ret = -EINVAL;
371 goto out;
372 }
373 }
374
375 j = 0;
376 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300377 /* alignment tests are only done with continuous buffers */
378 if (align_offset != 0)
379 break;
380
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300381 if (!template[i].np)
382 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800383
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300384 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800385 memset(result, 0, digest_size);
Herbert Xuda7f0332008-07-31 17:08:25 +0800386
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300387 temp = 0;
388 sg_init_table(sg, template[i].np);
389 ret = -EINVAL;
390 for (k = 0; k < template[i].np; k++) {
391 if (WARN_ON(offset_in_page(IDX[k]) +
392 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +0800393 goto out;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300394 sg_set_buf(&sg[k],
395 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
396 offset_in_page(IDX[k]),
397 template[i].plaintext + temp,
398 template[i].tap[k]),
399 template[i].tap[k]);
400 temp += template[i].tap[k];
401 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800402
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300403 if (template[i].ksize) {
404 if (template[i].ksize > MAX_KEYLEN) {
405 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
406 j, algo, template[i].ksize, MAX_KEYLEN);
Herbert Xuda7f0332008-07-31 17:08:25 +0800407 ret = -EINVAL;
408 goto out;
409 }
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300410 crypto_ahash_clear_flags(tfm, ~0);
411 memcpy(key, template[i].key, template[i].ksize);
412 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
413
414 if (ret) {
415 printk(KERN_ERR "alg: hash: setkey "
416 "failed on chunking test %d "
417 "for %s: ret=%d\n", j, algo, -ret);
418 goto out;
419 }
420 }
421
422 ahash_request_set_crypt(req, sg, result, template[i].psize);
423 ret = crypto_ahash_digest(req);
424 switch (ret) {
425 case 0:
426 break;
427 case -EINPROGRESS:
428 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100429 wait_for_completion(&tresult.completion);
430 reinit_completion(&tresult.completion);
431 ret = tresult.err;
432 if (!ret)
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300433 break;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300434 /* fall through */
435 default:
436 printk(KERN_ERR "alg: hash: digest failed "
437 "on chunking test %d for %s: "
438 "ret=%d\n", j, algo, -ret);
439 goto out;
440 }
441
442 if (memcmp(result, template[i].digest,
443 crypto_ahash_digestsize(tfm))) {
444 printk(KERN_ERR "alg: hash: Chunking test %d "
445 "failed for %s\n", j, algo);
446 hexdump(result, crypto_ahash_digestsize(tfm));
447 ret = -EINVAL;
448 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800449 }
450 }
451
Wang, Rui Y018ba952016-02-03 18:26:57 +0800452 /* partial update exercise */
453 j = 0;
454 for (i = 0; i < tcount; i++) {
455 /* alignment tests are only done with continuous buffers */
456 if (align_offset != 0)
457 break;
458
459 if (template[i].np < 2)
460 continue;
461
462 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800463 memset(result, 0, digest_size);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800464
465 ret = -EINVAL;
466 hash_buff = xbuf[0];
467 memcpy(hash_buff, template[i].plaintext,
468 template[i].tap[0]);
469 sg_init_one(&sg[0], hash_buff, template[i].tap[0]);
470
471 if (template[i].ksize) {
472 crypto_ahash_clear_flags(tfm, ~0);
473 if (template[i].ksize > MAX_KEYLEN) {
474 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
475 j, algo, template[i].ksize, MAX_KEYLEN);
476 ret = -EINVAL;
477 goto out;
478 }
479 memcpy(key, template[i].key, template[i].ksize);
480 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
481 if (ret) {
482 pr_err("alg: hash: setkey failed on test %d for %s: ret=%d\n",
483 j, algo, -ret);
484 goto out;
485 }
486 }
487
488 ahash_request_set_crypt(req, sg, result, template[i].tap[0]);
489 ret = wait_async_op(&tresult, crypto_ahash_init(req));
490 if (ret) {
491 pr_err("alt: hash: init failed on test %d for %s: ret=%d\n",
492 j, algo, -ret);
493 goto out;
494 }
495 ret = wait_async_op(&tresult, crypto_ahash_update(req));
496 if (ret) {
497 pr_err("alt: hash: update failed on test %d for %s: ret=%d\n",
498 j, algo, -ret);
499 goto out;
500 }
501
502 temp = template[i].tap[0];
503 for (k = 1; k < template[i].np; k++) {
504 ret = ahash_partial_update(&req, tfm, &template[i],
505 hash_buff, k, temp, &sg[0], algo, result,
506 &tresult);
507 if (ret) {
508 pr_err("hash: partial update failed on test %d for %s: ret=%d\n",
509 j, algo, -ret);
510 goto out_noreq;
511 }
512 temp += template[i].tap[k];
513 }
514 ret = wait_async_op(&tresult, crypto_ahash_final(req));
515 if (ret) {
516 pr_err("alt: hash: final failed on test %d for %s: ret=%d\n",
517 j, algo, -ret);
518 goto out;
519 }
520 if (memcmp(result, template[i].digest,
521 crypto_ahash_digestsize(tfm))) {
522 pr_err("alg: hash: Partial Test %d failed for %s\n",
523 j, algo);
524 hexdump(result, crypto_ahash_digestsize(tfm));
525 ret = -EINVAL;
526 goto out;
527 }
528 }
529
Herbert Xuda7f0332008-07-31 17:08:25 +0800530 ret = 0;
531
532out:
533 ahash_request_free(req);
534out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800535 testmgr_free_buf(xbuf);
536out_nobuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300537 kfree(key);
538 kfree(result);
Herbert Xuda7f0332008-07-31 17:08:25 +0800539 return ret;
540}
541
Eric Biggersb13b1e02017-02-24 15:46:59 -0800542static int test_hash(struct crypto_ahash *tfm,
543 const struct hash_testvec *template,
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300544 unsigned int tcount, bool use_digest)
545{
546 unsigned int alignmask;
547 int ret;
548
549 ret = __test_hash(tfm, template, tcount, use_digest, 0);
550 if (ret)
551 return ret;
552
553 /* test unaligned buffers, check with one byte offset */
554 ret = __test_hash(tfm, template, tcount, use_digest, 1);
555 if (ret)
556 return ret;
557
558 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
559 if (alignmask) {
560 /* Check if alignment mask for tfm is correctly set. */
561 ret = __test_hash(tfm, template, tcount, use_digest,
562 alignmask + 1);
563 if (ret)
564 return ret;
565 }
566
567 return 0;
568}
569
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300570static int __test_aead(struct crypto_aead *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -0800571 const struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300572 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800573{
574 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
575 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800576 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800577 char *q;
578 char *key;
579 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300580 struct scatterlist *sg;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300581 struct scatterlist *sgout;
582 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800583 struct tcrypt_result result;
Cristian Stoica424a5da2015-01-28 11:03:05 +0200584 unsigned int authsize, iv_len;
Herbert Xuda7f0332008-07-31 17:08:25 +0800585 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300586 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800587 void *assoc;
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700588 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800589 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300590 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800591 char *axbuf[XBUFSIZE];
592
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700593 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
594 if (!iv)
595 return ret;
Horia Geanta29b77e52014-07-23 11:59:38 +0300596 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
597 if (!key)
598 goto out_noxbuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800599 if (testmgr_alloc_buf(xbuf))
600 goto out_noxbuf;
601 if (testmgr_alloc_buf(axbuf))
602 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300603 if (diff_dst && testmgr_alloc_buf(xoutbuf))
604 goto out_nooutbuf;
605
606 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800607 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 4 : 2), GFP_KERNEL);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300608 if (!sg)
609 goto out_nosg;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800610 sgout = &sg[16];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300611
612 if (diff_dst)
613 d = "-ddst";
614 else
615 d = "";
616
Herbert Xuda7f0332008-07-31 17:08:25 +0800617 if (enc == ENCRYPT)
618 e = "encryption";
619 else
620 e = "decryption";
621
622 init_completion(&result.completion);
623
624 req = aead_request_alloc(tfm, GFP_KERNEL);
625 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300626 pr_err("alg: aead%s: Failed to allocate request for %s\n",
627 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800628 goto out;
629 }
630
631 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
632 tcrypt_complete, &result);
633
Jerome Marchandabfa7f42016-02-03 13:58:12 +0100634 iv_len = crypto_aead_ivsize(tfm);
635
Herbert Xuda7f0332008-07-31 17:08:25 +0800636 for (i = 0, j = 0; i < tcount; i++) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300637 if (template[i].np)
638 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800639
Cristian Stoica05b1d332014-07-28 13:11:23 +0300640 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800641
Cristian Stoica05b1d332014-07-28 13:11:23 +0300642 /* some templates have no input data but they will
643 * touch input
644 */
645 input = xbuf[0];
646 input += align_offset;
647 assoc = axbuf[0];
648
649 ret = -EINVAL;
650 if (WARN_ON(align_offset + template[i].ilen >
651 PAGE_SIZE || template[i].alen > PAGE_SIZE))
652 goto out;
653
654 memcpy(input, template[i].input, template[i].ilen);
655 memcpy(assoc, template[i].assoc, template[i].alen);
656 if (template[i].iv)
Cristian Stoica424a5da2015-01-28 11:03:05 +0200657 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300658 else
Cristian Stoica424a5da2015-01-28 11:03:05 +0200659 memset(iv, 0, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300660
661 crypto_aead_clear_flags(tfm, ~0);
662 if (template[i].wk)
663 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
664
665 if (template[i].klen > MAX_KEYLEN) {
666 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
667 d, j, algo, template[i].klen,
668 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +1000669 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300670 goto out;
671 }
672 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +1000673
Cristian Stoica05b1d332014-07-28 13:11:23 +0300674 ret = crypto_aead_setkey(tfm, key, template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +0800675 if (template[i].fail == !ret) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300676 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
677 d, j, algo, crypto_aead_get_flags(tfm));
678 goto out;
679 } else if (ret)
680 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800681
Cristian Stoica05b1d332014-07-28 13:11:23 +0300682 authsize = abs(template[i].rlen - template[i].ilen);
683 ret = crypto_aead_setauthsize(tfm, authsize);
684 if (ret) {
685 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
686 d, authsize, j, algo);
687 goto out;
688 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800689
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800690 k = !!template[i].alen;
691 sg_init_table(sg, k + 1);
692 sg_set_buf(&sg[0], assoc, template[i].alen);
693 sg_set_buf(&sg[k], input,
694 template[i].ilen + (enc ? authsize : 0));
695 output = input;
696
Cristian Stoica05b1d332014-07-28 13:11:23 +0300697 if (diff_dst) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800698 sg_init_table(sgout, k + 1);
699 sg_set_buf(&sgout[0], assoc, template[i].alen);
700
Cristian Stoica05b1d332014-07-28 13:11:23 +0300701 output = xoutbuf[0];
702 output += align_offset;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800703 sg_set_buf(&sgout[k], output,
704 template[i].rlen + (enc ? 0 : authsize));
Cristian Stoica05b1d332014-07-28 13:11:23 +0300705 }
706
Cristian Stoica05b1d332014-07-28 13:11:23 +0300707 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
708 template[i].ilen, iv);
709
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800710 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300711
712 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
713
714 switch (ret) {
715 case 0:
716 if (template[i].novrfy) {
717 /* verification was supposed to fail */
718 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
719 d, e, j, algo);
720 /* so really, we got a bad message */
721 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +0300722 goto out;
723 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300724 break;
725 case -EINPROGRESS:
726 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100727 wait_for_completion(&result.completion);
728 reinit_completion(&result.completion);
729 ret = result.err;
730 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +0800731 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300732 case -EBADMSG:
733 if (template[i].novrfy)
734 /* verification failure was expected */
735 continue;
736 /* fall through */
737 default:
738 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
739 d, e, j, algo, -ret);
740 goto out;
741 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800742
Cristian Stoica05b1d332014-07-28 13:11:23 +0300743 q = output;
744 if (memcmp(q, template[i].result, template[i].rlen)) {
745 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
746 d, j, e, algo);
747 hexdump(q, template[i].rlen);
748 ret = -EINVAL;
749 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800750 }
751 }
752
753 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300754 /* alignment tests are only done with continuous buffers */
755 if (align_offset != 0)
756 break;
757
Cristian Stoica05b1d332014-07-28 13:11:23 +0300758 if (!template[i].np)
759 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800760
Cristian Stoica05b1d332014-07-28 13:11:23 +0300761 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800762
Cristian Stoica05b1d332014-07-28 13:11:23 +0300763 if (template[i].iv)
Jerome Marchandabfa7f42016-02-03 13:58:12 +0100764 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300765 else
766 memset(iv, 0, MAX_IVLEN);
767
768 crypto_aead_clear_flags(tfm, ~0);
769 if (template[i].wk)
770 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
771 if (template[i].klen > MAX_KEYLEN) {
772 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
773 d, j, algo, template[i].klen, MAX_KEYLEN);
774 ret = -EINVAL;
775 goto out;
776 }
777 memcpy(key, template[i].key, template[i].klen);
778
779 ret = crypto_aead_setkey(tfm, key, template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +0800780 if (template[i].fail == !ret) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300781 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
782 d, j, algo, crypto_aead_get_flags(tfm));
783 goto out;
784 } else if (ret)
785 continue;
786
787 authsize = abs(template[i].rlen - template[i].ilen);
788
789 ret = -EINVAL;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800790 sg_init_table(sg, template[i].anp + template[i].np);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300791 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800792 sg_init_table(sgout, template[i].anp + template[i].np);
793
794 ret = -EINVAL;
795 for (k = 0, temp = 0; k < template[i].anp; k++) {
796 if (WARN_ON(offset_in_page(IDX[k]) +
797 template[i].atap[k] > PAGE_SIZE))
798 goto out;
799 sg_set_buf(&sg[k],
800 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
801 offset_in_page(IDX[k]),
802 template[i].assoc + temp,
803 template[i].atap[k]),
804 template[i].atap[k]);
805 if (diff_dst)
806 sg_set_buf(&sgout[k],
807 axbuf[IDX[k] >> PAGE_SHIFT] +
808 offset_in_page(IDX[k]),
809 template[i].atap[k]);
810 temp += template[i].atap[k];
811 }
812
Cristian Stoica05b1d332014-07-28 13:11:23 +0300813 for (k = 0, temp = 0; k < template[i].np; k++) {
814 if (WARN_ON(offset_in_page(IDX[k]) +
815 template[i].tap[k] > PAGE_SIZE))
816 goto out;
817
818 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
819 memcpy(q, template[i].input + temp, template[i].tap[k]);
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800820 sg_set_buf(&sg[template[i].anp + k],
821 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300822
823 if (diff_dst) {
824 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
825 offset_in_page(IDX[k]);
826
827 memset(q, 0, template[i].tap[k]);
828
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800829 sg_set_buf(&sgout[template[i].anp + k],
830 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300831 }
832
833 n = template[i].tap[k];
834 if (k == template[i].np - 1 && enc)
835 n += authsize;
836 if (offset_in_page(q) + n < PAGE_SIZE)
837 q[n] = 0;
838
839 temp += template[i].tap[k];
840 }
841
842 ret = crypto_aead_setauthsize(tfm, authsize);
843 if (ret) {
844 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
845 d, authsize, j, algo);
846 goto out;
847 }
848
849 if (enc) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800850 if (WARN_ON(sg[template[i].anp + k - 1].offset +
851 sg[template[i].anp + k - 1].length +
852 authsize > PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300853 ret = -EINVAL;
854 goto out;
855 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800856
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300857 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800858 sgout[template[i].anp + k - 1].length +=
859 authsize;
860 sg[template[i].anp + k - 1].length += authsize;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300861 }
862
863 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
864 template[i].ilen,
865 iv);
866
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800867 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300868
869 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
870
871 switch (ret) {
872 case 0:
873 if (template[i].novrfy) {
874 /* verification was supposed to fail */
875 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
876 d, e, j, algo);
877 /* so really, we got a bad message */
878 ret = -EBADMSG;
879 goto out;
880 }
881 break;
882 case -EINPROGRESS:
883 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100884 wait_for_completion(&result.completion);
885 reinit_completion(&result.completion);
886 ret = result.err;
887 if (!ret)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300888 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300889 case -EBADMSG:
890 if (template[i].novrfy)
891 /* verification failure was expected */
892 continue;
893 /* fall through */
894 default:
895 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
896 d, e, j, algo, -ret);
897 goto out;
898 }
899
900 ret = -EINVAL;
901 for (k = 0, temp = 0; k < template[i].np; k++) {
902 if (diff_dst)
903 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
904 offset_in_page(IDX[k]);
905 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800906 q = xbuf[IDX[k] >> PAGE_SHIFT] +
907 offset_in_page(IDX[k]);
908
Cristian Stoica05b1d332014-07-28 13:11:23 +0300909 n = template[i].tap[k];
910 if (k == template[i].np - 1)
911 n += enc ? authsize : -authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800912
Cristian Stoica05b1d332014-07-28 13:11:23 +0300913 if (memcmp(q, template[i].result + temp, n)) {
914 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
915 d, j, e, k, algo);
916 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800917 goto out;
918 }
919
Cristian Stoica05b1d332014-07-28 13:11:23 +0300920 q += n;
921 if (k == template[i].np - 1 && !enc) {
922 if (!diff_dst &&
923 memcmp(q, template[i].input +
924 temp + n, authsize))
925 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200926 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300927 n = 0;
928 } else {
929 for (n = 0; offset_in_page(q + n) && q[n]; n++)
930 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800931 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300932 if (n) {
933 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
934 d, j, e, k, algo, n);
935 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800936 goto out;
937 }
938
Cristian Stoica05b1d332014-07-28 13:11:23 +0300939 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800940 }
941 }
942
943 ret = 0;
944
945out:
946 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300947 kfree(sg);
948out_nosg:
949 if (diff_dst)
950 testmgr_free_buf(xoutbuf);
951out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800952 testmgr_free_buf(axbuf);
953out_noaxbuf:
954 testmgr_free_buf(xbuf);
955out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300956 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700957 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800958 return ret;
959}
960
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300961static int test_aead(struct crypto_aead *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -0800962 const struct aead_testvec *template, unsigned int tcount)
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300963{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300964 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300965 int ret;
966
967 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300968 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300969 if (ret)
970 return ret;
971
972 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300973 ret = __test_aead(tfm, enc, template, tcount, true, 0);
974 if (ret)
975 return ret;
976
977 /* test unaligned buffers, check with one byte offset */
978 ret = __test_aead(tfm, enc, template, tcount, true, 1);
979 if (ret)
980 return ret;
981
982 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
983 if (alignmask) {
984 /* Check if alignment mask for tfm is correctly set. */
985 ret = __test_aead(tfm, enc, template, tcount, true,
986 alignmask + 1);
987 if (ret)
988 return ret;
989 }
990
991 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300992}
993
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000994static int test_cipher(struct crypto_cipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -0800995 const struct cipher_testvec *template,
996 unsigned int tcount)
Herbert Xuda7f0332008-07-31 17:08:25 +0800997{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000998 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
999 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001000 char *q;
1001 const char *e;
1002 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001003 char *xbuf[XBUFSIZE];
1004 int ret = -ENOMEM;
1005
1006 if (testmgr_alloc_buf(xbuf))
1007 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001008
1009 if (enc == ENCRYPT)
1010 e = "encryption";
1011 else
1012 e = "decryption";
1013
1014 j = 0;
1015 for (i = 0; i < tcount; i++) {
1016 if (template[i].np)
1017 continue;
1018
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001019 if (fips_enabled && template[i].fips_skip)
1020 continue;
1021
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001022 j++;
1023
Herbert Xufd57f222009-05-29 16:05:42 +10001024 ret = -EINVAL;
1025 if (WARN_ON(template[i].ilen > PAGE_SIZE))
1026 goto out;
1027
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001028 data = xbuf[0];
1029 memcpy(data, template[i].input, template[i].ilen);
1030
1031 crypto_cipher_clear_flags(tfm, ~0);
1032 if (template[i].wk)
1033 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1034
1035 ret = crypto_cipher_setkey(tfm, template[i].key,
1036 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001037 if (template[i].fail == !ret) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001038 printk(KERN_ERR "alg: cipher: setkey failed "
1039 "on test %d for %s: flags=%x\n", j,
1040 algo, crypto_cipher_get_flags(tfm));
1041 goto out;
1042 } else if (ret)
1043 continue;
1044
1045 for (k = 0; k < template[i].ilen;
1046 k += crypto_cipher_blocksize(tfm)) {
1047 if (enc)
1048 crypto_cipher_encrypt_one(tfm, data + k,
1049 data + k);
1050 else
1051 crypto_cipher_decrypt_one(tfm, data + k,
1052 data + k);
1053 }
1054
1055 q = data;
1056 if (memcmp(q, template[i].result, template[i].rlen)) {
1057 printk(KERN_ERR "alg: cipher: Test %d failed "
1058 "on %s for %s\n", j, e, algo);
1059 hexdump(q, template[i].rlen);
1060 ret = -EINVAL;
1061 goto out;
1062 }
1063 }
1064
1065 ret = 0;
1066
1067out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001068 testmgr_free_buf(xbuf);
1069out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001070 return ret;
1071}
1072
Herbert Xu12773d92015-08-20 15:21:46 +08001073static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001074 const struct cipher_testvec *template,
1075 unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001076 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001077{
Herbert Xuda7f0332008-07-31 17:08:25 +08001078 const char *algo =
Herbert Xu12773d92015-08-20 15:21:46 +08001079 crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +08001080 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +08001081 char *q;
Herbert Xu12773d92015-08-20 15:21:46 +08001082 struct skcipher_request *req;
Herbert Xuda7f0332008-07-31 17:08:25 +08001083 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001084 struct scatterlist sgout[8];
1085 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +08001086 struct tcrypt_result result;
1087 void *data;
1088 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001089 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001090 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001091 int ret = -ENOMEM;
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001092 unsigned int ivsize = crypto_skcipher_ivsize(tfm);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001093
1094 if (testmgr_alloc_buf(xbuf))
1095 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +08001096
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001097 if (diff_dst && testmgr_alloc_buf(xoutbuf))
1098 goto out_nooutbuf;
1099
1100 if (diff_dst)
1101 d = "-ddst";
1102 else
1103 d = "";
1104
Herbert Xuda7f0332008-07-31 17:08:25 +08001105 if (enc == ENCRYPT)
1106 e = "encryption";
1107 else
1108 e = "decryption";
1109
1110 init_completion(&result.completion);
1111
Herbert Xu12773d92015-08-20 15:21:46 +08001112 req = skcipher_request_alloc(tfm, GFP_KERNEL);
Herbert Xuda7f0332008-07-31 17:08:25 +08001113 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001114 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
1115 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +08001116 goto out;
1117 }
1118
Herbert Xu12773d92015-08-20 15:21:46 +08001119 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1120 tcrypt_complete, &result);
Herbert Xuda7f0332008-07-31 17:08:25 +08001121
1122 j = 0;
1123 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001124 if (template[i].np && !template[i].also_non_np)
1125 continue;
1126
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001127 if (fips_enabled && template[i].fips_skip)
1128 continue;
1129
Herbert Xuda7f0332008-07-31 17:08:25 +08001130 if (template[i].iv)
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001131 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001132 else
1133 memset(iv, 0, MAX_IVLEN);
1134
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001135 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001136 ret = -EINVAL;
1137 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
1138 goto out;
1139
1140 data = xbuf[0];
1141 data += align_offset;
1142 memcpy(data, template[i].input, template[i].ilen);
1143
Herbert Xu12773d92015-08-20 15:21:46 +08001144 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001145 if (template[i].wk)
Herbert Xu12773d92015-08-20 15:21:46 +08001146 crypto_skcipher_set_flags(tfm,
1147 CRYPTO_TFM_REQ_WEAK_KEY);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001148
Herbert Xu12773d92015-08-20 15:21:46 +08001149 ret = crypto_skcipher_setkey(tfm, template[i].key,
1150 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001151 if (template[i].fail == !ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001152 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001153 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001154 goto out;
1155 } else if (ret)
1156 continue;
1157
1158 sg_init_one(&sg[0], data, template[i].ilen);
1159 if (diff_dst) {
1160 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001161 data += align_offset;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001162 sg_init_one(&sgout[0], data, template[i].ilen);
1163 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001164
Herbert Xu12773d92015-08-20 15:21:46 +08001165 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1166 template[i].ilen, iv);
1167 ret = enc ? crypto_skcipher_encrypt(req) :
1168 crypto_skcipher_decrypt(req);
Herbert Xuda7f0332008-07-31 17:08:25 +08001169
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001170 switch (ret) {
1171 case 0:
1172 break;
1173 case -EINPROGRESS:
1174 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001175 wait_for_completion(&result.completion);
1176 reinit_completion(&result.completion);
1177 ret = result.err;
1178 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +08001179 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001180 /* fall through */
1181 default:
1182 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1183 d, e, j, algo, -ret);
1184 goto out;
1185 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001186
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001187 q = data;
1188 if (memcmp(q, template[i].result, template[i].rlen)) {
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001189 pr_err("alg: skcipher%s: Test %d failed (invalid result) on %s for %s\n",
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001190 d, j, e, algo);
1191 hexdump(q, template[i].rlen);
1192 ret = -EINVAL;
1193 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001194 }
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001195
1196 if (template[i].iv_out &&
1197 memcmp(iv, template[i].iv_out,
1198 crypto_skcipher_ivsize(tfm))) {
1199 pr_err("alg: skcipher%s: Test %d failed (invalid output IV) on %s for %s\n",
1200 d, j, e, algo);
1201 hexdump(iv, crypto_skcipher_ivsize(tfm));
1202 ret = -EINVAL;
1203 goto out;
1204 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001205 }
1206
1207 j = 0;
1208 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001209 /* alignment tests are only done with continuous buffers */
1210 if (align_offset != 0)
1211 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001212
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001213 if (!template[i].np)
1214 continue;
1215
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001216 if (fips_enabled && template[i].fips_skip)
1217 continue;
1218
Herbert Xuda7f0332008-07-31 17:08:25 +08001219 if (template[i].iv)
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001220 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001221 else
1222 memset(iv, 0, MAX_IVLEN);
1223
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001224 j++;
Herbert Xu12773d92015-08-20 15:21:46 +08001225 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001226 if (template[i].wk)
Herbert Xu12773d92015-08-20 15:21:46 +08001227 crypto_skcipher_set_flags(tfm,
1228 CRYPTO_TFM_REQ_WEAK_KEY);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001229
Herbert Xu12773d92015-08-20 15:21:46 +08001230 ret = crypto_skcipher_setkey(tfm, template[i].key,
1231 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001232 if (template[i].fail == !ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001233 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001234 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001235 goto out;
1236 } else if (ret)
1237 continue;
1238
1239 temp = 0;
1240 ret = -EINVAL;
1241 sg_init_table(sg, template[i].np);
1242 if (diff_dst)
1243 sg_init_table(sgout, template[i].np);
1244 for (k = 0; k < template[i].np; k++) {
1245 if (WARN_ON(offset_in_page(IDX[k]) +
1246 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001247 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001248
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001249 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1250
1251 memcpy(q, template[i].input + temp, template[i].tap[k]);
1252
1253 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1254 q[template[i].tap[k]] = 0;
1255
1256 sg_set_buf(&sg[k], q, template[i].tap[k]);
1257 if (diff_dst) {
1258 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1259 offset_in_page(IDX[k]);
1260
1261 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1262
1263 memset(q, 0, template[i].tap[k]);
1264 if (offset_in_page(q) +
1265 template[i].tap[k] < PAGE_SIZE)
1266 q[template[i].tap[k]] = 0;
1267 }
1268
1269 temp += template[i].tap[k];
1270 }
1271
Herbert Xu12773d92015-08-20 15:21:46 +08001272 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1273 template[i].ilen, iv);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001274
Herbert Xu12773d92015-08-20 15:21:46 +08001275 ret = enc ? crypto_skcipher_encrypt(req) :
1276 crypto_skcipher_decrypt(req);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001277
1278 switch (ret) {
1279 case 0:
1280 break;
1281 case -EINPROGRESS:
1282 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001283 wait_for_completion(&result.completion);
1284 reinit_completion(&result.completion);
1285 ret = result.err;
1286 if (!ret)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001287 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001288 /* fall through */
1289 default:
1290 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1291 d, e, j, algo, -ret);
1292 goto out;
1293 }
1294
1295 temp = 0;
1296 ret = -EINVAL;
1297 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001298 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001299 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1300 offset_in_page(IDX[k]);
1301 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001302 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1303 offset_in_page(IDX[k]);
1304
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001305 if (memcmp(q, template[i].result + temp,
1306 template[i].tap[k])) {
1307 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1308 d, j, e, k, algo);
1309 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001310 goto out;
1311 }
1312
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001313 q += template[i].tap[k];
1314 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1315 ;
1316 if (n) {
1317 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1318 d, j, e, k, algo, n);
1319 hexdump(q, n);
1320 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001321 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001322 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001323 }
1324 }
1325
1326 ret = 0;
1327
1328out:
Herbert Xu12773d92015-08-20 15:21:46 +08001329 skcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001330 if (diff_dst)
1331 testmgr_free_buf(xoutbuf);
1332out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001333 testmgr_free_buf(xbuf);
1334out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001335 return ret;
1336}
1337
Herbert Xu12773d92015-08-20 15:21:46 +08001338static int test_skcipher(struct crypto_skcipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001339 const struct cipher_testvec *template,
1340 unsigned int tcount)
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001341{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001342 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001343 int ret;
1344
1345 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001346 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001347 if (ret)
1348 return ret;
1349
1350 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001351 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1352 if (ret)
1353 return ret;
1354
1355 /* test unaligned buffers, check with one byte offset */
1356 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1357 if (ret)
1358 return ret;
1359
1360 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1361 if (alignmask) {
1362 /* Check if alignment mask for tfm is correctly set. */
1363 ret = __test_skcipher(tfm, enc, template, tcount, true,
1364 alignmask + 1);
1365 if (ret)
1366 return ret;
1367 }
1368
1369 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001370}
1371
Eric Biggersb13b1e02017-02-24 15:46:59 -08001372static int test_comp(struct crypto_comp *tfm,
1373 const struct comp_testvec *ctemplate,
1374 const struct comp_testvec *dtemplate,
1375 int ctcount, int dtcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08001376{
1377 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1378 unsigned int i;
1379 char result[COMP_BUF_SIZE];
1380 int ret;
1381
1382 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001383 int ilen;
1384 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001385
1386 memset(result, 0, sizeof (result));
1387
1388 ilen = ctemplate[i].inlen;
1389 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1390 ilen, result, &dlen);
1391 if (ret) {
1392 printk(KERN_ERR "alg: comp: compression failed "
1393 "on test %d for %s: ret=%d\n", i + 1, algo,
1394 -ret);
1395 goto out;
1396 }
1397
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001398 if (dlen != ctemplate[i].outlen) {
1399 printk(KERN_ERR "alg: comp: Compression test %d "
1400 "failed for %s: output len = %d\n", i + 1, algo,
1401 dlen);
1402 ret = -EINVAL;
1403 goto out;
1404 }
1405
Herbert Xuda7f0332008-07-31 17:08:25 +08001406 if (memcmp(result, ctemplate[i].output, dlen)) {
1407 printk(KERN_ERR "alg: comp: Compression test %d "
1408 "failed for %s\n", i + 1, algo);
1409 hexdump(result, dlen);
1410 ret = -EINVAL;
1411 goto out;
1412 }
1413 }
1414
1415 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001416 int ilen;
1417 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001418
1419 memset(result, 0, sizeof (result));
1420
1421 ilen = dtemplate[i].inlen;
1422 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1423 ilen, result, &dlen);
1424 if (ret) {
1425 printk(KERN_ERR "alg: comp: decompression failed "
1426 "on test %d for %s: ret=%d\n", i + 1, algo,
1427 -ret);
1428 goto out;
1429 }
1430
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001431 if (dlen != dtemplate[i].outlen) {
1432 printk(KERN_ERR "alg: comp: Decompression test %d "
1433 "failed for %s: output len = %d\n", i + 1, algo,
1434 dlen);
1435 ret = -EINVAL;
1436 goto out;
1437 }
1438
Herbert Xuda7f0332008-07-31 17:08:25 +08001439 if (memcmp(result, dtemplate[i].output, dlen)) {
1440 printk(KERN_ERR "alg: comp: Decompression test %d "
1441 "failed for %s\n", i + 1, algo);
1442 hexdump(result, dlen);
1443 ret = -EINVAL;
1444 goto out;
1445 }
1446 }
1447
1448 ret = 0;
1449
1450out:
1451 return ret;
1452}
1453
Eric Biggersb13b1e02017-02-24 15:46:59 -08001454static int test_acomp(struct crypto_acomp *tfm,
1455 const struct comp_testvec *ctemplate,
1456 const struct comp_testvec *dtemplate,
1457 int ctcount, int dtcount)
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001458{
1459 const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
1460 unsigned int i;
Eric Biggerseb095592016-11-23 10:24:35 -08001461 char *output;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001462 int ret;
1463 struct scatterlist src, dst;
1464 struct acomp_req *req;
1465 struct tcrypt_result result;
1466
Eric Biggerseb095592016-11-23 10:24:35 -08001467 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1468 if (!output)
1469 return -ENOMEM;
1470
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001471 for (i = 0; i < ctcount; i++) {
1472 unsigned int dlen = COMP_BUF_SIZE;
1473 int ilen = ctemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08001474 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001475
Eric Biggersd2110222016-12-30 14:12:00 -06001476 input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08001477 if (!input_vec) {
1478 ret = -ENOMEM;
1479 goto out;
1480 }
1481
Eric Biggerseb095592016-11-23 10:24:35 -08001482 memset(output, 0, dlen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001483 init_completion(&result.completion);
Laura Abbott02608e02016-12-21 12:32:54 -08001484 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001485 sg_init_one(&dst, output, dlen);
1486
1487 req = acomp_request_alloc(tfm);
1488 if (!req) {
1489 pr_err("alg: acomp: request alloc failed for %s\n",
1490 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08001491 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001492 ret = -ENOMEM;
1493 goto out;
1494 }
1495
1496 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1497 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1498 tcrypt_complete, &result);
1499
1500 ret = wait_async_op(&result, crypto_acomp_compress(req));
1501 if (ret) {
1502 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
1503 i + 1, algo, -ret);
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 (req->dlen != ctemplate[i].outlen) {
1510 pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
1511 i + 1, algo, req->dlen);
1512 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001513 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001514 acomp_request_free(req);
1515 goto out;
1516 }
1517
1518 if (memcmp(output, ctemplate[i].output, req->dlen)) {
1519 pr_err("alg: acomp: Compression test %d failed for %s\n",
1520 i + 1, algo);
1521 hexdump(output, req->dlen);
1522 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001523 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001524 acomp_request_free(req);
1525 goto out;
1526 }
1527
Laura Abbott02608e02016-12-21 12:32:54 -08001528 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001529 acomp_request_free(req);
1530 }
1531
1532 for (i = 0; i < dtcount; i++) {
1533 unsigned int dlen = COMP_BUF_SIZE;
1534 int ilen = dtemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08001535 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001536
Eric Biggersd2110222016-12-30 14:12:00 -06001537 input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08001538 if (!input_vec) {
1539 ret = -ENOMEM;
1540 goto out;
1541 }
1542
Eric Biggerseb095592016-11-23 10:24:35 -08001543 memset(output, 0, dlen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001544 init_completion(&result.completion);
Laura Abbott02608e02016-12-21 12:32:54 -08001545 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001546 sg_init_one(&dst, output, dlen);
1547
1548 req = acomp_request_alloc(tfm);
1549 if (!req) {
1550 pr_err("alg: acomp: request alloc failed for %s\n",
1551 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08001552 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001553 ret = -ENOMEM;
1554 goto out;
1555 }
1556
1557 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1558 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1559 tcrypt_complete, &result);
1560
1561 ret = wait_async_op(&result, crypto_acomp_decompress(req));
1562 if (ret) {
1563 pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
1564 i + 1, algo, -ret);
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 (req->dlen != dtemplate[i].outlen) {
1571 pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
1572 i + 1, algo, req->dlen);
1573 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001574 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001575 acomp_request_free(req);
1576 goto out;
1577 }
1578
1579 if (memcmp(output, dtemplate[i].output, req->dlen)) {
1580 pr_err("alg: acomp: Decompression test %d failed for %s\n",
1581 i + 1, algo);
1582 hexdump(output, req->dlen);
1583 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001584 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001585 acomp_request_free(req);
1586 goto out;
1587 }
1588
Laura Abbott02608e02016-12-21 12:32:54 -08001589 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001590 acomp_request_free(req);
1591 }
1592
1593 ret = 0;
1594
1595out:
Eric Biggerseb095592016-11-23 10:24:35 -08001596 kfree(output);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001597 return ret;
1598}
1599
Eric Biggersb13b1e02017-02-24 15:46:59 -08001600static int test_cprng(struct crypto_rng *tfm,
1601 const struct cprng_testvec *template,
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001602 unsigned int tcount)
1603{
1604 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001605 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001606 u8 *seed;
1607 char result[32];
1608
1609 seedsize = crypto_rng_seedsize(tfm);
1610
1611 seed = kmalloc(seedsize, GFP_KERNEL);
1612 if (!seed) {
1613 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1614 "for %s\n", algo);
1615 return -ENOMEM;
1616 }
1617
1618 for (i = 0; i < tcount; i++) {
1619 memset(result, 0, 32);
1620
1621 memcpy(seed, template[i].v, template[i].vlen);
1622 memcpy(seed + template[i].vlen, template[i].key,
1623 template[i].klen);
1624 memcpy(seed + template[i].vlen + template[i].klen,
1625 template[i].dt, template[i].dtlen);
1626
1627 err = crypto_rng_reset(tfm, seed, seedsize);
1628 if (err) {
1629 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1630 "for %s\n", algo);
1631 goto out;
1632 }
1633
1634 for (j = 0; j < template[i].loops; j++) {
1635 err = crypto_rng_get_bytes(tfm, result,
1636 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01001637 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001638 printk(KERN_ERR "alg: cprng: Failed to obtain "
1639 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01001640 "%s (requested %d)\n", algo,
1641 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001642 goto out;
1643 }
1644 }
1645
1646 err = memcmp(result, template[i].result,
1647 template[i].rlen);
1648 if (err) {
1649 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1650 i, algo);
1651 hexdump(result, template[i].rlen);
1652 err = -EINVAL;
1653 goto out;
1654 }
1655 }
1656
1657out:
1658 kfree(seed);
1659 return err;
1660}
1661
Herbert Xuda7f0332008-07-31 17:08:25 +08001662static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1663 u32 type, u32 mask)
1664{
1665 struct crypto_aead *tfm;
1666 int err = 0;
1667
Herbert Xueed93e02016-11-22 20:08:31 +08001668 tfm = crypto_alloc_aead(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001669 if (IS_ERR(tfm)) {
1670 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1671 "%ld\n", driver, PTR_ERR(tfm));
1672 return PTR_ERR(tfm);
1673 }
1674
1675 if (desc->suite.aead.enc.vecs) {
1676 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1677 desc->suite.aead.enc.count);
1678 if (err)
1679 goto out;
1680 }
1681
1682 if (!err && desc->suite.aead.dec.vecs)
1683 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1684 desc->suite.aead.dec.count);
1685
1686out:
1687 crypto_free_aead(tfm);
1688 return err;
1689}
1690
1691static int alg_test_cipher(const struct alg_test_desc *desc,
1692 const char *driver, u32 type, u32 mask)
1693{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001694 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001695 int err = 0;
1696
Herbert Xueed93e02016-11-22 20:08:31 +08001697 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001698 if (IS_ERR(tfm)) {
1699 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1700 "%s: %ld\n", driver, PTR_ERR(tfm));
1701 return PTR_ERR(tfm);
1702 }
1703
1704 if (desc->suite.cipher.enc.vecs) {
1705 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1706 desc->suite.cipher.enc.count);
1707 if (err)
1708 goto out;
1709 }
1710
1711 if (desc->suite.cipher.dec.vecs)
1712 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1713 desc->suite.cipher.dec.count);
1714
1715out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001716 crypto_free_cipher(tfm);
1717 return err;
1718}
1719
1720static int alg_test_skcipher(const struct alg_test_desc *desc,
1721 const char *driver, u32 type, u32 mask)
1722{
Herbert Xu12773d92015-08-20 15:21:46 +08001723 struct crypto_skcipher *tfm;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001724 int err = 0;
1725
Herbert Xueed93e02016-11-22 20:08:31 +08001726 tfm = crypto_alloc_skcipher(driver, type, mask);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001727 if (IS_ERR(tfm)) {
1728 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1729 "%s: %ld\n", driver, PTR_ERR(tfm));
1730 return PTR_ERR(tfm);
1731 }
1732
1733 if (desc->suite.cipher.enc.vecs) {
1734 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1735 desc->suite.cipher.enc.count);
1736 if (err)
1737 goto out;
1738 }
1739
1740 if (desc->suite.cipher.dec.vecs)
1741 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1742 desc->suite.cipher.dec.count);
1743
1744out:
Herbert Xu12773d92015-08-20 15:21:46 +08001745 crypto_free_skcipher(tfm);
Herbert Xuda7f0332008-07-31 17:08:25 +08001746 return err;
1747}
1748
1749static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1750 u32 type, u32 mask)
1751{
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001752 struct crypto_comp *comp;
1753 struct crypto_acomp *acomp;
Herbert Xuda7f0332008-07-31 17:08:25 +08001754 int err;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001755 u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
Herbert Xuda7f0332008-07-31 17:08:25 +08001756
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001757 if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
1758 acomp = crypto_alloc_acomp(driver, type, mask);
1759 if (IS_ERR(acomp)) {
1760 pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
1761 driver, PTR_ERR(acomp));
1762 return PTR_ERR(acomp);
1763 }
1764 err = test_acomp(acomp, desc->suite.comp.comp.vecs,
1765 desc->suite.comp.decomp.vecs,
1766 desc->suite.comp.comp.count,
1767 desc->suite.comp.decomp.count);
1768 crypto_free_acomp(acomp);
1769 } else {
1770 comp = crypto_alloc_comp(driver, type, mask);
1771 if (IS_ERR(comp)) {
1772 pr_err("alg: comp: Failed to load transform for %s: %ld\n",
1773 driver, PTR_ERR(comp));
1774 return PTR_ERR(comp);
1775 }
1776
1777 err = test_comp(comp, desc->suite.comp.comp.vecs,
1778 desc->suite.comp.decomp.vecs,
1779 desc->suite.comp.comp.count,
1780 desc->suite.comp.decomp.count);
1781
1782 crypto_free_comp(comp);
Herbert Xuda7f0332008-07-31 17:08:25 +08001783 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001784 return err;
1785}
1786
1787static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1788 u32 type, u32 mask)
1789{
1790 struct crypto_ahash *tfm;
1791 int err;
1792
Herbert Xueed93e02016-11-22 20:08:31 +08001793 tfm = crypto_alloc_ahash(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001794 if (IS_ERR(tfm)) {
1795 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1796 "%ld\n", driver, PTR_ERR(tfm));
1797 return PTR_ERR(tfm);
1798 }
1799
David S. Millera8f1a052010-05-19 14:12:03 +10001800 err = test_hash(tfm, desc->suite.hash.vecs,
1801 desc->suite.hash.count, true);
1802 if (!err)
1803 err = test_hash(tfm, desc->suite.hash.vecs,
1804 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001805
1806 crypto_free_ahash(tfm);
1807 return err;
1808}
1809
Herbert Xu8e3ee852008-11-07 14:58:52 +08001810static int alg_test_crc32c(const struct alg_test_desc *desc,
1811 const char *driver, u32 type, u32 mask)
1812{
1813 struct crypto_shash *tfm;
1814 u32 val;
1815 int err;
1816
1817 err = alg_test_hash(desc, driver, type, mask);
1818 if (err)
1819 goto out;
1820
Herbert Xueed93e02016-11-22 20:08:31 +08001821 tfm = crypto_alloc_shash(driver, type, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001822 if (IS_ERR(tfm)) {
1823 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1824 "%ld\n", driver, PTR_ERR(tfm));
1825 err = PTR_ERR(tfm);
1826 goto out;
1827 }
1828
1829 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001830 SHASH_DESC_ON_STACK(shash, tfm);
1831 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001832
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001833 shash->tfm = tfm;
1834 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001835
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001836 *ctx = le32_to_cpu(420553207);
1837 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001838 if (err) {
1839 printk(KERN_ERR "alg: crc32c: Operation failed for "
1840 "%s: %d\n", driver, err);
1841 break;
1842 }
1843
1844 if (val != ~420553207) {
1845 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1846 "%d\n", driver, val);
1847 err = -EINVAL;
1848 }
1849 } while (0);
1850
1851 crypto_free_shash(tfm);
1852
1853out:
1854 return err;
1855}
1856
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001857static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1858 u32 type, u32 mask)
1859{
1860 struct crypto_rng *rng;
1861 int err;
1862
Herbert Xueed93e02016-11-22 20:08:31 +08001863 rng = crypto_alloc_rng(driver, type, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001864 if (IS_ERR(rng)) {
1865 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1866 "%ld\n", driver, PTR_ERR(rng));
1867 return PTR_ERR(rng);
1868 }
1869
1870 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1871
1872 crypto_free_rng(rng);
1873
1874 return err;
1875}
1876
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001877
Eric Biggersb13b1e02017-02-24 15:46:59 -08001878static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001879 const char *driver, u32 type, u32 mask)
1880{
1881 int ret = -EAGAIN;
1882 struct crypto_rng *drng;
1883 struct drbg_test_data test_data;
1884 struct drbg_string addtl, pers, testentropy;
1885 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1886
1887 if (!buf)
1888 return -ENOMEM;
1889
Herbert Xueed93e02016-11-22 20:08:31 +08001890 drng = crypto_alloc_rng(driver, type, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001891 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001892 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001893 "%s\n", driver);
1894 kzfree(buf);
1895 return -ENOMEM;
1896 }
1897
1898 test_data.testentropy = &testentropy;
1899 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1900 drbg_string_fill(&pers, test->pers, test->perslen);
1901 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1902 if (ret) {
1903 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1904 goto outbuf;
1905 }
1906
1907 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1908 if (pr) {
1909 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1910 ret = crypto_drbg_get_bytes_addtl_test(drng,
1911 buf, test->expectedlen, &addtl, &test_data);
1912 } else {
1913 ret = crypto_drbg_get_bytes_addtl(drng,
1914 buf, test->expectedlen, &addtl);
1915 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001916 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001917 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001918 "driver %s\n", driver);
1919 goto outbuf;
1920 }
1921
1922 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1923 if (pr) {
1924 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1925 ret = crypto_drbg_get_bytes_addtl_test(drng,
1926 buf, test->expectedlen, &addtl, &test_data);
1927 } else {
1928 ret = crypto_drbg_get_bytes_addtl(drng,
1929 buf, test->expectedlen, &addtl);
1930 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001931 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001932 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001933 "driver %s\n", driver);
1934 goto outbuf;
1935 }
1936
1937 ret = memcmp(test->expected, buf, test->expectedlen);
1938
1939outbuf:
1940 crypto_free_rng(drng);
1941 kzfree(buf);
1942 return ret;
1943}
1944
1945
1946static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1947 u32 type, u32 mask)
1948{
1949 int err = 0;
1950 int pr = 0;
1951 int i = 0;
Eric Biggersb13b1e02017-02-24 15:46:59 -08001952 const struct drbg_testvec *template = desc->suite.drbg.vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001953 unsigned int tcount = desc->suite.drbg.count;
1954
1955 if (0 == memcmp(driver, "drbg_pr_", 8))
1956 pr = 1;
1957
1958 for (i = 0; i < tcount; i++) {
1959 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1960 if (err) {
1961 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1962 i, driver);
1963 err = -EINVAL;
1964 break;
1965 }
1966 }
1967 return err;
1968
1969}
1970
Eric Biggersb13b1e02017-02-24 15:46:59 -08001971static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01001972 const char *alg)
1973{
1974 struct kpp_request *req;
1975 void *input_buf = NULL;
1976 void *output_buf = NULL;
1977 struct tcrypt_result result;
1978 unsigned int out_len_max;
1979 int err = -ENOMEM;
1980 struct scatterlist src, dst;
1981
1982 req = kpp_request_alloc(tfm, GFP_KERNEL);
1983 if (!req)
1984 return err;
1985
1986 init_completion(&result.completion);
1987
1988 err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
1989 if (err < 0)
1990 goto free_req;
1991
1992 out_len_max = crypto_kpp_maxsize(tfm);
1993 output_buf = kzalloc(out_len_max, GFP_KERNEL);
1994 if (!output_buf) {
1995 err = -ENOMEM;
1996 goto free_req;
1997 }
1998
1999 /* Use appropriate parameter as base */
2000 kpp_request_set_input(req, NULL, 0);
2001 sg_init_one(&dst, output_buf, out_len_max);
2002 kpp_request_set_output(req, &dst, out_len_max);
2003 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
2004 tcrypt_complete, &result);
2005
2006 /* Compute public key */
2007 err = wait_async_op(&result, crypto_kpp_generate_public_key(req));
2008 if (err) {
2009 pr_err("alg: %s: generate public key test failed. err %d\n",
2010 alg, err);
2011 goto free_output;
2012 }
2013 /* Verify calculated public key */
2014 if (memcmp(vec->expected_a_public, sg_virt(req->dst),
2015 vec->expected_a_public_size)) {
2016 pr_err("alg: %s: generate public key test failed. Invalid output\n",
2017 alg);
2018 err = -EINVAL;
2019 goto free_output;
2020 }
2021
2022 /* Calculate shared secret key by using counter part (b) public key. */
2023 input_buf = kzalloc(vec->b_public_size, GFP_KERNEL);
2024 if (!input_buf) {
2025 err = -ENOMEM;
2026 goto free_output;
2027 }
2028
2029 memcpy(input_buf, vec->b_public, vec->b_public_size);
2030 sg_init_one(&src, input_buf, vec->b_public_size);
2031 sg_init_one(&dst, output_buf, out_len_max);
2032 kpp_request_set_input(req, &src, vec->b_public_size);
2033 kpp_request_set_output(req, &dst, out_len_max);
2034 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
2035 tcrypt_complete, &result);
2036 err = wait_async_op(&result, crypto_kpp_compute_shared_secret(req));
2037 if (err) {
2038 pr_err("alg: %s: compute shard secret test failed. err %d\n",
2039 alg, err);
2040 goto free_all;
2041 }
2042 /*
2043 * verify shared secret from which the user will derive
2044 * secret key by executing whatever hash it has chosen
2045 */
2046 if (memcmp(vec->expected_ss, sg_virt(req->dst),
2047 vec->expected_ss_size)) {
2048 pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
2049 alg);
2050 err = -EINVAL;
2051 }
2052
2053free_all:
2054 kfree(input_buf);
2055free_output:
2056 kfree(output_buf);
2057free_req:
2058 kpp_request_free(req);
2059 return err;
2060}
2061
2062static int test_kpp(struct crypto_kpp *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002063 const struct kpp_testvec *vecs, unsigned int tcount)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002064{
2065 int ret, i;
2066
2067 for (i = 0; i < tcount; i++) {
2068 ret = do_test_kpp(tfm, vecs++, alg);
2069 if (ret) {
2070 pr_err("alg: %s: test failed on vector %d, err=%d\n",
2071 alg, i + 1, ret);
2072 return ret;
2073 }
2074 }
2075 return 0;
2076}
2077
2078static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
2079 u32 type, u32 mask)
2080{
2081 struct crypto_kpp *tfm;
2082 int err = 0;
2083
Herbert Xueed93e02016-11-22 20:08:31 +08002084 tfm = crypto_alloc_kpp(driver, type, mask);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002085 if (IS_ERR(tfm)) {
2086 pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
2087 driver, PTR_ERR(tfm));
2088 return PTR_ERR(tfm);
2089 }
2090 if (desc->suite.kpp.vecs)
2091 err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
2092 desc->suite.kpp.count);
2093
2094 crypto_free_kpp(tfm);
2095 return err;
2096}
2097
Herbert Xu50d2b6432016-06-29 19:32:20 +08002098static int test_akcipher_one(struct crypto_akcipher *tfm,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002099 const struct akcipher_testvec *vecs)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002100{
Herbert Xudf27b262016-05-05 16:42:49 +08002101 char *xbuf[XBUFSIZE];
Tadeusz Struk946cc462015-06-16 10:31:06 -07002102 struct akcipher_request *req;
2103 void *outbuf_enc = NULL;
2104 void *outbuf_dec = NULL;
2105 struct tcrypt_result result;
2106 unsigned int out_len_max, out_len = 0;
2107 int err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002108 struct scatterlist src, dst, src_tab[2];
Tadeusz Struk946cc462015-06-16 10:31:06 -07002109
Herbert Xudf27b262016-05-05 16:42:49 +08002110 if (testmgr_alloc_buf(xbuf))
2111 return err;
2112
Tadeusz Struk946cc462015-06-16 10:31:06 -07002113 req = akcipher_request_alloc(tfm, GFP_KERNEL);
2114 if (!req)
Herbert Xudf27b262016-05-05 16:42:49 +08002115 goto free_xbuf;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002116
2117 init_completion(&result.completion);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002118
2119 if (vecs->public_key_vec)
2120 err = crypto_akcipher_set_pub_key(tfm, vecs->key,
2121 vecs->key_len);
2122 else
2123 err = crypto_akcipher_set_priv_key(tfm, vecs->key,
2124 vecs->key_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002125 if (err)
2126 goto free_req;
2127
Salvatore Benedetto57763f52016-07-04 10:52:34 +01002128 err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002129 out_len_max = crypto_akcipher_maxsize(tfm);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002130 outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
2131 if (!outbuf_enc)
2132 goto free_req;
2133
Herbert Xudf27b262016-05-05 16:42:49 +08002134 if (WARN_ON(vecs->m_size > PAGE_SIZE))
2135 goto free_all;
2136
2137 memcpy(xbuf[0], vecs->m, vecs->m_size);
2138
Tadeusz Struk22287b02015-10-08 09:26:55 -07002139 sg_init_table(src_tab, 2);
Herbert Xudf27b262016-05-05 16:42:49 +08002140 sg_set_buf(&src_tab[0], xbuf[0], 8);
2141 sg_set_buf(&src_tab[1], xbuf[0] + 8, vecs->m_size - 8);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002142 sg_init_one(&dst, outbuf_enc, out_len_max);
2143 akcipher_request_set_crypt(req, src_tab, &dst, vecs->m_size,
2144 out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002145 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
2146 tcrypt_complete, &result);
2147
2148 /* Run RSA encrypt - c = m^e mod n;*/
2149 err = wait_async_op(&result, crypto_akcipher_encrypt(req));
2150 if (err) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002151 pr_err("alg: akcipher: encrypt test failed. err %d\n", err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002152 goto free_all;
2153 }
Tadeusz Struk22287b02015-10-08 09:26:55 -07002154 if (req->dst_len != vecs->c_size) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002155 pr_err("alg: akcipher: encrypt test failed. Invalid output len\n");
Tadeusz Struk946cc462015-06-16 10:31:06 -07002156 err = -EINVAL;
2157 goto free_all;
2158 }
2159 /* verify that encrypted message is equal to expected */
Herbert Xudf27b262016-05-05 16:42:49 +08002160 if (memcmp(vecs->c, outbuf_enc, vecs->c_size)) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002161 pr_err("alg: akcipher: encrypt test failed. Invalid output\n");
2162 hexdump(outbuf_enc, vecs->c_size);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002163 err = -EINVAL;
2164 goto free_all;
2165 }
2166 /* Don't invoke decrypt for vectors with public key */
2167 if (vecs->public_key_vec) {
2168 err = 0;
2169 goto free_all;
2170 }
2171 outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
2172 if (!outbuf_dec) {
2173 err = -ENOMEM;
2174 goto free_all;
2175 }
Herbert Xudf27b262016-05-05 16:42:49 +08002176
2177 if (WARN_ON(vecs->c_size > PAGE_SIZE))
2178 goto free_all;
2179
2180 memcpy(xbuf[0], vecs->c, vecs->c_size);
2181
2182 sg_init_one(&src, xbuf[0], vecs->c_size);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002183 sg_init_one(&dst, outbuf_dec, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002184 init_completion(&result.completion);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002185 akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002186
2187 /* Run RSA decrypt - m = c^d mod n;*/
2188 err = wait_async_op(&result, crypto_akcipher_decrypt(req));
2189 if (err) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002190 pr_err("alg: akcipher: decrypt test failed. err %d\n", err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002191 goto free_all;
2192 }
2193 out_len = req->dst_len;
Herbert Xu50d2b6432016-06-29 19:32:20 +08002194 if (out_len < vecs->m_size) {
2195 pr_err("alg: akcipher: decrypt test failed. "
2196 "Invalid output len %u\n", out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002197 err = -EINVAL;
2198 goto free_all;
2199 }
2200 /* verify that decrypted message is equal to the original msg */
Herbert Xu50d2b6432016-06-29 19:32:20 +08002201 if (memchr_inv(outbuf_dec, 0, out_len - vecs->m_size) ||
2202 memcmp(vecs->m, outbuf_dec + out_len - vecs->m_size,
2203 vecs->m_size)) {
2204 pr_err("alg: akcipher: decrypt test failed. Invalid output\n");
2205 hexdump(outbuf_dec, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002206 err = -EINVAL;
2207 }
2208free_all:
2209 kfree(outbuf_dec);
2210 kfree(outbuf_enc);
2211free_req:
2212 akcipher_request_free(req);
Herbert Xudf27b262016-05-05 16:42:49 +08002213free_xbuf:
2214 testmgr_free_buf(xbuf);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002215 return err;
2216}
2217
Herbert Xu50d2b6432016-06-29 19:32:20 +08002218static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002219 const struct akcipher_testvec *vecs,
2220 unsigned int tcount)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002221{
Herbert Xu15226e42016-07-18 18:20:10 +08002222 const char *algo =
2223 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
Tadeusz Struk946cc462015-06-16 10:31:06 -07002224 int ret, i;
2225
2226 for (i = 0; i < tcount; i++) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002227 ret = test_akcipher_one(tfm, vecs++);
2228 if (!ret)
2229 continue;
2230
Herbert Xu15226e42016-07-18 18:20:10 +08002231 pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
2232 i + 1, algo, ret);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002233 return ret;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002234 }
2235 return 0;
2236}
2237
Tadeusz Struk946cc462015-06-16 10:31:06 -07002238static int alg_test_akcipher(const struct alg_test_desc *desc,
2239 const char *driver, u32 type, u32 mask)
2240{
2241 struct crypto_akcipher *tfm;
2242 int err = 0;
2243
Herbert Xueed93e02016-11-22 20:08:31 +08002244 tfm = crypto_alloc_akcipher(driver, type, mask);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002245 if (IS_ERR(tfm)) {
2246 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
2247 driver, PTR_ERR(tfm));
2248 return PTR_ERR(tfm);
2249 }
2250 if (desc->suite.akcipher.vecs)
2251 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
2252 desc->suite.akcipher.count);
2253
2254 crypto_free_akcipher(tfm);
2255 return err;
2256}
2257
Youquan, Song863b5572009-12-23 19:45:20 +08002258static int alg_test_null(const struct alg_test_desc *desc,
2259 const char *driver, u32 type, u32 mask)
2260{
2261 return 0;
2262}
2263
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002264#define __VECS(tv) { .vecs = tv, .count = ARRAY_SIZE(tv) }
2265
Herbert Xuda7f0332008-07-31 17:08:25 +08002266/* Please keep this list sorted by algorithm name. */
2267static const struct alg_test_desc alg_test_descs[] = {
2268 {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002269 .alg = "ansi_cprng",
2270 .test = alg_test_cprng,
2271 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002272 .cprng = __VECS(ansi_cprng_aes_tv_template)
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002273 }
2274 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002275 .alg = "authenc(hmac(md5),ecb(cipher_null))",
2276 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002277 .suite = {
2278 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002279 .enc = __VECS(hmac_md5_ecb_cipher_null_enc_tv_template),
2280 .dec = __VECS(hmac_md5_ecb_cipher_null_dec_tv_template)
Horia Geantabca4feb2014-03-14 17:46:51 +02002281 }
2282 }
2283 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002284 .alg = "authenc(hmac(sha1),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002285 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002286 .suite = {
2287 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002288 .enc = __VECS(hmac_sha1_aes_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302289 }
2290 }
2291 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002292 .alg = "authenc(hmac(sha1),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302293 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302294 .suite = {
2295 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002296 .enc = __VECS(hmac_sha1_des_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302297 }
2298 }
2299 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002300 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302301 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002302 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302303 .suite = {
2304 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002305 .enc = __VECS(hmac_sha1_des3_ede_cbc_enc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002306 }
2307 }
2308 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002309 .alg = "authenc(hmac(sha1),ctr(aes))",
2310 .test = alg_test_null,
2311 .fips_allowed = 1,
2312 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002313 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
2314 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002315 .suite = {
2316 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002317 .enc = __VECS(hmac_sha1_ecb_cipher_null_enc_tv_temp),
2318 .dec = __VECS(hmac_sha1_ecb_cipher_null_dec_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302319 }
2320 }
2321 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002322 .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
2323 .test = alg_test_null,
2324 .fips_allowed = 1,
2325 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002326 .alg = "authenc(hmac(sha224),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302327 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302328 .suite = {
2329 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002330 .enc = __VECS(hmac_sha224_des_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302331 }
2332 }
2333 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002334 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302335 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002336 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302337 .suite = {
2338 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002339 .enc = __VECS(hmac_sha224_des3_ede_cbc_enc_tv_temp)
Horia Geantabca4feb2014-03-14 17:46:51 +02002340 }
2341 }
2342 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002343 .alg = "authenc(hmac(sha256),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002344 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002345 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002346 .suite = {
2347 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002348 .enc = __VECS(hmac_sha256_aes_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302349 }
2350 }
2351 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002352 .alg = "authenc(hmac(sha256),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302353 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302354 .suite = {
2355 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002356 .enc = __VECS(hmac_sha256_des_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302357 }
2358 }
2359 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002360 .alg = "authenc(hmac(sha256),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 = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002365 .enc = __VECS(hmac_sha256_des3_ede_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302366 }
2367 }
2368 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002369 .alg = "authenc(hmac(sha256),ctr(aes))",
2370 .test = alg_test_null,
2371 .fips_allowed = 1,
2372 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002373 .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
2374 .test = alg_test_null,
2375 .fips_allowed = 1,
2376 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002377 .alg = "authenc(hmac(sha384),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302378 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302379 .suite = {
2380 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002381 .enc = __VECS(hmac_sha384_des_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302382 }
2383 }
2384 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002385 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302386 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002387 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302388 .suite = {
2389 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002390 .enc = __VECS(hmac_sha384_des3_ede_cbc_enc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002391 }
2392 }
2393 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002394 .alg = "authenc(hmac(sha384),ctr(aes))",
2395 .test = alg_test_null,
2396 .fips_allowed = 1,
2397 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002398 .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
2399 .test = alg_test_null,
2400 .fips_allowed = 1,
2401 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002402 .alg = "authenc(hmac(sha512),cbc(aes))",
Marcus Meissnered1afac2016-02-05 14:23:33 +01002403 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002404 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002405 .suite = {
2406 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002407 .enc = __VECS(hmac_sha512_aes_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302408 }
2409 }
2410 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002411 .alg = "authenc(hmac(sha512),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302412 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302413 .suite = {
2414 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002415 .enc = __VECS(hmac_sha512_des_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302416 }
2417 }
2418 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002419 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302420 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002421 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302422 .suite = {
2423 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002424 .enc = __VECS(hmac_sha512_des3_ede_cbc_enc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002425 }
2426 }
2427 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002428 .alg = "authenc(hmac(sha512),ctr(aes))",
2429 .test = alg_test_null,
2430 .fips_allowed = 1,
2431 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002432 .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
2433 .test = alg_test_null,
2434 .fips_allowed = 1,
2435 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002436 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002437 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002438 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002439 .suite = {
2440 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002441 .enc = __VECS(aes_cbc_enc_tv_template),
2442 .dec = __VECS(aes_cbc_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002443 }
2444 }
2445 }, {
2446 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002447 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002448 .suite = {
2449 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002450 .enc = __VECS(anubis_cbc_enc_tv_template),
2451 .dec = __VECS(anubis_cbc_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002452 }
2453 }
2454 }, {
2455 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002456 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002457 .suite = {
2458 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002459 .enc = __VECS(bf_cbc_enc_tv_template),
2460 .dec = __VECS(bf_cbc_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002461 }
2462 }
2463 }, {
2464 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002465 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002466 .suite = {
2467 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002468 .enc = __VECS(camellia_cbc_enc_tv_template),
2469 .dec = __VECS(camellia_cbc_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002470 }
2471 }
2472 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002473 .alg = "cbc(cast5)",
2474 .test = alg_test_skcipher,
2475 .suite = {
2476 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002477 .enc = __VECS(cast5_cbc_enc_tv_template),
2478 .dec = __VECS(cast5_cbc_dec_tv_template)
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002479 }
2480 }
2481 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002482 .alg = "cbc(cast6)",
2483 .test = alg_test_skcipher,
2484 .suite = {
2485 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002486 .enc = __VECS(cast6_cbc_enc_tv_template),
2487 .dec = __VECS(cast6_cbc_dec_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002488 }
2489 }
2490 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002491 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002492 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002493 .suite = {
2494 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002495 .enc = __VECS(des_cbc_enc_tv_template),
2496 .dec = __VECS(des_cbc_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002497 }
2498 }
2499 }, {
2500 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002501 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002502 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002503 .suite = {
2504 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002505 .enc = __VECS(des3_ede_cbc_enc_tv_template),
2506 .dec = __VECS(des3_ede_cbc_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002507 }
2508 }
2509 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002510 .alg = "cbc(serpent)",
2511 .test = alg_test_skcipher,
2512 .suite = {
2513 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002514 .enc = __VECS(serpent_cbc_enc_tv_template),
2515 .dec = __VECS(serpent_cbc_dec_tv_template)
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002516 }
2517 }
2518 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002519 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002520 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002521 .suite = {
2522 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002523 .enc = __VECS(tf_cbc_enc_tv_template),
2524 .dec = __VECS(tf_cbc_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002525 }
2526 }
2527 }, {
Ard Biesheuvel092acf02017-02-03 14:49:35 +00002528 .alg = "cbcmac(aes)",
2529 .fips_allowed = 1,
2530 .test = alg_test_hash,
2531 .suite = {
2532 .hash = __VECS(aes_cbcmac_tv_template)
2533 }
2534 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002535 .alg = "ccm(aes)",
2536 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002537 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002538 .suite = {
2539 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002540 .enc = __VECS(aes_ccm_enc_tv_template),
2541 .dec = __VECS(aes_ccm_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002542 }
2543 }
2544 }, {
Martin Willi3590ebf2015-06-01 13:43:57 +02002545 .alg = "chacha20",
2546 .test = alg_test_skcipher,
2547 .suite = {
2548 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002549 .enc = __VECS(chacha20_enc_tv_template),
2550 .dec = __VECS(chacha20_enc_tv_template),
Martin Willi3590ebf2015-06-01 13:43:57 +02002551 }
2552 }
2553 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002554 .alg = "cmac(aes)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002555 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002556 .test = alg_test_hash,
2557 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002558 .hash = __VECS(aes_cmac128_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002559 }
2560 }, {
2561 .alg = "cmac(des3_ede)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002562 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002563 .test = alg_test_hash,
2564 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002565 .hash = __VECS(des3_ede_cmac64_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002566 }
2567 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002568 .alg = "compress_null",
2569 .test = alg_test_null,
2570 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02002571 .alg = "crc32",
2572 .test = alg_test_hash,
2573 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002574 .hash = __VECS(crc32_tv_template)
Ard Biesheuvelebb34722015-05-04 11:00:17 +02002575 }
2576 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002577 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002578 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002579 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002580 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002581 .hash = __VECS(crc32c_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002582 }
2583 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002584 .alg = "crct10dif",
2585 .test = alg_test_hash,
2586 .fips_allowed = 1,
2587 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002588 .hash = __VECS(crct10dif_tv_template)
Herbert Xu684115212013-09-07 12:56:26 +10002589 }
2590 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002591 .alg = "ctr(aes)",
2592 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002593 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002594 .suite = {
2595 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002596 .enc = __VECS(aes_ctr_enc_tv_template),
2597 .dec = __VECS(aes_ctr_dec_tv_template)
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002598 }
2599 }
2600 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002601 .alg = "ctr(blowfish)",
2602 .test = alg_test_skcipher,
2603 .suite = {
2604 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002605 .enc = __VECS(bf_ctr_enc_tv_template),
2606 .dec = __VECS(bf_ctr_dec_tv_template)
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002607 }
2608 }
2609 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002610 .alg = "ctr(camellia)",
2611 .test = alg_test_skcipher,
2612 .suite = {
2613 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002614 .enc = __VECS(camellia_ctr_enc_tv_template),
2615 .dec = __VECS(camellia_ctr_dec_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02002616 }
2617 }
2618 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002619 .alg = "ctr(cast5)",
2620 .test = alg_test_skcipher,
2621 .suite = {
2622 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002623 .enc = __VECS(cast5_ctr_enc_tv_template),
2624 .dec = __VECS(cast5_ctr_dec_tv_template)
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002625 }
2626 }
2627 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002628 .alg = "ctr(cast6)",
2629 .test = alg_test_skcipher,
2630 .suite = {
2631 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002632 .enc = __VECS(cast6_ctr_enc_tv_template),
2633 .dec = __VECS(cast6_ctr_dec_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002634 }
2635 }
2636 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002637 .alg = "ctr(des)",
2638 .test = alg_test_skcipher,
2639 .suite = {
2640 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002641 .enc = __VECS(des_ctr_enc_tv_template),
2642 .dec = __VECS(des_ctr_dec_tv_template)
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002643 }
2644 }
2645 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002646 .alg = "ctr(des3_ede)",
2647 .test = alg_test_skcipher,
2648 .suite = {
2649 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002650 .enc = __VECS(des3_ede_ctr_enc_tv_template),
2651 .dec = __VECS(des3_ede_ctr_dec_tv_template)
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002652 }
2653 }
2654 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002655 .alg = "ctr(serpent)",
2656 .test = alg_test_skcipher,
2657 .suite = {
2658 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002659 .enc = __VECS(serpent_ctr_enc_tv_template),
2660 .dec = __VECS(serpent_ctr_dec_tv_template)
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002661 }
2662 }
2663 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002664 .alg = "ctr(twofish)",
2665 .test = alg_test_skcipher,
2666 .suite = {
2667 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002668 .enc = __VECS(tf_ctr_enc_tv_template),
2669 .dec = __VECS(tf_ctr_dec_tv_template)
Jussi Kivilinna573da622011-10-10 23:03:12 +03002670 }
2671 }
2672 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002673 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002674 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002675 .suite = {
2676 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002677 .enc = __VECS(cts_mode_enc_tv_template),
2678 .dec = __VECS(cts_mode_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002679 }
2680 }
2681 }, {
2682 .alg = "deflate",
2683 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002684 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002685 .suite = {
2686 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002687 .comp = __VECS(deflate_comp_tv_template),
2688 .decomp = __VECS(deflate_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002689 }
2690 }
2691 }, {
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002692 .alg = "dh",
2693 .test = alg_test_kpp,
2694 .fips_allowed = 1,
2695 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002696 .kpp = __VECS(dh_tv_template)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002697 }
2698 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002699 .alg = "digest_null",
2700 .test = alg_test_null,
2701 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002702 .alg = "drbg_nopr_ctr_aes128",
2703 .test = alg_test_drbg,
2704 .fips_allowed = 1,
2705 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002706 .drbg = __VECS(drbg_nopr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002707 }
2708 }, {
2709 .alg = "drbg_nopr_ctr_aes192",
2710 .test = alg_test_drbg,
2711 .fips_allowed = 1,
2712 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002713 .drbg = __VECS(drbg_nopr_ctr_aes192_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002714 }
2715 }, {
2716 .alg = "drbg_nopr_ctr_aes256",
2717 .test = alg_test_drbg,
2718 .fips_allowed = 1,
2719 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002720 .drbg = __VECS(drbg_nopr_ctr_aes256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002721 }
2722 }, {
2723 /*
2724 * There is no need to specifically test the DRBG with every
2725 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2726 */
2727 .alg = "drbg_nopr_hmac_sha1",
2728 .fips_allowed = 1,
2729 .test = alg_test_null,
2730 }, {
2731 .alg = "drbg_nopr_hmac_sha256",
2732 .test = alg_test_drbg,
2733 .fips_allowed = 1,
2734 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002735 .drbg = __VECS(drbg_nopr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002736 }
2737 }, {
2738 /* covered by drbg_nopr_hmac_sha256 test */
2739 .alg = "drbg_nopr_hmac_sha384",
2740 .fips_allowed = 1,
2741 .test = alg_test_null,
2742 }, {
2743 .alg = "drbg_nopr_hmac_sha512",
2744 .test = alg_test_null,
2745 .fips_allowed = 1,
2746 }, {
2747 .alg = "drbg_nopr_sha1",
2748 .fips_allowed = 1,
2749 .test = alg_test_null,
2750 }, {
2751 .alg = "drbg_nopr_sha256",
2752 .test = alg_test_drbg,
2753 .fips_allowed = 1,
2754 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002755 .drbg = __VECS(drbg_nopr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002756 }
2757 }, {
2758 /* covered by drbg_nopr_sha256 test */
2759 .alg = "drbg_nopr_sha384",
2760 .fips_allowed = 1,
2761 .test = alg_test_null,
2762 }, {
2763 .alg = "drbg_nopr_sha512",
2764 .fips_allowed = 1,
2765 .test = alg_test_null,
2766 }, {
2767 .alg = "drbg_pr_ctr_aes128",
2768 .test = alg_test_drbg,
2769 .fips_allowed = 1,
2770 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002771 .drbg = __VECS(drbg_pr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002772 }
2773 }, {
2774 /* covered by drbg_pr_ctr_aes128 test */
2775 .alg = "drbg_pr_ctr_aes192",
2776 .fips_allowed = 1,
2777 .test = alg_test_null,
2778 }, {
2779 .alg = "drbg_pr_ctr_aes256",
2780 .fips_allowed = 1,
2781 .test = alg_test_null,
2782 }, {
2783 .alg = "drbg_pr_hmac_sha1",
2784 .fips_allowed = 1,
2785 .test = alg_test_null,
2786 }, {
2787 .alg = "drbg_pr_hmac_sha256",
2788 .test = alg_test_drbg,
2789 .fips_allowed = 1,
2790 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002791 .drbg = __VECS(drbg_pr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002792 }
2793 }, {
2794 /* covered by drbg_pr_hmac_sha256 test */
2795 .alg = "drbg_pr_hmac_sha384",
2796 .fips_allowed = 1,
2797 .test = alg_test_null,
2798 }, {
2799 .alg = "drbg_pr_hmac_sha512",
2800 .test = alg_test_null,
2801 .fips_allowed = 1,
2802 }, {
2803 .alg = "drbg_pr_sha1",
2804 .fips_allowed = 1,
2805 .test = alg_test_null,
2806 }, {
2807 .alg = "drbg_pr_sha256",
2808 .test = alg_test_drbg,
2809 .fips_allowed = 1,
2810 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002811 .drbg = __VECS(drbg_pr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002812 }
2813 }, {
2814 /* covered by drbg_pr_sha256 test */
2815 .alg = "drbg_pr_sha384",
2816 .fips_allowed = 1,
2817 .test = alg_test_null,
2818 }, {
2819 .alg = "drbg_pr_sha512",
2820 .fips_allowed = 1,
2821 .test = alg_test_null,
2822 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002823 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002824 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002825 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002826 .suite = {
2827 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002828 .enc = __VECS(aes_enc_tv_template),
2829 .dec = __VECS(aes_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002830 }
2831 }
2832 }, {
2833 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002834 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002835 .suite = {
2836 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002837 .enc = __VECS(anubis_enc_tv_template),
2838 .dec = __VECS(anubis_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002839 }
2840 }
2841 }, {
2842 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002843 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002844 .suite = {
2845 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002846 .enc = __VECS(arc4_enc_tv_template),
2847 .dec = __VECS(arc4_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002848 }
2849 }
2850 }, {
2851 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002852 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002853 .suite = {
2854 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002855 .enc = __VECS(bf_enc_tv_template),
2856 .dec = __VECS(bf_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002857 }
2858 }
2859 }, {
2860 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002861 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002862 .suite = {
2863 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002864 .enc = __VECS(camellia_enc_tv_template),
2865 .dec = __VECS(camellia_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002866 }
2867 }
2868 }, {
2869 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002870 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002871 .suite = {
2872 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002873 .enc = __VECS(cast5_enc_tv_template),
2874 .dec = __VECS(cast5_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002875 }
2876 }
2877 }, {
2878 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002879 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002880 .suite = {
2881 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002882 .enc = __VECS(cast6_enc_tv_template),
2883 .dec = __VECS(cast6_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002884 }
2885 }
2886 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002887 .alg = "ecb(cipher_null)",
2888 .test = alg_test_null,
2889 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002890 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002891 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002892 .suite = {
2893 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002894 .enc = __VECS(des_enc_tv_template),
2895 .dec = __VECS(des_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002896 }
2897 }
2898 }, {
2899 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002900 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002901 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002902 .suite = {
2903 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002904 .enc = __VECS(des3_ede_enc_tv_template),
2905 .dec = __VECS(des3_ede_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002906 }
2907 }
2908 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002909 .alg = "ecb(fcrypt)",
2910 .test = alg_test_skcipher,
2911 .suite = {
2912 .cipher = {
2913 .enc = {
2914 .vecs = fcrypt_pcbc_enc_tv_template,
2915 .count = 1
2916 },
2917 .dec = {
2918 .vecs = fcrypt_pcbc_dec_tv_template,
2919 .count = 1
2920 }
2921 }
2922 }
2923 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002924 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002925 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002926 .suite = {
2927 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002928 .enc = __VECS(khazad_enc_tv_template),
2929 .dec = __VECS(khazad_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002930 }
2931 }
2932 }, {
2933 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002934 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002935 .suite = {
2936 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002937 .enc = __VECS(seed_enc_tv_template),
2938 .dec = __VECS(seed_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002939 }
2940 }
2941 }, {
2942 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002943 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002944 .suite = {
2945 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002946 .enc = __VECS(serpent_enc_tv_template),
2947 .dec = __VECS(serpent_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002948 }
2949 }
2950 }, {
2951 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002952 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002953 .suite = {
2954 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002955 .enc = __VECS(tea_enc_tv_template),
2956 .dec = __VECS(tea_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002957 }
2958 }
2959 }, {
2960 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002961 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002962 .suite = {
2963 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002964 .enc = __VECS(tnepres_enc_tv_template),
2965 .dec = __VECS(tnepres_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002966 }
2967 }
2968 }, {
2969 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002970 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002971 .suite = {
2972 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002973 .enc = __VECS(tf_enc_tv_template),
2974 .dec = __VECS(tf_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002975 }
2976 }
2977 }, {
2978 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002979 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002980 .suite = {
2981 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002982 .enc = __VECS(xeta_enc_tv_template),
2983 .dec = __VECS(xeta_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002984 }
2985 }
2986 }, {
2987 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002988 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002989 .suite = {
2990 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002991 .enc = __VECS(xtea_enc_tv_template),
2992 .dec = __VECS(xtea_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002993 }
2994 }
2995 }, {
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01002996 .alg = "ecdh",
2997 .test = alg_test_kpp,
2998 .fips_allowed = 1,
2999 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003000 .kpp = __VECS(ecdh_tv_template)
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003001 }
3002 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003003 .alg = "gcm(aes)",
3004 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003005 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003006 .suite = {
3007 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003008 .enc = __VECS(aes_gcm_enc_tv_template),
3009 .dec = __VECS(aes_gcm_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003010 }
3011 }
3012 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003013 .alg = "ghash",
3014 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003015 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003016 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003017 .hash = __VECS(ghash_tv_template)
Youquan, Song507069c2009-11-23 20:23:04 +08003018 }
3019 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003020 .alg = "hmac(crc32)",
3021 .test = alg_test_hash,
3022 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003023 .hash = __VECS(bfin_crc_tv_template)
Sonic Zhanga482b082012-05-25 17:54:13 +08003024 }
3025 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003026 .alg = "hmac(md5)",
3027 .test = alg_test_hash,
3028 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003029 .hash = __VECS(hmac_md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003030 }
3031 }, {
3032 .alg = "hmac(rmd128)",
3033 .test = alg_test_hash,
3034 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003035 .hash = __VECS(hmac_rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003036 }
3037 }, {
3038 .alg = "hmac(rmd160)",
3039 .test = alg_test_hash,
3040 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003041 .hash = __VECS(hmac_rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003042 }
3043 }, {
3044 .alg = "hmac(sha1)",
3045 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003046 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003047 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003048 .hash = __VECS(hmac_sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003049 }
3050 }, {
3051 .alg = "hmac(sha224)",
3052 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003053 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003054 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003055 .hash = __VECS(hmac_sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003056 }
3057 }, {
3058 .alg = "hmac(sha256)",
3059 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003060 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003061 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003062 .hash = __VECS(hmac_sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003063 }
3064 }, {
raveendra padasalagi98eca722016-07-01 11:16:54 +05303065 .alg = "hmac(sha3-224)",
3066 .test = alg_test_hash,
3067 .fips_allowed = 1,
3068 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003069 .hash = __VECS(hmac_sha3_224_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303070 }
3071 }, {
3072 .alg = "hmac(sha3-256)",
3073 .test = alg_test_hash,
3074 .fips_allowed = 1,
3075 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003076 .hash = __VECS(hmac_sha3_256_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303077 }
3078 }, {
3079 .alg = "hmac(sha3-384)",
3080 .test = alg_test_hash,
3081 .fips_allowed = 1,
3082 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003083 .hash = __VECS(hmac_sha3_384_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303084 }
3085 }, {
3086 .alg = "hmac(sha3-512)",
3087 .test = alg_test_hash,
3088 .fips_allowed = 1,
3089 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003090 .hash = __VECS(hmac_sha3_512_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303091 }
3092 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003093 .alg = "hmac(sha384)",
3094 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003095 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003096 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003097 .hash = __VECS(hmac_sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003098 }
3099 }, {
3100 .alg = "hmac(sha512)",
3101 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003102 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003103 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003104 .hash = __VECS(hmac_sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003105 }
3106 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003107 .alg = "jitterentropy_rng",
3108 .fips_allowed = 1,
3109 .test = alg_test_null,
3110 }, {
Stephan Mueller35351982015-09-21 20:59:56 +02003111 .alg = "kw(aes)",
3112 .test = alg_test_skcipher,
3113 .fips_allowed = 1,
3114 .suite = {
3115 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003116 .enc = __VECS(aes_kw_enc_tv_template),
3117 .dec = __VECS(aes_kw_dec_tv_template)
Stephan Mueller35351982015-09-21 20:59:56 +02003118 }
3119 }
3120 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003121 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003122 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003123 .suite = {
3124 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003125 .enc = __VECS(aes_lrw_enc_tv_template),
3126 .dec = __VECS(aes_lrw_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003127 }
3128 }
3129 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003130 .alg = "lrw(camellia)",
3131 .test = alg_test_skcipher,
3132 .suite = {
3133 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003134 .enc = __VECS(camellia_lrw_enc_tv_template),
3135 .dec = __VECS(camellia_lrw_dec_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003136 }
3137 }
3138 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003139 .alg = "lrw(cast6)",
3140 .test = alg_test_skcipher,
3141 .suite = {
3142 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003143 .enc = __VECS(cast6_lrw_enc_tv_template),
3144 .dec = __VECS(cast6_lrw_dec_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003145 }
3146 }
3147 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003148 .alg = "lrw(serpent)",
3149 .test = alg_test_skcipher,
3150 .suite = {
3151 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003152 .enc = __VECS(serpent_lrw_enc_tv_template),
3153 .dec = __VECS(serpent_lrw_dec_tv_template)
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003154 }
3155 }
3156 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003157 .alg = "lrw(twofish)",
3158 .test = alg_test_skcipher,
3159 .suite = {
3160 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003161 .enc = __VECS(tf_lrw_enc_tv_template),
3162 .dec = __VECS(tf_lrw_dec_tv_template)
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003163 }
3164 }
3165 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003166 .alg = "lz4",
3167 .test = alg_test_comp,
3168 .fips_allowed = 1,
3169 .suite = {
3170 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003171 .comp = __VECS(lz4_comp_tv_template),
3172 .decomp = __VECS(lz4_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003173 }
3174 }
3175 }, {
3176 .alg = "lz4hc",
3177 .test = alg_test_comp,
3178 .fips_allowed = 1,
3179 .suite = {
3180 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003181 .comp = __VECS(lz4hc_comp_tv_template),
3182 .decomp = __VECS(lz4hc_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003183 }
3184 }
3185 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003186 .alg = "lzo",
3187 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003188 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003189 .suite = {
3190 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003191 .comp = __VECS(lzo_comp_tv_template),
3192 .decomp = __VECS(lzo_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003193 }
3194 }
3195 }, {
3196 .alg = "md4",
3197 .test = alg_test_hash,
3198 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003199 .hash = __VECS(md4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003200 }
3201 }, {
3202 .alg = "md5",
3203 .test = alg_test_hash,
3204 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003205 .hash = __VECS(md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003206 }
3207 }, {
3208 .alg = "michael_mic",
3209 .test = alg_test_hash,
3210 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003211 .hash = __VECS(michael_mic_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003212 }
3213 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003214 .alg = "ofb(aes)",
3215 .test = alg_test_skcipher,
3216 .fips_allowed = 1,
3217 .suite = {
3218 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003219 .enc = __VECS(aes_ofb_enc_tv_template),
3220 .dec = __VECS(aes_ofb_dec_tv_template)
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003221 }
3222 }
3223 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003224 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003225 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003226 .suite = {
3227 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003228 .enc = __VECS(fcrypt_pcbc_enc_tv_template),
3229 .dec = __VECS(fcrypt_pcbc_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003230 }
3231 }
3232 }, {
Martin Willieee9dc62015-06-01 13:43:59 +02003233 .alg = "poly1305",
3234 .test = alg_test_hash,
3235 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003236 .hash = __VECS(poly1305_tv_template)
Martin Willieee9dc62015-06-01 13:43:59 +02003237 }
3238 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003239 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003240 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003241 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003242 .suite = {
3243 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003244 .enc = __VECS(aes_ctr_rfc3686_enc_tv_template),
3245 .dec = __VECS(aes_ctr_rfc3686_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003246 }
3247 }
3248 }, {
Herbert Xu3f31a742015-07-09 07:17:34 +08003249 .alg = "rfc4106(gcm(aes))",
Adrian Hoban69435b92010-11-04 15:02:04 -04003250 .test = alg_test_aead,
Jarod Wilsondb71f29a2015-01-23 12:42:15 -05003251 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003252 .suite = {
3253 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003254 .enc = __VECS(aes_gcm_rfc4106_enc_tv_template),
3255 .dec = __VECS(aes_gcm_rfc4106_dec_tv_template)
Adrian Hoban69435b92010-11-04 15:02:04 -04003256 }
3257 }
3258 }, {
Herbert Xu544c4362015-07-14 16:53:22 +08003259 .alg = "rfc4309(ccm(aes))",
Jarod Wilson5d667322009-05-04 19:23:40 +08003260 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003261 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003262 .suite = {
3263 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003264 .enc = __VECS(aes_ccm_rfc4309_enc_tv_template),
3265 .dec = __VECS(aes_ccm_rfc4309_dec_tv_template)
Jarod Wilson5d667322009-05-04 19:23:40 +08003266 }
3267 }
3268 }, {
Herbert Xubb687452015-06-16 13:54:24 +08003269 .alg = "rfc4543(gcm(aes))",
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003270 .test = alg_test_aead,
3271 .suite = {
3272 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003273 .enc = __VECS(aes_gcm_rfc4543_enc_tv_template),
3274 .dec = __VECS(aes_gcm_rfc4543_dec_tv_template),
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003275 }
3276 }
3277 }, {
Martin Williaf2b76b2015-06-01 13:44:01 +02003278 .alg = "rfc7539(chacha20,poly1305)",
3279 .test = alg_test_aead,
3280 .suite = {
3281 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003282 .enc = __VECS(rfc7539_enc_tv_template),
3283 .dec = __VECS(rfc7539_dec_tv_template),
Martin Williaf2b76b2015-06-01 13:44:01 +02003284 }
3285 }
3286 }, {
Martin Willi59007582015-06-01 13:44:03 +02003287 .alg = "rfc7539esp(chacha20,poly1305)",
3288 .test = alg_test_aead,
3289 .suite = {
3290 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003291 .enc = __VECS(rfc7539esp_enc_tv_template),
3292 .dec = __VECS(rfc7539esp_dec_tv_template),
Martin Willi59007582015-06-01 13:44:03 +02003293 }
3294 }
3295 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003296 .alg = "rmd128",
3297 .test = alg_test_hash,
3298 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003299 .hash = __VECS(rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003300 }
3301 }, {
3302 .alg = "rmd160",
3303 .test = alg_test_hash,
3304 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003305 .hash = __VECS(rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003306 }
3307 }, {
3308 .alg = "rmd256",
3309 .test = alg_test_hash,
3310 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003311 .hash = __VECS(rmd256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003312 }
3313 }, {
3314 .alg = "rmd320",
3315 .test = alg_test_hash,
3316 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003317 .hash = __VECS(rmd320_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003318 }
3319 }, {
Tadeusz Struk946cc462015-06-16 10:31:06 -07003320 .alg = "rsa",
3321 .test = alg_test_akcipher,
3322 .fips_allowed = 1,
3323 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003324 .akcipher = __VECS(rsa_tv_template)
Tadeusz Struk946cc462015-06-16 10:31:06 -07003325 }
3326 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003327 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003328 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003329 .suite = {
3330 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003331 .enc = __VECS(salsa20_stream_enc_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003332 }
3333 }
3334 }, {
3335 .alg = "sha1",
3336 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003337 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003338 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003339 .hash = __VECS(sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003340 }
3341 }, {
3342 .alg = "sha224",
3343 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003344 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003345 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003346 .hash = __VECS(sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003347 }
3348 }, {
3349 .alg = "sha256",
3350 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003351 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003352 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003353 .hash = __VECS(sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003354 }
3355 }, {
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303356 .alg = "sha3-224",
3357 .test = alg_test_hash,
3358 .fips_allowed = 1,
3359 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003360 .hash = __VECS(sha3_224_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303361 }
3362 }, {
3363 .alg = "sha3-256",
3364 .test = alg_test_hash,
3365 .fips_allowed = 1,
3366 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003367 .hash = __VECS(sha3_256_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303368 }
3369 }, {
3370 .alg = "sha3-384",
3371 .test = alg_test_hash,
3372 .fips_allowed = 1,
3373 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003374 .hash = __VECS(sha3_384_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303375 }
3376 }, {
3377 .alg = "sha3-512",
3378 .test = alg_test_hash,
3379 .fips_allowed = 1,
3380 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003381 .hash = __VECS(sha3_512_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303382 }
3383 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003384 .alg = "sha384",
3385 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003386 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003387 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003388 .hash = __VECS(sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003389 }
3390 }, {
3391 .alg = "sha512",
3392 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003393 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003394 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003395 .hash = __VECS(sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003396 }
3397 }, {
3398 .alg = "tgr128",
3399 .test = alg_test_hash,
3400 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003401 .hash = __VECS(tgr128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003402 }
3403 }, {
3404 .alg = "tgr160",
3405 .test = alg_test_hash,
3406 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003407 .hash = __VECS(tgr160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003408 }
3409 }, {
3410 .alg = "tgr192",
3411 .test = alg_test_hash,
3412 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003413 .hash = __VECS(tgr192_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003414 }
3415 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003416 .alg = "vmac(aes)",
3417 .test = alg_test_hash,
3418 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003419 .hash = __VECS(aes_vmac128_tv_template)
Shane Wangf1939f72009-09-02 20:05:22 +10003420 }
3421 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003422 .alg = "wp256",
3423 .test = alg_test_hash,
3424 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003425 .hash = __VECS(wp256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003426 }
3427 }, {
3428 .alg = "wp384",
3429 .test = alg_test_hash,
3430 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003431 .hash = __VECS(wp384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003432 }
3433 }, {
3434 .alg = "wp512",
3435 .test = alg_test_hash,
3436 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003437 .hash = __VECS(wp512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003438 }
3439 }, {
3440 .alg = "xcbc(aes)",
3441 .test = alg_test_hash,
3442 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003443 .hash = __VECS(aes_xcbc128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003444 }
3445 }, {
3446 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003447 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003448 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003449 .suite = {
3450 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003451 .enc = __VECS(aes_xts_enc_tv_template),
3452 .dec = __VECS(aes_xts_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003453 }
3454 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003455 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003456 .alg = "xts(camellia)",
3457 .test = alg_test_skcipher,
3458 .suite = {
3459 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003460 .enc = __VECS(camellia_xts_enc_tv_template),
3461 .dec = __VECS(camellia_xts_dec_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003462 }
3463 }
3464 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003465 .alg = "xts(cast6)",
3466 .test = alg_test_skcipher,
3467 .suite = {
3468 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003469 .enc = __VECS(cast6_xts_enc_tv_template),
3470 .dec = __VECS(cast6_xts_dec_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003471 }
3472 }
3473 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003474 .alg = "xts(serpent)",
3475 .test = alg_test_skcipher,
3476 .suite = {
3477 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003478 .enc = __VECS(serpent_xts_enc_tv_template),
3479 .dec = __VECS(serpent_xts_dec_tv_template)
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003480 }
3481 }
3482 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003483 .alg = "xts(twofish)",
3484 .test = alg_test_skcipher,
3485 .suite = {
3486 .cipher = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003487 .enc = __VECS(tf_xts_enc_tv_template),
3488 .dec = __VECS(tf_xts_dec_tv_template)
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003489 }
3490 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003491 }
3492};
3493
Jussi Kivilinna57147582013-06-13 17:37:40 +03003494static bool alg_test_descs_checked;
3495
3496static void alg_test_descs_check_order(void)
3497{
3498 int i;
3499
3500 /* only check once */
3501 if (alg_test_descs_checked)
3502 return;
3503
3504 alg_test_descs_checked = true;
3505
3506 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3507 int diff = strcmp(alg_test_descs[i - 1].alg,
3508 alg_test_descs[i].alg);
3509
3510 if (WARN_ON(diff > 0)) {
3511 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3512 alg_test_descs[i - 1].alg,
3513 alg_test_descs[i].alg);
3514 }
3515
3516 if (WARN_ON(diff == 0)) {
3517 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3518 alg_test_descs[i].alg);
3519 }
3520 }
3521}
3522
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003523static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003524{
3525 int start = 0;
3526 int end = ARRAY_SIZE(alg_test_descs);
3527
3528 while (start < end) {
3529 int i = (start + end) / 2;
3530 int diff = strcmp(alg_test_descs[i].alg, alg);
3531
3532 if (diff > 0) {
3533 end = i;
3534 continue;
3535 }
3536
3537 if (diff < 0) {
3538 start = i + 1;
3539 continue;
3540 }
3541
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003542 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003543 }
3544
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003545 return -1;
3546}
3547
3548int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3549{
3550 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003551 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003552 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003553
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +01003554 if (!fips_enabled && notests) {
3555 printk_once(KERN_INFO "alg: self-tests disabled\n");
3556 return 0;
3557 }
3558
Jussi Kivilinna57147582013-06-13 17:37:40 +03003559 alg_test_descs_check_order();
3560
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003561 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3562 char nalg[CRYPTO_MAX_ALG_NAME];
3563
3564 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3565 sizeof(nalg))
3566 return -ENAMETOOLONG;
3567
3568 i = alg_find_test(nalg);
3569 if (i < 0)
3570 goto notest;
3571
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003572 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3573 goto non_fips_alg;
3574
Jarod Wilson941fb322009-05-04 19:49:23 +08003575 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3576 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003577 }
3578
3579 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003580 j = alg_find_test(driver);
3581 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003582 goto notest;
3583
Herbert Xua68f6612009-07-02 16:32:12 +08003584 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3585 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003586 goto non_fips_alg;
3587
Herbert Xua68f6612009-07-02 16:32:12 +08003588 rc = 0;
3589 if (i >= 0)
3590 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3591 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003592 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003593 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3594 type, mask);
3595
Jarod Wilson941fb322009-05-04 19:49:23 +08003596test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003597 if (fips_enabled && rc)
3598 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3599
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003600 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09003601 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003602
Neil Hormand12d6b62008-10-12 20:36:51 +08003603 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003604
3605notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003606 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3607 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003608non_fips_alg:
3609 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003610}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003611
Herbert Xu326a6342010-08-06 09:40:28 +08003612#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003613
Herbert Xuda7f0332008-07-31 17:08:25 +08003614EXPORT_SYMBOL_GPL(alg_test);