blob: 2c2ddebb48d3772af3e583bde4591c1e24557de3 [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 Biggers5b2706a2019-01-31 23:51:44 -080048#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
49static bool noextratests;
50module_param(noextratests, bool, 0644);
51MODULE_PARM_DESC(noextratests, "disable expensive crypto self-tests");
52
53static unsigned int fuzz_iterations = 100;
54module_param(fuzz_iterations, uint, 0644);
55MODULE_PARM_DESC(fuzz_iterations, "number of fuzz test iterations");
Eric Biggersb55e1a32019-03-12 22:12:47 -070056
57DEFINE_PER_CPU(bool, crypto_simd_disabled_for_test);
58EXPORT_PER_CPU_SYMBOL_GPL(crypto_simd_disabled_for_test);
Eric Biggers5b2706a2019-01-31 23:51:44 -080059#endif
60
Herbert Xu326a6342010-08-06 09:40:28 +080061#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
Alexander Shishkin0b767f92010-06-03 20:53:43 +100062
63/* a perfect nop */
64int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
65{
66 return 0;
67}
68
69#else
70
Herbert Xuda7f0332008-07-31 17:08:25 +080071#include "testmgr.h"
72
73/*
74 * Need slab memory for testing (size in number of pages).
75 */
76#define XBUFSIZE 8
77
78/*
Herbert Xuda7f0332008-07-31 17:08:25 +080079* Used by test_cipher()
80*/
81#define ENCRYPT 1
82#define DECRYPT 0
83
Herbert Xuda7f0332008-07-31 17:08:25 +080084struct aead_test_suite {
Eric Biggersa0d608ee2019-01-13 15:32:28 -080085 const struct aead_testvec *vecs;
86 unsigned int count;
Herbert Xuda7f0332008-07-31 17:08:25 +080087};
88
89struct cipher_test_suite {
Eric Biggers92a4c9f2018-05-20 22:50:29 -070090 const struct cipher_testvec *vecs;
91 unsigned int count;
Herbert Xuda7f0332008-07-31 17:08:25 +080092};
93
94struct comp_test_suite {
95 struct {
Eric Biggersb13b1e02017-02-24 15:46:59 -080096 const struct comp_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +080097 unsigned int count;
98 } comp, decomp;
99};
100
101struct hash_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800102 const struct hash_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +0800103 unsigned int count;
104};
105
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800106struct cprng_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800107 const struct cprng_testvec *vecs;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800108 unsigned int count;
109};
110
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200111struct drbg_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800112 const struct drbg_testvec *vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200113 unsigned int count;
114};
115
Tadeusz Struk946cc462015-06-16 10:31:06 -0700116struct akcipher_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800117 const struct akcipher_testvec *vecs;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700118 unsigned int count;
119};
120
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100121struct kpp_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800122 const struct kpp_testvec *vecs;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100123 unsigned int count;
124};
125
Herbert Xuda7f0332008-07-31 17:08:25 +0800126struct alg_test_desc {
127 const char *alg;
128 int (*test)(const struct alg_test_desc *desc, const char *driver,
129 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000130 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800131
132 union {
133 struct aead_test_suite aead;
134 struct cipher_test_suite cipher;
135 struct comp_test_suite comp;
136 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800137 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200138 struct drbg_test_suite drbg;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700139 struct akcipher_test_suite akcipher;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100140 struct kpp_test_suite kpp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800141 } suite;
142};
143
Herbert Xuda7f0332008-07-31 17:08:25 +0800144static void hexdump(unsigned char *buf, unsigned int len)
145{
146 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
147 16, 1,
148 buf, len, false);
149}
150
Eric Biggers3f47a032019-01-31 23:51:43 -0800151static int __testmgr_alloc_buf(char *buf[XBUFSIZE], int order)
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800152{
153 int i;
154
155 for (i = 0; i < XBUFSIZE; i++) {
Eric Biggers3f47a032019-01-31 23:51:43 -0800156 buf[i] = (char *)__get_free_pages(GFP_KERNEL, order);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800157 if (!buf[i])
158 goto err_free_buf;
159 }
160
161 return 0;
162
163err_free_buf:
164 while (i-- > 0)
Eric Biggers3f47a032019-01-31 23:51:43 -0800165 free_pages((unsigned long)buf[i], order);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800166
167 return -ENOMEM;
168}
169
Eric Biggers3f47a032019-01-31 23:51:43 -0800170static int testmgr_alloc_buf(char *buf[XBUFSIZE])
171{
172 return __testmgr_alloc_buf(buf, 0);
173}
174
175static void __testmgr_free_buf(char *buf[XBUFSIZE], int order)
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800176{
177 int i;
178
179 for (i = 0; i < XBUFSIZE; i++)
Eric Biggers3f47a032019-01-31 23:51:43 -0800180 free_pages((unsigned long)buf[i], order);
181}
182
183static void testmgr_free_buf(char *buf[XBUFSIZE])
184{
185 __testmgr_free_buf(buf, 0);
186}
187
188#define TESTMGR_POISON_BYTE 0xfe
189#define TESTMGR_POISON_LEN 16
190
191static inline void testmgr_poison(void *addr, size_t len)
192{
193 memset(addr, TESTMGR_POISON_BYTE, len);
194}
195
196/* Is the memory region still fully poisoned? */
197static inline bool testmgr_is_poison(const void *addr, size_t len)
198{
199 return memchr_inv(addr, TESTMGR_POISON_BYTE, len) == NULL;
200}
201
202/* flush type for hash algorithms */
203enum flush_type {
204 /* merge with update of previous buffer(s) */
205 FLUSH_TYPE_NONE = 0,
206
207 /* update with previous buffer(s) before doing this one */
208 FLUSH_TYPE_FLUSH,
209
210 /* likewise, but also export and re-import the intermediate state */
211 FLUSH_TYPE_REIMPORT,
212};
213
214/* finalization function for hash algorithms */
215enum finalization_type {
216 FINALIZATION_TYPE_FINAL, /* use final() */
217 FINALIZATION_TYPE_FINUP, /* use finup() */
218 FINALIZATION_TYPE_DIGEST, /* use digest() */
219};
220
221#define TEST_SG_TOTAL 10000
222
223/**
224 * struct test_sg_division - description of a scatterlist entry
225 *
226 * This struct describes one entry of a scatterlist being constructed to check a
227 * crypto test vector.
228 *
229 * @proportion_of_total: length of this chunk relative to the total length,
230 * given as a proportion out of TEST_SG_TOTAL so that it
231 * scales to fit any test vector
232 * @offset: byte offset into a 2-page buffer at which this chunk will start
233 * @offset_relative_to_alignmask: if true, add the algorithm's alignmask to the
234 * @offset
235 * @flush_type: for hashes, whether an update() should be done now vs.
236 * continuing to accumulate data
Eric Biggers65707372019-03-12 22:12:52 -0700237 * @nosimd: if doing the pending update(), do it with SIMD disabled?
Eric Biggers3f47a032019-01-31 23:51:43 -0800238 */
239struct test_sg_division {
240 unsigned int proportion_of_total;
241 unsigned int offset;
242 bool offset_relative_to_alignmask;
243 enum flush_type flush_type;
Eric Biggers65707372019-03-12 22:12:52 -0700244 bool nosimd;
Eric Biggers3f47a032019-01-31 23:51:43 -0800245};
246
247/**
248 * struct testvec_config - configuration for testing a crypto test vector
249 *
250 * This struct describes the data layout and other parameters with which each
251 * crypto test vector can be tested.
252 *
253 * @name: name of this config, logged for debugging purposes if a test fails
254 * @inplace: operate on the data in-place, if applicable for the algorithm type?
255 * @req_flags: extra request_flags, e.g. CRYPTO_TFM_REQ_MAY_SLEEP
256 * @src_divs: description of how to arrange the source scatterlist
257 * @dst_divs: description of how to arrange the dst scatterlist, if applicable
258 * for the algorithm type. Defaults to @src_divs if unset.
259 * @iv_offset: misalignment of the IV in the range [0..MAX_ALGAPI_ALIGNMASK+1],
260 * where 0 is aligned to a 2*(MAX_ALGAPI_ALIGNMASK+1) byte boundary
261 * @iv_offset_relative_to_alignmask: if true, add the algorithm's alignmask to
262 * the @iv_offset
263 * @finalization_type: what finalization function to use for hashes
Eric Biggers65707372019-03-12 22:12:52 -0700264 * @nosimd: execute with SIMD disabled? Requires !CRYPTO_TFM_REQ_MAY_SLEEP.
Eric Biggers3f47a032019-01-31 23:51:43 -0800265 */
266struct testvec_config {
267 const char *name;
268 bool inplace;
269 u32 req_flags;
270 struct test_sg_division src_divs[XBUFSIZE];
271 struct test_sg_division dst_divs[XBUFSIZE];
272 unsigned int iv_offset;
273 bool iv_offset_relative_to_alignmask;
274 enum finalization_type finalization_type;
Eric Biggers65707372019-03-12 22:12:52 -0700275 bool nosimd;
Eric Biggers3f47a032019-01-31 23:51:43 -0800276};
277
278#define TESTVEC_CONFIG_NAMELEN 192
279
Eric Biggers4e7babba2019-01-31 23:51:46 -0800280/*
281 * The following are the lists of testvec_configs to test for each algorithm
282 * type when the basic crypto self-tests are enabled, i.e. when
283 * CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is unset. They aim to provide good test
284 * coverage, while keeping the test time much shorter than the full fuzz tests
285 * so that the basic tests can be enabled in a wider range of circumstances.
286 */
287
288/* Configs for skciphers and aeads */
289static const struct testvec_config default_cipher_testvec_configs[] = {
290 {
291 .name = "in-place",
292 .inplace = true,
293 .src_divs = { { .proportion_of_total = 10000 } },
294 }, {
295 .name = "out-of-place",
296 .src_divs = { { .proportion_of_total = 10000 } },
297 }, {
298 .name = "unaligned buffer, offset=1",
299 .src_divs = { { .proportion_of_total = 10000, .offset = 1 } },
300 .iv_offset = 1,
301 }, {
302 .name = "buffer aligned only to alignmask",
303 .src_divs = {
304 {
305 .proportion_of_total = 10000,
306 .offset = 1,
307 .offset_relative_to_alignmask = true,
308 },
309 },
310 .iv_offset = 1,
311 .iv_offset_relative_to_alignmask = true,
312 }, {
313 .name = "two even aligned splits",
314 .src_divs = {
315 { .proportion_of_total = 5000 },
316 { .proportion_of_total = 5000 },
317 },
318 }, {
319 .name = "uneven misaligned splits, may sleep",
320 .req_flags = CRYPTO_TFM_REQ_MAY_SLEEP,
321 .src_divs = {
322 { .proportion_of_total = 1900, .offset = 33 },
323 { .proportion_of_total = 3300, .offset = 7 },
324 { .proportion_of_total = 4800, .offset = 18 },
325 },
326 .iv_offset = 3,
327 }, {
328 .name = "misaligned splits crossing pages, inplace",
329 .inplace = true,
330 .src_divs = {
331 {
332 .proportion_of_total = 7500,
333 .offset = PAGE_SIZE - 32
334 }, {
335 .proportion_of_total = 2500,
336 .offset = PAGE_SIZE - 7
337 },
338 },
339 }
340};
341
Eric Biggers4cc2dcf2019-01-31 23:51:48 -0800342static const struct testvec_config default_hash_testvec_configs[] = {
343 {
344 .name = "init+update+final aligned buffer",
345 .src_divs = { { .proportion_of_total = 10000 } },
346 .finalization_type = FINALIZATION_TYPE_FINAL,
347 }, {
348 .name = "init+finup aligned buffer",
349 .src_divs = { { .proportion_of_total = 10000 } },
350 .finalization_type = FINALIZATION_TYPE_FINUP,
351 }, {
352 .name = "digest aligned buffer",
353 .src_divs = { { .proportion_of_total = 10000 } },
354 .finalization_type = FINALIZATION_TYPE_DIGEST,
355 }, {
356 .name = "init+update+final misaligned buffer",
357 .src_divs = { { .proportion_of_total = 10000, .offset = 1 } },
358 .finalization_type = FINALIZATION_TYPE_FINAL,
359 }, {
360 .name = "digest buffer aligned only to alignmask",
361 .src_divs = {
362 {
363 .proportion_of_total = 10000,
364 .offset = 1,
365 .offset_relative_to_alignmask = true,
366 },
367 },
368 .finalization_type = FINALIZATION_TYPE_DIGEST,
369 }, {
370 .name = "init+update+update+final two even splits",
371 .src_divs = {
372 { .proportion_of_total = 5000 },
373 {
374 .proportion_of_total = 5000,
375 .flush_type = FLUSH_TYPE_FLUSH,
376 },
377 },
378 .finalization_type = FINALIZATION_TYPE_FINAL,
379 }, {
380 .name = "digest uneven misaligned splits, may sleep",
381 .req_flags = CRYPTO_TFM_REQ_MAY_SLEEP,
382 .src_divs = {
383 { .proportion_of_total = 1900, .offset = 33 },
384 { .proportion_of_total = 3300, .offset = 7 },
385 { .proportion_of_total = 4800, .offset = 18 },
386 },
387 .finalization_type = FINALIZATION_TYPE_DIGEST,
388 }, {
389 .name = "digest misaligned splits crossing pages",
390 .src_divs = {
391 {
392 .proportion_of_total = 7500,
393 .offset = PAGE_SIZE - 32,
394 }, {
395 .proportion_of_total = 2500,
396 .offset = PAGE_SIZE - 7,
397 },
398 },
399 .finalization_type = FINALIZATION_TYPE_DIGEST,
400 }, {
401 .name = "import/export",
402 .src_divs = {
403 {
404 .proportion_of_total = 6500,
405 .flush_type = FLUSH_TYPE_REIMPORT,
406 }, {
407 .proportion_of_total = 3500,
408 .flush_type = FLUSH_TYPE_REIMPORT,
409 },
410 },
411 .finalization_type = FINALIZATION_TYPE_FINAL,
412 }
413};
414
Eric Biggers3f47a032019-01-31 23:51:43 -0800415static unsigned int count_test_sg_divisions(const struct test_sg_division *divs)
416{
417 unsigned int remaining = TEST_SG_TOTAL;
418 unsigned int ndivs = 0;
419
420 do {
421 remaining -= divs[ndivs++].proportion_of_total;
422 } while (remaining);
423
424 return ndivs;
425}
426
Eric Biggers65707372019-03-12 22:12:52 -0700427#define SGDIVS_HAVE_FLUSHES BIT(0)
428#define SGDIVS_HAVE_NOSIMD BIT(1)
429
Eric Biggers3f47a032019-01-31 23:51:43 -0800430static bool valid_sg_divisions(const struct test_sg_division *divs,
Eric Biggers65707372019-03-12 22:12:52 -0700431 unsigned int count, int *flags_ret)
Eric Biggers3f47a032019-01-31 23:51:43 -0800432{
433 unsigned int total = 0;
434 unsigned int i;
435
436 for (i = 0; i < count && total != TEST_SG_TOTAL; i++) {
437 if (divs[i].proportion_of_total <= 0 ||
438 divs[i].proportion_of_total > TEST_SG_TOTAL - total)
439 return false;
440 total += divs[i].proportion_of_total;
441 if (divs[i].flush_type != FLUSH_TYPE_NONE)
Eric Biggers65707372019-03-12 22:12:52 -0700442 *flags_ret |= SGDIVS_HAVE_FLUSHES;
443 if (divs[i].nosimd)
444 *flags_ret |= SGDIVS_HAVE_NOSIMD;
Eric Biggers3f47a032019-01-31 23:51:43 -0800445 }
446 return total == TEST_SG_TOTAL &&
447 memchr_inv(&divs[i], 0, (count - i) * sizeof(divs[0])) == NULL;
448}
449
450/*
451 * Check whether the given testvec_config is valid. This isn't strictly needed
452 * since every testvec_config should be valid, but check anyway so that people
453 * don't unknowingly add broken configs that don't do what they wanted.
454 */
455static bool valid_testvec_config(const struct testvec_config *cfg)
456{
Eric Biggers65707372019-03-12 22:12:52 -0700457 int flags = 0;
Eric Biggers3f47a032019-01-31 23:51:43 -0800458
459 if (cfg->name == NULL)
460 return false;
461
462 if (!valid_sg_divisions(cfg->src_divs, ARRAY_SIZE(cfg->src_divs),
Eric Biggers65707372019-03-12 22:12:52 -0700463 &flags))
Eric Biggers3f47a032019-01-31 23:51:43 -0800464 return false;
465
466 if (cfg->dst_divs[0].proportion_of_total) {
467 if (!valid_sg_divisions(cfg->dst_divs,
Eric Biggers65707372019-03-12 22:12:52 -0700468 ARRAY_SIZE(cfg->dst_divs), &flags))
Eric Biggers3f47a032019-01-31 23:51:43 -0800469 return false;
470 } else {
471 if (memchr_inv(cfg->dst_divs, 0, sizeof(cfg->dst_divs)))
472 return false;
473 /* defaults to dst_divs=src_divs */
474 }
475
476 if (cfg->iv_offset +
477 (cfg->iv_offset_relative_to_alignmask ? MAX_ALGAPI_ALIGNMASK : 0) >
478 MAX_ALGAPI_ALIGNMASK + 1)
479 return false;
480
Eric Biggers65707372019-03-12 22:12:52 -0700481 if ((flags & (SGDIVS_HAVE_FLUSHES | SGDIVS_HAVE_NOSIMD)) &&
482 cfg->finalization_type == FINALIZATION_TYPE_DIGEST)
483 return false;
484
485 if ((cfg->nosimd || (flags & SGDIVS_HAVE_NOSIMD)) &&
486 (cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP))
Eric Biggers3f47a032019-01-31 23:51:43 -0800487 return false;
488
489 return true;
490}
491
492struct test_sglist {
493 char *bufs[XBUFSIZE];
494 struct scatterlist sgl[XBUFSIZE];
495 struct scatterlist sgl_saved[XBUFSIZE];
496 struct scatterlist *sgl_ptr;
497 unsigned int nents;
498};
499
500static int init_test_sglist(struct test_sglist *tsgl)
501{
502 return __testmgr_alloc_buf(tsgl->bufs, 1 /* two pages per buffer */);
503}
504
505static void destroy_test_sglist(struct test_sglist *tsgl)
506{
507 return __testmgr_free_buf(tsgl->bufs, 1 /* two pages per buffer */);
508}
509
510/**
511 * build_test_sglist() - build a scatterlist for a crypto test
512 *
513 * @tsgl: the scatterlist to build. @tsgl->bufs[] contains an array of 2-page
514 * buffers which the scatterlist @tsgl->sgl[] will be made to point into.
515 * @divs: the layout specification on which the scatterlist will be based
516 * @alignmask: the algorithm's alignmask
517 * @total_len: the total length of the scatterlist to build in bytes
518 * @data: if non-NULL, the buffers will be filled with this data until it ends.
519 * Otherwise the buffers will be poisoned. In both cases, some bytes
520 * past the end of each buffer will be poisoned to help detect overruns.
521 * @out_divs: if non-NULL, the test_sg_division to which each scatterlist entry
522 * corresponds will be returned here. This will match @divs except
523 * that divisions resolving to a length of 0 are omitted as they are
524 * not included in the scatterlist.
525 *
526 * Return: 0 or a -errno value
527 */
528static int build_test_sglist(struct test_sglist *tsgl,
529 const struct test_sg_division *divs,
530 const unsigned int alignmask,
531 const unsigned int total_len,
532 struct iov_iter *data,
533 const struct test_sg_division *out_divs[XBUFSIZE])
534{
535 struct {
536 const struct test_sg_division *div;
537 size_t length;
538 } partitions[XBUFSIZE];
539 const unsigned int ndivs = count_test_sg_divisions(divs);
540 unsigned int len_remaining = total_len;
541 unsigned int i;
542
543 BUILD_BUG_ON(ARRAY_SIZE(partitions) != ARRAY_SIZE(tsgl->sgl));
544 if (WARN_ON(ndivs > ARRAY_SIZE(partitions)))
545 return -EINVAL;
546
547 /* Calculate the (div, length) pairs */
548 tsgl->nents = 0;
549 for (i = 0; i < ndivs; i++) {
550 unsigned int len_this_sg =
551 min(len_remaining,
552 (total_len * divs[i].proportion_of_total +
553 TEST_SG_TOTAL / 2) / TEST_SG_TOTAL);
554
555 if (len_this_sg != 0) {
556 partitions[tsgl->nents].div = &divs[i];
557 partitions[tsgl->nents].length = len_this_sg;
558 tsgl->nents++;
559 len_remaining -= len_this_sg;
560 }
561 }
562 if (tsgl->nents == 0) {
563 partitions[tsgl->nents].div = &divs[0];
564 partitions[tsgl->nents].length = 0;
565 tsgl->nents++;
566 }
567 partitions[tsgl->nents - 1].length += len_remaining;
568
569 /* Set up the sgl entries and fill the data or poison */
570 sg_init_table(tsgl->sgl, tsgl->nents);
571 for (i = 0; i < tsgl->nents; i++) {
572 unsigned int offset = partitions[i].div->offset;
573 void *addr;
574
575 if (partitions[i].div->offset_relative_to_alignmask)
576 offset += alignmask;
577
578 while (offset + partitions[i].length + TESTMGR_POISON_LEN >
579 2 * PAGE_SIZE) {
580 if (WARN_ON(offset <= 0))
581 return -EINVAL;
582 offset /= 2;
583 }
584
585 addr = &tsgl->bufs[i][offset];
586 sg_set_buf(&tsgl->sgl[i], addr, partitions[i].length);
587
588 if (out_divs)
589 out_divs[i] = partitions[i].div;
590
591 if (data) {
592 size_t copy_len, copied;
593
594 copy_len = min(partitions[i].length, data->count);
595 copied = copy_from_iter(addr, copy_len, data);
596 if (WARN_ON(copied != copy_len))
597 return -EINVAL;
598 testmgr_poison(addr + copy_len, partitions[i].length +
599 TESTMGR_POISON_LEN - copy_len);
600 } else {
601 testmgr_poison(addr, partitions[i].length +
602 TESTMGR_POISON_LEN);
603 }
604 }
605
606 sg_mark_end(&tsgl->sgl[tsgl->nents - 1]);
607 tsgl->sgl_ptr = tsgl->sgl;
608 memcpy(tsgl->sgl_saved, tsgl->sgl, tsgl->nents * sizeof(tsgl->sgl[0]));
609 return 0;
610}
611
612/*
613 * Verify that a scatterlist crypto operation produced the correct output.
614 *
615 * @tsgl: scatterlist containing the actual output
616 * @expected_output: buffer containing the expected output
617 * @len_to_check: length of @expected_output in bytes
618 * @unchecked_prefix_len: number of ignored bytes in @tsgl prior to real result
619 * @check_poison: verify that the poison bytes after each chunk are intact?
620 *
621 * Return: 0 if correct, -EINVAL if incorrect, -EOVERFLOW if buffer overrun.
622 */
623static int verify_correct_output(const struct test_sglist *tsgl,
624 const char *expected_output,
625 unsigned int len_to_check,
626 unsigned int unchecked_prefix_len,
627 bool check_poison)
628{
629 unsigned int i;
630
631 for (i = 0; i < tsgl->nents; i++) {
632 struct scatterlist *sg = &tsgl->sgl_ptr[i];
633 unsigned int len = sg->length;
634 unsigned int offset = sg->offset;
635 const char *actual_output;
636
637 if (unchecked_prefix_len) {
638 if (unchecked_prefix_len >= len) {
639 unchecked_prefix_len -= len;
640 continue;
641 }
642 offset += unchecked_prefix_len;
643 len -= unchecked_prefix_len;
644 unchecked_prefix_len = 0;
645 }
646 len = min(len, len_to_check);
647 actual_output = page_address(sg_page(sg)) + offset;
648 if (memcmp(expected_output, actual_output, len) != 0)
649 return -EINVAL;
650 if (check_poison &&
651 !testmgr_is_poison(actual_output + len, TESTMGR_POISON_LEN))
652 return -EOVERFLOW;
653 len_to_check -= len;
654 expected_output += len;
655 }
656 if (WARN_ON(len_to_check != 0))
657 return -EINVAL;
658 return 0;
659}
660
661static bool is_test_sglist_corrupted(const struct test_sglist *tsgl)
662{
663 unsigned int i;
664
665 for (i = 0; i < tsgl->nents; i++) {
666 if (tsgl->sgl[i].page_link != tsgl->sgl_saved[i].page_link)
667 return true;
668 if (tsgl->sgl[i].offset != tsgl->sgl_saved[i].offset)
669 return true;
670 if (tsgl->sgl[i].length != tsgl->sgl_saved[i].length)
671 return true;
672 }
673 return false;
674}
675
676struct cipher_test_sglists {
677 struct test_sglist src;
678 struct test_sglist dst;
679};
680
681static struct cipher_test_sglists *alloc_cipher_test_sglists(void)
682{
683 struct cipher_test_sglists *tsgls;
684
685 tsgls = kmalloc(sizeof(*tsgls), GFP_KERNEL);
686 if (!tsgls)
687 return NULL;
688
689 if (init_test_sglist(&tsgls->src) != 0)
690 goto fail_kfree;
691 if (init_test_sglist(&tsgls->dst) != 0)
692 goto fail_destroy_src;
693
694 return tsgls;
695
696fail_destroy_src:
697 destroy_test_sglist(&tsgls->src);
698fail_kfree:
699 kfree(tsgls);
700 return NULL;
701}
702
703static void free_cipher_test_sglists(struct cipher_test_sglists *tsgls)
704{
705 if (tsgls) {
706 destroy_test_sglist(&tsgls->src);
707 destroy_test_sglist(&tsgls->dst);
708 kfree(tsgls);
709 }
710}
711
712/* Build the src and dst scatterlists for an skcipher or AEAD test */
713static int build_cipher_test_sglists(struct cipher_test_sglists *tsgls,
714 const struct testvec_config *cfg,
715 unsigned int alignmask,
716 unsigned int src_total_len,
717 unsigned int dst_total_len,
718 const struct kvec *inputs,
719 unsigned int nr_inputs)
720{
721 struct iov_iter input;
722 int err;
723
724 iov_iter_kvec(&input, WRITE, inputs, nr_inputs, src_total_len);
725 err = build_test_sglist(&tsgls->src, cfg->src_divs, alignmask,
726 cfg->inplace ?
727 max(dst_total_len, src_total_len) :
728 src_total_len,
729 &input, NULL);
730 if (err)
731 return err;
732
733 if (cfg->inplace) {
734 tsgls->dst.sgl_ptr = tsgls->src.sgl;
735 tsgls->dst.nents = tsgls->src.nents;
736 return 0;
737 }
738 return build_test_sglist(&tsgls->dst,
739 cfg->dst_divs[0].proportion_of_total ?
740 cfg->dst_divs : cfg->src_divs,
741 alignmask, dst_total_len, NULL, NULL);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800742}
743
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800744#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
745static char *generate_random_sgl_divisions(struct test_sg_division *divs,
746 size_t max_divs, char *p, char *end,
Eric Biggers65707372019-03-12 22:12:52 -0700747 bool gen_flushes, u32 req_flags)
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800748{
749 struct test_sg_division *div = divs;
750 unsigned int remaining = TEST_SG_TOTAL;
751
752 do {
753 unsigned int this_len;
Eric Biggers65707372019-03-12 22:12:52 -0700754 const char *flushtype_str;
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800755
756 if (div == &divs[max_divs - 1] || prandom_u32() % 2 == 0)
757 this_len = remaining;
758 else
759 this_len = 1 + (prandom_u32() % remaining);
760 div->proportion_of_total = this_len;
761
762 if (prandom_u32() % 4 == 0)
763 div->offset = (PAGE_SIZE - 128) + (prandom_u32() % 128);
764 else if (prandom_u32() % 2 == 0)
765 div->offset = prandom_u32() % 32;
766 else
767 div->offset = prandom_u32() % PAGE_SIZE;
768 if (prandom_u32() % 8 == 0)
769 div->offset_relative_to_alignmask = true;
770
771 div->flush_type = FLUSH_TYPE_NONE;
772 if (gen_flushes) {
773 switch (prandom_u32() % 4) {
774 case 0:
775 div->flush_type = FLUSH_TYPE_REIMPORT;
776 break;
777 case 1:
778 div->flush_type = FLUSH_TYPE_FLUSH;
779 break;
780 }
781 }
782
Eric Biggers65707372019-03-12 22:12:52 -0700783 if (div->flush_type != FLUSH_TYPE_NONE &&
784 !(req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) &&
785 prandom_u32() % 2 == 0)
786 div->nosimd = true;
787
788 switch (div->flush_type) {
789 case FLUSH_TYPE_FLUSH:
790 if (div->nosimd)
791 flushtype_str = "<flush,nosimd>";
792 else
793 flushtype_str = "<flush>";
794 break;
795 case FLUSH_TYPE_REIMPORT:
796 if (div->nosimd)
797 flushtype_str = "<reimport,nosimd>";
798 else
799 flushtype_str = "<reimport>";
800 break;
801 default:
802 flushtype_str = "";
803 break;
804 }
805
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800806 BUILD_BUG_ON(TEST_SG_TOTAL != 10000); /* for "%u.%u%%" */
Eric Biggers65707372019-03-12 22:12:52 -0700807 p += scnprintf(p, end - p, "%s%u.%u%%@%s+%u%s", flushtype_str,
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800808 this_len / 100, this_len % 100,
809 div->offset_relative_to_alignmask ?
810 "alignmask" : "",
811 div->offset, this_len == remaining ? "" : ", ");
812 remaining -= this_len;
813 div++;
814 } while (remaining);
815
816 return p;
817}
818
819/* Generate a random testvec_config for fuzz testing */
820static void generate_random_testvec_config(struct testvec_config *cfg,
821 char *name, size_t max_namelen)
822{
823 char *p = name;
824 char * const end = name + max_namelen;
825
826 memset(cfg, 0, sizeof(*cfg));
827
828 cfg->name = name;
829
830 p += scnprintf(p, end - p, "random:");
831
832 if (prandom_u32() % 2 == 0) {
833 cfg->inplace = true;
834 p += scnprintf(p, end - p, " inplace");
835 }
836
837 if (prandom_u32() % 2 == 0) {
838 cfg->req_flags |= CRYPTO_TFM_REQ_MAY_SLEEP;
839 p += scnprintf(p, end - p, " may_sleep");
840 }
841
842 switch (prandom_u32() % 4) {
843 case 0:
844 cfg->finalization_type = FINALIZATION_TYPE_FINAL;
845 p += scnprintf(p, end - p, " use_final");
846 break;
847 case 1:
848 cfg->finalization_type = FINALIZATION_TYPE_FINUP;
849 p += scnprintf(p, end - p, " use_finup");
850 break;
851 default:
852 cfg->finalization_type = FINALIZATION_TYPE_DIGEST;
853 p += scnprintf(p, end - p, " use_digest");
854 break;
855 }
856
Eric Biggers65707372019-03-12 22:12:52 -0700857 if (!(cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) &&
858 prandom_u32() % 2 == 0) {
859 cfg->nosimd = true;
860 p += scnprintf(p, end - p, " nosimd");
861 }
862
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800863 p += scnprintf(p, end - p, " src_divs=[");
864 p = generate_random_sgl_divisions(cfg->src_divs,
865 ARRAY_SIZE(cfg->src_divs), p, end,
866 (cfg->finalization_type !=
Eric Biggers65707372019-03-12 22:12:52 -0700867 FINALIZATION_TYPE_DIGEST),
868 cfg->req_flags);
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800869 p += scnprintf(p, end - p, "]");
870
871 if (!cfg->inplace && prandom_u32() % 2 == 0) {
872 p += scnprintf(p, end - p, " dst_divs=[");
873 p = generate_random_sgl_divisions(cfg->dst_divs,
874 ARRAY_SIZE(cfg->dst_divs),
Eric Biggers65707372019-03-12 22:12:52 -0700875 p, end, false,
876 cfg->req_flags);
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800877 p += scnprintf(p, end - p, "]");
878 }
879
880 if (prandom_u32() % 2 == 0) {
881 cfg->iv_offset = 1 + (prandom_u32() % MAX_ALGAPI_ALIGNMASK);
882 p += scnprintf(p, end - p, " iv_offset=%u", cfg->iv_offset);
883 }
884
885 WARN_ON_ONCE(!valid_testvec_config(cfg));
886}
Eric Biggersb55e1a32019-03-12 22:12:47 -0700887
888static void crypto_disable_simd_for_test(void)
889{
890 preempt_disable();
891 __this_cpu_write(crypto_simd_disabled_for_test, true);
892}
893
894static void crypto_reenable_simd_for_test(void)
895{
896 __this_cpu_write(crypto_simd_disabled_for_test, false);
897 preempt_enable();
898}
899#else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
900static void crypto_disable_simd_for_test(void)
901{
902}
903
904static void crypto_reenable_simd_for_test(void)
905{
906}
907#endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800908
Eric Biggers65707372019-03-12 22:12:52 -0700909static int do_ahash_op(int (*op)(struct ahash_request *req),
910 struct ahash_request *req,
911 struct crypto_wait *wait, bool nosimd)
912{
913 int err;
914
915 if (nosimd)
916 crypto_disable_simd_for_test();
917
918 err = op(req);
919
920 if (nosimd)
921 crypto_reenable_simd_for_test();
922
923 return crypto_wait_req(err, wait);
924}
925
Eric Biggers4cc2dcf2019-01-31 23:51:48 -0800926static int check_nonfinal_hash_op(const char *op, int err,
927 u8 *result, unsigned int digestsize,
928 const char *driver, unsigned int vec_num,
929 const struct testvec_config *cfg)
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100930{
Eric Biggers4cc2dcf2019-01-31 23:51:48 -0800931 if (err) {
932 pr_err("alg: hash: %s %s() failed with err %d on test vector %u, cfg=\"%s\"\n",
933 driver, op, err, vec_num, cfg->name);
934 return err;
935 }
936 if (!testmgr_is_poison(result, digestsize)) {
937 pr_err("alg: hash: %s %s() used result buffer on test vector %u, cfg=\"%s\"\n",
938 driver, op, vec_num, cfg->name);
939 return -EINVAL;
940 }
941 return 0;
942}
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100943
Eric Biggers4cc2dcf2019-01-31 23:51:48 -0800944static int test_hash_vec_cfg(const char *driver,
945 const struct hash_testvec *vec,
946 unsigned int vec_num,
947 const struct testvec_config *cfg,
948 struct ahash_request *req,
949 struct test_sglist *tsgl,
950 u8 *hashstate)
951{
952 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
953 const unsigned int alignmask = crypto_ahash_alignmask(tfm);
954 const unsigned int digestsize = crypto_ahash_digestsize(tfm);
955 const unsigned int statesize = crypto_ahash_statesize(tfm);
956 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
957 const struct test_sg_division *divs[XBUFSIZE];
958 DECLARE_CRYPTO_WAIT(wait);
959 struct kvec _input;
960 struct iov_iter input;
961 unsigned int i;
962 struct scatterlist *pending_sgl;
963 unsigned int pending_len;
964 u8 result[HASH_MAX_DIGESTSIZE + TESTMGR_POISON_LEN];
965 int err;
966
967 /* Set the key, if specified */
968 if (vec->ksize) {
969 err = crypto_ahash_setkey(tfm, vec->key, vec->ksize);
970 if (err) {
971 pr_err("alg: hash: %s setkey failed with err %d on test vector %u; flags=%#x\n",
972 driver, err, vec_num,
973 crypto_ahash_get_flags(tfm));
974 return err;
975 }
976 }
977
978 /* Build the scatterlist for the source data */
979 _input.iov_base = (void *)vec->plaintext;
980 _input.iov_len = vec->psize;
981 iov_iter_kvec(&input, WRITE, &_input, 1, vec->psize);
982 err = build_test_sglist(tsgl, cfg->src_divs, alignmask, vec->psize,
983 &input, divs);
984 if (err) {
985 pr_err("alg: hash: %s: error preparing scatterlist for test vector %u, cfg=\"%s\"\n",
986 driver, vec_num, cfg->name);
987 return err;
988 }
989
990 /* Do the actual hashing */
991
992 testmgr_poison(req->__ctx, crypto_ahash_reqsize(tfm));
993 testmgr_poison(result, digestsize + TESTMGR_POISON_LEN);
994
995 if (cfg->finalization_type == FINALIZATION_TYPE_DIGEST) {
996 /* Just using digest() */
997 ahash_request_set_callback(req, req_flags, crypto_req_done,
998 &wait);
999 ahash_request_set_crypt(req, tsgl->sgl, result, vec->psize);
Eric Biggers65707372019-03-12 22:12:52 -07001000 err = do_ahash_op(crypto_ahash_digest, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001001 if (err) {
1002 pr_err("alg: hash: %s digest() failed with err %d on test vector %u, cfg=\"%s\"\n",
1003 driver, err, vec_num, cfg->name);
1004 return err;
1005 }
1006 goto result_ready;
1007 }
1008
1009 /* Using init(), zero or more update(), then final() or finup() */
1010
1011 ahash_request_set_callback(req, req_flags, crypto_req_done, &wait);
1012 ahash_request_set_crypt(req, NULL, result, 0);
Eric Biggers65707372019-03-12 22:12:52 -07001013 err = do_ahash_op(crypto_ahash_init, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001014 err = check_nonfinal_hash_op("init", err, result, digestsize,
1015 driver, vec_num, cfg);
1016 if (err)
1017 return err;
1018
1019 pending_sgl = NULL;
1020 pending_len = 0;
1021 for (i = 0; i < tsgl->nents; i++) {
1022 if (divs[i]->flush_type != FLUSH_TYPE_NONE &&
1023 pending_sgl != NULL) {
1024 /* update() with the pending data */
1025 ahash_request_set_callback(req, req_flags,
1026 crypto_req_done, &wait);
1027 ahash_request_set_crypt(req, pending_sgl, result,
1028 pending_len);
Eric Biggers65707372019-03-12 22:12:52 -07001029 err = do_ahash_op(crypto_ahash_update, req, &wait,
1030 divs[i]->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001031 err = check_nonfinal_hash_op("update", err,
1032 result, digestsize,
1033 driver, vec_num, cfg);
1034 if (err)
1035 return err;
1036 pending_sgl = NULL;
1037 pending_len = 0;
1038 }
1039 if (divs[i]->flush_type == FLUSH_TYPE_REIMPORT) {
1040 /* Test ->export() and ->import() */
1041 testmgr_poison(hashstate + statesize,
1042 TESTMGR_POISON_LEN);
1043 err = crypto_ahash_export(req, hashstate);
1044 err = check_nonfinal_hash_op("export", err,
1045 result, digestsize,
1046 driver, vec_num, cfg);
1047 if (err)
1048 return err;
1049 if (!testmgr_is_poison(hashstate + statesize,
1050 TESTMGR_POISON_LEN)) {
1051 pr_err("alg: hash: %s export() overran state buffer on test vector %u, cfg=\"%s\"\n",
1052 driver, vec_num, cfg->name);
1053 return -EOVERFLOW;
1054 }
1055
1056 testmgr_poison(req->__ctx, crypto_ahash_reqsize(tfm));
1057 err = crypto_ahash_import(req, hashstate);
1058 err = check_nonfinal_hash_op("import", err,
1059 result, digestsize,
1060 driver, vec_num, cfg);
1061 if (err)
1062 return err;
1063 }
1064 if (pending_sgl == NULL)
1065 pending_sgl = &tsgl->sgl[i];
1066 pending_len += tsgl->sgl[i].length;
1067 }
1068
1069 ahash_request_set_callback(req, req_flags, crypto_req_done, &wait);
1070 ahash_request_set_crypt(req, pending_sgl, result, pending_len);
1071 if (cfg->finalization_type == FINALIZATION_TYPE_FINAL) {
1072 /* finish with update() and final() */
Eric Biggers65707372019-03-12 22:12:52 -07001073 err = do_ahash_op(crypto_ahash_update, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001074 err = check_nonfinal_hash_op("update", err, result, digestsize,
1075 driver, vec_num, cfg);
1076 if (err)
1077 return err;
Eric Biggers65707372019-03-12 22:12:52 -07001078 err = do_ahash_op(crypto_ahash_final, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001079 if (err) {
1080 pr_err("alg: hash: %s final() failed with err %d on test vector %u, cfg=\"%s\"\n",
1081 driver, err, vec_num, cfg->name);
1082 return err;
1083 }
1084 } else {
1085 /* finish with finup() */
Eric Biggers65707372019-03-12 22:12:52 -07001086 err = do_ahash_op(crypto_ahash_finup, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001087 if (err) {
1088 pr_err("alg: hash: %s finup() failed with err %d on test vector %u, cfg=\"%s\"\n",
1089 driver, err, vec_num, cfg->name);
1090 return err;
1091 }
1092 }
1093
1094result_ready:
1095 /* Check that the algorithm produced the correct digest */
1096 if (memcmp(result, vec->digest, digestsize) != 0) {
1097 pr_err("alg: hash: %s test failed (wrong result) on test vector %u, cfg=\"%s\"\n",
1098 driver, vec_num, cfg->name);
1099 return -EINVAL;
1100 }
1101 if (!testmgr_is_poison(&result[digestsize], TESTMGR_POISON_LEN)) {
1102 pr_err("alg: hash: %s overran result buffer on test vector %u, cfg=\"%s\"\n",
1103 driver, vec_num, cfg->name);
1104 return -EOVERFLOW;
1105 }
1106
1107 return 0;
1108}
1109
1110static int test_hash_vec(const char *driver, const struct hash_testvec *vec,
1111 unsigned int vec_num, struct ahash_request *req,
1112 struct test_sglist *tsgl, u8 *hashstate)
1113{
1114 unsigned int i;
1115 int err;
1116
1117 for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++) {
1118 err = test_hash_vec_cfg(driver, vec, vec_num,
1119 &default_hash_testvec_configs[i],
1120 req, tsgl, hashstate);
1121 if (err)
1122 return err;
1123 }
1124
1125#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1126 if (!noextratests) {
1127 struct testvec_config cfg;
1128 char cfgname[TESTVEC_CONFIG_NAMELEN];
1129
1130 for (i = 0; i < fuzz_iterations; i++) {
1131 generate_random_testvec_config(&cfg, cfgname,
1132 sizeof(cfgname));
1133 err = test_hash_vec_cfg(driver, vec, vec_num, &cfg,
1134 req, tsgl, hashstate);
1135 if (err)
1136 return err;
1137 }
1138 }
1139#endif
1140 return 0;
1141}
1142
1143static int __alg_test_hash(const struct hash_testvec *vecs,
1144 unsigned int num_vecs, const char *driver,
1145 u32 type, u32 mask)
1146{
1147 struct crypto_ahash *tfm;
1148 struct ahash_request *req = NULL;
1149 struct test_sglist *tsgl = NULL;
1150 u8 *hashstate = NULL;
1151 unsigned int i;
1152 int err;
1153
1154 tfm = crypto_alloc_ahash(driver, type, mask);
1155 if (IS_ERR(tfm)) {
1156 pr_err("alg: hash: failed to allocate transform for %s: %ld\n",
1157 driver, PTR_ERR(tfm));
1158 return PTR_ERR(tfm);
1159 }
1160
1161 req = ahash_request_alloc(tfm, GFP_KERNEL);
1162 if (!req) {
1163 pr_err("alg: hash: failed to allocate request for %s\n",
1164 driver);
1165 err = -ENOMEM;
1166 goto out;
1167 }
1168
1169 tsgl = kmalloc(sizeof(*tsgl), GFP_KERNEL);
1170 if (!tsgl || init_test_sglist(tsgl) != 0) {
1171 pr_err("alg: hash: failed to allocate test buffers for %s\n",
1172 driver);
1173 kfree(tsgl);
1174 tsgl = NULL;
1175 err = -ENOMEM;
1176 goto out;
1177 }
1178
1179 hashstate = kmalloc(crypto_ahash_statesize(tfm) + TESTMGR_POISON_LEN,
1180 GFP_KERNEL);
1181 if (!hashstate) {
1182 pr_err("alg: hash: failed to allocate hash state buffer for %s\n",
1183 driver);
1184 err = -ENOMEM;
1185 goto out;
1186 }
1187
1188 for (i = 0; i < num_vecs; i++) {
1189 err = test_hash_vec(driver, &vecs[i], i, req, tsgl, hashstate);
1190 if (err)
1191 goto out;
1192 }
1193 err = 0;
1194out:
1195 kfree(hashstate);
1196 if (tsgl) {
1197 destroy_test_sglist(tsgl);
1198 kfree(tsgl);
1199 }
1200 ahash_request_free(req);
1201 crypto_free_ahash(tfm);
1202 return err;
1203}
1204
1205static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1206 u32 type, u32 mask)
1207{
1208 const struct hash_testvec *template = desc->suite.hash.vecs;
1209 unsigned int tcount = desc->suite.hash.count;
1210 unsigned int nr_unkeyed, nr_keyed;
1211 int err;
1212
1213 /*
1214 * For OPTIONAL_KEY algorithms, we have to do all the unkeyed tests
1215 * first, before setting a key on the tfm. To make this easier, we
1216 * require that the unkeyed test vectors (if any) are listed first.
1217 */
1218
1219 for (nr_unkeyed = 0; nr_unkeyed < tcount; nr_unkeyed++) {
1220 if (template[nr_unkeyed].ksize)
1221 break;
1222 }
1223 for (nr_keyed = 0; nr_unkeyed + nr_keyed < tcount; nr_keyed++) {
1224 if (!template[nr_unkeyed + nr_keyed].ksize) {
1225 pr_err("alg: hash: test vectors for %s out of order, "
1226 "unkeyed ones must come first\n", desc->alg);
Kamil Konieczny466d7b92018-01-16 15:26:13 +01001227 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08001228 }
1229 }
1230
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001231 err = 0;
1232 if (nr_unkeyed) {
1233 err = __alg_test_hash(template, nr_unkeyed, driver, type, mask);
1234 template += nr_unkeyed;
Herbert Xuda7f0332008-07-31 17:08:25 +08001235 }
1236
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001237 if (!err && nr_keyed)
1238 err = __alg_test_hash(template, nr_keyed, driver, type, mask);
Wang, Rui Y018ba952016-02-03 18:26:57 +08001239
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001240 return err;
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +03001241}
1242
Eric Biggersed968042019-01-31 23:51:47 -08001243static int test_aead_vec_cfg(const char *driver, int enc,
1244 const struct aead_testvec *vec,
1245 unsigned int vec_num,
1246 const struct testvec_config *cfg,
1247 struct aead_request *req,
1248 struct cipher_test_sglists *tsgls)
Herbert Xuda7f0332008-07-31 17:08:25 +08001249{
Eric Biggersed968042019-01-31 23:51:47 -08001250 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1251 const unsigned int alignmask = crypto_aead_alignmask(tfm);
1252 const unsigned int ivsize = crypto_aead_ivsize(tfm);
1253 const unsigned int authsize = vec->clen - vec->plen;
1254 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
1255 const char *op = enc ? "encryption" : "decryption";
1256 DECLARE_CRYPTO_WAIT(wait);
1257 u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN];
1258 u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) +
1259 cfg->iv_offset +
1260 (cfg->iv_offset_relative_to_alignmask ? alignmask : 0);
1261 struct kvec input[2];
1262 int err;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001263
Eric Biggersed968042019-01-31 23:51:47 -08001264 /* Set the key */
1265 if (vec->wk)
1266 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001267 else
Eric Biggersed968042019-01-31 23:51:47 -08001268 crypto_aead_clear_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
1269 err = crypto_aead_setkey(tfm, vec->key, vec->klen);
1270 if (err) {
1271 if (vec->fail) /* expectedly failed to set key? */
1272 return 0;
1273 pr_err("alg: aead: %s setkey failed with err %d on test vector %u; flags=%#x\n",
1274 driver, err, vec_num, crypto_aead_get_flags(tfm));
1275 return err;
1276 }
1277 if (vec->fail) {
1278 pr_err("alg: aead: %s setkey unexpectedly succeeded on test vector %u\n",
1279 driver, vec_num);
1280 return -EINVAL;
1281 }
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001282
Eric Biggersed968042019-01-31 23:51:47 -08001283 /* Set the authentication tag size */
1284 err = crypto_aead_setauthsize(tfm, authsize);
1285 if (err) {
1286 pr_err("alg: aead: %s setauthsize failed with err %d on test vector %u\n",
1287 driver, err, vec_num);
1288 return err;
1289 }
1290
1291 /* The IV must be copied to a buffer, as the algorithm may modify it */
1292 if (WARN_ON(ivsize > MAX_IVLEN))
1293 return -EINVAL;
1294 if (vec->iv)
1295 memcpy(iv, vec->iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001296 else
Eric Biggersed968042019-01-31 23:51:47 -08001297 memset(iv, 0, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001298
Eric Biggersed968042019-01-31 23:51:47 -08001299 /* Build the src/dst scatterlists */
1300 input[0].iov_base = (void *)vec->assoc;
1301 input[0].iov_len = vec->alen;
1302 input[1].iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext;
1303 input[1].iov_len = enc ? vec->plen : vec->clen;
1304 err = build_cipher_test_sglists(tsgls, cfg, alignmask,
1305 vec->alen + (enc ? vec->plen :
1306 vec->clen),
1307 vec->alen + (enc ? vec->clen :
1308 vec->plen),
1309 input, 2);
1310 if (err) {
1311 pr_err("alg: aead: %s %s: error preparing scatterlists for test vector %u, cfg=\"%s\"\n",
1312 driver, op, vec_num, cfg->name);
1313 return err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001314 }
1315
Eric Biggersed968042019-01-31 23:51:47 -08001316 /* Do the actual encryption or decryption */
1317 testmgr_poison(req->__ctx, crypto_aead_reqsize(tfm));
1318 aead_request_set_callback(req, req_flags, crypto_req_done, &wait);
1319 aead_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr,
1320 enc ? vec->plen : vec->clen, iv);
1321 aead_request_set_ad(req, vec->alen);
Eric Biggers65707372019-03-12 22:12:52 -07001322 if (cfg->nosimd)
1323 crypto_disable_simd_for_test();
1324 err = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
1325 if (cfg->nosimd)
1326 crypto_reenable_simd_for_test();
1327 err = crypto_wait_req(err, &wait);
Eric Biggersed968042019-01-31 23:51:47 -08001328 if (err) {
1329 if (err == -EBADMSG && vec->novrfy)
1330 return 0;
1331 pr_err("alg: aead: %s %s failed with err %d on test vector %u, cfg=\"%s\"\n",
1332 driver, op, err, vec_num, cfg->name);
1333 return err;
1334 }
1335 if (vec->novrfy) {
1336 pr_err("alg: aead: %s %s unexpectedly succeeded on test vector %u, cfg=\"%s\"\n",
1337 driver, op, vec_num, cfg->name);
1338 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08001339 }
1340
Eric Biggersa6e5ef92019-01-31 23:51:50 -08001341 /* Check that the algorithm didn't overwrite things it shouldn't have */
1342 if (req->cryptlen != (enc ? vec->plen : vec->clen) ||
1343 req->assoclen != vec->alen ||
1344 req->iv != iv ||
1345 req->src != tsgls->src.sgl_ptr ||
1346 req->dst != tsgls->dst.sgl_ptr ||
1347 crypto_aead_reqtfm(req) != tfm ||
1348 req->base.complete != crypto_req_done ||
1349 req->base.flags != req_flags ||
1350 req->base.data != &wait) {
1351 pr_err("alg: aead: %s %s corrupted request struct on test vector %u, cfg=\"%s\"\n",
1352 driver, op, vec_num, cfg->name);
1353 if (req->cryptlen != (enc ? vec->plen : vec->clen))
1354 pr_err("alg: aead: changed 'req->cryptlen'\n");
1355 if (req->assoclen != vec->alen)
1356 pr_err("alg: aead: changed 'req->assoclen'\n");
1357 if (req->iv != iv)
1358 pr_err("alg: aead: changed 'req->iv'\n");
1359 if (req->src != tsgls->src.sgl_ptr)
1360 pr_err("alg: aead: changed 'req->src'\n");
1361 if (req->dst != tsgls->dst.sgl_ptr)
1362 pr_err("alg: aead: changed 'req->dst'\n");
1363 if (crypto_aead_reqtfm(req) != tfm)
1364 pr_err("alg: aead: changed 'req->base.tfm'\n");
1365 if (req->base.complete != crypto_req_done)
1366 pr_err("alg: aead: changed 'req->base.complete'\n");
1367 if (req->base.flags != req_flags)
1368 pr_err("alg: aead: changed 'req->base.flags'\n");
1369 if (req->base.data != &wait)
1370 pr_err("alg: aead: changed 'req->base.data'\n");
1371 return -EINVAL;
1372 }
1373 if (is_test_sglist_corrupted(&tsgls->src)) {
1374 pr_err("alg: aead: %s %s corrupted src sgl on test vector %u, cfg=\"%s\"\n",
1375 driver, op, vec_num, cfg->name);
1376 return -EINVAL;
1377 }
1378 if (tsgls->dst.sgl_ptr != tsgls->src.sgl &&
1379 is_test_sglist_corrupted(&tsgls->dst)) {
1380 pr_err("alg: aead: %s %s corrupted dst sgl on test vector %u, cfg=\"%s\"\n",
1381 driver, op, vec_num, cfg->name);
1382 return -EINVAL;
1383 }
1384
Eric Biggersed968042019-01-31 23:51:47 -08001385 /* Check for the correct output (ciphertext or plaintext) */
1386 err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext,
1387 enc ? vec->clen : vec->plen,
1388 vec->alen, enc || !cfg->inplace);
1389 if (err == -EOVERFLOW) {
1390 pr_err("alg: aead: %s %s overran dst buffer on test vector %u, cfg=\"%s\"\n",
1391 driver, op, vec_num, cfg->name);
1392 return err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001393 }
Eric Biggersed968042019-01-31 23:51:47 -08001394 if (err) {
1395 pr_err("alg: aead: %s %s test failed (wrong result) on test vector %u, cfg=\"%s\"\n",
1396 driver, op, vec_num, cfg->name);
1397 return err;
Jussi Kivilinna58dcf542013-06-13 17:37:50 +03001398 }
1399
1400 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001401}
1402
Eric Biggersed968042019-01-31 23:51:47 -08001403static int test_aead_vec(const char *driver, int enc,
1404 const struct aead_testvec *vec, unsigned int vec_num,
1405 struct aead_request *req,
1406 struct cipher_test_sglists *tsgls)
1407{
1408 unsigned int i;
1409 int err;
1410
1411 if (enc && vec->novrfy)
1412 return 0;
1413
1414 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
1415 err = test_aead_vec_cfg(driver, enc, vec, vec_num,
1416 &default_cipher_testvec_configs[i],
1417 req, tsgls);
1418 if (err)
1419 return err;
1420 }
1421
1422#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1423 if (!noextratests) {
1424 struct testvec_config cfg;
1425 char cfgname[TESTVEC_CONFIG_NAMELEN];
1426
1427 for (i = 0; i < fuzz_iterations; i++) {
1428 generate_random_testvec_config(&cfg, cfgname,
1429 sizeof(cfgname));
1430 err = test_aead_vec_cfg(driver, enc, vec, vec_num,
1431 &cfg, req, tsgls);
1432 if (err)
1433 return err;
1434 }
1435 }
1436#endif
1437 return 0;
1438}
1439
1440static int test_aead(const char *driver, int enc,
1441 const struct aead_test_suite *suite,
1442 struct aead_request *req,
1443 struct cipher_test_sglists *tsgls)
1444{
1445 unsigned int i;
1446 int err;
1447
1448 for (i = 0; i < suite->count; i++) {
1449 err = test_aead_vec(driver, enc, &suite->vecs[i], i, req,
1450 tsgls);
1451 if (err)
1452 return err;
1453 }
1454 return 0;
1455}
1456
1457static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1458 u32 type, u32 mask)
1459{
1460 const struct aead_test_suite *suite = &desc->suite.aead;
1461 struct crypto_aead *tfm;
1462 struct aead_request *req = NULL;
1463 struct cipher_test_sglists *tsgls = NULL;
1464 int err;
1465
1466 if (suite->count <= 0) {
1467 pr_err("alg: aead: empty test suite for %s\n", driver);
1468 return -EINVAL;
1469 }
1470
1471 tfm = crypto_alloc_aead(driver, type, mask);
1472 if (IS_ERR(tfm)) {
1473 pr_err("alg: aead: failed to allocate transform for %s: %ld\n",
1474 driver, PTR_ERR(tfm));
1475 return PTR_ERR(tfm);
1476 }
1477
1478 req = aead_request_alloc(tfm, GFP_KERNEL);
1479 if (!req) {
1480 pr_err("alg: aead: failed to allocate request for %s\n",
1481 driver);
1482 err = -ENOMEM;
1483 goto out;
1484 }
1485
1486 tsgls = alloc_cipher_test_sglists();
1487 if (!tsgls) {
1488 pr_err("alg: aead: failed to allocate test buffers for %s\n",
1489 driver);
1490 err = -ENOMEM;
1491 goto out;
1492 }
1493
1494 err = test_aead(driver, ENCRYPT, suite, req, tsgls);
1495 if (err)
1496 goto out;
1497
1498 err = test_aead(driver, DECRYPT, suite, req, tsgls);
1499out:
1500 free_cipher_test_sglists(tsgls);
1501 aead_request_free(req);
1502 crypto_free_aead(tfm);
1503 return err;
1504}
1505
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001506static int test_cipher(struct crypto_cipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001507 const struct cipher_testvec *template,
1508 unsigned int tcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08001509{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001510 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
1511 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001512 char *q;
1513 const char *e;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001514 const char *input, *result;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001515 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001516 char *xbuf[XBUFSIZE];
1517 int ret = -ENOMEM;
1518
1519 if (testmgr_alloc_buf(xbuf))
1520 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001521
1522 if (enc == ENCRYPT)
1523 e = "encryption";
1524 else
1525 e = "decryption";
1526
1527 j = 0;
1528 for (i = 0; i < tcount; i++) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001529
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001530 if (fips_enabled && template[i].fips_skip)
1531 continue;
1532
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001533 input = enc ? template[i].ptext : template[i].ctext;
1534 result = enc ? template[i].ctext : template[i].ptext;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001535 j++;
1536
Herbert Xufd57f222009-05-29 16:05:42 +10001537 ret = -EINVAL;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001538 if (WARN_ON(template[i].len > PAGE_SIZE))
Herbert Xufd57f222009-05-29 16:05:42 +10001539 goto out;
1540
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001541 data = xbuf[0];
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001542 memcpy(data, input, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001543
1544 crypto_cipher_clear_flags(tfm, ~0);
1545 if (template[i].wk)
Eric Biggers231baec2019-01-18 22:48:00 -08001546 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001547
1548 ret = crypto_cipher_setkey(tfm, template[i].key,
1549 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001550 if (template[i].fail == !ret) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001551 printk(KERN_ERR "alg: cipher: setkey failed "
1552 "on test %d for %s: flags=%x\n", j,
1553 algo, crypto_cipher_get_flags(tfm));
1554 goto out;
1555 } else if (ret)
1556 continue;
1557
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001558 for (k = 0; k < template[i].len;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001559 k += crypto_cipher_blocksize(tfm)) {
1560 if (enc)
1561 crypto_cipher_encrypt_one(tfm, data + k,
1562 data + k);
1563 else
1564 crypto_cipher_decrypt_one(tfm, data + k,
1565 data + k);
1566 }
1567
1568 q = data;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001569 if (memcmp(q, result, template[i].len)) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001570 printk(KERN_ERR "alg: cipher: Test %d failed "
1571 "on %s for %s\n", j, e, algo);
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001572 hexdump(q, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001573 ret = -EINVAL;
1574 goto out;
1575 }
1576 }
1577
1578 ret = 0;
1579
1580out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001581 testmgr_free_buf(xbuf);
1582out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001583 return ret;
1584}
1585
Eric Biggers4e7babba2019-01-31 23:51:46 -08001586static int test_skcipher_vec_cfg(const char *driver, int enc,
1587 const struct cipher_testvec *vec,
1588 unsigned int vec_num,
1589 const struct testvec_config *cfg,
1590 struct skcipher_request *req,
1591 struct cipher_test_sglists *tsgls)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001592{
Eric Biggers4e7babba2019-01-31 23:51:46 -08001593 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
1594 const unsigned int alignmask = crypto_skcipher_alignmask(tfm);
1595 const unsigned int ivsize = crypto_skcipher_ivsize(tfm);
1596 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
1597 const char *op = enc ? "encryption" : "decryption";
1598 DECLARE_CRYPTO_WAIT(wait);
1599 u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN];
1600 u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) +
1601 cfg->iv_offset +
1602 (cfg->iv_offset_relative_to_alignmask ? alignmask : 0);
1603 struct kvec input;
1604 int err;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001605
Eric Biggers4e7babba2019-01-31 23:51:46 -08001606 /* Set the key */
1607 if (vec->wk)
1608 crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001609 else
Eric Biggers4e7babba2019-01-31 23:51:46 -08001610 crypto_skcipher_clear_flags(tfm,
1611 CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
1612 err = crypto_skcipher_setkey(tfm, vec->key, vec->klen);
1613 if (err) {
1614 if (vec->fail) /* expectedly failed to set key? */
1615 return 0;
1616 pr_err("alg: skcipher: %s setkey failed with err %d on test vector %u; flags=%#x\n",
1617 driver, err, vec_num, crypto_skcipher_get_flags(tfm));
1618 return err;
1619 }
1620 if (vec->fail) {
1621 pr_err("alg: skcipher: %s setkey unexpectedly succeeded on test vector %u\n",
1622 driver, vec_num);
1623 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08001624 }
1625
Eric Biggers4e7babba2019-01-31 23:51:46 -08001626 /* The IV must be copied to a buffer, as the algorithm may modify it */
1627 if (ivsize) {
1628 if (WARN_ON(ivsize > MAX_IVLEN))
1629 return -EINVAL;
Eric Biggers8efd9722019-02-14 00:03:51 -08001630 if (vec->generates_iv && !enc)
1631 memcpy(iv, vec->iv_out, ivsize);
1632 else if (vec->iv)
Eric Biggers4e7babba2019-01-31 23:51:46 -08001633 memcpy(iv, vec->iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001634 else
Eric Biggers4e7babba2019-01-31 23:51:46 -08001635 memset(iv, 0, ivsize);
1636 } else {
1637 if (vec->generates_iv) {
1638 pr_err("alg: skcipher: %s has ivsize=0 but test vector %u generates IV!\n",
1639 driver, vec_num);
1640 return -EINVAL;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001641 }
Eric Biggers4e7babba2019-01-31 23:51:46 -08001642 iv = NULL;
Herbert Xuda7f0332008-07-31 17:08:25 +08001643 }
1644
Eric Biggers4e7babba2019-01-31 23:51:46 -08001645 /* Build the src/dst scatterlists */
1646 input.iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext;
1647 input.iov_len = vec->len;
1648 err = build_cipher_test_sglists(tsgls, cfg, alignmask,
1649 vec->len, vec->len, &input, 1);
1650 if (err) {
1651 pr_err("alg: skcipher: %s %s: error preparing scatterlists for test vector %u, cfg=\"%s\"\n",
1652 driver, op, vec_num, cfg->name);
1653 return err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001654 }
1655
Eric Biggers4e7babba2019-01-31 23:51:46 -08001656 /* Do the actual encryption or decryption */
1657 testmgr_poison(req->__ctx, crypto_skcipher_reqsize(tfm));
1658 skcipher_request_set_callback(req, req_flags, crypto_req_done, &wait);
1659 skcipher_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr,
1660 vec->len, iv);
Eric Biggers65707372019-03-12 22:12:52 -07001661 if (cfg->nosimd)
1662 crypto_disable_simd_for_test();
1663 err = enc ? crypto_skcipher_encrypt(req) : crypto_skcipher_decrypt(req);
1664 if (cfg->nosimd)
1665 crypto_reenable_simd_for_test();
1666 err = crypto_wait_req(err, &wait);
Eric Biggers4e7babba2019-01-31 23:51:46 -08001667 if (err) {
1668 pr_err("alg: skcipher: %s %s failed with err %d on test vector %u, cfg=\"%s\"\n",
1669 driver, op, err, vec_num, cfg->name);
1670 return err;
1671 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001672
Eric Biggersfa353c92019-01-31 23:51:49 -08001673 /* Check that the algorithm didn't overwrite things it shouldn't have */
1674 if (req->cryptlen != vec->len ||
1675 req->iv != iv ||
1676 req->src != tsgls->src.sgl_ptr ||
1677 req->dst != tsgls->dst.sgl_ptr ||
1678 crypto_skcipher_reqtfm(req) != tfm ||
1679 req->base.complete != crypto_req_done ||
1680 req->base.flags != req_flags ||
1681 req->base.data != &wait) {
1682 pr_err("alg: skcipher: %s %s corrupted request struct on test vector %u, cfg=\"%s\"\n",
1683 driver, op, vec_num, cfg->name);
1684 if (req->cryptlen != vec->len)
1685 pr_err("alg: skcipher: changed 'req->cryptlen'\n");
1686 if (req->iv != iv)
1687 pr_err("alg: skcipher: changed 'req->iv'\n");
1688 if (req->src != tsgls->src.sgl_ptr)
1689 pr_err("alg: skcipher: changed 'req->src'\n");
1690 if (req->dst != tsgls->dst.sgl_ptr)
1691 pr_err("alg: skcipher: changed 'req->dst'\n");
1692 if (crypto_skcipher_reqtfm(req) != tfm)
1693 pr_err("alg: skcipher: changed 'req->base.tfm'\n");
1694 if (req->base.complete != crypto_req_done)
1695 pr_err("alg: skcipher: changed 'req->base.complete'\n");
1696 if (req->base.flags != req_flags)
1697 pr_err("alg: skcipher: changed 'req->base.flags'\n");
1698 if (req->base.data != &wait)
1699 pr_err("alg: skcipher: changed 'req->base.data'\n");
1700 return -EINVAL;
1701 }
1702 if (is_test_sglist_corrupted(&tsgls->src)) {
1703 pr_err("alg: skcipher: %s %s corrupted src sgl on test vector %u, cfg=\"%s\"\n",
1704 driver, op, vec_num, cfg->name);
1705 return -EINVAL;
1706 }
1707 if (tsgls->dst.sgl_ptr != tsgls->src.sgl &&
1708 is_test_sglist_corrupted(&tsgls->dst)) {
1709 pr_err("alg: skcipher: %s %s corrupted dst sgl on test vector %u, cfg=\"%s\"\n",
1710 driver, op, vec_num, cfg->name);
1711 return -EINVAL;
1712 }
1713
Eric Biggers4e7babba2019-01-31 23:51:46 -08001714 /* Check for the correct output (ciphertext or plaintext) */
1715 err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext,
1716 vec->len, 0, true);
1717 if (err == -EOVERFLOW) {
1718 pr_err("alg: skcipher: %s %s overran dst buffer on test vector %u, cfg=\"%s\"\n",
1719 driver, op, vec_num, cfg->name);
1720 return err;
1721 }
1722 if (err) {
1723 pr_err("alg: skcipher: %s %s test failed (wrong result) on test vector %u, cfg=\"%s\"\n",
1724 driver, op, vec_num, cfg->name);
1725 return err;
1726 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001727
Eric Biggers4e7babba2019-01-31 23:51:46 -08001728 /* If applicable, check that the algorithm generated the correct IV */
Eric Biggers8efd9722019-02-14 00:03:51 -08001729 if (vec->iv_out && memcmp(iv, vec->iv_out, ivsize) != 0) {
Eric Biggers4e7babba2019-01-31 23:51:46 -08001730 pr_err("alg: skcipher: %s %s test failed (wrong output IV) on test vector %u, cfg=\"%s\"\n",
1731 driver, op, vec_num, cfg->name);
1732 hexdump(iv, ivsize);
1733 return -EINVAL;
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001734 }
1735
1736 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001737}
1738
Eric Biggers4e7babba2019-01-31 23:51:46 -08001739static int test_skcipher_vec(const char *driver, int enc,
1740 const struct cipher_testvec *vec,
1741 unsigned int vec_num,
1742 struct skcipher_request *req,
1743 struct cipher_test_sglists *tsgls)
1744{
1745 unsigned int i;
1746 int err;
1747
1748 if (fips_enabled && vec->fips_skip)
1749 return 0;
1750
1751 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
1752 err = test_skcipher_vec_cfg(driver, enc, vec, vec_num,
1753 &default_cipher_testvec_configs[i],
1754 req, tsgls);
1755 if (err)
1756 return err;
1757 }
1758
1759#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1760 if (!noextratests) {
1761 struct testvec_config cfg;
1762 char cfgname[TESTVEC_CONFIG_NAMELEN];
1763
1764 for (i = 0; i < fuzz_iterations; i++) {
1765 generate_random_testvec_config(&cfg, cfgname,
1766 sizeof(cfgname));
1767 err = test_skcipher_vec_cfg(driver, enc, vec, vec_num,
1768 &cfg, req, tsgls);
1769 if (err)
1770 return err;
1771 }
1772 }
1773#endif
1774 return 0;
1775}
1776
1777static int test_skcipher(const char *driver, int enc,
1778 const struct cipher_test_suite *suite,
1779 struct skcipher_request *req,
1780 struct cipher_test_sglists *tsgls)
1781{
1782 unsigned int i;
1783 int err;
1784
1785 for (i = 0; i < suite->count; i++) {
1786 err = test_skcipher_vec(driver, enc, &suite->vecs[i], i, req,
1787 tsgls);
1788 if (err)
1789 return err;
1790 }
1791 return 0;
1792}
1793
1794static int alg_test_skcipher(const struct alg_test_desc *desc,
1795 const char *driver, u32 type, u32 mask)
1796{
1797 const struct cipher_test_suite *suite = &desc->suite.cipher;
1798 struct crypto_skcipher *tfm;
1799 struct skcipher_request *req = NULL;
1800 struct cipher_test_sglists *tsgls = NULL;
1801 int err;
1802
1803 if (suite->count <= 0) {
1804 pr_err("alg: skcipher: empty test suite for %s\n", driver);
1805 return -EINVAL;
1806 }
1807
1808 tfm = crypto_alloc_skcipher(driver, type, mask);
1809 if (IS_ERR(tfm)) {
1810 pr_err("alg: skcipher: failed to allocate transform for %s: %ld\n",
1811 driver, PTR_ERR(tfm));
1812 return PTR_ERR(tfm);
1813 }
1814
1815 req = skcipher_request_alloc(tfm, GFP_KERNEL);
1816 if (!req) {
1817 pr_err("alg: skcipher: failed to allocate request for %s\n",
1818 driver);
1819 err = -ENOMEM;
1820 goto out;
1821 }
1822
1823 tsgls = alloc_cipher_test_sglists();
1824 if (!tsgls) {
1825 pr_err("alg: skcipher: failed to allocate test buffers for %s\n",
1826 driver);
1827 err = -ENOMEM;
1828 goto out;
1829 }
1830
1831 err = test_skcipher(driver, ENCRYPT, suite, req, tsgls);
1832 if (err)
1833 goto out;
1834
1835 err = test_skcipher(driver, DECRYPT, suite, req, tsgls);
1836out:
1837 free_cipher_test_sglists(tsgls);
1838 skcipher_request_free(req);
1839 crypto_free_skcipher(tfm);
1840 return err;
1841}
1842
Eric Biggersb13b1e02017-02-24 15:46:59 -08001843static int test_comp(struct crypto_comp *tfm,
1844 const struct comp_testvec *ctemplate,
1845 const struct comp_testvec *dtemplate,
1846 int ctcount, int dtcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08001847{
1848 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
Mahipal Challa33607382018-04-11 20:28:32 +02001849 char *output, *decomp_output;
Herbert Xuda7f0332008-07-31 17:08:25 +08001850 unsigned int i;
Herbert Xuda7f0332008-07-31 17:08:25 +08001851 int ret;
1852
Mahipal Challa33607382018-04-11 20:28:32 +02001853 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1854 if (!output)
1855 return -ENOMEM;
1856
1857 decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1858 if (!decomp_output) {
1859 kfree(output);
1860 return -ENOMEM;
1861 }
1862
Herbert Xuda7f0332008-07-31 17:08:25 +08001863 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001864 int ilen;
1865 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001866
Michael Schupikov22a81182018-10-07 13:58:10 +02001867 memset(output, 0, COMP_BUF_SIZE);
1868 memset(decomp_output, 0, COMP_BUF_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +08001869
1870 ilen = ctemplate[i].inlen;
1871 ret = crypto_comp_compress(tfm, ctemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02001872 ilen, output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001873 if (ret) {
1874 printk(KERN_ERR "alg: comp: compression failed "
1875 "on test %d for %s: ret=%d\n", i + 1, algo,
1876 -ret);
1877 goto out;
1878 }
1879
Mahipal Challa33607382018-04-11 20:28:32 +02001880 ilen = dlen;
1881 dlen = COMP_BUF_SIZE;
1882 ret = crypto_comp_decompress(tfm, output,
1883 ilen, decomp_output, &dlen);
1884 if (ret) {
1885 pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n",
1886 i + 1, algo, -ret);
1887 goto out;
1888 }
1889
1890 if (dlen != ctemplate[i].inlen) {
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001891 printk(KERN_ERR "alg: comp: Compression test %d "
1892 "failed for %s: output len = %d\n", i + 1, algo,
1893 dlen);
1894 ret = -EINVAL;
1895 goto out;
1896 }
1897
Mahipal Challa33607382018-04-11 20:28:32 +02001898 if (memcmp(decomp_output, ctemplate[i].input,
1899 ctemplate[i].inlen)) {
1900 pr_err("alg: comp: compression failed: output differs: on test %d for %s\n",
1901 i + 1, algo);
1902 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001903 ret = -EINVAL;
1904 goto out;
1905 }
1906 }
1907
1908 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001909 int ilen;
1910 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001911
Michael Schupikov22a81182018-10-07 13:58:10 +02001912 memset(decomp_output, 0, COMP_BUF_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +08001913
1914 ilen = dtemplate[i].inlen;
1915 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02001916 ilen, decomp_output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001917 if (ret) {
1918 printk(KERN_ERR "alg: comp: decompression failed "
1919 "on test %d for %s: ret=%d\n", i + 1, algo,
1920 -ret);
1921 goto out;
1922 }
1923
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001924 if (dlen != dtemplate[i].outlen) {
1925 printk(KERN_ERR "alg: comp: Decompression test %d "
1926 "failed for %s: output len = %d\n", i + 1, algo,
1927 dlen);
1928 ret = -EINVAL;
1929 goto out;
1930 }
1931
Mahipal Challa33607382018-04-11 20:28:32 +02001932 if (memcmp(decomp_output, dtemplate[i].output, dlen)) {
Herbert Xuda7f0332008-07-31 17:08:25 +08001933 printk(KERN_ERR "alg: comp: Decompression test %d "
1934 "failed for %s\n", i + 1, algo);
Mahipal Challa33607382018-04-11 20:28:32 +02001935 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001936 ret = -EINVAL;
1937 goto out;
1938 }
1939 }
1940
1941 ret = 0;
1942
1943out:
Mahipal Challa33607382018-04-11 20:28:32 +02001944 kfree(decomp_output);
1945 kfree(output);
Herbert Xuda7f0332008-07-31 17:08:25 +08001946 return ret;
1947}
1948
Eric Biggersb13b1e02017-02-24 15:46:59 -08001949static int test_acomp(struct crypto_acomp *tfm,
Mahipal Challa33607382018-04-11 20:28:32 +02001950 const struct comp_testvec *ctemplate,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001951 const struct comp_testvec *dtemplate,
1952 int ctcount, int dtcount)
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001953{
1954 const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
1955 unsigned int i;
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001956 char *output, *decomp_out;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001957 int ret;
1958 struct scatterlist src, dst;
1959 struct acomp_req *req;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001960 struct crypto_wait wait;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001961
Eric Biggerseb095592016-11-23 10:24:35 -08001962 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1963 if (!output)
1964 return -ENOMEM;
1965
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001966 decomp_out = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1967 if (!decomp_out) {
1968 kfree(output);
1969 return -ENOMEM;
1970 }
1971
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001972 for (i = 0; i < ctcount; i++) {
1973 unsigned int dlen = COMP_BUF_SIZE;
1974 int ilen = ctemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08001975 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001976
Eric Biggersd2110222016-12-30 14:12:00 -06001977 input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08001978 if (!input_vec) {
1979 ret = -ENOMEM;
1980 goto out;
1981 }
1982
Eric Biggerseb095592016-11-23 10:24:35 -08001983 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001984 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08001985 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001986 sg_init_one(&dst, output, dlen);
1987
1988 req = acomp_request_alloc(tfm);
1989 if (!req) {
1990 pr_err("alg: acomp: request alloc failed for %s\n",
1991 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08001992 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001993 ret = -ENOMEM;
1994 goto out;
1995 }
1996
1997 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1998 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001999 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002000
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002001 ret = crypto_wait_req(crypto_acomp_compress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002002 if (ret) {
2003 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
2004 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08002005 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002006 acomp_request_free(req);
2007 goto out;
2008 }
2009
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002010 ilen = req->dlen;
2011 dlen = COMP_BUF_SIZE;
2012 sg_init_one(&src, output, ilen);
2013 sg_init_one(&dst, decomp_out, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002014 crypto_init_wait(&wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002015 acomp_request_set_params(req, &src, &dst, ilen, dlen);
2016
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002017 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002018 if (ret) {
2019 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
2020 i + 1, algo, -ret);
2021 kfree(input_vec);
2022 acomp_request_free(req);
2023 goto out;
2024 }
2025
2026 if (req->dlen != ctemplate[i].inlen) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002027 pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
2028 i + 1, algo, req->dlen);
2029 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002030 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002031 acomp_request_free(req);
2032 goto out;
2033 }
2034
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002035 if (memcmp(input_vec, decomp_out, req->dlen)) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002036 pr_err("alg: acomp: Compression test %d failed for %s\n",
2037 i + 1, algo);
2038 hexdump(output, req->dlen);
2039 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002040 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002041 acomp_request_free(req);
2042 goto out;
2043 }
2044
Laura Abbott02608e02016-12-21 12:32:54 -08002045 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002046 acomp_request_free(req);
2047 }
2048
2049 for (i = 0; i < dtcount; i++) {
2050 unsigned int dlen = COMP_BUF_SIZE;
2051 int ilen = dtemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08002052 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002053
Eric Biggersd2110222016-12-30 14:12:00 -06002054 input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08002055 if (!input_vec) {
2056 ret = -ENOMEM;
2057 goto out;
2058 }
2059
Eric Biggerseb095592016-11-23 10:24:35 -08002060 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002061 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08002062 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002063 sg_init_one(&dst, output, dlen);
2064
2065 req = acomp_request_alloc(tfm);
2066 if (!req) {
2067 pr_err("alg: acomp: request alloc failed for %s\n",
2068 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08002069 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002070 ret = -ENOMEM;
2071 goto out;
2072 }
2073
2074 acomp_request_set_params(req, &src, &dst, ilen, dlen);
2075 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002076 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002077
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002078 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002079 if (ret) {
2080 pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
2081 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08002082 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002083 acomp_request_free(req);
2084 goto out;
2085 }
2086
2087 if (req->dlen != dtemplate[i].outlen) {
2088 pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
2089 i + 1, algo, req->dlen);
2090 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002091 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002092 acomp_request_free(req);
2093 goto out;
2094 }
2095
2096 if (memcmp(output, dtemplate[i].output, req->dlen)) {
2097 pr_err("alg: acomp: Decompression test %d failed for %s\n",
2098 i + 1, algo);
2099 hexdump(output, req->dlen);
2100 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002101 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002102 acomp_request_free(req);
2103 goto out;
2104 }
2105
Laura Abbott02608e02016-12-21 12:32:54 -08002106 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002107 acomp_request_free(req);
2108 }
2109
2110 ret = 0;
2111
2112out:
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002113 kfree(decomp_out);
Eric Biggerseb095592016-11-23 10:24:35 -08002114 kfree(output);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002115 return ret;
2116}
2117
Eric Biggersb13b1e02017-02-24 15:46:59 -08002118static int test_cprng(struct crypto_rng *tfm,
2119 const struct cprng_testvec *template,
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002120 unsigned int tcount)
2121{
2122 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08002123 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002124 u8 *seed;
2125 char result[32];
2126
2127 seedsize = crypto_rng_seedsize(tfm);
2128
2129 seed = kmalloc(seedsize, GFP_KERNEL);
2130 if (!seed) {
2131 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
2132 "for %s\n", algo);
2133 return -ENOMEM;
2134 }
2135
2136 for (i = 0; i < tcount; i++) {
2137 memset(result, 0, 32);
2138
2139 memcpy(seed, template[i].v, template[i].vlen);
2140 memcpy(seed + template[i].vlen, template[i].key,
2141 template[i].klen);
2142 memcpy(seed + template[i].vlen + template[i].klen,
2143 template[i].dt, template[i].dtlen);
2144
2145 err = crypto_rng_reset(tfm, seed, seedsize);
2146 if (err) {
2147 printk(KERN_ERR "alg: cprng: Failed to reset rng "
2148 "for %s\n", algo);
2149 goto out;
2150 }
2151
2152 for (j = 0; j < template[i].loops; j++) {
2153 err = crypto_rng_get_bytes(tfm, result,
2154 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01002155 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002156 printk(KERN_ERR "alg: cprng: Failed to obtain "
2157 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01002158 "%s (requested %d)\n", algo,
2159 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002160 goto out;
2161 }
2162 }
2163
2164 err = memcmp(result, template[i].result,
2165 template[i].rlen);
2166 if (err) {
2167 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
2168 i, algo);
2169 hexdump(result, template[i].rlen);
2170 err = -EINVAL;
2171 goto out;
2172 }
2173 }
2174
2175out:
2176 kfree(seed);
2177 return err;
2178}
2179
Herbert Xuda7f0332008-07-31 17:08:25 +08002180static int alg_test_cipher(const struct alg_test_desc *desc,
2181 const char *driver, u32 type, u32 mask)
2182{
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002183 const struct cipher_test_suite *suite = &desc->suite.cipher;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002184 struct crypto_cipher *tfm;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002185 int err;
Herbert Xuda7f0332008-07-31 17:08:25 +08002186
Herbert Xueed93e02016-11-22 20:08:31 +08002187 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08002188 if (IS_ERR(tfm)) {
2189 printk(KERN_ERR "alg: cipher: Failed to load transform for "
2190 "%s: %ld\n", driver, PTR_ERR(tfm));
2191 return PTR_ERR(tfm);
2192 }
2193
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002194 err = test_cipher(tfm, ENCRYPT, suite->vecs, suite->count);
2195 if (!err)
2196 err = test_cipher(tfm, DECRYPT, suite->vecs, suite->count);
Herbert Xuda7f0332008-07-31 17:08:25 +08002197
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002198 crypto_free_cipher(tfm);
2199 return err;
2200}
2201
Herbert Xuda7f0332008-07-31 17:08:25 +08002202static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
2203 u32 type, u32 mask)
2204{
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002205 struct crypto_comp *comp;
2206 struct crypto_acomp *acomp;
Herbert Xuda7f0332008-07-31 17:08:25 +08002207 int err;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002208 u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
Herbert Xuda7f0332008-07-31 17:08:25 +08002209
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002210 if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
2211 acomp = crypto_alloc_acomp(driver, type, mask);
2212 if (IS_ERR(acomp)) {
2213 pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
2214 driver, PTR_ERR(acomp));
2215 return PTR_ERR(acomp);
2216 }
2217 err = test_acomp(acomp, desc->suite.comp.comp.vecs,
2218 desc->suite.comp.decomp.vecs,
2219 desc->suite.comp.comp.count,
2220 desc->suite.comp.decomp.count);
2221 crypto_free_acomp(acomp);
2222 } else {
2223 comp = crypto_alloc_comp(driver, type, mask);
2224 if (IS_ERR(comp)) {
2225 pr_err("alg: comp: Failed to load transform for %s: %ld\n",
2226 driver, PTR_ERR(comp));
2227 return PTR_ERR(comp);
2228 }
2229
2230 err = test_comp(comp, desc->suite.comp.comp.vecs,
2231 desc->suite.comp.decomp.vecs,
2232 desc->suite.comp.comp.count,
2233 desc->suite.comp.decomp.count);
2234
2235 crypto_free_comp(comp);
Herbert Xuda7f0332008-07-31 17:08:25 +08002236 }
Herbert Xuda7f0332008-07-31 17:08:25 +08002237 return err;
2238}
2239
Herbert Xu8e3ee852008-11-07 14:58:52 +08002240static int alg_test_crc32c(const struct alg_test_desc *desc,
2241 const char *driver, u32 type, u32 mask)
2242{
2243 struct crypto_shash *tfm;
Eric Biggerscb9dde82019-01-10 12:17:55 -08002244 __le32 val;
Herbert Xu8e3ee852008-11-07 14:58:52 +08002245 int err;
2246
2247 err = alg_test_hash(desc, driver, type, mask);
2248 if (err)
Eric Biggerseb5e6732019-01-23 20:57:35 -08002249 return err;
Herbert Xu8e3ee852008-11-07 14:58:52 +08002250
Herbert Xueed93e02016-11-22 20:08:31 +08002251 tfm = crypto_alloc_shash(driver, type, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002252 if (IS_ERR(tfm)) {
Eric Biggerseb5e6732019-01-23 20:57:35 -08002253 if (PTR_ERR(tfm) == -ENOENT) {
2254 /*
2255 * This crc32c implementation is only available through
2256 * ahash API, not the shash API, so the remaining part
2257 * of the test is not applicable to it.
2258 */
2259 return 0;
2260 }
Herbert Xu8e3ee852008-11-07 14:58:52 +08002261 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
2262 "%ld\n", driver, PTR_ERR(tfm));
Eric Biggerseb5e6732019-01-23 20:57:35 -08002263 return PTR_ERR(tfm);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002264 }
2265
2266 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02002267 SHASH_DESC_ON_STACK(shash, tfm);
2268 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002269
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02002270 shash->tfm = tfm;
2271 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08002272
Eric Biggerscb9dde82019-01-10 12:17:55 -08002273 *ctx = 420553207;
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02002274 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002275 if (err) {
2276 printk(KERN_ERR "alg: crc32c: Operation failed for "
2277 "%s: %d\n", driver, err);
2278 break;
2279 }
2280
Eric Biggerscb9dde82019-01-10 12:17:55 -08002281 if (val != cpu_to_le32(~420553207)) {
2282 pr_err("alg: crc32c: Test failed for %s: %u\n",
2283 driver, le32_to_cpu(val));
Herbert Xu8e3ee852008-11-07 14:58:52 +08002284 err = -EINVAL;
2285 }
2286 } while (0);
2287
2288 crypto_free_shash(tfm);
2289
Herbert Xu8e3ee852008-11-07 14:58:52 +08002290 return err;
2291}
2292
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002293static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
2294 u32 type, u32 mask)
2295{
2296 struct crypto_rng *rng;
2297 int err;
2298
Herbert Xueed93e02016-11-22 20:08:31 +08002299 rng = crypto_alloc_rng(driver, type, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002300 if (IS_ERR(rng)) {
2301 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
2302 "%ld\n", driver, PTR_ERR(rng));
2303 return PTR_ERR(rng);
2304 }
2305
2306 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
2307
2308 crypto_free_rng(rng);
2309
2310 return err;
2311}
2312
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002313
Eric Biggersb13b1e02017-02-24 15:46:59 -08002314static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002315 const char *driver, u32 type, u32 mask)
2316{
2317 int ret = -EAGAIN;
2318 struct crypto_rng *drng;
2319 struct drbg_test_data test_data;
2320 struct drbg_string addtl, pers, testentropy;
2321 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
2322
2323 if (!buf)
2324 return -ENOMEM;
2325
Herbert Xueed93e02016-11-22 20:08:31 +08002326 drng = crypto_alloc_rng(driver, type, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002327 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002328 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002329 "%s\n", driver);
2330 kzfree(buf);
2331 return -ENOMEM;
2332 }
2333
2334 test_data.testentropy = &testentropy;
2335 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
2336 drbg_string_fill(&pers, test->pers, test->perslen);
2337 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
2338 if (ret) {
2339 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
2340 goto outbuf;
2341 }
2342
2343 drbg_string_fill(&addtl, test->addtla, test->addtllen);
2344 if (pr) {
2345 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
2346 ret = crypto_drbg_get_bytes_addtl_test(drng,
2347 buf, test->expectedlen, &addtl, &test_data);
2348 } else {
2349 ret = crypto_drbg_get_bytes_addtl(drng,
2350 buf, test->expectedlen, &addtl);
2351 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01002352 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002353 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002354 "driver %s\n", driver);
2355 goto outbuf;
2356 }
2357
2358 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
2359 if (pr) {
2360 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
2361 ret = crypto_drbg_get_bytes_addtl_test(drng,
2362 buf, test->expectedlen, &addtl, &test_data);
2363 } else {
2364 ret = crypto_drbg_get_bytes_addtl(drng,
2365 buf, test->expectedlen, &addtl);
2366 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01002367 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002368 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002369 "driver %s\n", driver);
2370 goto outbuf;
2371 }
2372
2373 ret = memcmp(test->expected, buf, test->expectedlen);
2374
2375outbuf:
2376 crypto_free_rng(drng);
2377 kzfree(buf);
2378 return ret;
2379}
2380
2381
2382static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
2383 u32 type, u32 mask)
2384{
2385 int err = 0;
2386 int pr = 0;
2387 int i = 0;
Eric Biggersb13b1e02017-02-24 15:46:59 -08002388 const struct drbg_testvec *template = desc->suite.drbg.vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002389 unsigned int tcount = desc->suite.drbg.count;
2390
2391 if (0 == memcmp(driver, "drbg_pr_", 8))
2392 pr = 1;
2393
2394 for (i = 0; i < tcount; i++) {
2395 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
2396 if (err) {
2397 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
2398 i, driver);
2399 err = -EINVAL;
2400 break;
2401 }
2402 }
2403 return err;
2404
2405}
2406
Eric Biggersb13b1e02017-02-24 15:46:59 -08002407static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002408 const char *alg)
2409{
2410 struct kpp_request *req;
2411 void *input_buf = NULL;
2412 void *output_buf = NULL;
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002413 void *a_public = NULL;
2414 void *a_ss = NULL;
2415 void *shared_secret = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002416 struct crypto_wait wait;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002417 unsigned int out_len_max;
2418 int err = -ENOMEM;
2419 struct scatterlist src, dst;
2420
2421 req = kpp_request_alloc(tfm, GFP_KERNEL);
2422 if (!req)
2423 return err;
2424
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002425 crypto_init_wait(&wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002426
2427 err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
2428 if (err < 0)
2429 goto free_req;
2430
2431 out_len_max = crypto_kpp_maxsize(tfm);
2432 output_buf = kzalloc(out_len_max, GFP_KERNEL);
2433 if (!output_buf) {
2434 err = -ENOMEM;
2435 goto free_req;
2436 }
2437
2438 /* Use appropriate parameter as base */
2439 kpp_request_set_input(req, NULL, 0);
2440 sg_init_one(&dst, output_buf, out_len_max);
2441 kpp_request_set_output(req, &dst, out_len_max);
2442 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002443 crypto_req_done, &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002444
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002445 /* Compute party A's public key */
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002446 err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002447 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002448 pr_err("alg: %s: Party A: generate public key test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002449 alg, err);
2450 goto free_output;
2451 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002452
2453 if (vec->genkey) {
2454 /* Save party A's public key */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05002455 a_public = kmemdup(sg_virt(req->dst), out_len_max, GFP_KERNEL);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002456 if (!a_public) {
2457 err = -ENOMEM;
2458 goto free_output;
2459 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002460 } else {
2461 /* Verify calculated public key */
2462 if (memcmp(vec->expected_a_public, sg_virt(req->dst),
2463 vec->expected_a_public_size)) {
2464 pr_err("alg: %s: Party A: generate public key test failed. Invalid output\n",
2465 alg);
2466 err = -EINVAL;
2467 goto free_output;
2468 }
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002469 }
2470
2471 /* Calculate shared secret key by using counter part (b) public key. */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05002472 input_buf = kmemdup(vec->b_public, vec->b_public_size, GFP_KERNEL);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002473 if (!input_buf) {
2474 err = -ENOMEM;
2475 goto free_output;
2476 }
2477
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002478 sg_init_one(&src, input_buf, vec->b_public_size);
2479 sg_init_one(&dst, output_buf, out_len_max);
2480 kpp_request_set_input(req, &src, vec->b_public_size);
2481 kpp_request_set_output(req, &dst, out_len_max);
2482 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002483 crypto_req_done, &wait);
2484 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002485 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002486 pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002487 alg, err);
2488 goto free_all;
2489 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002490
2491 if (vec->genkey) {
2492 /* Save the shared secret obtained by party A */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05002493 a_ss = kmemdup(sg_virt(req->dst), vec->expected_ss_size, GFP_KERNEL);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002494 if (!a_ss) {
2495 err = -ENOMEM;
2496 goto free_all;
2497 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002498
2499 /*
2500 * Calculate party B's shared secret by using party A's
2501 * public key.
2502 */
2503 err = crypto_kpp_set_secret(tfm, vec->b_secret,
2504 vec->b_secret_size);
2505 if (err < 0)
2506 goto free_all;
2507
2508 sg_init_one(&src, a_public, vec->expected_a_public_size);
2509 sg_init_one(&dst, output_buf, out_len_max);
2510 kpp_request_set_input(req, &src, vec->expected_a_public_size);
2511 kpp_request_set_output(req, &dst, out_len_max);
2512 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002513 crypto_req_done, &wait);
2514 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req),
2515 &wait);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002516 if (err) {
2517 pr_err("alg: %s: Party B: compute shared secret failed. err %d\n",
2518 alg, err);
2519 goto free_all;
2520 }
2521
2522 shared_secret = a_ss;
2523 } else {
2524 shared_secret = (void *)vec->expected_ss;
2525 }
2526
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002527 /*
2528 * verify shared secret from which the user will derive
2529 * secret key by executing whatever hash it has chosen
2530 */
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002531 if (memcmp(shared_secret, sg_virt(req->dst),
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002532 vec->expected_ss_size)) {
2533 pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
2534 alg);
2535 err = -EINVAL;
2536 }
2537
2538free_all:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002539 kfree(a_ss);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002540 kfree(input_buf);
2541free_output:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002542 kfree(a_public);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002543 kfree(output_buf);
2544free_req:
2545 kpp_request_free(req);
2546 return err;
2547}
2548
2549static int test_kpp(struct crypto_kpp *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002550 const struct kpp_testvec *vecs, unsigned int tcount)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002551{
2552 int ret, i;
2553
2554 for (i = 0; i < tcount; i++) {
2555 ret = do_test_kpp(tfm, vecs++, alg);
2556 if (ret) {
2557 pr_err("alg: %s: test failed on vector %d, err=%d\n",
2558 alg, i + 1, ret);
2559 return ret;
2560 }
2561 }
2562 return 0;
2563}
2564
2565static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
2566 u32 type, u32 mask)
2567{
2568 struct crypto_kpp *tfm;
2569 int err = 0;
2570
Herbert Xueed93e02016-11-22 20:08:31 +08002571 tfm = crypto_alloc_kpp(driver, type, mask);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002572 if (IS_ERR(tfm)) {
2573 pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
2574 driver, PTR_ERR(tfm));
2575 return PTR_ERR(tfm);
2576 }
2577 if (desc->suite.kpp.vecs)
2578 err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
2579 desc->suite.kpp.count);
2580
2581 crypto_free_kpp(tfm);
2582 return err;
2583}
2584
Herbert Xu50d2b6432016-06-29 19:32:20 +08002585static int test_akcipher_one(struct crypto_akcipher *tfm,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002586 const struct akcipher_testvec *vecs)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002587{
Herbert Xudf27b262016-05-05 16:42:49 +08002588 char *xbuf[XBUFSIZE];
Tadeusz Struk946cc462015-06-16 10:31:06 -07002589 struct akcipher_request *req;
2590 void *outbuf_enc = NULL;
2591 void *outbuf_dec = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002592 struct crypto_wait wait;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002593 unsigned int out_len_max, out_len = 0;
2594 int err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002595 struct scatterlist src, dst, src_tab[2];
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002596 const char *m, *c;
2597 unsigned int m_size, c_size;
2598 const char *op;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002599
Herbert Xudf27b262016-05-05 16:42:49 +08002600 if (testmgr_alloc_buf(xbuf))
2601 return err;
2602
Tadeusz Struk946cc462015-06-16 10:31:06 -07002603 req = akcipher_request_alloc(tfm, GFP_KERNEL);
2604 if (!req)
Herbert Xudf27b262016-05-05 16:42:49 +08002605 goto free_xbuf;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002606
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002607 crypto_init_wait(&wait);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002608
2609 if (vecs->public_key_vec)
2610 err = crypto_akcipher_set_pub_key(tfm, vecs->key,
2611 vecs->key_len);
2612 else
2613 err = crypto_akcipher_set_priv_key(tfm, vecs->key,
2614 vecs->key_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002615 if (err)
2616 goto free_req;
2617
Salvatore Benedetto57763f52016-07-04 10:52:34 +01002618 err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002619 out_len_max = crypto_akcipher_maxsize(tfm);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002620
2621 /*
2622 * First run test which do not require a private key, such as
2623 * encrypt or verify.
2624 */
Tadeusz Struk946cc462015-06-16 10:31:06 -07002625 outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
2626 if (!outbuf_enc)
2627 goto free_req;
2628
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002629 if (!vecs->siggen_sigver_test) {
2630 m = vecs->m;
2631 m_size = vecs->m_size;
2632 c = vecs->c;
2633 c_size = vecs->c_size;
2634 op = "encrypt";
2635 } else {
2636 /* Swap args so we could keep plaintext (digest)
2637 * in vecs->m, and cooked signature in vecs->c.
2638 */
2639 m = vecs->c; /* signature */
2640 m_size = vecs->c_size;
2641 c = vecs->m; /* digest */
2642 c_size = vecs->m_size;
2643 op = "verify";
2644 }
Herbert Xudf27b262016-05-05 16:42:49 +08002645
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002646 if (WARN_ON(m_size > PAGE_SIZE))
2647 goto free_all;
2648 memcpy(xbuf[0], m, m_size);
Herbert Xudf27b262016-05-05 16:42:49 +08002649
Tadeusz Struk22287b02015-10-08 09:26:55 -07002650 sg_init_table(src_tab, 2);
Herbert Xudf27b262016-05-05 16:42:49 +08002651 sg_set_buf(&src_tab[0], xbuf[0], 8);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002652 sg_set_buf(&src_tab[1], xbuf[0] + 8, m_size - 8);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002653 sg_init_one(&dst, outbuf_enc, out_len_max);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002654 akcipher_request_set_crypt(req, src_tab, &dst, m_size,
Tadeusz Struk22287b02015-10-08 09:26:55 -07002655 out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002656 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002657 crypto_req_done, &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002658
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002659 err = crypto_wait_req(vecs->siggen_sigver_test ?
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002660 /* Run asymmetric signature verification */
2661 crypto_akcipher_verify(req) :
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002662 /* Run asymmetric encrypt */
2663 crypto_akcipher_encrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002664 if (err) {
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002665 pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002666 goto free_all;
2667 }
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002668 if (req->dst_len != c_size) {
2669 pr_err("alg: akcipher: %s test failed. Invalid output len\n",
2670 op);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002671 err = -EINVAL;
2672 goto free_all;
2673 }
2674 /* verify that encrypted message is equal to expected */
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002675 if (memcmp(c, outbuf_enc, c_size)) {
2676 pr_err("alg: akcipher: %s test failed. Invalid output\n", op);
2677 hexdump(outbuf_enc, c_size);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002678 err = -EINVAL;
2679 goto free_all;
2680 }
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002681
2682 /*
2683 * Don't invoke (decrypt or sign) test which require a private key
2684 * for vectors with only a public key.
2685 */
Tadeusz Struk946cc462015-06-16 10:31:06 -07002686 if (vecs->public_key_vec) {
2687 err = 0;
2688 goto free_all;
2689 }
2690 outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
2691 if (!outbuf_dec) {
2692 err = -ENOMEM;
2693 goto free_all;
2694 }
Herbert Xudf27b262016-05-05 16:42:49 +08002695
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002696 op = vecs->siggen_sigver_test ? "sign" : "decrypt";
2697 if (WARN_ON(c_size > PAGE_SIZE))
Herbert Xudf27b262016-05-05 16:42:49 +08002698 goto free_all;
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002699 memcpy(xbuf[0], c, c_size);
Herbert Xudf27b262016-05-05 16:42:49 +08002700
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002701 sg_init_one(&src, xbuf[0], c_size);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002702 sg_init_one(&dst, outbuf_dec, out_len_max);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002703 crypto_init_wait(&wait);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002704 akcipher_request_set_crypt(req, &src, &dst, c_size, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002705
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002706 err = crypto_wait_req(vecs->siggen_sigver_test ?
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002707 /* Run asymmetric signature generation */
2708 crypto_akcipher_sign(req) :
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002709 /* Run asymmetric decrypt */
2710 crypto_akcipher_decrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002711 if (err) {
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002712 pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002713 goto free_all;
2714 }
2715 out_len = req->dst_len;
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002716 if (out_len < m_size) {
2717 pr_err("alg: akcipher: %s test failed. Invalid output len %u\n",
2718 op, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002719 err = -EINVAL;
2720 goto free_all;
2721 }
2722 /* verify that decrypted message is equal to the original msg */
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002723 if (memchr_inv(outbuf_dec, 0, out_len - m_size) ||
2724 memcmp(m, outbuf_dec + out_len - m_size, m_size)) {
2725 pr_err("alg: akcipher: %s test failed. Invalid output\n", op);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002726 hexdump(outbuf_dec, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002727 err = -EINVAL;
2728 }
2729free_all:
2730 kfree(outbuf_dec);
2731 kfree(outbuf_enc);
2732free_req:
2733 akcipher_request_free(req);
Herbert Xudf27b262016-05-05 16:42:49 +08002734free_xbuf:
2735 testmgr_free_buf(xbuf);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002736 return err;
2737}
2738
Herbert Xu50d2b6432016-06-29 19:32:20 +08002739static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002740 const struct akcipher_testvec *vecs,
2741 unsigned int tcount)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002742{
Herbert Xu15226e42016-07-18 18:20:10 +08002743 const char *algo =
2744 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
Tadeusz Struk946cc462015-06-16 10:31:06 -07002745 int ret, i;
2746
2747 for (i = 0; i < tcount; i++) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002748 ret = test_akcipher_one(tfm, vecs++);
2749 if (!ret)
2750 continue;
2751
Herbert Xu15226e42016-07-18 18:20:10 +08002752 pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
2753 i + 1, algo, ret);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002754 return ret;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002755 }
2756 return 0;
2757}
2758
Tadeusz Struk946cc462015-06-16 10:31:06 -07002759static int alg_test_akcipher(const struct alg_test_desc *desc,
2760 const char *driver, u32 type, u32 mask)
2761{
2762 struct crypto_akcipher *tfm;
2763 int err = 0;
2764
Herbert Xueed93e02016-11-22 20:08:31 +08002765 tfm = crypto_alloc_akcipher(driver, type, mask);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002766 if (IS_ERR(tfm)) {
2767 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
2768 driver, PTR_ERR(tfm));
2769 return PTR_ERR(tfm);
2770 }
2771 if (desc->suite.akcipher.vecs)
2772 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
2773 desc->suite.akcipher.count);
2774
2775 crypto_free_akcipher(tfm);
2776 return err;
2777}
2778
Youquan, Song863b5572009-12-23 19:45:20 +08002779static int alg_test_null(const struct alg_test_desc *desc,
2780 const char *driver, u32 type, u32 mask)
2781{
2782 return 0;
2783}
2784
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002785#define __VECS(tv) { .vecs = tv, .count = ARRAY_SIZE(tv) }
2786
Herbert Xuda7f0332008-07-31 17:08:25 +08002787/* Please keep this list sorted by algorithm name. */
2788static const struct alg_test_desc alg_test_descs[] = {
2789 {
Eric Biggers059c2a42018-11-16 17:26:31 -08002790 .alg = "adiantum(xchacha12,aes)",
2791 .test = alg_test_skcipher,
2792 .suite = {
2793 .cipher = __VECS(adiantum_xchacha12_aes_tv_template)
2794 },
2795 }, {
2796 .alg = "adiantum(xchacha20,aes)",
2797 .test = alg_test_skcipher,
2798 .suite = {
2799 .cipher = __VECS(adiantum_xchacha20_aes_tv_template)
2800 },
2801 }, {
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002802 .alg = "aegis128",
2803 .test = alg_test_aead,
2804 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002805 .aead = __VECS(aegis128_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002806 }
2807 }, {
2808 .alg = "aegis128l",
2809 .test = alg_test_aead,
2810 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002811 .aead = __VECS(aegis128l_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002812 }
2813 }, {
2814 .alg = "aegis256",
2815 .test = alg_test_aead,
2816 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002817 .aead = __VECS(aegis256_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002818 }
2819 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002820 .alg = "ansi_cprng",
2821 .test = alg_test_cprng,
2822 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002823 .cprng = __VECS(ansi_cprng_aes_tv_template)
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002824 }
2825 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002826 .alg = "authenc(hmac(md5),ecb(cipher_null))",
2827 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002828 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002829 .aead = __VECS(hmac_md5_ecb_cipher_null_tv_template)
Horia Geantabca4feb2014-03-14 17:46:51 +02002830 }
2831 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002832 .alg = "authenc(hmac(sha1),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002833 .test = alg_test_aead,
Herbert Xubcf741c2017-06-28 19:09:07 +08002834 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002835 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002836 .aead = __VECS(hmac_sha1_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302837 }
2838 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002839 .alg = "authenc(hmac(sha1),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302840 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302841 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002842 .aead = __VECS(hmac_sha1_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302843 }
2844 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002845 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302846 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002847 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302848 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002849 .aead = __VECS(hmac_sha1_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002850 }
2851 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002852 .alg = "authenc(hmac(sha1),ctr(aes))",
2853 .test = alg_test_null,
2854 .fips_allowed = 1,
2855 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002856 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
2857 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002858 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002859 .aead = __VECS(hmac_sha1_ecb_cipher_null_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302860 }
2861 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002862 .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
2863 .test = alg_test_null,
2864 .fips_allowed = 1,
2865 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002866 .alg = "authenc(hmac(sha224),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302867 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302868 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002869 .aead = __VECS(hmac_sha224_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302870 }
2871 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002872 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302873 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002874 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302875 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002876 .aead = __VECS(hmac_sha224_des3_ede_cbc_tv_temp)
Horia Geantabca4feb2014-03-14 17:46:51 +02002877 }
2878 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002879 .alg = "authenc(hmac(sha256),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002880 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002881 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002882 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002883 .aead = __VECS(hmac_sha256_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302884 }
2885 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002886 .alg = "authenc(hmac(sha256),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302887 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302888 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002889 .aead = __VECS(hmac_sha256_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302890 }
2891 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002892 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302893 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002894 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302895 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002896 .aead = __VECS(hmac_sha256_des3_ede_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302897 }
2898 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002899 .alg = "authenc(hmac(sha256),ctr(aes))",
2900 .test = alg_test_null,
2901 .fips_allowed = 1,
2902 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002903 .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
2904 .test = alg_test_null,
2905 .fips_allowed = 1,
2906 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002907 .alg = "authenc(hmac(sha384),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302908 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302909 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002910 .aead = __VECS(hmac_sha384_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302911 }
2912 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002913 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302914 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002915 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302916 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002917 .aead = __VECS(hmac_sha384_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002918 }
2919 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002920 .alg = "authenc(hmac(sha384),ctr(aes))",
2921 .test = alg_test_null,
2922 .fips_allowed = 1,
2923 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002924 .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
2925 .test = alg_test_null,
2926 .fips_allowed = 1,
2927 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002928 .alg = "authenc(hmac(sha512),cbc(aes))",
Marcus Meissnered1afac2016-02-05 14:23:33 +01002929 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002930 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002931 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002932 .aead = __VECS(hmac_sha512_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302933 }
2934 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002935 .alg = "authenc(hmac(sha512),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302936 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302937 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002938 .aead = __VECS(hmac_sha512_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302939 }
2940 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002941 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302942 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002943 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302944 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002945 .aead = __VECS(hmac_sha512_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002946 }
2947 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002948 .alg = "authenc(hmac(sha512),ctr(aes))",
2949 .test = alg_test_null,
2950 .fips_allowed = 1,
2951 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002952 .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
2953 .test = alg_test_null,
2954 .fips_allowed = 1,
2955 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002956 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002957 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002958 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002959 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002960 .cipher = __VECS(aes_cbc_tv_template)
2961 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002962 }, {
2963 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002964 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002965 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002966 .cipher = __VECS(anubis_cbc_tv_template)
2967 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002968 }, {
2969 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002970 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002971 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002972 .cipher = __VECS(bf_cbc_tv_template)
2973 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002974 }, {
2975 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002976 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002977 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002978 .cipher = __VECS(camellia_cbc_tv_template)
2979 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002980 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002981 .alg = "cbc(cast5)",
2982 .test = alg_test_skcipher,
2983 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002984 .cipher = __VECS(cast5_cbc_tv_template)
2985 },
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002986 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002987 .alg = "cbc(cast6)",
2988 .test = alg_test_skcipher,
2989 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002990 .cipher = __VECS(cast6_cbc_tv_template)
2991 },
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002992 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002993 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002994 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002995 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002996 .cipher = __VECS(des_cbc_tv_template)
2997 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002998 }, {
2999 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003000 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003001 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003002 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003003 .cipher = __VECS(des3_ede_cbc_tv_template)
3004 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003005 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003006 /* Same as cbc(aes) except the key is stored in
3007 * hardware secure memory which we reference by index
3008 */
3009 .alg = "cbc(paes)",
3010 .test = alg_test_null,
3011 .fips_allowed = 1,
3012 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003013 .alg = "cbc(serpent)",
3014 .test = alg_test_skcipher,
3015 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003016 .cipher = __VECS(serpent_cbc_tv_template)
3017 },
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003018 }, {
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01003019 .alg = "cbc(sm4)",
3020 .test = alg_test_skcipher,
3021 .suite = {
3022 .cipher = __VECS(sm4_cbc_tv_template)
3023 }
3024 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003025 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003026 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003027 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003028 .cipher = __VECS(tf_cbc_tv_template)
3029 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003030 }, {
Ard Biesheuvel092acf02017-02-03 14:49:35 +00003031 .alg = "cbcmac(aes)",
3032 .fips_allowed = 1,
3033 .test = alg_test_hash,
3034 .suite = {
3035 .hash = __VECS(aes_cbcmac_tv_template)
3036 }
3037 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003038 .alg = "ccm(aes)",
3039 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003040 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003041 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003042 .aead = __VECS(aes_ccm_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003043 }
3044 }, {
Dmitry Eremin-Solenikov7da66672018-10-20 02:01:53 +03003045 .alg = "cfb(aes)",
3046 .test = alg_test_skcipher,
3047 .fips_allowed = 1,
3048 .suite = {
3049 .cipher = __VECS(aes_cfb_tv_template)
3050 },
3051 }, {
Martin Willi3590ebf2015-06-01 13:43:57 +02003052 .alg = "chacha20",
3053 .test = alg_test_skcipher,
3054 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003055 .cipher = __VECS(chacha20_tv_template)
3056 },
Martin Willi3590ebf2015-06-01 13:43:57 +02003057 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003058 .alg = "cmac(aes)",
Stephan Mueller8f183752015-08-19 08:42:07 +02003059 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003060 .test = alg_test_hash,
3061 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003062 .hash = __VECS(aes_cmac128_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003063 }
3064 }, {
3065 .alg = "cmac(des3_ede)",
Stephan Mueller8f183752015-08-19 08:42:07 +02003066 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003067 .test = alg_test_hash,
3068 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003069 .hash = __VECS(des3_ede_cmac64_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003070 }
3071 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003072 .alg = "compress_null",
3073 .test = alg_test_null,
3074 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003075 .alg = "crc32",
3076 .test = alg_test_hash,
Milan Broza8a34412019-01-25 10:31:47 +01003077 .fips_allowed = 1,
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003078 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003079 .hash = __VECS(crc32_tv_template)
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003080 }
3081 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003082 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08003083 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003084 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003085 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003086 .hash = __VECS(crc32c_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003087 }
3088 }, {
Herbert Xu684115212013-09-07 12:56:26 +10003089 .alg = "crct10dif",
3090 .test = alg_test_hash,
3091 .fips_allowed = 1,
3092 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003093 .hash = __VECS(crct10dif_tv_template)
Herbert Xu684115212013-09-07 12:56:26 +10003094 }
3095 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003096 .alg = "ctr(aes)",
3097 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003098 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003099 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003100 .cipher = __VECS(aes_ctr_tv_template)
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003101 }
3102 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03003103 .alg = "ctr(blowfish)",
3104 .test = alg_test_skcipher,
3105 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003106 .cipher = __VECS(bf_ctr_tv_template)
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03003107 }
3108 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003109 .alg = "ctr(camellia)",
3110 .test = alg_test_skcipher,
3111 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003112 .cipher = __VECS(camellia_ctr_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003113 }
3114 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003115 .alg = "ctr(cast5)",
3116 .test = alg_test_skcipher,
3117 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003118 .cipher = __VECS(cast5_ctr_tv_template)
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003119 }
3120 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003121 .alg = "ctr(cast6)",
3122 .test = alg_test_skcipher,
3123 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003124 .cipher = __VECS(cast6_ctr_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003125 }
3126 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03003127 .alg = "ctr(des)",
3128 .test = alg_test_skcipher,
3129 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003130 .cipher = __VECS(des_ctr_tv_template)
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03003131 }
3132 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003133 .alg = "ctr(des3_ede)",
3134 .test = alg_test_skcipher,
Marcelo Cerri0d8da102017-03-20 17:28:05 -03003135 .fips_allowed = 1,
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003136 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003137 .cipher = __VECS(des3_ede_ctr_tv_template)
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003138 }
3139 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003140 /* Same as ctr(aes) except the key is stored in
3141 * hardware secure memory which we reference by index
3142 */
3143 .alg = "ctr(paes)",
3144 .test = alg_test_null,
3145 .fips_allowed = 1,
3146 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003147 .alg = "ctr(serpent)",
3148 .test = alg_test_skcipher,
3149 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003150 .cipher = __VECS(serpent_ctr_tv_template)
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003151 }
3152 }, {
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01003153 .alg = "ctr(sm4)",
3154 .test = alg_test_skcipher,
3155 .suite = {
3156 .cipher = __VECS(sm4_ctr_tv_template)
3157 }
3158 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03003159 .alg = "ctr(twofish)",
3160 .test = alg_test_skcipher,
3161 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003162 .cipher = __VECS(tf_ctr_tv_template)
Jussi Kivilinna573da622011-10-10 23:03:12 +03003163 }
3164 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003165 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003166 .test = alg_test_skcipher,
Gilad Ben-Yossef196ad602018-11-04 10:05:24 +00003167 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003168 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003169 .cipher = __VECS(cts_mode_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003170 }
3171 }, {
3172 .alg = "deflate",
3173 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003174 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003175 .suite = {
3176 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003177 .comp = __VECS(deflate_comp_tv_template),
3178 .decomp = __VECS(deflate_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003179 }
3180 }
3181 }, {
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003182 .alg = "dh",
3183 .test = alg_test_kpp,
3184 .fips_allowed = 1,
3185 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003186 .kpp = __VECS(dh_tv_template)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003187 }
3188 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003189 .alg = "digest_null",
3190 .test = alg_test_null,
3191 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003192 .alg = "drbg_nopr_ctr_aes128",
3193 .test = alg_test_drbg,
3194 .fips_allowed = 1,
3195 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003196 .drbg = __VECS(drbg_nopr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003197 }
3198 }, {
3199 .alg = "drbg_nopr_ctr_aes192",
3200 .test = alg_test_drbg,
3201 .fips_allowed = 1,
3202 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003203 .drbg = __VECS(drbg_nopr_ctr_aes192_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003204 }
3205 }, {
3206 .alg = "drbg_nopr_ctr_aes256",
3207 .test = alg_test_drbg,
3208 .fips_allowed = 1,
3209 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003210 .drbg = __VECS(drbg_nopr_ctr_aes256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003211 }
3212 }, {
3213 /*
3214 * There is no need to specifically test the DRBG with every
3215 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
3216 */
3217 .alg = "drbg_nopr_hmac_sha1",
3218 .fips_allowed = 1,
3219 .test = alg_test_null,
3220 }, {
3221 .alg = "drbg_nopr_hmac_sha256",
3222 .test = alg_test_drbg,
3223 .fips_allowed = 1,
3224 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003225 .drbg = __VECS(drbg_nopr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003226 }
3227 }, {
3228 /* covered by drbg_nopr_hmac_sha256 test */
3229 .alg = "drbg_nopr_hmac_sha384",
3230 .fips_allowed = 1,
3231 .test = alg_test_null,
3232 }, {
3233 .alg = "drbg_nopr_hmac_sha512",
3234 .test = alg_test_null,
3235 .fips_allowed = 1,
3236 }, {
3237 .alg = "drbg_nopr_sha1",
3238 .fips_allowed = 1,
3239 .test = alg_test_null,
3240 }, {
3241 .alg = "drbg_nopr_sha256",
3242 .test = alg_test_drbg,
3243 .fips_allowed = 1,
3244 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003245 .drbg = __VECS(drbg_nopr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003246 }
3247 }, {
3248 /* covered by drbg_nopr_sha256 test */
3249 .alg = "drbg_nopr_sha384",
3250 .fips_allowed = 1,
3251 .test = alg_test_null,
3252 }, {
3253 .alg = "drbg_nopr_sha512",
3254 .fips_allowed = 1,
3255 .test = alg_test_null,
3256 }, {
3257 .alg = "drbg_pr_ctr_aes128",
3258 .test = alg_test_drbg,
3259 .fips_allowed = 1,
3260 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003261 .drbg = __VECS(drbg_pr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003262 }
3263 }, {
3264 /* covered by drbg_pr_ctr_aes128 test */
3265 .alg = "drbg_pr_ctr_aes192",
3266 .fips_allowed = 1,
3267 .test = alg_test_null,
3268 }, {
3269 .alg = "drbg_pr_ctr_aes256",
3270 .fips_allowed = 1,
3271 .test = alg_test_null,
3272 }, {
3273 .alg = "drbg_pr_hmac_sha1",
3274 .fips_allowed = 1,
3275 .test = alg_test_null,
3276 }, {
3277 .alg = "drbg_pr_hmac_sha256",
3278 .test = alg_test_drbg,
3279 .fips_allowed = 1,
3280 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003281 .drbg = __VECS(drbg_pr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003282 }
3283 }, {
3284 /* covered by drbg_pr_hmac_sha256 test */
3285 .alg = "drbg_pr_hmac_sha384",
3286 .fips_allowed = 1,
3287 .test = alg_test_null,
3288 }, {
3289 .alg = "drbg_pr_hmac_sha512",
3290 .test = alg_test_null,
3291 .fips_allowed = 1,
3292 }, {
3293 .alg = "drbg_pr_sha1",
3294 .fips_allowed = 1,
3295 .test = alg_test_null,
3296 }, {
3297 .alg = "drbg_pr_sha256",
3298 .test = alg_test_drbg,
3299 .fips_allowed = 1,
3300 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003301 .drbg = __VECS(drbg_pr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003302 }
3303 }, {
3304 /* covered by drbg_pr_sha256 test */
3305 .alg = "drbg_pr_sha384",
3306 .fips_allowed = 1,
3307 .test = alg_test_null,
3308 }, {
3309 .alg = "drbg_pr_sha512",
3310 .fips_allowed = 1,
3311 .test = alg_test_null,
3312 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003313 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003314 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003315 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003316 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003317 .cipher = __VECS(aes_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003318 }
3319 }, {
3320 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003321 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003322 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003323 .cipher = __VECS(anubis_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003324 }
3325 }, {
3326 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003327 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003328 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003329 .cipher = __VECS(arc4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003330 }
3331 }, {
3332 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003333 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003334 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003335 .cipher = __VECS(bf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003336 }
3337 }, {
3338 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003339 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003340 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003341 .cipher = __VECS(camellia_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003342 }
3343 }, {
3344 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003345 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003346 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003347 .cipher = __VECS(cast5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003348 }
3349 }, {
3350 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003351 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003352 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003353 .cipher = __VECS(cast6_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003354 }
3355 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003356 .alg = "ecb(cipher_null)",
3357 .test = alg_test_null,
Milan Broz6175ca22017-04-21 13:03:06 +02003358 .fips_allowed = 1,
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003359 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003360 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003361 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003362 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003363 .cipher = __VECS(des_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003364 }
3365 }, {
3366 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003367 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003368 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003369 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003370 .cipher = __VECS(des3_ede_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003371 }
3372 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003373 .alg = "ecb(fcrypt)",
3374 .test = alg_test_skcipher,
3375 .suite = {
3376 .cipher = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003377 .vecs = fcrypt_pcbc_tv_template,
3378 .count = 1
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003379 }
3380 }
3381 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003382 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003383 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003384 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003385 .cipher = __VECS(khazad_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003386 }
3387 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003388 /* Same as ecb(aes) except the key is stored in
3389 * hardware secure memory which we reference by index
3390 */
3391 .alg = "ecb(paes)",
3392 .test = alg_test_null,
3393 .fips_allowed = 1,
3394 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003395 .alg = "ecb(seed)",
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(seed_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003399 }
3400 }, {
3401 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003402 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003403 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003404 .cipher = __VECS(serpent_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003405 }
3406 }, {
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00003407 .alg = "ecb(sm4)",
3408 .test = alg_test_skcipher,
3409 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003410 .cipher = __VECS(sm4_tv_template)
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00003411 }
3412 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003413 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003414 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003415 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003416 .cipher = __VECS(tea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003417 }
3418 }, {
3419 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003420 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003421 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003422 .cipher = __VECS(tnepres_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003423 }
3424 }, {
3425 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003426 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003427 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003428 .cipher = __VECS(tf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003429 }
3430 }, {
3431 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003432 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003433 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003434 .cipher = __VECS(xeta_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003435 }
3436 }, {
3437 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003438 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003439 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003440 .cipher = __VECS(xtea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003441 }
3442 }, {
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003443 .alg = "ecdh",
3444 .test = alg_test_kpp,
3445 .fips_allowed = 1,
3446 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003447 .kpp = __VECS(ecdh_tv_template)
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003448 }
3449 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003450 .alg = "gcm(aes)",
3451 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003452 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003453 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003454 .aead = __VECS(aes_gcm_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003455 }
3456 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003457 .alg = "ghash",
3458 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003459 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003460 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003461 .hash = __VECS(ghash_tv_template)
Youquan, Song507069c2009-11-23 20:23:04 +08003462 }
3463 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003464 .alg = "hmac(md5)",
3465 .test = alg_test_hash,
3466 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003467 .hash = __VECS(hmac_md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003468 }
3469 }, {
3470 .alg = "hmac(rmd128)",
3471 .test = alg_test_hash,
3472 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003473 .hash = __VECS(hmac_rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003474 }
3475 }, {
3476 .alg = "hmac(rmd160)",
3477 .test = alg_test_hash,
3478 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003479 .hash = __VECS(hmac_rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003480 }
3481 }, {
3482 .alg = "hmac(sha1)",
3483 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003484 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003485 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003486 .hash = __VECS(hmac_sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003487 }
3488 }, {
3489 .alg = "hmac(sha224)",
3490 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003491 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003492 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003493 .hash = __VECS(hmac_sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003494 }
3495 }, {
3496 .alg = "hmac(sha256)",
3497 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003498 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003499 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003500 .hash = __VECS(hmac_sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003501 }
3502 }, {
raveendra padasalagi98eca722016-07-01 11:16:54 +05303503 .alg = "hmac(sha3-224)",
3504 .test = alg_test_hash,
3505 .fips_allowed = 1,
3506 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003507 .hash = __VECS(hmac_sha3_224_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303508 }
3509 }, {
3510 .alg = "hmac(sha3-256)",
3511 .test = alg_test_hash,
3512 .fips_allowed = 1,
3513 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003514 .hash = __VECS(hmac_sha3_256_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303515 }
3516 }, {
3517 .alg = "hmac(sha3-384)",
3518 .test = alg_test_hash,
3519 .fips_allowed = 1,
3520 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003521 .hash = __VECS(hmac_sha3_384_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303522 }
3523 }, {
3524 .alg = "hmac(sha3-512)",
3525 .test = alg_test_hash,
3526 .fips_allowed = 1,
3527 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003528 .hash = __VECS(hmac_sha3_512_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303529 }
3530 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003531 .alg = "hmac(sha384)",
3532 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003533 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003534 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003535 .hash = __VECS(hmac_sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003536 }
3537 }, {
3538 .alg = "hmac(sha512)",
3539 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003540 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003541 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003542 .hash = __VECS(hmac_sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003543 }
3544 }, {
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03003545 .alg = "hmac(streebog256)",
3546 .test = alg_test_hash,
3547 .suite = {
3548 .hash = __VECS(hmac_streebog256_tv_template)
3549 }
3550 }, {
3551 .alg = "hmac(streebog512)",
3552 .test = alg_test_hash,
3553 .suite = {
3554 .hash = __VECS(hmac_streebog512_tv_template)
3555 }
3556 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003557 .alg = "jitterentropy_rng",
3558 .fips_allowed = 1,
3559 .test = alg_test_null,
3560 }, {
Stephan Mueller35351982015-09-21 20:59:56 +02003561 .alg = "kw(aes)",
3562 .test = alg_test_skcipher,
3563 .fips_allowed = 1,
3564 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003565 .cipher = __VECS(aes_kw_tv_template)
Stephan Mueller35351982015-09-21 20:59:56 +02003566 }
3567 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003568 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003569 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003570 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003571 .cipher = __VECS(aes_lrw_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003572 }
3573 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003574 .alg = "lrw(camellia)",
3575 .test = alg_test_skcipher,
3576 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003577 .cipher = __VECS(camellia_lrw_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003578 }
3579 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003580 .alg = "lrw(cast6)",
3581 .test = alg_test_skcipher,
3582 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003583 .cipher = __VECS(cast6_lrw_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003584 }
3585 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003586 .alg = "lrw(serpent)",
3587 .test = alg_test_skcipher,
3588 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003589 .cipher = __VECS(serpent_lrw_tv_template)
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003590 }
3591 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003592 .alg = "lrw(twofish)",
3593 .test = alg_test_skcipher,
3594 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003595 .cipher = __VECS(tf_lrw_tv_template)
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003596 }
3597 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003598 .alg = "lz4",
3599 .test = alg_test_comp,
3600 .fips_allowed = 1,
3601 .suite = {
3602 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003603 .comp = __VECS(lz4_comp_tv_template),
3604 .decomp = __VECS(lz4_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003605 }
3606 }
3607 }, {
3608 .alg = "lz4hc",
3609 .test = alg_test_comp,
3610 .fips_allowed = 1,
3611 .suite = {
3612 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003613 .comp = __VECS(lz4hc_comp_tv_template),
3614 .decomp = __VECS(lz4hc_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003615 }
3616 }
3617 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003618 .alg = "lzo",
3619 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003620 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003621 .suite = {
3622 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003623 .comp = __VECS(lzo_comp_tv_template),
3624 .decomp = __VECS(lzo_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003625 }
3626 }
3627 }, {
3628 .alg = "md4",
3629 .test = alg_test_hash,
3630 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003631 .hash = __VECS(md4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003632 }
3633 }, {
3634 .alg = "md5",
3635 .test = alg_test_hash,
3636 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003637 .hash = __VECS(md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003638 }
3639 }, {
3640 .alg = "michael_mic",
3641 .test = alg_test_hash,
3642 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003643 .hash = __VECS(michael_mic_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003644 }
3645 }, {
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003646 .alg = "morus1280",
3647 .test = alg_test_aead,
3648 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003649 .aead = __VECS(morus1280_tv_template)
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003650 }
3651 }, {
3652 .alg = "morus640",
3653 .test = alg_test_aead,
3654 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003655 .aead = __VECS(morus640_tv_template)
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003656 }
3657 }, {
Eric Biggers26609a22018-11-16 17:26:29 -08003658 .alg = "nhpoly1305",
3659 .test = alg_test_hash,
3660 .suite = {
3661 .hash = __VECS(nhpoly1305_tv_template)
3662 }
3663 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003664 .alg = "ofb(aes)",
3665 .test = alg_test_skcipher,
3666 .fips_allowed = 1,
3667 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003668 .cipher = __VECS(aes_ofb_tv_template)
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003669 }
3670 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003671 /* Same as ofb(aes) except the key is stored in
3672 * hardware secure memory which we reference by index
3673 */
3674 .alg = "ofb(paes)",
3675 .test = alg_test_null,
3676 .fips_allowed = 1,
3677 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003678 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003679 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003680 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003681 .cipher = __VECS(fcrypt_pcbc_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003682 }
3683 }, {
Stephan Mueller12071072017-06-12 23:27:51 +02003684 .alg = "pkcs1pad(rsa,sha224)",
3685 .test = alg_test_null,
3686 .fips_allowed = 1,
3687 }, {
3688 .alg = "pkcs1pad(rsa,sha256)",
3689 .test = alg_test_akcipher,
3690 .fips_allowed = 1,
3691 .suite = {
3692 .akcipher = __VECS(pkcs1pad_rsa_tv_template)
3693 }
3694 }, {
3695 .alg = "pkcs1pad(rsa,sha384)",
3696 .test = alg_test_null,
3697 .fips_allowed = 1,
3698 }, {
3699 .alg = "pkcs1pad(rsa,sha512)",
3700 .test = alg_test_null,
3701 .fips_allowed = 1,
3702 }, {
Martin Willieee9dc62015-06-01 13:43:59 +02003703 .alg = "poly1305",
3704 .test = alg_test_hash,
3705 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003706 .hash = __VECS(poly1305_tv_template)
Martin Willieee9dc62015-06-01 13:43:59 +02003707 }
3708 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003709 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003710 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003711 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003712 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003713 .cipher = __VECS(aes_ctr_rfc3686_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003714 }
3715 }, {
Herbert Xu3f31a742015-07-09 07:17:34 +08003716 .alg = "rfc4106(gcm(aes))",
Adrian Hoban69435b92010-11-04 15:02:04 -04003717 .test = alg_test_aead,
Jarod Wilsondb71f29a2015-01-23 12:42:15 -05003718 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003719 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003720 .aead = __VECS(aes_gcm_rfc4106_tv_template)
Adrian Hoban69435b92010-11-04 15:02:04 -04003721 }
3722 }, {
Herbert Xu544c4362015-07-14 16:53:22 +08003723 .alg = "rfc4309(ccm(aes))",
Jarod Wilson5d667322009-05-04 19:23:40 +08003724 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003725 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003726 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003727 .aead = __VECS(aes_ccm_rfc4309_tv_template)
Jarod Wilson5d667322009-05-04 19:23:40 +08003728 }
3729 }, {
Herbert Xubb687452015-06-16 13:54:24 +08003730 .alg = "rfc4543(gcm(aes))",
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003731 .test = alg_test_aead,
3732 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003733 .aead = __VECS(aes_gcm_rfc4543_tv_template)
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003734 }
3735 }, {
Martin Williaf2b76b2015-06-01 13:44:01 +02003736 .alg = "rfc7539(chacha20,poly1305)",
3737 .test = alg_test_aead,
3738 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003739 .aead = __VECS(rfc7539_tv_template)
Martin Williaf2b76b2015-06-01 13:44:01 +02003740 }
3741 }, {
Martin Willi59007582015-06-01 13:44:03 +02003742 .alg = "rfc7539esp(chacha20,poly1305)",
3743 .test = alg_test_aead,
3744 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003745 .aead = __VECS(rfc7539esp_tv_template)
Martin Willi59007582015-06-01 13:44:03 +02003746 }
3747 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003748 .alg = "rmd128",
3749 .test = alg_test_hash,
3750 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003751 .hash = __VECS(rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003752 }
3753 }, {
3754 .alg = "rmd160",
3755 .test = alg_test_hash,
3756 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003757 .hash = __VECS(rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003758 }
3759 }, {
3760 .alg = "rmd256",
3761 .test = alg_test_hash,
3762 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003763 .hash = __VECS(rmd256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003764 }
3765 }, {
3766 .alg = "rmd320",
3767 .test = alg_test_hash,
3768 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003769 .hash = __VECS(rmd320_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003770 }
3771 }, {
Tadeusz Struk946cc462015-06-16 10:31:06 -07003772 .alg = "rsa",
3773 .test = alg_test_akcipher,
3774 .fips_allowed = 1,
3775 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003776 .akcipher = __VECS(rsa_tv_template)
Tadeusz Struk946cc462015-06-16 10:31:06 -07003777 }
3778 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003779 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003780 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003781 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003782 .cipher = __VECS(salsa20_stream_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003783 }
3784 }, {
3785 .alg = "sha1",
3786 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003787 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003788 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003789 .hash = __VECS(sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003790 }
3791 }, {
3792 .alg = "sha224",
3793 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003794 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003795 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003796 .hash = __VECS(sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003797 }
3798 }, {
3799 .alg = "sha256",
3800 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003801 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003802 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003803 .hash = __VECS(sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003804 }
3805 }, {
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303806 .alg = "sha3-224",
3807 .test = alg_test_hash,
3808 .fips_allowed = 1,
3809 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003810 .hash = __VECS(sha3_224_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303811 }
3812 }, {
3813 .alg = "sha3-256",
3814 .test = alg_test_hash,
3815 .fips_allowed = 1,
3816 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003817 .hash = __VECS(sha3_256_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303818 }
3819 }, {
3820 .alg = "sha3-384",
3821 .test = alg_test_hash,
3822 .fips_allowed = 1,
3823 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003824 .hash = __VECS(sha3_384_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303825 }
3826 }, {
3827 .alg = "sha3-512",
3828 .test = alg_test_hash,
3829 .fips_allowed = 1,
3830 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003831 .hash = __VECS(sha3_512_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303832 }
3833 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003834 .alg = "sha384",
3835 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003836 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003837 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003838 .hash = __VECS(sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003839 }
3840 }, {
3841 .alg = "sha512",
3842 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003843 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003844 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003845 .hash = __VECS(sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003846 }
3847 }, {
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03003848 .alg = "sm3",
3849 .test = alg_test_hash,
3850 .suite = {
3851 .hash = __VECS(sm3_tv_template)
3852 }
3853 }, {
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03003854 .alg = "streebog256",
3855 .test = alg_test_hash,
3856 .suite = {
3857 .hash = __VECS(streebog256_tv_template)
3858 }
3859 }, {
3860 .alg = "streebog512",
3861 .test = alg_test_hash,
3862 .suite = {
3863 .hash = __VECS(streebog512_tv_template)
3864 }
3865 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003866 .alg = "tgr128",
3867 .test = alg_test_hash,
3868 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003869 .hash = __VECS(tgr128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003870 }
3871 }, {
3872 .alg = "tgr160",
3873 .test = alg_test_hash,
3874 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003875 .hash = __VECS(tgr160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003876 }
3877 }, {
3878 .alg = "tgr192",
3879 .test = alg_test_hash,
3880 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003881 .hash = __VECS(tgr192_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003882 }
3883 }, {
Eric Biggersed331ad2018-06-18 10:22:39 -07003884 .alg = "vmac64(aes)",
3885 .test = alg_test_hash,
3886 .suite = {
3887 .hash = __VECS(vmac64_aes_tv_template)
3888 }
3889 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003890 .alg = "wp256",
3891 .test = alg_test_hash,
3892 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003893 .hash = __VECS(wp256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003894 }
3895 }, {
3896 .alg = "wp384",
3897 .test = alg_test_hash,
3898 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003899 .hash = __VECS(wp384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003900 }
3901 }, {
3902 .alg = "wp512",
3903 .test = alg_test_hash,
3904 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003905 .hash = __VECS(wp512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003906 }
3907 }, {
3908 .alg = "xcbc(aes)",
3909 .test = alg_test_hash,
3910 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003911 .hash = __VECS(aes_xcbc128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003912 }
3913 }, {
Eric Biggersaa762402018-11-16 17:26:22 -08003914 .alg = "xchacha12",
3915 .test = alg_test_skcipher,
3916 .suite = {
3917 .cipher = __VECS(xchacha12_tv_template)
3918 },
3919 }, {
Eric Biggersde61d7a2018-11-16 17:26:20 -08003920 .alg = "xchacha20",
3921 .test = alg_test_skcipher,
3922 .suite = {
3923 .cipher = __VECS(xchacha20_tv_template)
3924 },
3925 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003926 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003927 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003928 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003929 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003930 .cipher = __VECS(aes_xts_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003931 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003932 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003933 .alg = "xts(camellia)",
3934 .test = alg_test_skcipher,
3935 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003936 .cipher = __VECS(camellia_xts_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003937 }
3938 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003939 .alg = "xts(cast6)",
3940 .test = alg_test_skcipher,
3941 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003942 .cipher = __VECS(cast6_xts_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003943 }
3944 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003945 /* Same as xts(aes) except the key is stored in
3946 * hardware secure memory which we reference by index
3947 */
3948 .alg = "xts(paes)",
3949 .test = alg_test_null,
3950 .fips_allowed = 1,
3951 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003952 .alg = "xts(serpent)",
3953 .test = alg_test_skcipher,
3954 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003955 .cipher = __VECS(serpent_xts_tv_template)
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003956 }
3957 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003958 .alg = "xts(twofish)",
3959 .test = alg_test_skcipher,
3960 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003961 .cipher = __VECS(tf_xts_tv_template)
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003962 }
Giovanni Cabiddua368f432017-04-21 21:54:30 +01003963 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003964 .alg = "xts4096(paes)",
3965 .test = alg_test_null,
3966 .fips_allowed = 1,
3967 }, {
3968 .alg = "xts512(paes)",
3969 .test = alg_test_null,
3970 .fips_allowed = 1,
3971 }, {
Giovanni Cabiddua368f432017-04-21 21:54:30 +01003972 .alg = "zlib-deflate",
3973 .test = alg_test_comp,
3974 .fips_allowed = 1,
3975 .suite = {
3976 .comp = {
3977 .comp = __VECS(zlib_deflate_comp_tv_template),
3978 .decomp = __VECS(zlib_deflate_decomp_tv_template)
3979 }
3980 }
Nick Terrelld28fc3d2018-03-30 12:14:53 -07003981 }, {
3982 .alg = "zstd",
3983 .test = alg_test_comp,
3984 .fips_allowed = 1,
3985 .suite = {
3986 .comp = {
3987 .comp = __VECS(zstd_comp_tv_template),
3988 .decomp = __VECS(zstd_decomp_tv_template)
3989 }
3990 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003991 }
3992};
3993
Eric Biggers3f47a032019-01-31 23:51:43 -08003994static void alg_check_test_descs_order(void)
Jussi Kivilinna57147582013-06-13 17:37:40 +03003995{
3996 int i;
3997
Jussi Kivilinna57147582013-06-13 17:37:40 +03003998 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3999 int diff = strcmp(alg_test_descs[i - 1].alg,
4000 alg_test_descs[i].alg);
4001
4002 if (WARN_ON(diff > 0)) {
4003 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
4004 alg_test_descs[i - 1].alg,
4005 alg_test_descs[i].alg);
4006 }
4007
4008 if (WARN_ON(diff == 0)) {
4009 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
4010 alg_test_descs[i].alg);
4011 }
4012 }
4013}
4014
Eric Biggers3f47a032019-01-31 23:51:43 -08004015static void alg_check_testvec_configs(void)
4016{
Eric Biggers4e7babba2019-01-31 23:51:46 -08004017 int i;
4018
4019 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++)
4020 WARN_ON(!valid_testvec_config(
4021 &default_cipher_testvec_configs[i]));
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08004022
4023 for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++)
4024 WARN_ON(!valid_testvec_config(
4025 &default_hash_testvec_configs[i]));
Eric Biggers3f47a032019-01-31 23:51:43 -08004026}
4027
4028static void testmgr_onetime_init(void)
4029{
4030 alg_check_test_descs_order();
4031 alg_check_testvec_configs();
Eric Biggers5b2706a2019-01-31 23:51:44 -08004032
4033#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
4034 pr_warn("alg: extra crypto tests enabled. This is intended for developer use only.\n");
4035#endif
Eric Biggers3f47a032019-01-31 23:51:43 -08004036}
4037
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004038static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08004039{
4040 int start = 0;
4041 int end = ARRAY_SIZE(alg_test_descs);
4042
4043 while (start < end) {
4044 int i = (start + end) / 2;
4045 int diff = strcmp(alg_test_descs[i].alg, alg);
4046
4047 if (diff > 0) {
4048 end = i;
4049 continue;
4050 }
4051
4052 if (diff < 0) {
4053 start = i + 1;
4054 continue;
4055 }
4056
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004057 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08004058 }
4059
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004060 return -1;
4061}
4062
4063int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
4064{
4065 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08004066 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08004067 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004068
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +01004069 if (!fips_enabled && notests) {
4070 printk_once(KERN_INFO "alg: self-tests disabled\n");
4071 return 0;
4072 }
4073
Eric Biggers3f47a032019-01-31 23:51:43 -08004074 DO_ONCE(testmgr_onetime_init);
Jussi Kivilinna57147582013-06-13 17:37:40 +03004075
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004076 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
4077 char nalg[CRYPTO_MAX_ALG_NAME];
4078
4079 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
4080 sizeof(nalg))
4081 return -ENAMETOOLONG;
4082
4083 i = alg_find_test(nalg);
4084 if (i < 0)
4085 goto notest;
4086
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004087 if (fips_enabled && !alg_test_descs[i].fips_allowed)
4088 goto non_fips_alg;
4089
Jarod Wilson941fb322009-05-04 19:49:23 +08004090 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
4091 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004092 }
4093
4094 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08004095 j = alg_find_test(driver);
4096 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004097 goto notest;
4098
Herbert Xua68f6612009-07-02 16:32:12 +08004099 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
4100 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004101 goto non_fips_alg;
4102
Herbert Xua68f6612009-07-02 16:32:12 +08004103 rc = 0;
4104 if (i >= 0)
4105 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
4106 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03004107 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08004108 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
4109 type, mask);
4110
Jarod Wilson941fb322009-05-04 19:49:23 +08004111test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08004112 if (fips_enabled && rc)
4113 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
4114
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004115 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09004116 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004117
Neil Hormand12d6b62008-10-12 20:36:51 +08004118 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004119
4120notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08004121 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
4122 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004123non_fips_alg:
4124 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08004125}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004126
Herbert Xu326a6342010-08-06 09:40:28 +08004127#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004128
Herbert Xuda7f0332008-07-31 17:08:25 +08004129EXPORT_SYMBOL_GPL(alg_test);