blob: a73455b543ad819dab4c462816b44b845be8ea17 [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
Herbert Xuda7f0332008-07-31 17:08:25 +080079struct aead_test_suite {
Eric Biggersa0d608ee2019-01-13 15:32:28 -080080 const struct aead_testvec *vecs;
81 unsigned int count;
Herbert Xuda7f0332008-07-31 17:08:25 +080082};
83
84struct cipher_test_suite {
Eric Biggers92a4c9f2018-05-20 22:50:29 -070085 const struct cipher_testvec *vecs;
86 unsigned int count;
Herbert Xuda7f0332008-07-31 17:08:25 +080087};
88
89struct comp_test_suite {
90 struct {
Eric Biggersb13b1e02017-02-24 15:46:59 -080091 const struct comp_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +080092 unsigned int count;
93 } comp, decomp;
94};
95
96struct hash_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -080097 const struct hash_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +080098 unsigned int count;
99};
100
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800101struct cprng_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800102 const struct cprng_testvec *vecs;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800103 unsigned int count;
104};
105
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200106struct drbg_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800107 const struct drbg_testvec *vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200108 unsigned int count;
109};
110
Tadeusz Struk946cc462015-06-16 10:31:06 -0700111struct akcipher_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800112 const struct akcipher_testvec *vecs;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700113 unsigned int count;
114};
115
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100116struct kpp_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800117 const struct kpp_testvec *vecs;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100118 unsigned int count;
119};
120
Herbert Xuda7f0332008-07-31 17:08:25 +0800121struct alg_test_desc {
122 const char *alg;
123 int (*test)(const struct alg_test_desc *desc, const char *driver,
124 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000125 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800126
127 union {
128 struct aead_test_suite aead;
129 struct cipher_test_suite cipher;
130 struct comp_test_suite comp;
131 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800132 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200133 struct drbg_test_suite drbg;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700134 struct akcipher_test_suite akcipher;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100135 struct kpp_test_suite kpp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800136 } suite;
137};
138
Eric Biggersb13b1e02017-02-24 15:46:59 -0800139static const unsigned int IDX[8] = {
140 IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
Herbert Xuda7f0332008-07-31 17:08:25 +0800141
Herbert Xuda7f0332008-07-31 17:08:25 +0800142static void hexdump(unsigned char *buf, unsigned int len)
143{
144 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
145 16, 1,
146 buf, len, false);
147}
148
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800149static int testmgr_alloc_buf(char *buf[XBUFSIZE])
150{
151 int i;
152
153 for (i = 0; i < XBUFSIZE; i++) {
154 buf[i] = (void *)__get_free_page(GFP_KERNEL);
155 if (!buf[i])
156 goto err_free_buf;
157 }
158
159 return 0;
160
161err_free_buf:
162 while (i-- > 0)
163 free_page((unsigned long)buf[i]);
164
165 return -ENOMEM;
166}
167
168static void testmgr_free_buf(char *buf[XBUFSIZE])
169{
170 int i;
171
172 for (i = 0; i < XBUFSIZE; i++)
173 free_page((unsigned long)buf[i]);
174}
175
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100176static int ahash_guard_result(char *result, char c, int size)
177{
178 int i;
179
180 for (i = 0; i < size; i++) {
181 if (result[i] != c)
182 return -EINVAL;
183 }
184
185 return 0;
186}
187
Wang, Rui Y018ba952016-02-03 18:26:57 +0800188static int ahash_partial_update(struct ahash_request **preq,
Eric Biggersb13b1e02017-02-24 15:46:59 -0800189 struct crypto_ahash *tfm, const struct hash_testvec *template,
Wang, Rui Y018ba952016-02-03 18:26:57 +0800190 void *hash_buff, int k, int temp, struct scatterlist *sg,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100191 const char *algo, char *result, struct crypto_wait *wait)
Wang, Rui Y018ba952016-02-03 18:26:57 +0800192{
193 char *state;
194 struct ahash_request *req;
195 int statesize, ret = -EINVAL;
Joey Pabalinasda1729c2018-01-01 10:40:14 -1000196 static const unsigned char guard[] = { 0x00, 0xba, 0xad, 0x00 };
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100197 int digestsize = crypto_ahash_digestsize(tfm);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800198
199 req = *preq;
200 statesize = crypto_ahash_statesize(
201 crypto_ahash_reqtfm(req));
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200202 state = kmalloc(statesize + sizeof(guard), GFP_KERNEL);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800203 if (!state) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300204 pr_err("alg: hash: Failed to alloc state for %s\n", algo);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800205 goto out_nostate;
206 }
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200207 memcpy(state + statesize, guard, sizeof(guard));
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100208 memset(result, 1, digestsize);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800209 ret = crypto_ahash_export(req, state);
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200210 WARN_ON(memcmp(state + statesize, guard, sizeof(guard)));
Wang, Rui Y018ba952016-02-03 18:26:57 +0800211 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300212 pr_err("alg: hash: Failed to export() for %s\n", algo);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800213 goto out;
214 }
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100215 ret = ahash_guard_result(result, 1, digestsize);
216 if (ret) {
217 pr_err("alg: hash: Failed, export used req->result for %s\n",
218 algo);
219 goto out;
220 }
Wang, Rui Y018ba952016-02-03 18:26:57 +0800221 ahash_request_free(req);
222 req = ahash_request_alloc(tfm, GFP_KERNEL);
223 if (!req) {
224 pr_err("alg: hash: Failed to alloc request for %s\n", algo);
225 goto out_noreq;
226 }
227 ahash_request_set_callback(req,
228 CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100229 crypto_req_done, wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800230
231 memcpy(hash_buff, template->plaintext + temp,
232 template->tap[k]);
233 sg_init_one(&sg[0], hash_buff, template->tap[k]);
234 ahash_request_set_crypt(req, sg, result, template->tap[k]);
235 ret = crypto_ahash_import(req, state);
236 if (ret) {
237 pr_err("alg: hash: Failed to import() for %s\n", algo);
238 goto out;
239 }
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100240 ret = ahash_guard_result(result, 1, digestsize);
241 if (ret) {
242 pr_err("alg: hash: Failed, import used req->result for %s\n",
243 algo);
244 goto out;
245 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100246 ret = crypto_wait_req(crypto_ahash_update(req), wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800247 if (ret)
248 goto out;
249 *preq = req;
250 ret = 0;
251 goto out_noreq;
252out:
253 ahash_request_free(req);
254out_noreq:
255 kfree(state);
256out_nostate:
257 return ret;
258}
259
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100260enum hash_test {
261 HASH_TEST_DIGEST,
262 HASH_TEST_FINAL,
263 HASH_TEST_FINUP
264};
265
Eric Biggersb13b1e02017-02-24 15:46:59 -0800266static int __test_hash(struct crypto_ahash *tfm,
267 const struct hash_testvec *template, unsigned int tcount,
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100268 enum hash_test test_type, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800269{
270 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800271 size_t digest_size = crypto_ahash_digestsize(tfm);
Herbert Xuda7f0332008-07-31 17:08:25 +0800272 unsigned int i, j, k, temp;
273 struct scatterlist sg[8];
Horia Geanta29b77e52014-07-23 11:59:38 +0300274 char *result;
275 char *key;
Herbert Xuda7f0332008-07-31 17:08:25 +0800276 struct ahash_request *req;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100277 struct crypto_wait wait;
Herbert Xuda7f0332008-07-31 17:08:25 +0800278 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800279 char *xbuf[XBUFSIZE];
280 int ret = -ENOMEM;
281
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800282 result = kmalloc(digest_size, GFP_KERNEL);
Horia Geanta29b77e52014-07-23 11:59:38 +0300283 if (!result)
284 return ret;
285 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
286 if (!key)
287 goto out_nobuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800288 if (testmgr_alloc_buf(xbuf))
289 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800290
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100291 crypto_init_wait(&wait);
Herbert Xuda7f0332008-07-31 17:08:25 +0800292
293 req = ahash_request_alloc(tfm, GFP_KERNEL);
294 if (!req) {
295 printk(KERN_ERR "alg: hash: Failed to allocate request for "
296 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800297 goto out_noreq;
298 }
299 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100300 crypto_req_done, &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +0800301
Herbert Xua0cfae52009-05-29 16:23:12 +1000302 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800303 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000304 if (template[i].np)
305 continue;
306
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300307 ret = -EINVAL;
308 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
309 goto out;
310
Herbert Xua0cfae52009-05-29 16:23:12 +1000311 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800312 memset(result, 0, digest_size);
Herbert Xuda7f0332008-07-31 17:08:25 +0800313
314 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300315 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800316
317 memcpy(hash_buff, template[i].plaintext, template[i].psize);
318 sg_init_one(&sg[0], hash_buff, template[i].psize);
319
320 if (template[i].ksize) {
321 crypto_ahash_clear_flags(tfm, ~0);
Horia Geanta29b77e52014-07-23 11:59:38 +0300322 if (template[i].ksize > MAX_KEYLEN) {
323 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
324 j, algo, template[i].ksize, MAX_KEYLEN);
325 ret = -EINVAL;
326 goto out;
327 }
328 memcpy(key, template[i].key, template[i].ksize);
329 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
Herbert Xuda7f0332008-07-31 17:08:25 +0800330 if (ret) {
331 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000332 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800333 -ret);
334 goto out;
335 }
336 }
337
338 ahash_request_set_crypt(req, sg, result, template[i].psize);
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100339 switch (test_type) {
340 case HASH_TEST_DIGEST:
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100341 ret = crypto_wait_req(crypto_ahash_digest(req), &wait);
David S. Millera8f1a052010-05-19 14:12:03 +1000342 if (ret) {
343 pr_err("alg: hash: digest failed on test %d "
344 "for %s: ret=%d\n", j, algo, -ret);
345 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800346 }
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100347 break;
348
349 case HASH_TEST_FINAL:
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100350 memset(result, 1, digest_size);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100351 ret = crypto_wait_req(crypto_ahash_init(req), &wait);
David S. Millera8f1a052010-05-19 14:12:03 +1000352 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300353 pr_err("alg: hash: init failed on test %d "
David S. Millera8f1a052010-05-19 14:12:03 +1000354 "for %s: ret=%d\n", j, algo, -ret);
355 goto out;
356 }
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100357 ret = ahash_guard_result(result, 1, digest_size);
358 if (ret) {
359 pr_err("alg: hash: init failed on test %d "
360 "for %s: used req->result\n", j, algo);
361 goto out;
362 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100363 ret = crypto_wait_req(crypto_ahash_update(req), &wait);
David S. Millera8f1a052010-05-19 14:12:03 +1000364 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300365 pr_err("alg: hash: update failed on test %d "
David S. Millera8f1a052010-05-19 14:12:03 +1000366 "for %s: ret=%d\n", j, algo, -ret);
367 goto out;
368 }
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100369 ret = ahash_guard_result(result, 1, digest_size);
370 if (ret) {
371 pr_err("alg: hash: update failed on test %d "
372 "for %s: used req->result\n", j, algo);
373 goto out;
374 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100375 ret = crypto_wait_req(crypto_ahash_final(req), &wait);
David S. Millera8f1a052010-05-19 14:12:03 +1000376 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300377 pr_err("alg: hash: final failed on test %d "
David S. Millera8f1a052010-05-19 14:12:03 +1000378 "for %s: ret=%d\n", j, algo, -ret);
379 goto out;
380 }
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100381 break;
382
383 case HASH_TEST_FINUP:
384 memset(result, 1, digest_size);
385 ret = crypto_wait_req(crypto_ahash_init(req), &wait);
386 if (ret) {
387 pr_err("alg: hash: init failed on test %d "
388 "for %s: ret=%d\n", j, algo, -ret);
389 goto out;
390 }
391 ret = ahash_guard_result(result, 1, digest_size);
392 if (ret) {
393 pr_err("alg: hash: init failed on test %d "
394 "for %s: used req->result\n", j, algo);
395 goto out;
396 }
397 ret = crypto_wait_req(crypto_ahash_finup(req), &wait);
398 if (ret) {
399 pr_err("alg: hash: final failed on test %d "
400 "for %s: ret=%d\n", j, algo, -ret);
401 goto out;
402 }
403 break;
Herbert Xuda7f0332008-07-31 17:08:25 +0800404 }
405
406 if (memcmp(result, template[i].digest,
407 crypto_ahash_digestsize(tfm))) {
408 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000409 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800410 hexdump(result, crypto_ahash_digestsize(tfm));
411 ret = -EINVAL;
412 goto out;
413 }
414 }
415
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100416 if (test_type)
417 goto out;
418
Herbert Xuda7f0332008-07-31 17:08:25 +0800419 j = 0;
420 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300421 /* alignment tests are only done with continuous buffers */
422 if (align_offset != 0)
423 break;
424
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300425 if (!template[i].np)
426 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800427
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300428 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800429 memset(result, 0, digest_size);
Herbert Xuda7f0332008-07-31 17:08:25 +0800430
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300431 temp = 0;
432 sg_init_table(sg, template[i].np);
433 ret = -EINVAL;
434 for (k = 0; k < template[i].np; k++) {
435 if (WARN_ON(offset_in_page(IDX[k]) +
436 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +0800437 goto out;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300438 sg_set_buf(&sg[k],
439 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
440 offset_in_page(IDX[k]),
441 template[i].plaintext + temp,
442 template[i].tap[k]),
443 template[i].tap[k]);
444 temp += template[i].tap[k];
445 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800446
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300447 if (template[i].ksize) {
448 if (template[i].ksize > MAX_KEYLEN) {
449 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
450 j, algo, template[i].ksize, MAX_KEYLEN);
Herbert Xuda7f0332008-07-31 17:08:25 +0800451 ret = -EINVAL;
452 goto out;
453 }
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300454 crypto_ahash_clear_flags(tfm, ~0);
455 memcpy(key, template[i].key, template[i].ksize);
456 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
457
458 if (ret) {
459 printk(KERN_ERR "alg: hash: setkey "
460 "failed on chunking test %d "
461 "for %s: ret=%d\n", j, algo, -ret);
462 goto out;
463 }
464 }
465
466 ahash_request_set_crypt(req, sg, result, template[i].psize);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100467 ret = crypto_wait_req(crypto_ahash_digest(req), &wait);
468 if (ret) {
469 pr_err("alg: hash: digest failed on chunking test %d for %s: ret=%d\n",
470 j, algo, -ret);
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300471 goto out;
472 }
473
474 if (memcmp(result, template[i].digest,
475 crypto_ahash_digestsize(tfm))) {
476 printk(KERN_ERR "alg: hash: Chunking test %d "
477 "failed for %s\n", j, algo);
478 hexdump(result, crypto_ahash_digestsize(tfm));
479 ret = -EINVAL;
480 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800481 }
482 }
483
Wang, Rui Y018ba952016-02-03 18:26:57 +0800484 /* partial update exercise */
485 j = 0;
486 for (i = 0; i < tcount; i++) {
487 /* alignment tests are only done with continuous buffers */
488 if (align_offset != 0)
489 break;
490
491 if (template[i].np < 2)
492 continue;
493
494 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800495 memset(result, 0, digest_size);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800496
497 ret = -EINVAL;
498 hash_buff = xbuf[0];
499 memcpy(hash_buff, template[i].plaintext,
500 template[i].tap[0]);
501 sg_init_one(&sg[0], hash_buff, template[i].tap[0]);
502
503 if (template[i].ksize) {
504 crypto_ahash_clear_flags(tfm, ~0);
505 if (template[i].ksize > MAX_KEYLEN) {
506 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
507 j, algo, template[i].ksize, MAX_KEYLEN);
508 ret = -EINVAL;
509 goto out;
510 }
511 memcpy(key, template[i].key, template[i].ksize);
512 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
513 if (ret) {
514 pr_err("alg: hash: setkey failed on test %d for %s: ret=%d\n",
515 j, algo, -ret);
516 goto out;
517 }
518 }
519
520 ahash_request_set_crypt(req, sg, result, template[i].tap[0]);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100521 ret = crypto_wait_req(crypto_ahash_init(req), &wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800522 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300523 pr_err("alg: hash: init failed on test %d for %s: ret=%d\n",
Wang, Rui Y018ba952016-02-03 18:26:57 +0800524 j, algo, -ret);
525 goto out;
526 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100527 ret = crypto_wait_req(crypto_ahash_update(req), &wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800528 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300529 pr_err("alg: hash: update failed on test %d for %s: ret=%d\n",
Wang, Rui Y018ba952016-02-03 18:26:57 +0800530 j, algo, -ret);
531 goto out;
532 }
533
534 temp = template[i].tap[0];
535 for (k = 1; k < template[i].np; k++) {
536 ret = ahash_partial_update(&req, tfm, &template[i],
537 hash_buff, k, temp, &sg[0], algo, result,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100538 &wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800539 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300540 pr_err("alg: hash: partial update failed on test %d for %s: ret=%d\n",
Wang, Rui Y018ba952016-02-03 18:26:57 +0800541 j, algo, -ret);
542 goto out_noreq;
543 }
544 temp += template[i].tap[k];
545 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100546 ret = crypto_wait_req(crypto_ahash_final(req), &wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800547 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300548 pr_err("alg: hash: final failed on test %d for %s: ret=%d\n",
Wang, Rui Y018ba952016-02-03 18:26:57 +0800549 j, algo, -ret);
550 goto out;
551 }
552 if (memcmp(result, template[i].digest,
553 crypto_ahash_digestsize(tfm))) {
554 pr_err("alg: hash: Partial Test %d failed for %s\n",
555 j, algo);
556 hexdump(result, crypto_ahash_digestsize(tfm));
557 ret = -EINVAL;
558 goto out;
559 }
560 }
561
Herbert Xuda7f0332008-07-31 17:08:25 +0800562 ret = 0;
563
564out:
565 ahash_request_free(req);
566out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800567 testmgr_free_buf(xbuf);
568out_nobuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300569 kfree(key);
570 kfree(result);
Herbert Xuda7f0332008-07-31 17:08:25 +0800571 return ret;
572}
573
Eric Biggersb13b1e02017-02-24 15:46:59 -0800574static int test_hash(struct crypto_ahash *tfm,
575 const struct hash_testvec *template,
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100576 unsigned int tcount, enum hash_test test_type)
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300577{
578 unsigned int alignmask;
579 int ret;
580
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100581 ret = __test_hash(tfm, template, tcount, test_type, 0);
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300582 if (ret)
583 return ret;
584
585 /* test unaligned buffers, check with one byte offset */
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100586 ret = __test_hash(tfm, template, tcount, test_type, 1);
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300587 if (ret)
588 return ret;
589
590 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
591 if (alignmask) {
592 /* Check if alignment mask for tfm is correctly set. */
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100593 ret = __test_hash(tfm, template, tcount, test_type,
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300594 alignmask + 1);
595 if (ret)
596 return ret;
597 }
598
599 return 0;
600}
601
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300602static int __test_aead(struct crypto_aead *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -0800603 const struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300604 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800605{
606 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
607 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800608 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800609 char *q;
610 char *key;
611 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300612 struct scatterlist *sg;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300613 struct scatterlist *sgout;
614 const char *e, *d;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100615 struct crypto_wait wait;
Cristian Stoica424a5da2015-01-28 11:03:05 +0200616 unsigned int authsize, iv_len;
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700617 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800618 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300619 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800620 char *axbuf[XBUFSIZE];
621
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700622 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
623 if (!iv)
624 return ret;
Horia Geanta29b77e52014-07-23 11:59:38 +0300625 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
626 if (!key)
627 goto out_noxbuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800628 if (testmgr_alloc_buf(xbuf))
629 goto out_noxbuf;
630 if (testmgr_alloc_buf(axbuf))
631 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300632 if (diff_dst && testmgr_alloc_buf(xoutbuf))
633 goto out_nooutbuf;
634
635 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
Kees Cook6da2ec52018-06-12 13:55:00 -0700636 sg = kmalloc(array3_size(sizeof(*sg), 8, (diff_dst ? 4 : 2)),
637 GFP_KERNEL);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300638 if (!sg)
639 goto out_nosg;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800640 sgout = &sg[16];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300641
642 if (diff_dst)
643 d = "-ddst";
644 else
645 d = "";
646
Herbert Xuda7f0332008-07-31 17:08:25 +0800647 if (enc == ENCRYPT)
648 e = "encryption";
649 else
650 e = "decryption";
651
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100652 crypto_init_wait(&wait);
Herbert Xuda7f0332008-07-31 17:08:25 +0800653
654 req = aead_request_alloc(tfm, GFP_KERNEL);
655 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300656 pr_err("alg: aead%s: Failed to allocate request for %s\n",
657 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800658 goto out;
659 }
660
661 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100662 crypto_req_done, &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +0800663
Jerome Marchandabfa7f42016-02-03 13:58:12 +0100664 iv_len = crypto_aead_ivsize(tfm);
665
Herbert Xuda7f0332008-07-31 17:08:25 +0800666 for (i = 0, j = 0; i < tcount; i++) {
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800667 const char *input, *expected_output;
668 unsigned int inlen, outlen;
669 char *inbuf, *outbuf, *assocbuf;
670
Cristian Stoica05b1d332014-07-28 13:11:23 +0300671 if (template[i].np)
672 continue;
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800673 if (enc) {
674 if (template[i].novrfy)
675 continue;
676 input = template[i].ptext;
677 inlen = template[i].plen;
678 expected_output = template[i].ctext;
679 outlen = template[i].clen;
680 } else {
681 input = template[i].ctext;
682 inlen = template[i].clen;
683 expected_output = template[i].ptext;
684 outlen = template[i].plen;
685 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800686
Cristian Stoica05b1d332014-07-28 13:11:23 +0300687 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800688
Cristian Stoica05b1d332014-07-28 13:11:23 +0300689 /* some templates have no input data but they will
690 * touch input
691 */
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800692 inbuf = xbuf[0] + align_offset;
693 assocbuf = axbuf[0];
Cristian Stoica05b1d332014-07-28 13:11:23 +0300694
695 ret = -EINVAL;
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800696 if (WARN_ON(align_offset + template[i].clen > PAGE_SIZE ||
697 template[i].alen > PAGE_SIZE))
Cristian Stoica05b1d332014-07-28 13:11:23 +0300698 goto out;
699
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800700 memcpy(inbuf, input, inlen);
701 memcpy(assocbuf, template[i].assoc, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300702 if (template[i].iv)
Cristian Stoica424a5da2015-01-28 11:03:05 +0200703 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300704 else
Cristian Stoica424a5da2015-01-28 11:03:05 +0200705 memset(iv, 0, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300706
707 crypto_aead_clear_flags(tfm, ~0);
708 if (template[i].wk)
Eric Biggers231baec2019-01-18 22:48:00 -0800709 crypto_aead_set_flags(tfm,
710 CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300711
712 if (template[i].klen > MAX_KEYLEN) {
713 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
714 d, j, algo, template[i].klen,
715 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +1000716 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300717 goto out;
718 }
719 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +1000720
Cristian Stoica05b1d332014-07-28 13:11:23 +0300721 ret = crypto_aead_setkey(tfm, key, template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +0800722 if (template[i].fail == !ret) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300723 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
724 d, j, algo, crypto_aead_get_flags(tfm));
725 goto out;
726 } else if (ret)
727 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800728
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800729 authsize = template[i].clen - template[i].plen;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300730 ret = crypto_aead_setauthsize(tfm, authsize);
731 if (ret) {
732 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
733 d, authsize, j, algo);
734 goto out;
735 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800736
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800737 k = !!template[i].alen;
738 sg_init_table(sg, k + 1);
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800739 sg_set_buf(&sg[0], assocbuf, template[i].alen);
740 sg_set_buf(&sg[k], inbuf, template[i].clen);
741 outbuf = inbuf;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800742
Cristian Stoica05b1d332014-07-28 13:11:23 +0300743 if (diff_dst) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800744 sg_init_table(sgout, k + 1);
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800745 sg_set_buf(&sgout[0], assocbuf, template[i].alen);
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800746
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800747 outbuf = xoutbuf[0] + align_offset;
748 sg_set_buf(&sgout[k], outbuf, template[i].clen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300749 }
750
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800751 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, inlen,
752 iv);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300753
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800754 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300755
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100756 ret = crypto_wait_req(enc ? crypto_aead_encrypt(req)
757 : crypto_aead_decrypt(req), &wait);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300758
759 switch (ret) {
760 case 0:
761 if (template[i].novrfy) {
762 /* verification was supposed to fail */
763 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
764 d, e, j, algo);
765 /* so really, we got a bad message */
766 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +0300767 goto out;
768 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300769 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300770 case -EBADMSG:
771 if (template[i].novrfy)
772 /* verification failure was expected */
773 continue;
774 /* fall through */
775 default:
776 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
777 d, e, j, algo, -ret);
778 goto out;
779 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800780
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800781 if (memcmp(outbuf, expected_output, outlen)) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300782 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
783 d, j, e, algo);
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800784 hexdump(outbuf, outlen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300785 ret = -EINVAL;
786 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800787 }
788 }
789
790 for (i = 0, j = 0; i < tcount; i++) {
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800791 const char *input, *expected_output;
792 unsigned int inlen, outlen;
793
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300794 /* alignment tests are only done with continuous buffers */
795 if (align_offset != 0)
796 break;
797
Cristian Stoica05b1d332014-07-28 13:11:23 +0300798 if (!template[i].np)
799 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800800
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800801 if (enc) {
802 if (template[i].novrfy)
803 continue;
804 input = template[i].ptext;
805 inlen = template[i].plen;
806 expected_output = template[i].ctext;
807 outlen = template[i].clen;
808 } else {
809 input = template[i].ctext;
810 inlen = template[i].clen;
811 expected_output = template[i].ptext;
812 outlen = template[i].plen;
813 }
Eric Biggers5bc3de52019-01-13 15:32:24 -0800814
Cristian Stoica05b1d332014-07-28 13:11:23 +0300815 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800816
Cristian Stoica05b1d332014-07-28 13:11:23 +0300817 if (template[i].iv)
Jerome Marchandabfa7f42016-02-03 13:58:12 +0100818 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300819 else
820 memset(iv, 0, MAX_IVLEN);
821
822 crypto_aead_clear_flags(tfm, ~0);
823 if (template[i].wk)
Eric Biggers231baec2019-01-18 22:48:00 -0800824 crypto_aead_set_flags(tfm,
825 CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300826 if (template[i].klen > MAX_KEYLEN) {
827 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
828 d, j, algo, template[i].klen, MAX_KEYLEN);
829 ret = -EINVAL;
830 goto out;
831 }
832 memcpy(key, template[i].key, template[i].klen);
833
834 ret = crypto_aead_setkey(tfm, key, template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +0800835 if (template[i].fail == !ret) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300836 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
837 d, j, algo, crypto_aead_get_flags(tfm));
838 goto out;
839 } else if (ret)
840 continue;
841
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800842 authsize = template[i].clen - template[i].plen;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300843
844 ret = -EINVAL;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800845 sg_init_table(sg, template[i].anp + template[i].np);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300846 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800847 sg_init_table(sgout, template[i].anp + template[i].np);
848
849 ret = -EINVAL;
850 for (k = 0, temp = 0; k < template[i].anp; k++) {
851 if (WARN_ON(offset_in_page(IDX[k]) +
852 template[i].atap[k] > PAGE_SIZE))
853 goto out;
854 sg_set_buf(&sg[k],
855 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
856 offset_in_page(IDX[k]),
857 template[i].assoc + temp,
858 template[i].atap[k]),
859 template[i].atap[k]);
860 if (diff_dst)
861 sg_set_buf(&sgout[k],
862 axbuf[IDX[k] >> PAGE_SHIFT] +
863 offset_in_page(IDX[k]),
864 template[i].atap[k]);
865 temp += template[i].atap[k];
866 }
867
Cristian Stoica05b1d332014-07-28 13:11:23 +0300868 for (k = 0, temp = 0; k < template[i].np; k++) {
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800869 n = template[i].tap[k];
870 if (k == template[i].np - 1 && !enc)
871 n += authsize;
872
873 if (WARN_ON(offset_in_page(IDX[k]) + n > PAGE_SIZE))
Cristian Stoica05b1d332014-07-28 13:11:23 +0300874 goto out;
875
876 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800877 memcpy(q, input + temp, n);
878 sg_set_buf(&sg[template[i].anp + k], q, n);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300879
880 if (diff_dst) {
881 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
882 offset_in_page(IDX[k]);
883
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800884 memset(q, 0, n);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300885
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800886 sg_set_buf(&sgout[template[i].anp + k], q, n);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300887 }
888
Cristian Stoica05b1d332014-07-28 13:11:23 +0300889 if (k == template[i].np - 1 && enc)
890 n += authsize;
891 if (offset_in_page(q) + n < PAGE_SIZE)
892 q[n] = 0;
893
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800894 temp += n;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300895 }
896
897 ret = crypto_aead_setauthsize(tfm, authsize);
898 if (ret) {
899 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
900 d, authsize, j, algo);
901 goto out;
902 }
903
904 if (enc) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800905 if (WARN_ON(sg[template[i].anp + k - 1].offset +
906 sg[template[i].anp + k - 1].length +
907 authsize > PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300908 ret = -EINVAL;
909 goto out;
910 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800911
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300912 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800913 sgout[template[i].anp + k - 1].length +=
914 authsize;
915 sg[template[i].anp + k - 1].length += authsize;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300916 }
917
918 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800919 inlen, iv);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300920
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800921 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300922
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100923 ret = crypto_wait_req(enc ? crypto_aead_encrypt(req)
924 : crypto_aead_decrypt(req), &wait);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300925
926 switch (ret) {
927 case 0:
928 if (template[i].novrfy) {
929 /* verification was supposed to fail */
930 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
931 d, e, j, algo);
932 /* so really, we got a bad message */
933 ret = -EBADMSG;
934 goto out;
935 }
936 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300937 case -EBADMSG:
938 if (template[i].novrfy)
939 /* verification failure was expected */
940 continue;
941 /* fall through */
942 default:
943 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
944 d, e, j, algo, -ret);
945 goto out;
946 }
947
948 ret = -EINVAL;
949 for (k = 0, temp = 0; k < template[i].np; k++) {
950 if (diff_dst)
951 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
952 offset_in_page(IDX[k]);
953 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800954 q = xbuf[IDX[k] >> PAGE_SHIFT] +
955 offset_in_page(IDX[k]);
956
Cristian Stoica05b1d332014-07-28 13:11:23 +0300957 n = template[i].tap[k];
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800958 if (k == template[i].np - 1 && enc)
959 n += authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800960
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800961 if (memcmp(q, expected_output + temp, n)) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300962 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
963 d, j, e, k, algo);
964 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800965 goto out;
966 }
967
Cristian Stoica05b1d332014-07-28 13:11:23 +0300968 q += n;
969 if (k == template[i].np - 1 && !enc) {
Eric Biggersa0d608ee2019-01-13 15:32:28 -0800970 if (!diff_dst && memcmp(q, input + temp + n,
971 authsize))
Cristian Stoica05b1d332014-07-28 13:11:23 +0300972 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200973 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300974 n = 0;
975 } else {
976 for (n = 0; offset_in_page(q + n) && q[n]; n++)
977 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800978 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300979 if (n) {
980 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
981 d, j, e, k, algo, n);
982 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800983 goto out;
984 }
985
Cristian Stoica05b1d332014-07-28 13:11:23 +0300986 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800987 }
988 }
989
990 ret = 0;
991
992out:
993 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300994 kfree(sg);
995out_nosg:
996 if (diff_dst)
997 testmgr_free_buf(xoutbuf);
998out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800999 testmgr_free_buf(axbuf);
1000out_noaxbuf:
1001 testmgr_free_buf(xbuf);
1002out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +03001003 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -07001004 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +08001005 return ret;
1006}
1007
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001008static int test_aead(struct crypto_aead *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001009 const struct aead_testvec *template, unsigned int tcount)
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001010{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +03001011 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001012 int ret;
1013
1014 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +03001015 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001016 if (ret)
1017 return ret;
1018
1019 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +03001020 ret = __test_aead(tfm, enc, template, tcount, true, 0);
1021 if (ret)
1022 return ret;
1023
1024 /* test unaligned buffers, check with one byte offset */
1025 ret = __test_aead(tfm, enc, template, tcount, true, 1);
1026 if (ret)
1027 return ret;
1028
1029 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1030 if (alignmask) {
1031 /* Check if alignment mask for tfm is correctly set. */
1032 ret = __test_aead(tfm, enc, template, tcount, true,
1033 alignmask + 1);
1034 if (ret)
1035 return ret;
1036 }
1037
1038 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001039}
1040
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001041static int test_cipher(struct crypto_cipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001042 const struct cipher_testvec *template,
1043 unsigned int tcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08001044{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001045 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
1046 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001047 char *q;
1048 const char *e;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001049 const char *input, *result;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001050 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001051 char *xbuf[XBUFSIZE];
1052 int ret = -ENOMEM;
1053
1054 if (testmgr_alloc_buf(xbuf))
1055 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001056
1057 if (enc == ENCRYPT)
1058 e = "encryption";
1059 else
1060 e = "decryption";
1061
1062 j = 0;
1063 for (i = 0; i < tcount; i++) {
1064 if (template[i].np)
1065 continue;
1066
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001067 if (fips_enabled && template[i].fips_skip)
1068 continue;
1069
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001070 input = enc ? template[i].ptext : template[i].ctext;
1071 result = enc ? template[i].ctext : template[i].ptext;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001072 j++;
1073
Herbert Xufd57f222009-05-29 16:05:42 +10001074 ret = -EINVAL;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001075 if (WARN_ON(template[i].len > PAGE_SIZE))
Herbert Xufd57f222009-05-29 16:05:42 +10001076 goto out;
1077
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001078 data = xbuf[0];
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001079 memcpy(data, input, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001080
1081 crypto_cipher_clear_flags(tfm, ~0);
1082 if (template[i].wk)
Eric Biggers231baec2019-01-18 22:48:00 -08001083 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001084
1085 ret = crypto_cipher_setkey(tfm, template[i].key,
1086 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001087 if (template[i].fail == !ret) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001088 printk(KERN_ERR "alg: cipher: setkey failed "
1089 "on test %d for %s: flags=%x\n", j,
1090 algo, crypto_cipher_get_flags(tfm));
1091 goto out;
1092 } else if (ret)
1093 continue;
1094
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001095 for (k = 0; k < template[i].len;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001096 k += crypto_cipher_blocksize(tfm)) {
1097 if (enc)
1098 crypto_cipher_encrypt_one(tfm, data + k,
1099 data + k);
1100 else
1101 crypto_cipher_decrypt_one(tfm, data + k,
1102 data + k);
1103 }
1104
1105 q = data;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001106 if (memcmp(q, result, template[i].len)) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001107 printk(KERN_ERR "alg: cipher: Test %d failed "
1108 "on %s for %s\n", j, e, algo);
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001109 hexdump(q, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001110 ret = -EINVAL;
1111 goto out;
1112 }
1113 }
1114
1115 ret = 0;
1116
1117out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001118 testmgr_free_buf(xbuf);
1119out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001120 return ret;
1121}
1122
Herbert Xu12773d92015-08-20 15:21:46 +08001123static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001124 const struct cipher_testvec *template,
1125 unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001126 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001127{
Herbert Xuda7f0332008-07-31 17:08:25 +08001128 const char *algo =
Herbert Xu12773d92015-08-20 15:21:46 +08001129 crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +08001130 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +08001131 char *q;
Herbert Xu12773d92015-08-20 15:21:46 +08001132 struct skcipher_request *req;
Herbert Xuda7f0332008-07-31 17:08:25 +08001133 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001134 struct scatterlist sgout[8];
1135 const char *e, *d;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001136 struct crypto_wait wait;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001137 const char *input, *result;
Herbert Xuda7f0332008-07-31 17:08:25 +08001138 void *data;
1139 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001140 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001141 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001142 int ret = -ENOMEM;
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001143 unsigned int ivsize = crypto_skcipher_ivsize(tfm);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001144
1145 if (testmgr_alloc_buf(xbuf))
1146 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +08001147
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001148 if (diff_dst && testmgr_alloc_buf(xoutbuf))
1149 goto out_nooutbuf;
1150
1151 if (diff_dst)
1152 d = "-ddst";
1153 else
1154 d = "";
1155
Herbert Xuda7f0332008-07-31 17:08:25 +08001156 if (enc == ENCRYPT)
1157 e = "encryption";
1158 else
1159 e = "decryption";
1160
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001161 crypto_init_wait(&wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001162
Herbert Xu12773d92015-08-20 15:21:46 +08001163 req = skcipher_request_alloc(tfm, GFP_KERNEL);
Herbert Xuda7f0332008-07-31 17:08:25 +08001164 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001165 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
1166 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +08001167 goto out;
1168 }
1169
Herbert Xu12773d92015-08-20 15:21:46 +08001170 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001171 crypto_req_done, &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001172
1173 j = 0;
1174 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001175 if (template[i].np && !template[i].also_non_np)
1176 continue;
1177
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001178 if (fips_enabled && template[i].fips_skip)
1179 continue;
1180
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001181 if (template[i].iv && !(template[i].generates_iv && enc))
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001182 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001183 else
1184 memset(iv, 0, MAX_IVLEN);
1185
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001186 input = enc ? template[i].ptext : template[i].ctext;
1187 result = enc ? template[i].ctext : template[i].ptext;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001188 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001189 ret = -EINVAL;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001190 if (WARN_ON(align_offset + template[i].len > PAGE_SIZE))
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001191 goto out;
1192
1193 data = xbuf[0];
1194 data += align_offset;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001195 memcpy(data, input, template[i].len);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001196
Herbert Xu12773d92015-08-20 15:21:46 +08001197 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001198 if (template[i].wk)
Eric Biggers231baec2019-01-18 22:48:00 -08001199 crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001200
Herbert Xu12773d92015-08-20 15:21:46 +08001201 ret = crypto_skcipher_setkey(tfm, template[i].key,
1202 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001203 if (template[i].fail == !ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001204 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001205 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001206 goto out;
1207 } else if (ret)
1208 continue;
1209
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001210 sg_init_one(&sg[0], data, template[i].len);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001211 if (diff_dst) {
1212 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001213 data += align_offset;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001214 sg_init_one(&sgout[0], data, template[i].len);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001215 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001216
Herbert Xu12773d92015-08-20 15:21:46 +08001217 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001218 template[i].len, iv);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001219 ret = crypto_wait_req(enc ? crypto_skcipher_encrypt(req) :
1220 crypto_skcipher_decrypt(req), &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001221
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001222 if (ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001223 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1224 d, e, j, algo, -ret);
1225 goto out;
1226 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001227
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001228 q = data;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001229 if (memcmp(q, result, template[i].len)) {
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001230 pr_err("alg: skcipher%s: Test %d failed (invalid result) on %s for %s\n",
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001231 d, j, e, algo);
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001232 hexdump(q, template[i].len);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001233 ret = -EINVAL;
1234 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001235 }
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001236
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001237 if (template[i].generates_iv && enc &&
1238 memcmp(iv, template[i].iv, crypto_skcipher_ivsize(tfm))) {
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001239 pr_err("alg: skcipher%s: Test %d failed (invalid output IV) on %s for %s\n",
1240 d, j, e, algo);
1241 hexdump(iv, crypto_skcipher_ivsize(tfm));
1242 ret = -EINVAL;
1243 goto out;
1244 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001245 }
1246
1247 j = 0;
1248 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001249 /* alignment tests are only done with continuous buffers */
1250 if (align_offset != 0)
1251 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001252
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001253 if (!template[i].np)
1254 continue;
1255
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001256 if (fips_enabled && template[i].fips_skip)
1257 continue;
1258
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001259 if (template[i].iv && !(template[i].generates_iv && enc))
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001260 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001261 else
1262 memset(iv, 0, MAX_IVLEN);
1263
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001264 input = enc ? template[i].ptext : template[i].ctext;
1265 result = enc ? template[i].ctext : template[i].ptext;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001266 j++;
Herbert Xu12773d92015-08-20 15:21:46 +08001267 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001268 if (template[i].wk)
Eric Biggers231baec2019-01-18 22:48:00 -08001269 crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001270
Herbert Xu12773d92015-08-20 15:21:46 +08001271 ret = crypto_skcipher_setkey(tfm, template[i].key,
1272 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001273 if (template[i].fail == !ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001274 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001275 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001276 goto out;
1277 } else if (ret)
1278 continue;
1279
1280 temp = 0;
1281 ret = -EINVAL;
1282 sg_init_table(sg, template[i].np);
1283 if (diff_dst)
1284 sg_init_table(sgout, template[i].np);
1285 for (k = 0; k < template[i].np; k++) {
1286 if (WARN_ON(offset_in_page(IDX[k]) +
1287 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001288 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001289
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001290 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1291
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001292 memcpy(q, input + temp, template[i].tap[k]);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001293
1294 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1295 q[template[i].tap[k]] = 0;
1296
1297 sg_set_buf(&sg[k], q, template[i].tap[k]);
1298 if (diff_dst) {
1299 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1300 offset_in_page(IDX[k]);
1301
1302 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1303
1304 memset(q, 0, template[i].tap[k]);
1305 if (offset_in_page(q) +
1306 template[i].tap[k] < PAGE_SIZE)
1307 q[template[i].tap[k]] = 0;
1308 }
1309
1310 temp += template[i].tap[k];
1311 }
1312
Herbert Xu12773d92015-08-20 15:21:46 +08001313 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001314 template[i].len, iv);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001315
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001316 ret = crypto_wait_req(enc ? crypto_skcipher_encrypt(req) :
1317 crypto_skcipher_decrypt(req), &wait);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001318
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001319 if (ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001320 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1321 d, e, j, algo, -ret);
1322 goto out;
1323 }
1324
1325 temp = 0;
1326 ret = -EINVAL;
1327 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001328 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001329 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1330 offset_in_page(IDX[k]);
1331 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001332 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1333 offset_in_page(IDX[k]);
1334
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001335 if (memcmp(q, result + temp, template[i].tap[k])) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001336 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1337 d, j, e, k, algo);
1338 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001339 goto out;
1340 }
1341
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001342 q += template[i].tap[k];
1343 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1344 ;
1345 if (n) {
1346 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1347 d, j, e, k, algo, n);
1348 hexdump(q, n);
1349 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001350 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001351 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001352 }
1353 }
1354
1355 ret = 0;
1356
1357out:
Herbert Xu12773d92015-08-20 15:21:46 +08001358 skcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001359 if (diff_dst)
1360 testmgr_free_buf(xoutbuf);
1361out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001362 testmgr_free_buf(xbuf);
1363out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001364 return ret;
1365}
1366
Herbert Xu12773d92015-08-20 15:21:46 +08001367static int test_skcipher(struct crypto_skcipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001368 const struct cipher_testvec *template,
1369 unsigned int tcount)
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001370{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001371 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001372 int ret;
1373
1374 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001375 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001376 if (ret)
1377 return ret;
1378
1379 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001380 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1381 if (ret)
1382 return ret;
1383
1384 /* test unaligned buffers, check with one byte offset */
1385 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1386 if (ret)
1387 return ret;
1388
1389 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1390 if (alignmask) {
1391 /* Check if alignment mask for tfm is correctly set. */
1392 ret = __test_skcipher(tfm, enc, template, tcount, true,
1393 alignmask + 1);
1394 if (ret)
1395 return ret;
1396 }
1397
1398 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001399}
1400
Eric Biggersb13b1e02017-02-24 15:46:59 -08001401static int test_comp(struct crypto_comp *tfm,
1402 const struct comp_testvec *ctemplate,
1403 const struct comp_testvec *dtemplate,
1404 int ctcount, int dtcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08001405{
1406 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
Mahipal Challa33607382018-04-11 20:28:32 +02001407 char *output, *decomp_output;
Herbert Xuda7f0332008-07-31 17:08:25 +08001408 unsigned int i;
Herbert Xuda7f0332008-07-31 17:08:25 +08001409 int ret;
1410
Mahipal Challa33607382018-04-11 20:28:32 +02001411 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1412 if (!output)
1413 return -ENOMEM;
1414
1415 decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1416 if (!decomp_output) {
1417 kfree(output);
1418 return -ENOMEM;
1419 }
1420
Herbert Xuda7f0332008-07-31 17:08:25 +08001421 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001422 int ilen;
1423 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001424
Michael Schupikov22a81182018-10-07 13:58:10 +02001425 memset(output, 0, COMP_BUF_SIZE);
1426 memset(decomp_output, 0, COMP_BUF_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +08001427
1428 ilen = ctemplate[i].inlen;
1429 ret = crypto_comp_compress(tfm, ctemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02001430 ilen, output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001431 if (ret) {
1432 printk(KERN_ERR "alg: comp: compression failed "
1433 "on test %d for %s: ret=%d\n", i + 1, algo,
1434 -ret);
1435 goto out;
1436 }
1437
Mahipal Challa33607382018-04-11 20:28:32 +02001438 ilen = dlen;
1439 dlen = COMP_BUF_SIZE;
1440 ret = crypto_comp_decompress(tfm, output,
1441 ilen, decomp_output, &dlen);
1442 if (ret) {
1443 pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n",
1444 i + 1, algo, -ret);
1445 goto out;
1446 }
1447
1448 if (dlen != ctemplate[i].inlen) {
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001449 printk(KERN_ERR "alg: comp: Compression test %d "
1450 "failed for %s: output len = %d\n", i + 1, algo,
1451 dlen);
1452 ret = -EINVAL;
1453 goto out;
1454 }
1455
Mahipal Challa33607382018-04-11 20:28:32 +02001456 if (memcmp(decomp_output, ctemplate[i].input,
1457 ctemplate[i].inlen)) {
1458 pr_err("alg: comp: compression failed: output differs: on test %d for %s\n",
1459 i + 1, algo);
1460 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001461 ret = -EINVAL;
1462 goto out;
1463 }
1464 }
1465
1466 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001467 int ilen;
1468 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001469
Michael Schupikov22a81182018-10-07 13:58:10 +02001470 memset(decomp_output, 0, COMP_BUF_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +08001471
1472 ilen = dtemplate[i].inlen;
1473 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02001474 ilen, decomp_output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001475 if (ret) {
1476 printk(KERN_ERR "alg: comp: decompression failed "
1477 "on test %d for %s: ret=%d\n", i + 1, algo,
1478 -ret);
1479 goto out;
1480 }
1481
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001482 if (dlen != dtemplate[i].outlen) {
1483 printk(KERN_ERR "alg: comp: Decompression test %d "
1484 "failed for %s: output len = %d\n", i + 1, algo,
1485 dlen);
1486 ret = -EINVAL;
1487 goto out;
1488 }
1489
Mahipal Challa33607382018-04-11 20:28:32 +02001490 if (memcmp(decomp_output, dtemplate[i].output, dlen)) {
Herbert Xuda7f0332008-07-31 17:08:25 +08001491 printk(KERN_ERR "alg: comp: Decompression test %d "
1492 "failed for %s\n", i + 1, algo);
Mahipal Challa33607382018-04-11 20:28:32 +02001493 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001494 ret = -EINVAL;
1495 goto out;
1496 }
1497 }
1498
1499 ret = 0;
1500
1501out:
Mahipal Challa33607382018-04-11 20:28:32 +02001502 kfree(decomp_output);
1503 kfree(output);
Herbert Xuda7f0332008-07-31 17:08:25 +08001504 return ret;
1505}
1506
Eric Biggersb13b1e02017-02-24 15:46:59 -08001507static int test_acomp(struct crypto_acomp *tfm,
Mahipal Challa33607382018-04-11 20:28:32 +02001508 const struct comp_testvec *ctemplate,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001509 const struct comp_testvec *dtemplate,
1510 int ctcount, int dtcount)
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001511{
1512 const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
1513 unsigned int i;
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001514 char *output, *decomp_out;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001515 int ret;
1516 struct scatterlist src, dst;
1517 struct acomp_req *req;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001518 struct crypto_wait wait;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001519
Eric Biggerseb095592016-11-23 10:24:35 -08001520 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1521 if (!output)
1522 return -ENOMEM;
1523
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001524 decomp_out = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1525 if (!decomp_out) {
1526 kfree(output);
1527 return -ENOMEM;
1528 }
1529
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001530 for (i = 0; i < ctcount; i++) {
1531 unsigned int dlen = COMP_BUF_SIZE;
1532 int ilen = ctemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08001533 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001534
Eric Biggersd2110222016-12-30 14:12:00 -06001535 input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08001536 if (!input_vec) {
1537 ret = -ENOMEM;
1538 goto out;
1539 }
1540
Eric Biggerseb095592016-11-23 10:24:35 -08001541 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001542 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08001543 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001544 sg_init_one(&dst, output, dlen);
1545
1546 req = acomp_request_alloc(tfm);
1547 if (!req) {
1548 pr_err("alg: acomp: request alloc failed for %s\n",
1549 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08001550 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001551 ret = -ENOMEM;
1552 goto out;
1553 }
1554
1555 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1556 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001557 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001558
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001559 ret = crypto_wait_req(crypto_acomp_compress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001560 if (ret) {
1561 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
1562 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08001563 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001564 acomp_request_free(req);
1565 goto out;
1566 }
1567
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001568 ilen = req->dlen;
1569 dlen = COMP_BUF_SIZE;
1570 sg_init_one(&src, output, ilen);
1571 sg_init_one(&dst, decomp_out, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001572 crypto_init_wait(&wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001573 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1574
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001575 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001576 if (ret) {
1577 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
1578 i + 1, algo, -ret);
1579 kfree(input_vec);
1580 acomp_request_free(req);
1581 goto out;
1582 }
1583
1584 if (req->dlen != ctemplate[i].inlen) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001585 pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
1586 i + 1, algo, req->dlen);
1587 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001588 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001589 acomp_request_free(req);
1590 goto out;
1591 }
1592
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001593 if (memcmp(input_vec, decomp_out, req->dlen)) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001594 pr_err("alg: acomp: Compression test %d failed for %s\n",
1595 i + 1, algo);
1596 hexdump(output, req->dlen);
1597 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001598 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001599 acomp_request_free(req);
1600 goto out;
1601 }
1602
Laura Abbott02608e02016-12-21 12:32:54 -08001603 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001604 acomp_request_free(req);
1605 }
1606
1607 for (i = 0; i < dtcount; i++) {
1608 unsigned int dlen = COMP_BUF_SIZE;
1609 int ilen = dtemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08001610 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001611
Eric Biggersd2110222016-12-30 14:12:00 -06001612 input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08001613 if (!input_vec) {
1614 ret = -ENOMEM;
1615 goto out;
1616 }
1617
Eric Biggerseb095592016-11-23 10:24:35 -08001618 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001619 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08001620 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001621 sg_init_one(&dst, output, dlen);
1622
1623 req = acomp_request_alloc(tfm);
1624 if (!req) {
1625 pr_err("alg: acomp: request alloc failed for %s\n",
1626 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08001627 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001628 ret = -ENOMEM;
1629 goto out;
1630 }
1631
1632 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1633 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001634 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001635
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001636 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001637 if (ret) {
1638 pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
1639 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08001640 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001641 acomp_request_free(req);
1642 goto out;
1643 }
1644
1645 if (req->dlen != dtemplate[i].outlen) {
1646 pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
1647 i + 1, algo, req->dlen);
1648 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001649 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001650 acomp_request_free(req);
1651 goto out;
1652 }
1653
1654 if (memcmp(output, dtemplate[i].output, req->dlen)) {
1655 pr_err("alg: acomp: Decompression test %d failed for %s\n",
1656 i + 1, algo);
1657 hexdump(output, req->dlen);
1658 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001659 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001660 acomp_request_free(req);
1661 goto out;
1662 }
1663
Laura Abbott02608e02016-12-21 12:32:54 -08001664 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001665 acomp_request_free(req);
1666 }
1667
1668 ret = 0;
1669
1670out:
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001671 kfree(decomp_out);
Eric Biggerseb095592016-11-23 10:24:35 -08001672 kfree(output);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001673 return ret;
1674}
1675
Eric Biggersb13b1e02017-02-24 15:46:59 -08001676static int test_cprng(struct crypto_rng *tfm,
1677 const struct cprng_testvec *template,
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001678 unsigned int tcount)
1679{
1680 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001681 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001682 u8 *seed;
1683 char result[32];
1684
1685 seedsize = crypto_rng_seedsize(tfm);
1686
1687 seed = kmalloc(seedsize, GFP_KERNEL);
1688 if (!seed) {
1689 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1690 "for %s\n", algo);
1691 return -ENOMEM;
1692 }
1693
1694 for (i = 0; i < tcount; i++) {
1695 memset(result, 0, 32);
1696
1697 memcpy(seed, template[i].v, template[i].vlen);
1698 memcpy(seed + template[i].vlen, template[i].key,
1699 template[i].klen);
1700 memcpy(seed + template[i].vlen + template[i].klen,
1701 template[i].dt, template[i].dtlen);
1702
1703 err = crypto_rng_reset(tfm, seed, seedsize);
1704 if (err) {
1705 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1706 "for %s\n", algo);
1707 goto out;
1708 }
1709
1710 for (j = 0; j < template[i].loops; j++) {
1711 err = crypto_rng_get_bytes(tfm, result,
1712 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01001713 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001714 printk(KERN_ERR "alg: cprng: Failed to obtain "
1715 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01001716 "%s (requested %d)\n", algo,
1717 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001718 goto out;
1719 }
1720 }
1721
1722 err = memcmp(result, template[i].result,
1723 template[i].rlen);
1724 if (err) {
1725 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1726 i, algo);
1727 hexdump(result, template[i].rlen);
1728 err = -EINVAL;
1729 goto out;
1730 }
1731 }
1732
1733out:
1734 kfree(seed);
1735 return err;
1736}
1737
Herbert Xuda7f0332008-07-31 17:08:25 +08001738static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1739 u32 type, u32 mask)
1740{
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001741 const struct aead_test_suite *suite = &desc->suite.aead;
Herbert Xuda7f0332008-07-31 17:08:25 +08001742 struct crypto_aead *tfm;
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001743 int err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001744
Herbert Xueed93e02016-11-22 20:08:31 +08001745 tfm = crypto_alloc_aead(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001746 if (IS_ERR(tfm)) {
1747 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1748 "%ld\n", driver, PTR_ERR(tfm));
1749 return PTR_ERR(tfm);
1750 }
1751
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001752 err = test_aead(tfm, ENCRYPT, suite->vecs, suite->count);
1753 if (!err)
1754 err = test_aead(tfm, DECRYPT, suite->vecs, suite->count);
Herbert Xuda7f0332008-07-31 17:08:25 +08001755
Herbert Xuda7f0332008-07-31 17:08:25 +08001756 crypto_free_aead(tfm);
1757 return err;
1758}
1759
1760static int alg_test_cipher(const struct alg_test_desc *desc,
1761 const char *driver, u32 type, u32 mask)
1762{
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001763 const struct cipher_test_suite *suite = &desc->suite.cipher;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001764 struct crypto_cipher *tfm;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001765 int err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001766
Herbert Xueed93e02016-11-22 20:08:31 +08001767 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001768 if (IS_ERR(tfm)) {
1769 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1770 "%s: %ld\n", driver, PTR_ERR(tfm));
1771 return PTR_ERR(tfm);
1772 }
1773
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001774 err = test_cipher(tfm, ENCRYPT, suite->vecs, suite->count);
1775 if (!err)
1776 err = test_cipher(tfm, DECRYPT, suite->vecs, suite->count);
Herbert Xuda7f0332008-07-31 17:08:25 +08001777
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001778 crypto_free_cipher(tfm);
1779 return err;
1780}
1781
1782static int alg_test_skcipher(const struct alg_test_desc *desc,
1783 const char *driver, u32 type, u32 mask)
1784{
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001785 const struct cipher_test_suite *suite = &desc->suite.cipher;
Herbert Xu12773d92015-08-20 15:21:46 +08001786 struct crypto_skcipher *tfm;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001787 int err;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001788
Herbert Xueed93e02016-11-22 20:08:31 +08001789 tfm = crypto_alloc_skcipher(driver, type, mask);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001790 if (IS_ERR(tfm)) {
1791 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1792 "%s: %ld\n", driver, PTR_ERR(tfm));
1793 return PTR_ERR(tfm);
1794 }
1795
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001796 err = test_skcipher(tfm, ENCRYPT, suite->vecs, suite->count);
1797 if (!err)
1798 err = test_skcipher(tfm, DECRYPT, suite->vecs, suite->count);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001799
Herbert Xu12773d92015-08-20 15:21:46 +08001800 crypto_free_skcipher(tfm);
Herbert Xuda7f0332008-07-31 17:08:25 +08001801 return err;
1802}
1803
1804static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1805 u32 type, u32 mask)
1806{
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001807 struct crypto_comp *comp;
1808 struct crypto_acomp *acomp;
Herbert Xuda7f0332008-07-31 17:08:25 +08001809 int err;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001810 u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
Herbert Xuda7f0332008-07-31 17:08:25 +08001811
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001812 if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
1813 acomp = crypto_alloc_acomp(driver, type, mask);
1814 if (IS_ERR(acomp)) {
1815 pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
1816 driver, PTR_ERR(acomp));
1817 return PTR_ERR(acomp);
1818 }
1819 err = test_acomp(acomp, desc->suite.comp.comp.vecs,
1820 desc->suite.comp.decomp.vecs,
1821 desc->suite.comp.comp.count,
1822 desc->suite.comp.decomp.count);
1823 crypto_free_acomp(acomp);
1824 } else {
1825 comp = crypto_alloc_comp(driver, type, mask);
1826 if (IS_ERR(comp)) {
1827 pr_err("alg: comp: Failed to load transform for %s: %ld\n",
1828 driver, PTR_ERR(comp));
1829 return PTR_ERR(comp);
1830 }
1831
1832 err = test_comp(comp, desc->suite.comp.comp.vecs,
1833 desc->suite.comp.decomp.vecs,
1834 desc->suite.comp.comp.count,
1835 desc->suite.comp.decomp.count);
1836
1837 crypto_free_comp(comp);
Herbert Xuda7f0332008-07-31 17:08:25 +08001838 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001839 return err;
1840}
1841
Eric Biggers9b3abc0162018-05-19 22:07:41 -07001842static int __alg_test_hash(const struct hash_testvec *template,
1843 unsigned int tcount, const char *driver,
1844 u32 type, u32 mask)
Herbert Xuda7f0332008-07-31 17:08:25 +08001845{
1846 struct crypto_ahash *tfm;
1847 int err;
1848
Herbert Xueed93e02016-11-22 20:08:31 +08001849 tfm = crypto_alloc_ahash(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001850 if (IS_ERR(tfm)) {
1851 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1852 "%ld\n", driver, PTR_ERR(tfm));
1853 return PTR_ERR(tfm);
1854 }
1855
Gilad Ben-Yossef76715092018-07-01 08:02:35 +01001856 err = test_hash(tfm, template, tcount, HASH_TEST_DIGEST);
David S. Millera8f1a052010-05-19 14:12:03 +10001857 if (!err)
Gilad Ben-Yossef76715092018-07-01 08:02:35 +01001858 err = test_hash(tfm, template, tcount, HASH_TEST_FINAL);
1859 if (!err)
1860 err = test_hash(tfm, template, tcount, HASH_TEST_FINUP);
Herbert Xuda7f0332008-07-31 17:08:25 +08001861 crypto_free_ahash(tfm);
1862 return err;
1863}
1864
Eric Biggers9b3abc0162018-05-19 22:07:41 -07001865static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1866 u32 type, u32 mask)
1867{
1868 const struct hash_testvec *template = desc->suite.hash.vecs;
1869 unsigned int tcount = desc->suite.hash.count;
1870 unsigned int nr_unkeyed, nr_keyed;
1871 int err;
1872
1873 /*
1874 * For OPTIONAL_KEY algorithms, we have to do all the unkeyed tests
1875 * first, before setting a key on the tfm. To make this easier, we
1876 * require that the unkeyed test vectors (if any) are listed first.
1877 */
1878
1879 for (nr_unkeyed = 0; nr_unkeyed < tcount; nr_unkeyed++) {
1880 if (template[nr_unkeyed].ksize)
1881 break;
1882 }
1883 for (nr_keyed = 0; nr_unkeyed + nr_keyed < tcount; nr_keyed++) {
1884 if (!template[nr_unkeyed + nr_keyed].ksize) {
1885 pr_err("alg: hash: test vectors for %s out of order, "
1886 "unkeyed ones must come first\n", desc->alg);
1887 return -EINVAL;
1888 }
1889 }
1890
1891 err = 0;
1892 if (nr_unkeyed) {
1893 err = __alg_test_hash(template, nr_unkeyed, driver, type, mask);
1894 template += nr_unkeyed;
1895 }
1896
1897 if (!err && nr_keyed)
1898 err = __alg_test_hash(template, nr_keyed, driver, type, mask);
1899
1900 return err;
1901}
1902
Herbert Xu8e3ee852008-11-07 14:58:52 +08001903static int alg_test_crc32c(const struct alg_test_desc *desc,
1904 const char *driver, u32 type, u32 mask)
1905{
1906 struct crypto_shash *tfm;
Eric Biggerscb9dde82019-01-10 12:17:55 -08001907 __le32 val;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001908 int err;
1909
1910 err = alg_test_hash(desc, driver, type, mask);
1911 if (err)
Eric Biggerseb5e6732019-01-23 20:57:35 -08001912 return err;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001913
Herbert Xueed93e02016-11-22 20:08:31 +08001914 tfm = crypto_alloc_shash(driver, type, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001915 if (IS_ERR(tfm)) {
Eric Biggerseb5e6732019-01-23 20:57:35 -08001916 if (PTR_ERR(tfm) == -ENOENT) {
1917 /*
1918 * This crc32c implementation is only available through
1919 * ahash API, not the shash API, so the remaining part
1920 * of the test is not applicable to it.
1921 */
1922 return 0;
1923 }
Herbert Xu8e3ee852008-11-07 14:58:52 +08001924 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1925 "%ld\n", driver, PTR_ERR(tfm));
Eric Biggerseb5e6732019-01-23 20:57:35 -08001926 return PTR_ERR(tfm);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001927 }
1928
1929 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001930 SHASH_DESC_ON_STACK(shash, tfm);
1931 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001932
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001933 shash->tfm = tfm;
1934 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001935
Eric Biggerscb9dde82019-01-10 12:17:55 -08001936 *ctx = 420553207;
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001937 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001938 if (err) {
1939 printk(KERN_ERR "alg: crc32c: Operation failed for "
1940 "%s: %d\n", driver, err);
1941 break;
1942 }
1943
Eric Biggerscb9dde82019-01-10 12:17:55 -08001944 if (val != cpu_to_le32(~420553207)) {
1945 pr_err("alg: crc32c: Test failed for %s: %u\n",
1946 driver, le32_to_cpu(val));
Herbert Xu8e3ee852008-11-07 14:58:52 +08001947 err = -EINVAL;
1948 }
1949 } while (0);
1950
1951 crypto_free_shash(tfm);
1952
Herbert Xu8e3ee852008-11-07 14:58:52 +08001953 return err;
1954}
1955
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001956static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1957 u32 type, u32 mask)
1958{
1959 struct crypto_rng *rng;
1960 int err;
1961
Herbert Xueed93e02016-11-22 20:08:31 +08001962 rng = crypto_alloc_rng(driver, type, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001963 if (IS_ERR(rng)) {
1964 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1965 "%ld\n", driver, PTR_ERR(rng));
1966 return PTR_ERR(rng);
1967 }
1968
1969 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1970
1971 crypto_free_rng(rng);
1972
1973 return err;
1974}
1975
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001976
Eric Biggersb13b1e02017-02-24 15:46:59 -08001977static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001978 const char *driver, u32 type, u32 mask)
1979{
1980 int ret = -EAGAIN;
1981 struct crypto_rng *drng;
1982 struct drbg_test_data test_data;
1983 struct drbg_string addtl, pers, testentropy;
1984 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1985
1986 if (!buf)
1987 return -ENOMEM;
1988
Herbert Xueed93e02016-11-22 20:08:31 +08001989 drng = crypto_alloc_rng(driver, type, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001990 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001991 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001992 "%s\n", driver);
1993 kzfree(buf);
1994 return -ENOMEM;
1995 }
1996
1997 test_data.testentropy = &testentropy;
1998 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1999 drbg_string_fill(&pers, test->pers, test->perslen);
2000 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
2001 if (ret) {
2002 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
2003 goto outbuf;
2004 }
2005
2006 drbg_string_fill(&addtl, test->addtla, test->addtllen);
2007 if (pr) {
2008 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
2009 ret = crypto_drbg_get_bytes_addtl_test(drng,
2010 buf, test->expectedlen, &addtl, &test_data);
2011 } else {
2012 ret = crypto_drbg_get_bytes_addtl(drng,
2013 buf, test->expectedlen, &addtl);
2014 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01002015 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002016 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002017 "driver %s\n", driver);
2018 goto outbuf;
2019 }
2020
2021 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
2022 if (pr) {
2023 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
2024 ret = crypto_drbg_get_bytes_addtl_test(drng,
2025 buf, test->expectedlen, &addtl, &test_data);
2026 } else {
2027 ret = crypto_drbg_get_bytes_addtl(drng,
2028 buf, test->expectedlen, &addtl);
2029 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01002030 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002031 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002032 "driver %s\n", driver);
2033 goto outbuf;
2034 }
2035
2036 ret = memcmp(test->expected, buf, test->expectedlen);
2037
2038outbuf:
2039 crypto_free_rng(drng);
2040 kzfree(buf);
2041 return ret;
2042}
2043
2044
2045static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
2046 u32 type, u32 mask)
2047{
2048 int err = 0;
2049 int pr = 0;
2050 int i = 0;
Eric Biggersb13b1e02017-02-24 15:46:59 -08002051 const struct drbg_testvec *template = desc->suite.drbg.vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002052 unsigned int tcount = desc->suite.drbg.count;
2053
2054 if (0 == memcmp(driver, "drbg_pr_", 8))
2055 pr = 1;
2056
2057 for (i = 0; i < tcount; i++) {
2058 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
2059 if (err) {
2060 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
2061 i, driver);
2062 err = -EINVAL;
2063 break;
2064 }
2065 }
2066 return err;
2067
2068}
2069
Eric Biggersb13b1e02017-02-24 15:46:59 -08002070static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002071 const char *alg)
2072{
2073 struct kpp_request *req;
2074 void *input_buf = NULL;
2075 void *output_buf = NULL;
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002076 void *a_public = NULL;
2077 void *a_ss = NULL;
2078 void *shared_secret = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002079 struct crypto_wait wait;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002080 unsigned int out_len_max;
2081 int err = -ENOMEM;
2082 struct scatterlist src, dst;
2083
2084 req = kpp_request_alloc(tfm, GFP_KERNEL);
2085 if (!req)
2086 return err;
2087
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002088 crypto_init_wait(&wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002089
2090 err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
2091 if (err < 0)
2092 goto free_req;
2093
2094 out_len_max = crypto_kpp_maxsize(tfm);
2095 output_buf = kzalloc(out_len_max, GFP_KERNEL);
2096 if (!output_buf) {
2097 err = -ENOMEM;
2098 goto free_req;
2099 }
2100
2101 /* Use appropriate parameter as base */
2102 kpp_request_set_input(req, NULL, 0);
2103 sg_init_one(&dst, output_buf, out_len_max);
2104 kpp_request_set_output(req, &dst, out_len_max);
2105 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002106 crypto_req_done, &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002107
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002108 /* Compute party A's public key */
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002109 err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002110 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002111 pr_err("alg: %s: Party A: generate public key test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002112 alg, err);
2113 goto free_output;
2114 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002115
2116 if (vec->genkey) {
2117 /* Save party A's public key */
2118 a_public = kzalloc(out_len_max, GFP_KERNEL);
2119 if (!a_public) {
2120 err = -ENOMEM;
2121 goto free_output;
2122 }
2123 memcpy(a_public, sg_virt(req->dst), out_len_max);
2124 } else {
2125 /* Verify calculated public key */
2126 if (memcmp(vec->expected_a_public, sg_virt(req->dst),
2127 vec->expected_a_public_size)) {
2128 pr_err("alg: %s: Party A: generate public key test failed. Invalid output\n",
2129 alg);
2130 err = -EINVAL;
2131 goto free_output;
2132 }
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002133 }
2134
2135 /* Calculate shared secret key by using counter part (b) public key. */
2136 input_buf = kzalloc(vec->b_public_size, GFP_KERNEL);
2137 if (!input_buf) {
2138 err = -ENOMEM;
2139 goto free_output;
2140 }
2141
2142 memcpy(input_buf, vec->b_public, vec->b_public_size);
2143 sg_init_one(&src, input_buf, vec->b_public_size);
2144 sg_init_one(&dst, output_buf, out_len_max);
2145 kpp_request_set_input(req, &src, vec->b_public_size);
2146 kpp_request_set_output(req, &dst, out_len_max);
2147 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002148 crypto_req_done, &wait);
2149 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002150 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002151 pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002152 alg, err);
2153 goto free_all;
2154 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002155
2156 if (vec->genkey) {
2157 /* Save the shared secret obtained by party A */
2158 a_ss = kzalloc(vec->expected_ss_size, GFP_KERNEL);
2159 if (!a_ss) {
2160 err = -ENOMEM;
2161 goto free_all;
2162 }
2163 memcpy(a_ss, sg_virt(req->dst), vec->expected_ss_size);
2164
2165 /*
2166 * Calculate party B's shared secret by using party A's
2167 * public key.
2168 */
2169 err = crypto_kpp_set_secret(tfm, vec->b_secret,
2170 vec->b_secret_size);
2171 if (err < 0)
2172 goto free_all;
2173
2174 sg_init_one(&src, a_public, vec->expected_a_public_size);
2175 sg_init_one(&dst, output_buf, out_len_max);
2176 kpp_request_set_input(req, &src, vec->expected_a_public_size);
2177 kpp_request_set_output(req, &dst, out_len_max);
2178 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002179 crypto_req_done, &wait);
2180 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req),
2181 &wait);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002182 if (err) {
2183 pr_err("alg: %s: Party B: compute shared secret failed. err %d\n",
2184 alg, err);
2185 goto free_all;
2186 }
2187
2188 shared_secret = a_ss;
2189 } else {
2190 shared_secret = (void *)vec->expected_ss;
2191 }
2192
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002193 /*
2194 * verify shared secret from which the user will derive
2195 * secret key by executing whatever hash it has chosen
2196 */
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002197 if (memcmp(shared_secret, sg_virt(req->dst),
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002198 vec->expected_ss_size)) {
2199 pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
2200 alg);
2201 err = -EINVAL;
2202 }
2203
2204free_all:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002205 kfree(a_ss);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002206 kfree(input_buf);
2207free_output:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002208 kfree(a_public);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002209 kfree(output_buf);
2210free_req:
2211 kpp_request_free(req);
2212 return err;
2213}
2214
2215static int test_kpp(struct crypto_kpp *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002216 const struct kpp_testvec *vecs, unsigned int tcount)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002217{
2218 int ret, i;
2219
2220 for (i = 0; i < tcount; i++) {
2221 ret = do_test_kpp(tfm, vecs++, alg);
2222 if (ret) {
2223 pr_err("alg: %s: test failed on vector %d, err=%d\n",
2224 alg, i + 1, ret);
2225 return ret;
2226 }
2227 }
2228 return 0;
2229}
2230
2231static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
2232 u32 type, u32 mask)
2233{
2234 struct crypto_kpp *tfm;
2235 int err = 0;
2236
Herbert Xueed93e02016-11-22 20:08:31 +08002237 tfm = crypto_alloc_kpp(driver, type, mask);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002238 if (IS_ERR(tfm)) {
2239 pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
2240 driver, PTR_ERR(tfm));
2241 return PTR_ERR(tfm);
2242 }
2243 if (desc->suite.kpp.vecs)
2244 err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
2245 desc->suite.kpp.count);
2246
2247 crypto_free_kpp(tfm);
2248 return err;
2249}
2250
Herbert Xu50d2b6432016-06-29 19:32:20 +08002251static int test_akcipher_one(struct crypto_akcipher *tfm,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002252 const struct akcipher_testvec *vecs)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002253{
Herbert Xudf27b262016-05-05 16:42:49 +08002254 char *xbuf[XBUFSIZE];
Tadeusz Struk946cc462015-06-16 10:31:06 -07002255 struct akcipher_request *req;
2256 void *outbuf_enc = NULL;
2257 void *outbuf_dec = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002258 struct crypto_wait wait;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002259 unsigned int out_len_max, out_len = 0;
2260 int err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002261 struct scatterlist src, dst, src_tab[2];
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002262 const char *m, *c;
2263 unsigned int m_size, c_size;
2264 const char *op;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002265
Herbert Xudf27b262016-05-05 16:42:49 +08002266 if (testmgr_alloc_buf(xbuf))
2267 return err;
2268
Tadeusz Struk946cc462015-06-16 10:31:06 -07002269 req = akcipher_request_alloc(tfm, GFP_KERNEL);
2270 if (!req)
Herbert Xudf27b262016-05-05 16:42:49 +08002271 goto free_xbuf;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002272
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002273 crypto_init_wait(&wait);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002274
2275 if (vecs->public_key_vec)
2276 err = crypto_akcipher_set_pub_key(tfm, vecs->key,
2277 vecs->key_len);
2278 else
2279 err = crypto_akcipher_set_priv_key(tfm, vecs->key,
2280 vecs->key_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002281 if (err)
2282 goto free_req;
2283
Salvatore Benedetto57763f52016-07-04 10:52:34 +01002284 err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002285 out_len_max = crypto_akcipher_maxsize(tfm);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002286
2287 /*
2288 * First run test which do not require a private key, such as
2289 * encrypt or verify.
2290 */
Tadeusz Struk946cc462015-06-16 10:31:06 -07002291 outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
2292 if (!outbuf_enc)
2293 goto free_req;
2294
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002295 if (!vecs->siggen_sigver_test) {
2296 m = vecs->m;
2297 m_size = vecs->m_size;
2298 c = vecs->c;
2299 c_size = vecs->c_size;
2300 op = "encrypt";
2301 } else {
2302 /* Swap args so we could keep plaintext (digest)
2303 * in vecs->m, and cooked signature in vecs->c.
2304 */
2305 m = vecs->c; /* signature */
2306 m_size = vecs->c_size;
2307 c = vecs->m; /* digest */
2308 c_size = vecs->m_size;
2309 op = "verify";
2310 }
Herbert Xudf27b262016-05-05 16:42:49 +08002311
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002312 if (WARN_ON(m_size > PAGE_SIZE))
2313 goto free_all;
2314 memcpy(xbuf[0], m, m_size);
Herbert Xudf27b262016-05-05 16:42:49 +08002315
Tadeusz Struk22287b02015-10-08 09:26:55 -07002316 sg_init_table(src_tab, 2);
Herbert Xudf27b262016-05-05 16:42:49 +08002317 sg_set_buf(&src_tab[0], xbuf[0], 8);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002318 sg_set_buf(&src_tab[1], xbuf[0] + 8, m_size - 8);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002319 sg_init_one(&dst, outbuf_enc, out_len_max);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002320 akcipher_request_set_crypt(req, src_tab, &dst, m_size,
Tadeusz Struk22287b02015-10-08 09:26:55 -07002321 out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002322 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002323 crypto_req_done, &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002324
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002325 err = crypto_wait_req(vecs->siggen_sigver_test ?
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002326 /* Run asymmetric signature verification */
2327 crypto_akcipher_verify(req) :
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002328 /* Run asymmetric encrypt */
2329 crypto_akcipher_encrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002330 if (err) {
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002331 pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002332 goto free_all;
2333 }
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002334 if (req->dst_len != c_size) {
2335 pr_err("alg: akcipher: %s test failed. Invalid output len\n",
2336 op);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002337 err = -EINVAL;
2338 goto free_all;
2339 }
2340 /* verify that encrypted message is equal to expected */
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002341 if (memcmp(c, outbuf_enc, c_size)) {
2342 pr_err("alg: akcipher: %s test failed. Invalid output\n", op);
2343 hexdump(outbuf_enc, c_size);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002344 err = -EINVAL;
2345 goto free_all;
2346 }
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002347
2348 /*
2349 * Don't invoke (decrypt or sign) test which require a private key
2350 * for vectors with only a public key.
2351 */
Tadeusz Struk946cc462015-06-16 10:31:06 -07002352 if (vecs->public_key_vec) {
2353 err = 0;
2354 goto free_all;
2355 }
2356 outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
2357 if (!outbuf_dec) {
2358 err = -ENOMEM;
2359 goto free_all;
2360 }
Herbert Xudf27b262016-05-05 16:42:49 +08002361
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002362 op = vecs->siggen_sigver_test ? "sign" : "decrypt";
2363 if (WARN_ON(c_size > PAGE_SIZE))
Herbert Xudf27b262016-05-05 16:42:49 +08002364 goto free_all;
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002365 memcpy(xbuf[0], c, c_size);
Herbert Xudf27b262016-05-05 16:42:49 +08002366
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002367 sg_init_one(&src, xbuf[0], c_size);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002368 sg_init_one(&dst, outbuf_dec, out_len_max);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002369 crypto_init_wait(&wait);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002370 akcipher_request_set_crypt(req, &src, &dst, c_size, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002371
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002372 err = crypto_wait_req(vecs->siggen_sigver_test ?
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002373 /* Run asymmetric signature generation */
2374 crypto_akcipher_sign(req) :
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002375 /* Run asymmetric decrypt */
2376 crypto_akcipher_decrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002377 if (err) {
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002378 pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002379 goto free_all;
2380 }
2381 out_len = req->dst_len;
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002382 if (out_len < m_size) {
2383 pr_err("alg: akcipher: %s test failed. Invalid output len %u\n",
2384 op, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002385 err = -EINVAL;
2386 goto free_all;
2387 }
2388 /* verify that decrypted message is equal to the original msg */
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002389 if (memchr_inv(outbuf_dec, 0, out_len - m_size) ||
2390 memcmp(m, outbuf_dec + out_len - m_size, m_size)) {
2391 pr_err("alg: akcipher: %s test failed. Invalid output\n", op);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002392 hexdump(outbuf_dec, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002393 err = -EINVAL;
2394 }
2395free_all:
2396 kfree(outbuf_dec);
2397 kfree(outbuf_enc);
2398free_req:
2399 akcipher_request_free(req);
Herbert Xudf27b262016-05-05 16:42:49 +08002400free_xbuf:
2401 testmgr_free_buf(xbuf);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002402 return err;
2403}
2404
Herbert Xu50d2b6432016-06-29 19:32:20 +08002405static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002406 const struct akcipher_testvec *vecs,
2407 unsigned int tcount)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002408{
Herbert Xu15226e42016-07-18 18:20:10 +08002409 const char *algo =
2410 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
Tadeusz Struk946cc462015-06-16 10:31:06 -07002411 int ret, i;
2412
2413 for (i = 0; i < tcount; i++) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002414 ret = test_akcipher_one(tfm, vecs++);
2415 if (!ret)
2416 continue;
2417
Herbert Xu15226e42016-07-18 18:20:10 +08002418 pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
2419 i + 1, algo, ret);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002420 return ret;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002421 }
2422 return 0;
2423}
2424
Tadeusz Struk946cc462015-06-16 10:31:06 -07002425static int alg_test_akcipher(const struct alg_test_desc *desc,
2426 const char *driver, u32 type, u32 mask)
2427{
2428 struct crypto_akcipher *tfm;
2429 int err = 0;
2430
Herbert Xueed93e02016-11-22 20:08:31 +08002431 tfm = crypto_alloc_akcipher(driver, type, mask);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002432 if (IS_ERR(tfm)) {
2433 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
2434 driver, PTR_ERR(tfm));
2435 return PTR_ERR(tfm);
2436 }
2437 if (desc->suite.akcipher.vecs)
2438 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
2439 desc->suite.akcipher.count);
2440
2441 crypto_free_akcipher(tfm);
2442 return err;
2443}
2444
Youquan, Song863b5572009-12-23 19:45:20 +08002445static int alg_test_null(const struct alg_test_desc *desc,
2446 const char *driver, u32 type, u32 mask)
2447{
2448 return 0;
2449}
2450
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002451#define __VECS(tv) { .vecs = tv, .count = ARRAY_SIZE(tv) }
2452
Herbert Xuda7f0332008-07-31 17:08:25 +08002453/* Please keep this list sorted by algorithm name. */
2454static const struct alg_test_desc alg_test_descs[] = {
2455 {
Eric Biggers059c2a42018-11-16 17:26:31 -08002456 .alg = "adiantum(xchacha12,aes)",
2457 .test = alg_test_skcipher,
2458 .suite = {
2459 .cipher = __VECS(adiantum_xchacha12_aes_tv_template)
2460 },
2461 }, {
2462 .alg = "adiantum(xchacha20,aes)",
2463 .test = alg_test_skcipher,
2464 .suite = {
2465 .cipher = __VECS(adiantum_xchacha20_aes_tv_template)
2466 },
2467 }, {
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002468 .alg = "aegis128",
2469 .test = alg_test_aead,
2470 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002471 .aead = __VECS(aegis128_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002472 }
2473 }, {
2474 .alg = "aegis128l",
2475 .test = alg_test_aead,
2476 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002477 .aead = __VECS(aegis128l_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002478 }
2479 }, {
2480 .alg = "aegis256",
2481 .test = alg_test_aead,
2482 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002483 .aead = __VECS(aegis256_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002484 }
2485 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002486 .alg = "ansi_cprng",
2487 .test = alg_test_cprng,
2488 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002489 .cprng = __VECS(ansi_cprng_aes_tv_template)
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002490 }
2491 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002492 .alg = "authenc(hmac(md5),ecb(cipher_null))",
2493 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002494 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002495 .aead = __VECS(hmac_md5_ecb_cipher_null_tv_template)
Horia Geantabca4feb2014-03-14 17:46:51 +02002496 }
2497 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002498 .alg = "authenc(hmac(sha1),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002499 .test = alg_test_aead,
Herbert Xubcf741c2017-06-28 19:09:07 +08002500 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002501 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002502 .aead = __VECS(hmac_sha1_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302503 }
2504 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002505 .alg = "authenc(hmac(sha1),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302506 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302507 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002508 .aead = __VECS(hmac_sha1_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302509 }
2510 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002511 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302512 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002513 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302514 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002515 .aead = __VECS(hmac_sha1_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002516 }
2517 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002518 .alg = "authenc(hmac(sha1),ctr(aes))",
2519 .test = alg_test_null,
2520 .fips_allowed = 1,
2521 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002522 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
2523 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002524 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002525 .aead = __VECS(hmac_sha1_ecb_cipher_null_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302526 }
2527 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002528 .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
2529 .test = alg_test_null,
2530 .fips_allowed = 1,
2531 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002532 .alg = "authenc(hmac(sha224),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302533 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302534 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002535 .aead = __VECS(hmac_sha224_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302536 }
2537 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002538 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302539 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002540 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302541 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002542 .aead = __VECS(hmac_sha224_des3_ede_cbc_tv_temp)
Horia Geantabca4feb2014-03-14 17:46:51 +02002543 }
2544 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002545 .alg = "authenc(hmac(sha256),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002546 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002547 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002548 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002549 .aead = __VECS(hmac_sha256_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302550 }
2551 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002552 .alg = "authenc(hmac(sha256),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302553 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302554 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002555 .aead = __VECS(hmac_sha256_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302556 }
2557 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002558 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302559 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002560 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302561 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002562 .aead = __VECS(hmac_sha256_des3_ede_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302563 }
2564 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002565 .alg = "authenc(hmac(sha256),ctr(aes))",
2566 .test = alg_test_null,
2567 .fips_allowed = 1,
2568 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002569 .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
2570 .test = alg_test_null,
2571 .fips_allowed = 1,
2572 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002573 .alg = "authenc(hmac(sha384),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302574 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302575 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002576 .aead = __VECS(hmac_sha384_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302577 }
2578 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002579 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302580 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002581 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302582 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002583 .aead = __VECS(hmac_sha384_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002584 }
2585 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002586 .alg = "authenc(hmac(sha384),ctr(aes))",
2587 .test = alg_test_null,
2588 .fips_allowed = 1,
2589 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002590 .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
2591 .test = alg_test_null,
2592 .fips_allowed = 1,
2593 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002594 .alg = "authenc(hmac(sha512),cbc(aes))",
Marcus Meissnered1afac2016-02-05 14:23:33 +01002595 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002596 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002597 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002598 .aead = __VECS(hmac_sha512_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302599 }
2600 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002601 .alg = "authenc(hmac(sha512),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302602 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302603 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002604 .aead = __VECS(hmac_sha512_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302605 }
2606 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002607 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302608 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002609 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302610 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002611 .aead = __VECS(hmac_sha512_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002612 }
2613 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002614 .alg = "authenc(hmac(sha512),ctr(aes))",
2615 .test = alg_test_null,
2616 .fips_allowed = 1,
2617 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002618 .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
2619 .test = alg_test_null,
2620 .fips_allowed = 1,
2621 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002622 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002623 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002624 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002625 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002626 .cipher = __VECS(aes_cbc_tv_template)
2627 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002628 }, {
2629 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002630 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002631 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002632 .cipher = __VECS(anubis_cbc_tv_template)
2633 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002634 }, {
2635 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002636 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002637 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002638 .cipher = __VECS(bf_cbc_tv_template)
2639 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002640 }, {
2641 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002642 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002643 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002644 .cipher = __VECS(camellia_cbc_tv_template)
2645 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002646 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002647 .alg = "cbc(cast5)",
2648 .test = alg_test_skcipher,
2649 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002650 .cipher = __VECS(cast5_cbc_tv_template)
2651 },
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002652 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002653 .alg = "cbc(cast6)",
2654 .test = alg_test_skcipher,
2655 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002656 .cipher = __VECS(cast6_cbc_tv_template)
2657 },
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002658 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002659 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002660 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002661 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002662 .cipher = __VECS(des_cbc_tv_template)
2663 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002664 }, {
2665 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002666 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002667 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002668 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002669 .cipher = __VECS(des3_ede_cbc_tv_template)
2670 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002671 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01002672 /* Same as cbc(aes) except the key is stored in
2673 * hardware secure memory which we reference by index
2674 */
2675 .alg = "cbc(paes)",
2676 .test = alg_test_null,
2677 .fips_allowed = 1,
2678 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002679 .alg = "cbc(serpent)",
2680 .test = alg_test_skcipher,
2681 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002682 .cipher = __VECS(serpent_cbc_tv_template)
2683 },
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002684 }, {
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01002685 .alg = "cbc(sm4)",
2686 .test = alg_test_skcipher,
2687 .suite = {
2688 .cipher = __VECS(sm4_cbc_tv_template)
2689 }
2690 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002691 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002692 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002693 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002694 .cipher = __VECS(tf_cbc_tv_template)
2695 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002696 }, {
Ard Biesheuvel092acf02017-02-03 14:49:35 +00002697 .alg = "cbcmac(aes)",
2698 .fips_allowed = 1,
2699 .test = alg_test_hash,
2700 .suite = {
2701 .hash = __VECS(aes_cbcmac_tv_template)
2702 }
2703 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002704 .alg = "ccm(aes)",
2705 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002706 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002707 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002708 .aead = __VECS(aes_ccm_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002709 }
2710 }, {
Dmitry Eremin-Solenikov7da66672018-10-20 02:01:53 +03002711 .alg = "cfb(aes)",
2712 .test = alg_test_skcipher,
2713 .fips_allowed = 1,
2714 .suite = {
2715 .cipher = __VECS(aes_cfb_tv_template)
2716 },
2717 }, {
Martin Willi3590ebf2015-06-01 13:43:57 +02002718 .alg = "chacha20",
2719 .test = alg_test_skcipher,
2720 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002721 .cipher = __VECS(chacha20_tv_template)
2722 },
Martin Willi3590ebf2015-06-01 13:43:57 +02002723 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002724 .alg = "cmac(aes)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002725 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002726 .test = alg_test_hash,
2727 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002728 .hash = __VECS(aes_cmac128_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002729 }
2730 }, {
2731 .alg = "cmac(des3_ede)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002732 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002733 .test = alg_test_hash,
2734 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002735 .hash = __VECS(des3_ede_cmac64_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002736 }
2737 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002738 .alg = "compress_null",
2739 .test = alg_test_null,
2740 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02002741 .alg = "crc32",
2742 .test = alg_test_hash,
2743 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002744 .hash = __VECS(crc32_tv_template)
Ard Biesheuvelebb34722015-05-04 11:00:17 +02002745 }
2746 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002747 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002748 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002749 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002750 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002751 .hash = __VECS(crc32c_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002752 }
2753 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002754 .alg = "crct10dif",
2755 .test = alg_test_hash,
2756 .fips_allowed = 1,
2757 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002758 .hash = __VECS(crct10dif_tv_template)
Herbert Xu684115212013-09-07 12:56:26 +10002759 }
2760 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002761 .alg = "ctr(aes)",
2762 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002763 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002764 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002765 .cipher = __VECS(aes_ctr_tv_template)
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002766 }
2767 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002768 .alg = "ctr(blowfish)",
2769 .test = alg_test_skcipher,
2770 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002771 .cipher = __VECS(bf_ctr_tv_template)
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002772 }
2773 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002774 .alg = "ctr(camellia)",
2775 .test = alg_test_skcipher,
2776 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002777 .cipher = __VECS(camellia_ctr_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02002778 }
2779 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002780 .alg = "ctr(cast5)",
2781 .test = alg_test_skcipher,
2782 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002783 .cipher = __VECS(cast5_ctr_tv_template)
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002784 }
2785 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002786 .alg = "ctr(cast6)",
2787 .test = alg_test_skcipher,
2788 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002789 .cipher = __VECS(cast6_ctr_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002790 }
2791 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002792 .alg = "ctr(des)",
2793 .test = alg_test_skcipher,
2794 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002795 .cipher = __VECS(des_ctr_tv_template)
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002796 }
2797 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002798 .alg = "ctr(des3_ede)",
2799 .test = alg_test_skcipher,
Marcelo Cerri0d8da102017-03-20 17:28:05 -03002800 .fips_allowed = 1,
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002801 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002802 .cipher = __VECS(des3_ede_ctr_tv_template)
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002803 }
2804 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01002805 /* Same as ctr(aes) except the key is stored in
2806 * hardware secure memory which we reference by index
2807 */
2808 .alg = "ctr(paes)",
2809 .test = alg_test_null,
2810 .fips_allowed = 1,
2811 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002812 .alg = "ctr(serpent)",
2813 .test = alg_test_skcipher,
2814 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002815 .cipher = __VECS(serpent_ctr_tv_template)
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002816 }
2817 }, {
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01002818 .alg = "ctr(sm4)",
2819 .test = alg_test_skcipher,
2820 .suite = {
2821 .cipher = __VECS(sm4_ctr_tv_template)
2822 }
2823 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002824 .alg = "ctr(twofish)",
2825 .test = alg_test_skcipher,
2826 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002827 .cipher = __VECS(tf_ctr_tv_template)
Jussi Kivilinna573da622011-10-10 23:03:12 +03002828 }
2829 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002830 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002831 .test = alg_test_skcipher,
Gilad Ben-Yossef196ad602018-11-04 10:05:24 +00002832 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002833 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002834 .cipher = __VECS(cts_mode_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002835 }
2836 }, {
2837 .alg = "deflate",
2838 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002839 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002840 .suite = {
2841 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002842 .comp = __VECS(deflate_comp_tv_template),
2843 .decomp = __VECS(deflate_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002844 }
2845 }
2846 }, {
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002847 .alg = "dh",
2848 .test = alg_test_kpp,
2849 .fips_allowed = 1,
2850 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002851 .kpp = __VECS(dh_tv_template)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002852 }
2853 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002854 .alg = "digest_null",
2855 .test = alg_test_null,
2856 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002857 .alg = "drbg_nopr_ctr_aes128",
2858 .test = alg_test_drbg,
2859 .fips_allowed = 1,
2860 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002861 .drbg = __VECS(drbg_nopr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002862 }
2863 }, {
2864 .alg = "drbg_nopr_ctr_aes192",
2865 .test = alg_test_drbg,
2866 .fips_allowed = 1,
2867 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002868 .drbg = __VECS(drbg_nopr_ctr_aes192_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002869 }
2870 }, {
2871 .alg = "drbg_nopr_ctr_aes256",
2872 .test = alg_test_drbg,
2873 .fips_allowed = 1,
2874 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002875 .drbg = __VECS(drbg_nopr_ctr_aes256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002876 }
2877 }, {
2878 /*
2879 * There is no need to specifically test the DRBG with every
2880 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2881 */
2882 .alg = "drbg_nopr_hmac_sha1",
2883 .fips_allowed = 1,
2884 .test = alg_test_null,
2885 }, {
2886 .alg = "drbg_nopr_hmac_sha256",
2887 .test = alg_test_drbg,
2888 .fips_allowed = 1,
2889 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002890 .drbg = __VECS(drbg_nopr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002891 }
2892 }, {
2893 /* covered by drbg_nopr_hmac_sha256 test */
2894 .alg = "drbg_nopr_hmac_sha384",
2895 .fips_allowed = 1,
2896 .test = alg_test_null,
2897 }, {
2898 .alg = "drbg_nopr_hmac_sha512",
2899 .test = alg_test_null,
2900 .fips_allowed = 1,
2901 }, {
2902 .alg = "drbg_nopr_sha1",
2903 .fips_allowed = 1,
2904 .test = alg_test_null,
2905 }, {
2906 .alg = "drbg_nopr_sha256",
2907 .test = alg_test_drbg,
2908 .fips_allowed = 1,
2909 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002910 .drbg = __VECS(drbg_nopr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002911 }
2912 }, {
2913 /* covered by drbg_nopr_sha256 test */
2914 .alg = "drbg_nopr_sha384",
2915 .fips_allowed = 1,
2916 .test = alg_test_null,
2917 }, {
2918 .alg = "drbg_nopr_sha512",
2919 .fips_allowed = 1,
2920 .test = alg_test_null,
2921 }, {
2922 .alg = "drbg_pr_ctr_aes128",
2923 .test = alg_test_drbg,
2924 .fips_allowed = 1,
2925 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002926 .drbg = __VECS(drbg_pr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002927 }
2928 }, {
2929 /* covered by drbg_pr_ctr_aes128 test */
2930 .alg = "drbg_pr_ctr_aes192",
2931 .fips_allowed = 1,
2932 .test = alg_test_null,
2933 }, {
2934 .alg = "drbg_pr_ctr_aes256",
2935 .fips_allowed = 1,
2936 .test = alg_test_null,
2937 }, {
2938 .alg = "drbg_pr_hmac_sha1",
2939 .fips_allowed = 1,
2940 .test = alg_test_null,
2941 }, {
2942 .alg = "drbg_pr_hmac_sha256",
2943 .test = alg_test_drbg,
2944 .fips_allowed = 1,
2945 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002946 .drbg = __VECS(drbg_pr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002947 }
2948 }, {
2949 /* covered by drbg_pr_hmac_sha256 test */
2950 .alg = "drbg_pr_hmac_sha384",
2951 .fips_allowed = 1,
2952 .test = alg_test_null,
2953 }, {
2954 .alg = "drbg_pr_hmac_sha512",
2955 .test = alg_test_null,
2956 .fips_allowed = 1,
2957 }, {
2958 .alg = "drbg_pr_sha1",
2959 .fips_allowed = 1,
2960 .test = alg_test_null,
2961 }, {
2962 .alg = "drbg_pr_sha256",
2963 .test = alg_test_drbg,
2964 .fips_allowed = 1,
2965 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002966 .drbg = __VECS(drbg_pr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002967 }
2968 }, {
2969 /* covered by drbg_pr_sha256 test */
2970 .alg = "drbg_pr_sha384",
2971 .fips_allowed = 1,
2972 .test = alg_test_null,
2973 }, {
2974 .alg = "drbg_pr_sha512",
2975 .fips_allowed = 1,
2976 .test = alg_test_null,
2977 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002978 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002979 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002980 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002981 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002982 .cipher = __VECS(aes_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002983 }
2984 }, {
2985 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002986 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002987 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002988 .cipher = __VECS(anubis_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002989 }
2990 }, {
2991 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002992 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002993 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002994 .cipher = __VECS(arc4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002995 }
2996 }, {
2997 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002998 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002999 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003000 .cipher = __VECS(bf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003001 }
3002 }, {
3003 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003004 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003005 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003006 .cipher = __VECS(camellia_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003007 }
3008 }, {
3009 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003010 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003011 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003012 .cipher = __VECS(cast5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003013 }
3014 }, {
3015 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003016 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003017 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003018 .cipher = __VECS(cast6_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003019 }
3020 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003021 .alg = "ecb(cipher_null)",
3022 .test = alg_test_null,
Milan Broz6175ca22017-04-21 13:03:06 +02003023 .fips_allowed = 1,
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003024 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003025 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003026 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003027 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003028 .cipher = __VECS(des_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003029 }
3030 }, {
3031 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003032 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003033 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003034 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003035 .cipher = __VECS(des3_ede_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003036 }
3037 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003038 .alg = "ecb(fcrypt)",
3039 .test = alg_test_skcipher,
3040 .suite = {
3041 .cipher = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003042 .vecs = fcrypt_pcbc_tv_template,
3043 .count = 1
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003044 }
3045 }
3046 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003047 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003048 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003049 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003050 .cipher = __VECS(khazad_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003051 }
3052 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003053 /* Same as ecb(aes) except the key is stored in
3054 * hardware secure memory which we reference by index
3055 */
3056 .alg = "ecb(paes)",
3057 .test = alg_test_null,
3058 .fips_allowed = 1,
3059 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003060 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003061 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003062 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003063 .cipher = __VECS(seed_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003064 }
3065 }, {
3066 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003067 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003068 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003069 .cipher = __VECS(serpent_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003070 }
3071 }, {
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00003072 .alg = "ecb(sm4)",
3073 .test = alg_test_skcipher,
3074 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003075 .cipher = __VECS(sm4_tv_template)
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00003076 }
3077 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003078 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003079 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003080 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003081 .cipher = __VECS(tea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003082 }
3083 }, {
3084 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003085 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003086 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003087 .cipher = __VECS(tnepres_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003088 }
3089 }, {
3090 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003091 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003092 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003093 .cipher = __VECS(tf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003094 }
3095 }, {
3096 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003097 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003098 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003099 .cipher = __VECS(xeta_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003100 }
3101 }, {
3102 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003103 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003104 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003105 .cipher = __VECS(xtea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003106 }
3107 }, {
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003108 .alg = "ecdh",
3109 .test = alg_test_kpp,
3110 .fips_allowed = 1,
3111 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003112 .kpp = __VECS(ecdh_tv_template)
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003113 }
3114 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003115 .alg = "gcm(aes)",
3116 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003117 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003118 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003119 .aead = __VECS(aes_gcm_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003120 }
3121 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003122 .alg = "ghash",
3123 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003124 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003125 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003126 .hash = __VECS(ghash_tv_template)
Youquan, Song507069c2009-11-23 20:23:04 +08003127 }
3128 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003129 .alg = "hmac(md5)",
3130 .test = alg_test_hash,
3131 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003132 .hash = __VECS(hmac_md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003133 }
3134 }, {
3135 .alg = "hmac(rmd128)",
3136 .test = alg_test_hash,
3137 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003138 .hash = __VECS(hmac_rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003139 }
3140 }, {
3141 .alg = "hmac(rmd160)",
3142 .test = alg_test_hash,
3143 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003144 .hash = __VECS(hmac_rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003145 }
3146 }, {
3147 .alg = "hmac(sha1)",
3148 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003149 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003150 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003151 .hash = __VECS(hmac_sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003152 }
3153 }, {
3154 .alg = "hmac(sha224)",
3155 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003156 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003157 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003158 .hash = __VECS(hmac_sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003159 }
3160 }, {
3161 .alg = "hmac(sha256)",
3162 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003163 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003164 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003165 .hash = __VECS(hmac_sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003166 }
3167 }, {
raveendra padasalagi98eca722016-07-01 11:16:54 +05303168 .alg = "hmac(sha3-224)",
3169 .test = alg_test_hash,
3170 .fips_allowed = 1,
3171 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003172 .hash = __VECS(hmac_sha3_224_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303173 }
3174 }, {
3175 .alg = "hmac(sha3-256)",
3176 .test = alg_test_hash,
3177 .fips_allowed = 1,
3178 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003179 .hash = __VECS(hmac_sha3_256_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303180 }
3181 }, {
3182 .alg = "hmac(sha3-384)",
3183 .test = alg_test_hash,
3184 .fips_allowed = 1,
3185 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003186 .hash = __VECS(hmac_sha3_384_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303187 }
3188 }, {
3189 .alg = "hmac(sha3-512)",
3190 .test = alg_test_hash,
3191 .fips_allowed = 1,
3192 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003193 .hash = __VECS(hmac_sha3_512_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303194 }
3195 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003196 .alg = "hmac(sha384)",
3197 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003198 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003199 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003200 .hash = __VECS(hmac_sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003201 }
3202 }, {
3203 .alg = "hmac(sha512)",
3204 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003205 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003206 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003207 .hash = __VECS(hmac_sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003208 }
3209 }, {
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03003210 .alg = "hmac(streebog256)",
3211 .test = alg_test_hash,
3212 .suite = {
3213 .hash = __VECS(hmac_streebog256_tv_template)
3214 }
3215 }, {
3216 .alg = "hmac(streebog512)",
3217 .test = alg_test_hash,
3218 .suite = {
3219 .hash = __VECS(hmac_streebog512_tv_template)
3220 }
3221 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003222 .alg = "jitterentropy_rng",
3223 .fips_allowed = 1,
3224 .test = alg_test_null,
3225 }, {
Stephan Mueller35351982015-09-21 20:59:56 +02003226 .alg = "kw(aes)",
3227 .test = alg_test_skcipher,
3228 .fips_allowed = 1,
3229 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003230 .cipher = __VECS(aes_kw_tv_template)
Stephan Mueller35351982015-09-21 20:59:56 +02003231 }
3232 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003233 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003234 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003235 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003236 .cipher = __VECS(aes_lrw_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003237 }
3238 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003239 .alg = "lrw(camellia)",
3240 .test = alg_test_skcipher,
3241 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003242 .cipher = __VECS(camellia_lrw_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003243 }
3244 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003245 .alg = "lrw(cast6)",
3246 .test = alg_test_skcipher,
3247 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003248 .cipher = __VECS(cast6_lrw_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003249 }
3250 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003251 .alg = "lrw(serpent)",
3252 .test = alg_test_skcipher,
3253 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003254 .cipher = __VECS(serpent_lrw_tv_template)
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003255 }
3256 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003257 .alg = "lrw(twofish)",
3258 .test = alg_test_skcipher,
3259 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003260 .cipher = __VECS(tf_lrw_tv_template)
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003261 }
3262 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003263 .alg = "lz4",
3264 .test = alg_test_comp,
3265 .fips_allowed = 1,
3266 .suite = {
3267 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003268 .comp = __VECS(lz4_comp_tv_template),
3269 .decomp = __VECS(lz4_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003270 }
3271 }
3272 }, {
3273 .alg = "lz4hc",
3274 .test = alg_test_comp,
3275 .fips_allowed = 1,
3276 .suite = {
3277 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003278 .comp = __VECS(lz4hc_comp_tv_template),
3279 .decomp = __VECS(lz4hc_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003280 }
3281 }
3282 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003283 .alg = "lzo",
3284 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003285 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003286 .suite = {
3287 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003288 .comp = __VECS(lzo_comp_tv_template),
3289 .decomp = __VECS(lzo_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003290 }
3291 }
3292 }, {
3293 .alg = "md4",
3294 .test = alg_test_hash,
3295 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003296 .hash = __VECS(md4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003297 }
3298 }, {
3299 .alg = "md5",
3300 .test = alg_test_hash,
3301 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003302 .hash = __VECS(md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003303 }
3304 }, {
3305 .alg = "michael_mic",
3306 .test = alg_test_hash,
3307 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003308 .hash = __VECS(michael_mic_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003309 }
3310 }, {
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003311 .alg = "morus1280",
3312 .test = alg_test_aead,
3313 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003314 .aead = __VECS(morus1280_tv_template)
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003315 }
3316 }, {
3317 .alg = "morus640",
3318 .test = alg_test_aead,
3319 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003320 .aead = __VECS(morus640_tv_template)
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003321 }
3322 }, {
Eric Biggers26609a22018-11-16 17:26:29 -08003323 .alg = "nhpoly1305",
3324 .test = alg_test_hash,
3325 .suite = {
3326 .hash = __VECS(nhpoly1305_tv_template)
3327 }
3328 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003329 .alg = "ofb(aes)",
3330 .test = alg_test_skcipher,
3331 .fips_allowed = 1,
3332 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003333 .cipher = __VECS(aes_ofb_tv_template)
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003334 }
3335 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003336 /* Same as ofb(aes) except the key is stored in
3337 * hardware secure memory which we reference by index
3338 */
3339 .alg = "ofb(paes)",
3340 .test = alg_test_null,
3341 .fips_allowed = 1,
3342 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003343 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003344 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003345 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003346 .cipher = __VECS(fcrypt_pcbc_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003347 }
3348 }, {
Stephan Mueller12071072017-06-12 23:27:51 +02003349 .alg = "pkcs1pad(rsa,sha224)",
3350 .test = alg_test_null,
3351 .fips_allowed = 1,
3352 }, {
3353 .alg = "pkcs1pad(rsa,sha256)",
3354 .test = alg_test_akcipher,
3355 .fips_allowed = 1,
3356 .suite = {
3357 .akcipher = __VECS(pkcs1pad_rsa_tv_template)
3358 }
3359 }, {
3360 .alg = "pkcs1pad(rsa,sha384)",
3361 .test = alg_test_null,
3362 .fips_allowed = 1,
3363 }, {
3364 .alg = "pkcs1pad(rsa,sha512)",
3365 .test = alg_test_null,
3366 .fips_allowed = 1,
3367 }, {
Martin Willieee9dc62015-06-01 13:43:59 +02003368 .alg = "poly1305",
3369 .test = alg_test_hash,
3370 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003371 .hash = __VECS(poly1305_tv_template)
Martin Willieee9dc62015-06-01 13:43:59 +02003372 }
3373 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003374 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003375 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003376 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003377 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003378 .cipher = __VECS(aes_ctr_rfc3686_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003379 }
3380 }, {
Herbert Xu3f31a742015-07-09 07:17:34 +08003381 .alg = "rfc4106(gcm(aes))",
Adrian Hoban69435b92010-11-04 15:02:04 -04003382 .test = alg_test_aead,
Jarod Wilsondb71f29a2015-01-23 12:42:15 -05003383 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003384 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003385 .aead = __VECS(aes_gcm_rfc4106_tv_template)
Adrian Hoban69435b92010-11-04 15:02:04 -04003386 }
3387 }, {
Herbert Xu544c4362015-07-14 16:53:22 +08003388 .alg = "rfc4309(ccm(aes))",
Jarod Wilson5d667322009-05-04 19:23:40 +08003389 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003390 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003391 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003392 .aead = __VECS(aes_ccm_rfc4309_tv_template)
Jarod Wilson5d667322009-05-04 19:23:40 +08003393 }
3394 }, {
Herbert Xubb687452015-06-16 13:54:24 +08003395 .alg = "rfc4543(gcm(aes))",
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003396 .test = alg_test_aead,
3397 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003398 .aead = __VECS(aes_gcm_rfc4543_tv_template)
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003399 }
3400 }, {
Martin Williaf2b76b2015-06-01 13:44:01 +02003401 .alg = "rfc7539(chacha20,poly1305)",
3402 .test = alg_test_aead,
3403 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003404 .aead = __VECS(rfc7539_tv_template)
Martin Williaf2b76b2015-06-01 13:44:01 +02003405 }
3406 }, {
Martin Willi59007582015-06-01 13:44:03 +02003407 .alg = "rfc7539esp(chacha20,poly1305)",
3408 .test = alg_test_aead,
3409 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003410 .aead = __VECS(rfc7539esp_tv_template)
Martin Willi59007582015-06-01 13:44:03 +02003411 }
3412 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003413 .alg = "rmd128",
3414 .test = alg_test_hash,
3415 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003416 .hash = __VECS(rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003417 }
3418 }, {
3419 .alg = "rmd160",
3420 .test = alg_test_hash,
3421 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003422 .hash = __VECS(rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003423 }
3424 }, {
3425 .alg = "rmd256",
3426 .test = alg_test_hash,
3427 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003428 .hash = __VECS(rmd256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003429 }
3430 }, {
3431 .alg = "rmd320",
3432 .test = alg_test_hash,
3433 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003434 .hash = __VECS(rmd320_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003435 }
3436 }, {
Tadeusz Struk946cc462015-06-16 10:31:06 -07003437 .alg = "rsa",
3438 .test = alg_test_akcipher,
3439 .fips_allowed = 1,
3440 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003441 .akcipher = __VECS(rsa_tv_template)
Tadeusz Struk946cc462015-06-16 10:31:06 -07003442 }
3443 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003444 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003445 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003446 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003447 .cipher = __VECS(salsa20_stream_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003448 }
3449 }, {
3450 .alg = "sha1",
3451 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003452 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003453 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003454 .hash = __VECS(sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003455 }
3456 }, {
3457 .alg = "sha224",
3458 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003459 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003460 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003461 .hash = __VECS(sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003462 }
3463 }, {
3464 .alg = "sha256",
3465 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003466 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003467 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003468 .hash = __VECS(sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003469 }
3470 }, {
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303471 .alg = "sha3-224",
3472 .test = alg_test_hash,
3473 .fips_allowed = 1,
3474 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003475 .hash = __VECS(sha3_224_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303476 }
3477 }, {
3478 .alg = "sha3-256",
3479 .test = alg_test_hash,
3480 .fips_allowed = 1,
3481 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003482 .hash = __VECS(sha3_256_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303483 }
3484 }, {
3485 .alg = "sha3-384",
3486 .test = alg_test_hash,
3487 .fips_allowed = 1,
3488 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003489 .hash = __VECS(sha3_384_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303490 }
3491 }, {
3492 .alg = "sha3-512",
3493 .test = alg_test_hash,
3494 .fips_allowed = 1,
3495 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003496 .hash = __VECS(sha3_512_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303497 }
3498 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003499 .alg = "sha384",
3500 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003501 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003502 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003503 .hash = __VECS(sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003504 }
3505 }, {
3506 .alg = "sha512",
3507 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003508 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003509 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003510 .hash = __VECS(sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003511 }
3512 }, {
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03003513 .alg = "sm3",
3514 .test = alg_test_hash,
3515 .suite = {
3516 .hash = __VECS(sm3_tv_template)
3517 }
3518 }, {
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03003519 .alg = "streebog256",
3520 .test = alg_test_hash,
3521 .suite = {
3522 .hash = __VECS(streebog256_tv_template)
3523 }
3524 }, {
3525 .alg = "streebog512",
3526 .test = alg_test_hash,
3527 .suite = {
3528 .hash = __VECS(streebog512_tv_template)
3529 }
3530 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003531 .alg = "tgr128",
3532 .test = alg_test_hash,
3533 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003534 .hash = __VECS(tgr128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003535 }
3536 }, {
3537 .alg = "tgr160",
3538 .test = alg_test_hash,
3539 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003540 .hash = __VECS(tgr160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003541 }
3542 }, {
3543 .alg = "tgr192",
3544 .test = alg_test_hash,
3545 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003546 .hash = __VECS(tgr192_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003547 }
3548 }, {
Eric Biggersed331ad2018-06-18 10:22:39 -07003549 .alg = "vmac64(aes)",
3550 .test = alg_test_hash,
3551 .suite = {
3552 .hash = __VECS(vmac64_aes_tv_template)
3553 }
3554 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003555 .alg = "wp256",
3556 .test = alg_test_hash,
3557 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003558 .hash = __VECS(wp256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003559 }
3560 }, {
3561 .alg = "wp384",
3562 .test = alg_test_hash,
3563 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003564 .hash = __VECS(wp384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003565 }
3566 }, {
3567 .alg = "wp512",
3568 .test = alg_test_hash,
3569 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003570 .hash = __VECS(wp512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003571 }
3572 }, {
3573 .alg = "xcbc(aes)",
3574 .test = alg_test_hash,
3575 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003576 .hash = __VECS(aes_xcbc128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003577 }
3578 }, {
Eric Biggersaa762402018-11-16 17:26:22 -08003579 .alg = "xchacha12",
3580 .test = alg_test_skcipher,
3581 .suite = {
3582 .cipher = __VECS(xchacha12_tv_template)
3583 },
3584 }, {
Eric Biggersde61d7a2018-11-16 17:26:20 -08003585 .alg = "xchacha20",
3586 .test = alg_test_skcipher,
3587 .suite = {
3588 .cipher = __VECS(xchacha20_tv_template)
3589 },
3590 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003591 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003592 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003593 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003594 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003595 .cipher = __VECS(aes_xts_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003596 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003597 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003598 .alg = "xts(camellia)",
3599 .test = alg_test_skcipher,
3600 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003601 .cipher = __VECS(camellia_xts_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003602 }
3603 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003604 .alg = "xts(cast6)",
3605 .test = alg_test_skcipher,
3606 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003607 .cipher = __VECS(cast6_xts_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003608 }
3609 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003610 /* Same as xts(aes) except the key is stored in
3611 * hardware secure memory which we reference by index
3612 */
3613 .alg = "xts(paes)",
3614 .test = alg_test_null,
3615 .fips_allowed = 1,
3616 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003617 .alg = "xts(serpent)",
3618 .test = alg_test_skcipher,
3619 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003620 .cipher = __VECS(serpent_xts_tv_template)
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003621 }
3622 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003623 .alg = "xts(twofish)",
3624 .test = alg_test_skcipher,
3625 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003626 .cipher = __VECS(tf_xts_tv_template)
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003627 }
Giovanni Cabiddua368f432017-04-21 21:54:30 +01003628 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003629 .alg = "xts4096(paes)",
3630 .test = alg_test_null,
3631 .fips_allowed = 1,
3632 }, {
3633 .alg = "xts512(paes)",
3634 .test = alg_test_null,
3635 .fips_allowed = 1,
3636 }, {
Giovanni Cabiddua368f432017-04-21 21:54:30 +01003637 .alg = "zlib-deflate",
3638 .test = alg_test_comp,
3639 .fips_allowed = 1,
3640 .suite = {
3641 .comp = {
3642 .comp = __VECS(zlib_deflate_comp_tv_template),
3643 .decomp = __VECS(zlib_deflate_decomp_tv_template)
3644 }
3645 }
Nick Terrelld28fc3d2018-03-30 12:14:53 -07003646 }, {
3647 .alg = "zstd",
3648 .test = alg_test_comp,
3649 .fips_allowed = 1,
3650 .suite = {
3651 .comp = {
3652 .comp = __VECS(zstd_comp_tv_template),
3653 .decomp = __VECS(zstd_decomp_tv_template)
3654 }
3655 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003656 }
3657};
3658
Jussi Kivilinna57147582013-06-13 17:37:40 +03003659static bool alg_test_descs_checked;
3660
3661static void alg_test_descs_check_order(void)
3662{
3663 int i;
3664
3665 /* only check once */
3666 if (alg_test_descs_checked)
3667 return;
3668
3669 alg_test_descs_checked = true;
3670
3671 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3672 int diff = strcmp(alg_test_descs[i - 1].alg,
3673 alg_test_descs[i].alg);
3674
3675 if (WARN_ON(diff > 0)) {
3676 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3677 alg_test_descs[i - 1].alg,
3678 alg_test_descs[i].alg);
3679 }
3680
3681 if (WARN_ON(diff == 0)) {
3682 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3683 alg_test_descs[i].alg);
3684 }
3685 }
3686}
3687
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003688static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003689{
3690 int start = 0;
3691 int end = ARRAY_SIZE(alg_test_descs);
3692
3693 while (start < end) {
3694 int i = (start + end) / 2;
3695 int diff = strcmp(alg_test_descs[i].alg, alg);
3696
3697 if (diff > 0) {
3698 end = i;
3699 continue;
3700 }
3701
3702 if (diff < 0) {
3703 start = i + 1;
3704 continue;
3705 }
3706
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003707 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003708 }
3709
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003710 return -1;
3711}
3712
3713int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3714{
3715 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003716 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003717 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003718
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +01003719 if (!fips_enabled && notests) {
3720 printk_once(KERN_INFO "alg: self-tests disabled\n");
3721 return 0;
3722 }
3723
Jussi Kivilinna57147582013-06-13 17:37:40 +03003724 alg_test_descs_check_order();
3725
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003726 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3727 char nalg[CRYPTO_MAX_ALG_NAME];
3728
3729 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3730 sizeof(nalg))
3731 return -ENAMETOOLONG;
3732
3733 i = alg_find_test(nalg);
3734 if (i < 0)
3735 goto notest;
3736
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003737 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3738 goto non_fips_alg;
3739
Jarod Wilson941fb322009-05-04 19:49:23 +08003740 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3741 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003742 }
3743
3744 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003745 j = alg_find_test(driver);
3746 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003747 goto notest;
3748
Herbert Xua68f6612009-07-02 16:32:12 +08003749 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3750 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003751 goto non_fips_alg;
3752
Herbert Xua68f6612009-07-02 16:32:12 +08003753 rc = 0;
3754 if (i >= 0)
3755 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3756 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003757 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003758 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3759 type, mask);
3760
Jarod Wilson941fb322009-05-04 19:49:23 +08003761test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003762 if (fips_enabled && rc)
3763 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3764
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003765 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09003766 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003767
Neil Hormand12d6b62008-10-12 20:36:51 +08003768 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003769
3770notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003771 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3772 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003773non_fips_alg:
3774 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003775}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003776
Herbert Xu326a6342010-08-06 09:40:28 +08003777#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003778
Herbert Xuda7f0332008-07-31 17:08:25 +08003779EXPORT_SYMBOL_GPL(alg_test);