blob: 60a557b0f8d39a1d17edb52dbe556afbe763cb7c [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 */
Kees Cook6da2ec52018-06-12 13:55:00 -0700606 sg = kmalloc(array3_size(sizeof(*sg), 8, (diff_dst ? 4 : 2)),
607 GFP_KERNEL);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300608 if (!sg)
609 goto out_nosg;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800610 sgout = &sg[16];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300611
612 if (diff_dst)
613 d = "-ddst";
614 else
615 d = "";
616
Herbert Xuda7f0332008-07-31 17:08:25 +0800617 if (enc == ENCRYPT)
618 e = "encryption";
619 else
620 e = "decryption";
621
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100622 crypto_init_wait(&wait);
Herbert Xuda7f0332008-07-31 17:08:25 +0800623
624 req = aead_request_alloc(tfm, GFP_KERNEL);
625 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300626 pr_err("alg: aead%s: Failed to allocate request for %s\n",
627 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800628 goto out;
629 }
630
631 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100632 crypto_req_done, &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +0800633
Jerome Marchandabfa7f42016-02-03 13:58:12 +0100634 iv_len = crypto_aead_ivsize(tfm);
635
Herbert Xuda7f0332008-07-31 17:08:25 +0800636 for (i = 0, j = 0; i < tcount; i++) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300637 if (template[i].np)
638 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800639
Cristian Stoica05b1d332014-07-28 13:11:23 +0300640 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800641
Cristian Stoica05b1d332014-07-28 13:11:23 +0300642 /* some templates have no input data but they will
643 * touch input
644 */
645 input = xbuf[0];
646 input += align_offset;
647 assoc = axbuf[0];
648
649 ret = -EINVAL;
650 if (WARN_ON(align_offset + template[i].ilen >
651 PAGE_SIZE || template[i].alen > PAGE_SIZE))
652 goto out;
653
654 memcpy(input, template[i].input, template[i].ilen);
655 memcpy(assoc, template[i].assoc, template[i].alen);
656 if (template[i].iv)
Cristian Stoica424a5da2015-01-28 11:03:05 +0200657 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300658 else
Cristian Stoica424a5da2015-01-28 11:03:05 +0200659 memset(iv, 0, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300660
661 crypto_aead_clear_flags(tfm, ~0);
662 if (template[i].wk)
663 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
664
665 if (template[i].klen > MAX_KEYLEN) {
666 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
667 d, j, algo, template[i].klen,
668 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +1000669 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300670 goto out;
671 }
672 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +1000673
Cristian Stoica05b1d332014-07-28 13:11:23 +0300674 ret = crypto_aead_setkey(tfm, key, template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +0800675 if (template[i].fail == !ret) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300676 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
677 d, j, algo, crypto_aead_get_flags(tfm));
678 goto out;
679 } else if (ret)
680 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800681
Cristian Stoica05b1d332014-07-28 13:11:23 +0300682 authsize = abs(template[i].rlen - template[i].ilen);
683 ret = crypto_aead_setauthsize(tfm, authsize);
684 if (ret) {
685 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
686 d, authsize, j, algo);
687 goto out;
688 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800689
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800690 k = !!template[i].alen;
691 sg_init_table(sg, k + 1);
692 sg_set_buf(&sg[0], assoc, template[i].alen);
693 sg_set_buf(&sg[k], input,
694 template[i].ilen + (enc ? authsize : 0));
695 output = input;
696
Cristian Stoica05b1d332014-07-28 13:11:23 +0300697 if (diff_dst) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800698 sg_init_table(sgout, k + 1);
699 sg_set_buf(&sgout[0], assoc, template[i].alen);
700
Cristian Stoica05b1d332014-07-28 13:11:23 +0300701 output = xoutbuf[0];
702 output += align_offset;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800703 sg_set_buf(&sgout[k], output,
704 template[i].rlen + (enc ? 0 : authsize));
Cristian Stoica05b1d332014-07-28 13:11:23 +0300705 }
706
Cristian Stoica05b1d332014-07-28 13:11:23 +0300707 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
708 template[i].ilen, iv);
709
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800710 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300711
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100712 ret = crypto_wait_req(enc ? crypto_aead_encrypt(req)
713 : crypto_aead_decrypt(req), &wait);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300714
715 switch (ret) {
716 case 0:
717 if (template[i].novrfy) {
718 /* verification was supposed to fail */
719 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
720 d, e, j, algo);
721 /* so really, we got a bad message */
722 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +0300723 goto out;
724 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300725 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300726 case -EBADMSG:
727 if (template[i].novrfy)
728 /* verification failure was expected */
729 continue;
730 /* fall through */
731 default:
732 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
733 d, e, j, algo, -ret);
734 goto out;
735 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800736
Cristian Stoica05b1d332014-07-28 13:11:23 +0300737 q = output;
738 if (memcmp(q, template[i].result, template[i].rlen)) {
739 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
740 d, j, e, algo);
741 hexdump(q, template[i].rlen);
742 ret = -EINVAL;
743 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800744 }
745 }
746
747 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300748 /* alignment tests are only done with continuous buffers */
749 if (align_offset != 0)
750 break;
751
Cristian Stoica05b1d332014-07-28 13:11:23 +0300752 if (!template[i].np)
753 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800754
Cristian Stoica05b1d332014-07-28 13:11:23 +0300755 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800756
Cristian Stoica05b1d332014-07-28 13:11:23 +0300757 if (template[i].iv)
Jerome Marchandabfa7f42016-02-03 13:58:12 +0100758 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300759 else
760 memset(iv, 0, MAX_IVLEN);
761
762 crypto_aead_clear_flags(tfm, ~0);
763 if (template[i].wk)
764 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
765 if (template[i].klen > MAX_KEYLEN) {
766 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
767 d, j, algo, template[i].klen, MAX_KEYLEN);
768 ret = -EINVAL;
769 goto out;
770 }
771 memcpy(key, template[i].key, template[i].klen);
772
773 ret = crypto_aead_setkey(tfm, key, template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +0800774 if (template[i].fail == !ret) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300775 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
776 d, j, algo, crypto_aead_get_flags(tfm));
777 goto out;
778 } else if (ret)
779 continue;
780
781 authsize = abs(template[i].rlen - template[i].ilen);
782
783 ret = -EINVAL;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800784 sg_init_table(sg, template[i].anp + template[i].np);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300785 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800786 sg_init_table(sgout, template[i].anp + template[i].np);
787
788 ret = -EINVAL;
789 for (k = 0, temp = 0; k < template[i].anp; k++) {
790 if (WARN_ON(offset_in_page(IDX[k]) +
791 template[i].atap[k] > PAGE_SIZE))
792 goto out;
793 sg_set_buf(&sg[k],
794 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
795 offset_in_page(IDX[k]),
796 template[i].assoc + temp,
797 template[i].atap[k]),
798 template[i].atap[k]);
799 if (diff_dst)
800 sg_set_buf(&sgout[k],
801 axbuf[IDX[k] >> PAGE_SHIFT] +
802 offset_in_page(IDX[k]),
803 template[i].atap[k]);
804 temp += template[i].atap[k];
805 }
806
Cristian Stoica05b1d332014-07-28 13:11:23 +0300807 for (k = 0, temp = 0; k < template[i].np; k++) {
808 if (WARN_ON(offset_in_page(IDX[k]) +
809 template[i].tap[k] > PAGE_SIZE))
810 goto out;
811
812 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
813 memcpy(q, template[i].input + temp, template[i].tap[k]);
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800814 sg_set_buf(&sg[template[i].anp + k],
815 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300816
817 if (diff_dst) {
818 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
819 offset_in_page(IDX[k]);
820
821 memset(q, 0, template[i].tap[k]);
822
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800823 sg_set_buf(&sgout[template[i].anp + k],
824 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300825 }
826
827 n = template[i].tap[k];
828 if (k == template[i].np - 1 && enc)
829 n += authsize;
830 if (offset_in_page(q) + n < PAGE_SIZE)
831 q[n] = 0;
832
833 temp += template[i].tap[k];
834 }
835
836 ret = crypto_aead_setauthsize(tfm, authsize);
837 if (ret) {
838 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
839 d, authsize, j, algo);
840 goto out;
841 }
842
843 if (enc) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800844 if (WARN_ON(sg[template[i].anp + k - 1].offset +
845 sg[template[i].anp + k - 1].length +
846 authsize > PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300847 ret = -EINVAL;
848 goto out;
849 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800850
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300851 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800852 sgout[template[i].anp + k - 1].length +=
853 authsize;
854 sg[template[i].anp + k - 1].length += authsize;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300855 }
856
857 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
858 template[i].ilen,
859 iv);
860
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800861 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300862
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100863 ret = crypto_wait_req(enc ? crypto_aead_encrypt(req)
864 : crypto_aead_decrypt(req), &wait);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300865
866 switch (ret) {
867 case 0:
868 if (template[i].novrfy) {
869 /* verification was supposed to fail */
870 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
871 d, e, j, algo);
872 /* so really, we got a bad message */
873 ret = -EBADMSG;
874 goto out;
875 }
876 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300877 case -EBADMSG:
878 if (template[i].novrfy)
879 /* verification failure was expected */
880 continue;
881 /* fall through */
882 default:
883 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
884 d, e, j, algo, -ret);
885 goto out;
886 }
887
888 ret = -EINVAL;
889 for (k = 0, temp = 0; k < template[i].np; k++) {
890 if (diff_dst)
891 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
892 offset_in_page(IDX[k]);
893 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800894 q = xbuf[IDX[k] >> PAGE_SHIFT] +
895 offset_in_page(IDX[k]);
896
Cristian Stoica05b1d332014-07-28 13:11:23 +0300897 n = template[i].tap[k];
898 if (k == template[i].np - 1)
899 n += enc ? authsize : -authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800900
Cristian Stoica05b1d332014-07-28 13:11:23 +0300901 if (memcmp(q, template[i].result + temp, n)) {
902 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
903 d, j, e, k, algo);
904 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800905 goto out;
906 }
907
Cristian Stoica05b1d332014-07-28 13:11:23 +0300908 q += n;
909 if (k == template[i].np - 1 && !enc) {
910 if (!diff_dst &&
911 memcmp(q, template[i].input +
912 temp + n, authsize))
913 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200914 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300915 n = 0;
916 } else {
917 for (n = 0; offset_in_page(q + n) && q[n]; n++)
918 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800919 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300920 if (n) {
921 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
922 d, j, e, k, algo, n);
923 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800924 goto out;
925 }
926
Cristian Stoica05b1d332014-07-28 13:11:23 +0300927 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800928 }
929 }
930
931 ret = 0;
932
933out:
934 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300935 kfree(sg);
936out_nosg:
937 if (diff_dst)
938 testmgr_free_buf(xoutbuf);
939out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800940 testmgr_free_buf(axbuf);
941out_noaxbuf:
942 testmgr_free_buf(xbuf);
943out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300944 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700945 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800946 return ret;
947}
948
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300949static int test_aead(struct crypto_aead *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -0800950 const struct aead_testvec *template, unsigned int tcount)
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300951{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300952 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300953 int ret;
954
955 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300956 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300957 if (ret)
958 return ret;
959
960 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300961 ret = __test_aead(tfm, enc, template, tcount, true, 0);
962 if (ret)
963 return ret;
964
965 /* test unaligned buffers, check with one byte offset */
966 ret = __test_aead(tfm, enc, template, tcount, true, 1);
967 if (ret)
968 return ret;
969
970 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
971 if (alignmask) {
972 /* Check if alignment mask for tfm is correctly set. */
973 ret = __test_aead(tfm, enc, template, tcount, true,
974 alignmask + 1);
975 if (ret)
976 return ret;
977 }
978
979 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300980}
981
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000982static int test_cipher(struct crypto_cipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -0800983 const struct cipher_testvec *template,
984 unsigned int tcount)
Herbert Xuda7f0332008-07-31 17:08:25 +0800985{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000986 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
987 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000988 char *q;
989 const char *e;
Eric Biggers92a4c9f2018-05-20 22:50:29 -0700990 const char *input, *result;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000991 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800992 char *xbuf[XBUFSIZE];
993 int ret = -ENOMEM;
994
995 if (testmgr_alloc_buf(xbuf))
996 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000997
998 if (enc == ENCRYPT)
999 e = "encryption";
1000 else
1001 e = "decryption";
1002
1003 j = 0;
1004 for (i = 0; i < tcount; i++) {
1005 if (template[i].np)
1006 continue;
1007
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001008 if (fips_enabled && template[i].fips_skip)
1009 continue;
1010
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001011 input = enc ? template[i].ptext : template[i].ctext;
1012 result = enc ? template[i].ctext : template[i].ptext;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001013 j++;
1014
Herbert Xufd57f222009-05-29 16:05:42 +10001015 ret = -EINVAL;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001016 if (WARN_ON(template[i].len > PAGE_SIZE))
Herbert Xufd57f222009-05-29 16:05:42 +10001017 goto out;
1018
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001019 data = xbuf[0];
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001020 memcpy(data, input, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001021
1022 crypto_cipher_clear_flags(tfm, ~0);
1023 if (template[i].wk)
1024 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1025
1026 ret = crypto_cipher_setkey(tfm, template[i].key,
1027 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001028 if (template[i].fail == !ret) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001029 printk(KERN_ERR "alg: cipher: setkey failed "
1030 "on test %d for %s: flags=%x\n", j,
1031 algo, crypto_cipher_get_flags(tfm));
1032 goto out;
1033 } else if (ret)
1034 continue;
1035
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001036 for (k = 0; k < template[i].len;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001037 k += crypto_cipher_blocksize(tfm)) {
1038 if (enc)
1039 crypto_cipher_encrypt_one(tfm, data + k,
1040 data + k);
1041 else
1042 crypto_cipher_decrypt_one(tfm, data + k,
1043 data + k);
1044 }
1045
1046 q = data;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001047 if (memcmp(q, result, template[i].len)) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001048 printk(KERN_ERR "alg: cipher: Test %d failed "
1049 "on %s for %s\n", j, e, algo);
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001050 hexdump(q, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001051 ret = -EINVAL;
1052 goto out;
1053 }
1054 }
1055
1056 ret = 0;
1057
1058out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001059 testmgr_free_buf(xbuf);
1060out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001061 return ret;
1062}
1063
Herbert Xu12773d92015-08-20 15:21:46 +08001064static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001065 const struct cipher_testvec *template,
1066 unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001067 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001068{
Herbert Xuda7f0332008-07-31 17:08:25 +08001069 const char *algo =
Herbert Xu12773d92015-08-20 15:21:46 +08001070 crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +08001071 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +08001072 char *q;
Herbert Xu12773d92015-08-20 15:21:46 +08001073 struct skcipher_request *req;
Herbert Xuda7f0332008-07-31 17:08:25 +08001074 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001075 struct scatterlist sgout[8];
1076 const char *e, *d;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001077 struct crypto_wait wait;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001078 const char *input, *result;
Herbert Xuda7f0332008-07-31 17:08:25 +08001079 void *data;
1080 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001081 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001082 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001083 int ret = -ENOMEM;
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001084 unsigned int ivsize = crypto_skcipher_ivsize(tfm);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001085
1086 if (testmgr_alloc_buf(xbuf))
1087 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +08001088
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001089 if (diff_dst && testmgr_alloc_buf(xoutbuf))
1090 goto out_nooutbuf;
1091
1092 if (diff_dst)
1093 d = "-ddst";
1094 else
1095 d = "";
1096
Herbert Xuda7f0332008-07-31 17:08:25 +08001097 if (enc == ENCRYPT)
1098 e = "encryption";
1099 else
1100 e = "decryption";
1101
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001102 crypto_init_wait(&wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001103
Herbert Xu12773d92015-08-20 15:21:46 +08001104 req = skcipher_request_alloc(tfm, GFP_KERNEL);
Herbert Xuda7f0332008-07-31 17:08:25 +08001105 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001106 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
1107 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +08001108 goto out;
1109 }
1110
Herbert Xu12773d92015-08-20 15:21:46 +08001111 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001112 crypto_req_done, &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001113
1114 j = 0;
1115 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001116 if (template[i].np && !template[i].also_non_np)
1117 continue;
1118
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001119 if (fips_enabled && template[i].fips_skip)
1120 continue;
1121
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001122 if (template[i].iv && !(template[i].generates_iv && enc))
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001123 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001124 else
1125 memset(iv, 0, MAX_IVLEN);
1126
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001127 input = enc ? template[i].ptext : template[i].ctext;
1128 result = enc ? template[i].ctext : template[i].ptext;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001129 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001130 ret = -EINVAL;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001131 if (WARN_ON(align_offset + template[i].len > PAGE_SIZE))
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001132 goto out;
1133
1134 data = xbuf[0];
1135 data += align_offset;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001136 memcpy(data, input, template[i].len);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001137
Herbert Xu12773d92015-08-20 15:21:46 +08001138 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001139 if (template[i].wk)
Herbert Xu12773d92015-08-20 15:21:46 +08001140 crypto_skcipher_set_flags(tfm,
1141 CRYPTO_TFM_REQ_WEAK_KEY);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001142
Herbert Xu12773d92015-08-20 15:21:46 +08001143 ret = crypto_skcipher_setkey(tfm, template[i].key,
1144 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001145 if (template[i].fail == !ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001146 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001147 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001148 goto out;
1149 } else if (ret)
1150 continue;
1151
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001152 sg_init_one(&sg[0], data, template[i].len);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001153 if (diff_dst) {
1154 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001155 data += align_offset;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001156 sg_init_one(&sgout[0], data, template[i].len);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001157 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001158
Herbert Xu12773d92015-08-20 15:21:46 +08001159 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001160 template[i].len, iv);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001161 ret = crypto_wait_req(enc ? crypto_skcipher_encrypt(req) :
1162 crypto_skcipher_decrypt(req), &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001163
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001164 if (ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001165 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1166 d, e, j, algo, -ret);
1167 goto out;
1168 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001169
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001170 q = data;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001171 if (memcmp(q, result, template[i].len)) {
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001172 pr_err("alg: skcipher%s: Test %d failed (invalid result) on %s for %s\n",
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001173 d, j, e, algo);
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001174 hexdump(q, template[i].len);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001175 ret = -EINVAL;
1176 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001177 }
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001178
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001179 if (template[i].generates_iv && enc &&
1180 memcmp(iv, template[i].iv, crypto_skcipher_ivsize(tfm))) {
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001181 pr_err("alg: skcipher%s: Test %d failed (invalid output IV) on %s for %s\n",
1182 d, j, e, algo);
1183 hexdump(iv, crypto_skcipher_ivsize(tfm));
1184 ret = -EINVAL;
1185 goto out;
1186 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001187 }
1188
1189 j = 0;
1190 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001191 /* alignment tests are only done with continuous buffers */
1192 if (align_offset != 0)
1193 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001194
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001195 if (!template[i].np)
1196 continue;
1197
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001198 if (fips_enabled && template[i].fips_skip)
1199 continue;
1200
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001201 if (template[i].iv && !(template[i].generates_iv && enc))
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001202 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001203 else
1204 memset(iv, 0, MAX_IVLEN);
1205
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001206 input = enc ? template[i].ptext : template[i].ctext;
1207 result = enc ? template[i].ctext : template[i].ptext;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001208 j++;
Herbert Xu12773d92015-08-20 15:21:46 +08001209 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001210 if (template[i].wk)
Herbert Xu12773d92015-08-20 15:21:46 +08001211 crypto_skcipher_set_flags(tfm,
1212 CRYPTO_TFM_REQ_WEAK_KEY);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001213
Herbert Xu12773d92015-08-20 15:21:46 +08001214 ret = crypto_skcipher_setkey(tfm, template[i].key,
1215 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001216 if (template[i].fail == !ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001217 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001218 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001219 goto out;
1220 } else if (ret)
1221 continue;
1222
1223 temp = 0;
1224 ret = -EINVAL;
1225 sg_init_table(sg, template[i].np);
1226 if (diff_dst)
1227 sg_init_table(sgout, template[i].np);
1228 for (k = 0; k < template[i].np; k++) {
1229 if (WARN_ON(offset_in_page(IDX[k]) +
1230 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001231 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001232
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001233 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1234
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001235 memcpy(q, input + temp, template[i].tap[k]);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001236
1237 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1238 q[template[i].tap[k]] = 0;
1239
1240 sg_set_buf(&sg[k], q, template[i].tap[k]);
1241 if (diff_dst) {
1242 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1243 offset_in_page(IDX[k]);
1244
1245 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1246
1247 memset(q, 0, template[i].tap[k]);
1248 if (offset_in_page(q) +
1249 template[i].tap[k] < PAGE_SIZE)
1250 q[template[i].tap[k]] = 0;
1251 }
1252
1253 temp += template[i].tap[k];
1254 }
1255
Herbert Xu12773d92015-08-20 15:21:46 +08001256 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001257 template[i].len, iv);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001258
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001259 ret = crypto_wait_req(enc ? crypto_skcipher_encrypt(req) :
1260 crypto_skcipher_decrypt(req), &wait);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001261
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001262 if (ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001263 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1264 d, e, j, algo, -ret);
1265 goto out;
1266 }
1267
1268 temp = 0;
1269 ret = -EINVAL;
1270 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001271 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001272 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1273 offset_in_page(IDX[k]);
1274 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001275 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1276 offset_in_page(IDX[k]);
1277
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001278 if (memcmp(q, result + temp, template[i].tap[k])) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001279 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1280 d, j, e, k, algo);
1281 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001282 goto out;
1283 }
1284
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001285 q += template[i].tap[k];
1286 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1287 ;
1288 if (n) {
1289 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1290 d, j, e, k, algo, n);
1291 hexdump(q, n);
1292 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001293 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001294 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001295 }
1296 }
1297
1298 ret = 0;
1299
1300out:
Herbert Xu12773d92015-08-20 15:21:46 +08001301 skcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001302 if (diff_dst)
1303 testmgr_free_buf(xoutbuf);
1304out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001305 testmgr_free_buf(xbuf);
1306out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001307 return ret;
1308}
1309
Herbert Xu12773d92015-08-20 15:21:46 +08001310static int test_skcipher(struct crypto_skcipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001311 const struct cipher_testvec *template,
1312 unsigned int tcount)
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001313{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001314 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001315 int ret;
1316
1317 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001318 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001319 if (ret)
1320 return ret;
1321
1322 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001323 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1324 if (ret)
1325 return ret;
1326
1327 /* test unaligned buffers, check with one byte offset */
1328 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1329 if (ret)
1330 return ret;
1331
1332 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1333 if (alignmask) {
1334 /* Check if alignment mask for tfm is correctly set. */
1335 ret = __test_skcipher(tfm, enc, template, tcount, true,
1336 alignmask + 1);
1337 if (ret)
1338 return ret;
1339 }
1340
1341 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001342}
1343
Eric Biggersb13b1e02017-02-24 15:46:59 -08001344static int test_comp(struct crypto_comp *tfm,
1345 const struct comp_testvec *ctemplate,
1346 const struct comp_testvec *dtemplate,
1347 int ctcount, int dtcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08001348{
1349 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
Mahipal Challa33607382018-04-11 20:28:32 +02001350 char *output, *decomp_output;
Herbert Xuda7f0332008-07-31 17:08:25 +08001351 unsigned int i;
Herbert Xuda7f0332008-07-31 17:08:25 +08001352 int ret;
1353
Mahipal Challa33607382018-04-11 20:28:32 +02001354 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1355 if (!output)
1356 return -ENOMEM;
1357
1358 decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1359 if (!decomp_output) {
1360 kfree(output);
1361 return -ENOMEM;
1362 }
1363
Herbert Xuda7f0332008-07-31 17:08:25 +08001364 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001365 int ilen;
1366 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001367
Mahipal Challa33607382018-04-11 20:28:32 +02001368 memset(output, 0, sizeof(COMP_BUF_SIZE));
1369 memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
Herbert Xuda7f0332008-07-31 17:08:25 +08001370
1371 ilen = ctemplate[i].inlen;
1372 ret = crypto_comp_compress(tfm, ctemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02001373 ilen, output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001374 if (ret) {
1375 printk(KERN_ERR "alg: comp: compression failed "
1376 "on test %d for %s: ret=%d\n", i + 1, algo,
1377 -ret);
1378 goto out;
1379 }
1380
Mahipal Challa33607382018-04-11 20:28:32 +02001381 ilen = dlen;
1382 dlen = COMP_BUF_SIZE;
1383 ret = crypto_comp_decompress(tfm, output,
1384 ilen, decomp_output, &dlen);
1385 if (ret) {
1386 pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n",
1387 i + 1, algo, -ret);
1388 goto out;
1389 }
1390
1391 if (dlen != ctemplate[i].inlen) {
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001392 printk(KERN_ERR "alg: comp: Compression test %d "
1393 "failed for %s: output len = %d\n", i + 1, algo,
1394 dlen);
1395 ret = -EINVAL;
1396 goto out;
1397 }
1398
Mahipal Challa33607382018-04-11 20:28:32 +02001399 if (memcmp(decomp_output, ctemplate[i].input,
1400 ctemplate[i].inlen)) {
1401 pr_err("alg: comp: compression failed: output differs: on test %d for %s\n",
1402 i + 1, algo);
1403 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001404 ret = -EINVAL;
1405 goto out;
1406 }
1407 }
1408
1409 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001410 int ilen;
1411 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001412
Mahipal Challa33607382018-04-11 20:28:32 +02001413 memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
Herbert Xuda7f0332008-07-31 17:08:25 +08001414
1415 ilen = dtemplate[i].inlen;
1416 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02001417 ilen, decomp_output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001418 if (ret) {
1419 printk(KERN_ERR "alg: comp: decompression failed "
1420 "on test %d for %s: ret=%d\n", i + 1, algo,
1421 -ret);
1422 goto out;
1423 }
1424
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001425 if (dlen != dtemplate[i].outlen) {
1426 printk(KERN_ERR "alg: comp: Decompression test %d "
1427 "failed for %s: output len = %d\n", i + 1, algo,
1428 dlen);
1429 ret = -EINVAL;
1430 goto out;
1431 }
1432
Mahipal Challa33607382018-04-11 20:28:32 +02001433 if (memcmp(decomp_output, dtemplate[i].output, dlen)) {
Herbert Xuda7f0332008-07-31 17:08:25 +08001434 printk(KERN_ERR "alg: comp: Decompression test %d "
1435 "failed for %s\n", i + 1, algo);
Mahipal Challa33607382018-04-11 20:28:32 +02001436 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001437 ret = -EINVAL;
1438 goto out;
1439 }
1440 }
1441
1442 ret = 0;
1443
1444out:
Mahipal Challa33607382018-04-11 20:28:32 +02001445 kfree(decomp_output);
1446 kfree(output);
Herbert Xuda7f0332008-07-31 17:08:25 +08001447 return ret;
1448}
1449
Eric Biggersb13b1e02017-02-24 15:46:59 -08001450static int test_acomp(struct crypto_acomp *tfm,
Mahipal Challa33607382018-04-11 20:28:32 +02001451 const struct comp_testvec *ctemplate,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001452 const struct comp_testvec *dtemplate,
1453 int ctcount, int dtcount)
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001454{
1455 const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
1456 unsigned int i;
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001457 char *output, *decomp_out;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001458 int ret;
1459 struct scatterlist src, dst;
1460 struct acomp_req *req;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001461 struct crypto_wait wait;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001462
Eric Biggerseb095592016-11-23 10:24:35 -08001463 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1464 if (!output)
1465 return -ENOMEM;
1466
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001467 decomp_out = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1468 if (!decomp_out) {
1469 kfree(output);
1470 return -ENOMEM;
1471 }
1472
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001473 for (i = 0; i < ctcount; i++) {
1474 unsigned int dlen = COMP_BUF_SIZE;
1475 int ilen = ctemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08001476 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001477
Eric Biggersd2110222016-12-30 14:12:00 -06001478 input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08001479 if (!input_vec) {
1480 ret = -ENOMEM;
1481 goto out;
1482 }
1483
Eric Biggerseb095592016-11-23 10:24:35 -08001484 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001485 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08001486 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001487 sg_init_one(&dst, output, dlen);
1488
1489 req = acomp_request_alloc(tfm);
1490 if (!req) {
1491 pr_err("alg: acomp: request alloc failed for %s\n",
1492 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08001493 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001494 ret = -ENOMEM;
1495 goto out;
1496 }
1497
1498 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1499 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001500 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001501
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001502 ret = crypto_wait_req(crypto_acomp_compress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001503 if (ret) {
1504 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
1505 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08001506 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001507 acomp_request_free(req);
1508 goto out;
1509 }
1510
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001511 ilen = req->dlen;
1512 dlen = COMP_BUF_SIZE;
1513 sg_init_one(&src, output, ilen);
1514 sg_init_one(&dst, decomp_out, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001515 crypto_init_wait(&wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001516 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1517
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001518 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001519 if (ret) {
1520 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
1521 i + 1, algo, -ret);
1522 kfree(input_vec);
1523 acomp_request_free(req);
1524 goto out;
1525 }
1526
1527 if (req->dlen != ctemplate[i].inlen) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001528 pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
1529 i + 1, algo, req->dlen);
1530 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001531 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001532 acomp_request_free(req);
1533 goto out;
1534 }
1535
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001536 if (memcmp(input_vec, decomp_out, req->dlen)) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001537 pr_err("alg: acomp: Compression test %d failed for %s\n",
1538 i + 1, algo);
1539 hexdump(output, req->dlen);
1540 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001541 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001542 acomp_request_free(req);
1543 goto out;
1544 }
1545
Laura Abbott02608e02016-12-21 12:32:54 -08001546 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001547 acomp_request_free(req);
1548 }
1549
1550 for (i = 0; i < dtcount; i++) {
1551 unsigned int dlen = COMP_BUF_SIZE;
1552 int ilen = dtemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08001553 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001554
Eric Biggersd2110222016-12-30 14:12:00 -06001555 input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08001556 if (!input_vec) {
1557 ret = -ENOMEM;
1558 goto out;
1559 }
1560
Eric Biggerseb095592016-11-23 10:24:35 -08001561 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001562 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08001563 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001564 sg_init_one(&dst, output, dlen);
1565
1566 req = acomp_request_alloc(tfm);
1567 if (!req) {
1568 pr_err("alg: acomp: request alloc failed for %s\n",
1569 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08001570 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001571 ret = -ENOMEM;
1572 goto out;
1573 }
1574
1575 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1576 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001577 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001578
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001579 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001580 if (ret) {
1581 pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
1582 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08001583 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001584 acomp_request_free(req);
1585 goto out;
1586 }
1587
1588 if (req->dlen != dtemplate[i].outlen) {
1589 pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
1590 i + 1, algo, req->dlen);
1591 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001592 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001593 acomp_request_free(req);
1594 goto out;
1595 }
1596
1597 if (memcmp(output, dtemplate[i].output, req->dlen)) {
1598 pr_err("alg: acomp: Decompression test %d failed for %s\n",
1599 i + 1, algo);
1600 hexdump(output, req->dlen);
1601 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001602 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001603 acomp_request_free(req);
1604 goto out;
1605 }
1606
Laura Abbott02608e02016-12-21 12:32:54 -08001607 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001608 acomp_request_free(req);
1609 }
1610
1611 ret = 0;
1612
1613out:
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001614 kfree(decomp_out);
Eric Biggerseb095592016-11-23 10:24:35 -08001615 kfree(output);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001616 return ret;
1617}
1618
Eric Biggersb13b1e02017-02-24 15:46:59 -08001619static int test_cprng(struct crypto_rng *tfm,
1620 const struct cprng_testvec *template,
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001621 unsigned int tcount)
1622{
1623 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001624 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001625 u8 *seed;
1626 char result[32];
1627
1628 seedsize = crypto_rng_seedsize(tfm);
1629
1630 seed = kmalloc(seedsize, GFP_KERNEL);
1631 if (!seed) {
1632 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1633 "for %s\n", algo);
1634 return -ENOMEM;
1635 }
1636
1637 for (i = 0; i < tcount; i++) {
1638 memset(result, 0, 32);
1639
1640 memcpy(seed, template[i].v, template[i].vlen);
1641 memcpy(seed + template[i].vlen, template[i].key,
1642 template[i].klen);
1643 memcpy(seed + template[i].vlen + template[i].klen,
1644 template[i].dt, template[i].dtlen);
1645
1646 err = crypto_rng_reset(tfm, seed, seedsize);
1647 if (err) {
1648 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1649 "for %s\n", algo);
1650 goto out;
1651 }
1652
1653 for (j = 0; j < template[i].loops; j++) {
1654 err = crypto_rng_get_bytes(tfm, result,
1655 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01001656 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001657 printk(KERN_ERR "alg: cprng: Failed to obtain "
1658 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01001659 "%s (requested %d)\n", algo,
1660 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001661 goto out;
1662 }
1663 }
1664
1665 err = memcmp(result, template[i].result,
1666 template[i].rlen);
1667 if (err) {
1668 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1669 i, algo);
1670 hexdump(result, template[i].rlen);
1671 err = -EINVAL;
1672 goto out;
1673 }
1674 }
1675
1676out:
1677 kfree(seed);
1678 return err;
1679}
1680
Herbert Xuda7f0332008-07-31 17:08:25 +08001681static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1682 u32 type, u32 mask)
1683{
1684 struct crypto_aead *tfm;
1685 int err = 0;
1686
Herbert Xueed93e02016-11-22 20:08:31 +08001687 tfm = crypto_alloc_aead(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001688 if (IS_ERR(tfm)) {
1689 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1690 "%ld\n", driver, PTR_ERR(tfm));
1691 return PTR_ERR(tfm);
1692 }
1693
1694 if (desc->suite.aead.enc.vecs) {
1695 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1696 desc->suite.aead.enc.count);
1697 if (err)
1698 goto out;
1699 }
1700
1701 if (!err && desc->suite.aead.dec.vecs)
1702 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1703 desc->suite.aead.dec.count);
1704
1705out:
1706 crypto_free_aead(tfm);
1707 return err;
1708}
1709
1710static int alg_test_cipher(const struct alg_test_desc *desc,
1711 const char *driver, u32 type, u32 mask)
1712{
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001713 const struct cipher_test_suite *suite = &desc->suite.cipher;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001714 struct crypto_cipher *tfm;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001715 int err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001716
Herbert Xueed93e02016-11-22 20:08:31 +08001717 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001718 if (IS_ERR(tfm)) {
1719 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1720 "%s: %ld\n", driver, PTR_ERR(tfm));
1721 return PTR_ERR(tfm);
1722 }
1723
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001724 err = test_cipher(tfm, ENCRYPT, suite->vecs, suite->count);
1725 if (!err)
1726 err = test_cipher(tfm, DECRYPT, suite->vecs, suite->count);
Herbert Xuda7f0332008-07-31 17:08:25 +08001727
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001728 crypto_free_cipher(tfm);
1729 return err;
1730}
1731
1732static int alg_test_skcipher(const struct alg_test_desc *desc,
1733 const char *driver, u32 type, u32 mask)
1734{
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001735 const struct cipher_test_suite *suite = &desc->suite.cipher;
Herbert Xu12773d92015-08-20 15:21:46 +08001736 struct crypto_skcipher *tfm;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001737 int err;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001738
Herbert Xueed93e02016-11-22 20:08:31 +08001739 tfm = crypto_alloc_skcipher(driver, type, mask);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001740 if (IS_ERR(tfm)) {
1741 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1742 "%s: %ld\n", driver, PTR_ERR(tfm));
1743 return PTR_ERR(tfm);
1744 }
1745
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001746 err = test_skcipher(tfm, ENCRYPT, suite->vecs, suite->count);
1747 if (!err)
1748 err = test_skcipher(tfm, DECRYPT, suite->vecs, suite->count);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001749
Herbert Xu12773d92015-08-20 15:21:46 +08001750 crypto_free_skcipher(tfm);
Herbert Xuda7f0332008-07-31 17:08:25 +08001751 return err;
1752}
1753
1754static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1755 u32 type, u32 mask)
1756{
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001757 struct crypto_comp *comp;
1758 struct crypto_acomp *acomp;
Herbert Xuda7f0332008-07-31 17:08:25 +08001759 int err;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001760 u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
Herbert Xuda7f0332008-07-31 17:08:25 +08001761
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001762 if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
1763 acomp = crypto_alloc_acomp(driver, type, mask);
1764 if (IS_ERR(acomp)) {
1765 pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
1766 driver, PTR_ERR(acomp));
1767 return PTR_ERR(acomp);
1768 }
1769 err = test_acomp(acomp, desc->suite.comp.comp.vecs,
1770 desc->suite.comp.decomp.vecs,
1771 desc->suite.comp.comp.count,
1772 desc->suite.comp.decomp.count);
1773 crypto_free_acomp(acomp);
1774 } else {
1775 comp = crypto_alloc_comp(driver, type, mask);
1776 if (IS_ERR(comp)) {
1777 pr_err("alg: comp: Failed to load transform for %s: %ld\n",
1778 driver, PTR_ERR(comp));
1779 return PTR_ERR(comp);
1780 }
1781
1782 err = test_comp(comp, desc->suite.comp.comp.vecs,
1783 desc->suite.comp.decomp.vecs,
1784 desc->suite.comp.comp.count,
1785 desc->suite.comp.decomp.count);
1786
1787 crypto_free_comp(comp);
Herbert Xuda7f0332008-07-31 17:08:25 +08001788 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001789 return err;
1790}
1791
Eric Biggers9b3abc0162018-05-19 22:07:41 -07001792static int __alg_test_hash(const struct hash_testvec *template,
1793 unsigned int tcount, const char *driver,
1794 u32 type, u32 mask)
Herbert Xuda7f0332008-07-31 17:08:25 +08001795{
1796 struct crypto_ahash *tfm;
1797 int err;
1798
Herbert Xueed93e02016-11-22 20:08:31 +08001799 tfm = crypto_alloc_ahash(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001800 if (IS_ERR(tfm)) {
1801 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1802 "%ld\n", driver, PTR_ERR(tfm));
1803 return PTR_ERR(tfm);
1804 }
1805
Eric Biggers9b3abc0162018-05-19 22:07:41 -07001806 err = test_hash(tfm, template, tcount, true);
David S. Millera8f1a052010-05-19 14:12:03 +10001807 if (!err)
Eric Biggers9b3abc0162018-05-19 22:07:41 -07001808 err = test_hash(tfm, template, tcount, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001809 crypto_free_ahash(tfm);
1810 return err;
1811}
1812
Eric Biggers9b3abc0162018-05-19 22:07:41 -07001813static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1814 u32 type, u32 mask)
1815{
1816 const struct hash_testvec *template = desc->suite.hash.vecs;
1817 unsigned int tcount = desc->suite.hash.count;
1818 unsigned int nr_unkeyed, nr_keyed;
1819 int err;
1820
1821 /*
1822 * For OPTIONAL_KEY algorithms, we have to do all the unkeyed tests
1823 * first, before setting a key on the tfm. To make this easier, we
1824 * require that the unkeyed test vectors (if any) are listed first.
1825 */
1826
1827 for (nr_unkeyed = 0; nr_unkeyed < tcount; nr_unkeyed++) {
1828 if (template[nr_unkeyed].ksize)
1829 break;
1830 }
1831 for (nr_keyed = 0; nr_unkeyed + nr_keyed < tcount; nr_keyed++) {
1832 if (!template[nr_unkeyed + nr_keyed].ksize) {
1833 pr_err("alg: hash: test vectors for %s out of order, "
1834 "unkeyed ones must come first\n", desc->alg);
1835 return -EINVAL;
1836 }
1837 }
1838
1839 err = 0;
1840 if (nr_unkeyed) {
1841 err = __alg_test_hash(template, nr_unkeyed, driver, type, mask);
1842 template += nr_unkeyed;
1843 }
1844
1845 if (!err && nr_keyed)
1846 err = __alg_test_hash(template, nr_keyed, driver, type, mask);
1847
1848 return err;
1849}
1850
Herbert Xu8e3ee852008-11-07 14:58:52 +08001851static int alg_test_crc32c(const struct alg_test_desc *desc,
1852 const char *driver, u32 type, u32 mask)
1853{
1854 struct crypto_shash *tfm;
1855 u32 val;
1856 int err;
1857
1858 err = alg_test_hash(desc, driver, type, mask);
1859 if (err)
1860 goto out;
1861
Herbert Xueed93e02016-11-22 20:08:31 +08001862 tfm = crypto_alloc_shash(driver, type, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001863 if (IS_ERR(tfm)) {
1864 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1865 "%ld\n", driver, PTR_ERR(tfm));
1866 err = PTR_ERR(tfm);
1867 goto out;
1868 }
1869
1870 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001871 SHASH_DESC_ON_STACK(shash, tfm);
1872 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001873
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001874 shash->tfm = tfm;
1875 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001876
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001877 *ctx = le32_to_cpu(420553207);
1878 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001879 if (err) {
1880 printk(KERN_ERR "alg: crc32c: Operation failed for "
1881 "%s: %d\n", driver, err);
1882 break;
1883 }
1884
1885 if (val != ~420553207) {
1886 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1887 "%d\n", driver, val);
1888 err = -EINVAL;
1889 }
1890 } while (0);
1891
1892 crypto_free_shash(tfm);
1893
1894out:
1895 return err;
1896}
1897
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001898static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1899 u32 type, u32 mask)
1900{
1901 struct crypto_rng *rng;
1902 int err;
1903
Herbert Xueed93e02016-11-22 20:08:31 +08001904 rng = crypto_alloc_rng(driver, type, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001905 if (IS_ERR(rng)) {
1906 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1907 "%ld\n", driver, PTR_ERR(rng));
1908 return PTR_ERR(rng);
1909 }
1910
1911 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1912
1913 crypto_free_rng(rng);
1914
1915 return err;
1916}
1917
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001918
Eric Biggersb13b1e02017-02-24 15:46:59 -08001919static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001920 const char *driver, u32 type, u32 mask)
1921{
1922 int ret = -EAGAIN;
1923 struct crypto_rng *drng;
1924 struct drbg_test_data test_data;
1925 struct drbg_string addtl, pers, testentropy;
1926 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1927
1928 if (!buf)
1929 return -ENOMEM;
1930
Herbert Xueed93e02016-11-22 20:08:31 +08001931 drng = crypto_alloc_rng(driver, type, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001932 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001933 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001934 "%s\n", driver);
1935 kzfree(buf);
1936 return -ENOMEM;
1937 }
1938
1939 test_data.testentropy = &testentropy;
1940 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1941 drbg_string_fill(&pers, test->pers, test->perslen);
1942 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1943 if (ret) {
1944 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1945 goto outbuf;
1946 }
1947
1948 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1949 if (pr) {
1950 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1951 ret = crypto_drbg_get_bytes_addtl_test(drng,
1952 buf, test->expectedlen, &addtl, &test_data);
1953 } else {
1954 ret = crypto_drbg_get_bytes_addtl(drng,
1955 buf, test->expectedlen, &addtl);
1956 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001957 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001958 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001959 "driver %s\n", driver);
1960 goto outbuf;
1961 }
1962
1963 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1964 if (pr) {
1965 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1966 ret = crypto_drbg_get_bytes_addtl_test(drng,
1967 buf, test->expectedlen, &addtl, &test_data);
1968 } else {
1969 ret = crypto_drbg_get_bytes_addtl(drng,
1970 buf, test->expectedlen, &addtl);
1971 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001972 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001973 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001974 "driver %s\n", driver);
1975 goto outbuf;
1976 }
1977
1978 ret = memcmp(test->expected, buf, test->expectedlen);
1979
1980outbuf:
1981 crypto_free_rng(drng);
1982 kzfree(buf);
1983 return ret;
1984}
1985
1986
1987static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1988 u32 type, u32 mask)
1989{
1990 int err = 0;
1991 int pr = 0;
1992 int i = 0;
Eric Biggersb13b1e02017-02-24 15:46:59 -08001993 const struct drbg_testvec *template = desc->suite.drbg.vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001994 unsigned int tcount = desc->suite.drbg.count;
1995
1996 if (0 == memcmp(driver, "drbg_pr_", 8))
1997 pr = 1;
1998
1999 for (i = 0; i < tcount; i++) {
2000 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
2001 if (err) {
2002 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
2003 i, driver);
2004 err = -EINVAL;
2005 break;
2006 }
2007 }
2008 return err;
2009
2010}
2011
Eric Biggersb13b1e02017-02-24 15:46:59 -08002012static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002013 const char *alg)
2014{
2015 struct kpp_request *req;
2016 void *input_buf = NULL;
2017 void *output_buf = NULL;
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002018 void *a_public = NULL;
2019 void *a_ss = NULL;
2020 void *shared_secret = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002021 struct crypto_wait wait;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002022 unsigned int out_len_max;
2023 int err = -ENOMEM;
2024 struct scatterlist src, dst;
2025
2026 req = kpp_request_alloc(tfm, GFP_KERNEL);
2027 if (!req)
2028 return err;
2029
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002030 crypto_init_wait(&wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002031
2032 err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
2033 if (err < 0)
2034 goto free_req;
2035
2036 out_len_max = crypto_kpp_maxsize(tfm);
2037 output_buf = kzalloc(out_len_max, GFP_KERNEL);
2038 if (!output_buf) {
2039 err = -ENOMEM;
2040 goto free_req;
2041 }
2042
2043 /* Use appropriate parameter as base */
2044 kpp_request_set_input(req, NULL, 0);
2045 sg_init_one(&dst, output_buf, out_len_max);
2046 kpp_request_set_output(req, &dst, out_len_max);
2047 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002048 crypto_req_done, &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002049
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002050 /* Compute party A's public key */
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002051 err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002052 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002053 pr_err("alg: %s: Party A: generate public key test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002054 alg, err);
2055 goto free_output;
2056 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002057
2058 if (vec->genkey) {
2059 /* Save party A's public key */
2060 a_public = kzalloc(out_len_max, GFP_KERNEL);
2061 if (!a_public) {
2062 err = -ENOMEM;
2063 goto free_output;
2064 }
2065 memcpy(a_public, sg_virt(req->dst), out_len_max);
2066 } else {
2067 /* Verify calculated public key */
2068 if (memcmp(vec->expected_a_public, sg_virt(req->dst),
2069 vec->expected_a_public_size)) {
2070 pr_err("alg: %s: Party A: generate public key test failed. Invalid output\n",
2071 alg);
2072 err = -EINVAL;
2073 goto free_output;
2074 }
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002075 }
2076
2077 /* Calculate shared secret key by using counter part (b) public key. */
2078 input_buf = kzalloc(vec->b_public_size, GFP_KERNEL);
2079 if (!input_buf) {
2080 err = -ENOMEM;
2081 goto free_output;
2082 }
2083
2084 memcpy(input_buf, vec->b_public, vec->b_public_size);
2085 sg_init_one(&src, input_buf, vec->b_public_size);
2086 sg_init_one(&dst, output_buf, out_len_max);
2087 kpp_request_set_input(req, &src, vec->b_public_size);
2088 kpp_request_set_output(req, &dst, out_len_max);
2089 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002090 crypto_req_done, &wait);
2091 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002092 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002093 pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002094 alg, err);
2095 goto free_all;
2096 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002097
2098 if (vec->genkey) {
2099 /* Save the shared secret obtained by party A */
2100 a_ss = kzalloc(vec->expected_ss_size, GFP_KERNEL);
2101 if (!a_ss) {
2102 err = -ENOMEM;
2103 goto free_all;
2104 }
2105 memcpy(a_ss, sg_virt(req->dst), vec->expected_ss_size);
2106
2107 /*
2108 * Calculate party B's shared secret by using party A's
2109 * public key.
2110 */
2111 err = crypto_kpp_set_secret(tfm, vec->b_secret,
2112 vec->b_secret_size);
2113 if (err < 0)
2114 goto free_all;
2115
2116 sg_init_one(&src, a_public, vec->expected_a_public_size);
2117 sg_init_one(&dst, output_buf, out_len_max);
2118 kpp_request_set_input(req, &src, vec->expected_a_public_size);
2119 kpp_request_set_output(req, &dst, out_len_max);
2120 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002121 crypto_req_done, &wait);
2122 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req),
2123 &wait);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002124 if (err) {
2125 pr_err("alg: %s: Party B: compute shared secret failed. err %d\n",
2126 alg, err);
2127 goto free_all;
2128 }
2129
2130 shared_secret = a_ss;
2131 } else {
2132 shared_secret = (void *)vec->expected_ss;
2133 }
2134
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002135 /*
2136 * verify shared secret from which the user will derive
2137 * secret key by executing whatever hash it has chosen
2138 */
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002139 if (memcmp(shared_secret, sg_virt(req->dst),
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002140 vec->expected_ss_size)) {
2141 pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
2142 alg);
2143 err = -EINVAL;
2144 }
2145
2146free_all:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002147 kfree(a_ss);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002148 kfree(input_buf);
2149free_output:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002150 kfree(a_public);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002151 kfree(output_buf);
2152free_req:
2153 kpp_request_free(req);
2154 return err;
2155}
2156
2157static int test_kpp(struct crypto_kpp *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002158 const struct kpp_testvec *vecs, unsigned int tcount)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002159{
2160 int ret, i;
2161
2162 for (i = 0; i < tcount; i++) {
2163 ret = do_test_kpp(tfm, vecs++, alg);
2164 if (ret) {
2165 pr_err("alg: %s: test failed on vector %d, err=%d\n",
2166 alg, i + 1, ret);
2167 return ret;
2168 }
2169 }
2170 return 0;
2171}
2172
2173static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
2174 u32 type, u32 mask)
2175{
2176 struct crypto_kpp *tfm;
2177 int err = 0;
2178
Herbert Xueed93e02016-11-22 20:08:31 +08002179 tfm = crypto_alloc_kpp(driver, type, mask);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002180 if (IS_ERR(tfm)) {
2181 pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
2182 driver, PTR_ERR(tfm));
2183 return PTR_ERR(tfm);
2184 }
2185 if (desc->suite.kpp.vecs)
2186 err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
2187 desc->suite.kpp.count);
2188
2189 crypto_free_kpp(tfm);
2190 return err;
2191}
2192
Herbert Xu50d2b6432016-06-29 19:32:20 +08002193static int test_akcipher_one(struct crypto_akcipher *tfm,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002194 const struct akcipher_testvec *vecs)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002195{
Herbert Xudf27b262016-05-05 16:42:49 +08002196 char *xbuf[XBUFSIZE];
Tadeusz Struk946cc462015-06-16 10:31:06 -07002197 struct akcipher_request *req;
2198 void *outbuf_enc = NULL;
2199 void *outbuf_dec = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002200 struct crypto_wait wait;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002201 unsigned int out_len_max, out_len = 0;
2202 int err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002203 struct scatterlist src, dst, src_tab[2];
Tadeusz Struk946cc462015-06-16 10:31:06 -07002204
Herbert Xudf27b262016-05-05 16:42:49 +08002205 if (testmgr_alloc_buf(xbuf))
2206 return err;
2207
Tadeusz Struk946cc462015-06-16 10:31:06 -07002208 req = akcipher_request_alloc(tfm, GFP_KERNEL);
2209 if (!req)
Herbert Xudf27b262016-05-05 16:42:49 +08002210 goto free_xbuf;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002211
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002212 crypto_init_wait(&wait);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002213
2214 if (vecs->public_key_vec)
2215 err = crypto_akcipher_set_pub_key(tfm, vecs->key,
2216 vecs->key_len);
2217 else
2218 err = crypto_akcipher_set_priv_key(tfm, vecs->key,
2219 vecs->key_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002220 if (err)
2221 goto free_req;
2222
Salvatore Benedetto57763f52016-07-04 10:52:34 +01002223 err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002224 out_len_max = crypto_akcipher_maxsize(tfm);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002225 outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
2226 if (!outbuf_enc)
2227 goto free_req;
2228
Herbert Xudf27b262016-05-05 16:42:49 +08002229 if (WARN_ON(vecs->m_size > PAGE_SIZE))
2230 goto free_all;
2231
2232 memcpy(xbuf[0], vecs->m, vecs->m_size);
2233
Tadeusz Struk22287b02015-10-08 09:26:55 -07002234 sg_init_table(src_tab, 2);
Herbert Xudf27b262016-05-05 16:42:49 +08002235 sg_set_buf(&src_tab[0], xbuf[0], 8);
2236 sg_set_buf(&src_tab[1], xbuf[0] + 8, vecs->m_size - 8);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002237 sg_init_one(&dst, outbuf_enc, out_len_max);
2238 akcipher_request_set_crypt(req, src_tab, &dst, vecs->m_size,
2239 out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002240 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002241 crypto_req_done, &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002242
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002243 err = crypto_wait_req(vecs->siggen_sigver_test ?
2244 /* Run asymmetric signature generation */
2245 crypto_akcipher_sign(req) :
2246 /* Run asymmetric encrypt */
2247 crypto_akcipher_encrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002248 if (err) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002249 pr_err("alg: akcipher: encrypt test failed. err %d\n", err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002250 goto free_all;
2251 }
Tadeusz Struk22287b02015-10-08 09:26:55 -07002252 if (req->dst_len != vecs->c_size) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002253 pr_err("alg: akcipher: encrypt test failed. Invalid output len\n");
Tadeusz Struk946cc462015-06-16 10:31:06 -07002254 err = -EINVAL;
2255 goto free_all;
2256 }
2257 /* verify that encrypted message is equal to expected */
Herbert Xudf27b262016-05-05 16:42:49 +08002258 if (memcmp(vecs->c, outbuf_enc, vecs->c_size)) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002259 pr_err("alg: akcipher: encrypt test failed. Invalid output\n");
2260 hexdump(outbuf_enc, vecs->c_size);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002261 err = -EINVAL;
2262 goto free_all;
2263 }
2264 /* Don't invoke decrypt for vectors with public key */
2265 if (vecs->public_key_vec) {
2266 err = 0;
2267 goto free_all;
2268 }
2269 outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
2270 if (!outbuf_dec) {
2271 err = -ENOMEM;
2272 goto free_all;
2273 }
Herbert Xudf27b262016-05-05 16:42:49 +08002274
2275 if (WARN_ON(vecs->c_size > PAGE_SIZE))
2276 goto free_all;
2277
2278 memcpy(xbuf[0], vecs->c, vecs->c_size);
2279
2280 sg_init_one(&src, xbuf[0], vecs->c_size);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002281 sg_init_one(&dst, outbuf_dec, out_len_max);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002282 crypto_init_wait(&wait);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002283 akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002284
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002285 err = crypto_wait_req(vecs->siggen_sigver_test ?
2286 /* Run asymmetric signature verification */
2287 crypto_akcipher_verify(req) :
2288 /* Run asymmetric decrypt */
2289 crypto_akcipher_decrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002290 if (err) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002291 pr_err("alg: akcipher: decrypt test failed. err %d\n", err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002292 goto free_all;
2293 }
2294 out_len = req->dst_len;
Herbert Xu50d2b6432016-06-29 19:32:20 +08002295 if (out_len < vecs->m_size) {
2296 pr_err("alg: akcipher: decrypt test failed. "
2297 "Invalid output len %u\n", out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002298 err = -EINVAL;
2299 goto free_all;
2300 }
2301 /* verify that decrypted message is equal to the original msg */
Herbert Xu50d2b6432016-06-29 19:32:20 +08002302 if (memchr_inv(outbuf_dec, 0, out_len - vecs->m_size) ||
2303 memcmp(vecs->m, outbuf_dec + out_len - vecs->m_size,
2304 vecs->m_size)) {
2305 pr_err("alg: akcipher: decrypt test failed. Invalid output\n");
2306 hexdump(outbuf_dec, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002307 err = -EINVAL;
2308 }
2309free_all:
2310 kfree(outbuf_dec);
2311 kfree(outbuf_enc);
2312free_req:
2313 akcipher_request_free(req);
Herbert Xudf27b262016-05-05 16:42:49 +08002314free_xbuf:
2315 testmgr_free_buf(xbuf);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002316 return err;
2317}
2318
Herbert Xu50d2b6432016-06-29 19:32:20 +08002319static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002320 const struct akcipher_testvec *vecs,
2321 unsigned int tcount)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002322{
Herbert Xu15226e42016-07-18 18:20:10 +08002323 const char *algo =
2324 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
Tadeusz Struk946cc462015-06-16 10:31:06 -07002325 int ret, i;
2326
2327 for (i = 0; i < tcount; i++) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002328 ret = test_akcipher_one(tfm, vecs++);
2329 if (!ret)
2330 continue;
2331
Herbert Xu15226e42016-07-18 18:20:10 +08002332 pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
2333 i + 1, algo, ret);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002334 return ret;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002335 }
2336 return 0;
2337}
2338
Tadeusz Struk946cc462015-06-16 10:31:06 -07002339static int alg_test_akcipher(const struct alg_test_desc *desc,
2340 const char *driver, u32 type, u32 mask)
2341{
2342 struct crypto_akcipher *tfm;
2343 int err = 0;
2344
Herbert Xueed93e02016-11-22 20:08:31 +08002345 tfm = crypto_alloc_akcipher(driver, type, mask);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002346 if (IS_ERR(tfm)) {
2347 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
2348 driver, PTR_ERR(tfm));
2349 return PTR_ERR(tfm);
2350 }
2351 if (desc->suite.akcipher.vecs)
2352 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
2353 desc->suite.akcipher.count);
2354
2355 crypto_free_akcipher(tfm);
2356 return err;
2357}
2358
Youquan, Song863b5572009-12-23 19:45:20 +08002359static int alg_test_null(const struct alg_test_desc *desc,
2360 const char *driver, u32 type, u32 mask)
2361{
2362 return 0;
2363}
2364
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002365#define __VECS(tv) { .vecs = tv, .count = ARRAY_SIZE(tv) }
2366
Herbert Xuda7f0332008-07-31 17:08:25 +08002367/* Please keep this list sorted by algorithm name. */
2368static const struct alg_test_desc alg_test_descs[] = {
2369 {
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002370 .alg = "aegis128",
2371 .test = alg_test_aead,
2372 .suite = {
2373 .aead = {
2374 .enc = __VECS(aegis128_enc_tv_template),
2375 .dec = __VECS(aegis128_dec_tv_template),
2376 }
2377 }
2378 }, {
2379 .alg = "aegis128l",
2380 .test = alg_test_aead,
2381 .suite = {
2382 .aead = {
2383 .enc = __VECS(aegis128l_enc_tv_template),
2384 .dec = __VECS(aegis128l_dec_tv_template),
2385 }
2386 }
2387 }, {
2388 .alg = "aegis256",
2389 .test = alg_test_aead,
2390 .suite = {
2391 .aead = {
2392 .enc = __VECS(aegis256_enc_tv_template),
2393 .dec = __VECS(aegis256_dec_tv_template),
2394 }
2395 }
2396 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002397 .alg = "ansi_cprng",
2398 .test = alg_test_cprng,
2399 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002400 .cprng = __VECS(ansi_cprng_aes_tv_template)
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002401 }
2402 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002403 .alg = "authenc(hmac(md5),ecb(cipher_null))",
2404 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002405 .suite = {
2406 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002407 .enc = __VECS(hmac_md5_ecb_cipher_null_enc_tv_template),
2408 .dec = __VECS(hmac_md5_ecb_cipher_null_dec_tv_template)
Horia Geantabca4feb2014-03-14 17:46:51 +02002409 }
2410 }
2411 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002412 .alg = "authenc(hmac(sha1),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002413 .test = alg_test_aead,
Herbert Xubcf741c2017-06-28 19:09:07 +08002414 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002415 .suite = {
2416 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002417 .enc = __VECS(hmac_sha1_aes_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302418 }
2419 }
2420 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002421 .alg = "authenc(hmac(sha1),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302422 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302423 .suite = {
2424 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002425 .enc = __VECS(hmac_sha1_des_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302426 }
2427 }
2428 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002429 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302430 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002431 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302432 .suite = {
2433 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002434 .enc = __VECS(hmac_sha1_des3_ede_cbc_enc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002435 }
2436 }
2437 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002438 .alg = "authenc(hmac(sha1),ctr(aes))",
2439 .test = alg_test_null,
2440 .fips_allowed = 1,
2441 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002442 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
2443 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002444 .suite = {
2445 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002446 .enc = __VECS(hmac_sha1_ecb_cipher_null_enc_tv_temp),
2447 .dec = __VECS(hmac_sha1_ecb_cipher_null_dec_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302448 }
2449 }
2450 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002451 .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
2452 .test = alg_test_null,
2453 .fips_allowed = 1,
2454 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002455 .alg = "authenc(hmac(sha224),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302456 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302457 .suite = {
2458 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002459 .enc = __VECS(hmac_sha224_des_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302460 }
2461 }
2462 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002463 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302464 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002465 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302466 .suite = {
2467 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002468 .enc = __VECS(hmac_sha224_des3_ede_cbc_enc_tv_temp)
Horia Geantabca4feb2014-03-14 17:46:51 +02002469 }
2470 }
2471 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002472 .alg = "authenc(hmac(sha256),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002473 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002474 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002475 .suite = {
2476 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002477 .enc = __VECS(hmac_sha256_aes_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302478 }
2479 }
2480 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002481 .alg = "authenc(hmac(sha256),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302482 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302483 .suite = {
2484 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002485 .enc = __VECS(hmac_sha256_des_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302486 }
2487 }
2488 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002489 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302490 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002491 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302492 .suite = {
2493 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002494 .enc = __VECS(hmac_sha256_des3_ede_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302495 }
2496 }
2497 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002498 .alg = "authenc(hmac(sha256),ctr(aes))",
2499 .test = alg_test_null,
2500 .fips_allowed = 1,
2501 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002502 .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
2503 .test = alg_test_null,
2504 .fips_allowed = 1,
2505 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002506 .alg = "authenc(hmac(sha384),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302507 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302508 .suite = {
2509 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002510 .enc = __VECS(hmac_sha384_des_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302511 }
2512 }
2513 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002514 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302515 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002516 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302517 .suite = {
2518 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002519 .enc = __VECS(hmac_sha384_des3_ede_cbc_enc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002520 }
2521 }
2522 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002523 .alg = "authenc(hmac(sha384),ctr(aes))",
2524 .test = alg_test_null,
2525 .fips_allowed = 1,
2526 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002527 .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
2528 .test = alg_test_null,
2529 .fips_allowed = 1,
2530 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002531 .alg = "authenc(hmac(sha512),cbc(aes))",
Marcus Meissnered1afac2016-02-05 14:23:33 +01002532 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002533 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002534 .suite = {
2535 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002536 .enc = __VECS(hmac_sha512_aes_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302537 }
2538 }
2539 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002540 .alg = "authenc(hmac(sha512),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302541 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302542 .suite = {
2543 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002544 .enc = __VECS(hmac_sha512_des_cbc_enc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302545 }
2546 }
2547 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002548 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302549 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002550 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302551 .suite = {
2552 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002553 .enc = __VECS(hmac_sha512_des3_ede_cbc_enc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002554 }
2555 }
2556 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002557 .alg = "authenc(hmac(sha512),ctr(aes))",
2558 .test = alg_test_null,
2559 .fips_allowed = 1,
2560 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002561 .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
2562 .test = alg_test_null,
2563 .fips_allowed = 1,
2564 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002565 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002566 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002567 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002568 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002569 .cipher = __VECS(aes_cbc_tv_template)
2570 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002571 }, {
2572 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002573 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002574 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002575 .cipher = __VECS(anubis_cbc_tv_template)
2576 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002577 }, {
2578 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002579 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002580 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002581 .cipher = __VECS(bf_cbc_tv_template)
2582 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002583 }, {
2584 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002585 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002586 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002587 .cipher = __VECS(camellia_cbc_tv_template)
2588 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002589 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002590 .alg = "cbc(cast5)",
2591 .test = alg_test_skcipher,
2592 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002593 .cipher = __VECS(cast5_cbc_tv_template)
2594 },
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002595 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002596 .alg = "cbc(cast6)",
2597 .test = alg_test_skcipher,
2598 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002599 .cipher = __VECS(cast6_cbc_tv_template)
2600 },
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002601 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002602 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002603 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002604 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002605 .cipher = __VECS(des_cbc_tv_template)
2606 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002607 }, {
2608 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002609 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002610 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002611 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002612 .cipher = __VECS(des3_ede_cbc_tv_template)
2613 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002614 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01002615 /* Same as cbc(aes) except the key is stored in
2616 * hardware secure memory which we reference by index
2617 */
2618 .alg = "cbc(paes)",
2619 .test = alg_test_null,
2620 .fips_allowed = 1,
2621 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002622 .alg = "cbc(serpent)",
2623 .test = alg_test_skcipher,
2624 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002625 .cipher = __VECS(serpent_cbc_tv_template)
2626 },
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002627 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002628 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002629 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002630 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002631 .cipher = __VECS(tf_cbc_tv_template)
2632 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002633 }, {
Ard Biesheuvel092acf02017-02-03 14:49:35 +00002634 .alg = "cbcmac(aes)",
2635 .fips_allowed = 1,
2636 .test = alg_test_hash,
2637 .suite = {
2638 .hash = __VECS(aes_cbcmac_tv_template)
2639 }
2640 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002641 .alg = "ccm(aes)",
2642 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002643 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002644 .suite = {
2645 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002646 .enc = __VECS(aes_ccm_enc_tv_template),
2647 .dec = __VECS(aes_ccm_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002648 }
2649 }
2650 }, {
Martin Willi3590ebf2015-06-01 13:43:57 +02002651 .alg = "chacha20",
2652 .test = alg_test_skcipher,
2653 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002654 .cipher = __VECS(chacha20_tv_template)
2655 },
Martin Willi3590ebf2015-06-01 13:43:57 +02002656 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002657 .alg = "cmac(aes)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002658 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002659 .test = alg_test_hash,
2660 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002661 .hash = __VECS(aes_cmac128_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002662 }
2663 }, {
2664 .alg = "cmac(des3_ede)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002665 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002666 .test = alg_test_hash,
2667 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002668 .hash = __VECS(des3_ede_cmac64_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002669 }
2670 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002671 .alg = "compress_null",
2672 .test = alg_test_null,
2673 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02002674 .alg = "crc32",
2675 .test = alg_test_hash,
2676 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002677 .hash = __VECS(crc32_tv_template)
Ard Biesheuvelebb34722015-05-04 11:00:17 +02002678 }
2679 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002680 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002681 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002682 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002683 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002684 .hash = __VECS(crc32c_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002685 }
2686 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002687 .alg = "crct10dif",
2688 .test = alg_test_hash,
2689 .fips_allowed = 1,
2690 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002691 .hash = __VECS(crct10dif_tv_template)
Herbert Xu684115212013-09-07 12:56:26 +10002692 }
2693 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002694 .alg = "ctr(aes)",
2695 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002696 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002697 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002698 .cipher = __VECS(aes_ctr_tv_template)
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002699 }
2700 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002701 .alg = "ctr(blowfish)",
2702 .test = alg_test_skcipher,
2703 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002704 .cipher = __VECS(bf_ctr_tv_template)
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002705 }
2706 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002707 .alg = "ctr(camellia)",
2708 .test = alg_test_skcipher,
2709 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002710 .cipher = __VECS(camellia_ctr_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02002711 }
2712 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002713 .alg = "ctr(cast5)",
2714 .test = alg_test_skcipher,
2715 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002716 .cipher = __VECS(cast5_ctr_tv_template)
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002717 }
2718 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002719 .alg = "ctr(cast6)",
2720 .test = alg_test_skcipher,
2721 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002722 .cipher = __VECS(cast6_ctr_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002723 }
2724 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002725 .alg = "ctr(des)",
2726 .test = alg_test_skcipher,
2727 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002728 .cipher = __VECS(des_ctr_tv_template)
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002729 }
2730 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002731 .alg = "ctr(des3_ede)",
2732 .test = alg_test_skcipher,
Marcelo Cerri0d8da102017-03-20 17:28:05 -03002733 .fips_allowed = 1,
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002734 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002735 .cipher = __VECS(des3_ede_ctr_tv_template)
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002736 }
2737 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01002738 /* Same as ctr(aes) except the key is stored in
2739 * hardware secure memory which we reference by index
2740 */
2741 .alg = "ctr(paes)",
2742 .test = alg_test_null,
2743 .fips_allowed = 1,
2744 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002745 .alg = "ctr(serpent)",
2746 .test = alg_test_skcipher,
2747 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002748 .cipher = __VECS(serpent_ctr_tv_template)
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002749 }
2750 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002751 .alg = "ctr(twofish)",
2752 .test = alg_test_skcipher,
2753 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002754 .cipher = __VECS(tf_ctr_tv_template)
Jussi Kivilinna573da622011-10-10 23:03:12 +03002755 }
2756 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002757 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002758 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002759 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002760 .cipher = __VECS(cts_mode_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002761 }
2762 }, {
2763 .alg = "deflate",
2764 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002765 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002766 .suite = {
2767 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002768 .comp = __VECS(deflate_comp_tv_template),
2769 .decomp = __VECS(deflate_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002770 }
2771 }
2772 }, {
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002773 .alg = "dh",
2774 .test = alg_test_kpp,
2775 .fips_allowed = 1,
2776 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002777 .kpp = __VECS(dh_tv_template)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002778 }
2779 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002780 .alg = "digest_null",
2781 .test = alg_test_null,
2782 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002783 .alg = "drbg_nopr_ctr_aes128",
2784 .test = alg_test_drbg,
2785 .fips_allowed = 1,
2786 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002787 .drbg = __VECS(drbg_nopr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002788 }
2789 }, {
2790 .alg = "drbg_nopr_ctr_aes192",
2791 .test = alg_test_drbg,
2792 .fips_allowed = 1,
2793 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002794 .drbg = __VECS(drbg_nopr_ctr_aes192_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002795 }
2796 }, {
2797 .alg = "drbg_nopr_ctr_aes256",
2798 .test = alg_test_drbg,
2799 .fips_allowed = 1,
2800 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002801 .drbg = __VECS(drbg_nopr_ctr_aes256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002802 }
2803 }, {
2804 /*
2805 * There is no need to specifically test the DRBG with every
2806 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2807 */
2808 .alg = "drbg_nopr_hmac_sha1",
2809 .fips_allowed = 1,
2810 .test = alg_test_null,
2811 }, {
2812 .alg = "drbg_nopr_hmac_sha256",
2813 .test = alg_test_drbg,
2814 .fips_allowed = 1,
2815 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002816 .drbg = __VECS(drbg_nopr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002817 }
2818 }, {
2819 /* covered by drbg_nopr_hmac_sha256 test */
2820 .alg = "drbg_nopr_hmac_sha384",
2821 .fips_allowed = 1,
2822 .test = alg_test_null,
2823 }, {
2824 .alg = "drbg_nopr_hmac_sha512",
2825 .test = alg_test_null,
2826 .fips_allowed = 1,
2827 }, {
2828 .alg = "drbg_nopr_sha1",
2829 .fips_allowed = 1,
2830 .test = alg_test_null,
2831 }, {
2832 .alg = "drbg_nopr_sha256",
2833 .test = alg_test_drbg,
2834 .fips_allowed = 1,
2835 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002836 .drbg = __VECS(drbg_nopr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002837 }
2838 }, {
2839 /* covered by drbg_nopr_sha256 test */
2840 .alg = "drbg_nopr_sha384",
2841 .fips_allowed = 1,
2842 .test = alg_test_null,
2843 }, {
2844 .alg = "drbg_nopr_sha512",
2845 .fips_allowed = 1,
2846 .test = alg_test_null,
2847 }, {
2848 .alg = "drbg_pr_ctr_aes128",
2849 .test = alg_test_drbg,
2850 .fips_allowed = 1,
2851 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002852 .drbg = __VECS(drbg_pr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002853 }
2854 }, {
2855 /* covered by drbg_pr_ctr_aes128 test */
2856 .alg = "drbg_pr_ctr_aes192",
2857 .fips_allowed = 1,
2858 .test = alg_test_null,
2859 }, {
2860 .alg = "drbg_pr_ctr_aes256",
2861 .fips_allowed = 1,
2862 .test = alg_test_null,
2863 }, {
2864 .alg = "drbg_pr_hmac_sha1",
2865 .fips_allowed = 1,
2866 .test = alg_test_null,
2867 }, {
2868 .alg = "drbg_pr_hmac_sha256",
2869 .test = alg_test_drbg,
2870 .fips_allowed = 1,
2871 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002872 .drbg = __VECS(drbg_pr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002873 }
2874 }, {
2875 /* covered by drbg_pr_hmac_sha256 test */
2876 .alg = "drbg_pr_hmac_sha384",
2877 .fips_allowed = 1,
2878 .test = alg_test_null,
2879 }, {
2880 .alg = "drbg_pr_hmac_sha512",
2881 .test = alg_test_null,
2882 .fips_allowed = 1,
2883 }, {
2884 .alg = "drbg_pr_sha1",
2885 .fips_allowed = 1,
2886 .test = alg_test_null,
2887 }, {
2888 .alg = "drbg_pr_sha256",
2889 .test = alg_test_drbg,
2890 .fips_allowed = 1,
2891 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002892 .drbg = __VECS(drbg_pr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002893 }
2894 }, {
2895 /* covered by drbg_pr_sha256 test */
2896 .alg = "drbg_pr_sha384",
2897 .fips_allowed = 1,
2898 .test = alg_test_null,
2899 }, {
2900 .alg = "drbg_pr_sha512",
2901 .fips_allowed = 1,
2902 .test = alg_test_null,
2903 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002904 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002905 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002906 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002907 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002908 .cipher = __VECS(aes_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002909 }
2910 }, {
2911 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002912 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002913 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002914 .cipher = __VECS(anubis_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002915 }
2916 }, {
2917 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002918 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002919 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002920 .cipher = __VECS(arc4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002921 }
2922 }, {
2923 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002924 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002925 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002926 .cipher = __VECS(bf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002927 }
2928 }, {
2929 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002930 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002931 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002932 .cipher = __VECS(camellia_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002933 }
2934 }, {
2935 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002936 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002937 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002938 .cipher = __VECS(cast5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002939 }
2940 }, {
2941 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002942 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002943 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002944 .cipher = __VECS(cast6_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002945 }
2946 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002947 .alg = "ecb(cipher_null)",
2948 .test = alg_test_null,
Milan Broz6175ca22017-04-21 13:03:06 +02002949 .fips_allowed = 1,
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002950 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002951 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002952 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002953 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002954 .cipher = __VECS(des_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002955 }
2956 }, {
2957 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002958 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002959 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002960 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002961 .cipher = __VECS(des3_ede_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002962 }
2963 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002964 .alg = "ecb(fcrypt)",
2965 .test = alg_test_skcipher,
2966 .suite = {
2967 .cipher = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002968 .vecs = fcrypt_pcbc_tv_template,
2969 .count = 1
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002970 }
2971 }
2972 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002973 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002974 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002975 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002976 .cipher = __VECS(khazad_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002977 }
2978 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01002979 /* Same as ecb(aes) except the key is stored in
2980 * hardware secure memory which we reference by index
2981 */
2982 .alg = "ecb(paes)",
2983 .test = alg_test_null,
2984 .fips_allowed = 1,
2985 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002986 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002987 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002988 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002989 .cipher = __VECS(seed_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002990 }
2991 }, {
2992 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002993 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002994 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002995 .cipher = __VECS(serpent_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002996 }
2997 }, {
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00002998 .alg = "ecb(sm4)",
2999 .test = alg_test_skcipher,
3000 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003001 .cipher = __VECS(sm4_tv_template)
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00003002 }
3003 }, {
Eric Biggersda7a0ab2018-02-14 10:42:19 -08003004 .alg = "ecb(speck128)",
3005 .test = alg_test_skcipher,
3006 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003007 .cipher = __VECS(speck128_tv_template)
Eric Biggersda7a0ab2018-02-14 10:42:19 -08003008 }
3009 }, {
3010 .alg = "ecb(speck64)",
3011 .test = alg_test_skcipher,
3012 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003013 .cipher = __VECS(speck64_tv_template)
Eric Biggersda7a0ab2018-02-14 10:42:19 -08003014 }
3015 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003016 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003017 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003018 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003019 .cipher = __VECS(tea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003020 }
3021 }, {
3022 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003023 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003024 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003025 .cipher = __VECS(tnepres_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003026 }
3027 }, {
3028 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003029 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003030 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003031 .cipher = __VECS(tf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003032 }
3033 }, {
3034 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003035 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003036 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003037 .cipher = __VECS(xeta_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003038 }
3039 }, {
3040 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003041 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003042 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003043 .cipher = __VECS(xtea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003044 }
3045 }, {
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003046 .alg = "ecdh",
3047 .test = alg_test_kpp,
3048 .fips_allowed = 1,
3049 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003050 .kpp = __VECS(ecdh_tv_template)
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003051 }
3052 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003053 .alg = "gcm(aes)",
3054 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003055 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003056 .suite = {
3057 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003058 .enc = __VECS(aes_gcm_enc_tv_template),
3059 .dec = __VECS(aes_gcm_dec_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003060 }
3061 }
3062 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003063 .alg = "ghash",
3064 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003065 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003066 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003067 .hash = __VECS(ghash_tv_template)
Youquan, Song507069c2009-11-23 20:23:04 +08003068 }
3069 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003070 .alg = "hmac(md5)",
3071 .test = alg_test_hash,
3072 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003073 .hash = __VECS(hmac_md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003074 }
3075 }, {
3076 .alg = "hmac(rmd128)",
3077 .test = alg_test_hash,
3078 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003079 .hash = __VECS(hmac_rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003080 }
3081 }, {
3082 .alg = "hmac(rmd160)",
3083 .test = alg_test_hash,
3084 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003085 .hash = __VECS(hmac_rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003086 }
3087 }, {
3088 .alg = "hmac(sha1)",
3089 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003090 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003091 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003092 .hash = __VECS(hmac_sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003093 }
3094 }, {
3095 .alg = "hmac(sha224)",
3096 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003097 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003098 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003099 .hash = __VECS(hmac_sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003100 }
3101 }, {
3102 .alg = "hmac(sha256)",
3103 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003104 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003105 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003106 .hash = __VECS(hmac_sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003107 }
3108 }, {
raveendra padasalagi98eca722016-07-01 11:16:54 +05303109 .alg = "hmac(sha3-224)",
3110 .test = alg_test_hash,
3111 .fips_allowed = 1,
3112 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003113 .hash = __VECS(hmac_sha3_224_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303114 }
3115 }, {
3116 .alg = "hmac(sha3-256)",
3117 .test = alg_test_hash,
3118 .fips_allowed = 1,
3119 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003120 .hash = __VECS(hmac_sha3_256_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303121 }
3122 }, {
3123 .alg = "hmac(sha3-384)",
3124 .test = alg_test_hash,
3125 .fips_allowed = 1,
3126 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003127 .hash = __VECS(hmac_sha3_384_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303128 }
3129 }, {
3130 .alg = "hmac(sha3-512)",
3131 .test = alg_test_hash,
3132 .fips_allowed = 1,
3133 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003134 .hash = __VECS(hmac_sha3_512_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303135 }
3136 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003137 .alg = "hmac(sha384)",
3138 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003139 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003140 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003141 .hash = __VECS(hmac_sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003142 }
3143 }, {
3144 .alg = "hmac(sha512)",
3145 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003146 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003147 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003148 .hash = __VECS(hmac_sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003149 }
3150 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003151 .alg = "jitterentropy_rng",
3152 .fips_allowed = 1,
3153 .test = alg_test_null,
3154 }, {
Stephan Mueller35351982015-09-21 20:59:56 +02003155 .alg = "kw(aes)",
3156 .test = alg_test_skcipher,
3157 .fips_allowed = 1,
3158 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003159 .cipher = __VECS(aes_kw_tv_template)
Stephan Mueller35351982015-09-21 20:59:56 +02003160 }
3161 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003162 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003163 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003164 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003165 .cipher = __VECS(aes_lrw_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003166 }
3167 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003168 .alg = "lrw(camellia)",
3169 .test = alg_test_skcipher,
3170 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003171 .cipher = __VECS(camellia_lrw_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003172 }
3173 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003174 .alg = "lrw(cast6)",
3175 .test = alg_test_skcipher,
3176 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003177 .cipher = __VECS(cast6_lrw_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003178 }
3179 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003180 .alg = "lrw(serpent)",
3181 .test = alg_test_skcipher,
3182 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003183 .cipher = __VECS(serpent_lrw_tv_template)
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003184 }
3185 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003186 .alg = "lrw(twofish)",
3187 .test = alg_test_skcipher,
3188 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003189 .cipher = __VECS(tf_lrw_tv_template)
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003190 }
3191 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003192 .alg = "lz4",
3193 .test = alg_test_comp,
3194 .fips_allowed = 1,
3195 .suite = {
3196 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003197 .comp = __VECS(lz4_comp_tv_template),
3198 .decomp = __VECS(lz4_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003199 }
3200 }
3201 }, {
3202 .alg = "lz4hc",
3203 .test = alg_test_comp,
3204 .fips_allowed = 1,
3205 .suite = {
3206 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003207 .comp = __VECS(lz4hc_comp_tv_template),
3208 .decomp = __VECS(lz4hc_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003209 }
3210 }
3211 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003212 .alg = "lzo",
3213 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003214 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003215 .suite = {
3216 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003217 .comp = __VECS(lzo_comp_tv_template),
3218 .decomp = __VECS(lzo_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003219 }
3220 }
3221 }, {
3222 .alg = "md4",
3223 .test = alg_test_hash,
3224 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003225 .hash = __VECS(md4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003226 }
3227 }, {
3228 .alg = "md5",
3229 .test = alg_test_hash,
3230 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003231 .hash = __VECS(md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003232 }
3233 }, {
3234 .alg = "michael_mic",
3235 .test = alg_test_hash,
3236 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003237 .hash = __VECS(michael_mic_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003238 }
3239 }, {
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003240 .alg = "morus1280",
3241 .test = alg_test_aead,
3242 .suite = {
3243 .aead = {
3244 .enc = __VECS(morus1280_enc_tv_template),
3245 .dec = __VECS(morus1280_dec_tv_template),
3246 }
3247 }
3248 }, {
3249 .alg = "morus640",
3250 .test = alg_test_aead,
3251 .suite = {
3252 .aead = {
3253 .enc = __VECS(morus640_enc_tv_template),
3254 .dec = __VECS(morus640_dec_tv_template),
3255 }
3256 }
3257 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003258 .alg = "ofb(aes)",
3259 .test = alg_test_skcipher,
3260 .fips_allowed = 1,
3261 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003262 .cipher = __VECS(aes_ofb_tv_template)
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003263 }
3264 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003265 /* Same as ofb(aes) except the key is stored in
3266 * hardware secure memory which we reference by index
3267 */
3268 .alg = "ofb(paes)",
3269 .test = alg_test_null,
3270 .fips_allowed = 1,
3271 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003272 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003273 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003274 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003275 .cipher = __VECS(fcrypt_pcbc_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003276 }
3277 }, {
Stephan Mueller12071072017-06-12 23:27:51 +02003278 .alg = "pkcs1pad(rsa,sha224)",
3279 .test = alg_test_null,
3280 .fips_allowed = 1,
3281 }, {
3282 .alg = "pkcs1pad(rsa,sha256)",
3283 .test = alg_test_akcipher,
3284 .fips_allowed = 1,
3285 .suite = {
3286 .akcipher = __VECS(pkcs1pad_rsa_tv_template)
3287 }
3288 }, {
3289 .alg = "pkcs1pad(rsa,sha384)",
3290 .test = alg_test_null,
3291 .fips_allowed = 1,
3292 }, {
3293 .alg = "pkcs1pad(rsa,sha512)",
3294 .test = alg_test_null,
3295 .fips_allowed = 1,
3296 }, {
Martin Willieee9dc62015-06-01 13:43:59 +02003297 .alg = "poly1305",
3298 .test = alg_test_hash,
3299 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003300 .hash = __VECS(poly1305_tv_template)
Martin Willieee9dc62015-06-01 13:43:59 +02003301 }
3302 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003303 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003304 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003305 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003306 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003307 .cipher = __VECS(aes_ctr_rfc3686_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003308 }
3309 }, {
Herbert Xu3f31a742015-07-09 07:17:34 +08003310 .alg = "rfc4106(gcm(aes))",
Adrian Hoban69435b92010-11-04 15:02:04 -04003311 .test = alg_test_aead,
Jarod Wilsondb71f29a2015-01-23 12:42:15 -05003312 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003313 .suite = {
3314 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003315 .enc = __VECS(aes_gcm_rfc4106_enc_tv_template),
3316 .dec = __VECS(aes_gcm_rfc4106_dec_tv_template)
Adrian Hoban69435b92010-11-04 15:02:04 -04003317 }
3318 }
3319 }, {
Herbert Xu544c4362015-07-14 16:53:22 +08003320 .alg = "rfc4309(ccm(aes))",
Jarod Wilson5d667322009-05-04 19:23:40 +08003321 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003322 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003323 .suite = {
3324 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003325 .enc = __VECS(aes_ccm_rfc4309_enc_tv_template),
3326 .dec = __VECS(aes_ccm_rfc4309_dec_tv_template)
Jarod Wilson5d667322009-05-04 19:23:40 +08003327 }
3328 }
3329 }, {
Herbert Xubb687452015-06-16 13:54:24 +08003330 .alg = "rfc4543(gcm(aes))",
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003331 .test = alg_test_aead,
3332 .suite = {
3333 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003334 .enc = __VECS(aes_gcm_rfc4543_enc_tv_template),
3335 .dec = __VECS(aes_gcm_rfc4543_dec_tv_template),
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003336 }
3337 }
3338 }, {
Martin Williaf2b76b2015-06-01 13:44:01 +02003339 .alg = "rfc7539(chacha20,poly1305)",
3340 .test = alg_test_aead,
3341 .suite = {
3342 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003343 .enc = __VECS(rfc7539_enc_tv_template),
3344 .dec = __VECS(rfc7539_dec_tv_template),
Martin Williaf2b76b2015-06-01 13:44:01 +02003345 }
3346 }
3347 }, {
Martin Willi59007582015-06-01 13:44:03 +02003348 .alg = "rfc7539esp(chacha20,poly1305)",
3349 .test = alg_test_aead,
3350 .suite = {
3351 .aead = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003352 .enc = __VECS(rfc7539esp_enc_tv_template),
3353 .dec = __VECS(rfc7539esp_dec_tv_template),
Martin Willi59007582015-06-01 13:44:03 +02003354 }
3355 }
3356 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003357 .alg = "rmd128",
3358 .test = alg_test_hash,
3359 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003360 .hash = __VECS(rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003361 }
3362 }, {
3363 .alg = "rmd160",
3364 .test = alg_test_hash,
3365 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003366 .hash = __VECS(rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003367 }
3368 }, {
3369 .alg = "rmd256",
3370 .test = alg_test_hash,
3371 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003372 .hash = __VECS(rmd256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003373 }
3374 }, {
3375 .alg = "rmd320",
3376 .test = alg_test_hash,
3377 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003378 .hash = __VECS(rmd320_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003379 }
3380 }, {
Tadeusz Struk946cc462015-06-16 10:31:06 -07003381 .alg = "rsa",
3382 .test = alg_test_akcipher,
3383 .fips_allowed = 1,
3384 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003385 .akcipher = __VECS(rsa_tv_template)
Tadeusz Struk946cc462015-06-16 10:31:06 -07003386 }
3387 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003388 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003389 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003390 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003391 .cipher = __VECS(salsa20_stream_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003392 }
3393 }, {
3394 .alg = "sha1",
3395 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003396 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003397 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003398 .hash = __VECS(sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003399 }
3400 }, {
3401 .alg = "sha224",
3402 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003403 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003404 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003405 .hash = __VECS(sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003406 }
3407 }, {
3408 .alg = "sha256",
3409 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003410 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003411 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003412 .hash = __VECS(sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003413 }
3414 }, {
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303415 .alg = "sha3-224",
3416 .test = alg_test_hash,
3417 .fips_allowed = 1,
3418 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003419 .hash = __VECS(sha3_224_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303420 }
3421 }, {
3422 .alg = "sha3-256",
3423 .test = alg_test_hash,
3424 .fips_allowed = 1,
3425 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003426 .hash = __VECS(sha3_256_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303427 }
3428 }, {
3429 .alg = "sha3-384",
3430 .test = alg_test_hash,
3431 .fips_allowed = 1,
3432 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003433 .hash = __VECS(sha3_384_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303434 }
3435 }, {
3436 .alg = "sha3-512",
3437 .test = alg_test_hash,
3438 .fips_allowed = 1,
3439 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003440 .hash = __VECS(sha3_512_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303441 }
3442 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003443 .alg = "sha384",
3444 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003445 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003446 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003447 .hash = __VECS(sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003448 }
3449 }, {
3450 .alg = "sha512",
3451 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003452 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003453 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003454 .hash = __VECS(sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003455 }
3456 }, {
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03003457 .alg = "sm3",
3458 .test = alg_test_hash,
3459 .suite = {
3460 .hash = __VECS(sm3_tv_template)
3461 }
3462 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003463 .alg = "tgr128",
3464 .test = alg_test_hash,
3465 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003466 .hash = __VECS(tgr128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003467 }
3468 }, {
3469 .alg = "tgr160",
3470 .test = alg_test_hash,
3471 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003472 .hash = __VECS(tgr160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003473 }
3474 }, {
3475 .alg = "tgr192",
3476 .test = alg_test_hash,
3477 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003478 .hash = __VECS(tgr192_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003479 }
3480 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003481 .alg = "vmac(aes)",
3482 .test = alg_test_hash,
3483 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003484 .hash = __VECS(aes_vmac128_tv_template)
Shane Wangf1939f72009-09-02 20:05:22 +10003485 }
3486 }, {
Eric Biggersed331ad2018-06-18 10:22:39 -07003487 .alg = "vmac64(aes)",
3488 .test = alg_test_hash,
3489 .suite = {
3490 .hash = __VECS(vmac64_aes_tv_template)
3491 }
3492 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003493 .alg = "wp256",
3494 .test = alg_test_hash,
3495 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003496 .hash = __VECS(wp256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003497 }
3498 }, {
3499 .alg = "wp384",
3500 .test = alg_test_hash,
3501 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003502 .hash = __VECS(wp384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003503 }
3504 }, {
3505 .alg = "wp512",
3506 .test = alg_test_hash,
3507 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003508 .hash = __VECS(wp512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003509 }
3510 }, {
3511 .alg = "xcbc(aes)",
3512 .test = alg_test_hash,
3513 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003514 .hash = __VECS(aes_xcbc128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003515 }
3516 }, {
3517 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003518 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003519 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003520 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003521 .cipher = __VECS(aes_xts_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003522 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003523 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003524 .alg = "xts(camellia)",
3525 .test = alg_test_skcipher,
3526 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003527 .cipher = __VECS(camellia_xts_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003528 }
3529 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003530 .alg = "xts(cast6)",
3531 .test = alg_test_skcipher,
3532 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003533 .cipher = __VECS(cast6_xts_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003534 }
3535 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003536 /* Same as xts(aes) except the key is stored in
3537 * hardware secure memory which we reference by index
3538 */
3539 .alg = "xts(paes)",
3540 .test = alg_test_null,
3541 .fips_allowed = 1,
3542 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003543 .alg = "xts(serpent)",
3544 .test = alg_test_skcipher,
3545 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003546 .cipher = __VECS(serpent_xts_tv_template)
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003547 }
3548 }, {
Eric Biggersc3bb5212018-02-14 10:42:22 -08003549 .alg = "xts(speck128)",
3550 .test = alg_test_skcipher,
3551 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003552 .cipher = __VECS(speck128_xts_tv_template)
Eric Biggersc3bb5212018-02-14 10:42:22 -08003553 }
3554 }, {
Eric Biggers41b33162018-02-14 10:42:23 -08003555 .alg = "xts(speck64)",
3556 .test = alg_test_skcipher,
3557 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003558 .cipher = __VECS(speck64_xts_tv_template)
Eric Biggers41b33162018-02-14 10:42:23 -08003559 }
3560 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003561 .alg = "xts(twofish)",
3562 .test = alg_test_skcipher,
3563 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003564 .cipher = __VECS(tf_xts_tv_template)
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003565 }
Giovanni Cabiddua368f432017-04-21 21:54:30 +01003566 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003567 .alg = "xts4096(paes)",
3568 .test = alg_test_null,
3569 .fips_allowed = 1,
3570 }, {
3571 .alg = "xts512(paes)",
3572 .test = alg_test_null,
3573 .fips_allowed = 1,
3574 }, {
Giovanni Cabiddua368f432017-04-21 21:54:30 +01003575 .alg = "zlib-deflate",
3576 .test = alg_test_comp,
3577 .fips_allowed = 1,
3578 .suite = {
3579 .comp = {
3580 .comp = __VECS(zlib_deflate_comp_tv_template),
3581 .decomp = __VECS(zlib_deflate_decomp_tv_template)
3582 }
3583 }
Nick Terrelld28fc3d2018-03-30 12:14:53 -07003584 }, {
3585 .alg = "zstd",
3586 .test = alg_test_comp,
3587 .fips_allowed = 1,
3588 .suite = {
3589 .comp = {
3590 .comp = __VECS(zstd_comp_tv_template),
3591 .decomp = __VECS(zstd_decomp_tv_template)
3592 }
3593 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003594 }
3595};
3596
Jussi Kivilinna57147582013-06-13 17:37:40 +03003597static bool alg_test_descs_checked;
3598
3599static void alg_test_descs_check_order(void)
3600{
3601 int i;
3602
3603 /* only check once */
3604 if (alg_test_descs_checked)
3605 return;
3606
3607 alg_test_descs_checked = true;
3608
3609 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3610 int diff = strcmp(alg_test_descs[i - 1].alg,
3611 alg_test_descs[i].alg);
3612
3613 if (WARN_ON(diff > 0)) {
3614 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3615 alg_test_descs[i - 1].alg,
3616 alg_test_descs[i].alg);
3617 }
3618
3619 if (WARN_ON(diff == 0)) {
3620 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3621 alg_test_descs[i].alg);
3622 }
3623 }
3624}
3625
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003626static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003627{
3628 int start = 0;
3629 int end = ARRAY_SIZE(alg_test_descs);
3630
3631 while (start < end) {
3632 int i = (start + end) / 2;
3633 int diff = strcmp(alg_test_descs[i].alg, alg);
3634
3635 if (diff > 0) {
3636 end = i;
3637 continue;
3638 }
3639
3640 if (diff < 0) {
3641 start = i + 1;
3642 continue;
3643 }
3644
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003645 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003646 }
3647
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003648 return -1;
3649}
3650
3651int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3652{
3653 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003654 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003655 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003656
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +01003657 if (!fips_enabled && notests) {
3658 printk_once(KERN_INFO "alg: self-tests disabled\n");
3659 return 0;
3660 }
3661
Jussi Kivilinna57147582013-06-13 17:37:40 +03003662 alg_test_descs_check_order();
3663
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003664 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3665 char nalg[CRYPTO_MAX_ALG_NAME];
3666
3667 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3668 sizeof(nalg))
3669 return -ENAMETOOLONG;
3670
3671 i = alg_find_test(nalg);
3672 if (i < 0)
3673 goto notest;
3674
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003675 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3676 goto non_fips_alg;
3677
Jarod Wilson941fb322009-05-04 19:49:23 +08003678 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3679 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003680 }
3681
3682 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003683 j = alg_find_test(driver);
3684 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003685 goto notest;
3686
Herbert Xua68f6612009-07-02 16:32:12 +08003687 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3688 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003689 goto non_fips_alg;
3690
Herbert Xua68f6612009-07-02 16:32:12 +08003691 rc = 0;
3692 if (i >= 0)
3693 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3694 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003695 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003696 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3697 type, mask);
3698
Jarod Wilson941fb322009-05-04 19:49:23 +08003699test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003700 if (fips_enabled && rc)
3701 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3702
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003703 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09003704 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003705
Neil Hormand12d6b62008-10-12 20:36:51 +08003706 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003707
3708notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003709 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3710 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003711non_fips_alg:
3712 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003713}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003714
Herbert Xu326a6342010-08-06 09:40:28 +08003715#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003716
Herbert Xuda7f0332008-07-31 17:08:25 +08003717EXPORT_SYMBOL_GPL(alg_test);