blob: d1d99843cce4d731f3cca0df1c3af6ec32d50308 [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 {
80 struct {
Eric Biggersb13b1e02017-02-24 15:46:59 -080081 const struct aead_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +080082 unsigned int count;
83 } enc, dec;
84};
85
86struct cipher_test_suite {
Eric Biggers92a4c9f2018-05-20 22:50:29 -070087 const struct cipher_testvec *vecs;
88 unsigned int count;
Herbert Xuda7f0332008-07-31 17:08:25 +080089};
90
91struct comp_test_suite {
92 struct {
Eric Biggersb13b1e02017-02-24 15:46:59 -080093 const struct comp_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +080094 unsigned int count;
95 } comp, decomp;
96};
97
98struct hash_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -080099 const struct hash_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +0800100 unsigned int count;
101};
102
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800103struct cprng_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800104 const struct cprng_testvec *vecs;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800105 unsigned int count;
106};
107
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200108struct drbg_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800109 const struct drbg_testvec *vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200110 unsigned int count;
111};
112
Tadeusz Struk946cc462015-06-16 10:31:06 -0700113struct akcipher_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800114 const struct akcipher_testvec *vecs;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700115 unsigned int count;
116};
117
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100118struct kpp_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800119 const struct kpp_testvec *vecs;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100120 unsigned int count;
121};
122
Herbert Xuda7f0332008-07-31 17:08:25 +0800123struct alg_test_desc {
124 const char *alg;
125 int (*test)(const struct alg_test_desc *desc, const char *driver,
126 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000127 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800128
129 union {
130 struct aead_test_suite aead;
131 struct cipher_test_suite cipher;
132 struct comp_test_suite comp;
133 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800134 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200135 struct drbg_test_suite drbg;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700136 struct akcipher_test_suite akcipher;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100137 struct kpp_test_suite kpp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800138 } suite;
139};
140
Eric Biggersb13b1e02017-02-24 15:46:59 -0800141static const unsigned int IDX[8] = {
142 IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
Herbert Xuda7f0332008-07-31 17:08:25 +0800143
Herbert Xuda7f0332008-07-31 17:08:25 +0800144static void hexdump(unsigned char *buf, unsigned int len)
145{
146 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
147 16, 1,
148 buf, len, false);
149}
150
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800151static int testmgr_alloc_buf(char *buf[XBUFSIZE])
152{
153 int i;
154
155 for (i = 0; i < XBUFSIZE; i++) {
156 buf[i] = (void *)__get_free_page(GFP_KERNEL);
157 if (!buf[i])
158 goto err_free_buf;
159 }
160
161 return 0;
162
163err_free_buf:
164 while (i-- > 0)
165 free_page((unsigned long)buf[i]);
166
167 return -ENOMEM;
168}
169
170static void testmgr_free_buf(char *buf[XBUFSIZE])
171{
172 int i;
173
174 for (i = 0; i < XBUFSIZE; i++)
175 free_page((unsigned long)buf[i]);
176}
177
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100178static int ahash_guard_result(char *result, char c, int size)
179{
180 int i;
181
182 for (i = 0; i < size; i++) {
183 if (result[i] != c)
184 return -EINVAL;
185 }
186
187 return 0;
188}
189
Wang, Rui Y018ba952016-02-03 18:26:57 +0800190static int ahash_partial_update(struct ahash_request **preq,
Eric Biggersb13b1e02017-02-24 15:46:59 -0800191 struct crypto_ahash *tfm, const struct hash_testvec *template,
Wang, Rui Y018ba952016-02-03 18:26:57 +0800192 void *hash_buff, int k, int temp, struct scatterlist *sg,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100193 const char *algo, char *result, struct crypto_wait *wait)
Wang, Rui Y018ba952016-02-03 18:26:57 +0800194{
195 char *state;
196 struct ahash_request *req;
197 int statesize, ret = -EINVAL;
Joey Pabalinasda1729c2018-01-01 10:40:14 -1000198 static const unsigned char guard[] = { 0x00, 0xba, 0xad, 0x00 };
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100199 int digestsize = crypto_ahash_digestsize(tfm);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800200
201 req = *preq;
202 statesize = crypto_ahash_statesize(
203 crypto_ahash_reqtfm(req));
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200204 state = kmalloc(statesize + sizeof(guard), GFP_KERNEL);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800205 if (!state) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300206 pr_err("alg: hash: Failed to alloc state for %s\n", algo);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800207 goto out_nostate;
208 }
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200209 memcpy(state + statesize, guard, sizeof(guard));
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100210 memset(result, 1, digestsize);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800211 ret = crypto_ahash_export(req, state);
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200212 WARN_ON(memcmp(state + statesize, guard, sizeof(guard)));
Wang, Rui Y018ba952016-02-03 18:26:57 +0800213 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300214 pr_err("alg: hash: Failed to export() for %s\n", algo);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800215 goto out;
216 }
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100217 ret = ahash_guard_result(result, 1, digestsize);
218 if (ret) {
219 pr_err("alg: hash: Failed, export used req->result for %s\n",
220 algo);
221 goto out;
222 }
Wang, Rui Y018ba952016-02-03 18:26:57 +0800223 ahash_request_free(req);
224 req = ahash_request_alloc(tfm, GFP_KERNEL);
225 if (!req) {
226 pr_err("alg: hash: Failed to alloc request for %s\n", algo);
227 goto out_noreq;
228 }
229 ahash_request_set_callback(req,
230 CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100231 crypto_req_done, wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800232
233 memcpy(hash_buff, template->plaintext + temp,
234 template->tap[k]);
235 sg_init_one(&sg[0], hash_buff, template->tap[k]);
236 ahash_request_set_crypt(req, sg, result, template->tap[k]);
237 ret = crypto_ahash_import(req, state);
238 if (ret) {
239 pr_err("alg: hash: Failed to import() for %s\n", algo);
240 goto out;
241 }
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100242 ret = ahash_guard_result(result, 1, digestsize);
243 if (ret) {
244 pr_err("alg: hash: Failed, import used req->result for %s\n",
245 algo);
246 goto out;
247 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100248 ret = crypto_wait_req(crypto_ahash_update(req), wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800249 if (ret)
250 goto out;
251 *preq = req;
252 ret = 0;
253 goto out_noreq;
254out:
255 ahash_request_free(req);
256out_noreq:
257 kfree(state);
258out_nostate:
259 return ret;
260}
261
Eric Biggersb13b1e02017-02-24 15:46:59 -0800262static int __test_hash(struct crypto_ahash *tfm,
263 const struct hash_testvec *template, unsigned int tcount,
264 bool use_digest, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800265{
266 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800267 size_t digest_size = crypto_ahash_digestsize(tfm);
Herbert Xuda7f0332008-07-31 17:08:25 +0800268 unsigned int i, j, k, temp;
269 struct scatterlist sg[8];
Horia Geanta29b77e52014-07-23 11:59:38 +0300270 char *result;
271 char *key;
Herbert Xuda7f0332008-07-31 17:08:25 +0800272 struct ahash_request *req;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100273 struct crypto_wait wait;
Herbert Xuda7f0332008-07-31 17:08:25 +0800274 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800275 char *xbuf[XBUFSIZE];
276 int ret = -ENOMEM;
277
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800278 result = kmalloc(digest_size, GFP_KERNEL);
Horia Geanta29b77e52014-07-23 11:59:38 +0300279 if (!result)
280 return ret;
281 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
282 if (!key)
283 goto out_nobuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800284 if (testmgr_alloc_buf(xbuf))
285 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800286
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100287 crypto_init_wait(&wait);
Herbert Xuda7f0332008-07-31 17:08:25 +0800288
289 req = ahash_request_alloc(tfm, GFP_KERNEL);
290 if (!req) {
291 printk(KERN_ERR "alg: hash: Failed to allocate request for "
292 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800293 goto out_noreq;
294 }
295 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100296 crypto_req_done, &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +0800297
Herbert Xua0cfae52009-05-29 16:23:12 +1000298 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800299 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000300 if (template[i].np)
301 continue;
302
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300303 ret = -EINVAL;
304 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
305 goto out;
306
Herbert Xua0cfae52009-05-29 16:23:12 +1000307 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800308 memset(result, 0, digest_size);
Herbert Xuda7f0332008-07-31 17:08:25 +0800309
310 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300311 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800312
313 memcpy(hash_buff, template[i].plaintext, template[i].psize);
314 sg_init_one(&sg[0], hash_buff, template[i].psize);
315
316 if (template[i].ksize) {
317 crypto_ahash_clear_flags(tfm, ~0);
Horia Geanta29b77e52014-07-23 11:59:38 +0300318 if (template[i].ksize > MAX_KEYLEN) {
319 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
320 j, algo, template[i].ksize, MAX_KEYLEN);
321 ret = -EINVAL;
322 goto out;
323 }
324 memcpy(key, template[i].key, template[i].ksize);
325 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
Herbert Xuda7f0332008-07-31 17:08:25 +0800326 if (ret) {
327 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000328 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800329 -ret);
330 goto out;
331 }
332 }
333
334 ahash_request_set_crypt(req, sg, result, template[i].psize);
David S. Millera8f1a052010-05-19 14:12:03 +1000335 if (use_digest) {
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100336 ret = crypto_wait_req(crypto_ahash_digest(req), &wait);
David S. Millera8f1a052010-05-19 14:12:03 +1000337 if (ret) {
338 pr_err("alg: hash: digest failed on test %d "
339 "for %s: ret=%d\n", j, algo, -ret);
340 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800341 }
David S. Millera8f1a052010-05-19 14:12:03 +1000342 } else {
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100343 memset(result, 1, digest_size);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100344 ret = crypto_wait_req(crypto_ahash_init(req), &wait);
David S. Millera8f1a052010-05-19 14:12:03 +1000345 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300346 pr_err("alg: hash: init failed on test %d "
David S. Millera8f1a052010-05-19 14:12:03 +1000347 "for %s: ret=%d\n", j, algo, -ret);
348 goto out;
349 }
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100350 ret = ahash_guard_result(result, 1, digest_size);
351 if (ret) {
352 pr_err("alg: hash: init failed on test %d "
353 "for %s: used req->result\n", j, algo);
354 goto out;
355 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100356 ret = crypto_wait_req(crypto_ahash_update(req), &wait);
David S. Millera8f1a052010-05-19 14:12:03 +1000357 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300358 pr_err("alg: hash: update failed on test %d "
David S. Millera8f1a052010-05-19 14:12:03 +1000359 "for %s: ret=%d\n", j, algo, -ret);
360 goto out;
361 }
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100362 ret = ahash_guard_result(result, 1, digest_size);
363 if (ret) {
364 pr_err("alg: hash: update failed on test %d "
365 "for %s: used req->result\n", j, algo);
366 goto out;
367 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100368 ret = crypto_wait_req(crypto_ahash_final(req), &wait);
David S. Millera8f1a052010-05-19 14:12:03 +1000369 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300370 pr_err("alg: hash: final failed on test %d "
David S. Millera8f1a052010-05-19 14:12:03 +1000371 "for %s: ret=%d\n", j, algo, -ret);
372 goto out;
373 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800374 }
375
376 if (memcmp(result, template[i].digest,
377 crypto_ahash_digestsize(tfm))) {
378 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000379 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800380 hexdump(result, crypto_ahash_digestsize(tfm));
381 ret = -EINVAL;
382 goto out;
383 }
384 }
385
386 j = 0;
387 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300388 /* alignment tests are only done with continuous buffers */
389 if (align_offset != 0)
390 break;
391
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300392 if (!template[i].np)
393 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800394
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300395 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800396 memset(result, 0, digest_size);
Herbert Xuda7f0332008-07-31 17:08:25 +0800397
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300398 temp = 0;
399 sg_init_table(sg, template[i].np);
400 ret = -EINVAL;
401 for (k = 0; k < template[i].np; k++) {
402 if (WARN_ON(offset_in_page(IDX[k]) +
403 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +0800404 goto out;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300405 sg_set_buf(&sg[k],
406 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
407 offset_in_page(IDX[k]),
408 template[i].plaintext + temp,
409 template[i].tap[k]),
410 template[i].tap[k]);
411 temp += template[i].tap[k];
412 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800413
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300414 if (template[i].ksize) {
415 if (template[i].ksize > MAX_KEYLEN) {
416 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
417 j, algo, template[i].ksize, MAX_KEYLEN);
Herbert Xuda7f0332008-07-31 17:08:25 +0800418 ret = -EINVAL;
419 goto out;
420 }
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300421 crypto_ahash_clear_flags(tfm, ~0);
422 memcpy(key, template[i].key, template[i].ksize);
423 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
424
425 if (ret) {
426 printk(KERN_ERR "alg: hash: setkey "
427 "failed on chunking test %d "
428 "for %s: ret=%d\n", j, algo, -ret);
429 goto out;
430 }
431 }
432
433 ahash_request_set_crypt(req, sg, result, template[i].psize);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100434 ret = crypto_wait_req(crypto_ahash_digest(req), &wait);
435 if (ret) {
436 pr_err("alg: hash: digest failed on chunking test %d for %s: ret=%d\n",
437 j, algo, -ret);
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300438 goto out;
439 }
440
441 if (memcmp(result, template[i].digest,
442 crypto_ahash_digestsize(tfm))) {
443 printk(KERN_ERR "alg: hash: Chunking test %d "
444 "failed for %s\n", j, algo);
445 hexdump(result, crypto_ahash_digestsize(tfm));
446 ret = -EINVAL;
447 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800448 }
449 }
450
Wang, Rui Y018ba952016-02-03 18:26:57 +0800451 /* partial update exercise */
452 j = 0;
453 for (i = 0; i < tcount; i++) {
454 /* alignment tests are only done with continuous buffers */
455 if (align_offset != 0)
456 break;
457
458 if (template[i].np < 2)
459 continue;
460
461 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800462 memset(result, 0, digest_size);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800463
464 ret = -EINVAL;
465 hash_buff = xbuf[0];
466 memcpy(hash_buff, template[i].plaintext,
467 template[i].tap[0]);
468 sg_init_one(&sg[0], hash_buff, template[i].tap[0]);
469
470 if (template[i].ksize) {
471 crypto_ahash_clear_flags(tfm, ~0);
472 if (template[i].ksize > MAX_KEYLEN) {
473 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
474 j, algo, template[i].ksize, MAX_KEYLEN);
475 ret = -EINVAL;
476 goto out;
477 }
478 memcpy(key, template[i].key, template[i].ksize);
479 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
480 if (ret) {
481 pr_err("alg: hash: setkey failed on test %d for %s: ret=%d\n",
482 j, algo, -ret);
483 goto out;
484 }
485 }
486
487 ahash_request_set_crypt(req, sg, result, template[i].tap[0]);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100488 ret = crypto_wait_req(crypto_ahash_init(req), &wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800489 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300490 pr_err("alg: hash: init failed on test %d for %s: ret=%d\n",
Wang, Rui Y018ba952016-02-03 18:26:57 +0800491 j, algo, -ret);
492 goto out;
493 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100494 ret = crypto_wait_req(crypto_ahash_update(req), &wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800495 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300496 pr_err("alg: hash: update failed on test %d for %s: ret=%d\n",
Wang, Rui Y018ba952016-02-03 18:26:57 +0800497 j, algo, -ret);
498 goto out;
499 }
500
501 temp = template[i].tap[0];
502 for (k = 1; k < template[i].np; k++) {
503 ret = ahash_partial_update(&req, tfm, &template[i],
504 hash_buff, k, temp, &sg[0], algo, result,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100505 &wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800506 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300507 pr_err("alg: hash: partial update failed on test %d for %s: ret=%d\n",
Wang, Rui Y018ba952016-02-03 18:26:57 +0800508 j, algo, -ret);
509 goto out_noreq;
510 }
511 temp += template[i].tap[k];
512 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100513 ret = crypto_wait_req(crypto_ahash_final(req), &wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800514 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300515 pr_err("alg: hash: final failed on test %d for %s: ret=%d\n",
Wang, Rui Y018ba952016-02-03 18:26:57 +0800516 j, algo, -ret);
517 goto out;
518 }
519 if (memcmp(result, template[i].digest,
520 crypto_ahash_digestsize(tfm))) {
521 pr_err("alg: hash: Partial Test %d failed for %s\n",
522 j, algo);
523 hexdump(result, crypto_ahash_digestsize(tfm));
524 ret = -EINVAL;
525 goto out;
526 }
527 }
528
Herbert Xuda7f0332008-07-31 17:08:25 +0800529 ret = 0;
530
531out:
532 ahash_request_free(req);
533out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800534 testmgr_free_buf(xbuf);
535out_nobuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300536 kfree(key);
537 kfree(result);
Herbert Xuda7f0332008-07-31 17:08:25 +0800538 return ret;
539}
540
Eric Biggersb13b1e02017-02-24 15:46:59 -0800541static int test_hash(struct crypto_ahash *tfm,
542 const struct hash_testvec *template,
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300543 unsigned int tcount, bool use_digest)
544{
545 unsigned int alignmask;
546 int ret;
547
548 ret = __test_hash(tfm, template, tcount, use_digest, 0);
549 if (ret)
550 return ret;
551
552 /* test unaligned buffers, check with one byte offset */
553 ret = __test_hash(tfm, template, tcount, use_digest, 1);
554 if (ret)
555 return ret;
556
557 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
558 if (alignmask) {
559 /* Check if alignment mask for tfm is correctly set. */
560 ret = __test_hash(tfm, template, tcount, use_digest,
561 alignmask + 1);
562 if (ret)
563 return ret;
564 }
565
566 return 0;
567}
568
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300569static int __test_aead(struct crypto_aead *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -0800570 const struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300571 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800572{
573 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
574 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800575 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800576 char *q;
577 char *key;
578 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300579 struct scatterlist *sg;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300580 struct scatterlist *sgout;
581 const char *e, *d;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100582 struct crypto_wait wait;
Cristian Stoica424a5da2015-01-28 11:03:05 +0200583 unsigned int authsize, iv_len;
Herbert Xuda7f0332008-07-31 17:08:25 +0800584 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300585 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800586 void *assoc;
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700587 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800588 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300589 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800590 char *axbuf[XBUFSIZE];
591
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700592 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
593 if (!iv)
594 return ret;
Horia Geanta29b77e52014-07-23 11:59:38 +0300595 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
596 if (!key)
597 goto out_noxbuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800598 if (testmgr_alloc_buf(xbuf))
599 goto out_noxbuf;
600 if (testmgr_alloc_buf(axbuf))
601 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300602 if (diff_dst && testmgr_alloc_buf(xoutbuf))
603 goto out_nooutbuf;
604
605 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800606 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 4 : 2), GFP_KERNEL);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300607 if (!sg)
608 goto out_nosg;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800609 sgout = &sg[16];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300610
611 if (diff_dst)
612 d = "-ddst";
613 else
614 d = "";
615
Herbert Xuda7f0332008-07-31 17:08:25 +0800616 if (enc == ENCRYPT)
617 e = "encryption";
618 else
619 e = "decryption";
620
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100621 crypto_init_wait(&wait);
Herbert Xuda7f0332008-07-31 17:08:25 +0800622
623 req = aead_request_alloc(tfm, GFP_KERNEL);
624 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300625 pr_err("alg: aead%s: Failed to allocate request for %s\n",
626 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800627 goto out;
628 }
629
630 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100631 crypto_req_done, &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +0800632
Jerome Marchandabfa7f42016-02-03 13:58:12 +0100633 iv_len = crypto_aead_ivsize(tfm);
634
Herbert Xuda7f0332008-07-31 17:08:25 +0800635 for (i = 0, j = 0; i < tcount; i++) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300636 if (template[i].np)
637 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800638
Cristian Stoica05b1d332014-07-28 13:11:23 +0300639 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800640
Cristian Stoica05b1d332014-07-28 13:11:23 +0300641 /* some templates have no input data but they will
642 * touch input
643 */
644 input = xbuf[0];
645 input += align_offset;
646 assoc = axbuf[0];
647
648 ret = -EINVAL;
649 if (WARN_ON(align_offset + template[i].ilen >
650 PAGE_SIZE || template[i].alen > PAGE_SIZE))
651 goto out;
652
653 memcpy(input, template[i].input, template[i].ilen);
654 memcpy(assoc, template[i].assoc, template[i].alen);
655 if (template[i].iv)
Cristian Stoica424a5da2015-01-28 11:03:05 +0200656 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300657 else
Cristian Stoica424a5da2015-01-28 11:03:05 +0200658 memset(iv, 0, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300659
660 crypto_aead_clear_flags(tfm, ~0);
661 if (template[i].wk)
662 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
663
664 if (template[i].klen > MAX_KEYLEN) {
665 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
666 d, j, algo, template[i].klen,
667 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +1000668 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300669 goto out;
670 }
671 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +1000672
Cristian Stoica05b1d332014-07-28 13:11:23 +0300673 ret = crypto_aead_setkey(tfm, key, template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +0800674 if (template[i].fail == !ret) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300675 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
676 d, j, algo, crypto_aead_get_flags(tfm));
677 goto out;
678 } else if (ret)
679 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800680
Cristian Stoica05b1d332014-07-28 13:11:23 +0300681 authsize = abs(template[i].rlen - template[i].ilen);
682 ret = crypto_aead_setauthsize(tfm, authsize);
683 if (ret) {
684 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
685 d, authsize, j, algo);
686 goto out;
687 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800688
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800689 k = !!template[i].alen;
690 sg_init_table(sg, k + 1);
691 sg_set_buf(&sg[0], assoc, template[i].alen);
692 sg_set_buf(&sg[k], input,
693 template[i].ilen + (enc ? authsize : 0));
694 output = input;
695
Cristian Stoica05b1d332014-07-28 13:11:23 +0300696 if (diff_dst) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800697 sg_init_table(sgout, k + 1);
698 sg_set_buf(&sgout[0], assoc, template[i].alen);
699
Cristian Stoica05b1d332014-07-28 13:11:23 +0300700 output = xoutbuf[0];
701 output += align_offset;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800702 sg_set_buf(&sgout[k], output,
703 template[i].rlen + (enc ? 0 : authsize));
Cristian Stoica05b1d332014-07-28 13:11:23 +0300704 }
705
Cristian Stoica05b1d332014-07-28 13:11:23 +0300706 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
707 template[i].ilen, iv);
708
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800709 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300710
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100711 ret = crypto_wait_req(enc ? crypto_aead_encrypt(req)
712 : crypto_aead_decrypt(req), &wait);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300713
714 switch (ret) {
715 case 0:
716 if (template[i].novrfy) {
717 /* verification was supposed to fail */
718 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
719 d, e, j, algo);
720 /* so really, we got a bad message */
721 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +0300722 goto out;
723 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300724 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300725 case -EBADMSG:
726 if (template[i].novrfy)
727 /* verification failure was expected */
728 continue;
729 /* fall through */
730 default:
731 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
732 d, e, j, algo, -ret);
733 goto out;
734 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800735
Cristian Stoica05b1d332014-07-28 13:11:23 +0300736 q = output;
737 if (memcmp(q, template[i].result, template[i].rlen)) {
738 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
739 d, j, e, algo);
740 hexdump(q, template[i].rlen);
741 ret = -EINVAL;
742 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800743 }
744 }
745
746 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300747 /* alignment tests are only done with continuous buffers */
748 if (align_offset != 0)
749 break;
750
Cristian Stoica05b1d332014-07-28 13:11:23 +0300751 if (!template[i].np)
752 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800753
Cristian Stoica05b1d332014-07-28 13:11:23 +0300754 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800755
Cristian Stoica05b1d332014-07-28 13:11:23 +0300756 if (template[i].iv)
Jerome Marchandabfa7f42016-02-03 13:58:12 +0100757 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300758 else
759 memset(iv, 0, MAX_IVLEN);
760
761 crypto_aead_clear_flags(tfm, ~0);
762 if (template[i].wk)
763 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
764 if (template[i].klen > MAX_KEYLEN) {
765 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
766 d, j, algo, template[i].klen, MAX_KEYLEN);
767 ret = -EINVAL;
768 goto out;
769 }
770 memcpy(key, template[i].key, template[i].klen);
771
772 ret = crypto_aead_setkey(tfm, key, template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +0800773 if (template[i].fail == !ret) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300774 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
775 d, j, algo, crypto_aead_get_flags(tfm));
776 goto out;
777 } else if (ret)
778 continue;
779
780 authsize = abs(template[i].rlen - template[i].ilen);
781
782 ret = -EINVAL;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800783 sg_init_table(sg, template[i].anp + template[i].np);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300784 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800785 sg_init_table(sgout, template[i].anp + template[i].np);
786
787 ret = -EINVAL;
788 for (k = 0, temp = 0; k < template[i].anp; k++) {
789 if (WARN_ON(offset_in_page(IDX[k]) +
790 template[i].atap[k] > PAGE_SIZE))
791 goto out;
792 sg_set_buf(&sg[k],
793 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
794 offset_in_page(IDX[k]),
795 template[i].assoc + temp,
796 template[i].atap[k]),
797 template[i].atap[k]);
798 if (diff_dst)
799 sg_set_buf(&sgout[k],
800 axbuf[IDX[k] >> PAGE_SHIFT] +
801 offset_in_page(IDX[k]),
802 template[i].atap[k]);
803 temp += template[i].atap[k];
804 }
805
Cristian Stoica05b1d332014-07-28 13:11:23 +0300806 for (k = 0, temp = 0; k < template[i].np; k++) {
807 if (WARN_ON(offset_in_page(IDX[k]) +
808 template[i].tap[k] > PAGE_SIZE))
809 goto out;
810
811 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
812 memcpy(q, template[i].input + temp, template[i].tap[k]);
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800813 sg_set_buf(&sg[template[i].anp + k],
814 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300815
816 if (diff_dst) {
817 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
818 offset_in_page(IDX[k]);
819
820 memset(q, 0, template[i].tap[k]);
821
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800822 sg_set_buf(&sgout[template[i].anp + k],
823 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300824 }
825
826 n = template[i].tap[k];
827 if (k == template[i].np - 1 && enc)
828 n += authsize;
829 if (offset_in_page(q) + n < PAGE_SIZE)
830 q[n] = 0;
831
832 temp += template[i].tap[k];
833 }
834
835 ret = crypto_aead_setauthsize(tfm, authsize);
836 if (ret) {
837 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
838 d, authsize, j, algo);
839 goto out;
840 }
841
842 if (enc) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800843 if (WARN_ON(sg[template[i].anp + k - 1].offset +
844 sg[template[i].anp + k - 1].length +
845 authsize > PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300846 ret = -EINVAL;
847 goto out;
848 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800849
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300850 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800851 sgout[template[i].anp + k - 1].length +=
852 authsize;
853 sg[template[i].anp + k - 1].length += authsize;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300854 }
855
856 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
857 template[i].ilen,
858 iv);
859
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800860 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300861
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100862 ret = crypto_wait_req(enc ? crypto_aead_encrypt(req)
863 : crypto_aead_decrypt(req), &wait);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300864
865 switch (ret) {
866 case 0:
867 if (template[i].novrfy) {
868 /* verification was supposed to fail */
869 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
870 d, e, j, algo);
871 /* so really, we got a bad message */
872 ret = -EBADMSG;
873 goto out;
874 }
875 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300876 case -EBADMSG:
877 if (template[i].novrfy)
878 /* verification failure was expected */
879 continue;
880 /* fall through */
881 default:
882 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
883 d, e, j, algo, -ret);
884 goto out;
885 }
886
887 ret = -EINVAL;
888 for (k = 0, temp = 0; k < template[i].np; k++) {
889 if (diff_dst)
890 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
891 offset_in_page(IDX[k]);
892 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800893 q = xbuf[IDX[k] >> PAGE_SHIFT] +
894 offset_in_page(IDX[k]);
895
Cristian Stoica05b1d332014-07-28 13:11:23 +0300896 n = template[i].tap[k];
897 if (k == template[i].np - 1)
898 n += enc ? authsize : -authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800899
Cristian Stoica05b1d332014-07-28 13:11:23 +0300900 if (memcmp(q, template[i].result + temp, n)) {
901 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
902 d, j, e, k, algo);
903 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800904 goto out;
905 }
906
Cristian Stoica05b1d332014-07-28 13:11:23 +0300907 q += n;
908 if (k == template[i].np - 1 && !enc) {
909 if (!diff_dst &&
910 memcmp(q, template[i].input +
911 temp + n, authsize))
912 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200913 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300914 n = 0;
915 } else {
916 for (n = 0; offset_in_page(q + n) && q[n]; n++)
917 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800918 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300919 if (n) {
920 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
921 d, j, e, k, algo, n);
922 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800923 goto out;
924 }
925
Cristian Stoica05b1d332014-07-28 13:11:23 +0300926 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800927 }
928 }
929
930 ret = 0;
931
932out:
933 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300934 kfree(sg);
935out_nosg:
936 if (diff_dst)
937 testmgr_free_buf(xoutbuf);
938out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800939 testmgr_free_buf(axbuf);
940out_noaxbuf:
941 testmgr_free_buf(xbuf);
942out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300943 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700944 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800945 return ret;
946}
947
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300948static int test_aead(struct crypto_aead *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -0800949 const struct aead_testvec *template, unsigned int tcount)
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300950{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300951 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300952 int ret;
953
954 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300955 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300956 if (ret)
957 return ret;
958
959 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300960 ret = __test_aead(tfm, enc, template, tcount, true, 0);
961 if (ret)
962 return ret;
963
964 /* test unaligned buffers, check with one byte offset */
965 ret = __test_aead(tfm, enc, template, tcount, true, 1);
966 if (ret)
967 return ret;
968
969 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
970 if (alignmask) {
971 /* Check if alignment mask for tfm is correctly set. */
972 ret = __test_aead(tfm, enc, template, tcount, true,
973 alignmask + 1);
974 if (ret)
975 return ret;
976 }
977
978 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300979}
980
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000981static int test_cipher(struct crypto_cipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -0800982 const struct cipher_testvec *template,
983 unsigned int tcount)
Herbert Xuda7f0332008-07-31 17:08:25 +0800984{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000985 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
986 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000987 char *q;
988 const char *e;
Eric Biggers92a4c9f2018-05-20 22:50:29 -0700989 const char *input, *result;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000990 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800991 char *xbuf[XBUFSIZE];
992 int ret = -ENOMEM;
993
994 if (testmgr_alloc_buf(xbuf))
995 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000996
997 if (enc == ENCRYPT)
998 e = "encryption";
999 else
1000 e = "decryption";
1001
1002 j = 0;
1003 for (i = 0; i < tcount; i++) {
1004 if (template[i].np)
1005 continue;
1006
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001007 if (fips_enabled && template[i].fips_skip)
1008 continue;
1009
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001010 input = enc ? template[i].ptext : template[i].ctext;
1011 result = enc ? template[i].ctext : template[i].ptext;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001012 j++;
1013
Herbert Xufd57f222009-05-29 16:05:42 +10001014 ret = -EINVAL;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001015 if (WARN_ON(template[i].len > PAGE_SIZE))
Herbert Xufd57f222009-05-29 16:05:42 +10001016 goto out;
1017
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001018 data = xbuf[0];
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001019 memcpy(data, input, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001020
1021 crypto_cipher_clear_flags(tfm, ~0);
1022 if (template[i].wk)
1023 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1024
1025 ret = crypto_cipher_setkey(tfm, template[i].key,
1026 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001027 if (template[i].fail == !ret) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001028 printk(KERN_ERR "alg: cipher: setkey failed "
1029 "on test %d for %s: flags=%x\n", j,
1030 algo, crypto_cipher_get_flags(tfm));
1031 goto out;
1032 } else if (ret)
1033 continue;
1034
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001035 for (k = 0; k < template[i].len;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001036 k += crypto_cipher_blocksize(tfm)) {
1037 if (enc)
1038 crypto_cipher_encrypt_one(tfm, data + k,
1039 data + k);
1040 else
1041 crypto_cipher_decrypt_one(tfm, data + k,
1042 data + k);
1043 }
1044
1045 q = data;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001046 if (memcmp(q, result, template[i].len)) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001047 printk(KERN_ERR "alg: cipher: Test %d failed "
1048 "on %s for %s\n", j, e, algo);
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001049 hexdump(q, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001050 ret = -EINVAL;
1051 goto out;
1052 }
1053 }
1054
1055 ret = 0;
1056
1057out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001058 testmgr_free_buf(xbuf);
1059out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001060 return ret;
1061}
1062
Herbert Xu12773d92015-08-20 15:21:46 +08001063static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001064 const struct cipher_testvec *template,
1065 unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001066 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001067{
Herbert Xuda7f0332008-07-31 17:08:25 +08001068 const char *algo =
Herbert Xu12773d92015-08-20 15:21:46 +08001069 crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +08001070 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +08001071 char *q;
Herbert Xu12773d92015-08-20 15:21:46 +08001072 struct skcipher_request *req;
Herbert Xuda7f0332008-07-31 17:08:25 +08001073 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001074 struct scatterlist sgout[8];
1075 const char *e, *d;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001076 struct crypto_wait wait;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001077 const char *input, *result;
Herbert Xuda7f0332008-07-31 17:08:25 +08001078 void *data;
1079 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001080 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001081 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001082 int ret = -ENOMEM;
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001083 unsigned int ivsize = crypto_skcipher_ivsize(tfm);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001084
1085 if (testmgr_alloc_buf(xbuf))
1086 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +08001087
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001088 if (diff_dst && testmgr_alloc_buf(xoutbuf))
1089 goto out_nooutbuf;
1090
1091 if (diff_dst)
1092 d = "-ddst";
1093 else
1094 d = "";
1095
Herbert Xuda7f0332008-07-31 17:08:25 +08001096 if (enc == ENCRYPT)
1097 e = "encryption";
1098 else
1099 e = "decryption";
1100
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001101 crypto_init_wait(&wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001102
Herbert Xu12773d92015-08-20 15:21:46 +08001103 req = skcipher_request_alloc(tfm, GFP_KERNEL);
Herbert Xuda7f0332008-07-31 17:08:25 +08001104 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001105 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
1106 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +08001107 goto out;
1108 }
1109
Herbert Xu12773d92015-08-20 15:21:46 +08001110 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001111 crypto_req_done, &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001112
1113 j = 0;
1114 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001115 if (template[i].np && !template[i].also_non_np)
1116 continue;
1117
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001118 if (fips_enabled && template[i].fips_skip)
1119 continue;
1120
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001121 if (template[i].iv && !(template[i].generates_iv && enc))
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001122 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001123 else
1124 memset(iv, 0, MAX_IVLEN);
1125
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001126 input = enc ? template[i].ptext : template[i].ctext;
1127 result = enc ? template[i].ctext : template[i].ptext;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001128 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001129 ret = -EINVAL;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001130 if (WARN_ON(align_offset + template[i].len > PAGE_SIZE))
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001131 goto out;
1132
1133 data = xbuf[0];
1134 data += align_offset;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001135 memcpy(data, input, template[i].len);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001136
Herbert Xu12773d92015-08-20 15:21:46 +08001137 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001138 if (template[i].wk)
Herbert Xu12773d92015-08-20 15:21:46 +08001139 crypto_skcipher_set_flags(tfm,
1140 CRYPTO_TFM_REQ_WEAK_KEY);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001141
Herbert Xu12773d92015-08-20 15:21:46 +08001142 ret = crypto_skcipher_setkey(tfm, template[i].key,
1143 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001144 if (template[i].fail == !ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001145 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001146 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001147 goto out;
1148 } else if (ret)
1149 continue;
1150
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001151 sg_init_one(&sg[0], data, template[i].len);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001152 if (diff_dst) {
1153 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001154 data += align_offset;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001155 sg_init_one(&sgout[0], data, template[i].len);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001156 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001157
Herbert Xu12773d92015-08-20 15:21:46 +08001158 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001159 template[i].len, iv);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001160 ret = crypto_wait_req(enc ? crypto_skcipher_encrypt(req) :
1161 crypto_skcipher_decrypt(req), &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001162
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001163 if (ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001164 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1165 d, e, j, algo, -ret);
1166 goto out;
1167 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001168
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001169 q = data;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001170 if (memcmp(q, result, template[i].len)) {
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001171 pr_err("alg: skcipher%s: Test %d failed (invalid result) on %s for %s\n",
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001172 d, j, e, algo);
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001173 hexdump(q, template[i].len);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001174 ret = -EINVAL;
1175 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001176 }
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001177
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001178 if (template[i].generates_iv && enc &&
1179 memcmp(iv, template[i].iv, crypto_skcipher_ivsize(tfm))) {
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001180 pr_err("alg: skcipher%s: Test %d failed (invalid output IV) on %s for %s\n",
1181 d, j, e, algo);
1182 hexdump(iv, crypto_skcipher_ivsize(tfm));
1183 ret = -EINVAL;
1184 goto out;
1185 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001186 }
1187
1188 j = 0;
1189 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001190 /* alignment tests are only done with continuous buffers */
1191 if (align_offset != 0)
1192 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001193
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001194 if (!template[i].np)
1195 continue;
1196
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001197 if (fips_enabled && template[i].fips_skip)
1198 continue;
1199
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001200 if (template[i].iv && !(template[i].generates_iv && enc))
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001201 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001202 else
1203 memset(iv, 0, MAX_IVLEN);
1204
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001205 input = enc ? template[i].ptext : template[i].ctext;
1206 result = enc ? template[i].ctext : template[i].ptext;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001207 j++;
Herbert Xu12773d92015-08-20 15:21:46 +08001208 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001209 if (template[i].wk)
Herbert Xu12773d92015-08-20 15:21:46 +08001210 crypto_skcipher_set_flags(tfm,
1211 CRYPTO_TFM_REQ_WEAK_KEY);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001212
Herbert Xu12773d92015-08-20 15:21:46 +08001213 ret = crypto_skcipher_setkey(tfm, template[i].key,
1214 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001215 if (template[i].fail == !ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001216 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001217 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001218 goto out;
1219 } else if (ret)
1220 continue;
1221
1222 temp = 0;
1223 ret = -EINVAL;
1224 sg_init_table(sg, template[i].np);
1225 if (diff_dst)
1226 sg_init_table(sgout, template[i].np);
1227 for (k = 0; k < template[i].np; k++) {
1228 if (WARN_ON(offset_in_page(IDX[k]) +
1229 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001230 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001231
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001232 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1233
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001234 memcpy(q, input + temp, template[i].tap[k]);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001235
1236 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1237 q[template[i].tap[k]] = 0;
1238
1239 sg_set_buf(&sg[k], q, template[i].tap[k]);
1240 if (diff_dst) {
1241 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1242 offset_in_page(IDX[k]);
1243
1244 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1245
1246 memset(q, 0, template[i].tap[k]);
1247 if (offset_in_page(q) +
1248 template[i].tap[k] < PAGE_SIZE)
1249 q[template[i].tap[k]] = 0;
1250 }
1251
1252 temp += template[i].tap[k];
1253 }
1254
Herbert Xu12773d92015-08-20 15:21:46 +08001255 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001256 template[i].len, iv);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001257
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001258 ret = crypto_wait_req(enc ? crypto_skcipher_encrypt(req) :
1259 crypto_skcipher_decrypt(req), &wait);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001260
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001261 if (ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001262 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1263 d, e, j, algo, -ret);
1264 goto out;
1265 }
1266
1267 temp = 0;
1268 ret = -EINVAL;
1269 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001270 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001271 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1272 offset_in_page(IDX[k]);
1273 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001274 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1275 offset_in_page(IDX[k]);
1276
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001277 if (memcmp(q, result + temp, template[i].tap[k])) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001278 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1279 d, j, e, k, algo);
1280 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001281 goto out;
1282 }
1283
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001284 q += template[i].tap[k];
1285 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1286 ;
1287 if (n) {
1288 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1289 d, j, e, k, algo, n);
1290 hexdump(q, n);
1291 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001292 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001293 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001294 }
1295 }
1296
1297 ret = 0;
1298
1299out:
Herbert Xu12773d92015-08-20 15:21:46 +08001300 skcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001301 if (diff_dst)
1302 testmgr_free_buf(xoutbuf);
1303out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001304 testmgr_free_buf(xbuf);
1305out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001306 return ret;
1307}
1308
Herbert Xu12773d92015-08-20 15:21:46 +08001309static int test_skcipher(struct crypto_skcipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001310 const struct cipher_testvec *template,
1311 unsigned int tcount)
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001312{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001313 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001314 int ret;
1315
1316 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001317 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001318 if (ret)
1319 return ret;
1320
1321 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001322 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1323 if (ret)
1324 return ret;
1325
1326 /* test unaligned buffers, check with one byte offset */
1327 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1328 if (ret)
1329 return ret;
1330
1331 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1332 if (alignmask) {
1333 /* Check if alignment mask for tfm is correctly set. */
1334 ret = __test_skcipher(tfm, enc, template, tcount, true,
1335 alignmask + 1);
1336 if (ret)
1337 return ret;
1338 }
1339
1340 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001341}
1342
Eric Biggersb13b1e02017-02-24 15:46:59 -08001343static int test_comp(struct crypto_comp *tfm,
1344 const struct comp_testvec *ctemplate,
1345 const struct comp_testvec *dtemplate,
1346 int ctcount, int dtcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08001347{
1348 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
Mahipal Challa33607382018-04-11 20:28:32 +02001349 char *output, *decomp_output;
Herbert Xuda7f0332008-07-31 17:08:25 +08001350 unsigned int i;
Herbert Xuda7f0332008-07-31 17:08:25 +08001351 int ret;
1352
Mahipal Challa33607382018-04-11 20:28:32 +02001353 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1354 if (!output)
1355 return -ENOMEM;
1356
1357 decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1358 if (!decomp_output) {
1359 kfree(output);
1360 return -ENOMEM;
1361 }
1362
Herbert Xuda7f0332008-07-31 17:08:25 +08001363 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001364 int ilen;
1365 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001366
Mahipal Challa33607382018-04-11 20:28:32 +02001367 memset(output, 0, sizeof(COMP_BUF_SIZE));
1368 memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
Herbert Xuda7f0332008-07-31 17:08:25 +08001369
1370 ilen = ctemplate[i].inlen;
1371 ret = crypto_comp_compress(tfm, ctemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02001372 ilen, output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001373 if (ret) {
1374 printk(KERN_ERR "alg: comp: compression failed "
1375 "on test %d for %s: ret=%d\n", i + 1, algo,
1376 -ret);
1377 goto out;
1378 }
1379
Mahipal Challa33607382018-04-11 20:28:32 +02001380 ilen = dlen;
1381 dlen = COMP_BUF_SIZE;
1382 ret = crypto_comp_decompress(tfm, output,
1383 ilen, decomp_output, &dlen);
1384 if (ret) {
1385 pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n",
1386 i + 1, algo, -ret);
1387 goto out;
1388 }
1389
1390 if (dlen != ctemplate[i].inlen) {
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001391 printk(KERN_ERR "alg: comp: Compression test %d "
1392 "failed for %s: output len = %d\n", i + 1, algo,
1393 dlen);
1394 ret = -EINVAL;
1395 goto out;
1396 }
1397
Mahipal Challa33607382018-04-11 20:28:32 +02001398 if (memcmp(decomp_output, ctemplate[i].input,
1399 ctemplate[i].inlen)) {
1400 pr_err("alg: comp: compression failed: output differs: on test %d for %s\n",
1401 i + 1, algo);
1402 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001403 ret = -EINVAL;
1404 goto out;
1405 }
1406 }
1407
1408 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001409 int ilen;
1410 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001411
Mahipal Challa33607382018-04-11 20:28:32 +02001412 memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
Herbert Xuda7f0332008-07-31 17:08:25 +08001413
1414 ilen = dtemplate[i].inlen;
1415 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02001416 ilen, decomp_output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001417 if (ret) {
1418 printk(KERN_ERR "alg: comp: decompression failed "
1419 "on test %d for %s: ret=%d\n", i + 1, algo,
1420 -ret);
1421 goto out;
1422 }
1423
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001424 if (dlen != dtemplate[i].outlen) {
1425 printk(KERN_ERR "alg: comp: Decompression test %d "
1426 "failed for %s: output len = %d\n", i + 1, algo,
1427 dlen);
1428 ret = -EINVAL;
1429 goto out;
1430 }
1431
Mahipal Challa33607382018-04-11 20:28:32 +02001432 if (memcmp(decomp_output, dtemplate[i].output, dlen)) {
Herbert Xuda7f0332008-07-31 17:08:25 +08001433 printk(KERN_ERR "alg: comp: Decompression test %d "
1434 "failed for %s\n", i + 1, algo);
Mahipal Challa33607382018-04-11 20:28:32 +02001435 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001436 ret = -EINVAL;
1437 goto out;
1438 }
1439 }
1440
1441 ret = 0;
1442
1443out:
Mahipal Challa33607382018-04-11 20:28:32 +02001444 kfree(decomp_output);
1445 kfree(output);
Herbert Xuda7f0332008-07-31 17:08:25 +08001446 return ret;
1447}
1448
Eric Biggersb13b1e02017-02-24 15:46:59 -08001449static int test_acomp(struct crypto_acomp *tfm,
Mahipal Challa33607382018-04-11 20:28:32 +02001450 const struct comp_testvec *ctemplate,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001451 const struct comp_testvec *dtemplate,
1452 int ctcount, int dtcount)
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001453{
1454 const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
1455 unsigned int i;
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001456 char *output, *decomp_out;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001457 int ret;
1458 struct scatterlist src, dst;
1459 struct acomp_req *req;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001460 struct crypto_wait wait;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001461
Eric Biggerseb095592016-11-23 10:24:35 -08001462 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1463 if (!output)
1464 return -ENOMEM;
1465
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001466 decomp_out = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1467 if (!decomp_out) {
1468 kfree(output);
1469 return -ENOMEM;
1470 }
1471
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001472 for (i = 0; i < ctcount; i++) {
1473 unsigned int dlen = COMP_BUF_SIZE;
1474 int ilen = ctemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08001475 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001476
Eric Biggersd2110222016-12-30 14:12:00 -06001477 input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08001478 if (!input_vec) {
1479 ret = -ENOMEM;
1480 goto out;
1481 }
1482
Eric Biggerseb095592016-11-23 10:24:35 -08001483 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001484 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08001485 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001486 sg_init_one(&dst, output, dlen);
1487
1488 req = acomp_request_alloc(tfm);
1489 if (!req) {
1490 pr_err("alg: acomp: request alloc failed for %s\n",
1491 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08001492 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001493 ret = -ENOMEM;
1494 goto out;
1495 }
1496
1497 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1498 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001499 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001500
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001501 ret = crypto_wait_req(crypto_acomp_compress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001502 if (ret) {
1503 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
1504 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08001505 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001506 acomp_request_free(req);
1507 goto out;
1508 }
1509
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001510 ilen = req->dlen;
1511 dlen = COMP_BUF_SIZE;
1512 sg_init_one(&src, output, ilen);
1513 sg_init_one(&dst, decomp_out, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001514 crypto_init_wait(&wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001515 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1516
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001517 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001518 if (ret) {
1519 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
1520 i + 1, algo, -ret);
1521 kfree(input_vec);
1522 acomp_request_free(req);
1523 goto out;
1524 }
1525
1526 if (req->dlen != ctemplate[i].inlen) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001527 pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
1528 i + 1, algo, req->dlen);
1529 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001530 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001531 acomp_request_free(req);
1532 goto out;
1533 }
1534
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001535 if (memcmp(input_vec, decomp_out, req->dlen)) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001536 pr_err("alg: acomp: Compression test %d failed for %s\n",
1537 i + 1, algo);
1538 hexdump(output, req->dlen);
1539 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001540 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001541 acomp_request_free(req);
1542 goto out;
1543 }
1544
Laura Abbott02608e02016-12-21 12:32:54 -08001545 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001546 acomp_request_free(req);
1547 }
1548
1549 for (i = 0; i < dtcount; i++) {
1550 unsigned int dlen = COMP_BUF_SIZE;
1551 int ilen = dtemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08001552 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001553
Eric Biggersd2110222016-12-30 14:12:00 -06001554 input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08001555 if (!input_vec) {
1556 ret = -ENOMEM;
1557 goto out;
1558 }
1559
Eric Biggerseb095592016-11-23 10:24:35 -08001560 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001561 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08001562 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001563 sg_init_one(&dst, output, dlen);
1564
1565 req = acomp_request_alloc(tfm);
1566 if (!req) {
1567 pr_err("alg: acomp: request alloc failed for %s\n",
1568 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08001569 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001570 ret = -ENOMEM;
1571 goto out;
1572 }
1573
1574 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1575 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001576 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001577
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001578 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001579 if (ret) {
1580 pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
1581 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08001582 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001583 acomp_request_free(req);
1584 goto out;
1585 }
1586
1587 if (req->dlen != dtemplate[i].outlen) {
1588 pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
1589 i + 1, algo, req->dlen);
1590 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001591 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001592 acomp_request_free(req);
1593 goto out;
1594 }
1595
1596 if (memcmp(output, dtemplate[i].output, req->dlen)) {
1597 pr_err("alg: acomp: Decompression test %d failed for %s\n",
1598 i + 1, algo);
1599 hexdump(output, req->dlen);
1600 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001601 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001602 acomp_request_free(req);
1603 goto out;
1604 }
1605
Laura Abbott02608e02016-12-21 12:32:54 -08001606 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001607 acomp_request_free(req);
1608 }
1609
1610 ret = 0;
1611
1612out:
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001613 kfree(decomp_out);
Eric Biggerseb095592016-11-23 10:24:35 -08001614 kfree(output);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001615 return ret;
1616}
1617
Eric Biggersb13b1e02017-02-24 15:46:59 -08001618static int test_cprng(struct crypto_rng *tfm,
1619 const struct cprng_testvec *template,
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001620 unsigned int tcount)
1621{
1622 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001623 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001624 u8 *seed;
1625 char result[32];
1626
1627 seedsize = crypto_rng_seedsize(tfm);
1628
1629 seed = kmalloc(seedsize, GFP_KERNEL);
1630 if (!seed) {
1631 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1632 "for %s\n", algo);
1633 return -ENOMEM;
1634 }
1635
1636 for (i = 0; i < tcount; i++) {
1637 memset(result, 0, 32);
1638
1639 memcpy(seed, template[i].v, template[i].vlen);
1640 memcpy(seed + template[i].vlen, template[i].key,
1641 template[i].klen);
1642 memcpy(seed + template[i].vlen + template[i].klen,
1643 template[i].dt, template[i].dtlen);
1644
1645 err = crypto_rng_reset(tfm, seed, seedsize);
1646 if (err) {
1647 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1648 "for %s\n", algo);
1649 goto out;
1650 }
1651
1652 for (j = 0; j < template[i].loops; j++) {
1653 err = crypto_rng_get_bytes(tfm, result,
1654 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01001655 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001656 printk(KERN_ERR "alg: cprng: Failed to obtain "
1657 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01001658 "%s (requested %d)\n", algo,
1659 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001660 goto out;
1661 }
1662 }
1663
1664 err = memcmp(result, template[i].result,
1665 template[i].rlen);
1666 if (err) {
1667 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1668 i, algo);
1669 hexdump(result, template[i].rlen);
1670 err = -EINVAL;
1671 goto out;
1672 }
1673 }
1674
1675out:
1676 kfree(seed);
1677 return err;
1678}
1679
Herbert Xuda7f0332008-07-31 17:08:25 +08001680static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1681 u32 type, u32 mask)
1682{
1683 struct crypto_aead *tfm;
1684 int err = 0;
1685
Herbert Xueed93e02016-11-22 20:08:31 +08001686 tfm = crypto_alloc_aead(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001687 if (IS_ERR(tfm)) {
1688 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1689 "%ld\n", driver, PTR_ERR(tfm));
1690 return PTR_ERR(tfm);
1691 }
1692
1693 if (desc->suite.aead.enc.vecs) {
1694 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1695 desc->suite.aead.enc.count);
1696 if (err)
1697 goto out;
1698 }
1699
1700 if (!err && desc->suite.aead.dec.vecs)
1701 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1702 desc->suite.aead.dec.count);
1703
1704out:
1705 crypto_free_aead(tfm);
1706 return err;
1707}
1708
1709static int alg_test_cipher(const struct alg_test_desc *desc,
1710 const char *driver, u32 type, u32 mask)
1711{
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001712 const struct cipher_test_suite *suite = &desc->suite.cipher;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001713 struct crypto_cipher *tfm;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001714 int err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001715
Herbert Xueed93e02016-11-22 20:08:31 +08001716 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001717 if (IS_ERR(tfm)) {
1718 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1719 "%s: %ld\n", driver, PTR_ERR(tfm));
1720 return PTR_ERR(tfm);
1721 }
1722
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001723 err = test_cipher(tfm, ENCRYPT, suite->vecs, suite->count);
1724 if (!err)
1725 err = test_cipher(tfm, DECRYPT, suite->vecs, suite->count);
Herbert Xuda7f0332008-07-31 17:08:25 +08001726
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001727 crypto_free_cipher(tfm);
1728 return err;
1729}
1730
1731static int alg_test_skcipher(const struct alg_test_desc *desc,
1732 const char *driver, u32 type, u32 mask)
1733{
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001734 const struct cipher_test_suite *suite = &desc->suite.cipher;
Herbert Xu12773d92015-08-20 15:21:46 +08001735 struct crypto_skcipher *tfm;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001736 int err;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001737
Herbert Xueed93e02016-11-22 20:08:31 +08001738 tfm = crypto_alloc_skcipher(driver, type, mask);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001739 if (IS_ERR(tfm)) {
1740 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1741 "%s: %ld\n", driver, PTR_ERR(tfm));
1742 return PTR_ERR(tfm);
1743 }
1744
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001745 err = test_skcipher(tfm, ENCRYPT, suite->vecs, suite->count);
1746 if (!err)
1747 err = test_skcipher(tfm, DECRYPT, suite->vecs, suite->count);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001748
Herbert Xu12773d92015-08-20 15:21:46 +08001749 crypto_free_skcipher(tfm);
Herbert Xuda7f0332008-07-31 17:08:25 +08001750 return err;
1751}
1752
1753static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1754 u32 type, u32 mask)
1755{
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001756 struct crypto_comp *comp;
1757 struct crypto_acomp *acomp;
Herbert Xuda7f0332008-07-31 17:08:25 +08001758 int err;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001759 u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
Herbert Xuda7f0332008-07-31 17:08:25 +08001760
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001761 if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
1762 acomp = crypto_alloc_acomp(driver, type, mask);
1763 if (IS_ERR(acomp)) {
1764 pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
1765 driver, PTR_ERR(acomp));
1766 return PTR_ERR(acomp);
1767 }
1768 err = test_acomp(acomp, desc->suite.comp.comp.vecs,
1769 desc->suite.comp.decomp.vecs,
1770 desc->suite.comp.comp.count,
1771 desc->suite.comp.decomp.count);
1772 crypto_free_acomp(acomp);
1773 } else {
1774 comp = crypto_alloc_comp(driver, type, mask);
1775 if (IS_ERR(comp)) {
1776 pr_err("alg: comp: Failed to load transform for %s: %ld\n",
1777 driver, PTR_ERR(comp));
1778 return PTR_ERR(comp);
1779 }
1780
1781 err = test_comp(comp, desc->suite.comp.comp.vecs,
1782 desc->suite.comp.decomp.vecs,
1783 desc->suite.comp.comp.count,
1784 desc->suite.comp.decomp.count);
1785
1786 crypto_free_comp(comp);
Herbert Xuda7f0332008-07-31 17:08:25 +08001787 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001788 return err;
1789}
1790
Eric Biggers9b3abc0162018-05-19 22:07:41 -07001791static int __alg_test_hash(const struct hash_testvec *template,
1792 unsigned int tcount, const char *driver,
1793 u32 type, u32 mask)
Herbert Xuda7f0332008-07-31 17:08:25 +08001794{
1795 struct crypto_ahash *tfm;
1796 int err;
1797
Herbert Xueed93e02016-11-22 20:08:31 +08001798 tfm = crypto_alloc_ahash(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001799 if (IS_ERR(tfm)) {
1800 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1801 "%ld\n", driver, PTR_ERR(tfm));
1802 return PTR_ERR(tfm);
1803 }
1804
Eric Biggers9b3abc0162018-05-19 22:07:41 -07001805 err = test_hash(tfm, template, tcount, true);
David S. Millera8f1a052010-05-19 14:12:03 +10001806 if (!err)
Eric Biggers9b3abc0162018-05-19 22:07:41 -07001807 err = test_hash(tfm, template, tcount, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001808 crypto_free_ahash(tfm);
1809 return err;
1810}
1811
Eric Biggers9b3abc0162018-05-19 22:07:41 -07001812static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1813 u32 type, u32 mask)
1814{
1815 const struct hash_testvec *template = desc->suite.hash.vecs;
1816 unsigned int tcount = desc->suite.hash.count;
1817 unsigned int nr_unkeyed, nr_keyed;
1818 int err;
1819
1820 /*
1821 * For OPTIONAL_KEY algorithms, we have to do all the unkeyed tests
1822 * first, before setting a key on the tfm. To make this easier, we
1823 * require that the unkeyed test vectors (if any) are listed first.
1824 */
1825
1826 for (nr_unkeyed = 0; nr_unkeyed < tcount; nr_unkeyed++) {
1827 if (template[nr_unkeyed].ksize)
1828 break;
1829 }
1830 for (nr_keyed = 0; nr_unkeyed + nr_keyed < tcount; nr_keyed++) {
1831 if (!template[nr_unkeyed + nr_keyed].ksize) {
1832 pr_err("alg: hash: test vectors for %s out of order, "
1833 "unkeyed ones must come first\n", desc->alg);
1834 return -EINVAL;
1835 }
1836 }
1837
1838 err = 0;
1839 if (nr_unkeyed) {
1840 err = __alg_test_hash(template, nr_unkeyed, driver, type, mask);
1841 template += nr_unkeyed;
1842 }
1843
1844 if (!err && nr_keyed)
1845 err = __alg_test_hash(template, nr_keyed, driver, type, mask);
1846
1847 return err;
1848}
1849
Herbert Xu8e3ee852008-11-07 14:58:52 +08001850static int alg_test_crc32c(const struct alg_test_desc *desc,
1851 const char *driver, u32 type, u32 mask)
1852{
1853 struct crypto_shash *tfm;
1854 u32 val;
1855 int err;
1856
1857 err = alg_test_hash(desc, driver, type, mask);
1858 if (err)
1859 goto out;
1860
Herbert Xueed93e02016-11-22 20:08:31 +08001861 tfm = crypto_alloc_shash(driver, type, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001862 if (IS_ERR(tfm)) {
1863 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1864 "%ld\n", driver, PTR_ERR(tfm));
1865 err = PTR_ERR(tfm);
1866 goto out;
1867 }
1868
1869 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001870 SHASH_DESC_ON_STACK(shash, tfm);
1871 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001872
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001873 shash->tfm = tfm;
1874 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001875
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001876 *ctx = le32_to_cpu(420553207);
1877 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001878 if (err) {
1879 printk(KERN_ERR "alg: crc32c: Operation failed for "
1880 "%s: %d\n", driver, err);
1881 break;
1882 }
1883
1884 if (val != ~420553207) {
1885 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1886 "%d\n", driver, val);
1887 err = -EINVAL;
1888 }
1889 } while (0);
1890
1891 crypto_free_shash(tfm);
1892
1893out:
1894 return err;
1895}
1896
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001897static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1898 u32 type, u32 mask)
1899{
1900 struct crypto_rng *rng;
1901 int err;
1902
Herbert Xueed93e02016-11-22 20:08:31 +08001903 rng = crypto_alloc_rng(driver, type, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001904 if (IS_ERR(rng)) {
1905 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1906 "%ld\n", driver, PTR_ERR(rng));
1907 return PTR_ERR(rng);
1908 }
1909
1910 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1911
1912 crypto_free_rng(rng);
1913
1914 return err;
1915}
1916
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001917
Eric Biggersb13b1e02017-02-24 15:46:59 -08001918static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001919 const char *driver, u32 type, u32 mask)
1920{
1921 int ret = -EAGAIN;
1922 struct crypto_rng *drng;
1923 struct drbg_test_data test_data;
1924 struct drbg_string addtl, pers, testentropy;
1925 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1926
1927 if (!buf)
1928 return -ENOMEM;
1929
Herbert Xueed93e02016-11-22 20:08:31 +08001930 drng = crypto_alloc_rng(driver, type, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001931 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001932 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001933 "%s\n", driver);
1934 kzfree(buf);
1935 return -ENOMEM;
1936 }
1937
1938 test_data.testentropy = &testentropy;
1939 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1940 drbg_string_fill(&pers, test->pers, test->perslen);
1941 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1942 if (ret) {
1943 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1944 goto outbuf;
1945 }
1946
1947 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1948 if (pr) {
1949 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1950 ret = crypto_drbg_get_bytes_addtl_test(drng,
1951 buf, test->expectedlen, &addtl, &test_data);
1952 } else {
1953 ret = crypto_drbg_get_bytes_addtl(drng,
1954 buf, test->expectedlen, &addtl);
1955 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001956 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001957 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001958 "driver %s\n", driver);
1959 goto outbuf;
1960 }
1961
1962 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1963 if (pr) {
1964 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1965 ret = crypto_drbg_get_bytes_addtl_test(drng,
1966 buf, test->expectedlen, &addtl, &test_data);
1967 } else {
1968 ret = crypto_drbg_get_bytes_addtl(drng,
1969 buf, test->expectedlen, &addtl);
1970 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001971 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001972 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001973 "driver %s\n", driver);
1974 goto outbuf;
1975 }
1976
1977 ret = memcmp(test->expected, buf, test->expectedlen);
1978
1979outbuf:
1980 crypto_free_rng(drng);
1981 kzfree(buf);
1982 return ret;
1983}
1984
1985
1986static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1987 u32 type, u32 mask)
1988{
1989 int err = 0;
1990 int pr = 0;
1991 int i = 0;
Eric Biggersb13b1e02017-02-24 15:46:59 -08001992 const struct drbg_testvec *template = desc->suite.drbg.vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001993 unsigned int tcount = desc->suite.drbg.count;
1994
1995 if (0 == memcmp(driver, "drbg_pr_", 8))
1996 pr = 1;
1997
1998 for (i = 0; i < tcount; i++) {
1999 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
2000 if (err) {
2001 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
2002 i, driver);
2003 err = -EINVAL;
2004 break;
2005 }
2006 }
2007 return err;
2008
2009}
2010
Eric Biggersb13b1e02017-02-24 15:46:59 -08002011static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002012 const char *alg)
2013{
2014 struct kpp_request *req;
2015 void *input_buf = NULL;
2016 void *output_buf = NULL;
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002017 void *a_public = NULL;
2018 void *a_ss = NULL;
2019 void *shared_secret = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002020 struct crypto_wait wait;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002021 unsigned int out_len_max;
2022 int err = -ENOMEM;
2023 struct scatterlist src, dst;
2024
2025 req = kpp_request_alloc(tfm, GFP_KERNEL);
2026 if (!req)
2027 return err;
2028
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002029 crypto_init_wait(&wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002030
2031 err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
2032 if (err < 0)
2033 goto free_req;
2034
2035 out_len_max = crypto_kpp_maxsize(tfm);
2036 output_buf = kzalloc(out_len_max, GFP_KERNEL);
2037 if (!output_buf) {
2038 err = -ENOMEM;
2039 goto free_req;
2040 }
2041
2042 /* Use appropriate parameter as base */
2043 kpp_request_set_input(req, NULL, 0);
2044 sg_init_one(&dst, output_buf, out_len_max);
2045 kpp_request_set_output(req, &dst, out_len_max);
2046 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002047 crypto_req_done, &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002048
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002049 /* Compute party A's public key */
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002050 err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002051 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002052 pr_err("alg: %s: Party A: generate public key test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002053 alg, err);
2054 goto free_output;
2055 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002056
2057 if (vec->genkey) {
2058 /* Save party A's public key */
2059 a_public = kzalloc(out_len_max, GFP_KERNEL);
2060 if (!a_public) {
2061 err = -ENOMEM;
2062 goto free_output;
2063 }
2064 memcpy(a_public, sg_virt(req->dst), out_len_max);
2065 } else {
2066 /* Verify calculated public key */
2067 if (memcmp(vec->expected_a_public, sg_virt(req->dst),
2068 vec->expected_a_public_size)) {
2069 pr_err("alg: %s: Party A: generate public key test failed. Invalid output\n",
2070 alg);
2071 err = -EINVAL;
2072 goto free_output;
2073 }
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002074 }
2075
2076 /* Calculate shared secret key by using counter part (b) public key. */
2077 input_buf = kzalloc(vec->b_public_size, GFP_KERNEL);
2078 if (!input_buf) {
2079 err = -ENOMEM;
2080 goto free_output;
2081 }
2082
2083 memcpy(input_buf, vec->b_public, vec->b_public_size);
2084 sg_init_one(&src, input_buf, vec->b_public_size);
2085 sg_init_one(&dst, output_buf, out_len_max);
2086 kpp_request_set_input(req, &src, vec->b_public_size);
2087 kpp_request_set_output(req, &dst, out_len_max);
2088 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002089 crypto_req_done, &wait);
2090 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002091 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002092 pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002093 alg, err);
2094 goto free_all;
2095 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002096
2097 if (vec->genkey) {
2098 /* Save the shared secret obtained by party A */
2099 a_ss = kzalloc(vec->expected_ss_size, GFP_KERNEL);
2100 if (!a_ss) {
2101 err = -ENOMEM;
2102 goto free_all;
2103 }
2104 memcpy(a_ss, sg_virt(req->dst), vec->expected_ss_size);
2105
2106 /*
2107 * Calculate party B's shared secret by using party A's
2108 * public key.
2109 */
2110 err = crypto_kpp_set_secret(tfm, vec->b_secret,
2111 vec->b_secret_size);
2112 if (err < 0)
2113 goto free_all;
2114
2115 sg_init_one(&src, a_public, vec->expected_a_public_size);
2116 sg_init_one(&dst, output_buf, out_len_max);
2117 kpp_request_set_input(req, &src, vec->expected_a_public_size);
2118 kpp_request_set_output(req, &dst, out_len_max);
2119 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002120 crypto_req_done, &wait);
2121 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req),
2122 &wait);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002123 if (err) {
2124 pr_err("alg: %s: Party B: compute shared secret failed. err %d\n",
2125 alg, err);
2126 goto free_all;
2127 }
2128
2129 shared_secret = a_ss;
2130 } else {
2131 shared_secret = (void *)vec->expected_ss;
2132 }
2133
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002134 /*
2135 * verify shared secret from which the user will derive
2136 * secret key by executing whatever hash it has chosen
2137 */
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002138 if (memcmp(shared_secret, sg_virt(req->dst),
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002139 vec->expected_ss_size)) {
2140 pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
2141 alg);
2142 err = -EINVAL;
2143 }
2144
2145free_all:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002146 kfree(a_ss);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002147 kfree(input_buf);
2148free_output:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002149 kfree(a_public);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002150 kfree(output_buf);
2151free_req:
2152 kpp_request_free(req);
2153 return err;
2154}
2155
2156static int test_kpp(struct crypto_kpp *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002157 const struct kpp_testvec *vecs, unsigned int tcount)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002158{
2159 int ret, i;
2160
2161 for (i = 0; i < tcount; i++) {
2162 ret = do_test_kpp(tfm, vecs++, alg);
2163 if (ret) {
2164 pr_err("alg: %s: test failed on vector %d, err=%d\n",
2165 alg, i + 1, ret);
2166 return ret;
2167 }
2168 }
2169 return 0;
2170}
2171
2172static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
2173 u32 type, u32 mask)
2174{
2175 struct crypto_kpp *tfm;
2176 int err = 0;
2177
Herbert Xueed93e02016-11-22 20:08:31 +08002178 tfm = crypto_alloc_kpp(driver, type, mask);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002179 if (IS_ERR(tfm)) {
2180 pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
2181 driver, PTR_ERR(tfm));
2182 return PTR_ERR(tfm);
2183 }
2184 if (desc->suite.kpp.vecs)
2185 err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
2186 desc->suite.kpp.count);
2187
2188 crypto_free_kpp(tfm);
2189 return err;
2190}
2191
Herbert Xu50d2b6432016-06-29 19:32:20 +08002192static int test_akcipher_one(struct crypto_akcipher *tfm,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002193 const struct akcipher_testvec *vecs)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002194{
Herbert Xudf27b262016-05-05 16:42:49 +08002195 char *xbuf[XBUFSIZE];
Tadeusz Struk946cc462015-06-16 10:31:06 -07002196 struct akcipher_request *req;
2197 void *outbuf_enc = NULL;
2198 void *outbuf_dec = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002199 struct crypto_wait wait;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002200 unsigned int out_len_max, out_len = 0;
2201 int err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002202 struct scatterlist src, dst, src_tab[2];
Tadeusz Struk946cc462015-06-16 10:31:06 -07002203
Herbert Xudf27b262016-05-05 16:42:49 +08002204 if (testmgr_alloc_buf(xbuf))
2205 return err;
2206
Tadeusz Struk946cc462015-06-16 10:31:06 -07002207 req = akcipher_request_alloc(tfm, GFP_KERNEL);
2208 if (!req)
Herbert Xudf27b262016-05-05 16:42:49 +08002209 goto free_xbuf;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002210
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002211 crypto_init_wait(&wait);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002212
2213 if (vecs->public_key_vec)
2214 err = crypto_akcipher_set_pub_key(tfm, vecs->key,
2215 vecs->key_len);
2216 else
2217 err = crypto_akcipher_set_priv_key(tfm, vecs->key,
2218 vecs->key_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002219 if (err)
2220 goto free_req;
2221
Salvatore Benedetto57763f52016-07-04 10:52:34 +01002222 err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002223 out_len_max = crypto_akcipher_maxsize(tfm);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002224 outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
2225 if (!outbuf_enc)
2226 goto free_req;
2227
Herbert Xudf27b262016-05-05 16:42:49 +08002228 if (WARN_ON(vecs->m_size > PAGE_SIZE))
2229 goto free_all;
2230
2231 memcpy(xbuf[0], vecs->m, vecs->m_size);
2232
Tadeusz Struk22287b02015-10-08 09:26:55 -07002233 sg_init_table(src_tab, 2);
Herbert Xudf27b262016-05-05 16:42:49 +08002234 sg_set_buf(&src_tab[0], xbuf[0], 8);
2235 sg_set_buf(&src_tab[1], xbuf[0] + 8, vecs->m_size - 8);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002236 sg_init_one(&dst, outbuf_enc, out_len_max);
2237 akcipher_request_set_crypt(req, src_tab, &dst, vecs->m_size,
2238 out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002239 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002240 crypto_req_done, &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002241
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002242 err = crypto_wait_req(vecs->siggen_sigver_test ?
2243 /* Run asymmetric signature generation */
2244 crypto_akcipher_sign(req) :
2245 /* Run asymmetric encrypt */
2246 crypto_akcipher_encrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002247 if (err) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002248 pr_err("alg: akcipher: encrypt test failed. err %d\n", err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002249 goto free_all;
2250 }
Tadeusz Struk22287b02015-10-08 09:26:55 -07002251 if (req->dst_len != vecs->c_size) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002252 pr_err("alg: akcipher: encrypt test failed. Invalid output len\n");
Tadeusz Struk946cc462015-06-16 10:31:06 -07002253 err = -EINVAL;
2254 goto free_all;
2255 }
2256 /* verify that encrypted message is equal to expected */
Herbert Xudf27b262016-05-05 16:42:49 +08002257 if (memcmp(vecs->c, outbuf_enc, vecs->c_size)) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002258 pr_err("alg: akcipher: encrypt test failed. Invalid output\n");
2259 hexdump(outbuf_enc, vecs->c_size);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002260 err = -EINVAL;
2261 goto free_all;
2262 }
2263 /* Don't invoke decrypt for vectors with public key */
2264 if (vecs->public_key_vec) {
2265 err = 0;
2266 goto free_all;
2267 }
2268 outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
2269 if (!outbuf_dec) {
2270 err = -ENOMEM;
2271 goto free_all;
2272 }
Herbert Xudf27b262016-05-05 16:42:49 +08002273
2274 if (WARN_ON(vecs->c_size > PAGE_SIZE))
2275 goto free_all;
2276
2277 memcpy(xbuf[0], vecs->c, vecs->c_size);
2278
2279 sg_init_one(&src, xbuf[0], vecs->c_size);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002280 sg_init_one(&dst, outbuf_dec, out_len_max);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002281 crypto_init_wait(&wait);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002282 akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002283
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002284 err = crypto_wait_req(vecs->siggen_sigver_test ?
2285 /* Run asymmetric signature verification */
2286 crypto_akcipher_verify(req) :
2287 /* Run asymmetric decrypt */
2288 crypto_akcipher_decrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002289 if (err) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002290 pr_err("alg: akcipher: decrypt test failed. err %d\n", err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002291 goto free_all;
2292 }
2293 out_len = req->dst_len;
Herbert Xu50d2b6432016-06-29 19:32:20 +08002294 if (out_len < vecs->m_size) {
2295 pr_err("alg: akcipher: decrypt test failed. "
2296 "Invalid output len %u\n", out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002297 err = -EINVAL;
2298 goto free_all;
2299 }
2300 /* verify that decrypted message is equal to the original msg */
Herbert Xu50d2b6432016-06-29 19:32:20 +08002301 if (memchr_inv(outbuf_dec, 0, out_len - vecs->m_size) ||
2302 memcmp(vecs->m, outbuf_dec + out_len - vecs->m_size,
2303 vecs->m_size)) {
2304 pr_err("alg: akcipher: decrypt test failed. Invalid output\n");
2305 hexdump(outbuf_dec, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002306 err = -EINVAL;
2307 }
2308free_all:
2309 kfree(outbuf_dec);
2310 kfree(outbuf_enc);
2311free_req:
2312 akcipher_request_free(req);
Herbert Xudf27b262016-05-05 16:42:49 +08002313free_xbuf:
2314 testmgr_free_buf(xbuf);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002315 return err;
2316}
2317
Herbert Xu50d2b6432016-06-29 19:32:20 +08002318static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002319 const struct akcipher_testvec *vecs,
2320 unsigned int tcount)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002321{
Herbert Xu15226e42016-07-18 18:20:10 +08002322 const char *algo =
2323 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
Tadeusz Struk946cc462015-06-16 10:31:06 -07002324 int ret, i;
2325
2326 for (i = 0; i < tcount; i++) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002327 ret = test_akcipher_one(tfm, vecs++);
2328 if (!ret)
2329 continue;
2330
Herbert Xu15226e42016-07-18 18:20:10 +08002331 pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
2332 i + 1, algo, ret);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002333 return ret;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002334 }
2335 return 0;
2336}
2337
Tadeusz Struk946cc462015-06-16 10:31:06 -07002338static int alg_test_akcipher(const struct alg_test_desc *desc,
2339 const char *driver, u32 type, u32 mask)
2340{
2341 struct crypto_akcipher *tfm;
2342 int err = 0;
2343
Herbert Xueed93e02016-11-22 20:08:31 +08002344 tfm = crypto_alloc_akcipher(driver, type, mask);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002345 if (IS_ERR(tfm)) {
2346 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
2347 driver, PTR_ERR(tfm));
2348 return PTR_ERR(tfm);
2349 }
2350 if (desc->suite.akcipher.vecs)
2351 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
2352 desc->suite.akcipher.count);
2353
2354 crypto_free_akcipher(tfm);
2355 return err;
2356}
2357
Youquan, Song863b5572009-12-23 19:45:20 +08002358static int alg_test_null(const struct alg_test_desc *desc,
2359 const char *driver, u32 type, u32 mask)
2360{
2361 return 0;
2362}
2363
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002364#define __VECS(tv) { .vecs = tv, .count = ARRAY_SIZE(tv) }
2365
Herbert Xuda7f0332008-07-31 17:08:25 +08002366/* Please keep this list sorted by algorithm name. */
2367static const struct alg_test_desc alg_test_descs[] = {
2368 {
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002369 .alg = "aegis128",
2370 .test = alg_test_aead,
2371 .suite = {
2372 .aead = {
2373 .enc = __VECS(aegis128_enc_tv_template),
2374 .dec = __VECS(aegis128_dec_tv_template),
2375 }
2376 }
2377 }, {
2378 .alg = "aegis128l",
2379 .test = alg_test_aead,
2380 .suite = {
2381 .aead = {
2382 .enc = __VECS(aegis128l_enc_tv_template),
2383 .dec = __VECS(aegis128l_dec_tv_template),
2384 }
2385 }
2386 }, {
2387 .alg = "aegis256",
2388 .test = alg_test_aead,
2389 .suite = {
2390 .aead = {
2391 .enc = __VECS(aegis256_enc_tv_template),
2392 .dec = __VECS(aegis256_dec_tv_template),
2393 }
2394 }
2395 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002396 .alg = "ansi_cprng",
2397 .test = alg_test_cprng,
2398 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002399 .cprng = __VECS(ansi_cprng_aes_tv_template)
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002400 }
2401 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002402 .alg = "authenc(hmac(md5),ecb(cipher_null))",
2403 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002404 .suite = {
2405 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002406 .enc = __VECS(hmac_md5_ecb_cipher_null_enc_tv_template),
2407 .dec = __VECS(hmac_md5_ecb_cipher_null_dec_tv_template)
Horia Geantabca4feb2014-03-14 17:46:51 +02002408 }
2409 }
2410 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002411 .alg = "authenc(hmac(sha1),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002412 .test = alg_test_aead,
Herbert Xubcf741c2017-06-28 19:09:07 +08002413 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002414 .suite = {
2415 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002416 .enc = __VECS(hmac_sha1_aes_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302417 }
2418 }
2419 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002420 .alg = "authenc(hmac(sha1),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302421 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302422 .suite = {
2423 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002424 .enc = __VECS(hmac_sha1_des_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302425 }
2426 }
2427 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002428 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302429 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002430 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302431 .suite = {
2432 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002433 .enc = __VECS(hmac_sha1_des3_ede_cbc_enc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002434 }
2435 }
2436 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002437 .alg = "authenc(hmac(sha1),ctr(aes))",
2438 .test = alg_test_null,
2439 .fips_allowed = 1,
2440 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002441 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
2442 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002443 .suite = {
2444 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002445 .enc = __VECS(hmac_sha1_ecb_cipher_null_enc_tv_temp),
2446 .dec = __VECS(hmac_sha1_ecb_cipher_null_dec_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302447 }
2448 }
2449 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002450 .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
2451 .test = alg_test_null,
2452 .fips_allowed = 1,
2453 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002454 .alg = "authenc(hmac(sha224),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302455 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302456 .suite = {
2457 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002458 .enc = __VECS(hmac_sha224_des_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302459 }
2460 }
2461 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002462 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302463 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002464 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302465 .suite = {
2466 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002467 .enc = __VECS(hmac_sha224_des3_ede_cbc_enc_tv_temp)
Horia Geantabca4feb2014-03-14 17:46:51 +02002468 }
2469 }
2470 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002471 .alg = "authenc(hmac(sha256),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002472 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002473 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002474 .suite = {
2475 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002476 .enc = __VECS(hmac_sha256_aes_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302477 }
2478 }
2479 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002480 .alg = "authenc(hmac(sha256),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302481 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302482 .suite = {
2483 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002484 .enc = __VECS(hmac_sha256_des_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302485 }
2486 }
2487 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002488 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302489 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002490 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302491 .suite = {
2492 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002493 .enc = __VECS(hmac_sha256_des3_ede_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302494 }
2495 }
2496 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002497 .alg = "authenc(hmac(sha256),ctr(aes))",
2498 .test = alg_test_null,
2499 .fips_allowed = 1,
2500 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002501 .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
2502 .test = alg_test_null,
2503 .fips_allowed = 1,
2504 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002505 .alg = "authenc(hmac(sha384),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302506 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302507 .suite = {
2508 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002509 .enc = __VECS(hmac_sha384_des_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302510 }
2511 }
2512 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002513 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302514 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002515 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302516 .suite = {
2517 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002518 .enc = __VECS(hmac_sha384_des3_ede_cbc_enc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002519 }
2520 }
2521 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002522 .alg = "authenc(hmac(sha384),ctr(aes))",
2523 .test = alg_test_null,
2524 .fips_allowed = 1,
2525 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002526 .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
2527 .test = alg_test_null,
2528 .fips_allowed = 1,
2529 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002530 .alg = "authenc(hmac(sha512),cbc(aes))",
Marcus Meissnered1afac2016-02-05 14:23:33 +01002531 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002532 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002533 .suite = {
2534 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002535 .enc = __VECS(hmac_sha512_aes_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302536 }
2537 }
2538 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002539 .alg = "authenc(hmac(sha512),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302540 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302541 .suite = {
2542 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002543 .enc = __VECS(hmac_sha512_des_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302544 }
2545 }
2546 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002547 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302548 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002549 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302550 .suite = {
2551 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002552 .enc = __VECS(hmac_sha512_des3_ede_cbc_enc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002553 }
2554 }
2555 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002556 .alg = "authenc(hmac(sha512),ctr(aes))",
2557 .test = alg_test_null,
2558 .fips_allowed = 1,
2559 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002560 .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
2561 .test = alg_test_null,
2562 .fips_allowed = 1,
2563 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002564 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002565 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002566 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002567 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002568 .cipher = __VECS(aes_cbc_tv_template)
2569 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002570 }, {
2571 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002572 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002573 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002574 .cipher = __VECS(anubis_cbc_tv_template)
2575 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002576 }, {
2577 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002578 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002579 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002580 .cipher = __VECS(bf_cbc_tv_template)
2581 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002582 }, {
2583 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002584 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002585 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002586 .cipher = __VECS(camellia_cbc_tv_template)
2587 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002588 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002589 .alg = "cbc(cast5)",
2590 .test = alg_test_skcipher,
2591 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002592 .cipher = __VECS(cast5_cbc_tv_template)
2593 },
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002594 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002595 .alg = "cbc(cast6)",
2596 .test = alg_test_skcipher,
2597 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002598 .cipher = __VECS(cast6_cbc_tv_template)
2599 },
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002600 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002601 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002602 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002603 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002604 .cipher = __VECS(des_cbc_tv_template)
2605 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002606 }, {
2607 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002608 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002609 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002610 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002611 .cipher = __VECS(des3_ede_cbc_tv_template)
2612 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002613 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01002614 /* Same as cbc(aes) except the key is stored in
2615 * hardware secure memory which we reference by index
2616 */
2617 .alg = "cbc(paes)",
2618 .test = alg_test_null,
2619 .fips_allowed = 1,
2620 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002621 .alg = "cbc(serpent)",
2622 .test = alg_test_skcipher,
2623 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002624 .cipher = __VECS(serpent_cbc_tv_template)
2625 },
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002626 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002627 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002628 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002629 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002630 .cipher = __VECS(tf_cbc_tv_template)
2631 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002632 }, {
Ard Biesheuvel092acf02017-02-03 14:49:35 +00002633 .alg = "cbcmac(aes)",
2634 .fips_allowed = 1,
2635 .test = alg_test_hash,
2636 .suite = {
2637 .hash = __VECS(aes_cbcmac_tv_template)
2638 }
2639 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002640 .alg = "ccm(aes)",
2641 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002642 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002643 .suite = {
2644 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002645 .enc = __VECS(aes_ccm_enc_tv_template),
2646 .dec = __VECS(aes_ccm_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002647 }
2648 }
2649 }, {
Martin Willi3590ebf2015-06-01 13:43:57 +02002650 .alg = "chacha20",
2651 .test = alg_test_skcipher,
2652 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002653 .cipher = __VECS(chacha20_tv_template)
2654 },
Martin Willi3590ebf2015-06-01 13:43:57 +02002655 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002656 .alg = "cmac(aes)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002657 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002658 .test = alg_test_hash,
2659 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002660 .hash = __VECS(aes_cmac128_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002661 }
2662 }, {
2663 .alg = "cmac(des3_ede)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002664 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002665 .test = alg_test_hash,
2666 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002667 .hash = __VECS(des3_ede_cmac64_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002668 }
2669 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002670 .alg = "compress_null",
2671 .test = alg_test_null,
2672 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02002673 .alg = "crc32",
2674 .test = alg_test_hash,
2675 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002676 .hash = __VECS(crc32_tv_template)
Ard Biesheuvelebb34722015-05-04 11:00:17 +02002677 }
2678 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002679 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002680 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002681 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002682 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002683 .hash = __VECS(crc32c_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002684 }
2685 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002686 .alg = "crct10dif",
2687 .test = alg_test_hash,
2688 .fips_allowed = 1,
2689 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002690 .hash = __VECS(crct10dif_tv_template)
Herbert Xu684115212013-09-07 12:56:26 +10002691 }
2692 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002693 .alg = "ctr(aes)",
2694 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002695 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002696 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002697 .cipher = __VECS(aes_ctr_tv_template)
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002698 }
2699 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002700 .alg = "ctr(blowfish)",
2701 .test = alg_test_skcipher,
2702 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002703 .cipher = __VECS(bf_ctr_tv_template)
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002704 }
2705 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002706 .alg = "ctr(camellia)",
2707 .test = alg_test_skcipher,
2708 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002709 .cipher = __VECS(camellia_ctr_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02002710 }
2711 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002712 .alg = "ctr(cast5)",
2713 .test = alg_test_skcipher,
2714 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002715 .cipher = __VECS(cast5_ctr_tv_template)
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002716 }
2717 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002718 .alg = "ctr(cast6)",
2719 .test = alg_test_skcipher,
2720 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002721 .cipher = __VECS(cast6_ctr_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002722 }
2723 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002724 .alg = "ctr(des)",
2725 .test = alg_test_skcipher,
2726 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002727 .cipher = __VECS(des_ctr_tv_template)
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002728 }
2729 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002730 .alg = "ctr(des3_ede)",
2731 .test = alg_test_skcipher,
Marcelo Cerri0d8da102017-03-20 17:28:05 -03002732 .fips_allowed = 1,
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002733 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002734 .cipher = __VECS(des3_ede_ctr_tv_template)
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002735 }
2736 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01002737 /* Same as ctr(aes) except the key is stored in
2738 * hardware secure memory which we reference by index
2739 */
2740 .alg = "ctr(paes)",
2741 .test = alg_test_null,
2742 .fips_allowed = 1,
2743 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002744 .alg = "ctr(serpent)",
2745 .test = alg_test_skcipher,
2746 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002747 .cipher = __VECS(serpent_ctr_tv_template)
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002748 }
2749 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002750 .alg = "ctr(twofish)",
2751 .test = alg_test_skcipher,
2752 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002753 .cipher = __VECS(tf_ctr_tv_template)
Jussi Kivilinna573da622011-10-10 23:03:12 +03002754 }
2755 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002756 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002757 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002758 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002759 .cipher = __VECS(cts_mode_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002760 }
2761 }, {
2762 .alg = "deflate",
2763 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002764 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002765 .suite = {
2766 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002767 .comp = __VECS(deflate_comp_tv_template),
2768 .decomp = __VECS(deflate_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002769 }
2770 }
2771 }, {
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002772 .alg = "dh",
2773 .test = alg_test_kpp,
2774 .fips_allowed = 1,
2775 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002776 .kpp = __VECS(dh_tv_template)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002777 }
2778 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002779 .alg = "digest_null",
2780 .test = alg_test_null,
2781 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002782 .alg = "drbg_nopr_ctr_aes128",
2783 .test = alg_test_drbg,
2784 .fips_allowed = 1,
2785 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002786 .drbg = __VECS(drbg_nopr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002787 }
2788 }, {
2789 .alg = "drbg_nopr_ctr_aes192",
2790 .test = alg_test_drbg,
2791 .fips_allowed = 1,
2792 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002793 .drbg = __VECS(drbg_nopr_ctr_aes192_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002794 }
2795 }, {
2796 .alg = "drbg_nopr_ctr_aes256",
2797 .test = alg_test_drbg,
2798 .fips_allowed = 1,
2799 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002800 .drbg = __VECS(drbg_nopr_ctr_aes256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002801 }
2802 }, {
2803 /*
2804 * There is no need to specifically test the DRBG with every
2805 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2806 */
2807 .alg = "drbg_nopr_hmac_sha1",
2808 .fips_allowed = 1,
2809 .test = alg_test_null,
2810 }, {
2811 .alg = "drbg_nopr_hmac_sha256",
2812 .test = alg_test_drbg,
2813 .fips_allowed = 1,
2814 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002815 .drbg = __VECS(drbg_nopr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002816 }
2817 }, {
2818 /* covered by drbg_nopr_hmac_sha256 test */
2819 .alg = "drbg_nopr_hmac_sha384",
2820 .fips_allowed = 1,
2821 .test = alg_test_null,
2822 }, {
2823 .alg = "drbg_nopr_hmac_sha512",
2824 .test = alg_test_null,
2825 .fips_allowed = 1,
2826 }, {
2827 .alg = "drbg_nopr_sha1",
2828 .fips_allowed = 1,
2829 .test = alg_test_null,
2830 }, {
2831 .alg = "drbg_nopr_sha256",
2832 .test = alg_test_drbg,
2833 .fips_allowed = 1,
2834 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002835 .drbg = __VECS(drbg_nopr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002836 }
2837 }, {
2838 /* covered by drbg_nopr_sha256 test */
2839 .alg = "drbg_nopr_sha384",
2840 .fips_allowed = 1,
2841 .test = alg_test_null,
2842 }, {
2843 .alg = "drbg_nopr_sha512",
2844 .fips_allowed = 1,
2845 .test = alg_test_null,
2846 }, {
2847 .alg = "drbg_pr_ctr_aes128",
2848 .test = alg_test_drbg,
2849 .fips_allowed = 1,
2850 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002851 .drbg = __VECS(drbg_pr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002852 }
2853 }, {
2854 /* covered by drbg_pr_ctr_aes128 test */
2855 .alg = "drbg_pr_ctr_aes192",
2856 .fips_allowed = 1,
2857 .test = alg_test_null,
2858 }, {
2859 .alg = "drbg_pr_ctr_aes256",
2860 .fips_allowed = 1,
2861 .test = alg_test_null,
2862 }, {
2863 .alg = "drbg_pr_hmac_sha1",
2864 .fips_allowed = 1,
2865 .test = alg_test_null,
2866 }, {
2867 .alg = "drbg_pr_hmac_sha256",
2868 .test = alg_test_drbg,
2869 .fips_allowed = 1,
2870 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002871 .drbg = __VECS(drbg_pr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002872 }
2873 }, {
2874 /* covered by drbg_pr_hmac_sha256 test */
2875 .alg = "drbg_pr_hmac_sha384",
2876 .fips_allowed = 1,
2877 .test = alg_test_null,
2878 }, {
2879 .alg = "drbg_pr_hmac_sha512",
2880 .test = alg_test_null,
2881 .fips_allowed = 1,
2882 }, {
2883 .alg = "drbg_pr_sha1",
2884 .fips_allowed = 1,
2885 .test = alg_test_null,
2886 }, {
2887 .alg = "drbg_pr_sha256",
2888 .test = alg_test_drbg,
2889 .fips_allowed = 1,
2890 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002891 .drbg = __VECS(drbg_pr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002892 }
2893 }, {
2894 /* covered by drbg_pr_sha256 test */
2895 .alg = "drbg_pr_sha384",
2896 .fips_allowed = 1,
2897 .test = alg_test_null,
2898 }, {
2899 .alg = "drbg_pr_sha512",
2900 .fips_allowed = 1,
2901 .test = alg_test_null,
2902 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002903 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002904 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002905 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002906 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002907 .cipher = __VECS(aes_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002908 }
2909 }, {
2910 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002911 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002912 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002913 .cipher = __VECS(anubis_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002914 }
2915 }, {
2916 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002917 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002918 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002919 .cipher = __VECS(arc4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002920 }
2921 }, {
2922 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002923 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002924 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002925 .cipher = __VECS(bf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002926 }
2927 }, {
2928 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002929 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002930 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002931 .cipher = __VECS(camellia_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002932 }
2933 }, {
2934 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002935 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002936 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002937 .cipher = __VECS(cast5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002938 }
2939 }, {
2940 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002941 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002942 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002943 .cipher = __VECS(cast6_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002944 }
2945 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002946 .alg = "ecb(cipher_null)",
2947 .test = alg_test_null,
Milan Broz6175ca22017-04-21 13:03:06 +02002948 .fips_allowed = 1,
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002949 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002950 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002951 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002952 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002953 .cipher = __VECS(des_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002954 }
2955 }, {
2956 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002957 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002958 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002959 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002960 .cipher = __VECS(des3_ede_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002961 }
2962 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002963 .alg = "ecb(fcrypt)",
2964 .test = alg_test_skcipher,
2965 .suite = {
2966 .cipher = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002967 .vecs = fcrypt_pcbc_tv_template,
2968 .count = 1
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002969 }
2970 }
2971 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002972 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002973 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002974 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002975 .cipher = __VECS(khazad_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002976 }
2977 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01002978 /* Same as ecb(aes) except the key is stored in
2979 * hardware secure memory which we reference by index
2980 */
2981 .alg = "ecb(paes)",
2982 .test = alg_test_null,
2983 .fips_allowed = 1,
2984 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002985 .alg = "ecb(seed)",
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(seed_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002989 }
2990 }, {
2991 .alg = "ecb(serpent)",
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(serpent_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002995 }
2996 }, {
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00002997 .alg = "ecb(sm4)",
2998 .test = alg_test_skcipher,
2999 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003000 .cipher = __VECS(sm4_tv_template)
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00003001 }
3002 }, {
Eric Biggersda7a0ab2018-02-14 10:42:19 -08003003 .alg = "ecb(speck128)",
3004 .test = alg_test_skcipher,
3005 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003006 .cipher = __VECS(speck128_tv_template)
Eric Biggersda7a0ab2018-02-14 10:42:19 -08003007 }
3008 }, {
3009 .alg = "ecb(speck64)",
3010 .test = alg_test_skcipher,
3011 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003012 .cipher = __VECS(speck64_tv_template)
Eric Biggersda7a0ab2018-02-14 10:42:19 -08003013 }
3014 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003015 .alg = "ecb(tea)",
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(tea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003019 }
3020 }, {
3021 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003022 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003023 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003024 .cipher = __VECS(tnepres_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003025 }
3026 }, {
3027 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003028 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003029 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003030 .cipher = __VECS(tf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003031 }
3032 }, {
3033 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003034 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003035 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003036 .cipher = __VECS(xeta_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003037 }
3038 }, {
3039 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003040 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003041 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003042 .cipher = __VECS(xtea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003043 }
3044 }, {
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003045 .alg = "ecdh",
3046 .test = alg_test_kpp,
3047 .fips_allowed = 1,
3048 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003049 .kpp = __VECS(ecdh_tv_template)
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003050 }
3051 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003052 .alg = "gcm(aes)",
3053 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003054 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003055 .suite = {
3056 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003057 .enc = __VECS(aes_gcm_enc_tv_template),
3058 .dec = __VECS(aes_gcm_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003059 }
3060 }
3061 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003062 .alg = "ghash",
3063 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003064 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003065 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003066 .hash = __VECS(ghash_tv_template)
Youquan, Song507069c2009-11-23 20:23:04 +08003067 }
3068 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003069 .alg = "hmac(md5)",
3070 .test = alg_test_hash,
3071 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003072 .hash = __VECS(hmac_md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003073 }
3074 }, {
3075 .alg = "hmac(rmd128)",
3076 .test = alg_test_hash,
3077 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003078 .hash = __VECS(hmac_rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003079 }
3080 }, {
3081 .alg = "hmac(rmd160)",
3082 .test = alg_test_hash,
3083 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003084 .hash = __VECS(hmac_rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003085 }
3086 }, {
3087 .alg = "hmac(sha1)",
3088 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003089 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003090 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003091 .hash = __VECS(hmac_sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003092 }
3093 }, {
3094 .alg = "hmac(sha224)",
3095 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003096 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003097 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003098 .hash = __VECS(hmac_sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003099 }
3100 }, {
3101 .alg = "hmac(sha256)",
3102 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003103 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003104 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003105 .hash = __VECS(hmac_sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003106 }
3107 }, {
raveendra padasalagi98eca722016-07-01 11:16:54 +05303108 .alg = "hmac(sha3-224)",
3109 .test = alg_test_hash,
3110 .fips_allowed = 1,
3111 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003112 .hash = __VECS(hmac_sha3_224_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303113 }
3114 }, {
3115 .alg = "hmac(sha3-256)",
3116 .test = alg_test_hash,
3117 .fips_allowed = 1,
3118 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003119 .hash = __VECS(hmac_sha3_256_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303120 }
3121 }, {
3122 .alg = "hmac(sha3-384)",
3123 .test = alg_test_hash,
3124 .fips_allowed = 1,
3125 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003126 .hash = __VECS(hmac_sha3_384_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303127 }
3128 }, {
3129 .alg = "hmac(sha3-512)",
3130 .test = alg_test_hash,
3131 .fips_allowed = 1,
3132 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003133 .hash = __VECS(hmac_sha3_512_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303134 }
3135 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003136 .alg = "hmac(sha384)",
3137 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003138 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003139 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003140 .hash = __VECS(hmac_sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003141 }
3142 }, {
3143 .alg = "hmac(sha512)",
3144 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003145 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003146 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003147 .hash = __VECS(hmac_sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003148 }
3149 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003150 .alg = "jitterentropy_rng",
3151 .fips_allowed = 1,
3152 .test = alg_test_null,
3153 }, {
Stephan Mueller35351982015-09-21 20:59:56 +02003154 .alg = "kw(aes)",
3155 .test = alg_test_skcipher,
3156 .fips_allowed = 1,
3157 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003158 .cipher = __VECS(aes_kw_tv_template)
Stephan Mueller35351982015-09-21 20:59:56 +02003159 }
3160 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003161 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003162 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003163 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003164 .cipher = __VECS(aes_lrw_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003165 }
3166 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003167 .alg = "lrw(camellia)",
3168 .test = alg_test_skcipher,
3169 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003170 .cipher = __VECS(camellia_lrw_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003171 }
3172 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003173 .alg = "lrw(cast6)",
3174 .test = alg_test_skcipher,
3175 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003176 .cipher = __VECS(cast6_lrw_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003177 }
3178 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003179 .alg = "lrw(serpent)",
3180 .test = alg_test_skcipher,
3181 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003182 .cipher = __VECS(serpent_lrw_tv_template)
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003183 }
3184 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003185 .alg = "lrw(twofish)",
3186 .test = alg_test_skcipher,
3187 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003188 .cipher = __VECS(tf_lrw_tv_template)
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003189 }
3190 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003191 .alg = "lz4",
3192 .test = alg_test_comp,
3193 .fips_allowed = 1,
3194 .suite = {
3195 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003196 .comp = __VECS(lz4_comp_tv_template),
3197 .decomp = __VECS(lz4_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003198 }
3199 }
3200 }, {
3201 .alg = "lz4hc",
3202 .test = alg_test_comp,
3203 .fips_allowed = 1,
3204 .suite = {
3205 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003206 .comp = __VECS(lz4hc_comp_tv_template),
3207 .decomp = __VECS(lz4hc_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003208 }
3209 }
3210 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003211 .alg = "lzo",
3212 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003213 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003214 .suite = {
3215 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003216 .comp = __VECS(lzo_comp_tv_template),
3217 .decomp = __VECS(lzo_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003218 }
3219 }
3220 }, {
3221 .alg = "md4",
3222 .test = alg_test_hash,
3223 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003224 .hash = __VECS(md4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003225 }
3226 }, {
3227 .alg = "md5",
3228 .test = alg_test_hash,
3229 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003230 .hash = __VECS(md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003231 }
3232 }, {
3233 .alg = "michael_mic",
3234 .test = alg_test_hash,
3235 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003236 .hash = __VECS(michael_mic_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003237 }
3238 }, {
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003239 .alg = "morus1280",
3240 .test = alg_test_aead,
3241 .suite = {
3242 .aead = {
3243 .enc = __VECS(morus1280_enc_tv_template),
3244 .dec = __VECS(morus1280_dec_tv_template),
3245 }
3246 }
3247 }, {
3248 .alg = "morus640",
3249 .test = alg_test_aead,
3250 .suite = {
3251 .aead = {
3252 .enc = __VECS(morus640_enc_tv_template),
3253 .dec = __VECS(morus640_dec_tv_template),
3254 }
3255 }
3256 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003257 .alg = "ofb(aes)",
3258 .test = alg_test_skcipher,
3259 .fips_allowed = 1,
3260 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003261 .cipher = __VECS(aes_ofb_tv_template)
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003262 }
3263 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003264 /* Same as ofb(aes) except the key is stored in
3265 * hardware secure memory which we reference by index
3266 */
3267 .alg = "ofb(paes)",
3268 .test = alg_test_null,
3269 .fips_allowed = 1,
3270 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003271 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003272 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003273 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003274 .cipher = __VECS(fcrypt_pcbc_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003275 }
3276 }, {
Stephan Mueller12071072017-06-12 23:27:51 +02003277 .alg = "pkcs1pad(rsa,sha224)",
3278 .test = alg_test_null,
3279 .fips_allowed = 1,
3280 }, {
3281 .alg = "pkcs1pad(rsa,sha256)",
3282 .test = alg_test_akcipher,
3283 .fips_allowed = 1,
3284 .suite = {
3285 .akcipher = __VECS(pkcs1pad_rsa_tv_template)
3286 }
3287 }, {
3288 .alg = "pkcs1pad(rsa,sha384)",
3289 .test = alg_test_null,
3290 .fips_allowed = 1,
3291 }, {
3292 .alg = "pkcs1pad(rsa,sha512)",
3293 .test = alg_test_null,
3294 .fips_allowed = 1,
3295 }, {
Martin Willieee9dc62015-06-01 13:43:59 +02003296 .alg = "poly1305",
3297 .test = alg_test_hash,
3298 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003299 .hash = __VECS(poly1305_tv_template)
Martin Willieee9dc62015-06-01 13:43:59 +02003300 }
3301 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003302 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003303 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003304 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003305 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003306 .cipher = __VECS(aes_ctr_rfc3686_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003307 }
3308 }, {
Herbert Xu3f31a742015-07-09 07:17:34 +08003309 .alg = "rfc4106(gcm(aes))",
Adrian Hoban69435b92010-11-04 15:02:04 -04003310 .test = alg_test_aead,
Jarod Wilsondb71f29a2015-01-23 12:42:15 -05003311 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003312 .suite = {
3313 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003314 .enc = __VECS(aes_gcm_rfc4106_enc_tv_template),
3315 .dec = __VECS(aes_gcm_rfc4106_dec_tv_template)
Adrian Hoban69435b92010-11-04 15:02:04 -04003316 }
3317 }
3318 }, {
Herbert Xu544c4362015-07-14 16:53:22 +08003319 .alg = "rfc4309(ccm(aes))",
Jarod Wilson5d667322009-05-04 19:23:40 +08003320 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003321 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003322 .suite = {
3323 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003324 .enc = __VECS(aes_ccm_rfc4309_enc_tv_template),
3325 .dec = __VECS(aes_ccm_rfc4309_dec_tv_template)
Jarod Wilson5d667322009-05-04 19:23:40 +08003326 }
3327 }
3328 }, {
Herbert Xubb687452015-06-16 13:54:24 +08003329 .alg = "rfc4543(gcm(aes))",
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003330 .test = alg_test_aead,
3331 .suite = {
3332 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003333 .enc = __VECS(aes_gcm_rfc4543_enc_tv_template),
3334 .dec = __VECS(aes_gcm_rfc4543_dec_tv_template),
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003335 }
3336 }
3337 }, {
Martin Williaf2b76b2015-06-01 13:44:01 +02003338 .alg = "rfc7539(chacha20,poly1305)",
3339 .test = alg_test_aead,
3340 .suite = {
3341 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003342 .enc = __VECS(rfc7539_enc_tv_template),
3343 .dec = __VECS(rfc7539_dec_tv_template),
Martin Williaf2b76b2015-06-01 13:44:01 +02003344 }
3345 }
3346 }, {
Martin Willi59007582015-06-01 13:44:03 +02003347 .alg = "rfc7539esp(chacha20,poly1305)",
3348 .test = alg_test_aead,
3349 .suite = {
3350 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003351 .enc = __VECS(rfc7539esp_enc_tv_template),
3352 .dec = __VECS(rfc7539esp_dec_tv_template),
Martin Willi59007582015-06-01 13:44:03 +02003353 }
3354 }
3355 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003356 .alg = "rmd128",
3357 .test = alg_test_hash,
3358 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003359 .hash = __VECS(rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003360 }
3361 }, {
3362 .alg = "rmd160",
3363 .test = alg_test_hash,
3364 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003365 .hash = __VECS(rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003366 }
3367 }, {
3368 .alg = "rmd256",
3369 .test = alg_test_hash,
3370 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003371 .hash = __VECS(rmd256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003372 }
3373 }, {
3374 .alg = "rmd320",
3375 .test = alg_test_hash,
3376 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003377 .hash = __VECS(rmd320_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003378 }
3379 }, {
Tadeusz Struk946cc462015-06-16 10:31:06 -07003380 .alg = "rsa",
3381 .test = alg_test_akcipher,
3382 .fips_allowed = 1,
3383 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003384 .akcipher = __VECS(rsa_tv_template)
Tadeusz Struk946cc462015-06-16 10:31:06 -07003385 }
3386 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003387 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003388 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003389 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003390 .cipher = __VECS(salsa20_stream_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003391 }
3392 }, {
3393 .alg = "sha1",
3394 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003395 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003396 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003397 .hash = __VECS(sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003398 }
3399 }, {
3400 .alg = "sha224",
3401 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003402 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003403 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003404 .hash = __VECS(sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003405 }
3406 }, {
3407 .alg = "sha256",
3408 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003409 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003410 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003411 .hash = __VECS(sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003412 }
3413 }, {
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303414 .alg = "sha3-224",
3415 .test = alg_test_hash,
3416 .fips_allowed = 1,
3417 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003418 .hash = __VECS(sha3_224_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303419 }
3420 }, {
3421 .alg = "sha3-256",
3422 .test = alg_test_hash,
3423 .fips_allowed = 1,
3424 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003425 .hash = __VECS(sha3_256_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303426 }
3427 }, {
3428 .alg = "sha3-384",
3429 .test = alg_test_hash,
3430 .fips_allowed = 1,
3431 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003432 .hash = __VECS(sha3_384_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303433 }
3434 }, {
3435 .alg = "sha3-512",
3436 .test = alg_test_hash,
3437 .fips_allowed = 1,
3438 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003439 .hash = __VECS(sha3_512_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303440 }
3441 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003442 .alg = "sha384",
3443 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003444 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003445 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003446 .hash = __VECS(sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003447 }
3448 }, {
3449 .alg = "sha512",
3450 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003451 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003452 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003453 .hash = __VECS(sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003454 }
3455 }, {
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03003456 .alg = "sm3",
3457 .test = alg_test_hash,
3458 .suite = {
3459 .hash = __VECS(sm3_tv_template)
3460 }
3461 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003462 .alg = "tgr128",
3463 .test = alg_test_hash,
3464 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003465 .hash = __VECS(tgr128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003466 }
3467 }, {
3468 .alg = "tgr160",
3469 .test = alg_test_hash,
3470 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003471 .hash = __VECS(tgr160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003472 }
3473 }, {
3474 .alg = "tgr192",
3475 .test = alg_test_hash,
3476 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003477 .hash = __VECS(tgr192_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003478 }
3479 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003480 .alg = "vmac(aes)",
3481 .test = alg_test_hash,
3482 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003483 .hash = __VECS(aes_vmac128_tv_template)
Shane Wangf1939f72009-09-02 20:05:22 +10003484 }
3485 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003486 .alg = "wp256",
3487 .test = alg_test_hash,
3488 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003489 .hash = __VECS(wp256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003490 }
3491 }, {
3492 .alg = "wp384",
3493 .test = alg_test_hash,
3494 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003495 .hash = __VECS(wp384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003496 }
3497 }, {
3498 .alg = "wp512",
3499 .test = alg_test_hash,
3500 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003501 .hash = __VECS(wp512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003502 }
3503 }, {
3504 .alg = "xcbc(aes)",
3505 .test = alg_test_hash,
3506 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003507 .hash = __VECS(aes_xcbc128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003508 }
3509 }, {
3510 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003511 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003512 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003513 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003514 .cipher = __VECS(aes_xts_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003515 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003516 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003517 .alg = "xts(camellia)",
3518 .test = alg_test_skcipher,
3519 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003520 .cipher = __VECS(camellia_xts_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003521 }
3522 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003523 .alg = "xts(cast6)",
3524 .test = alg_test_skcipher,
3525 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003526 .cipher = __VECS(cast6_xts_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003527 }
3528 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003529 /* Same as xts(aes) except the key is stored in
3530 * hardware secure memory which we reference by index
3531 */
3532 .alg = "xts(paes)",
3533 .test = alg_test_null,
3534 .fips_allowed = 1,
3535 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003536 .alg = "xts(serpent)",
3537 .test = alg_test_skcipher,
3538 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003539 .cipher = __VECS(serpent_xts_tv_template)
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003540 }
3541 }, {
Eric Biggersc3bb5212018-02-14 10:42:22 -08003542 .alg = "xts(speck128)",
3543 .test = alg_test_skcipher,
3544 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003545 .cipher = __VECS(speck128_xts_tv_template)
Eric Biggersc3bb5212018-02-14 10:42:22 -08003546 }
3547 }, {
Eric Biggers41b33162018-02-14 10:42:23 -08003548 .alg = "xts(speck64)",
3549 .test = alg_test_skcipher,
3550 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003551 .cipher = __VECS(speck64_xts_tv_template)
Eric Biggers41b33162018-02-14 10:42:23 -08003552 }
3553 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003554 .alg = "xts(twofish)",
3555 .test = alg_test_skcipher,
3556 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003557 .cipher = __VECS(tf_xts_tv_template)
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003558 }
Giovanni Cabiddua368f432017-04-21 21:54:30 +01003559 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003560 .alg = "xts4096(paes)",
3561 .test = alg_test_null,
3562 .fips_allowed = 1,
3563 }, {
3564 .alg = "xts512(paes)",
3565 .test = alg_test_null,
3566 .fips_allowed = 1,
3567 }, {
Giovanni Cabiddua368f432017-04-21 21:54:30 +01003568 .alg = "zlib-deflate",
3569 .test = alg_test_comp,
3570 .fips_allowed = 1,
3571 .suite = {
3572 .comp = {
3573 .comp = __VECS(zlib_deflate_comp_tv_template),
3574 .decomp = __VECS(zlib_deflate_decomp_tv_template)
3575 }
3576 }
Nick Terrelld28fc3d2018-03-30 12:14:53 -07003577 }, {
3578 .alg = "zstd",
3579 .test = alg_test_comp,
3580 .fips_allowed = 1,
3581 .suite = {
3582 .comp = {
3583 .comp = __VECS(zstd_comp_tv_template),
3584 .decomp = __VECS(zstd_decomp_tv_template)
3585 }
3586 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003587 }
3588};
3589
Jussi Kivilinna57147582013-06-13 17:37:40 +03003590static bool alg_test_descs_checked;
3591
3592static void alg_test_descs_check_order(void)
3593{
3594 int i;
3595
3596 /* only check once */
3597 if (alg_test_descs_checked)
3598 return;
3599
3600 alg_test_descs_checked = true;
3601
3602 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3603 int diff = strcmp(alg_test_descs[i - 1].alg,
3604 alg_test_descs[i].alg);
3605
3606 if (WARN_ON(diff > 0)) {
3607 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3608 alg_test_descs[i - 1].alg,
3609 alg_test_descs[i].alg);
3610 }
3611
3612 if (WARN_ON(diff == 0)) {
3613 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3614 alg_test_descs[i].alg);
3615 }
3616 }
3617}
3618
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003619static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003620{
3621 int start = 0;
3622 int end = ARRAY_SIZE(alg_test_descs);
3623
3624 while (start < end) {
3625 int i = (start + end) / 2;
3626 int diff = strcmp(alg_test_descs[i].alg, alg);
3627
3628 if (diff > 0) {
3629 end = i;
3630 continue;
3631 }
3632
3633 if (diff < 0) {
3634 start = i + 1;
3635 continue;
3636 }
3637
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003638 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003639 }
3640
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003641 return -1;
3642}
3643
3644int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3645{
3646 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003647 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003648 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003649
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +01003650 if (!fips_enabled && notests) {
3651 printk_once(KERN_INFO "alg: self-tests disabled\n");
3652 return 0;
3653 }
3654
Jussi Kivilinna57147582013-06-13 17:37:40 +03003655 alg_test_descs_check_order();
3656
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003657 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3658 char nalg[CRYPTO_MAX_ALG_NAME];
3659
3660 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3661 sizeof(nalg))
3662 return -ENAMETOOLONG;
3663
3664 i = alg_find_test(nalg);
3665 if (i < 0)
3666 goto notest;
3667
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003668 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3669 goto non_fips_alg;
3670
Jarod Wilson941fb322009-05-04 19:49:23 +08003671 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3672 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003673 }
3674
3675 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003676 j = alg_find_test(driver);
3677 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003678 goto notest;
3679
Herbert Xua68f6612009-07-02 16:32:12 +08003680 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3681 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003682 goto non_fips_alg;
3683
Herbert Xua68f6612009-07-02 16:32:12 +08003684 rc = 0;
3685 if (i >= 0)
3686 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3687 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003688 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003689 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3690 type, mask);
3691
Jarod Wilson941fb322009-05-04 19:49:23 +08003692test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003693 if (fips_enabled && rc)
3694 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3695
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003696 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09003697 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003698
Neil Hormand12d6b62008-10-12 20:36:51 +08003699 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003700
3701notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003702 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3703 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003704non_fips_alg:
3705 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003706}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003707
Herbert Xu326a6342010-08-06 09:40:28 +08003708#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003709
Herbert Xuda7f0332008-07-31 17:08:25 +08003710EXPORT_SYMBOL_GPL(alg_test);