blob: 21b27996508a549f8e15bff67eaf3673e7e5b4ae [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>
Eric Biggers3f47a032019-01-31 23:51:43 -08008 * Copyright (c) 2019 Google LLC
Herbert Xuda7f0332008-07-31 17:08:25 +08009 *
Adrian Hoban69435b92010-11-04 15:02:04 -040010 * Updated RFC4106 AES-GCM testing.
11 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
12 * Adrian Hoban <adrian.hoban@intel.com>
13 * Gabriele Paoloni <gabriele.paoloni@intel.com>
14 * Tadeusz Struk (tadeusz.struk@intel.com)
15 * Copyright (c) 2010, Intel Corporation.
16 *
Herbert Xuda7f0332008-07-31 17:08:25 +080017 * This program is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License as published by the Free
19 * Software Foundation; either version 2 of the License, or (at your option)
20 * any later version.
21 *
22 */
23
Herbert Xu1ce33112015-04-22 15:06:31 +080024#include <crypto/aead.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080025#include <crypto/hash.h>
Herbert Xu12773d92015-08-20 15:21:46 +080026#include <crypto/skcipher.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080027#include <linux/err.h>
Herbert Xu1c41b882015-04-22 13:25:58 +080028#include <linux/fips.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080029#include <linux/module.h>
Eric Biggers3f47a032019-01-31 23:51:43 -080030#include <linux/once.h>
Eric Biggers25f9ddd2019-01-31 23:51:45 -080031#include <linux/random.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080032#include <linux/scatterlist.h>
33#include <linux/slab.h>
34#include <linux/string.h>
Jarod Wilson7647d6c2009-05-04 19:44:50 +080035#include <crypto/rng.h>
Stephan Mueller64d1cdf2014-05-31 17:25:36 +020036#include <crypto/drbg.h>
Tadeusz Struk946cc462015-06-16 10:31:06 -070037#include <crypto/akcipher.h>
Salvatore Benedetto802c7f12016-06-22 17:49:14 +010038#include <crypto/kpp.h>
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +010039#include <crypto/acompress.h>
Eric Biggersb55e1a32019-03-12 22:12:47 -070040#include <crypto/internal/simd.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080041
42#include "internal.h"
Alexander Shishkin0b767f92010-06-03 20:53:43 +100043
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +010044static bool notests;
45module_param(notests, bool, 0644);
46MODULE_PARM_DESC(notests, "disable crypto self-tests");
47
Eric Biggerseda69b02019-03-31 13:09:14 -070048static bool panic_on_fail;
49module_param(panic_on_fail, bool, 0444);
50
Eric Biggers5b2706a2019-01-31 23:51:44 -080051#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
52static bool noextratests;
53module_param(noextratests, bool, 0644);
54MODULE_PARM_DESC(noextratests, "disable expensive crypto self-tests");
55
56static unsigned int fuzz_iterations = 100;
57module_param(fuzz_iterations, uint, 0644);
58MODULE_PARM_DESC(fuzz_iterations, "number of fuzz test iterations");
Eric Biggersb55e1a32019-03-12 22:12:47 -070059
60DEFINE_PER_CPU(bool, crypto_simd_disabled_for_test);
61EXPORT_PER_CPU_SYMBOL_GPL(crypto_simd_disabled_for_test);
Eric Biggers5b2706a2019-01-31 23:51:44 -080062#endif
63
Herbert Xu326a6342010-08-06 09:40:28 +080064#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
Alexander Shishkin0b767f92010-06-03 20:53:43 +100065
66/* a perfect nop */
67int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
68{
69 return 0;
70}
71
72#else
73
Herbert Xuda7f0332008-07-31 17:08:25 +080074#include "testmgr.h"
75
76/*
77 * Need slab memory for testing (size in number of pages).
78 */
79#define XBUFSIZE 8
80
81/*
Herbert Xuda7f0332008-07-31 17:08:25 +080082* Used by test_cipher()
83*/
84#define ENCRYPT 1
85#define DECRYPT 0
86
Herbert Xuda7f0332008-07-31 17:08:25 +080087struct aead_test_suite {
Eric Biggersa0d608ee2019-01-13 15:32:28 -080088 const struct aead_testvec *vecs;
89 unsigned int count;
Herbert Xuda7f0332008-07-31 17:08:25 +080090};
91
92struct cipher_test_suite {
Eric Biggers92a4c9f2018-05-20 22:50:29 -070093 const struct cipher_testvec *vecs;
94 unsigned int count;
Herbert Xuda7f0332008-07-31 17:08:25 +080095};
96
97struct comp_test_suite {
98 struct {
Eric Biggersb13b1e02017-02-24 15:46:59 -080099 const struct comp_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +0800100 unsigned int count;
101 } comp, decomp;
102};
103
104struct hash_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800105 const struct hash_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +0800106 unsigned int count;
107};
108
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800109struct cprng_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800110 const struct cprng_testvec *vecs;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800111 unsigned int count;
112};
113
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200114struct drbg_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800115 const struct drbg_testvec *vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200116 unsigned int count;
117};
118
Tadeusz Struk946cc462015-06-16 10:31:06 -0700119struct akcipher_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800120 const struct akcipher_testvec *vecs;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700121 unsigned int count;
122};
123
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100124struct kpp_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800125 const struct kpp_testvec *vecs;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100126 unsigned int count;
127};
128
Herbert Xuda7f0332008-07-31 17:08:25 +0800129struct alg_test_desc {
130 const char *alg;
131 int (*test)(const struct alg_test_desc *desc, const char *driver,
132 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000133 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800134
135 union {
136 struct aead_test_suite aead;
137 struct cipher_test_suite cipher;
138 struct comp_test_suite comp;
139 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800140 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200141 struct drbg_test_suite drbg;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700142 struct akcipher_test_suite akcipher;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100143 struct kpp_test_suite kpp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800144 } suite;
145};
146
Herbert Xuda7f0332008-07-31 17:08:25 +0800147static void hexdump(unsigned char *buf, unsigned int len)
148{
149 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
150 16, 1,
151 buf, len, false);
152}
153
Eric Biggers3f47a032019-01-31 23:51:43 -0800154static int __testmgr_alloc_buf(char *buf[XBUFSIZE], int order)
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800155{
156 int i;
157
158 for (i = 0; i < XBUFSIZE; i++) {
Eric Biggers3f47a032019-01-31 23:51:43 -0800159 buf[i] = (char *)__get_free_pages(GFP_KERNEL, order);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800160 if (!buf[i])
161 goto err_free_buf;
162 }
163
164 return 0;
165
166err_free_buf:
167 while (i-- > 0)
Eric Biggers3f47a032019-01-31 23:51:43 -0800168 free_pages((unsigned long)buf[i], order);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800169
170 return -ENOMEM;
171}
172
Eric Biggers3f47a032019-01-31 23:51:43 -0800173static int testmgr_alloc_buf(char *buf[XBUFSIZE])
174{
175 return __testmgr_alloc_buf(buf, 0);
176}
177
178static void __testmgr_free_buf(char *buf[XBUFSIZE], int order)
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800179{
180 int i;
181
182 for (i = 0; i < XBUFSIZE; i++)
Eric Biggers3f47a032019-01-31 23:51:43 -0800183 free_pages((unsigned long)buf[i], order);
184}
185
186static void testmgr_free_buf(char *buf[XBUFSIZE])
187{
188 __testmgr_free_buf(buf, 0);
189}
190
191#define TESTMGR_POISON_BYTE 0xfe
192#define TESTMGR_POISON_LEN 16
193
194static inline void testmgr_poison(void *addr, size_t len)
195{
196 memset(addr, TESTMGR_POISON_BYTE, len);
197}
198
199/* Is the memory region still fully poisoned? */
200static inline bool testmgr_is_poison(const void *addr, size_t len)
201{
202 return memchr_inv(addr, TESTMGR_POISON_BYTE, len) == NULL;
203}
204
205/* flush type for hash algorithms */
206enum flush_type {
207 /* merge with update of previous buffer(s) */
208 FLUSH_TYPE_NONE = 0,
209
210 /* update with previous buffer(s) before doing this one */
211 FLUSH_TYPE_FLUSH,
212
213 /* likewise, but also export and re-import the intermediate state */
214 FLUSH_TYPE_REIMPORT,
215};
216
217/* finalization function for hash algorithms */
218enum finalization_type {
219 FINALIZATION_TYPE_FINAL, /* use final() */
220 FINALIZATION_TYPE_FINUP, /* use finup() */
221 FINALIZATION_TYPE_DIGEST, /* use digest() */
222};
223
224#define TEST_SG_TOTAL 10000
225
226/**
227 * struct test_sg_division - description of a scatterlist entry
228 *
229 * This struct describes one entry of a scatterlist being constructed to check a
230 * crypto test vector.
231 *
232 * @proportion_of_total: length of this chunk relative to the total length,
233 * given as a proportion out of TEST_SG_TOTAL so that it
234 * scales to fit any test vector
235 * @offset: byte offset into a 2-page buffer at which this chunk will start
236 * @offset_relative_to_alignmask: if true, add the algorithm's alignmask to the
237 * @offset
238 * @flush_type: for hashes, whether an update() should be done now vs.
239 * continuing to accumulate data
Eric Biggers65707372019-03-12 22:12:52 -0700240 * @nosimd: if doing the pending update(), do it with SIMD disabled?
Eric Biggers3f47a032019-01-31 23:51:43 -0800241 */
242struct test_sg_division {
243 unsigned int proportion_of_total;
244 unsigned int offset;
245 bool offset_relative_to_alignmask;
246 enum flush_type flush_type;
Eric Biggers65707372019-03-12 22:12:52 -0700247 bool nosimd;
Eric Biggers3f47a032019-01-31 23:51:43 -0800248};
249
250/**
251 * struct testvec_config - configuration for testing a crypto test vector
252 *
253 * This struct describes the data layout and other parameters with which each
254 * crypto test vector can be tested.
255 *
256 * @name: name of this config, logged for debugging purposes if a test fails
257 * @inplace: operate on the data in-place, if applicable for the algorithm type?
258 * @req_flags: extra request_flags, e.g. CRYPTO_TFM_REQ_MAY_SLEEP
259 * @src_divs: description of how to arrange the source scatterlist
260 * @dst_divs: description of how to arrange the dst scatterlist, if applicable
261 * for the algorithm type. Defaults to @src_divs if unset.
262 * @iv_offset: misalignment of the IV in the range [0..MAX_ALGAPI_ALIGNMASK+1],
263 * where 0 is aligned to a 2*(MAX_ALGAPI_ALIGNMASK+1) byte boundary
264 * @iv_offset_relative_to_alignmask: if true, add the algorithm's alignmask to
265 * the @iv_offset
266 * @finalization_type: what finalization function to use for hashes
Eric Biggers65707372019-03-12 22:12:52 -0700267 * @nosimd: execute with SIMD disabled? Requires !CRYPTO_TFM_REQ_MAY_SLEEP.
Eric Biggers3f47a032019-01-31 23:51:43 -0800268 */
269struct testvec_config {
270 const char *name;
271 bool inplace;
272 u32 req_flags;
273 struct test_sg_division src_divs[XBUFSIZE];
274 struct test_sg_division dst_divs[XBUFSIZE];
275 unsigned int iv_offset;
276 bool iv_offset_relative_to_alignmask;
277 enum finalization_type finalization_type;
Eric Biggers65707372019-03-12 22:12:52 -0700278 bool nosimd;
Eric Biggers3f47a032019-01-31 23:51:43 -0800279};
280
281#define TESTVEC_CONFIG_NAMELEN 192
282
Eric Biggers4e7babba2019-01-31 23:51:46 -0800283/*
284 * The following are the lists of testvec_configs to test for each algorithm
285 * type when the basic crypto self-tests are enabled, i.e. when
286 * CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is unset. They aim to provide good test
287 * coverage, while keeping the test time much shorter than the full fuzz tests
288 * so that the basic tests can be enabled in a wider range of circumstances.
289 */
290
291/* Configs for skciphers and aeads */
292static const struct testvec_config default_cipher_testvec_configs[] = {
293 {
294 .name = "in-place",
295 .inplace = true,
296 .src_divs = { { .proportion_of_total = 10000 } },
297 }, {
298 .name = "out-of-place",
299 .src_divs = { { .proportion_of_total = 10000 } },
300 }, {
301 .name = "unaligned buffer, offset=1",
302 .src_divs = { { .proportion_of_total = 10000, .offset = 1 } },
303 .iv_offset = 1,
304 }, {
305 .name = "buffer aligned only to alignmask",
306 .src_divs = {
307 {
308 .proportion_of_total = 10000,
309 .offset = 1,
310 .offset_relative_to_alignmask = true,
311 },
312 },
313 .iv_offset = 1,
314 .iv_offset_relative_to_alignmask = true,
315 }, {
316 .name = "two even aligned splits",
317 .src_divs = {
318 { .proportion_of_total = 5000 },
319 { .proportion_of_total = 5000 },
320 },
321 }, {
322 .name = "uneven misaligned splits, may sleep",
323 .req_flags = CRYPTO_TFM_REQ_MAY_SLEEP,
324 .src_divs = {
325 { .proportion_of_total = 1900, .offset = 33 },
326 { .proportion_of_total = 3300, .offset = 7 },
327 { .proportion_of_total = 4800, .offset = 18 },
328 },
329 .iv_offset = 3,
330 }, {
331 .name = "misaligned splits crossing pages, inplace",
332 .inplace = true,
333 .src_divs = {
334 {
335 .proportion_of_total = 7500,
336 .offset = PAGE_SIZE - 32
337 }, {
338 .proportion_of_total = 2500,
339 .offset = PAGE_SIZE - 7
340 },
341 },
342 }
343};
344
Eric Biggers4cc2dcf2019-01-31 23:51:48 -0800345static const struct testvec_config default_hash_testvec_configs[] = {
346 {
347 .name = "init+update+final aligned buffer",
348 .src_divs = { { .proportion_of_total = 10000 } },
349 .finalization_type = FINALIZATION_TYPE_FINAL,
350 }, {
351 .name = "init+finup aligned buffer",
352 .src_divs = { { .proportion_of_total = 10000 } },
353 .finalization_type = FINALIZATION_TYPE_FINUP,
354 }, {
355 .name = "digest aligned buffer",
356 .src_divs = { { .proportion_of_total = 10000 } },
357 .finalization_type = FINALIZATION_TYPE_DIGEST,
358 }, {
359 .name = "init+update+final misaligned buffer",
360 .src_divs = { { .proportion_of_total = 10000, .offset = 1 } },
361 .finalization_type = FINALIZATION_TYPE_FINAL,
362 }, {
363 .name = "digest buffer aligned only to alignmask",
364 .src_divs = {
365 {
366 .proportion_of_total = 10000,
367 .offset = 1,
368 .offset_relative_to_alignmask = true,
369 },
370 },
371 .finalization_type = FINALIZATION_TYPE_DIGEST,
372 }, {
373 .name = "init+update+update+final two even splits",
374 .src_divs = {
375 { .proportion_of_total = 5000 },
376 {
377 .proportion_of_total = 5000,
378 .flush_type = FLUSH_TYPE_FLUSH,
379 },
380 },
381 .finalization_type = FINALIZATION_TYPE_FINAL,
382 }, {
383 .name = "digest uneven misaligned splits, may sleep",
384 .req_flags = CRYPTO_TFM_REQ_MAY_SLEEP,
385 .src_divs = {
386 { .proportion_of_total = 1900, .offset = 33 },
387 { .proportion_of_total = 3300, .offset = 7 },
388 { .proportion_of_total = 4800, .offset = 18 },
389 },
390 .finalization_type = FINALIZATION_TYPE_DIGEST,
391 }, {
392 .name = "digest misaligned splits crossing pages",
393 .src_divs = {
394 {
395 .proportion_of_total = 7500,
396 .offset = PAGE_SIZE - 32,
397 }, {
398 .proportion_of_total = 2500,
399 .offset = PAGE_SIZE - 7,
400 },
401 },
402 .finalization_type = FINALIZATION_TYPE_DIGEST,
403 }, {
404 .name = "import/export",
405 .src_divs = {
406 {
407 .proportion_of_total = 6500,
408 .flush_type = FLUSH_TYPE_REIMPORT,
409 }, {
410 .proportion_of_total = 3500,
411 .flush_type = FLUSH_TYPE_REIMPORT,
412 },
413 },
414 .finalization_type = FINALIZATION_TYPE_FINAL,
415 }
416};
417
Eric Biggers3f47a032019-01-31 23:51:43 -0800418static unsigned int count_test_sg_divisions(const struct test_sg_division *divs)
419{
420 unsigned int remaining = TEST_SG_TOTAL;
421 unsigned int ndivs = 0;
422
423 do {
424 remaining -= divs[ndivs++].proportion_of_total;
425 } while (remaining);
426
427 return ndivs;
428}
429
Eric Biggers65707372019-03-12 22:12:52 -0700430#define SGDIVS_HAVE_FLUSHES BIT(0)
431#define SGDIVS_HAVE_NOSIMD BIT(1)
432
Eric Biggers3f47a032019-01-31 23:51:43 -0800433static bool valid_sg_divisions(const struct test_sg_division *divs,
Eric Biggers65707372019-03-12 22:12:52 -0700434 unsigned int count, int *flags_ret)
Eric Biggers3f47a032019-01-31 23:51:43 -0800435{
436 unsigned int total = 0;
437 unsigned int i;
438
439 for (i = 0; i < count && total != TEST_SG_TOTAL; i++) {
440 if (divs[i].proportion_of_total <= 0 ||
441 divs[i].proportion_of_total > TEST_SG_TOTAL - total)
442 return false;
443 total += divs[i].proportion_of_total;
444 if (divs[i].flush_type != FLUSH_TYPE_NONE)
Eric Biggers65707372019-03-12 22:12:52 -0700445 *flags_ret |= SGDIVS_HAVE_FLUSHES;
446 if (divs[i].nosimd)
447 *flags_ret |= SGDIVS_HAVE_NOSIMD;
Eric Biggers3f47a032019-01-31 23:51:43 -0800448 }
449 return total == TEST_SG_TOTAL &&
450 memchr_inv(&divs[i], 0, (count - i) * sizeof(divs[0])) == NULL;
451}
452
453/*
454 * Check whether the given testvec_config is valid. This isn't strictly needed
455 * since every testvec_config should be valid, but check anyway so that people
456 * don't unknowingly add broken configs that don't do what they wanted.
457 */
458static bool valid_testvec_config(const struct testvec_config *cfg)
459{
Eric Biggers65707372019-03-12 22:12:52 -0700460 int flags = 0;
Eric Biggers3f47a032019-01-31 23:51:43 -0800461
462 if (cfg->name == NULL)
463 return false;
464
465 if (!valid_sg_divisions(cfg->src_divs, ARRAY_SIZE(cfg->src_divs),
Eric Biggers65707372019-03-12 22:12:52 -0700466 &flags))
Eric Biggers3f47a032019-01-31 23:51:43 -0800467 return false;
468
469 if (cfg->dst_divs[0].proportion_of_total) {
470 if (!valid_sg_divisions(cfg->dst_divs,
Eric Biggers65707372019-03-12 22:12:52 -0700471 ARRAY_SIZE(cfg->dst_divs), &flags))
Eric Biggers3f47a032019-01-31 23:51:43 -0800472 return false;
473 } else {
474 if (memchr_inv(cfg->dst_divs, 0, sizeof(cfg->dst_divs)))
475 return false;
476 /* defaults to dst_divs=src_divs */
477 }
478
479 if (cfg->iv_offset +
480 (cfg->iv_offset_relative_to_alignmask ? MAX_ALGAPI_ALIGNMASK : 0) >
481 MAX_ALGAPI_ALIGNMASK + 1)
482 return false;
483
Eric Biggers65707372019-03-12 22:12:52 -0700484 if ((flags & (SGDIVS_HAVE_FLUSHES | SGDIVS_HAVE_NOSIMD)) &&
485 cfg->finalization_type == FINALIZATION_TYPE_DIGEST)
486 return false;
487
488 if ((cfg->nosimd || (flags & SGDIVS_HAVE_NOSIMD)) &&
489 (cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP))
Eric Biggers3f47a032019-01-31 23:51:43 -0800490 return false;
491
492 return true;
493}
494
495struct test_sglist {
496 char *bufs[XBUFSIZE];
497 struct scatterlist sgl[XBUFSIZE];
498 struct scatterlist sgl_saved[XBUFSIZE];
499 struct scatterlist *sgl_ptr;
500 unsigned int nents;
501};
502
503static int init_test_sglist(struct test_sglist *tsgl)
504{
505 return __testmgr_alloc_buf(tsgl->bufs, 1 /* two pages per buffer */);
506}
507
508static void destroy_test_sglist(struct test_sglist *tsgl)
509{
510 return __testmgr_free_buf(tsgl->bufs, 1 /* two pages per buffer */);
511}
512
513/**
514 * build_test_sglist() - build a scatterlist for a crypto test
515 *
516 * @tsgl: the scatterlist to build. @tsgl->bufs[] contains an array of 2-page
517 * buffers which the scatterlist @tsgl->sgl[] will be made to point into.
518 * @divs: the layout specification on which the scatterlist will be based
519 * @alignmask: the algorithm's alignmask
520 * @total_len: the total length of the scatterlist to build in bytes
521 * @data: if non-NULL, the buffers will be filled with this data until it ends.
522 * Otherwise the buffers will be poisoned. In both cases, some bytes
523 * past the end of each buffer will be poisoned to help detect overruns.
524 * @out_divs: if non-NULL, the test_sg_division to which each scatterlist entry
525 * corresponds will be returned here. This will match @divs except
526 * that divisions resolving to a length of 0 are omitted as they are
527 * not included in the scatterlist.
528 *
529 * Return: 0 or a -errno value
530 */
531static int build_test_sglist(struct test_sglist *tsgl,
532 const struct test_sg_division *divs,
533 const unsigned int alignmask,
534 const unsigned int total_len,
535 struct iov_iter *data,
536 const struct test_sg_division *out_divs[XBUFSIZE])
537{
538 struct {
539 const struct test_sg_division *div;
540 size_t length;
541 } partitions[XBUFSIZE];
542 const unsigned int ndivs = count_test_sg_divisions(divs);
543 unsigned int len_remaining = total_len;
544 unsigned int i;
545
546 BUILD_BUG_ON(ARRAY_SIZE(partitions) != ARRAY_SIZE(tsgl->sgl));
547 if (WARN_ON(ndivs > ARRAY_SIZE(partitions)))
548 return -EINVAL;
549
550 /* Calculate the (div, length) pairs */
551 tsgl->nents = 0;
552 for (i = 0; i < ndivs; i++) {
553 unsigned int len_this_sg =
554 min(len_remaining,
555 (total_len * divs[i].proportion_of_total +
556 TEST_SG_TOTAL / 2) / TEST_SG_TOTAL);
557
558 if (len_this_sg != 0) {
559 partitions[tsgl->nents].div = &divs[i];
560 partitions[tsgl->nents].length = len_this_sg;
561 tsgl->nents++;
562 len_remaining -= len_this_sg;
563 }
564 }
565 if (tsgl->nents == 0) {
566 partitions[tsgl->nents].div = &divs[0];
567 partitions[tsgl->nents].length = 0;
568 tsgl->nents++;
569 }
570 partitions[tsgl->nents - 1].length += len_remaining;
571
572 /* Set up the sgl entries and fill the data or poison */
573 sg_init_table(tsgl->sgl, tsgl->nents);
574 for (i = 0; i < tsgl->nents; i++) {
575 unsigned int offset = partitions[i].div->offset;
576 void *addr;
577
578 if (partitions[i].div->offset_relative_to_alignmask)
579 offset += alignmask;
580
581 while (offset + partitions[i].length + TESTMGR_POISON_LEN >
582 2 * PAGE_SIZE) {
583 if (WARN_ON(offset <= 0))
584 return -EINVAL;
585 offset /= 2;
586 }
587
588 addr = &tsgl->bufs[i][offset];
589 sg_set_buf(&tsgl->sgl[i], addr, partitions[i].length);
590
591 if (out_divs)
592 out_divs[i] = partitions[i].div;
593
594 if (data) {
595 size_t copy_len, copied;
596
597 copy_len = min(partitions[i].length, data->count);
598 copied = copy_from_iter(addr, copy_len, data);
599 if (WARN_ON(copied != copy_len))
600 return -EINVAL;
601 testmgr_poison(addr + copy_len, partitions[i].length +
602 TESTMGR_POISON_LEN - copy_len);
603 } else {
604 testmgr_poison(addr, partitions[i].length +
605 TESTMGR_POISON_LEN);
606 }
607 }
608
609 sg_mark_end(&tsgl->sgl[tsgl->nents - 1]);
610 tsgl->sgl_ptr = tsgl->sgl;
611 memcpy(tsgl->sgl_saved, tsgl->sgl, tsgl->nents * sizeof(tsgl->sgl[0]));
612 return 0;
613}
614
615/*
616 * Verify that a scatterlist crypto operation produced the correct output.
617 *
618 * @tsgl: scatterlist containing the actual output
619 * @expected_output: buffer containing the expected output
620 * @len_to_check: length of @expected_output in bytes
621 * @unchecked_prefix_len: number of ignored bytes in @tsgl prior to real result
622 * @check_poison: verify that the poison bytes after each chunk are intact?
623 *
624 * Return: 0 if correct, -EINVAL if incorrect, -EOVERFLOW if buffer overrun.
625 */
626static int verify_correct_output(const struct test_sglist *tsgl,
627 const char *expected_output,
628 unsigned int len_to_check,
629 unsigned int unchecked_prefix_len,
630 bool check_poison)
631{
632 unsigned int i;
633
634 for (i = 0; i < tsgl->nents; i++) {
635 struct scatterlist *sg = &tsgl->sgl_ptr[i];
636 unsigned int len = sg->length;
637 unsigned int offset = sg->offset;
638 const char *actual_output;
639
640 if (unchecked_prefix_len) {
641 if (unchecked_prefix_len >= len) {
642 unchecked_prefix_len -= len;
643 continue;
644 }
645 offset += unchecked_prefix_len;
646 len -= unchecked_prefix_len;
647 unchecked_prefix_len = 0;
648 }
649 len = min(len, len_to_check);
650 actual_output = page_address(sg_page(sg)) + offset;
651 if (memcmp(expected_output, actual_output, len) != 0)
652 return -EINVAL;
653 if (check_poison &&
654 !testmgr_is_poison(actual_output + len, TESTMGR_POISON_LEN))
655 return -EOVERFLOW;
656 len_to_check -= len;
657 expected_output += len;
658 }
659 if (WARN_ON(len_to_check != 0))
660 return -EINVAL;
661 return 0;
662}
663
664static bool is_test_sglist_corrupted(const struct test_sglist *tsgl)
665{
666 unsigned int i;
667
668 for (i = 0; i < tsgl->nents; i++) {
669 if (tsgl->sgl[i].page_link != tsgl->sgl_saved[i].page_link)
670 return true;
671 if (tsgl->sgl[i].offset != tsgl->sgl_saved[i].offset)
672 return true;
673 if (tsgl->sgl[i].length != tsgl->sgl_saved[i].length)
674 return true;
675 }
676 return false;
677}
678
679struct cipher_test_sglists {
680 struct test_sglist src;
681 struct test_sglist dst;
682};
683
684static struct cipher_test_sglists *alloc_cipher_test_sglists(void)
685{
686 struct cipher_test_sglists *tsgls;
687
688 tsgls = kmalloc(sizeof(*tsgls), GFP_KERNEL);
689 if (!tsgls)
690 return NULL;
691
692 if (init_test_sglist(&tsgls->src) != 0)
693 goto fail_kfree;
694 if (init_test_sglist(&tsgls->dst) != 0)
695 goto fail_destroy_src;
696
697 return tsgls;
698
699fail_destroy_src:
700 destroy_test_sglist(&tsgls->src);
701fail_kfree:
702 kfree(tsgls);
703 return NULL;
704}
705
706static void free_cipher_test_sglists(struct cipher_test_sglists *tsgls)
707{
708 if (tsgls) {
709 destroy_test_sglist(&tsgls->src);
710 destroy_test_sglist(&tsgls->dst);
711 kfree(tsgls);
712 }
713}
714
715/* Build the src and dst scatterlists for an skcipher or AEAD test */
716static int build_cipher_test_sglists(struct cipher_test_sglists *tsgls,
717 const struct testvec_config *cfg,
718 unsigned int alignmask,
719 unsigned int src_total_len,
720 unsigned int dst_total_len,
721 const struct kvec *inputs,
722 unsigned int nr_inputs)
723{
724 struct iov_iter input;
725 int err;
726
727 iov_iter_kvec(&input, WRITE, inputs, nr_inputs, src_total_len);
728 err = build_test_sglist(&tsgls->src, cfg->src_divs, alignmask,
729 cfg->inplace ?
730 max(dst_total_len, src_total_len) :
731 src_total_len,
732 &input, NULL);
733 if (err)
734 return err;
735
736 if (cfg->inplace) {
737 tsgls->dst.sgl_ptr = tsgls->src.sgl;
738 tsgls->dst.nents = tsgls->src.nents;
739 return 0;
740 }
741 return build_test_sglist(&tsgls->dst,
742 cfg->dst_divs[0].proportion_of_total ?
743 cfg->dst_divs : cfg->src_divs,
744 alignmask, dst_total_len, NULL, NULL);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800745}
746
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800747#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
748static char *generate_random_sgl_divisions(struct test_sg_division *divs,
749 size_t max_divs, char *p, char *end,
Eric Biggers65707372019-03-12 22:12:52 -0700750 bool gen_flushes, u32 req_flags)
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800751{
752 struct test_sg_division *div = divs;
753 unsigned int remaining = TEST_SG_TOTAL;
754
755 do {
756 unsigned int this_len;
Eric Biggers65707372019-03-12 22:12:52 -0700757 const char *flushtype_str;
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800758
759 if (div == &divs[max_divs - 1] || prandom_u32() % 2 == 0)
760 this_len = remaining;
761 else
762 this_len = 1 + (prandom_u32() % remaining);
763 div->proportion_of_total = this_len;
764
765 if (prandom_u32() % 4 == 0)
766 div->offset = (PAGE_SIZE - 128) + (prandom_u32() % 128);
767 else if (prandom_u32() % 2 == 0)
768 div->offset = prandom_u32() % 32;
769 else
770 div->offset = prandom_u32() % PAGE_SIZE;
771 if (prandom_u32() % 8 == 0)
772 div->offset_relative_to_alignmask = true;
773
774 div->flush_type = FLUSH_TYPE_NONE;
775 if (gen_flushes) {
776 switch (prandom_u32() % 4) {
777 case 0:
778 div->flush_type = FLUSH_TYPE_REIMPORT;
779 break;
780 case 1:
781 div->flush_type = FLUSH_TYPE_FLUSH;
782 break;
783 }
784 }
785
Eric Biggers65707372019-03-12 22:12:52 -0700786 if (div->flush_type != FLUSH_TYPE_NONE &&
787 !(req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) &&
788 prandom_u32() % 2 == 0)
789 div->nosimd = true;
790
791 switch (div->flush_type) {
792 case FLUSH_TYPE_FLUSH:
793 if (div->nosimd)
794 flushtype_str = "<flush,nosimd>";
795 else
796 flushtype_str = "<flush>";
797 break;
798 case FLUSH_TYPE_REIMPORT:
799 if (div->nosimd)
800 flushtype_str = "<reimport,nosimd>";
801 else
802 flushtype_str = "<reimport>";
803 break;
804 default:
805 flushtype_str = "";
806 break;
807 }
808
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800809 BUILD_BUG_ON(TEST_SG_TOTAL != 10000); /* for "%u.%u%%" */
Eric Biggers65707372019-03-12 22:12:52 -0700810 p += scnprintf(p, end - p, "%s%u.%u%%@%s+%u%s", flushtype_str,
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800811 this_len / 100, this_len % 100,
812 div->offset_relative_to_alignmask ?
813 "alignmask" : "",
814 div->offset, this_len == remaining ? "" : ", ");
815 remaining -= this_len;
816 div++;
817 } while (remaining);
818
819 return p;
820}
821
822/* Generate a random testvec_config for fuzz testing */
823static void generate_random_testvec_config(struct testvec_config *cfg,
824 char *name, size_t max_namelen)
825{
826 char *p = name;
827 char * const end = name + max_namelen;
828
829 memset(cfg, 0, sizeof(*cfg));
830
831 cfg->name = name;
832
833 p += scnprintf(p, end - p, "random:");
834
835 if (prandom_u32() % 2 == 0) {
836 cfg->inplace = true;
837 p += scnprintf(p, end - p, " inplace");
838 }
839
840 if (prandom_u32() % 2 == 0) {
841 cfg->req_flags |= CRYPTO_TFM_REQ_MAY_SLEEP;
842 p += scnprintf(p, end - p, " may_sleep");
843 }
844
845 switch (prandom_u32() % 4) {
846 case 0:
847 cfg->finalization_type = FINALIZATION_TYPE_FINAL;
848 p += scnprintf(p, end - p, " use_final");
849 break;
850 case 1:
851 cfg->finalization_type = FINALIZATION_TYPE_FINUP;
852 p += scnprintf(p, end - p, " use_finup");
853 break;
854 default:
855 cfg->finalization_type = FINALIZATION_TYPE_DIGEST;
856 p += scnprintf(p, end - p, " use_digest");
857 break;
858 }
859
Eric Biggers65707372019-03-12 22:12:52 -0700860 if (!(cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) &&
861 prandom_u32() % 2 == 0) {
862 cfg->nosimd = true;
863 p += scnprintf(p, end - p, " nosimd");
864 }
865
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800866 p += scnprintf(p, end - p, " src_divs=[");
867 p = generate_random_sgl_divisions(cfg->src_divs,
868 ARRAY_SIZE(cfg->src_divs), p, end,
869 (cfg->finalization_type !=
Eric Biggers65707372019-03-12 22:12:52 -0700870 FINALIZATION_TYPE_DIGEST),
871 cfg->req_flags);
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800872 p += scnprintf(p, end - p, "]");
873
874 if (!cfg->inplace && prandom_u32() % 2 == 0) {
875 p += scnprintf(p, end - p, " dst_divs=[");
876 p = generate_random_sgl_divisions(cfg->dst_divs,
877 ARRAY_SIZE(cfg->dst_divs),
Eric Biggers65707372019-03-12 22:12:52 -0700878 p, end, false,
879 cfg->req_flags);
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800880 p += scnprintf(p, end - p, "]");
881 }
882
883 if (prandom_u32() % 2 == 0) {
884 cfg->iv_offset = 1 + (prandom_u32() % MAX_ALGAPI_ALIGNMASK);
885 p += scnprintf(p, end - p, " iv_offset=%u", cfg->iv_offset);
886 }
887
888 WARN_ON_ONCE(!valid_testvec_config(cfg));
889}
Eric Biggersb55e1a32019-03-12 22:12:47 -0700890
891static void crypto_disable_simd_for_test(void)
892{
893 preempt_disable();
894 __this_cpu_write(crypto_simd_disabled_for_test, true);
895}
896
897static void crypto_reenable_simd_for_test(void)
898{
899 __this_cpu_write(crypto_simd_disabled_for_test, false);
900 preempt_enable();
901}
902#else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
903static void crypto_disable_simd_for_test(void)
904{
905}
906
907static void crypto_reenable_simd_for_test(void)
908{
909}
910#endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800911
Eric Biggers65707372019-03-12 22:12:52 -0700912static int do_ahash_op(int (*op)(struct ahash_request *req),
913 struct ahash_request *req,
914 struct crypto_wait *wait, bool nosimd)
915{
916 int err;
917
918 if (nosimd)
919 crypto_disable_simd_for_test();
920
921 err = op(req);
922
923 if (nosimd)
924 crypto_reenable_simd_for_test();
925
926 return crypto_wait_req(err, wait);
927}
928
Eric Biggers4cc2dcf2019-01-31 23:51:48 -0800929static int check_nonfinal_hash_op(const char *op, int err,
930 u8 *result, unsigned int digestsize,
931 const char *driver, unsigned int vec_num,
932 const struct testvec_config *cfg)
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100933{
Eric Biggers4cc2dcf2019-01-31 23:51:48 -0800934 if (err) {
935 pr_err("alg: hash: %s %s() failed with err %d on test vector %u, cfg=\"%s\"\n",
936 driver, op, err, vec_num, cfg->name);
937 return err;
938 }
939 if (!testmgr_is_poison(result, digestsize)) {
940 pr_err("alg: hash: %s %s() used result buffer on test vector %u, cfg=\"%s\"\n",
941 driver, op, vec_num, cfg->name);
942 return -EINVAL;
943 }
944 return 0;
945}
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100946
Eric Biggers4cc2dcf2019-01-31 23:51:48 -0800947static int test_hash_vec_cfg(const char *driver,
948 const struct hash_testvec *vec,
949 unsigned int vec_num,
950 const struct testvec_config *cfg,
951 struct ahash_request *req,
952 struct test_sglist *tsgl,
953 u8 *hashstate)
954{
955 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
956 const unsigned int alignmask = crypto_ahash_alignmask(tfm);
957 const unsigned int digestsize = crypto_ahash_digestsize(tfm);
958 const unsigned int statesize = crypto_ahash_statesize(tfm);
959 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
960 const struct test_sg_division *divs[XBUFSIZE];
961 DECLARE_CRYPTO_WAIT(wait);
962 struct kvec _input;
963 struct iov_iter input;
964 unsigned int i;
965 struct scatterlist *pending_sgl;
966 unsigned int pending_len;
967 u8 result[HASH_MAX_DIGESTSIZE + TESTMGR_POISON_LEN];
968 int err;
969
970 /* Set the key, if specified */
971 if (vec->ksize) {
972 err = crypto_ahash_setkey(tfm, vec->key, vec->ksize);
973 if (err) {
974 pr_err("alg: hash: %s setkey failed with err %d on test vector %u; flags=%#x\n",
975 driver, err, vec_num,
976 crypto_ahash_get_flags(tfm));
977 return err;
978 }
979 }
980
981 /* Build the scatterlist for the source data */
982 _input.iov_base = (void *)vec->plaintext;
983 _input.iov_len = vec->psize;
984 iov_iter_kvec(&input, WRITE, &_input, 1, vec->psize);
985 err = build_test_sglist(tsgl, cfg->src_divs, alignmask, vec->psize,
986 &input, divs);
987 if (err) {
988 pr_err("alg: hash: %s: error preparing scatterlist for test vector %u, cfg=\"%s\"\n",
989 driver, vec_num, cfg->name);
990 return err;
991 }
992
993 /* Do the actual hashing */
994
995 testmgr_poison(req->__ctx, crypto_ahash_reqsize(tfm));
996 testmgr_poison(result, digestsize + TESTMGR_POISON_LEN);
997
998 if (cfg->finalization_type == FINALIZATION_TYPE_DIGEST) {
999 /* Just using digest() */
1000 ahash_request_set_callback(req, req_flags, crypto_req_done,
1001 &wait);
1002 ahash_request_set_crypt(req, tsgl->sgl, result, vec->psize);
Eric Biggers65707372019-03-12 22:12:52 -07001003 err = do_ahash_op(crypto_ahash_digest, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001004 if (err) {
1005 pr_err("alg: hash: %s digest() failed with err %d on test vector %u, cfg=\"%s\"\n",
1006 driver, err, vec_num, cfg->name);
1007 return err;
1008 }
1009 goto result_ready;
1010 }
1011
1012 /* Using init(), zero or more update(), then final() or finup() */
1013
1014 ahash_request_set_callback(req, req_flags, crypto_req_done, &wait);
1015 ahash_request_set_crypt(req, NULL, result, 0);
Eric Biggers65707372019-03-12 22:12:52 -07001016 err = do_ahash_op(crypto_ahash_init, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001017 err = check_nonfinal_hash_op("init", err, result, digestsize,
1018 driver, vec_num, cfg);
1019 if (err)
1020 return err;
1021
1022 pending_sgl = NULL;
1023 pending_len = 0;
1024 for (i = 0; i < tsgl->nents; i++) {
1025 if (divs[i]->flush_type != FLUSH_TYPE_NONE &&
1026 pending_sgl != NULL) {
1027 /* update() with the pending data */
1028 ahash_request_set_callback(req, req_flags,
1029 crypto_req_done, &wait);
1030 ahash_request_set_crypt(req, pending_sgl, result,
1031 pending_len);
Eric Biggers65707372019-03-12 22:12:52 -07001032 err = do_ahash_op(crypto_ahash_update, req, &wait,
1033 divs[i]->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001034 err = check_nonfinal_hash_op("update", err,
1035 result, digestsize,
1036 driver, vec_num, cfg);
1037 if (err)
1038 return err;
1039 pending_sgl = NULL;
1040 pending_len = 0;
1041 }
1042 if (divs[i]->flush_type == FLUSH_TYPE_REIMPORT) {
1043 /* Test ->export() and ->import() */
1044 testmgr_poison(hashstate + statesize,
1045 TESTMGR_POISON_LEN);
1046 err = crypto_ahash_export(req, hashstate);
1047 err = check_nonfinal_hash_op("export", err,
1048 result, digestsize,
1049 driver, vec_num, cfg);
1050 if (err)
1051 return err;
1052 if (!testmgr_is_poison(hashstate + statesize,
1053 TESTMGR_POISON_LEN)) {
1054 pr_err("alg: hash: %s export() overran state buffer on test vector %u, cfg=\"%s\"\n",
1055 driver, vec_num, cfg->name);
1056 return -EOVERFLOW;
1057 }
1058
1059 testmgr_poison(req->__ctx, crypto_ahash_reqsize(tfm));
1060 err = crypto_ahash_import(req, hashstate);
1061 err = check_nonfinal_hash_op("import", err,
1062 result, digestsize,
1063 driver, vec_num, cfg);
1064 if (err)
1065 return err;
1066 }
1067 if (pending_sgl == NULL)
1068 pending_sgl = &tsgl->sgl[i];
1069 pending_len += tsgl->sgl[i].length;
1070 }
1071
1072 ahash_request_set_callback(req, req_flags, crypto_req_done, &wait);
1073 ahash_request_set_crypt(req, pending_sgl, result, pending_len);
1074 if (cfg->finalization_type == FINALIZATION_TYPE_FINAL) {
1075 /* finish with update() and final() */
Eric Biggers65707372019-03-12 22:12:52 -07001076 err = do_ahash_op(crypto_ahash_update, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001077 err = check_nonfinal_hash_op("update", err, result, digestsize,
1078 driver, vec_num, cfg);
1079 if (err)
1080 return err;
Eric Biggers65707372019-03-12 22:12:52 -07001081 err = do_ahash_op(crypto_ahash_final, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001082 if (err) {
1083 pr_err("alg: hash: %s final() failed with err %d on test vector %u, cfg=\"%s\"\n",
1084 driver, err, vec_num, cfg->name);
1085 return err;
1086 }
1087 } else {
1088 /* finish with finup() */
Eric Biggers65707372019-03-12 22:12:52 -07001089 err = do_ahash_op(crypto_ahash_finup, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001090 if (err) {
1091 pr_err("alg: hash: %s finup() failed with err %d on test vector %u, cfg=\"%s\"\n",
1092 driver, err, vec_num, cfg->name);
1093 return err;
1094 }
1095 }
1096
1097result_ready:
1098 /* Check that the algorithm produced the correct digest */
1099 if (memcmp(result, vec->digest, digestsize) != 0) {
1100 pr_err("alg: hash: %s test failed (wrong result) on test vector %u, cfg=\"%s\"\n",
1101 driver, vec_num, cfg->name);
1102 return -EINVAL;
1103 }
1104 if (!testmgr_is_poison(&result[digestsize], TESTMGR_POISON_LEN)) {
1105 pr_err("alg: hash: %s overran result buffer on test vector %u, cfg=\"%s\"\n",
1106 driver, vec_num, cfg->name);
1107 return -EOVERFLOW;
1108 }
1109
1110 return 0;
1111}
1112
1113static int test_hash_vec(const char *driver, const struct hash_testvec *vec,
1114 unsigned int vec_num, struct ahash_request *req,
1115 struct test_sglist *tsgl, u8 *hashstate)
1116{
1117 unsigned int i;
1118 int err;
1119
1120 for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++) {
1121 err = test_hash_vec_cfg(driver, vec, vec_num,
1122 &default_hash_testvec_configs[i],
1123 req, tsgl, hashstate);
1124 if (err)
1125 return err;
1126 }
1127
1128#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1129 if (!noextratests) {
1130 struct testvec_config cfg;
1131 char cfgname[TESTVEC_CONFIG_NAMELEN];
1132
1133 for (i = 0; i < fuzz_iterations; i++) {
1134 generate_random_testvec_config(&cfg, cfgname,
1135 sizeof(cfgname));
1136 err = test_hash_vec_cfg(driver, vec, vec_num, &cfg,
1137 req, tsgl, hashstate);
1138 if (err)
1139 return err;
1140 }
1141 }
1142#endif
1143 return 0;
1144}
1145
1146static int __alg_test_hash(const struct hash_testvec *vecs,
1147 unsigned int num_vecs, const char *driver,
1148 u32 type, u32 mask)
1149{
1150 struct crypto_ahash *tfm;
1151 struct ahash_request *req = NULL;
1152 struct test_sglist *tsgl = NULL;
1153 u8 *hashstate = NULL;
1154 unsigned int i;
1155 int err;
1156
1157 tfm = crypto_alloc_ahash(driver, type, mask);
1158 if (IS_ERR(tfm)) {
1159 pr_err("alg: hash: failed to allocate transform for %s: %ld\n",
1160 driver, PTR_ERR(tfm));
1161 return PTR_ERR(tfm);
1162 }
1163
1164 req = ahash_request_alloc(tfm, GFP_KERNEL);
1165 if (!req) {
1166 pr_err("alg: hash: failed to allocate request for %s\n",
1167 driver);
1168 err = -ENOMEM;
1169 goto out;
1170 }
1171
1172 tsgl = kmalloc(sizeof(*tsgl), GFP_KERNEL);
1173 if (!tsgl || init_test_sglist(tsgl) != 0) {
1174 pr_err("alg: hash: failed to allocate test buffers for %s\n",
1175 driver);
1176 kfree(tsgl);
1177 tsgl = NULL;
1178 err = -ENOMEM;
1179 goto out;
1180 }
1181
1182 hashstate = kmalloc(crypto_ahash_statesize(tfm) + TESTMGR_POISON_LEN,
1183 GFP_KERNEL);
1184 if (!hashstate) {
1185 pr_err("alg: hash: failed to allocate hash state buffer for %s\n",
1186 driver);
1187 err = -ENOMEM;
1188 goto out;
1189 }
1190
1191 for (i = 0; i < num_vecs; i++) {
1192 err = test_hash_vec(driver, &vecs[i], i, req, tsgl, hashstate);
1193 if (err)
1194 goto out;
1195 }
1196 err = 0;
1197out:
1198 kfree(hashstate);
1199 if (tsgl) {
1200 destroy_test_sglist(tsgl);
1201 kfree(tsgl);
1202 }
1203 ahash_request_free(req);
1204 crypto_free_ahash(tfm);
1205 return err;
1206}
1207
1208static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1209 u32 type, u32 mask)
1210{
1211 const struct hash_testvec *template = desc->suite.hash.vecs;
1212 unsigned int tcount = desc->suite.hash.count;
1213 unsigned int nr_unkeyed, nr_keyed;
1214 int err;
1215
1216 /*
1217 * For OPTIONAL_KEY algorithms, we have to do all the unkeyed tests
1218 * first, before setting a key on the tfm. To make this easier, we
1219 * require that the unkeyed test vectors (if any) are listed first.
1220 */
1221
1222 for (nr_unkeyed = 0; nr_unkeyed < tcount; nr_unkeyed++) {
1223 if (template[nr_unkeyed].ksize)
1224 break;
1225 }
1226 for (nr_keyed = 0; nr_unkeyed + nr_keyed < tcount; nr_keyed++) {
1227 if (!template[nr_unkeyed + nr_keyed].ksize) {
1228 pr_err("alg: hash: test vectors for %s out of order, "
1229 "unkeyed ones must come first\n", desc->alg);
Kamil Konieczny466d7b92018-01-16 15:26:13 +01001230 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08001231 }
1232 }
1233
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001234 err = 0;
1235 if (nr_unkeyed) {
1236 err = __alg_test_hash(template, nr_unkeyed, driver, type, mask);
1237 template += nr_unkeyed;
Herbert Xuda7f0332008-07-31 17:08:25 +08001238 }
1239
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001240 if (!err && nr_keyed)
1241 err = __alg_test_hash(template, nr_keyed, driver, type, mask);
Wang, Rui Y018ba952016-02-03 18:26:57 +08001242
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001243 return err;
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +03001244}
1245
Eric Biggersed968042019-01-31 23:51:47 -08001246static int test_aead_vec_cfg(const char *driver, int enc,
1247 const struct aead_testvec *vec,
1248 unsigned int vec_num,
1249 const struct testvec_config *cfg,
1250 struct aead_request *req,
1251 struct cipher_test_sglists *tsgls)
Herbert Xuda7f0332008-07-31 17:08:25 +08001252{
Eric Biggersed968042019-01-31 23:51:47 -08001253 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1254 const unsigned int alignmask = crypto_aead_alignmask(tfm);
1255 const unsigned int ivsize = crypto_aead_ivsize(tfm);
1256 const unsigned int authsize = vec->clen - vec->plen;
1257 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
1258 const char *op = enc ? "encryption" : "decryption";
1259 DECLARE_CRYPTO_WAIT(wait);
1260 u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN];
1261 u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) +
1262 cfg->iv_offset +
1263 (cfg->iv_offset_relative_to_alignmask ? alignmask : 0);
1264 struct kvec input[2];
1265 int err;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001266
Eric Biggersed968042019-01-31 23:51:47 -08001267 /* Set the key */
1268 if (vec->wk)
1269 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001270 else
Eric Biggersed968042019-01-31 23:51:47 -08001271 crypto_aead_clear_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
1272 err = crypto_aead_setkey(tfm, vec->key, vec->klen);
1273 if (err) {
1274 if (vec->fail) /* expectedly failed to set key? */
1275 return 0;
1276 pr_err("alg: aead: %s setkey failed with err %d on test vector %u; flags=%#x\n",
1277 driver, err, vec_num, crypto_aead_get_flags(tfm));
1278 return err;
1279 }
1280 if (vec->fail) {
1281 pr_err("alg: aead: %s setkey unexpectedly succeeded on test vector %u\n",
1282 driver, vec_num);
1283 return -EINVAL;
1284 }
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001285
Eric Biggersed968042019-01-31 23:51:47 -08001286 /* Set the authentication tag size */
1287 err = crypto_aead_setauthsize(tfm, authsize);
1288 if (err) {
1289 pr_err("alg: aead: %s setauthsize failed with err %d on test vector %u\n",
1290 driver, err, vec_num);
1291 return err;
1292 }
1293
1294 /* The IV must be copied to a buffer, as the algorithm may modify it */
1295 if (WARN_ON(ivsize > MAX_IVLEN))
1296 return -EINVAL;
1297 if (vec->iv)
1298 memcpy(iv, vec->iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001299 else
Eric Biggersed968042019-01-31 23:51:47 -08001300 memset(iv, 0, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001301
Eric Biggersed968042019-01-31 23:51:47 -08001302 /* Build the src/dst scatterlists */
1303 input[0].iov_base = (void *)vec->assoc;
1304 input[0].iov_len = vec->alen;
1305 input[1].iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext;
1306 input[1].iov_len = enc ? vec->plen : vec->clen;
1307 err = build_cipher_test_sglists(tsgls, cfg, alignmask,
1308 vec->alen + (enc ? vec->plen :
1309 vec->clen),
1310 vec->alen + (enc ? vec->clen :
1311 vec->plen),
1312 input, 2);
1313 if (err) {
1314 pr_err("alg: aead: %s %s: error preparing scatterlists for test vector %u, cfg=\"%s\"\n",
1315 driver, op, vec_num, cfg->name);
1316 return err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001317 }
1318
Eric Biggersed968042019-01-31 23:51:47 -08001319 /* Do the actual encryption or decryption */
1320 testmgr_poison(req->__ctx, crypto_aead_reqsize(tfm));
1321 aead_request_set_callback(req, req_flags, crypto_req_done, &wait);
1322 aead_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr,
1323 enc ? vec->plen : vec->clen, iv);
1324 aead_request_set_ad(req, vec->alen);
Eric Biggers65707372019-03-12 22:12:52 -07001325 if (cfg->nosimd)
1326 crypto_disable_simd_for_test();
1327 err = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
1328 if (cfg->nosimd)
1329 crypto_reenable_simd_for_test();
1330 err = crypto_wait_req(err, &wait);
Eric Biggersed968042019-01-31 23:51:47 -08001331 if (err) {
1332 if (err == -EBADMSG && vec->novrfy)
1333 return 0;
1334 pr_err("alg: aead: %s %s failed with err %d on test vector %u, cfg=\"%s\"\n",
1335 driver, op, err, vec_num, cfg->name);
1336 return err;
1337 }
1338 if (vec->novrfy) {
1339 pr_err("alg: aead: %s %s unexpectedly succeeded on test vector %u, cfg=\"%s\"\n",
1340 driver, op, vec_num, cfg->name);
1341 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08001342 }
1343
Eric Biggersa6e5ef92019-01-31 23:51:50 -08001344 /* Check that the algorithm didn't overwrite things it shouldn't have */
1345 if (req->cryptlen != (enc ? vec->plen : vec->clen) ||
1346 req->assoclen != vec->alen ||
1347 req->iv != iv ||
1348 req->src != tsgls->src.sgl_ptr ||
1349 req->dst != tsgls->dst.sgl_ptr ||
1350 crypto_aead_reqtfm(req) != tfm ||
1351 req->base.complete != crypto_req_done ||
1352 req->base.flags != req_flags ||
1353 req->base.data != &wait) {
1354 pr_err("alg: aead: %s %s corrupted request struct on test vector %u, cfg=\"%s\"\n",
1355 driver, op, vec_num, cfg->name);
1356 if (req->cryptlen != (enc ? vec->plen : vec->clen))
1357 pr_err("alg: aead: changed 'req->cryptlen'\n");
1358 if (req->assoclen != vec->alen)
1359 pr_err("alg: aead: changed 'req->assoclen'\n");
1360 if (req->iv != iv)
1361 pr_err("alg: aead: changed 'req->iv'\n");
1362 if (req->src != tsgls->src.sgl_ptr)
1363 pr_err("alg: aead: changed 'req->src'\n");
1364 if (req->dst != tsgls->dst.sgl_ptr)
1365 pr_err("alg: aead: changed 'req->dst'\n");
1366 if (crypto_aead_reqtfm(req) != tfm)
1367 pr_err("alg: aead: changed 'req->base.tfm'\n");
1368 if (req->base.complete != crypto_req_done)
1369 pr_err("alg: aead: changed 'req->base.complete'\n");
1370 if (req->base.flags != req_flags)
1371 pr_err("alg: aead: changed 'req->base.flags'\n");
1372 if (req->base.data != &wait)
1373 pr_err("alg: aead: changed 'req->base.data'\n");
1374 return -EINVAL;
1375 }
1376 if (is_test_sglist_corrupted(&tsgls->src)) {
1377 pr_err("alg: aead: %s %s corrupted src sgl on test vector %u, cfg=\"%s\"\n",
1378 driver, op, vec_num, cfg->name);
1379 return -EINVAL;
1380 }
1381 if (tsgls->dst.sgl_ptr != tsgls->src.sgl &&
1382 is_test_sglist_corrupted(&tsgls->dst)) {
1383 pr_err("alg: aead: %s %s corrupted dst sgl on test vector %u, cfg=\"%s\"\n",
1384 driver, op, vec_num, cfg->name);
1385 return -EINVAL;
1386 }
1387
Eric Biggersed968042019-01-31 23:51:47 -08001388 /* Check for the correct output (ciphertext or plaintext) */
1389 err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext,
1390 enc ? vec->clen : vec->plen,
1391 vec->alen, enc || !cfg->inplace);
1392 if (err == -EOVERFLOW) {
1393 pr_err("alg: aead: %s %s overran dst buffer on test vector %u, cfg=\"%s\"\n",
1394 driver, op, vec_num, cfg->name);
1395 return err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001396 }
Eric Biggersed968042019-01-31 23:51:47 -08001397 if (err) {
1398 pr_err("alg: aead: %s %s test failed (wrong result) on test vector %u, cfg=\"%s\"\n",
1399 driver, op, vec_num, cfg->name);
1400 return err;
Jussi Kivilinna58dcf542013-06-13 17:37:50 +03001401 }
1402
1403 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001404}
1405
Eric Biggersed968042019-01-31 23:51:47 -08001406static int test_aead_vec(const char *driver, int enc,
1407 const struct aead_testvec *vec, unsigned int vec_num,
1408 struct aead_request *req,
1409 struct cipher_test_sglists *tsgls)
1410{
1411 unsigned int i;
1412 int err;
1413
1414 if (enc && vec->novrfy)
1415 return 0;
1416
1417 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
1418 err = test_aead_vec_cfg(driver, enc, vec, vec_num,
1419 &default_cipher_testvec_configs[i],
1420 req, tsgls);
1421 if (err)
1422 return err;
1423 }
1424
1425#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1426 if (!noextratests) {
1427 struct testvec_config cfg;
1428 char cfgname[TESTVEC_CONFIG_NAMELEN];
1429
1430 for (i = 0; i < fuzz_iterations; i++) {
1431 generate_random_testvec_config(&cfg, cfgname,
1432 sizeof(cfgname));
1433 err = test_aead_vec_cfg(driver, enc, vec, vec_num,
1434 &cfg, req, tsgls);
1435 if (err)
1436 return err;
1437 }
1438 }
1439#endif
1440 return 0;
1441}
1442
1443static int test_aead(const char *driver, int enc,
1444 const struct aead_test_suite *suite,
1445 struct aead_request *req,
1446 struct cipher_test_sglists *tsgls)
1447{
1448 unsigned int i;
1449 int err;
1450
1451 for (i = 0; i < suite->count; i++) {
1452 err = test_aead_vec(driver, enc, &suite->vecs[i], i, req,
1453 tsgls);
1454 if (err)
1455 return err;
1456 }
1457 return 0;
1458}
1459
1460static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1461 u32 type, u32 mask)
1462{
1463 const struct aead_test_suite *suite = &desc->suite.aead;
1464 struct crypto_aead *tfm;
1465 struct aead_request *req = NULL;
1466 struct cipher_test_sglists *tsgls = NULL;
1467 int err;
1468
1469 if (suite->count <= 0) {
1470 pr_err("alg: aead: empty test suite for %s\n", driver);
1471 return -EINVAL;
1472 }
1473
1474 tfm = crypto_alloc_aead(driver, type, mask);
1475 if (IS_ERR(tfm)) {
1476 pr_err("alg: aead: failed to allocate transform for %s: %ld\n",
1477 driver, PTR_ERR(tfm));
1478 return PTR_ERR(tfm);
1479 }
1480
1481 req = aead_request_alloc(tfm, GFP_KERNEL);
1482 if (!req) {
1483 pr_err("alg: aead: failed to allocate request for %s\n",
1484 driver);
1485 err = -ENOMEM;
1486 goto out;
1487 }
1488
1489 tsgls = alloc_cipher_test_sglists();
1490 if (!tsgls) {
1491 pr_err("alg: aead: failed to allocate test buffers for %s\n",
1492 driver);
1493 err = -ENOMEM;
1494 goto out;
1495 }
1496
1497 err = test_aead(driver, ENCRYPT, suite, req, tsgls);
1498 if (err)
1499 goto out;
1500
1501 err = test_aead(driver, DECRYPT, suite, req, tsgls);
1502out:
1503 free_cipher_test_sglists(tsgls);
1504 aead_request_free(req);
1505 crypto_free_aead(tfm);
1506 return err;
1507}
1508
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001509static int test_cipher(struct crypto_cipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001510 const struct cipher_testvec *template,
1511 unsigned int tcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08001512{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001513 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
1514 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001515 char *q;
1516 const char *e;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001517 const char *input, *result;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001518 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001519 char *xbuf[XBUFSIZE];
1520 int ret = -ENOMEM;
1521
1522 if (testmgr_alloc_buf(xbuf))
1523 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001524
1525 if (enc == ENCRYPT)
1526 e = "encryption";
1527 else
1528 e = "decryption";
1529
1530 j = 0;
1531 for (i = 0; i < tcount; i++) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001532
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001533 if (fips_enabled && template[i].fips_skip)
1534 continue;
1535
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001536 input = enc ? template[i].ptext : template[i].ctext;
1537 result = enc ? template[i].ctext : template[i].ptext;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001538 j++;
1539
Herbert Xufd57f222009-05-29 16:05:42 +10001540 ret = -EINVAL;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001541 if (WARN_ON(template[i].len > PAGE_SIZE))
Herbert Xufd57f222009-05-29 16:05:42 +10001542 goto out;
1543
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001544 data = xbuf[0];
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001545 memcpy(data, input, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001546
1547 crypto_cipher_clear_flags(tfm, ~0);
1548 if (template[i].wk)
Eric Biggers231baec2019-01-18 22:48:00 -08001549 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001550
1551 ret = crypto_cipher_setkey(tfm, template[i].key,
1552 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001553 if (template[i].fail == !ret) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001554 printk(KERN_ERR "alg: cipher: setkey failed "
1555 "on test %d for %s: flags=%x\n", j,
1556 algo, crypto_cipher_get_flags(tfm));
1557 goto out;
1558 } else if (ret)
1559 continue;
1560
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001561 for (k = 0; k < template[i].len;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001562 k += crypto_cipher_blocksize(tfm)) {
1563 if (enc)
1564 crypto_cipher_encrypt_one(tfm, data + k,
1565 data + k);
1566 else
1567 crypto_cipher_decrypt_one(tfm, data + k,
1568 data + k);
1569 }
1570
1571 q = data;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001572 if (memcmp(q, result, template[i].len)) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001573 printk(KERN_ERR "alg: cipher: Test %d failed "
1574 "on %s for %s\n", j, e, algo);
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001575 hexdump(q, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001576 ret = -EINVAL;
1577 goto out;
1578 }
1579 }
1580
1581 ret = 0;
1582
1583out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001584 testmgr_free_buf(xbuf);
1585out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001586 return ret;
1587}
1588
Eric Biggers4e7babba2019-01-31 23:51:46 -08001589static int test_skcipher_vec_cfg(const char *driver, int enc,
1590 const struct cipher_testvec *vec,
1591 unsigned int vec_num,
1592 const struct testvec_config *cfg,
1593 struct skcipher_request *req,
1594 struct cipher_test_sglists *tsgls)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001595{
Eric Biggers4e7babba2019-01-31 23:51:46 -08001596 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
1597 const unsigned int alignmask = crypto_skcipher_alignmask(tfm);
1598 const unsigned int ivsize = crypto_skcipher_ivsize(tfm);
1599 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
1600 const char *op = enc ? "encryption" : "decryption";
1601 DECLARE_CRYPTO_WAIT(wait);
1602 u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN];
1603 u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) +
1604 cfg->iv_offset +
1605 (cfg->iv_offset_relative_to_alignmask ? alignmask : 0);
1606 struct kvec input;
1607 int err;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001608
Eric Biggers4e7babba2019-01-31 23:51:46 -08001609 /* Set the key */
1610 if (vec->wk)
1611 crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001612 else
Eric Biggers4e7babba2019-01-31 23:51:46 -08001613 crypto_skcipher_clear_flags(tfm,
1614 CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
1615 err = crypto_skcipher_setkey(tfm, vec->key, vec->klen);
1616 if (err) {
1617 if (vec->fail) /* expectedly failed to set key? */
1618 return 0;
1619 pr_err("alg: skcipher: %s setkey failed with err %d on test vector %u; flags=%#x\n",
1620 driver, err, vec_num, crypto_skcipher_get_flags(tfm));
1621 return err;
1622 }
1623 if (vec->fail) {
1624 pr_err("alg: skcipher: %s setkey unexpectedly succeeded on test vector %u\n",
1625 driver, vec_num);
1626 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08001627 }
1628
Eric Biggers4e7babba2019-01-31 23:51:46 -08001629 /* The IV must be copied to a buffer, as the algorithm may modify it */
1630 if (ivsize) {
1631 if (WARN_ON(ivsize > MAX_IVLEN))
1632 return -EINVAL;
Eric Biggers8efd9722019-02-14 00:03:51 -08001633 if (vec->generates_iv && !enc)
1634 memcpy(iv, vec->iv_out, ivsize);
1635 else if (vec->iv)
Eric Biggers4e7babba2019-01-31 23:51:46 -08001636 memcpy(iv, vec->iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001637 else
Eric Biggers4e7babba2019-01-31 23:51:46 -08001638 memset(iv, 0, ivsize);
1639 } else {
1640 if (vec->generates_iv) {
1641 pr_err("alg: skcipher: %s has ivsize=0 but test vector %u generates IV!\n",
1642 driver, vec_num);
1643 return -EINVAL;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001644 }
Eric Biggers4e7babba2019-01-31 23:51:46 -08001645 iv = NULL;
Herbert Xuda7f0332008-07-31 17:08:25 +08001646 }
1647
Eric Biggers4e7babba2019-01-31 23:51:46 -08001648 /* Build the src/dst scatterlists */
1649 input.iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext;
1650 input.iov_len = vec->len;
1651 err = build_cipher_test_sglists(tsgls, cfg, alignmask,
1652 vec->len, vec->len, &input, 1);
1653 if (err) {
1654 pr_err("alg: skcipher: %s %s: error preparing scatterlists for test vector %u, cfg=\"%s\"\n",
1655 driver, op, vec_num, cfg->name);
1656 return err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001657 }
1658
Eric Biggers4e7babba2019-01-31 23:51:46 -08001659 /* Do the actual encryption or decryption */
1660 testmgr_poison(req->__ctx, crypto_skcipher_reqsize(tfm));
1661 skcipher_request_set_callback(req, req_flags, crypto_req_done, &wait);
1662 skcipher_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr,
1663 vec->len, iv);
Eric Biggers65707372019-03-12 22:12:52 -07001664 if (cfg->nosimd)
1665 crypto_disable_simd_for_test();
1666 err = enc ? crypto_skcipher_encrypt(req) : crypto_skcipher_decrypt(req);
1667 if (cfg->nosimd)
1668 crypto_reenable_simd_for_test();
1669 err = crypto_wait_req(err, &wait);
Eric Biggers4e7babba2019-01-31 23:51:46 -08001670 if (err) {
1671 pr_err("alg: skcipher: %s %s failed with err %d on test vector %u, cfg=\"%s\"\n",
1672 driver, op, err, vec_num, cfg->name);
1673 return err;
1674 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001675
Eric Biggersfa353c92019-01-31 23:51:49 -08001676 /* Check that the algorithm didn't overwrite things it shouldn't have */
1677 if (req->cryptlen != vec->len ||
1678 req->iv != iv ||
1679 req->src != tsgls->src.sgl_ptr ||
1680 req->dst != tsgls->dst.sgl_ptr ||
1681 crypto_skcipher_reqtfm(req) != tfm ||
1682 req->base.complete != crypto_req_done ||
1683 req->base.flags != req_flags ||
1684 req->base.data != &wait) {
1685 pr_err("alg: skcipher: %s %s corrupted request struct on test vector %u, cfg=\"%s\"\n",
1686 driver, op, vec_num, cfg->name);
1687 if (req->cryptlen != vec->len)
1688 pr_err("alg: skcipher: changed 'req->cryptlen'\n");
1689 if (req->iv != iv)
1690 pr_err("alg: skcipher: changed 'req->iv'\n");
1691 if (req->src != tsgls->src.sgl_ptr)
1692 pr_err("alg: skcipher: changed 'req->src'\n");
1693 if (req->dst != tsgls->dst.sgl_ptr)
1694 pr_err("alg: skcipher: changed 'req->dst'\n");
1695 if (crypto_skcipher_reqtfm(req) != tfm)
1696 pr_err("alg: skcipher: changed 'req->base.tfm'\n");
1697 if (req->base.complete != crypto_req_done)
1698 pr_err("alg: skcipher: changed 'req->base.complete'\n");
1699 if (req->base.flags != req_flags)
1700 pr_err("alg: skcipher: changed 'req->base.flags'\n");
1701 if (req->base.data != &wait)
1702 pr_err("alg: skcipher: changed 'req->base.data'\n");
1703 return -EINVAL;
1704 }
1705 if (is_test_sglist_corrupted(&tsgls->src)) {
1706 pr_err("alg: skcipher: %s %s corrupted src sgl on test vector %u, cfg=\"%s\"\n",
1707 driver, op, vec_num, cfg->name);
1708 return -EINVAL;
1709 }
1710 if (tsgls->dst.sgl_ptr != tsgls->src.sgl &&
1711 is_test_sglist_corrupted(&tsgls->dst)) {
1712 pr_err("alg: skcipher: %s %s corrupted dst sgl on test vector %u, cfg=\"%s\"\n",
1713 driver, op, vec_num, cfg->name);
1714 return -EINVAL;
1715 }
1716
Eric Biggers4e7babba2019-01-31 23:51:46 -08001717 /* Check for the correct output (ciphertext or plaintext) */
1718 err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext,
1719 vec->len, 0, true);
1720 if (err == -EOVERFLOW) {
1721 pr_err("alg: skcipher: %s %s overran dst buffer on test vector %u, cfg=\"%s\"\n",
1722 driver, op, vec_num, cfg->name);
1723 return err;
1724 }
1725 if (err) {
1726 pr_err("alg: skcipher: %s %s test failed (wrong result) on test vector %u, cfg=\"%s\"\n",
1727 driver, op, vec_num, cfg->name);
1728 return err;
1729 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001730
Eric Biggers4e7babba2019-01-31 23:51:46 -08001731 /* If applicable, check that the algorithm generated the correct IV */
Eric Biggers8efd9722019-02-14 00:03:51 -08001732 if (vec->iv_out && memcmp(iv, vec->iv_out, ivsize) != 0) {
Eric Biggers4e7babba2019-01-31 23:51:46 -08001733 pr_err("alg: skcipher: %s %s test failed (wrong output IV) on test vector %u, cfg=\"%s\"\n",
1734 driver, op, vec_num, cfg->name);
1735 hexdump(iv, ivsize);
1736 return -EINVAL;
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001737 }
1738
1739 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001740}
1741
Eric Biggers4e7babba2019-01-31 23:51:46 -08001742static int test_skcipher_vec(const char *driver, int enc,
1743 const struct cipher_testvec *vec,
1744 unsigned int vec_num,
1745 struct skcipher_request *req,
1746 struct cipher_test_sglists *tsgls)
1747{
1748 unsigned int i;
1749 int err;
1750
1751 if (fips_enabled && vec->fips_skip)
1752 return 0;
1753
1754 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
1755 err = test_skcipher_vec_cfg(driver, enc, vec, vec_num,
1756 &default_cipher_testvec_configs[i],
1757 req, tsgls);
1758 if (err)
1759 return err;
1760 }
1761
1762#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1763 if (!noextratests) {
1764 struct testvec_config cfg;
1765 char cfgname[TESTVEC_CONFIG_NAMELEN];
1766
1767 for (i = 0; i < fuzz_iterations; i++) {
1768 generate_random_testvec_config(&cfg, cfgname,
1769 sizeof(cfgname));
1770 err = test_skcipher_vec_cfg(driver, enc, vec, vec_num,
1771 &cfg, req, tsgls);
1772 if (err)
1773 return err;
1774 }
1775 }
1776#endif
1777 return 0;
1778}
1779
1780static int test_skcipher(const char *driver, int enc,
1781 const struct cipher_test_suite *suite,
1782 struct skcipher_request *req,
1783 struct cipher_test_sglists *tsgls)
1784{
1785 unsigned int i;
1786 int err;
1787
1788 for (i = 0; i < suite->count; i++) {
1789 err = test_skcipher_vec(driver, enc, &suite->vecs[i], i, req,
1790 tsgls);
1791 if (err)
1792 return err;
1793 }
1794 return 0;
1795}
1796
1797static int alg_test_skcipher(const struct alg_test_desc *desc,
1798 const char *driver, u32 type, u32 mask)
1799{
1800 const struct cipher_test_suite *suite = &desc->suite.cipher;
1801 struct crypto_skcipher *tfm;
1802 struct skcipher_request *req = NULL;
1803 struct cipher_test_sglists *tsgls = NULL;
1804 int err;
1805
1806 if (suite->count <= 0) {
1807 pr_err("alg: skcipher: empty test suite for %s\n", driver);
1808 return -EINVAL;
1809 }
1810
1811 tfm = crypto_alloc_skcipher(driver, type, mask);
1812 if (IS_ERR(tfm)) {
1813 pr_err("alg: skcipher: failed to allocate transform for %s: %ld\n",
1814 driver, PTR_ERR(tfm));
1815 return PTR_ERR(tfm);
1816 }
1817
1818 req = skcipher_request_alloc(tfm, GFP_KERNEL);
1819 if (!req) {
1820 pr_err("alg: skcipher: failed to allocate request for %s\n",
1821 driver);
1822 err = -ENOMEM;
1823 goto out;
1824 }
1825
1826 tsgls = alloc_cipher_test_sglists();
1827 if (!tsgls) {
1828 pr_err("alg: skcipher: failed to allocate test buffers for %s\n",
1829 driver);
1830 err = -ENOMEM;
1831 goto out;
1832 }
1833
1834 err = test_skcipher(driver, ENCRYPT, suite, req, tsgls);
1835 if (err)
1836 goto out;
1837
1838 err = test_skcipher(driver, DECRYPT, suite, req, tsgls);
1839out:
1840 free_cipher_test_sglists(tsgls);
1841 skcipher_request_free(req);
1842 crypto_free_skcipher(tfm);
1843 return err;
1844}
1845
Eric Biggersb13b1e02017-02-24 15:46:59 -08001846static int test_comp(struct crypto_comp *tfm,
1847 const struct comp_testvec *ctemplate,
1848 const struct comp_testvec *dtemplate,
1849 int ctcount, int dtcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08001850{
1851 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
Mahipal Challa33607382018-04-11 20:28:32 +02001852 char *output, *decomp_output;
Herbert Xuda7f0332008-07-31 17:08:25 +08001853 unsigned int i;
Herbert Xuda7f0332008-07-31 17:08:25 +08001854 int ret;
1855
Mahipal Challa33607382018-04-11 20:28:32 +02001856 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1857 if (!output)
1858 return -ENOMEM;
1859
1860 decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1861 if (!decomp_output) {
1862 kfree(output);
1863 return -ENOMEM;
1864 }
1865
Herbert Xuda7f0332008-07-31 17:08:25 +08001866 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001867 int ilen;
1868 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001869
Michael Schupikov22a81182018-10-07 13:58:10 +02001870 memset(output, 0, COMP_BUF_SIZE);
1871 memset(decomp_output, 0, COMP_BUF_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +08001872
1873 ilen = ctemplate[i].inlen;
1874 ret = crypto_comp_compress(tfm, ctemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02001875 ilen, output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001876 if (ret) {
1877 printk(KERN_ERR "alg: comp: compression failed "
1878 "on test %d for %s: ret=%d\n", i + 1, algo,
1879 -ret);
1880 goto out;
1881 }
1882
Mahipal Challa33607382018-04-11 20:28:32 +02001883 ilen = dlen;
1884 dlen = COMP_BUF_SIZE;
1885 ret = crypto_comp_decompress(tfm, output,
1886 ilen, decomp_output, &dlen);
1887 if (ret) {
1888 pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n",
1889 i + 1, algo, -ret);
1890 goto out;
1891 }
1892
1893 if (dlen != ctemplate[i].inlen) {
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001894 printk(KERN_ERR "alg: comp: Compression test %d "
1895 "failed for %s: output len = %d\n", i + 1, algo,
1896 dlen);
1897 ret = -EINVAL;
1898 goto out;
1899 }
1900
Mahipal Challa33607382018-04-11 20:28:32 +02001901 if (memcmp(decomp_output, ctemplate[i].input,
1902 ctemplate[i].inlen)) {
1903 pr_err("alg: comp: compression failed: output differs: on test %d for %s\n",
1904 i + 1, algo);
1905 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001906 ret = -EINVAL;
1907 goto out;
1908 }
1909 }
1910
1911 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001912 int ilen;
1913 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001914
Michael Schupikov22a81182018-10-07 13:58:10 +02001915 memset(decomp_output, 0, COMP_BUF_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +08001916
1917 ilen = dtemplate[i].inlen;
1918 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02001919 ilen, decomp_output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001920 if (ret) {
1921 printk(KERN_ERR "alg: comp: decompression failed "
1922 "on test %d for %s: ret=%d\n", i + 1, algo,
1923 -ret);
1924 goto out;
1925 }
1926
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001927 if (dlen != dtemplate[i].outlen) {
1928 printk(KERN_ERR "alg: comp: Decompression test %d "
1929 "failed for %s: output len = %d\n", i + 1, algo,
1930 dlen);
1931 ret = -EINVAL;
1932 goto out;
1933 }
1934
Mahipal Challa33607382018-04-11 20:28:32 +02001935 if (memcmp(decomp_output, dtemplate[i].output, dlen)) {
Herbert Xuda7f0332008-07-31 17:08:25 +08001936 printk(KERN_ERR "alg: comp: Decompression test %d "
1937 "failed for %s\n", i + 1, algo);
Mahipal Challa33607382018-04-11 20:28:32 +02001938 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001939 ret = -EINVAL;
1940 goto out;
1941 }
1942 }
1943
1944 ret = 0;
1945
1946out:
Mahipal Challa33607382018-04-11 20:28:32 +02001947 kfree(decomp_output);
1948 kfree(output);
Herbert Xuda7f0332008-07-31 17:08:25 +08001949 return ret;
1950}
1951
Eric Biggersb13b1e02017-02-24 15:46:59 -08001952static int test_acomp(struct crypto_acomp *tfm,
Mahipal Challa33607382018-04-11 20:28:32 +02001953 const struct comp_testvec *ctemplate,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001954 const struct comp_testvec *dtemplate,
1955 int ctcount, int dtcount)
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001956{
1957 const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
1958 unsigned int i;
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001959 char *output, *decomp_out;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001960 int ret;
1961 struct scatterlist src, dst;
1962 struct acomp_req *req;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001963 struct crypto_wait wait;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001964
Eric Biggerseb095592016-11-23 10:24:35 -08001965 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1966 if (!output)
1967 return -ENOMEM;
1968
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001969 decomp_out = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1970 if (!decomp_out) {
1971 kfree(output);
1972 return -ENOMEM;
1973 }
1974
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001975 for (i = 0; i < ctcount; i++) {
1976 unsigned int dlen = COMP_BUF_SIZE;
1977 int ilen = ctemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08001978 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001979
Eric Biggersd2110222016-12-30 14:12:00 -06001980 input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08001981 if (!input_vec) {
1982 ret = -ENOMEM;
1983 goto out;
1984 }
1985
Eric Biggerseb095592016-11-23 10:24:35 -08001986 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001987 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08001988 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001989 sg_init_one(&dst, output, dlen);
1990
1991 req = acomp_request_alloc(tfm);
1992 if (!req) {
1993 pr_err("alg: acomp: request alloc failed for %s\n",
1994 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08001995 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001996 ret = -ENOMEM;
1997 goto out;
1998 }
1999
2000 acomp_request_set_params(req, &src, &dst, ilen, dlen);
2001 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002002 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002003
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002004 ret = crypto_wait_req(crypto_acomp_compress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002005 if (ret) {
2006 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
2007 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08002008 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002009 acomp_request_free(req);
2010 goto out;
2011 }
2012
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002013 ilen = req->dlen;
2014 dlen = COMP_BUF_SIZE;
2015 sg_init_one(&src, output, ilen);
2016 sg_init_one(&dst, decomp_out, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002017 crypto_init_wait(&wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002018 acomp_request_set_params(req, &src, &dst, ilen, dlen);
2019
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002020 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002021 if (ret) {
2022 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
2023 i + 1, algo, -ret);
2024 kfree(input_vec);
2025 acomp_request_free(req);
2026 goto out;
2027 }
2028
2029 if (req->dlen != ctemplate[i].inlen) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002030 pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
2031 i + 1, algo, req->dlen);
2032 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002033 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002034 acomp_request_free(req);
2035 goto out;
2036 }
2037
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002038 if (memcmp(input_vec, decomp_out, req->dlen)) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002039 pr_err("alg: acomp: Compression test %d failed for %s\n",
2040 i + 1, algo);
2041 hexdump(output, req->dlen);
2042 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002043 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002044 acomp_request_free(req);
2045 goto out;
2046 }
2047
Laura Abbott02608e02016-12-21 12:32:54 -08002048 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002049 acomp_request_free(req);
2050 }
2051
2052 for (i = 0; i < dtcount; i++) {
2053 unsigned int dlen = COMP_BUF_SIZE;
2054 int ilen = dtemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08002055 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002056
Eric Biggersd2110222016-12-30 14:12:00 -06002057 input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08002058 if (!input_vec) {
2059 ret = -ENOMEM;
2060 goto out;
2061 }
2062
Eric Biggerseb095592016-11-23 10:24:35 -08002063 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002064 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08002065 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002066 sg_init_one(&dst, output, dlen);
2067
2068 req = acomp_request_alloc(tfm);
2069 if (!req) {
2070 pr_err("alg: acomp: request alloc failed for %s\n",
2071 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08002072 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002073 ret = -ENOMEM;
2074 goto out;
2075 }
2076
2077 acomp_request_set_params(req, &src, &dst, ilen, dlen);
2078 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002079 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002080
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002081 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002082 if (ret) {
2083 pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
2084 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08002085 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002086 acomp_request_free(req);
2087 goto out;
2088 }
2089
2090 if (req->dlen != dtemplate[i].outlen) {
2091 pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
2092 i + 1, algo, req->dlen);
2093 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002094 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002095 acomp_request_free(req);
2096 goto out;
2097 }
2098
2099 if (memcmp(output, dtemplate[i].output, req->dlen)) {
2100 pr_err("alg: acomp: Decompression test %d failed for %s\n",
2101 i + 1, algo);
2102 hexdump(output, req->dlen);
2103 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002104 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002105 acomp_request_free(req);
2106 goto out;
2107 }
2108
Laura Abbott02608e02016-12-21 12:32:54 -08002109 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002110 acomp_request_free(req);
2111 }
2112
2113 ret = 0;
2114
2115out:
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002116 kfree(decomp_out);
Eric Biggerseb095592016-11-23 10:24:35 -08002117 kfree(output);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002118 return ret;
2119}
2120
Eric Biggersb13b1e02017-02-24 15:46:59 -08002121static int test_cprng(struct crypto_rng *tfm,
2122 const struct cprng_testvec *template,
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002123 unsigned int tcount)
2124{
2125 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08002126 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002127 u8 *seed;
2128 char result[32];
2129
2130 seedsize = crypto_rng_seedsize(tfm);
2131
2132 seed = kmalloc(seedsize, GFP_KERNEL);
2133 if (!seed) {
2134 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
2135 "for %s\n", algo);
2136 return -ENOMEM;
2137 }
2138
2139 for (i = 0; i < tcount; i++) {
2140 memset(result, 0, 32);
2141
2142 memcpy(seed, template[i].v, template[i].vlen);
2143 memcpy(seed + template[i].vlen, template[i].key,
2144 template[i].klen);
2145 memcpy(seed + template[i].vlen + template[i].klen,
2146 template[i].dt, template[i].dtlen);
2147
2148 err = crypto_rng_reset(tfm, seed, seedsize);
2149 if (err) {
2150 printk(KERN_ERR "alg: cprng: Failed to reset rng "
2151 "for %s\n", algo);
2152 goto out;
2153 }
2154
2155 for (j = 0; j < template[i].loops; j++) {
2156 err = crypto_rng_get_bytes(tfm, result,
2157 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01002158 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002159 printk(KERN_ERR "alg: cprng: Failed to obtain "
2160 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01002161 "%s (requested %d)\n", algo,
2162 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002163 goto out;
2164 }
2165 }
2166
2167 err = memcmp(result, template[i].result,
2168 template[i].rlen);
2169 if (err) {
2170 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
2171 i, algo);
2172 hexdump(result, template[i].rlen);
2173 err = -EINVAL;
2174 goto out;
2175 }
2176 }
2177
2178out:
2179 kfree(seed);
2180 return err;
2181}
2182
Herbert Xuda7f0332008-07-31 17:08:25 +08002183static int alg_test_cipher(const struct alg_test_desc *desc,
2184 const char *driver, u32 type, u32 mask)
2185{
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002186 const struct cipher_test_suite *suite = &desc->suite.cipher;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002187 struct crypto_cipher *tfm;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002188 int err;
Herbert Xuda7f0332008-07-31 17:08:25 +08002189
Herbert Xueed93e02016-11-22 20:08:31 +08002190 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08002191 if (IS_ERR(tfm)) {
2192 printk(KERN_ERR "alg: cipher: Failed to load transform for "
2193 "%s: %ld\n", driver, PTR_ERR(tfm));
2194 return PTR_ERR(tfm);
2195 }
2196
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002197 err = test_cipher(tfm, ENCRYPT, suite->vecs, suite->count);
2198 if (!err)
2199 err = test_cipher(tfm, DECRYPT, suite->vecs, suite->count);
Herbert Xuda7f0332008-07-31 17:08:25 +08002200
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002201 crypto_free_cipher(tfm);
2202 return err;
2203}
2204
Herbert Xuda7f0332008-07-31 17:08:25 +08002205static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
2206 u32 type, u32 mask)
2207{
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002208 struct crypto_comp *comp;
2209 struct crypto_acomp *acomp;
Herbert Xuda7f0332008-07-31 17:08:25 +08002210 int err;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002211 u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
Herbert Xuda7f0332008-07-31 17:08:25 +08002212
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002213 if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
2214 acomp = crypto_alloc_acomp(driver, type, mask);
2215 if (IS_ERR(acomp)) {
2216 pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
2217 driver, PTR_ERR(acomp));
2218 return PTR_ERR(acomp);
2219 }
2220 err = test_acomp(acomp, desc->suite.comp.comp.vecs,
2221 desc->suite.comp.decomp.vecs,
2222 desc->suite.comp.comp.count,
2223 desc->suite.comp.decomp.count);
2224 crypto_free_acomp(acomp);
2225 } else {
2226 comp = crypto_alloc_comp(driver, type, mask);
2227 if (IS_ERR(comp)) {
2228 pr_err("alg: comp: Failed to load transform for %s: %ld\n",
2229 driver, PTR_ERR(comp));
2230 return PTR_ERR(comp);
2231 }
2232
2233 err = test_comp(comp, desc->suite.comp.comp.vecs,
2234 desc->suite.comp.decomp.vecs,
2235 desc->suite.comp.comp.count,
2236 desc->suite.comp.decomp.count);
2237
2238 crypto_free_comp(comp);
Herbert Xuda7f0332008-07-31 17:08:25 +08002239 }
Herbert Xuda7f0332008-07-31 17:08:25 +08002240 return err;
2241}
2242
Herbert Xu8e3ee852008-11-07 14:58:52 +08002243static int alg_test_crc32c(const struct alg_test_desc *desc,
2244 const char *driver, u32 type, u32 mask)
2245{
2246 struct crypto_shash *tfm;
Eric Biggerscb9dde82019-01-10 12:17:55 -08002247 __le32 val;
Herbert Xu8e3ee852008-11-07 14:58:52 +08002248 int err;
2249
2250 err = alg_test_hash(desc, driver, type, mask);
2251 if (err)
Eric Biggerseb5e6732019-01-23 20:57:35 -08002252 return err;
Herbert Xu8e3ee852008-11-07 14:58:52 +08002253
Herbert Xueed93e02016-11-22 20:08:31 +08002254 tfm = crypto_alloc_shash(driver, type, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002255 if (IS_ERR(tfm)) {
Eric Biggerseb5e6732019-01-23 20:57:35 -08002256 if (PTR_ERR(tfm) == -ENOENT) {
2257 /*
2258 * This crc32c implementation is only available through
2259 * ahash API, not the shash API, so the remaining part
2260 * of the test is not applicable to it.
2261 */
2262 return 0;
2263 }
Herbert Xu8e3ee852008-11-07 14:58:52 +08002264 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
2265 "%ld\n", driver, PTR_ERR(tfm));
Eric Biggerseb5e6732019-01-23 20:57:35 -08002266 return PTR_ERR(tfm);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002267 }
2268
2269 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02002270 SHASH_DESC_ON_STACK(shash, tfm);
2271 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002272
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02002273 shash->tfm = tfm;
2274 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08002275
Eric Biggerscb9dde82019-01-10 12:17:55 -08002276 *ctx = 420553207;
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02002277 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002278 if (err) {
2279 printk(KERN_ERR "alg: crc32c: Operation failed for "
2280 "%s: %d\n", driver, err);
2281 break;
2282 }
2283
Eric Biggerscb9dde82019-01-10 12:17:55 -08002284 if (val != cpu_to_le32(~420553207)) {
2285 pr_err("alg: crc32c: Test failed for %s: %u\n",
2286 driver, le32_to_cpu(val));
Herbert Xu8e3ee852008-11-07 14:58:52 +08002287 err = -EINVAL;
2288 }
2289 } while (0);
2290
2291 crypto_free_shash(tfm);
2292
Herbert Xu8e3ee852008-11-07 14:58:52 +08002293 return err;
2294}
2295
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002296static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
2297 u32 type, u32 mask)
2298{
2299 struct crypto_rng *rng;
2300 int err;
2301
Herbert Xueed93e02016-11-22 20:08:31 +08002302 rng = crypto_alloc_rng(driver, type, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002303 if (IS_ERR(rng)) {
2304 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
2305 "%ld\n", driver, PTR_ERR(rng));
2306 return PTR_ERR(rng);
2307 }
2308
2309 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
2310
2311 crypto_free_rng(rng);
2312
2313 return err;
2314}
2315
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002316
Eric Biggersb13b1e02017-02-24 15:46:59 -08002317static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002318 const char *driver, u32 type, u32 mask)
2319{
2320 int ret = -EAGAIN;
2321 struct crypto_rng *drng;
2322 struct drbg_test_data test_data;
2323 struct drbg_string addtl, pers, testentropy;
2324 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
2325
2326 if (!buf)
2327 return -ENOMEM;
2328
Herbert Xueed93e02016-11-22 20:08:31 +08002329 drng = crypto_alloc_rng(driver, type, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002330 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002331 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002332 "%s\n", driver);
2333 kzfree(buf);
2334 return -ENOMEM;
2335 }
2336
2337 test_data.testentropy = &testentropy;
2338 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
2339 drbg_string_fill(&pers, test->pers, test->perslen);
2340 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
2341 if (ret) {
2342 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
2343 goto outbuf;
2344 }
2345
2346 drbg_string_fill(&addtl, test->addtla, test->addtllen);
2347 if (pr) {
2348 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
2349 ret = crypto_drbg_get_bytes_addtl_test(drng,
2350 buf, test->expectedlen, &addtl, &test_data);
2351 } else {
2352 ret = crypto_drbg_get_bytes_addtl(drng,
2353 buf, test->expectedlen, &addtl);
2354 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01002355 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002356 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002357 "driver %s\n", driver);
2358 goto outbuf;
2359 }
2360
2361 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
2362 if (pr) {
2363 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
2364 ret = crypto_drbg_get_bytes_addtl_test(drng,
2365 buf, test->expectedlen, &addtl, &test_data);
2366 } else {
2367 ret = crypto_drbg_get_bytes_addtl(drng,
2368 buf, test->expectedlen, &addtl);
2369 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01002370 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002371 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002372 "driver %s\n", driver);
2373 goto outbuf;
2374 }
2375
2376 ret = memcmp(test->expected, buf, test->expectedlen);
2377
2378outbuf:
2379 crypto_free_rng(drng);
2380 kzfree(buf);
2381 return ret;
2382}
2383
2384
2385static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
2386 u32 type, u32 mask)
2387{
2388 int err = 0;
2389 int pr = 0;
2390 int i = 0;
Eric Biggersb13b1e02017-02-24 15:46:59 -08002391 const struct drbg_testvec *template = desc->suite.drbg.vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002392 unsigned int tcount = desc->suite.drbg.count;
2393
2394 if (0 == memcmp(driver, "drbg_pr_", 8))
2395 pr = 1;
2396
2397 for (i = 0; i < tcount; i++) {
2398 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
2399 if (err) {
2400 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
2401 i, driver);
2402 err = -EINVAL;
2403 break;
2404 }
2405 }
2406 return err;
2407
2408}
2409
Eric Biggersb13b1e02017-02-24 15:46:59 -08002410static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002411 const char *alg)
2412{
2413 struct kpp_request *req;
2414 void *input_buf = NULL;
2415 void *output_buf = NULL;
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002416 void *a_public = NULL;
2417 void *a_ss = NULL;
2418 void *shared_secret = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002419 struct crypto_wait wait;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002420 unsigned int out_len_max;
2421 int err = -ENOMEM;
2422 struct scatterlist src, dst;
2423
2424 req = kpp_request_alloc(tfm, GFP_KERNEL);
2425 if (!req)
2426 return err;
2427
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002428 crypto_init_wait(&wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002429
2430 err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
2431 if (err < 0)
2432 goto free_req;
2433
2434 out_len_max = crypto_kpp_maxsize(tfm);
2435 output_buf = kzalloc(out_len_max, GFP_KERNEL);
2436 if (!output_buf) {
2437 err = -ENOMEM;
2438 goto free_req;
2439 }
2440
2441 /* Use appropriate parameter as base */
2442 kpp_request_set_input(req, NULL, 0);
2443 sg_init_one(&dst, output_buf, out_len_max);
2444 kpp_request_set_output(req, &dst, out_len_max);
2445 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002446 crypto_req_done, &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002447
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002448 /* Compute party A's public key */
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002449 err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002450 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002451 pr_err("alg: %s: Party A: generate public key test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002452 alg, err);
2453 goto free_output;
2454 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002455
2456 if (vec->genkey) {
2457 /* Save party A's public key */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05002458 a_public = kmemdup(sg_virt(req->dst), out_len_max, GFP_KERNEL);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002459 if (!a_public) {
2460 err = -ENOMEM;
2461 goto free_output;
2462 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002463 } else {
2464 /* Verify calculated public key */
2465 if (memcmp(vec->expected_a_public, sg_virt(req->dst),
2466 vec->expected_a_public_size)) {
2467 pr_err("alg: %s: Party A: generate public key test failed. Invalid output\n",
2468 alg);
2469 err = -EINVAL;
2470 goto free_output;
2471 }
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002472 }
2473
2474 /* Calculate shared secret key by using counter part (b) public key. */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05002475 input_buf = kmemdup(vec->b_public, vec->b_public_size, GFP_KERNEL);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002476 if (!input_buf) {
2477 err = -ENOMEM;
2478 goto free_output;
2479 }
2480
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002481 sg_init_one(&src, input_buf, vec->b_public_size);
2482 sg_init_one(&dst, output_buf, out_len_max);
2483 kpp_request_set_input(req, &src, vec->b_public_size);
2484 kpp_request_set_output(req, &dst, out_len_max);
2485 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002486 crypto_req_done, &wait);
2487 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002488 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002489 pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002490 alg, err);
2491 goto free_all;
2492 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002493
2494 if (vec->genkey) {
2495 /* Save the shared secret obtained by party A */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05002496 a_ss = kmemdup(sg_virt(req->dst), vec->expected_ss_size, GFP_KERNEL);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002497 if (!a_ss) {
2498 err = -ENOMEM;
2499 goto free_all;
2500 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002501
2502 /*
2503 * Calculate party B's shared secret by using party A's
2504 * public key.
2505 */
2506 err = crypto_kpp_set_secret(tfm, vec->b_secret,
2507 vec->b_secret_size);
2508 if (err < 0)
2509 goto free_all;
2510
2511 sg_init_one(&src, a_public, vec->expected_a_public_size);
2512 sg_init_one(&dst, output_buf, out_len_max);
2513 kpp_request_set_input(req, &src, vec->expected_a_public_size);
2514 kpp_request_set_output(req, &dst, out_len_max);
2515 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002516 crypto_req_done, &wait);
2517 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req),
2518 &wait);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002519 if (err) {
2520 pr_err("alg: %s: Party B: compute shared secret failed. err %d\n",
2521 alg, err);
2522 goto free_all;
2523 }
2524
2525 shared_secret = a_ss;
2526 } else {
2527 shared_secret = (void *)vec->expected_ss;
2528 }
2529
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002530 /*
2531 * verify shared secret from which the user will derive
2532 * secret key by executing whatever hash it has chosen
2533 */
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002534 if (memcmp(shared_secret, sg_virt(req->dst),
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002535 vec->expected_ss_size)) {
2536 pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
2537 alg);
2538 err = -EINVAL;
2539 }
2540
2541free_all:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002542 kfree(a_ss);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002543 kfree(input_buf);
2544free_output:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002545 kfree(a_public);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002546 kfree(output_buf);
2547free_req:
2548 kpp_request_free(req);
2549 return err;
2550}
2551
2552static int test_kpp(struct crypto_kpp *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002553 const struct kpp_testvec *vecs, unsigned int tcount)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002554{
2555 int ret, i;
2556
2557 for (i = 0; i < tcount; i++) {
2558 ret = do_test_kpp(tfm, vecs++, alg);
2559 if (ret) {
2560 pr_err("alg: %s: test failed on vector %d, err=%d\n",
2561 alg, i + 1, ret);
2562 return ret;
2563 }
2564 }
2565 return 0;
2566}
2567
2568static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
2569 u32 type, u32 mask)
2570{
2571 struct crypto_kpp *tfm;
2572 int err = 0;
2573
Herbert Xueed93e02016-11-22 20:08:31 +08002574 tfm = crypto_alloc_kpp(driver, type, mask);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002575 if (IS_ERR(tfm)) {
2576 pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
2577 driver, PTR_ERR(tfm));
2578 return PTR_ERR(tfm);
2579 }
2580 if (desc->suite.kpp.vecs)
2581 err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
2582 desc->suite.kpp.count);
2583
2584 crypto_free_kpp(tfm);
2585 return err;
2586}
2587
Herbert Xu50d2b6432016-06-29 19:32:20 +08002588static int test_akcipher_one(struct crypto_akcipher *tfm,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002589 const struct akcipher_testvec *vecs)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002590{
Herbert Xudf27b262016-05-05 16:42:49 +08002591 char *xbuf[XBUFSIZE];
Tadeusz Struk946cc462015-06-16 10:31:06 -07002592 struct akcipher_request *req;
2593 void *outbuf_enc = NULL;
2594 void *outbuf_dec = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002595 struct crypto_wait wait;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002596 unsigned int out_len_max, out_len = 0;
2597 int err = -ENOMEM;
Vitaly Chikunovc7381b02019-04-11 18:51:15 +03002598 struct scatterlist src, dst, src_tab[3];
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002599 const char *m, *c;
2600 unsigned int m_size, c_size;
2601 const char *op;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002602
Herbert Xudf27b262016-05-05 16:42:49 +08002603 if (testmgr_alloc_buf(xbuf))
2604 return err;
2605
Tadeusz Struk946cc462015-06-16 10:31:06 -07002606 req = akcipher_request_alloc(tfm, GFP_KERNEL);
2607 if (!req)
Herbert Xudf27b262016-05-05 16:42:49 +08002608 goto free_xbuf;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002609
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002610 crypto_init_wait(&wait);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002611
2612 if (vecs->public_key_vec)
2613 err = crypto_akcipher_set_pub_key(tfm, vecs->key,
2614 vecs->key_len);
2615 else
2616 err = crypto_akcipher_set_priv_key(tfm, vecs->key,
2617 vecs->key_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002618 if (err)
2619 goto free_req;
2620
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002621 /*
2622 * First run test which do not require a private key, such as
2623 * encrypt or verify.
2624 */
Vitaly Chikunovc7381b02019-04-11 18:51:15 +03002625 err = -ENOMEM;
2626 out_len_max = crypto_akcipher_maxsize(tfm);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002627 outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
2628 if (!outbuf_enc)
2629 goto free_req;
2630
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002631 if (!vecs->siggen_sigver_test) {
2632 m = vecs->m;
2633 m_size = vecs->m_size;
2634 c = vecs->c;
2635 c_size = vecs->c_size;
2636 op = "encrypt";
2637 } else {
2638 /* Swap args so we could keep plaintext (digest)
2639 * in vecs->m, and cooked signature in vecs->c.
2640 */
2641 m = vecs->c; /* signature */
2642 m_size = vecs->c_size;
2643 c = vecs->m; /* digest */
2644 c_size = vecs->m_size;
2645 op = "verify";
2646 }
Herbert Xudf27b262016-05-05 16:42:49 +08002647
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002648 if (WARN_ON(m_size > PAGE_SIZE))
2649 goto free_all;
2650 memcpy(xbuf[0], m, m_size);
Herbert Xudf27b262016-05-05 16:42:49 +08002651
Vitaly Chikunovc7381b02019-04-11 18:51:15 +03002652 sg_init_table(src_tab, 3);
Herbert Xudf27b262016-05-05 16:42:49 +08002653 sg_set_buf(&src_tab[0], xbuf[0], 8);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002654 sg_set_buf(&src_tab[1], xbuf[0] + 8, m_size - 8);
Vitaly Chikunovc7381b02019-04-11 18:51:15 +03002655 if (vecs->siggen_sigver_test) {
2656 if (WARN_ON(c_size > PAGE_SIZE))
2657 goto free_all;
2658 memcpy(xbuf[1], c, c_size);
2659 sg_set_buf(&src_tab[2], xbuf[1], c_size);
2660 akcipher_request_set_crypt(req, src_tab, NULL, m_size, c_size);
2661 } else {
2662 sg_init_one(&dst, outbuf_enc, out_len_max);
2663 akcipher_request_set_crypt(req, src_tab, &dst, m_size,
2664 out_len_max);
2665 }
Tadeusz Struk946cc462015-06-16 10:31:06 -07002666 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002667 crypto_req_done, &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002668
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002669 err = crypto_wait_req(vecs->siggen_sigver_test ?
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002670 /* Run asymmetric signature verification */
2671 crypto_akcipher_verify(req) :
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002672 /* Run asymmetric encrypt */
2673 crypto_akcipher_encrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002674 if (err) {
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002675 pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002676 goto free_all;
2677 }
Vitaly Chikunovc7381b02019-04-11 18:51:15 +03002678 if (!vecs->siggen_sigver_test) {
2679 if (req->dst_len != c_size) {
2680 pr_err("alg: akcipher: %s test failed. Invalid output len\n",
2681 op);
2682 err = -EINVAL;
2683 goto free_all;
2684 }
2685 /* verify that encrypted message is equal to expected */
2686 if (memcmp(c, outbuf_enc, c_size) != 0) {
2687 pr_err("alg: akcipher: %s test failed. Invalid output\n",
2688 op);
2689 hexdump(outbuf_enc, c_size);
2690 err = -EINVAL;
2691 goto free_all;
2692 }
Tadeusz Struk946cc462015-06-16 10:31:06 -07002693 }
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002694
2695 /*
2696 * Don't invoke (decrypt or sign) test which require a private key
2697 * for vectors with only a public key.
2698 */
Tadeusz Struk946cc462015-06-16 10:31:06 -07002699 if (vecs->public_key_vec) {
2700 err = 0;
2701 goto free_all;
2702 }
2703 outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
2704 if (!outbuf_dec) {
2705 err = -ENOMEM;
2706 goto free_all;
2707 }
Herbert Xudf27b262016-05-05 16:42:49 +08002708
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002709 op = vecs->siggen_sigver_test ? "sign" : "decrypt";
2710 if (WARN_ON(c_size > PAGE_SIZE))
Herbert Xudf27b262016-05-05 16:42:49 +08002711 goto free_all;
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002712 memcpy(xbuf[0], c, c_size);
Herbert Xudf27b262016-05-05 16:42:49 +08002713
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002714 sg_init_one(&src, xbuf[0], c_size);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002715 sg_init_one(&dst, outbuf_dec, out_len_max);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002716 crypto_init_wait(&wait);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002717 akcipher_request_set_crypt(req, &src, &dst, c_size, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002718
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002719 err = crypto_wait_req(vecs->siggen_sigver_test ?
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002720 /* Run asymmetric signature generation */
2721 crypto_akcipher_sign(req) :
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002722 /* Run asymmetric decrypt */
2723 crypto_akcipher_decrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002724 if (err) {
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002725 pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002726 goto free_all;
2727 }
2728 out_len = req->dst_len;
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002729 if (out_len < m_size) {
2730 pr_err("alg: akcipher: %s test failed. Invalid output len %u\n",
2731 op, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002732 err = -EINVAL;
2733 goto free_all;
2734 }
2735 /* verify that decrypted message is equal to the original msg */
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002736 if (memchr_inv(outbuf_dec, 0, out_len - m_size) ||
2737 memcmp(m, outbuf_dec + out_len - m_size, m_size)) {
2738 pr_err("alg: akcipher: %s test failed. Invalid output\n", op);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002739 hexdump(outbuf_dec, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002740 err = -EINVAL;
2741 }
2742free_all:
2743 kfree(outbuf_dec);
2744 kfree(outbuf_enc);
2745free_req:
2746 akcipher_request_free(req);
Herbert Xudf27b262016-05-05 16:42:49 +08002747free_xbuf:
2748 testmgr_free_buf(xbuf);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002749 return err;
2750}
2751
Herbert Xu50d2b6432016-06-29 19:32:20 +08002752static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002753 const struct akcipher_testvec *vecs,
2754 unsigned int tcount)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002755{
Herbert Xu15226e42016-07-18 18:20:10 +08002756 const char *algo =
2757 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
Tadeusz Struk946cc462015-06-16 10:31:06 -07002758 int ret, i;
2759
2760 for (i = 0; i < tcount; i++) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002761 ret = test_akcipher_one(tfm, vecs++);
2762 if (!ret)
2763 continue;
2764
Herbert Xu15226e42016-07-18 18:20:10 +08002765 pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
2766 i + 1, algo, ret);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002767 return ret;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002768 }
2769 return 0;
2770}
2771
Tadeusz Struk946cc462015-06-16 10:31:06 -07002772static int alg_test_akcipher(const struct alg_test_desc *desc,
2773 const char *driver, u32 type, u32 mask)
2774{
2775 struct crypto_akcipher *tfm;
2776 int err = 0;
2777
Herbert Xueed93e02016-11-22 20:08:31 +08002778 tfm = crypto_alloc_akcipher(driver, type, mask);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002779 if (IS_ERR(tfm)) {
2780 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
2781 driver, PTR_ERR(tfm));
2782 return PTR_ERR(tfm);
2783 }
2784 if (desc->suite.akcipher.vecs)
2785 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
2786 desc->suite.akcipher.count);
2787
2788 crypto_free_akcipher(tfm);
2789 return err;
2790}
2791
Youquan, Song863b5572009-12-23 19:45:20 +08002792static int alg_test_null(const struct alg_test_desc *desc,
2793 const char *driver, u32 type, u32 mask)
2794{
2795 return 0;
2796}
2797
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002798#define __VECS(tv) { .vecs = tv, .count = ARRAY_SIZE(tv) }
2799
Herbert Xuda7f0332008-07-31 17:08:25 +08002800/* Please keep this list sorted by algorithm name. */
2801static const struct alg_test_desc alg_test_descs[] = {
2802 {
Eric Biggers059c2a42018-11-16 17:26:31 -08002803 .alg = "adiantum(xchacha12,aes)",
2804 .test = alg_test_skcipher,
2805 .suite = {
2806 .cipher = __VECS(adiantum_xchacha12_aes_tv_template)
2807 },
2808 }, {
2809 .alg = "adiantum(xchacha20,aes)",
2810 .test = alg_test_skcipher,
2811 .suite = {
2812 .cipher = __VECS(adiantum_xchacha20_aes_tv_template)
2813 },
2814 }, {
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002815 .alg = "aegis128",
2816 .test = alg_test_aead,
2817 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002818 .aead = __VECS(aegis128_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002819 }
2820 }, {
2821 .alg = "aegis128l",
2822 .test = alg_test_aead,
2823 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002824 .aead = __VECS(aegis128l_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002825 }
2826 }, {
2827 .alg = "aegis256",
2828 .test = alg_test_aead,
2829 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002830 .aead = __VECS(aegis256_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002831 }
2832 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002833 .alg = "ansi_cprng",
2834 .test = alg_test_cprng,
2835 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002836 .cprng = __VECS(ansi_cprng_aes_tv_template)
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002837 }
2838 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002839 .alg = "authenc(hmac(md5),ecb(cipher_null))",
2840 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002841 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002842 .aead = __VECS(hmac_md5_ecb_cipher_null_tv_template)
Horia Geantabca4feb2014-03-14 17:46:51 +02002843 }
2844 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002845 .alg = "authenc(hmac(sha1),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002846 .test = alg_test_aead,
Herbert Xubcf741c2017-06-28 19:09:07 +08002847 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002848 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002849 .aead = __VECS(hmac_sha1_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302850 }
2851 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002852 .alg = "authenc(hmac(sha1),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302853 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302854 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002855 .aead = __VECS(hmac_sha1_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302856 }
2857 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002858 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302859 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002860 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302861 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002862 .aead = __VECS(hmac_sha1_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002863 }
2864 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002865 .alg = "authenc(hmac(sha1),ctr(aes))",
2866 .test = alg_test_null,
2867 .fips_allowed = 1,
2868 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002869 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
2870 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002871 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002872 .aead = __VECS(hmac_sha1_ecb_cipher_null_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302873 }
2874 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002875 .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
2876 .test = alg_test_null,
2877 .fips_allowed = 1,
2878 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002879 .alg = "authenc(hmac(sha224),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302880 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302881 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002882 .aead = __VECS(hmac_sha224_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302883 }
2884 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002885 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302886 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002887 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302888 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002889 .aead = __VECS(hmac_sha224_des3_ede_cbc_tv_temp)
Horia Geantabca4feb2014-03-14 17:46:51 +02002890 }
2891 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002892 .alg = "authenc(hmac(sha256),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002893 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002894 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002895 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002896 .aead = __VECS(hmac_sha256_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302897 }
2898 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002899 .alg = "authenc(hmac(sha256),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302900 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302901 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002902 .aead = __VECS(hmac_sha256_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302903 }
2904 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002905 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302906 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002907 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302908 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002909 .aead = __VECS(hmac_sha256_des3_ede_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302910 }
2911 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002912 .alg = "authenc(hmac(sha256),ctr(aes))",
2913 .test = alg_test_null,
2914 .fips_allowed = 1,
2915 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002916 .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
2917 .test = alg_test_null,
2918 .fips_allowed = 1,
2919 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002920 .alg = "authenc(hmac(sha384),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302921 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302922 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002923 .aead = __VECS(hmac_sha384_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302924 }
2925 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002926 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302927 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002928 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302929 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002930 .aead = __VECS(hmac_sha384_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002931 }
2932 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002933 .alg = "authenc(hmac(sha384),ctr(aes))",
2934 .test = alg_test_null,
2935 .fips_allowed = 1,
2936 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002937 .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
2938 .test = alg_test_null,
2939 .fips_allowed = 1,
2940 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002941 .alg = "authenc(hmac(sha512),cbc(aes))",
Marcus Meissnered1afac2016-02-05 14:23:33 +01002942 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002943 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002944 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002945 .aead = __VECS(hmac_sha512_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302946 }
2947 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002948 .alg = "authenc(hmac(sha512),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302949 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302950 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002951 .aead = __VECS(hmac_sha512_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302952 }
2953 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002954 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302955 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002956 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302957 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002958 .aead = __VECS(hmac_sha512_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002959 }
2960 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002961 .alg = "authenc(hmac(sha512),ctr(aes))",
2962 .test = alg_test_null,
2963 .fips_allowed = 1,
2964 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002965 .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
2966 .test = alg_test_null,
2967 .fips_allowed = 1,
2968 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002969 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002970 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002971 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002972 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002973 .cipher = __VECS(aes_cbc_tv_template)
2974 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002975 }, {
2976 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002977 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002978 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002979 .cipher = __VECS(anubis_cbc_tv_template)
2980 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002981 }, {
2982 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002983 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002984 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002985 .cipher = __VECS(bf_cbc_tv_template)
2986 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002987 }, {
2988 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002989 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002990 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002991 .cipher = __VECS(camellia_cbc_tv_template)
2992 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002993 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002994 .alg = "cbc(cast5)",
2995 .test = alg_test_skcipher,
2996 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002997 .cipher = __VECS(cast5_cbc_tv_template)
2998 },
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002999 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003000 .alg = "cbc(cast6)",
3001 .test = alg_test_skcipher,
3002 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003003 .cipher = __VECS(cast6_cbc_tv_template)
3004 },
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003005 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003006 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003007 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003008 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003009 .cipher = __VECS(des_cbc_tv_template)
3010 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003011 }, {
3012 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003013 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003014 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003015 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003016 .cipher = __VECS(des3_ede_cbc_tv_template)
3017 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003018 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003019 /* Same as cbc(aes) except the key is stored in
3020 * hardware secure memory which we reference by index
3021 */
3022 .alg = "cbc(paes)",
3023 .test = alg_test_null,
3024 .fips_allowed = 1,
3025 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003026 .alg = "cbc(serpent)",
3027 .test = alg_test_skcipher,
3028 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003029 .cipher = __VECS(serpent_cbc_tv_template)
3030 },
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003031 }, {
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01003032 .alg = "cbc(sm4)",
3033 .test = alg_test_skcipher,
3034 .suite = {
3035 .cipher = __VECS(sm4_cbc_tv_template)
3036 }
3037 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003038 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003039 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003040 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003041 .cipher = __VECS(tf_cbc_tv_template)
3042 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003043 }, {
Ard Biesheuvel092acf02017-02-03 14:49:35 +00003044 .alg = "cbcmac(aes)",
3045 .fips_allowed = 1,
3046 .test = alg_test_hash,
3047 .suite = {
3048 .hash = __VECS(aes_cbcmac_tv_template)
3049 }
3050 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003051 .alg = "ccm(aes)",
3052 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003053 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003054 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003055 .aead = __VECS(aes_ccm_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003056 }
3057 }, {
Dmitry Eremin-Solenikov7da66672018-10-20 02:01:53 +03003058 .alg = "cfb(aes)",
3059 .test = alg_test_skcipher,
3060 .fips_allowed = 1,
3061 .suite = {
3062 .cipher = __VECS(aes_cfb_tv_template)
3063 },
3064 }, {
Martin Willi3590ebf2015-06-01 13:43:57 +02003065 .alg = "chacha20",
3066 .test = alg_test_skcipher,
3067 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003068 .cipher = __VECS(chacha20_tv_template)
3069 },
Martin Willi3590ebf2015-06-01 13:43:57 +02003070 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003071 .alg = "cmac(aes)",
Stephan Mueller8f183752015-08-19 08:42:07 +02003072 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003073 .test = alg_test_hash,
3074 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003075 .hash = __VECS(aes_cmac128_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003076 }
3077 }, {
3078 .alg = "cmac(des3_ede)",
Stephan Mueller8f183752015-08-19 08:42:07 +02003079 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003080 .test = alg_test_hash,
3081 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003082 .hash = __VECS(des3_ede_cmac64_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003083 }
3084 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003085 .alg = "compress_null",
3086 .test = alg_test_null,
3087 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003088 .alg = "crc32",
3089 .test = alg_test_hash,
Milan Broza8a34412019-01-25 10:31:47 +01003090 .fips_allowed = 1,
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003091 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003092 .hash = __VECS(crc32_tv_template)
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003093 }
3094 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003095 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08003096 .test = alg_test_crc32c,
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(crc32c_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003100 }
3101 }, {
Herbert Xu684115212013-09-07 12:56:26 +10003102 .alg = "crct10dif",
3103 .test = alg_test_hash,
3104 .fips_allowed = 1,
3105 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003106 .hash = __VECS(crct10dif_tv_template)
Herbert Xu684115212013-09-07 12:56:26 +10003107 }
3108 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003109 .alg = "ctr(aes)",
3110 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003111 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003112 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003113 .cipher = __VECS(aes_ctr_tv_template)
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003114 }
3115 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03003116 .alg = "ctr(blowfish)",
3117 .test = alg_test_skcipher,
3118 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003119 .cipher = __VECS(bf_ctr_tv_template)
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03003120 }
3121 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003122 .alg = "ctr(camellia)",
3123 .test = alg_test_skcipher,
3124 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003125 .cipher = __VECS(camellia_ctr_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003126 }
3127 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003128 .alg = "ctr(cast5)",
3129 .test = alg_test_skcipher,
3130 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003131 .cipher = __VECS(cast5_ctr_tv_template)
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003132 }
3133 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003134 .alg = "ctr(cast6)",
3135 .test = alg_test_skcipher,
3136 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003137 .cipher = __VECS(cast6_ctr_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003138 }
3139 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03003140 .alg = "ctr(des)",
3141 .test = alg_test_skcipher,
3142 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003143 .cipher = __VECS(des_ctr_tv_template)
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03003144 }
3145 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003146 .alg = "ctr(des3_ede)",
3147 .test = alg_test_skcipher,
Marcelo Cerri0d8da102017-03-20 17:28:05 -03003148 .fips_allowed = 1,
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003149 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003150 .cipher = __VECS(des3_ede_ctr_tv_template)
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003151 }
3152 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003153 /* Same as ctr(aes) except the key is stored in
3154 * hardware secure memory which we reference by index
3155 */
3156 .alg = "ctr(paes)",
3157 .test = alg_test_null,
3158 .fips_allowed = 1,
3159 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003160 .alg = "ctr(serpent)",
3161 .test = alg_test_skcipher,
3162 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003163 .cipher = __VECS(serpent_ctr_tv_template)
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003164 }
3165 }, {
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01003166 .alg = "ctr(sm4)",
3167 .test = alg_test_skcipher,
3168 .suite = {
3169 .cipher = __VECS(sm4_ctr_tv_template)
3170 }
3171 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03003172 .alg = "ctr(twofish)",
3173 .test = alg_test_skcipher,
3174 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003175 .cipher = __VECS(tf_ctr_tv_template)
Jussi Kivilinna573da622011-10-10 23:03:12 +03003176 }
3177 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003178 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003179 .test = alg_test_skcipher,
Gilad Ben-Yossef196ad602018-11-04 10:05:24 +00003180 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003181 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003182 .cipher = __VECS(cts_mode_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003183 }
3184 }, {
3185 .alg = "deflate",
3186 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003187 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003188 .suite = {
3189 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003190 .comp = __VECS(deflate_comp_tv_template),
3191 .decomp = __VECS(deflate_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003192 }
3193 }
3194 }, {
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003195 .alg = "dh",
3196 .test = alg_test_kpp,
3197 .fips_allowed = 1,
3198 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003199 .kpp = __VECS(dh_tv_template)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003200 }
3201 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003202 .alg = "digest_null",
3203 .test = alg_test_null,
3204 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003205 .alg = "drbg_nopr_ctr_aes128",
3206 .test = alg_test_drbg,
3207 .fips_allowed = 1,
3208 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003209 .drbg = __VECS(drbg_nopr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003210 }
3211 }, {
3212 .alg = "drbg_nopr_ctr_aes192",
3213 .test = alg_test_drbg,
3214 .fips_allowed = 1,
3215 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003216 .drbg = __VECS(drbg_nopr_ctr_aes192_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003217 }
3218 }, {
3219 .alg = "drbg_nopr_ctr_aes256",
3220 .test = alg_test_drbg,
3221 .fips_allowed = 1,
3222 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003223 .drbg = __VECS(drbg_nopr_ctr_aes256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003224 }
3225 }, {
3226 /*
3227 * There is no need to specifically test the DRBG with every
3228 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
3229 */
3230 .alg = "drbg_nopr_hmac_sha1",
3231 .fips_allowed = 1,
3232 .test = alg_test_null,
3233 }, {
3234 .alg = "drbg_nopr_hmac_sha256",
3235 .test = alg_test_drbg,
3236 .fips_allowed = 1,
3237 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003238 .drbg = __VECS(drbg_nopr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003239 }
3240 }, {
3241 /* covered by drbg_nopr_hmac_sha256 test */
3242 .alg = "drbg_nopr_hmac_sha384",
3243 .fips_allowed = 1,
3244 .test = alg_test_null,
3245 }, {
3246 .alg = "drbg_nopr_hmac_sha512",
3247 .test = alg_test_null,
3248 .fips_allowed = 1,
3249 }, {
3250 .alg = "drbg_nopr_sha1",
3251 .fips_allowed = 1,
3252 .test = alg_test_null,
3253 }, {
3254 .alg = "drbg_nopr_sha256",
3255 .test = alg_test_drbg,
3256 .fips_allowed = 1,
3257 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003258 .drbg = __VECS(drbg_nopr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003259 }
3260 }, {
3261 /* covered by drbg_nopr_sha256 test */
3262 .alg = "drbg_nopr_sha384",
3263 .fips_allowed = 1,
3264 .test = alg_test_null,
3265 }, {
3266 .alg = "drbg_nopr_sha512",
3267 .fips_allowed = 1,
3268 .test = alg_test_null,
3269 }, {
3270 .alg = "drbg_pr_ctr_aes128",
3271 .test = alg_test_drbg,
3272 .fips_allowed = 1,
3273 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003274 .drbg = __VECS(drbg_pr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003275 }
3276 }, {
3277 /* covered by drbg_pr_ctr_aes128 test */
3278 .alg = "drbg_pr_ctr_aes192",
3279 .fips_allowed = 1,
3280 .test = alg_test_null,
3281 }, {
3282 .alg = "drbg_pr_ctr_aes256",
3283 .fips_allowed = 1,
3284 .test = alg_test_null,
3285 }, {
3286 .alg = "drbg_pr_hmac_sha1",
3287 .fips_allowed = 1,
3288 .test = alg_test_null,
3289 }, {
3290 .alg = "drbg_pr_hmac_sha256",
3291 .test = alg_test_drbg,
3292 .fips_allowed = 1,
3293 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003294 .drbg = __VECS(drbg_pr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003295 }
3296 }, {
3297 /* covered by drbg_pr_hmac_sha256 test */
3298 .alg = "drbg_pr_hmac_sha384",
3299 .fips_allowed = 1,
3300 .test = alg_test_null,
3301 }, {
3302 .alg = "drbg_pr_hmac_sha512",
3303 .test = alg_test_null,
3304 .fips_allowed = 1,
3305 }, {
3306 .alg = "drbg_pr_sha1",
3307 .fips_allowed = 1,
3308 .test = alg_test_null,
3309 }, {
3310 .alg = "drbg_pr_sha256",
3311 .test = alg_test_drbg,
3312 .fips_allowed = 1,
3313 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003314 .drbg = __VECS(drbg_pr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003315 }
3316 }, {
3317 /* covered by drbg_pr_sha256 test */
3318 .alg = "drbg_pr_sha384",
3319 .fips_allowed = 1,
3320 .test = alg_test_null,
3321 }, {
3322 .alg = "drbg_pr_sha512",
3323 .fips_allowed = 1,
3324 .test = alg_test_null,
3325 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003326 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003327 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003328 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003329 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003330 .cipher = __VECS(aes_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003331 }
3332 }, {
3333 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003334 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003335 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003336 .cipher = __VECS(anubis_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003337 }
3338 }, {
3339 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003340 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003341 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003342 .cipher = __VECS(arc4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003343 }
3344 }, {
3345 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003346 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003347 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003348 .cipher = __VECS(bf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003349 }
3350 }, {
3351 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003352 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003353 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003354 .cipher = __VECS(camellia_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003355 }
3356 }, {
3357 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003358 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003359 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003360 .cipher = __VECS(cast5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003361 }
3362 }, {
3363 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003364 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003365 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003366 .cipher = __VECS(cast6_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003367 }
3368 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003369 .alg = "ecb(cipher_null)",
3370 .test = alg_test_null,
Milan Broz6175ca22017-04-21 13:03:06 +02003371 .fips_allowed = 1,
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003372 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003373 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003374 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003375 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003376 .cipher = __VECS(des_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003377 }
3378 }, {
3379 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003380 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003381 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003382 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003383 .cipher = __VECS(des3_ede_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003384 }
3385 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003386 .alg = "ecb(fcrypt)",
3387 .test = alg_test_skcipher,
3388 .suite = {
3389 .cipher = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003390 .vecs = fcrypt_pcbc_tv_template,
3391 .count = 1
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003392 }
3393 }
3394 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003395 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003396 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003397 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003398 .cipher = __VECS(khazad_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003399 }
3400 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003401 /* Same as ecb(aes) except the key is stored in
3402 * hardware secure memory which we reference by index
3403 */
3404 .alg = "ecb(paes)",
3405 .test = alg_test_null,
3406 .fips_allowed = 1,
3407 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003408 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003409 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003410 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003411 .cipher = __VECS(seed_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003412 }
3413 }, {
3414 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003415 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003416 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003417 .cipher = __VECS(serpent_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003418 }
3419 }, {
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00003420 .alg = "ecb(sm4)",
3421 .test = alg_test_skcipher,
3422 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003423 .cipher = __VECS(sm4_tv_template)
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00003424 }
3425 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003426 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003427 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003428 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003429 .cipher = __VECS(tea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003430 }
3431 }, {
3432 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003433 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003434 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003435 .cipher = __VECS(tnepres_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003436 }
3437 }, {
3438 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003439 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003440 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003441 .cipher = __VECS(tf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003442 }
3443 }, {
3444 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003445 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003446 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003447 .cipher = __VECS(xeta_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003448 }
3449 }, {
3450 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003451 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003452 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003453 .cipher = __VECS(xtea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003454 }
3455 }, {
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003456 .alg = "ecdh",
3457 .test = alg_test_kpp,
3458 .fips_allowed = 1,
3459 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003460 .kpp = __VECS(ecdh_tv_template)
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003461 }
3462 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003463 .alg = "gcm(aes)",
3464 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003465 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003466 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003467 .aead = __VECS(aes_gcm_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003468 }
3469 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003470 .alg = "ghash",
3471 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003472 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003473 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003474 .hash = __VECS(ghash_tv_template)
Youquan, Song507069c2009-11-23 20:23:04 +08003475 }
3476 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003477 .alg = "hmac(md5)",
3478 .test = alg_test_hash,
3479 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003480 .hash = __VECS(hmac_md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003481 }
3482 }, {
3483 .alg = "hmac(rmd128)",
3484 .test = alg_test_hash,
3485 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003486 .hash = __VECS(hmac_rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003487 }
3488 }, {
3489 .alg = "hmac(rmd160)",
3490 .test = alg_test_hash,
3491 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003492 .hash = __VECS(hmac_rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003493 }
3494 }, {
3495 .alg = "hmac(sha1)",
3496 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003497 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003498 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003499 .hash = __VECS(hmac_sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003500 }
3501 }, {
3502 .alg = "hmac(sha224)",
3503 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003504 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003505 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003506 .hash = __VECS(hmac_sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003507 }
3508 }, {
3509 .alg = "hmac(sha256)",
3510 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003511 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003512 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003513 .hash = __VECS(hmac_sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003514 }
3515 }, {
raveendra padasalagi98eca722016-07-01 11:16:54 +05303516 .alg = "hmac(sha3-224)",
3517 .test = alg_test_hash,
3518 .fips_allowed = 1,
3519 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003520 .hash = __VECS(hmac_sha3_224_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303521 }
3522 }, {
3523 .alg = "hmac(sha3-256)",
3524 .test = alg_test_hash,
3525 .fips_allowed = 1,
3526 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003527 .hash = __VECS(hmac_sha3_256_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303528 }
3529 }, {
3530 .alg = "hmac(sha3-384)",
3531 .test = alg_test_hash,
3532 .fips_allowed = 1,
3533 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003534 .hash = __VECS(hmac_sha3_384_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303535 }
3536 }, {
3537 .alg = "hmac(sha3-512)",
3538 .test = alg_test_hash,
3539 .fips_allowed = 1,
3540 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003541 .hash = __VECS(hmac_sha3_512_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303542 }
3543 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003544 .alg = "hmac(sha384)",
3545 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003546 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003547 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003548 .hash = __VECS(hmac_sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003549 }
3550 }, {
3551 .alg = "hmac(sha512)",
3552 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003553 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003554 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003555 .hash = __VECS(hmac_sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003556 }
3557 }, {
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03003558 .alg = "hmac(streebog256)",
3559 .test = alg_test_hash,
3560 .suite = {
3561 .hash = __VECS(hmac_streebog256_tv_template)
3562 }
3563 }, {
3564 .alg = "hmac(streebog512)",
3565 .test = alg_test_hash,
3566 .suite = {
3567 .hash = __VECS(hmac_streebog512_tv_template)
3568 }
3569 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003570 .alg = "jitterentropy_rng",
3571 .fips_allowed = 1,
3572 .test = alg_test_null,
3573 }, {
Stephan Mueller35351982015-09-21 20:59:56 +02003574 .alg = "kw(aes)",
3575 .test = alg_test_skcipher,
3576 .fips_allowed = 1,
3577 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003578 .cipher = __VECS(aes_kw_tv_template)
Stephan Mueller35351982015-09-21 20:59:56 +02003579 }
3580 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003581 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003582 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003583 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003584 .cipher = __VECS(aes_lrw_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003585 }
3586 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003587 .alg = "lrw(camellia)",
3588 .test = alg_test_skcipher,
3589 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003590 .cipher = __VECS(camellia_lrw_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003591 }
3592 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003593 .alg = "lrw(cast6)",
3594 .test = alg_test_skcipher,
3595 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003596 .cipher = __VECS(cast6_lrw_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003597 }
3598 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003599 .alg = "lrw(serpent)",
3600 .test = alg_test_skcipher,
3601 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003602 .cipher = __VECS(serpent_lrw_tv_template)
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003603 }
3604 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003605 .alg = "lrw(twofish)",
3606 .test = alg_test_skcipher,
3607 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003608 .cipher = __VECS(tf_lrw_tv_template)
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003609 }
3610 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003611 .alg = "lz4",
3612 .test = alg_test_comp,
3613 .fips_allowed = 1,
3614 .suite = {
3615 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003616 .comp = __VECS(lz4_comp_tv_template),
3617 .decomp = __VECS(lz4_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003618 }
3619 }
3620 }, {
3621 .alg = "lz4hc",
3622 .test = alg_test_comp,
3623 .fips_allowed = 1,
3624 .suite = {
3625 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003626 .comp = __VECS(lz4hc_comp_tv_template),
3627 .decomp = __VECS(lz4hc_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003628 }
3629 }
3630 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003631 .alg = "lzo",
3632 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003633 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003634 .suite = {
3635 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003636 .comp = __VECS(lzo_comp_tv_template),
3637 .decomp = __VECS(lzo_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003638 }
3639 }
3640 }, {
3641 .alg = "md4",
3642 .test = alg_test_hash,
3643 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003644 .hash = __VECS(md4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003645 }
3646 }, {
3647 .alg = "md5",
3648 .test = alg_test_hash,
3649 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003650 .hash = __VECS(md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003651 }
3652 }, {
3653 .alg = "michael_mic",
3654 .test = alg_test_hash,
3655 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003656 .hash = __VECS(michael_mic_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003657 }
3658 }, {
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003659 .alg = "morus1280",
3660 .test = alg_test_aead,
3661 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003662 .aead = __VECS(morus1280_tv_template)
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003663 }
3664 }, {
3665 .alg = "morus640",
3666 .test = alg_test_aead,
3667 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003668 .aead = __VECS(morus640_tv_template)
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003669 }
3670 }, {
Eric Biggers26609a22018-11-16 17:26:29 -08003671 .alg = "nhpoly1305",
3672 .test = alg_test_hash,
3673 .suite = {
3674 .hash = __VECS(nhpoly1305_tv_template)
3675 }
3676 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003677 .alg = "ofb(aes)",
3678 .test = alg_test_skcipher,
3679 .fips_allowed = 1,
3680 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003681 .cipher = __VECS(aes_ofb_tv_template)
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003682 }
3683 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003684 /* Same as ofb(aes) except the key is stored in
3685 * hardware secure memory which we reference by index
3686 */
3687 .alg = "ofb(paes)",
3688 .test = alg_test_null,
3689 .fips_allowed = 1,
3690 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003691 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003692 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003693 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003694 .cipher = __VECS(fcrypt_pcbc_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003695 }
3696 }, {
Stephan Mueller12071072017-06-12 23:27:51 +02003697 .alg = "pkcs1pad(rsa,sha224)",
3698 .test = alg_test_null,
3699 .fips_allowed = 1,
3700 }, {
3701 .alg = "pkcs1pad(rsa,sha256)",
3702 .test = alg_test_akcipher,
3703 .fips_allowed = 1,
3704 .suite = {
3705 .akcipher = __VECS(pkcs1pad_rsa_tv_template)
3706 }
3707 }, {
3708 .alg = "pkcs1pad(rsa,sha384)",
3709 .test = alg_test_null,
3710 .fips_allowed = 1,
3711 }, {
3712 .alg = "pkcs1pad(rsa,sha512)",
3713 .test = alg_test_null,
3714 .fips_allowed = 1,
3715 }, {
Martin Willieee9dc62015-06-01 13:43:59 +02003716 .alg = "poly1305",
3717 .test = alg_test_hash,
3718 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003719 .hash = __VECS(poly1305_tv_template)
Martin Willieee9dc62015-06-01 13:43:59 +02003720 }
3721 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003722 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003723 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003724 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003725 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003726 .cipher = __VECS(aes_ctr_rfc3686_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003727 }
3728 }, {
Herbert Xu3f31a742015-07-09 07:17:34 +08003729 .alg = "rfc4106(gcm(aes))",
Adrian Hoban69435b92010-11-04 15:02:04 -04003730 .test = alg_test_aead,
Jarod Wilsondb71f29a2015-01-23 12:42:15 -05003731 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003732 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003733 .aead = __VECS(aes_gcm_rfc4106_tv_template)
Adrian Hoban69435b92010-11-04 15:02:04 -04003734 }
3735 }, {
Herbert Xu544c4362015-07-14 16:53:22 +08003736 .alg = "rfc4309(ccm(aes))",
Jarod Wilson5d667322009-05-04 19:23:40 +08003737 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003738 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003739 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003740 .aead = __VECS(aes_ccm_rfc4309_tv_template)
Jarod Wilson5d667322009-05-04 19:23:40 +08003741 }
3742 }, {
Herbert Xubb687452015-06-16 13:54:24 +08003743 .alg = "rfc4543(gcm(aes))",
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003744 .test = alg_test_aead,
3745 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003746 .aead = __VECS(aes_gcm_rfc4543_tv_template)
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003747 }
3748 }, {
Martin Williaf2b76b2015-06-01 13:44:01 +02003749 .alg = "rfc7539(chacha20,poly1305)",
3750 .test = alg_test_aead,
3751 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003752 .aead = __VECS(rfc7539_tv_template)
Martin Williaf2b76b2015-06-01 13:44:01 +02003753 }
3754 }, {
Martin Willi59007582015-06-01 13:44:03 +02003755 .alg = "rfc7539esp(chacha20,poly1305)",
3756 .test = alg_test_aead,
3757 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003758 .aead = __VECS(rfc7539esp_tv_template)
Martin Willi59007582015-06-01 13:44:03 +02003759 }
3760 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003761 .alg = "rmd128",
3762 .test = alg_test_hash,
3763 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003764 .hash = __VECS(rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003765 }
3766 }, {
3767 .alg = "rmd160",
3768 .test = alg_test_hash,
3769 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003770 .hash = __VECS(rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003771 }
3772 }, {
3773 .alg = "rmd256",
3774 .test = alg_test_hash,
3775 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003776 .hash = __VECS(rmd256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003777 }
3778 }, {
3779 .alg = "rmd320",
3780 .test = alg_test_hash,
3781 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003782 .hash = __VECS(rmd320_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003783 }
3784 }, {
Tadeusz Struk946cc462015-06-16 10:31:06 -07003785 .alg = "rsa",
3786 .test = alg_test_akcipher,
3787 .fips_allowed = 1,
3788 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003789 .akcipher = __VECS(rsa_tv_template)
Tadeusz Struk946cc462015-06-16 10:31:06 -07003790 }
3791 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003792 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003793 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003794 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003795 .cipher = __VECS(salsa20_stream_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003796 }
3797 }, {
3798 .alg = "sha1",
3799 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003800 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003801 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003802 .hash = __VECS(sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003803 }
3804 }, {
3805 .alg = "sha224",
3806 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003807 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003808 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003809 .hash = __VECS(sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003810 }
3811 }, {
3812 .alg = "sha256",
3813 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003814 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003815 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003816 .hash = __VECS(sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003817 }
3818 }, {
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303819 .alg = "sha3-224",
3820 .test = alg_test_hash,
3821 .fips_allowed = 1,
3822 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003823 .hash = __VECS(sha3_224_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303824 }
3825 }, {
3826 .alg = "sha3-256",
3827 .test = alg_test_hash,
3828 .fips_allowed = 1,
3829 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003830 .hash = __VECS(sha3_256_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303831 }
3832 }, {
3833 .alg = "sha3-384",
3834 .test = alg_test_hash,
3835 .fips_allowed = 1,
3836 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003837 .hash = __VECS(sha3_384_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303838 }
3839 }, {
3840 .alg = "sha3-512",
3841 .test = alg_test_hash,
3842 .fips_allowed = 1,
3843 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003844 .hash = __VECS(sha3_512_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303845 }
3846 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003847 .alg = "sha384",
3848 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003849 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003850 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003851 .hash = __VECS(sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003852 }
3853 }, {
3854 .alg = "sha512",
3855 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003856 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003857 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003858 .hash = __VECS(sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003859 }
3860 }, {
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03003861 .alg = "sm3",
3862 .test = alg_test_hash,
3863 .suite = {
3864 .hash = __VECS(sm3_tv_template)
3865 }
3866 }, {
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03003867 .alg = "streebog256",
3868 .test = alg_test_hash,
3869 .suite = {
3870 .hash = __VECS(streebog256_tv_template)
3871 }
3872 }, {
3873 .alg = "streebog512",
3874 .test = alg_test_hash,
3875 .suite = {
3876 .hash = __VECS(streebog512_tv_template)
3877 }
3878 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003879 .alg = "tgr128",
3880 .test = alg_test_hash,
3881 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003882 .hash = __VECS(tgr128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003883 }
3884 }, {
3885 .alg = "tgr160",
3886 .test = alg_test_hash,
3887 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003888 .hash = __VECS(tgr160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003889 }
3890 }, {
3891 .alg = "tgr192",
3892 .test = alg_test_hash,
3893 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003894 .hash = __VECS(tgr192_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003895 }
3896 }, {
Eric Biggersed331ad2018-06-18 10:22:39 -07003897 .alg = "vmac64(aes)",
3898 .test = alg_test_hash,
3899 .suite = {
3900 .hash = __VECS(vmac64_aes_tv_template)
3901 }
3902 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003903 .alg = "wp256",
3904 .test = alg_test_hash,
3905 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003906 .hash = __VECS(wp256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003907 }
3908 }, {
3909 .alg = "wp384",
3910 .test = alg_test_hash,
3911 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003912 .hash = __VECS(wp384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003913 }
3914 }, {
3915 .alg = "wp512",
3916 .test = alg_test_hash,
3917 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003918 .hash = __VECS(wp512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003919 }
3920 }, {
3921 .alg = "xcbc(aes)",
3922 .test = alg_test_hash,
3923 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003924 .hash = __VECS(aes_xcbc128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003925 }
3926 }, {
Eric Biggersaa762402018-11-16 17:26:22 -08003927 .alg = "xchacha12",
3928 .test = alg_test_skcipher,
3929 .suite = {
3930 .cipher = __VECS(xchacha12_tv_template)
3931 },
3932 }, {
Eric Biggersde61d7a2018-11-16 17:26:20 -08003933 .alg = "xchacha20",
3934 .test = alg_test_skcipher,
3935 .suite = {
3936 .cipher = __VECS(xchacha20_tv_template)
3937 },
3938 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003939 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003940 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003941 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003942 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003943 .cipher = __VECS(aes_xts_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003944 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003945 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003946 .alg = "xts(camellia)",
3947 .test = alg_test_skcipher,
3948 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003949 .cipher = __VECS(camellia_xts_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003950 }
3951 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003952 .alg = "xts(cast6)",
3953 .test = alg_test_skcipher,
3954 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003955 .cipher = __VECS(cast6_xts_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003956 }
3957 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003958 /* Same as xts(aes) except the key is stored in
3959 * hardware secure memory which we reference by index
3960 */
3961 .alg = "xts(paes)",
3962 .test = alg_test_null,
3963 .fips_allowed = 1,
3964 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003965 .alg = "xts(serpent)",
3966 .test = alg_test_skcipher,
3967 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003968 .cipher = __VECS(serpent_xts_tv_template)
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003969 }
3970 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003971 .alg = "xts(twofish)",
3972 .test = alg_test_skcipher,
3973 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003974 .cipher = __VECS(tf_xts_tv_template)
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003975 }
Giovanni Cabiddua368f432017-04-21 21:54:30 +01003976 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003977 .alg = "xts4096(paes)",
3978 .test = alg_test_null,
3979 .fips_allowed = 1,
3980 }, {
3981 .alg = "xts512(paes)",
3982 .test = alg_test_null,
3983 .fips_allowed = 1,
3984 }, {
Giovanni Cabiddua368f432017-04-21 21:54:30 +01003985 .alg = "zlib-deflate",
3986 .test = alg_test_comp,
3987 .fips_allowed = 1,
3988 .suite = {
3989 .comp = {
3990 .comp = __VECS(zlib_deflate_comp_tv_template),
3991 .decomp = __VECS(zlib_deflate_decomp_tv_template)
3992 }
3993 }
Nick Terrelld28fc3d2018-03-30 12:14:53 -07003994 }, {
3995 .alg = "zstd",
3996 .test = alg_test_comp,
3997 .fips_allowed = 1,
3998 .suite = {
3999 .comp = {
4000 .comp = __VECS(zstd_comp_tv_template),
4001 .decomp = __VECS(zstd_decomp_tv_template)
4002 }
4003 }
Herbert Xuda7f0332008-07-31 17:08:25 +08004004 }
4005};
4006
Eric Biggers3f47a032019-01-31 23:51:43 -08004007static void alg_check_test_descs_order(void)
Jussi Kivilinna57147582013-06-13 17:37:40 +03004008{
4009 int i;
4010
Jussi Kivilinna57147582013-06-13 17:37:40 +03004011 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
4012 int diff = strcmp(alg_test_descs[i - 1].alg,
4013 alg_test_descs[i].alg);
4014
4015 if (WARN_ON(diff > 0)) {
4016 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
4017 alg_test_descs[i - 1].alg,
4018 alg_test_descs[i].alg);
4019 }
4020
4021 if (WARN_ON(diff == 0)) {
4022 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
4023 alg_test_descs[i].alg);
4024 }
4025 }
4026}
4027
Eric Biggers3f47a032019-01-31 23:51:43 -08004028static void alg_check_testvec_configs(void)
4029{
Eric Biggers4e7babba2019-01-31 23:51:46 -08004030 int i;
4031
4032 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++)
4033 WARN_ON(!valid_testvec_config(
4034 &default_cipher_testvec_configs[i]));
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08004035
4036 for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++)
4037 WARN_ON(!valid_testvec_config(
4038 &default_hash_testvec_configs[i]));
Eric Biggers3f47a032019-01-31 23:51:43 -08004039}
4040
4041static void testmgr_onetime_init(void)
4042{
4043 alg_check_test_descs_order();
4044 alg_check_testvec_configs();
Eric Biggers5b2706a2019-01-31 23:51:44 -08004045
4046#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
4047 pr_warn("alg: extra crypto tests enabled. This is intended for developer use only.\n");
4048#endif
Eric Biggers3f47a032019-01-31 23:51:43 -08004049}
4050
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004051static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08004052{
4053 int start = 0;
4054 int end = ARRAY_SIZE(alg_test_descs);
4055
4056 while (start < end) {
4057 int i = (start + end) / 2;
4058 int diff = strcmp(alg_test_descs[i].alg, alg);
4059
4060 if (diff > 0) {
4061 end = i;
4062 continue;
4063 }
4064
4065 if (diff < 0) {
4066 start = i + 1;
4067 continue;
4068 }
4069
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004070 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08004071 }
4072
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004073 return -1;
4074}
4075
4076int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
4077{
4078 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08004079 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08004080 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004081
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +01004082 if (!fips_enabled && notests) {
4083 printk_once(KERN_INFO "alg: self-tests disabled\n");
4084 return 0;
4085 }
4086
Eric Biggers3f47a032019-01-31 23:51:43 -08004087 DO_ONCE(testmgr_onetime_init);
Jussi Kivilinna57147582013-06-13 17:37:40 +03004088
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004089 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
4090 char nalg[CRYPTO_MAX_ALG_NAME];
4091
4092 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
4093 sizeof(nalg))
4094 return -ENAMETOOLONG;
4095
4096 i = alg_find_test(nalg);
4097 if (i < 0)
4098 goto notest;
4099
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004100 if (fips_enabled && !alg_test_descs[i].fips_allowed)
4101 goto non_fips_alg;
4102
Jarod Wilson941fb322009-05-04 19:49:23 +08004103 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
4104 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004105 }
4106
4107 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08004108 j = alg_find_test(driver);
4109 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004110 goto notest;
4111
Herbert Xua68f6612009-07-02 16:32:12 +08004112 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
4113 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004114 goto non_fips_alg;
4115
Herbert Xua68f6612009-07-02 16:32:12 +08004116 rc = 0;
4117 if (i >= 0)
4118 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
4119 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03004120 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08004121 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
4122 type, mask);
4123
Jarod Wilson941fb322009-05-04 19:49:23 +08004124test_done:
Eric Biggerseda69b02019-03-31 13:09:14 -07004125 if (rc && (fips_enabled || panic_on_fail))
4126 panic("alg: self-tests for %s (%s) failed in %s mode!\n",
4127 driver, alg, fips_enabled ? "fips" : "panic_on_fail");
Neil Hormand12d6b62008-10-12 20:36:51 +08004128
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004129 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09004130 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004131
Neil Hormand12d6b62008-10-12 20:36:51 +08004132 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004133
4134notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08004135 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
4136 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004137non_fips_alg:
4138 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08004139}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004140
Herbert Xu326a6342010-08-06 09:40:28 +08004141#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004142
Herbert Xuda7f0332008-07-31 17:08:25 +08004143EXPORT_SYMBOL_GPL(alg_test);