blob: 675446157721565f009067a792f4c491dbcca972 [file] [log] [blame]
Herbert Xuda7f0332008-07-31 17:08:25 +08001/*
2 * Algorithm testing framework and tests.
3 *
4 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
5 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
6 * Copyright (c) 2007 Nokia Siemens Networks
7 * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
Eric Biggers3f47a032019-01-31 23:51:43 -08008 * Copyright (c) 2019 Google LLC
Herbert Xuda7f0332008-07-31 17:08:25 +08009 *
Adrian Hoban69435b92010-11-04 15:02:04 -040010 * Updated RFC4106 AES-GCM testing.
11 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
12 * Adrian Hoban <adrian.hoban@intel.com>
13 * Gabriele Paoloni <gabriele.paoloni@intel.com>
14 * Tadeusz Struk (tadeusz.struk@intel.com)
15 * Copyright (c) 2010, Intel Corporation.
16 *
Herbert Xuda7f0332008-07-31 17:08:25 +080017 * This program is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License as published by the Free
19 * Software Foundation; either version 2 of the License, or (at your option)
20 * any later version.
21 *
22 */
23
Herbert Xu1ce33112015-04-22 15:06:31 +080024#include <crypto/aead.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080025#include <crypto/hash.h>
Herbert Xu12773d92015-08-20 15:21:46 +080026#include <crypto/skcipher.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080027#include <linux/err.h>
Herbert Xu1c41b882015-04-22 13:25:58 +080028#include <linux/fips.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080029#include <linux/module.h>
Eric Biggers3f47a032019-01-31 23:51:43 -080030#include <linux/once.h>
Eric Biggers25f9ddd2019-01-31 23:51:45 -080031#include <linux/random.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080032#include <linux/scatterlist.h>
33#include <linux/slab.h>
34#include <linux/string.h>
Jarod Wilson7647d6c2009-05-04 19:44:50 +080035#include <crypto/rng.h>
Stephan Mueller64d1cdf2014-05-31 17:25:36 +020036#include <crypto/drbg.h>
Tadeusz Struk946cc462015-06-16 10:31:06 -070037#include <crypto/akcipher.h>
Salvatore Benedetto802c7f12016-06-22 17:49:14 +010038#include <crypto/kpp.h>
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +010039#include <crypto/acompress.h>
Eric Biggersb55e1a32019-03-12 22:12:47 -070040#include <crypto/internal/simd.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080041
42#include "internal.h"
Alexander Shishkin0b767f92010-06-03 20:53:43 +100043
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +010044static bool notests;
45module_param(notests, bool, 0644);
46MODULE_PARM_DESC(notests, "disable crypto self-tests");
47
Eric Biggerseda69b02019-03-31 13:09:14 -070048static bool panic_on_fail;
49module_param(panic_on_fail, bool, 0444);
50
Eric Biggers5b2706a2019-01-31 23:51:44 -080051#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
52static bool noextratests;
53module_param(noextratests, bool, 0644);
54MODULE_PARM_DESC(noextratests, "disable expensive crypto self-tests");
55
56static unsigned int fuzz_iterations = 100;
57module_param(fuzz_iterations, uint, 0644);
58MODULE_PARM_DESC(fuzz_iterations, "number of fuzz test iterations");
Eric Biggersb55e1a32019-03-12 22:12:47 -070059
60DEFINE_PER_CPU(bool, crypto_simd_disabled_for_test);
61EXPORT_PER_CPU_SYMBOL_GPL(crypto_simd_disabled_for_test);
Eric Biggers5b2706a2019-01-31 23:51:44 -080062#endif
63
Herbert Xu326a6342010-08-06 09:40:28 +080064#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
Alexander Shishkin0b767f92010-06-03 20:53:43 +100065
66/* a perfect nop */
67int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
68{
69 return 0;
70}
71
72#else
73
Herbert Xuda7f0332008-07-31 17:08:25 +080074#include "testmgr.h"
75
76/*
77 * Need slab memory for testing (size in number of pages).
78 */
79#define XBUFSIZE 8
80
81/*
Herbert Xuda7f0332008-07-31 17:08:25 +080082* Used by test_cipher()
83*/
84#define ENCRYPT 1
85#define DECRYPT 0
86
Herbert Xuda7f0332008-07-31 17:08:25 +080087struct aead_test_suite {
Eric Biggersa0d608ee2019-01-13 15:32:28 -080088 const struct aead_testvec *vecs;
89 unsigned int count;
Herbert Xuda7f0332008-07-31 17:08:25 +080090};
91
92struct cipher_test_suite {
Eric Biggers92a4c9f2018-05-20 22:50:29 -070093 const struct cipher_testvec *vecs;
94 unsigned int count;
Herbert Xuda7f0332008-07-31 17:08:25 +080095};
96
97struct comp_test_suite {
98 struct {
Eric Biggersb13b1e02017-02-24 15:46:59 -080099 const struct comp_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +0800100 unsigned int count;
101 } comp, decomp;
102};
103
104struct hash_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800105 const struct hash_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +0800106 unsigned int count;
107};
108
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800109struct cprng_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800110 const struct cprng_testvec *vecs;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800111 unsigned int count;
112};
113
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200114struct drbg_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800115 const struct drbg_testvec *vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200116 unsigned int count;
117};
118
Tadeusz Struk946cc462015-06-16 10:31:06 -0700119struct akcipher_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800120 const struct akcipher_testvec *vecs;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700121 unsigned int count;
122};
123
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100124struct kpp_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800125 const struct kpp_testvec *vecs;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100126 unsigned int count;
127};
128
Herbert Xuda7f0332008-07-31 17:08:25 +0800129struct alg_test_desc {
130 const char *alg;
131 int (*test)(const struct alg_test_desc *desc, const char *driver,
132 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000133 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800134
135 union {
136 struct aead_test_suite aead;
137 struct cipher_test_suite cipher;
138 struct comp_test_suite comp;
139 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800140 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200141 struct drbg_test_suite drbg;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700142 struct akcipher_test_suite akcipher;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100143 struct kpp_test_suite kpp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800144 } suite;
145};
146
Herbert Xuda7f0332008-07-31 17:08:25 +0800147static void hexdump(unsigned char *buf, unsigned int len)
148{
149 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
150 16, 1,
151 buf, len, false);
152}
153
Eric Biggers3f47a032019-01-31 23:51:43 -0800154static int __testmgr_alloc_buf(char *buf[XBUFSIZE], int order)
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800155{
156 int i;
157
158 for (i = 0; i < XBUFSIZE; i++) {
Eric Biggers3f47a032019-01-31 23:51:43 -0800159 buf[i] = (char *)__get_free_pages(GFP_KERNEL, order);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800160 if (!buf[i])
161 goto err_free_buf;
162 }
163
164 return 0;
165
166err_free_buf:
167 while (i-- > 0)
Eric Biggers3f47a032019-01-31 23:51:43 -0800168 free_pages((unsigned long)buf[i], order);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800169
170 return -ENOMEM;
171}
172
Eric Biggers3f47a032019-01-31 23:51:43 -0800173static int testmgr_alloc_buf(char *buf[XBUFSIZE])
174{
175 return __testmgr_alloc_buf(buf, 0);
176}
177
178static void __testmgr_free_buf(char *buf[XBUFSIZE], int order)
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800179{
180 int i;
181
182 for (i = 0; i < XBUFSIZE; i++)
Eric Biggers3f47a032019-01-31 23:51:43 -0800183 free_pages((unsigned long)buf[i], order);
184}
185
186static void testmgr_free_buf(char *buf[XBUFSIZE])
187{
188 __testmgr_free_buf(buf, 0);
189}
190
191#define TESTMGR_POISON_BYTE 0xfe
192#define TESTMGR_POISON_LEN 16
193
194static inline void testmgr_poison(void *addr, size_t len)
195{
196 memset(addr, TESTMGR_POISON_BYTE, len);
197}
198
199/* Is the memory region still fully poisoned? */
200static inline bool testmgr_is_poison(const void *addr, size_t len)
201{
202 return memchr_inv(addr, TESTMGR_POISON_BYTE, len) == NULL;
203}
204
205/* flush type for hash algorithms */
206enum flush_type {
207 /* merge with update of previous buffer(s) */
208 FLUSH_TYPE_NONE = 0,
209
210 /* update with previous buffer(s) before doing this one */
211 FLUSH_TYPE_FLUSH,
212
213 /* likewise, but also export and re-import the intermediate state */
214 FLUSH_TYPE_REIMPORT,
215};
216
217/* finalization function for hash algorithms */
218enum finalization_type {
219 FINALIZATION_TYPE_FINAL, /* use final() */
220 FINALIZATION_TYPE_FINUP, /* use finup() */
221 FINALIZATION_TYPE_DIGEST, /* use digest() */
222};
223
224#define TEST_SG_TOTAL 10000
225
226/**
227 * struct test_sg_division - description of a scatterlist entry
228 *
229 * This struct describes one entry of a scatterlist being constructed to check a
230 * crypto test vector.
231 *
232 * @proportion_of_total: length of this chunk relative to the total length,
233 * given as a proportion out of TEST_SG_TOTAL so that it
234 * scales to fit any test vector
235 * @offset: byte offset into a 2-page buffer at which this chunk will start
236 * @offset_relative_to_alignmask: if true, add the algorithm's alignmask to the
237 * @offset
238 * @flush_type: for hashes, whether an update() should be done now vs.
239 * continuing to accumulate data
Eric Biggers65707372019-03-12 22:12:52 -0700240 * @nosimd: if doing the pending update(), do it with SIMD disabled?
Eric Biggers3f47a032019-01-31 23:51:43 -0800241 */
242struct test_sg_division {
243 unsigned int proportion_of_total;
244 unsigned int offset;
245 bool offset_relative_to_alignmask;
246 enum flush_type flush_type;
Eric Biggers65707372019-03-12 22:12:52 -0700247 bool nosimd;
Eric Biggers3f47a032019-01-31 23:51:43 -0800248};
249
250/**
251 * struct testvec_config - configuration for testing a crypto test vector
252 *
253 * This struct describes the data layout and other parameters with which each
254 * crypto test vector can be tested.
255 *
256 * @name: name of this config, logged for debugging purposes if a test fails
257 * @inplace: operate on the data in-place, if applicable for the algorithm type?
258 * @req_flags: extra request_flags, e.g. CRYPTO_TFM_REQ_MAY_SLEEP
259 * @src_divs: description of how to arrange the source scatterlist
260 * @dst_divs: description of how to arrange the dst scatterlist, if applicable
261 * for the algorithm type. Defaults to @src_divs if unset.
262 * @iv_offset: misalignment of the IV in the range [0..MAX_ALGAPI_ALIGNMASK+1],
263 * where 0 is aligned to a 2*(MAX_ALGAPI_ALIGNMASK+1) byte boundary
264 * @iv_offset_relative_to_alignmask: if true, add the algorithm's alignmask to
265 * the @iv_offset
266 * @finalization_type: what finalization function to use for hashes
Eric Biggers65707372019-03-12 22:12:52 -0700267 * @nosimd: execute with SIMD disabled? Requires !CRYPTO_TFM_REQ_MAY_SLEEP.
Eric Biggers3f47a032019-01-31 23:51:43 -0800268 */
269struct testvec_config {
270 const char *name;
271 bool inplace;
272 u32 req_flags;
273 struct test_sg_division src_divs[XBUFSIZE];
274 struct test_sg_division dst_divs[XBUFSIZE];
275 unsigned int iv_offset;
276 bool iv_offset_relative_to_alignmask;
277 enum finalization_type finalization_type;
Eric Biggers65707372019-03-12 22:12:52 -0700278 bool nosimd;
Eric Biggers3f47a032019-01-31 23:51:43 -0800279};
280
281#define TESTVEC_CONFIG_NAMELEN 192
282
Eric Biggers4e7babba2019-01-31 23:51:46 -0800283/*
284 * The following are the lists of testvec_configs to test for each algorithm
285 * type when the basic crypto self-tests are enabled, i.e. when
286 * CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is unset. They aim to provide good test
287 * coverage, while keeping the test time much shorter than the full fuzz tests
288 * so that the basic tests can be enabled in a wider range of circumstances.
289 */
290
291/* Configs for skciphers and aeads */
292static const struct testvec_config default_cipher_testvec_configs[] = {
293 {
294 .name = "in-place",
295 .inplace = true,
296 .src_divs = { { .proportion_of_total = 10000 } },
297 }, {
298 .name = "out-of-place",
299 .src_divs = { { .proportion_of_total = 10000 } },
300 }, {
301 .name = "unaligned buffer, offset=1",
302 .src_divs = { { .proportion_of_total = 10000, .offset = 1 } },
303 .iv_offset = 1,
304 }, {
305 .name = "buffer aligned only to alignmask",
306 .src_divs = {
307 {
308 .proportion_of_total = 10000,
309 .offset = 1,
310 .offset_relative_to_alignmask = true,
311 },
312 },
313 .iv_offset = 1,
314 .iv_offset_relative_to_alignmask = true,
315 }, {
316 .name = "two even aligned splits",
317 .src_divs = {
318 { .proportion_of_total = 5000 },
319 { .proportion_of_total = 5000 },
320 },
321 }, {
322 .name = "uneven misaligned splits, may sleep",
323 .req_flags = CRYPTO_TFM_REQ_MAY_SLEEP,
324 .src_divs = {
325 { .proportion_of_total = 1900, .offset = 33 },
326 { .proportion_of_total = 3300, .offset = 7 },
327 { .proportion_of_total = 4800, .offset = 18 },
328 },
329 .iv_offset = 3,
330 }, {
331 .name = "misaligned splits crossing pages, inplace",
332 .inplace = true,
333 .src_divs = {
334 {
335 .proportion_of_total = 7500,
336 .offset = PAGE_SIZE - 32
337 }, {
338 .proportion_of_total = 2500,
339 .offset = PAGE_SIZE - 7
340 },
341 },
342 }
343};
344
Eric Biggers4cc2dcf2019-01-31 23:51:48 -0800345static const struct testvec_config default_hash_testvec_configs[] = {
346 {
347 .name = "init+update+final aligned buffer",
348 .src_divs = { { .proportion_of_total = 10000 } },
349 .finalization_type = FINALIZATION_TYPE_FINAL,
350 }, {
351 .name = "init+finup aligned buffer",
352 .src_divs = { { .proportion_of_total = 10000 } },
353 .finalization_type = FINALIZATION_TYPE_FINUP,
354 }, {
355 .name = "digest aligned buffer",
356 .src_divs = { { .proportion_of_total = 10000 } },
357 .finalization_type = FINALIZATION_TYPE_DIGEST,
358 }, {
359 .name = "init+update+final misaligned buffer",
360 .src_divs = { { .proportion_of_total = 10000, .offset = 1 } },
361 .finalization_type = FINALIZATION_TYPE_FINAL,
362 }, {
363 .name = "digest buffer aligned only to alignmask",
364 .src_divs = {
365 {
366 .proportion_of_total = 10000,
367 .offset = 1,
368 .offset_relative_to_alignmask = true,
369 },
370 },
371 .finalization_type = FINALIZATION_TYPE_DIGEST,
372 }, {
373 .name = "init+update+update+final two even splits",
374 .src_divs = {
375 { .proportion_of_total = 5000 },
376 {
377 .proportion_of_total = 5000,
378 .flush_type = FLUSH_TYPE_FLUSH,
379 },
380 },
381 .finalization_type = FINALIZATION_TYPE_FINAL,
382 }, {
383 .name = "digest uneven misaligned splits, may sleep",
384 .req_flags = CRYPTO_TFM_REQ_MAY_SLEEP,
385 .src_divs = {
386 { .proportion_of_total = 1900, .offset = 33 },
387 { .proportion_of_total = 3300, .offset = 7 },
388 { .proportion_of_total = 4800, .offset = 18 },
389 },
390 .finalization_type = FINALIZATION_TYPE_DIGEST,
391 }, {
392 .name = "digest misaligned splits crossing pages",
393 .src_divs = {
394 {
395 .proportion_of_total = 7500,
396 .offset = PAGE_SIZE - 32,
397 }, {
398 .proportion_of_total = 2500,
399 .offset = PAGE_SIZE - 7,
400 },
401 },
402 .finalization_type = FINALIZATION_TYPE_DIGEST,
403 }, {
404 .name = "import/export",
405 .src_divs = {
406 {
407 .proportion_of_total = 6500,
408 .flush_type = FLUSH_TYPE_REIMPORT,
409 }, {
410 .proportion_of_total = 3500,
411 .flush_type = FLUSH_TYPE_REIMPORT,
412 },
413 },
414 .finalization_type = FINALIZATION_TYPE_FINAL,
415 }
416};
417
Eric Biggers3f47a032019-01-31 23:51:43 -0800418static unsigned int count_test_sg_divisions(const struct test_sg_division *divs)
419{
420 unsigned int remaining = TEST_SG_TOTAL;
421 unsigned int ndivs = 0;
422
423 do {
424 remaining -= divs[ndivs++].proportion_of_total;
425 } while (remaining);
426
427 return ndivs;
428}
429
Eric Biggers65707372019-03-12 22:12:52 -0700430#define SGDIVS_HAVE_FLUSHES BIT(0)
431#define SGDIVS_HAVE_NOSIMD BIT(1)
432
Eric Biggers3f47a032019-01-31 23:51:43 -0800433static bool valid_sg_divisions(const struct test_sg_division *divs,
Eric Biggers65707372019-03-12 22:12:52 -0700434 unsigned int count, int *flags_ret)
Eric Biggers3f47a032019-01-31 23:51:43 -0800435{
436 unsigned int total = 0;
437 unsigned int i;
438
439 for (i = 0; i < count && total != TEST_SG_TOTAL; i++) {
440 if (divs[i].proportion_of_total <= 0 ||
441 divs[i].proportion_of_total > TEST_SG_TOTAL - total)
442 return false;
443 total += divs[i].proportion_of_total;
444 if (divs[i].flush_type != FLUSH_TYPE_NONE)
Eric Biggers65707372019-03-12 22:12:52 -0700445 *flags_ret |= SGDIVS_HAVE_FLUSHES;
446 if (divs[i].nosimd)
447 *flags_ret |= SGDIVS_HAVE_NOSIMD;
Eric Biggers3f47a032019-01-31 23:51:43 -0800448 }
449 return total == TEST_SG_TOTAL &&
450 memchr_inv(&divs[i], 0, (count - i) * sizeof(divs[0])) == NULL;
451}
452
453/*
454 * Check whether the given testvec_config is valid. This isn't strictly needed
455 * since every testvec_config should be valid, but check anyway so that people
456 * don't unknowingly add broken configs that don't do what they wanted.
457 */
458static bool valid_testvec_config(const struct testvec_config *cfg)
459{
Eric Biggers65707372019-03-12 22:12:52 -0700460 int flags = 0;
Eric Biggers3f47a032019-01-31 23:51:43 -0800461
462 if (cfg->name == NULL)
463 return false;
464
465 if (!valid_sg_divisions(cfg->src_divs, ARRAY_SIZE(cfg->src_divs),
Eric Biggers65707372019-03-12 22:12:52 -0700466 &flags))
Eric Biggers3f47a032019-01-31 23:51:43 -0800467 return false;
468
469 if (cfg->dst_divs[0].proportion_of_total) {
470 if (!valid_sg_divisions(cfg->dst_divs,
Eric Biggers65707372019-03-12 22:12:52 -0700471 ARRAY_SIZE(cfg->dst_divs), &flags))
Eric Biggers3f47a032019-01-31 23:51:43 -0800472 return false;
473 } else {
474 if (memchr_inv(cfg->dst_divs, 0, sizeof(cfg->dst_divs)))
475 return false;
476 /* defaults to dst_divs=src_divs */
477 }
478
479 if (cfg->iv_offset +
480 (cfg->iv_offset_relative_to_alignmask ? MAX_ALGAPI_ALIGNMASK : 0) >
481 MAX_ALGAPI_ALIGNMASK + 1)
482 return false;
483
Eric Biggers65707372019-03-12 22:12:52 -0700484 if ((flags & (SGDIVS_HAVE_FLUSHES | SGDIVS_HAVE_NOSIMD)) &&
485 cfg->finalization_type == FINALIZATION_TYPE_DIGEST)
486 return false;
487
488 if ((cfg->nosimd || (flags & SGDIVS_HAVE_NOSIMD)) &&
489 (cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP))
Eric Biggers3f47a032019-01-31 23:51:43 -0800490 return false;
491
492 return true;
493}
494
495struct test_sglist {
496 char *bufs[XBUFSIZE];
497 struct scatterlist sgl[XBUFSIZE];
498 struct scatterlist sgl_saved[XBUFSIZE];
499 struct scatterlist *sgl_ptr;
500 unsigned int nents;
501};
502
503static int init_test_sglist(struct test_sglist *tsgl)
504{
505 return __testmgr_alloc_buf(tsgl->bufs, 1 /* two pages per buffer */);
506}
507
508static void destroy_test_sglist(struct test_sglist *tsgl)
509{
510 return __testmgr_free_buf(tsgl->bufs, 1 /* two pages per buffer */);
511}
512
513/**
514 * build_test_sglist() - build a scatterlist for a crypto test
515 *
516 * @tsgl: the scatterlist to build. @tsgl->bufs[] contains an array of 2-page
517 * buffers which the scatterlist @tsgl->sgl[] will be made to point into.
518 * @divs: the layout specification on which the scatterlist will be based
519 * @alignmask: the algorithm's alignmask
520 * @total_len: the total length of the scatterlist to build in bytes
521 * @data: if non-NULL, the buffers will be filled with this data until it ends.
522 * Otherwise the buffers will be poisoned. In both cases, some bytes
523 * past the end of each buffer will be poisoned to help detect overruns.
524 * @out_divs: if non-NULL, the test_sg_division to which each scatterlist entry
525 * corresponds will be returned here. This will match @divs except
526 * that divisions resolving to a length of 0 are omitted as they are
527 * not included in the scatterlist.
528 *
529 * Return: 0 or a -errno value
530 */
531static int build_test_sglist(struct test_sglist *tsgl,
532 const struct test_sg_division *divs,
533 const unsigned int alignmask,
534 const unsigned int total_len,
535 struct iov_iter *data,
536 const struct test_sg_division *out_divs[XBUFSIZE])
537{
538 struct {
539 const struct test_sg_division *div;
540 size_t length;
541 } partitions[XBUFSIZE];
542 const unsigned int ndivs = count_test_sg_divisions(divs);
543 unsigned int len_remaining = total_len;
544 unsigned int i;
545
546 BUILD_BUG_ON(ARRAY_SIZE(partitions) != ARRAY_SIZE(tsgl->sgl));
547 if (WARN_ON(ndivs > ARRAY_SIZE(partitions)))
548 return -EINVAL;
549
550 /* Calculate the (div, length) pairs */
551 tsgl->nents = 0;
552 for (i = 0; i < ndivs; i++) {
553 unsigned int len_this_sg =
554 min(len_remaining,
555 (total_len * divs[i].proportion_of_total +
556 TEST_SG_TOTAL / 2) / TEST_SG_TOTAL);
557
558 if (len_this_sg != 0) {
559 partitions[tsgl->nents].div = &divs[i];
560 partitions[tsgl->nents].length = len_this_sg;
561 tsgl->nents++;
562 len_remaining -= len_this_sg;
563 }
564 }
565 if (tsgl->nents == 0) {
566 partitions[tsgl->nents].div = &divs[0];
567 partitions[tsgl->nents].length = 0;
568 tsgl->nents++;
569 }
570 partitions[tsgl->nents - 1].length += len_remaining;
571
572 /* Set up the sgl entries and fill the data or poison */
573 sg_init_table(tsgl->sgl, tsgl->nents);
574 for (i = 0; i < tsgl->nents; i++) {
575 unsigned int offset = partitions[i].div->offset;
576 void *addr;
577
578 if (partitions[i].div->offset_relative_to_alignmask)
579 offset += alignmask;
580
581 while (offset + partitions[i].length + TESTMGR_POISON_LEN >
582 2 * PAGE_SIZE) {
583 if (WARN_ON(offset <= 0))
584 return -EINVAL;
585 offset /= 2;
586 }
587
588 addr = &tsgl->bufs[i][offset];
589 sg_set_buf(&tsgl->sgl[i], addr, partitions[i].length);
590
591 if (out_divs)
592 out_divs[i] = partitions[i].div;
593
594 if (data) {
595 size_t copy_len, copied;
596
597 copy_len = min(partitions[i].length, data->count);
598 copied = copy_from_iter(addr, copy_len, data);
599 if (WARN_ON(copied != copy_len))
600 return -EINVAL;
601 testmgr_poison(addr + copy_len, partitions[i].length +
602 TESTMGR_POISON_LEN - copy_len);
603 } else {
604 testmgr_poison(addr, partitions[i].length +
605 TESTMGR_POISON_LEN);
606 }
607 }
608
609 sg_mark_end(&tsgl->sgl[tsgl->nents - 1]);
610 tsgl->sgl_ptr = tsgl->sgl;
611 memcpy(tsgl->sgl_saved, tsgl->sgl, tsgl->nents * sizeof(tsgl->sgl[0]));
612 return 0;
613}
614
615/*
616 * Verify that a scatterlist crypto operation produced the correct output.
617 *
618 * @tsgl: scatterlist containing the actual output
619 * @expected_output: buffer containing the expected output
620 * @len_to_check: length of @expected_output in bytes
621 * @unchecked_prefix_len: number of ignored bytes in @tsgl prior to real result
622 * @check_poison: verify that the poison bytes after each chunk are intact?
623 *
624 * Return: 0 if correct, -EINVAL if incorrect, -EOVERFLOW if buffer overrun.
625 */
626static int verify_correct_output(const struct test_sglist *tsgl,
627 const char *expected_output,
628 unsigned int len_to_check,
629 unsigned int unchecked_prefix_len,
630 bool check_poison)
631{
632 unsigned int i;
633
634 for (i = 0; i < tsgl->nents; i++) {
635 struct scatterlist *sg = &tsgl->sgl_ptr[i];
636 unsigned int len = sg->length;
637 unsigned int offset = sg->offset;
638 const char *actual_output;
639
640 if (unchecked_prefix_len) {
641 if (unchecked_prefix_len >= len) {
642 unchecked_prefix_len -= len;
643 continue;
644 }
645 offset += unchecked_prefix_len;
646 len -= unchecked_prefix_len;
647 unchecked_prefix_len = 0;
648 }
649 len = min(len, len_to_check);
650 actual_output = page_address(sg_page(sg)) + offset;
651 if (memcmp(expected_output, actual_output, len) != 0)
652 return -EINVAL;
653 if (check_poison &&
654 !testmgr_is_poison(actual_output + len, TESTMGR_POISON_LEN))
655 return -EOVERFLOW;
656 len_to_check -= len;
657 expected_output += len;
658 }
659 if (WARN_ON(len_to_check != 0))
660 return -EINVAL;
661 return 0;
662}
663
664static bool is_test_sglist_corrupted(const struct test_sglist *tsgl)
665{
666 unsigned int i;
667
668 for (i = 0; i < tsgl->nents; i++) {
669 if (tsgl->sgl[i].page_link != tsgl->sgl_saved[i].page_link)
670 return true;
671 if (tsgl->sgl[i].offset != tsgl->sgl_saved[i].offset)
672 return true;
673 if (tsgl->sgl[i].length != tsgl->sgl_saved[i].length)
674 return true;
675 }
676 return false;
677}
678
679struct cipher_test_sglists {
680 struct test_sglist src;
681 struct test_sglist dst;
682};
683
684static struct cipher_test_sglists *alloc_cipher_test_sglists(void)
685{
686 struct cipher_test_sglists *tsgls;
687
688 tsgls = kmalloc(sizeof(*tsgls), GFP_KERNEL);
689 if (!tsgls)
690 return NULL;
691
692 if (init_test_sglist(&tsgls->src) != 0)
693 goto fail_kfree;
694 if (init_test_sglist(&tsgls->dst) != 0)
695 goto fail_destroy_src;
696
697 return tsgls;
698
699fail_destroy_src:
700 destroy_test_sglist(&tsgls->src);
701fail_kfree:
702 kfree(tsgls);
703 return NULL;
704}
705
706static void free_cipher_test_sglists(struct cipher_test_sglists *tsgls)
707{
708 if (tsgls) {
709 destroy_test_sglist(&tsgls->src);
710 destroy_test_sglist(&tsgls->dst);
711 kfree(tsgls);
712 }
713}
714
715/* Build the src and dst scatterlists for an skcipher or AEAD test */
716static int build_cipher_test_sglists(struct cipher_test_sglists *tsgls,
717 const struct testvec_config *cfg,
718 unsigned int alignmask,
719 unsigned int src_total_len,
720 unsigned int dst_total_len,
721 const struct kvec *inputs,
722 unsigned int nr_inputs)
723{
724 struct iov_iter input;
725 int err;
726
727 iov_iter_kvec(&input, WRITE, inputs, nr_inputs, src_total_len);
728 err = build_test_sglist(&tsgls->src, cfg->src_divs, alignmask,
729 cfg->inplace ?
730 max(dst_total_len, src_total_len) :
731 src_total_len,
732 &input, NULL);
733 if (err)
734 return err;
735
736 if (cfg->inplace) {
737 tsgls->dst.sgl_ptr = tsgls->src.sgl;
738 tsgls->dst.nents = tsgls->src.nents;
739 return 0;
740 }
741 return build_test_sglist(&tsgls->dst,
742 cfg->dst_divs[0].proportion_of_total ?
743 cfg->dst_divs : cfg->src_divs,
744 alignmask, dst_total_len, NULL, NULL);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800745}
746
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800747#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
748static char *generate_random_sgl_divisions(struct test_sg_division *divs,
749 size_t max_divs, char *p, char *end,
Eric Biggers65707372019-03-12 22:12:52 -0700750 bool gen_flushes, u32 req_flags)
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800751{
752 struct test_sg_division *div = divs;
753 unsigned int remaining = TEST_SG_TOTAL;
754
755 do {
756 unsigned int this_len;
Eric Biggers65707372019-03-12 22:12:52 -0700757 const char *flushtype_str;
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800758
759 if (div == &divs[max_divs - 1] || prandom_u32() % 2 == 0)
760 this_len = remaining;
761 else
762 this_len = 1 + (prandom_u32() % remaining);
763 div->proportion_of_total = this_len;
764
765 if (prandom_u32() % 4 == 0)
766 div->offset = (PAGE_SIZE - 128) + (prandom_u32() % 128);
767 else if (prandom_u32() % 2 == 0)
768 div->offset = prandom_u32() % 32;
769 else
770 div->offset = prandom_u32() % PAGE_SIZE;
771 if (prandom_u32() % 8 == 0)
772 div->offset_relative_to_alignmask = true;
773
774 div->flush_type = FLUSH_TYPE_NONE;
775 if (gen_flushes) {
776 switch (prandom_u32() % 4) {
777 case 0:
778 div->flush_type = FLUSH_TYPE_REIMPORT;
779 break;
780 case 1:
781 div->flush_type = FLUSH_TYPE_FLUSH;
782 break;
783 }
784 }
785
Eric Biggers65707372019-03-12 22:12:52 -0700786 if (div->flush_type != FLUSH_TYPE_NONE &&
787 !(req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) &&
788 prandom_u32() % 2 == 0)
789 div->nosimd = true;
790
791 switch (div->flush_type) {
792 case FLUSH_TYPE_FLUSH:
793 if (div->nosimd)
794 flushtype_str = "<flush,nosimd>";
795 else
796 flushtype_str = "<flush>";
797 break;
798 case FLUSH_TYPE_REIMPORT:
799 if (div->nosimd)
800 flushtype_str = "<reimport,nosimd>";
801 else
802 flushtype_str = "<reimport>";
803 break;
804 default:
805 flushtype_str = "";
806 break;
807 }
808
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800809 BUILD_BUG_ON(TEST_SG_TOTAL != 10000); /* for "%u.%u%%" */
Eric Biggers65707372019-03-12 22:12:52 -0700810 p += scnprintf(p, end - p, "%s%u.%u%%@%s+%u%s", flushtype_str,
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800811 this_len / 100, this_len % 100,
812 div->offset_relative_to_alignmask ?
813 "alignmask" : "",
814 div->offset, this_len == remaining ? "" : ", ");
815 remaining -= this_len;
816 div++;
817 } while (remaining);
818
819 return p;
820}
821
822/* Generate a random testvec_config for fuzz testing */
823static void generate_random_testvec_config(struct testvec_config *cfg,
824 char *name, size_t max_namelen)
825{
826 char *p = name;
827 char * const end = name + max_namelen;
828
829 memset(cfg, 0, sizeof(*cfg));
830
831 cfg->name = name;
832
833 p += scnprintf(p, end - p, "random:");
834
835 if (prandom_u32() % 2 == 0) {
836 cfg->inplace = true;
837 p += scnprintf(p, end - p, " inplace");
838 }
839
840 if (prandom_u32() % 2 == 0) {
841 cfg->req_flags |= CRYPTO_TFM_REQ_MAY_SLEEP;
842 p += scnprintf(p, end - p, " may_sleep");
843 }
844
845 switch (prandom_u32() % 4) {
846 case 0:
847 cfg->finalization_type = FINALIZATION_TYPE_FINAL;
848 p += scnprintf(p, end - p, " use_final");
849 break;
850 case 1:
851 cfg->finalization_type = FINALIZATION_TYPE_FINUP;
852 p += scnprintf(p, end - p, " use_finup");
853 break;
854 default:
855 cfg->finalization_type = FINALIZATION_TYPE_DIGEST;
856 p += scnprintf(p, end - p, " use_digest");
857 break;
858 }
859
Eric Biggers65707372019-03-12 22:12:52 -0700860 if (!(cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) &&
861 prandom_u32() % 2 == 0) {
862 cfg->nosimd = true;
863 p += scnprintf(p, end - p, " nosimd");
864 }
865
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800866 p += scnprintf(p, end - p, " src_divs=[");
867 p = generate_random_sgl_divisions(cfg->src_divs,
868 ARRAY_SIZE(cfg->src_divs), p, end,
869 (cfg->finalization_type !=
Eric Biggers65707372019-03-12 22:12:52 -0700870 FINALIZATION_TYPE_DIGEST),
871 cfg->req_flags);
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800872 p += scnprintf(p, end - p, "]");
873
874 if (!cfg->inplace && prandom_u32() % 2 == 0) {
875 p += scnprintf(p, end - p, " dst_divs=[");
876 p = generate_random_sgl_divisions(cfg->dst_divs,
877 ARRAY_SIZE(cfg->dst_divs),
Eric Biggers65707372019-03-12 22:12:52 -0700878 p, end, false,
879 cfg->req_flags);
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800880 p += scnprintf(p, end - p, "]");
881 }
882
883 if (prandom_u32() % 2 == 0) {
884 cfg->iv_offset = 1 + (prandom_u32() % MAX_ALGAPI_ALIGNMASK);
885 p += scnprintf(p, end - p, " iv_offset=%u", cfg->iv_offset);
886 }
887
888 WARN_ON_ONCE(!valid_testvec_config(cfg));
889}
Eric Biggersb55e1a32019-03-12 22:12:47 -0700890
891static void crypto_disable_simd_for_test(void)
892{
893 preempt_disable();
894 __this_cpu_write(crypto_simd_disabled_for_test, true);
895}
896
897static void crypto_reenable_simd_for_test(void)
898{
899 __this_cpu_write(crypto_simd_disabled_for_test, false);
900 preempt_enable();
901}
902#else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
903static void crypto_disable_simd_for_test(void)
904{
905}
906
907static void crypto_reenable_simd_for_test(void)
908{
909}
910#endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800911
Eric Biggers65707372019-03-12 22:12:52 -0700912static int do_ahash_op(int (*op)(struct ahash_request *req),
913 struct ahash_request *req,
914 struct crypto_wait *wait, bool nosimd)
915{
916 int err;
917
918 if (nosimd)
919 crypto_disable_simd_for_test();
920
921 err = op(req);
922
923 if (nosimd)
924 crypto_reenable_simd_for_test();
925
926 return crypto_wait_req(err, wait);
927}
928
Eric Biggers4cc2dcf2019-01-31 23:51:48 -0800929static int check_nonfinal_hash_op(const char *op, int err,
930 u8 *result, unsigned int digestsize,
931 const char *driver, unsigned int vec_num,
932 const struct testvec_config *cfg)
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100933{
Eric Biggers4cc2dcf2019-01-31 23:51:48 -0800934 if (err) {
935 pr_err("alg: hash: %s %s() failed with err %d on test vector %u, cfg=\"%s\"\n",
936 driver, op, err, vec_num, cfg->name);
937 return err;
938 }
939 if (!testmgr_is_poison(result, digestsize)) {
940 pr_err("alg: hash: %s %s() used result buffer on test vector %u, cfg=\"%s\"\n",
941 driver, op, vec_num, cfg->name);
942 return -EINVAL;
943 }
944 return 0;
945}
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100946
Eric Biggers4cc2dcf2019-01-31 23:51:48 -0800947static int test_hash_vec_cfg(const char *driver,
948 const struct hash_testvec *vec,
949 unsigned int vec_num,
950 const struct testvec_config *cfg,
951 struct ahash_request *req,
952 struct test_sglist *tsgl,
953 u8 *hashstate)
954{
955 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
956 const unsigned int alignmask = crypto_ahash_alignmask(tfm);
957 const unsigned int digestsize = crypto_ahash_digestsize(tfm);
958 const unsigned int statesize = crypto_ahash_statesize(tfm);
959 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
960 const struct test_sg_division *divs[XBUFSIZE];
961 DECLARE_CRYPTO_WAIT(wait);
962 struct kvec _input;
963 struct iov_iter input;
964 unsigned int i;
965 struct scatterlist *pending_sgl;
966 unsigned int pending_len;
967 u8 result[HASH_MAX_DIGESTSIZE + TESTMGR_POISON_LEN];
968 int err;
969
970 /* Set the key, if specified */
971 if (vec->ksize) {
972 err = crypto_ahash_setkey(tfm, vec->key, vec->ksize);
973 if (err) {
Eric Biggers5283a8e2019-04-11 21:57:36 -0700974 if (err == vec->setkey_error)
975 return 0;
976 pr_err("alg: hash: %s setkey failed on test vector %u; expected_error=%d, actual_error=%d, flags=%#x\n",
977 driver, vec_num, vec->setkey_error, err,
Eric Biggers4cc2dcf2019-01-31 23:51:48 -0800978 crypto_ahash_get_flags(tfm));
979 return err;
980 }
Eric Biggers5283a8e2019-04-11 21:57:36 -0700981 if (vec->setkey_error) {
982 pr_err("alg: hash: %s setkey unexpectedly succeeded on test vector %u; expected_error=%d\n",
983 driver, vec_num, vec->setkey_error);
984 return -EINVAL;
985 }
Eric Biggers4cc2dcf2019-01-31 23:51:48 -0800986 }
987
988 /* Build the scatterlist for the source data */
989 _input.iov_base = (void *)vec->plaintext;
990 _input.iov_len = vec->psize;
991 iov_iter_kvec(&input, WRITE, &_input, 1, vec->psize);
992 err = build_test_sglist(tsgl, cfg->src_divs, alignmask, vec->psize,
993 &input, divs);
994 if (err) {
995 pr_err("alg: hash: %s: error preparing scatterlist for test vector %u, cfg=\"%s\"\n",
996 driver, vec_num, cfg->name);
997 return err;
998 }
999
1000 /* Do the actual hashing */
1001
1002 testmgr_poison(req->__ctx, crypto_ahash_reqsize(tfm));
1003 testmgr_poison(result, digestsize + TESTMGR_POISON_LEN);
1004
Eric Biggers5283a8e2019-04-11 21:57:36 -07001005 if (cfg->finalization_type == FINALIZATION_TYPE_DIGEST ||
1006 vec->digest_error) {
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001007 /* Just using digest() */
1008 ahash_request_set_callback(req, req_flags, crypto_req_done,
1009 &wait);
1010 ahash_request_set_crypt(req, tsgl->sgl, result, vec->psize);
Eric Biggers65707372019-03-12 22:12:52 -07001011 err = do_ahash_op(crypto_ahash_digest, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001012 if (err) {
Eric Biggers5283a8e2019-04-11 21:57:36 -07001013 if (err == vec->digest_error)
1014 return 0;
1015 pr_err("alg: hash: %s digest() failed on test vector %u; expected_error=%d, actual_error=%d, cfg=\"%s\"\n",
1016 driver, vec_num, vec->digest_error, err,
1017 cfg->name);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001018 return err;
1019 }
Eric Biggers5283a8e2019-04-11 21:57:36 -07001020 if (vec->digest_error) {
1021 pr_err("alg: hash: %s digest() unexpectedly succeeded on test vector %u; expected_error=%d, cfg=\"%s\"\n",
1022 driver, vec_num, vec->digest_error, cfg->name);
1023 return -EINVAL;
1024 }
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001025 goto result_ready;
1026 }
1027
1028 /* Using init(), zero or more update(), then final() or finup() */
1029
1030 ahash_request_set_callback(req, req_flags, crypto_req_done, &wait);
1031 ahash_request_set_crypt(req, NULL, result, 0);
Eric Biggers65707372019-03-12 22:12:52 -07001032 err = do_ahash_op(crypto_ahash_init, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001033 err = check_nonfinal_hash_op("init", err, result, digestsize,
1034 driver, vec_num, cfg);
1035 if (err)
1036 return err;
1037
1038 pending_sgl = NULL;
1039 pending_len = 0;
1040 for (i = 0; i < tsgl->nents; i++) {
1041 if (divs[i]->flush_type != FLUSH_TYPE_NONE &&
1042 pending_sgl != NULL) {
1043 /* update() with the pending data */
1044 ahash_request_set_callback(req, req_flags,
1045 crypto_req_done, &wait);
1046 ahash_request_set_crypt(req, pending_sgl, result,
1047 pending_len);
Eric Biggers65707372019-03-12 22:12:52 -07001048 err = do_ahash_op(crypto_ahash_update, req, &wait,
1049 divs[i]->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001050 err = check_nonfinal_hash_op("update", err,
1051 result, digestsize,
1052 driver, vec_num, cfg);
1053 if (err)
1054 return err;
1055 pending_sgl = NULL;
1056 pending_len = 0;
1057 }
1058 if (divs[i]->flush_type == FLUSH_TYPE_REIMPORT) {
1059 /* Test ->export() and ->import() */
1060 testmgr_poison(hashstate + statesize,
1061 TESTMGR_POISON_LEN);
1062 err = crypto_ahash_export(req, hashstate);
1063 err = check_nonfinal_hash_op("export", err,
1064 result, digestsize,
1065 driver, vec_num, cfg);
1066 if (err)
1067 return err;
1068 if (!testmgr_is_poison(hashstate + statesize,
1069 TESTMGR_POISON_LEN)) {
1070 pr_err("alg: hash: %s export() overran state buffer on test vector %u, cfg=\"%s\"\n",
1071 driver, vec_num, cfg->name);
1072 return -EOVERFLOW;
1073 }
1074
1075 testmgr_poison(req->__ctx, crypto_ahash_reqsize(tfm));
1076 err = crypto_ahash_import(req, hashstate);
1077 err = check_nonfinal_hash_op("import", err,
1078 result, digestsize,
1079 driver, vec_num, cfg);
1080 if (err)
1081 return err;
1082 }
1083 if (pending_sgl == NULL)
1084 pending_sgl = &tsgl->sgl[i];
1085 pending_len += tsgl->sgl[i].length;
1086 }
1087
1088 ahash_request_set_callback(req, req_flags, crypto_req_done, &wait);
1089 ahash_request_set_crypt(req, pending_sgl, result, pending_len);
1090 if (cfg->finalization_type == FINALIZATION_TYPE_FINAL) {
1091 /* finish with update() and final() */
Eric Biggers65707372019-03-12 22:12:52 -07001092 err = do_ahash_op(crypto_ahash_update, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001093 err = check_nonfinal_hash_op("update", err, result, digestsize,
1094 driver, vec_num, cfg);
1095 if (err)
1096 return err;
Eric Biggers65707372019-03-12 22:12:52 -07001097 err = do_ahash_op(crypto_ahash_final, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001098 if (err) {
1099 pr_err("alg: hash: %s final() failed with err %d on test vector %u, cfg=\"%s\"\n",
1100 driver, err, vec_num, cfg->name);
1101 return err;
1102 }
1103 } else {
1104 /* finish with finup() */
Eric Biggers65707372019-03-12 22:12:52 -07001105 err = do_ahash_op(crypto_ahash_finup, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001106 if (err) {
1107 pr_err("alg: hash: %s finup() failed with err %d on test vector %u, cfg=\"%s\"\n",
1108 driver, err, vec_num, cfg->name);
1109 return err;
1110 }
1111 }
1112
1113result_ready:
1114 /* Check that the algorithm produced the correct digest */
1115 if (memcmp(result, vec->digest, digestsize) != 0) {
1116 pr_err("alg: hash: %s test failed (wrong result) on test vector %u, cfg=\"%s\"\n",
1117 driver, vec_num, cfg->name);
1118 return -EINVAL;
1119 }
1120 if (!testmgr_is_poison(&result[digestsize], TESTMGR_POISON_LEN)) {
1121 pr_err("alg: hash: %s overran result buffer on test vector %u, cfg=\"%s\"\n",
1122 driver, vec_num, cfg->name);
1123 return -EOVERFLOW;
1124 }
1125
1126 return 0;
1127}
1128
1129static int test_hash_vec(const char *driver, const struct hash_testvec *vec,
1130 unsigned int vec_num, struct ahash_request *req,
1131 struct test_sglist *tsgl, u8 *hashstate)
1132{
1133 unsigned int i;
1134 int err;
1135
1136 for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++) {
1137 err = test_hash_vec_cfg(driver, vec, vec_num,
1138 &default_hash_testvec_configs[i],
1139 req, tsgl, hashstate);
1140 if (err)
1141 return err;
1142 }
1143
1144#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1145 if (!noextratests) {
1146 struct testvec_config cfg;
1147 char cfgname[TESTVEC_CONFIG_NAMELEN];
1148
1149 for (i = 0; i < fuzz_iterations; i++) {
1150 generate_random_testvec_config(&cfg, cfgname,
1151 sizeof(cfgname));
1152 err = test_hash_vec_cfg(driver, vec, vec_num, &cfg,
1153 req, tsgl, hashstate);
1154 if (err)
1155 return err;
1156 }
1157 }
1158#endif
1159 return 0;
1160}
1161
1162static int __alg_test_hash(const struct hash_testvec *vecs,
1163 unsigned int num_vecs, const char *driver,
1164 u32 type, u32 mask)
1165{
1166 struct crypto_ahash *tfm;
1167 struct ahash_request *req = NULL;
1168 struct test_sglist *tsgl = NULL;
1169 u8 *hashstate = NULL;
1170 unsigned int i;
1171 int err;
1172
1173 tfm = crypto_alloc_ahash(driver, type, mask);
1174 if (IS_ERR(tfm)) {
1175 pr_err("alg: hash: failed to allocate transform for %s: %ld\n",
1176 driver, PTR_ERR(tfm));
1177 return PTR_ERR(tfm);
1178 }
1179
1180 req = ahash_request_alloc(tfm, GFP_KERNEL);
1181 if (!req) {
1182 pr_err("alg: hash: failed to allocate request for %s\n",
1183 driver);
1184 err = -ENOMEM;
1185 goto out;
1186 }
1187
1188 tsgl = kmalloc(sizeof(*tsgl), GFP_KERNEL);
1189 if (!tsgl || init_test_sglist(tsgl) != 0) {
1190 pr_err("alg: hash: failed to allocate test buffers for %s\n",
1191 driver);
1192 kfree(tsgl);
1193 tsgl = NULL;
1194 err = -ENOMEM;
1195 goto out;
1196 }
1197
1198 hashstate = kmalloc(crypto_ahash_statesize(tfm) + TESTMGR_POISON_LEN,
1199 GFP_KERNEL);
1200 if (!hashstate) {
1201 pr_err("alg: hash: failed to allocate hash state buffer for %s\n",
1202 driver);
1203 err = -ENOMEM;
1204 goto out;
1205 }
1206
1207 for (i = 0; i < num_vecs; i++) {
1208 err = test_hash_vec(driver, &vecs[i], i, req, tsgl, hashstate);
1209 if (err)
1210 goto out;
1211 }
1212 err = 0;
1213out:
1214 kfree(hashstate);
1215 if (tsgl) {
1216 destroy_test_sglist(tsgl);
1217 kfree(tsgl);
1218 }
1219 ahash_request_free(req);
1220 crypto_free_ahash(tfm);
1221 return err;
1222}
1223
1224static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1225 u32 type, u32 mask)
1226{
1227 const struct hash_testvec *template = desc->suite.hash.vecs;
1228 unsigned int tcount = desc->suite.hash.count;
1229 unsigned int nr_unkeyed, nr_keyed;
1230 int err;
1231
1232 /*
1233 * For OPTIONAL_KEY algorithms, we have to do all the unkeyed tests
1234 * first, before setting a key on the tfm. To make this easier, we
1235 * require that the unkeyed test vectors (if any) are listed first.
1236 */
1237
1238 for (nr_unkeyed = 0; nr_unkeyed < tcount; nr_unkeyed++) {
1239 if (template[nr_unkeyed].ksize)
1240 break;
1241 }
1242 for (nr_keyed = 0; nr_unkeyed + nr_keyed < tcount; nr_keyed++) {
1243 if (!template[nr_unkeyed + nr_keyed].ksize) {
1244 pr_err("alg: hash: test vectors for %s out of order, "
1245 "unkeyed ones must come first\n", desc->alg);
Kamil Konieczny466d7b92018-01-16 15:26:13 +01001246 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08001247 }
1248 }
1249
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001250 err = 0;
1251 if (nr_unkeyed) {
1252 err = __alg_test_hash(template, nr_unkeyed, driver, type, mask);
1253 template += nr_unkeyed;
Herbert Xuda7f0332008-07-31 17:08:25 +08001254 }
1255
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001256 if (!err && nr_keyed)
1257 err = __alg_test_hash(template, nr_keyed, driver, type, mask);
Wang, Rui Y018ba952016-02-03 18:26:57 +08001258
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001259 return err;
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +03001260}
1261
Eric Biggersed968042019-01-31 23:51:47 -08001262static int test_aead_vec_cfg(const char *driver, int enc,
1263 const struct aead_testvec *vec,
1264 unsigned int vec_num,
1265 const struct testvec_config *cfg,
1266 struct aead_request *req,
1267 struct cipher_test_sglists *tsgls)
Herbert Xuda7f0332008-07-31 17:08:25 +08001268{
Eric Biggersed968042019-01-31 23:51:47 -08001269 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1270 const unsigned int alignmask = crypto_aead_alignmask(tfm);
1271 const unsigned int ivsize = crypto_aead_ivsize(tfm);
1272 const unsigned int authsize = vec->clen - vec->plen;
1273 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
1274 const char *op = enc ? "encryption" : "decryption";
1275 DECLARE_CRYPTO_WAIT(wait);
1276 u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN];
1277 u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) +
1278 cfg->iv_offset +
1279 (cfg->iv_offset_relative_to_alignmask ? alignmask : 0);
1280 struct kvec input[2];
Eric Biggers5283a8e2019-04-11 21:57:36 -07001281 int expected_error;
Eric Biggersed968042019-01-31 23:51:47 -08001282 int err;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001283
Eric Biggersed968042019-01-31 23:51:47 -08001284 /* Set the key */
1285 if (vec->wk)
1286 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001287 else
Eric Biggersed968042019-01-31 23:51:47 -08001288 crypto_aead_clear_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
1289 err = crypto_aead_setkey(tfm, vec->key, vec->klen);
Eric Biggers5283a8e2019-04-11 21:57:36 -07001290 if (err && err != vec->setkey_error) {
1291 pr_err("alg: aead: %s setkey failed on test vector %u; expected_error=%d, actual_error=%d, flags=%#x\n",
1292 driver, vec_num, vec->setkey_error, err,
1293 crypto_aead_get_flags(tfm));
Eric Biggersed968042019-01-31 23:51:47 -08001294 return err;
1295 }
Eric Biggers5283a8e2019-04-11 21:57:36 -07001296 if (!err && vec->setkey_error) {
1297 pr_err("alg: aead: %s setkey unexpectedly succeeded on test vector %u; expected_error=%d\n",
1298 driver, vec_num, vec->setkey_error);
Eric Biggersed968042019-01-31 23:51:47 -08001299 return -EINVAL;
1300 }
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001301
Eric Biggersed968042019-01-31 23:51:47 -08001302 /* Set the authentication tag size */
1303 err = crypto_aead_setauthsize(tfm, authsize);
Eric Biggers5283a8e2019-04-11 21:57:36 -07001304 if (err && err != vec->setauthsize_error) {
1305 pr_err("alg: aead: %s setauthsize failed on test vector %u; expected_error=%d, actual_error=%d\n",
1306 driver, vec_num, vec->setauthsize_error, err);
Eric Biggersed968042019-01-31 23:51:47 -08001307 return err;
1308 }
Eric Biggers5283a8e2019-04-11 21:57:36 -07001309 if (!err && vec->setauthsize_error) {
1310 pr_err("alg: aead: %s setauthsize unexpectedly succeeded on test vector %u; expected_error=%d\n",
1311 driver, vec_num, vec->setauthsize_error);
1312 return -EINVAL;
1313 }
1314
1315 if (vec->setkey_error || vec->setauthsize_error)
1316 return 0;
Eric Biggersed968042019-01-31 23:51:47 -08001317
1318 /* The IV must be copied to a buffer, as the algorithm may modify it */
1319 if (WARN_ON(ivsize > MAX_IVLEN))
1320 return -EINVAL;
1321 if (vec->iv)
1322 memcpy(iv, vec->iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001323 else
Eric Biggersed968042019-01-31 23:51:47 -08001324 memset(iv, 0, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001325
Eric Biggersed968042019-01-31 23:51:47 -08001326 /* Build the src/dst scatterlists */
1327 input[0].iov_base = (void *)vec->assoc;
1328 input[0].iov_len = vec->alen;
1329 input[1].iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext;
1330 input[1].iov_len = enc ? vec->plen : vec->clen;
1331 err = build_cipher_test_sglists(tsgls, cfg, alignmask,
1332 vec->alen + (enc ? vec->plen :
1333 vec->clen),
1334 vec->alen + (enc ? vec->clen :
1335 vec->plen),
1336 input, 2);
1337 if (err) {
1338 pr_err("alg: aead: %s %s: error preparing scatterlists for test vector %u, cfg=\"%s\"\n",
1339 driver, op, vec_num, cfg->name);
1340 return err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001341 }
1342
Eric Biggersed968042019-01-31 23:51:47 -08001343 /* Do the actual encryption or decryption */
1344 testmgr_poison(req->__ctx, crypto_aead_reqsize(tfm));
1345 aead_request_set_callback(req, req_flags, crypto_req_done, &wait);
1346 aead_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr,
1347 enc ? vec->plen : vec->clen, iv);
1348 aead_request_set_ad(req, vec->alen);
Eric Biggers65707372019-03-12 22:12:52 -07001349 if (cfg->nosimd)
1350 crypto_disable_simd_for_test();
1351 err = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
1352 if (cfg->nosimd)
1353 crypto_reenable_simd_for_test();
1354 err = crypto_wait_req(err, &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001355
Eric Biggersa6e5ef92019-01-31 23:51:50 -08001356 /* Check that the algorithm didn't overwrite things it shouldn't have */
1357 if (req->cryptlen != (enc ? vec->plen : vec->clen) ||
1358 req->assoclen != vec->alen ||
1359 req->iv != iv ||
1360 req->src != tsgls->src.sgl_ptr ||
1361 req->dst != tsgls->dst.sgl_ptr ||
1362 crypto_aead_reqtfm(req) != tfm ||
1363 req->base.complete != crypto_req_done ||
1364 req->base.flags != req_flags ||
1365 req->base.data != &wait) {
1366 pr_err("alg: aead: %s %s corrupted request struct on test vector %u, cfg=\"%s\"\n",
1367 driver, op, vec_num, cfg->name);
1368 if (req->cryptlen != (enc ? vec->plen : vec->clen))
1369 pr_err("alg: aead: changed 'req->cryptlen'\n");
1370 if (req->assoclen != vec->alen)
1371 pr_err("alg: aead: changed 'req->assoclen'\n");
1372 if (req->iv != iv)
1373 pr_err("alg: aead: changed 'req->iv'\n");
1374 if (req->src != tsgls->src.sgl_ptr)
1375 pr_err("alg: aead: changed 'req->src'\n");
1376 if (req->dst != tsgls->dst.sgl_ptr)
1377 pr_err("alg: aead: changed 'req->dst'\n");
1378 if (crypto_aead_reqtfm(req) != tfm)
1379 pr_err("alg: aead: changed 'req->base.tfm'\n");
1380 if (req->base.complete != crypto_req_done)
1381 pr_err("alg: aead: changed 'req->base.complete'\n");
1382 if (req->base.flags != req_flags)
1383 pr_err("alg: aead: changed 'req->base.flags'\n");
1384 if (req->base.data != &wait)
1385 pr_err("alg: aead: changed 'req->base.data'\n");
1386 return -EINVAL;
1387 }
1388 if (is_test_sglist_corrupted(&tsgls->src)) {
1389 pr_err("alg: aead: %s %s corrupted src sgl on test vector %u, cfg=\"%s\"\n",
1390 driver, op, vec_num, cfg->name);
1391 return -EINVAL;
1392 }
1393 if (tsgls->dst.sgl_ptr != tsgls->src.sgl &&
1394 is_test_sglist_corrupted(&tsgls->dst)) {
1395 pr_err("alg: aead: %s %s corrupted dst sgl on test vector %u, cfg=\"%s\"\n",
1396 driver, op, vec_num, cfg->name);
1397 return -EINVAL;
1398 }
1399
Eric Biggers5283a8e2019-04-11 21:57:36 -07001400 /* Check for success or failure */
1401 expected_error = vec->novrfy ? -EBADMSG : vec->crypt_error;
1402 if (err) {
1403 if (err == expected_error)
1404 return 0;
1405 pr_err("alg: aead: %s %s failed on test vector %u; expected_error=%d, actual_error=%d, cfg=\"%s\"\n",
1406 driver, op, vec_num, expected_error, err, cfg->name);
1407 return err;
1408 }
1409 if (expected_error) {
1410 pr_err("alg: aead: %s %s unexpectedly succeeded on test vector %u; expected_error=%d, cfg=\"%s\"\n",
1411 driver, op, vec_num, expected_error, cfg->name);
1412 return -EINVAL;
1413 }
1414
Eric Biggersed968042019-01-31 23:51:47 -08001415 /* Check for the correct output (ciphertext or plaintext) */
1416 err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext,
1417 enc ? vec->clen : vec->plen,
1418 vec->alen, enc || !cfg->inplace);
1419 if (err == -EOVERFLOW) {
1420 pr_err("alg: aead: %s %s overran dst buffer on test vector %u, cfg=\"%s\"\n",
1421 driver, op, vec_num, cfg->name);
1422 return err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001423 }
Eric Biggersed968042019-01-31 23:51:47 -08001424 if (err) {
1425 pr_err("alg: aead: %s %s test failed (wrong result) on test vector %u, cfg=\"%s\"\n",
1426 driver, op, vec_num, cfg->name);
1427 return err;
Jussi Kivilinna58dcf542013-06-13 17:37:50 +03001428 }
1429
1430 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001431}
1432
Eric Biggersed968042019-01-31 23:51:47 -08001433static int test_aead_vec(const char *driver, int enc,
1434 const struct aead_testvec *vec, unsigned int vec_num,
1435 struct aead_request *req,
1436 struct cipher_test_sglists *tsgls)
1437{
1438 unsigned int i;
1439 int err;
1440
1441 if (enc && vec->novrfy)
1442 return 0;
1443
1444 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
1445 err = test_aead_vec_cfg(driver, enc, vec, vec_num,
1446 &default_cipher_testvec_configs[i],
1447 req, tsgls);
1448 if (err)
1449 return err;
1450 }
1451
1452#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1453 if (!noextratests) {
1454 struct testvec_config cfg;
1455 char cfgname[TESTVEC_CONFIG_NAMELEN];
1456
1457 for (i = 0; i < fuzz_iterations; i++) {
1458 generate_random_testvec_config(&cfg, cfgname,
1459 sizeof(cfgname));
1460 err = test_aead_vec_cfg(driver, enc, vec, vec_num,
1461 &cfg, req, tsgls);
1462 if (err)
1463 return err;
1464 }
1465 }
1466#endif
1467 return 0;
1468}
1469
1470static int test_aead(const char *driver, int enc,
1471 const struct aead_test_suite *suite,
1472 struct aead_request *req,
1473 struct cipher_test_sglists *tsgls)
1474{
1475 unsigned int i;
1476 int err;
1477
1478 for (i = 0; i < suite->count; i++) {
1479 err = test_aead_vec(driver, enc, &suite->vecs[i], i, req,
1480 tsgls);
1481 if (err)
1482 return err;
1483 }
1484 return 0;
1485}
1486
1487static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1488 u32 type, u32 mask)
1489{
1490 const struct aead_test_suite *suite = &desc->suite.aead;
1491 struct crypto_aead *tfm;
1492 struct aead_request *req = NULL;
1493 struct cipher_test_sglists *tsgls = NULL;
1494 int err;
1495
1496 if (suite->count <= 0) {
1497 pr_err("alg: aead: empty test suite for %s\n", driver);
1498 return -EINVAL;
1499 }
1500
1501 tfm = crypto_alloc_aead(driver, type, mask);
1502 if (IS_ERR(tfm)) {
1503 pr_err("alg: aead: failed to allocate transform for %s: %ld\n",
1504 driver, PTR_ERR(tfm));
1505 return PTR_ERR(tfm);
1506 }
1507
1508 req = aead_request_alloc(tfm, GFP_KERNEL);
1509 if (!req) {
1510 pr_err("alg: aead: failed to allocate request for %s\n",
1511 driver);
1512 err = -ENOMEM;
1513 goto out;
1514 }
1515
1516 tsgls = alloc_cipher_test_sglists();
1517 if (!tsgls) {
1518 pr_err("alg: aead: failed to allocate test buffers for %s\n",
1519 driver);
1520 err = -ENOMEM;
1521 goto out;
1522 }
1523
1524 err = test_aead(driver, ENCRYPT, suite, req, tsgls);
1525 if (err)
1526 goto out;
1527
1528 err = test_aead(driver, DECRYPT, suite, req, tsgls);
1529out:
1530 free_cipher_test_sglists(tsgls);
1531 aead_request_free(req);
1532 crypto_free_aead(tfm);
1533 return err;
1534}
1535
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001536static int test_cipher(struct crypto_cipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001537 const struct cipher_testvec *template,
1538 unsigned int tcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08001539{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001540 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
1541 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001542 char *q;
1543 const char *e;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001544 const char *input, *result;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001545 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001546 char *xbuf[XBUFSIZE];
1547 int ret = -ENOMEM;
1548
1549 if (testmgr_alloc_buf(xbuf))
1550 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001551
1552 if (enc == ENCRYPT)
1553 e = "encryption";
1554 else
1555 e = "decryption";
1556
1557 j = 0;
1558 for (i = 0; i < tcount; i++) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001559
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001560 if (fips_enabled && template[i].fips_skip)
1561 continue;
1562
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001563 input = enc ? template[i].ptext : template[i].ctext;
1564 result = enc ? template[i].ctext : template[i].ptext;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001565 j++;
1566
Herbert Xufd57f222009-05-29 16:05:42 +10001567 ret = -EINVAL;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001568 if (WARN_ON(template[i].len > PAGE_SIZE))
Herbert Xufd57f222009-05-29 16:05:42 +10001569 goto out;
1570
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001571 data = xbuf[0];
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001572 memcpy(data, input, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001573
1574 crypto_cipher_clear_flags(tfm, ~0);
1575 if (template[i].wk)
Eric Biggers231baec2019-01-18 22:48:00 -08001576 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001577
1578 ret = crypto_cipher_setkey(tfm, template[i].key,
1579 template[i].klen);
Eric Biggers5283a8e2019-04-11 21:57:36 -07001580 if (ret) {
1581 if (ret == template[i].setkey_error)
1582 continue;
1583 pr_err("alg: cipher: %s setkey failed on test vector %u; expected_error=%d, actual_error=%d, flags=%#x\n",
1584 algo, j, template[i].setkey_error, ret,
1585 crypto_cipher_get_flags(tfm));
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001586 goto out;
Eric Biggers5283a8e2019-04-11 21:57:36 -07001587 }
1588 if (template[i].setkey_error) {
1589 pr_err("alg: cipher: %s setkey unexpectedly succeeded on test vector %u; expected_error=%d\n",
1590 algo, j, template[i].setkey_error);
1591 ret = -EINVAL;
1592 goto out;
1593 }
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001594
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001595 for (k = 0; k < template[i].len;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001596 k += crypto_cipher_blocksize(tfm)) {
1597 if (enc)
1598 crypto_cipher_encrypt_one(tfm, data + k,
1599 data + k);
1600 else
1601 crypto_cipher_decrypt_one(tfm, data + k,
1602 data + k);
1603 }
1604
1605 q = data;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001606 if (memcmp(q, result, template[i].len)) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001607 printk(KERN_ERR "alg: cipher: Test %d failed "
1608 "on %s for %s\n", j, e, algo);
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001609 hexdump(q, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001610 ret = -EINVAL;
1611 goto out;
1612 }
1613 }
1614
1615 ret = 0;
1616
1617out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001618 testmgr_free_buf(xbuf);
1619out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001620 return ret;
1621}
1622
Eric Biggers4e7babba2019-01-31 23:51:46 -08001623static int test_skcipher_vec_cfg(const char *driver, int enc,
1624 const struct cipher_testvec *vec,
1625 unsigned int vec_num,
1626 const struct testvec_config *cfg,
1627 struct skcipher_request *req,
1628 struct cipher_test_sglists *tsgls)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001629{
Eric Biggers4e7babba2019-01-31 23:51:46 -08001630 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
1631 const unsigned int alignmask = crypto_skcipher_alignmask(tfm);
1632 const unsigned int ivsize = crypto_skcipher_ivsize(tfm);
1633 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
1634 const char *op = enc ? "encryption" : "decryption";
1635 DECLARE_CRYPTO_WAIT(wait);
1636 u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN];
1637 u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) +
1638 cfg->iv_offset +
1639 (cfg->iv_offset_relative_to_alignmask ? alignmask : 0);
1640 struct kvec input;
1641 int err;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001642
Eric Biggers4e7babba2019-01-31 23:51:46 -08001643 /* Set the key */
1644 if (vec->wk)
1645 crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001646 else
Eric Biggers4e7babba2019-01-31 23:51:46 -08001647 crypto_skcipher_clear_flags(tfm,
1648 CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
1649 err = crypto_skcipher_setkey(tfm, vec->key, vec->klen);
1650 if (err) {
Eric Biggers5283a8e2019-04-11 21:57:36 -07001651 if (err == vec->setkey_error)
Eric Biggers4e7babba2019-01-31 23:51:46 -08001652 return 0;
Eric Biggers5283a8e2019-04-11 21:57:36 -07001653 pr_err("alg: skcipher: %s setkey failed on test vector %u; expected_error=%d, actual_error=%d, flags=%#x\n",
1654 driver, vec_num, vec->setkey_error, err,
1655 crypto_skcipher_get_flags(tfm));
Eric Biggers4e7babba2019-01-31 23:51:46 -08001656 return err;
1657 }
Eric Biggers5283a8e2019-04-11 21:57:36 -07001658 if (vec->setkey_error) {
1659 pr_err("alg: skcipher: %s setkey unexpectedly succeeded on test vector %u; expected_error=%d\n",
1660 driver, vec_num, vec->setkey_error);
Eric Biggers4e7babba2019-01-31 23:51:46 -08001661 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08001662 }
1663
Eric Biggers4e7babba2019-01-31 23:51:46 -08001664 /* The IV must be copied to a buffer, as the algorithm may modify it */
1665 if (ivsize) {
1666 if (WARN_ON(ivsize > MAX_IVLEN))
1667 return -EINVAL;
Eric Biggers8efd9722019-02-14 00:03:51 -08001668 if (vec->generates_iv && !enc)
1669 memcpy(iv, vec->iv_out, ivsize);
1670 else if (vec->iv)
Eric Biggers4e7babba2019-01-31 23:51:46 -08001671 memcpy(iv, vec->iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001672 else
Eric Biggers4e7babba2019-01-31 23:51:46 -08001673 memset(iv, 0, ivsize);
1674 } else {
1675 if (vec->generates_iv) {
1676 pr_err("alg: skcipher: %s has ivsize=0 but test vector %u generates IV!\n",
1677 driver, vec_num);
1678 return -EINVAL;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001679 }
Eric Biggers4e7babba2019-01-31 23:51:46 -08001680 iv = NULL;
Herbert Xuda7f0332008-07-31 17:08:25 +08001681 }
1682
Eric Biggers4e7babba2019-01-31 23:51:46 -08001683 /* Build the src/dst scatterlists */
1684 input.iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext;
1685 input.iov_len = vec->len;
1686 err = build_cipher_test_sglists(tsgls, cfg, alignmask,
1687 vec->len, vec->len, &input, 1);
1688 if (err) {
1689 pr_err("alg: skcipher: %s %s: error preparing scatterlists for test vector %u, cfg=\"%s\"\n",
1690 driver, op, vec_num, cfg->name);
1691 return err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001692 }
1693
Eric Biggers4e7babba2019-01-31 23:51:46 -08001694 /* Do the actual encryption or decryption */
1695 testmgr_poison(req->__ctx, crypto_skcipher_reqsize(tfm));
1696 skcipher_request_set_callback(req, req_flags, crypto_req_done, &wait);
1697 skcipher_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr,
1698 vec->len, iv);
Eric Biggers65707372019-03-12 22:12:52 -07001699 if (cfg->nosimd)
1700 crypto_disable_simd_for_test();
1701 err = enc ? crypto_skcipher_encrypt(req) : crypto_skcipher_decrypt(req);
1702 if (cfg->nosimd)
1703 crypto_reenable_simd_for_test();
1704 err = crypto_wait_req(err, &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001705
Eric Biggersfa353c92019-01-31 23:51:49 -08001706 /* Check that the algorithm didn't overwrite things it shouldn't have */
1707 if (req->cryptlen != vec->len ||
1708 req->iv != iv ||
1709 req->src != tsgls->src.sgl_ptr ||
1710 req->dst != tsgls->dst.sgl_ptr ||
1711 crypto_skcipher_reqtfm(req) != tfm ||
1712 req->base.complete != crypto_req_done ||
1713 req->base.flags != req_flags ||
1714 req->base.data != &wait) {
1715 pr_err("alg: skcipher: %s %s corrupted request struct on test vector %u, cfg=\"%s\"\n",
1716 driver, op, vec_num, cfg->name);
1717 if (req->cryptlen != vec->len)
1718 pr_err("alg: skcipher: changed 'req->cryptlen'\n");
1719 if (req->iv != iv)
1720 pr_err("alg: skcipher: changed 'req->iv'\n");
1721 if (req->src != tsgls->src.sgl_ptr)
1722 pr_err("alg: skcipher: changed 'req->src'\n");
1723 if (req->dst != tsgls->dst.sgl_ptr)
1724 pr_err("alg: skcipher: changed 'req->dst'\n");
1725 if (crypto_skcipher_reqtfm(req) != tfm)
1726 pr_err("alg: skcipher: changed 'req->base.tfm'\n");
1727 if (req->base.complete != crypto_req_done)
1728 pr_err("alg: skcipher: changed 'req->base.complete'\n");
1729 if (req->base.flags != req_flags)
1730 pr_err("alg: skcipher: changed 'req->base.flags'\n");
1731 if (req->base.data != &wait)
1732 pr_err("alg: skcipher: changed 'req->base.data'\n");
1733 return -EINVAL;
1734 }
1735 if (is_test_sglist_corrupted(&tsgls->src)) {
1736 pr_err("alg: skcipher: %s %s corrupted src sgl on test vector %u, cfg=\"%s\"\n",
1737 driver, op, vec_num, cfg->name);
1738 return -EINVAL;
1739 }
1740 if (tsgls->dst.sgl_ptr != tsgls->src.sgl &&
1741 is_test_sglist_corrupted(&tsgls->dst)) {
1742 pr_err("alg: skcipher: %s %s corrupted dst sgl on test vector %u, cfg=\"%s\"\n",
1743 driver, op, vec_num, cfg->name);
1744 return -EINVAL;
1745 }
1746
Eric Biggers5283a8e2019-04-11 21:57:36 -07001747 /* Check for success or failure */
1748 if (err) {
1749 if (err == vec->crypt_error)
1750 return 0;
1751 pr_err("alg: skcipher: %s %s failed on test vector %u; expected_error=%d, actual_error=%d, cfg=\"%s\"\n",
1752 driver, op, vec_num, vec->crypt_error, err, cfg->name);
1753 return err;
1754 }
1755 if (vec->crypt_error) {
1756 pr_err("alg: skcipher: %s %s unexpectedly succeeded on test vector %u; expected_error=%d, cfg=\"%s\"\n",
1757 driver, op, vec_num, vec->crypt_error, cfg->name);
1758 return -EINVAL;
1759 }
1760
Eric Biggers4e7babba2019-01-31 23:51:46 -08001761 /* Check for the correct output (ciphertext or plaintext) */
1762 err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext,
1763 vec->len, 0, true);
1764 if (err == -EOVERFLOW) {
1765 pr_err("alg: skcipher: %s %s overran dst buffer on test vector %u, cfg=\"%s\"\n",
1766 driver, op, vec_num, cfg->name);
1767 return err;
1768 }
1769 if (err) {
1770 pr_err("alg: skcipher: %s %s test failed (wrong result) on test vector %u, cfg=\"%s\"\n",
1771 driver, op, vec_num, cfg->name);
1772 return err;
1773 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001774
Eric Biggers4e7babba2019-01-31 23:51:46 -08001775 /* If applicable, check that the algorithm generated the correct IV */
Eric Biggers8efd9722019-02-14 00:03:51 -08001776 if (vec->iv_out && memcmp(iv, vec->iv_out, ivsize) != 0) {
Eric Biggers4e7babba2019-01-31 23:51:46 -08001777 pr_err("alg: skcipher: %s %s test failed (wrong output IV) on test vector %u, cfg=\"%s\"\n",
1778 driver, op, vec_num, cfg->name);
1779 hexdump(iv, ivsize);
1780 return -EINVAL;
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001781 }
1782
1783 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001784}
1785
Eric Biggers4e7babba2019-01-31 23:51:46 -08001786static int test_skcipher_vec(const char *driver, int enc,
1787 const struct cipher_testvec *vec,
1788 unsigned int vec_num,
1789 struct skcipher_request *req,
1790 struct cipher_test_sglists *tsgls)
1791{
1792 unsigned int i;
1793 int err;
1794
1795 if (fips_enabled && vec->fips_skip)
1796 return 0;
1797
1798 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
1799 err = test_skcipher_vec_cfg(driver, enc, vec, vec_num,
1800 &default_cipher_testvec_configs[i],
1801 req, tsgls);
1802 if (err)
1803 return err;
1804 }
1805
1806#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1807 if (!noextratests) {
1808 struct testvec_config cfg;
1809 char cfgname[TESTVEC_CONFIG_NAMELEN];
1810
1811 for (i = 0; i < fuzz_iterations; i++) {
1812 generate_random_testvec_config(&cfg, cfgname,
1813 sizeof(cfgname));
1814 err = test_skcipher_vec_cfg(driver, enc, vec, vec_num,
1815 &cfg, req, tsgls);
1816 if (err)
1817 return err;
1818 }
1819 }
1820#endif
1821 return 0;
1822}
1823
1824static int test_skcipher(const char *driver, int enc,
1825 const struct cipher_test_suite *suite,
1826 struct skcipher_request *req,
1827 struct cipher_test_sglists *tsgls)
1828{
1829 unsigned int i;
1830 int err;
1831
1832 for (i = 0; i < suite->count; i++) {
1833 err = test_skcipher_vec(driver, enc, &suite->vecs[i], i, req,
1834 tsgls);
1835 if (err)
1836 return err;
1837 }
1838 return 0;
1839}
1840
1841static int alg_test_skcipher(const struct alg_test_desc *desc,
1842 const char *driver, u32 type, u32 mask)
1843{
1844 const struct cipher_test_suite *suite = &desc->suite.cipher;
1845 struct crypto_skcipher *tfm;
1846 struct skcipher_request *req = NULL;
1847 struct cipher_test_sglists *tsgls = NULL;
1848 int err;
1849
1850 if (suite->count <= 0) {
1851 pr_err("alg: skcipher: empty test suite for %s\n", driver);
1852 return -EINVAL;
1853 }
1854
1855 tfm = crypto_alloc_skcipher(driver, type, mask);
1856 if (IS_ERR(tfm)) {
1857 pr_err("alg: skcipher: failed to allocate transform for %s: %ld\n",
1858 driver, PTR_ERR(tfm));
1859 return PTR_ERR(tfm);
1860 }
1861
1862 req = skcipher_request_alloc(tfm, GFP_KERNEL);
1863 if (!req) {
1864 pr_err("alg: skcipher: failed to allocate request for %s\n",
1865 driver);
1866 err = -ENOMEM;
1867 goto out;
1868 }
1869
1870 tsgls = alloc_cipher_test_sglists();
1871 if (!tsgls) {
1872 pr_err("alg: skcipher: failed to allocate test buffers for %s\n",
1873 driver);
1874 err = -ENOMEM;
1875 goto out;
1876 }
1877
1878 err = test_skcipher(driver, ENCRYPT, suite, req, tsgls);
1879 if (err)
1880 goto out;
1881
1882 err = test_skcipher(driver, DECRYPT, suite, req, tsgls);
1883out:
1884 free_cipher_test_sglists(tsgls);
1885 skcipher_request_free(req);
1886 crypto_free_skcipher(tfm);
1887 return err;
1888}
1889
Eric Biggersb13b1e02017-02-24 15:46:59 -08001890static int test_comp(struct crypto_comp *tfm,
1891 const struct comp_testvec *ctemplate,
1892 const struct comp_testvec *dtemplate,
1893 int ctcount, int dtcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08001894{
1895 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
Mahipal Challa33607382018-04-11 20:28:32 +02001896 char *output, *decomp_output;
Herbert Xuda7f0332008-07-31 17:08:25 +08001897 unsigned int i;
Herbert Xuda7f0332008-07-31 17:08:25 +08001898 int ret;
1899
Mahipal Challa33607382018-04-11 20:28:32 +02001900 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1901 if (!output)
1902 return -ENOMEM;
1903
1904 decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1905 if (!decomp_output) {
1906 kfree(output);
1907 return -ENOMEM;
1908 }
1909
Herbert Xuda7f0332008-07-31 17:08:25 +08001910 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001911 int ilen;
1912 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001913
Michael Schupikov22a81182018-10-07 13:58:10 +02001914 memset(output, 0, COMP_BUF_SIZE);
1915 memset(decomp_output, 0, COMP_BUF_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +08001916
1917 ilen = ctemplate[i].inlen;
1918 ret = crypto_comp_compress(tfm, ctemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02001919 ilen, output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001920 if (ret) {
1921 printk(KERN_ERR "alg: comp: compression failed "
1922 "on test %d for %s: ret=%d\n", i + 1, algo,
1923 -ret);
1924 goto out;
1925 }
1926
Mahipal Challa33607382018-04-11 20:28:32 +02001927 ilen = dlen;
1928 dlen = COMP_BUF_SIZE;
1929 ret = crypto_comp_decompress(tfm, output,
1930 ilen, decomp_output, &dlen);
1931 if (ret) {
1932 pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n",
1933 i + 1, algo, -ret);
1934 goto out;
1935 }
1936
1937 if (dlen != ctemplate[i].inlen) {
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001938 printk(KERN_ERR "alg: comp: Compression test %d "
1939 "failed for %s: output len = %d\n", i + 1, algo,
1940 dlen);
1941 ret = -EINVAL;
1942 goto out;
1943 }
1944
Mahipal Challa33607382018-04-11 20:28:32 +02001945 if (memcmp(decomp_output, ctemplate[i].input,
1946 ctemplate[i].inlen)) {
1947 pr_err("alg: comp: compression failed: output differs: on test %d for %s\n",
1948 i + 1, algo);
1949 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001950 ret = -EINVAL;
1951 goto out;
1952 }
1953 }
1954
1955 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001956 int ilen;
1957 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001958
Michael Schupikov22a81182018-10-07 13:58:10 +02001959 memset(decomp_output, 0, COMP_BUF_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +08001960
1961 ilen = dtemplate[i].inlen;
1962 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02001963 ilen, decomp_output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001964 if (ret) {
1965 printk(KERN_ERR "alg: comp: decompression failed "
1966 "on test %d for %s: ret=%d\n", i + 1, algo,
1967 -ret);
1968 goto out;
1969 }
1970
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001971 if (dlen != dtemplate[i].outlen) {
1972 printk(KERN_ERR "alg: comp: Decompression test %d "
1973 "failed for %s: output len = %d\n", i + 1, algo,
1974 dlen);
1975 ret = -EINVAL;
1976 goto out;
1977 }
1978
Mahipal Challa33607382018-04-11 20:28:32 +02001979 if (memcmp(decomp_output, dtemplate[i].output, dlen)) {
Herbert Xuda7f0332008-07-31 17:08:25 +08001980 printk(KERN_ERR "alg: comp: Decompression test %d "
1981 "failed for %s\n", i + 1, algo);
Mahipal Challa33607382018-04-11 20:28:32 +02001982 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001983 ret = -EINVAL;
1984 goto out;
1985 }
1986 }
1987
1988 ret = 0;
1989
1990out:
Mahipal Challa33607382018-04-11 20:28:32 +02001991 kfree(decomp_output);
1992 kfree(output);
Herbert Xuda7f0332008-07-31 17:08:25 +08001993 return ret;
1994}
1995
Eric Biggersb13b1e02017-02-24 15:46:59 -08001996static int test_acomp(struct crypto_acomp *tfm,
Mahipal Challa33607382018-04-11 20:28:32 +02001997 const struct comp_testvec *ctemplate,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001998 const struct comp_testvec *dtemplate,
1999 int ctcount, int dtcount)
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002000{
2001 const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
2002 unsigned int i;
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002003 char *output, *decomp_out;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002004 int ret;
2005 struct scatterlist src, dst;
2006 struct acomp_req *req;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002007 struct crypto_wait wait;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002008
Eric Biggerseb095592016-11-23 10:24:35 -08002009 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
2010 if (!output)
2011 return -ENOMEM;
2012
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002013 decomp_out = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
2014 if (!decomp_out) {
2015 kfree(output);
2016 return -ENOMEM;
2017 }
2018
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002019 for (i = 0; i < ctcount; i++) {
2020 unsigned int dlen = COMP_BUF_SIZE;
2021 int ilen = ctemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08002022 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002023
Eric Biggersd2110222016-12-30 14:12:00 -06002024 input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08002025 if (!input_vec) {
2026 ret = -ENOMEM;
2027 goto out;
2028 }
2029
Eric Biggerseb095592016-11-23 10:24:35 -08002030 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002031 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08002032 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002033 sg_init_one(&dst, output, dlen);
2034
2035 req = acomp_request_alloc(tfm);
2036 if (!req) {
2037 pr_err("alg: acomp: request alloc failed for %s\n",
2038 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08002039 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002040 ret = -ENOMEM;
2041 goto out;
2042 }
2043
2044 acomp_request_set_params(req, &src, &dst, ilen, dlen);
2045 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002046 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002047
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002048 ret = crypto_wait_req(crypto_acomp_compress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002049 if (ret) {
2050 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
2051 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08002052 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002053 acomp_request_free(req);
2054 goto out;
2055 }
2056
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002057 ilen = req->dlen;
2058 dlen = COMP_BUF_SIZE;
2059 sg_init_one(&src, output, ilen);
2060 sg_init_one(&dst, decomp_out, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002061 crypto_init_wait(&wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002062 acomp_request_set_params(req, &src, &dst, ilen, dlen);
2063
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002064 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002065 if (ret) {
2066 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
2067 i + 1, algo, -ret);
2068 kfree(input_vec);
2069 acomp_request_free(req);
2070 goto out;
2071 }
2072
2073 if (req->dlen != ctemplate[i].inlen) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002074 pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
2075 i + 1, algo, req->dlen);
2076 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002077 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002078 acomp_request_free(req);
2079 goto out;
2080 }
2081
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002082 if (memcmp(input_vec, decomp_out, req->dlen)) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002083 pr_err("alg: acomp: Compression test %d failed for %s\n",
2084 i + 1, algo);
2085 hexdump(output, req->dlen);
2086 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002087 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002088 acomp_request_free(req);
2089 goto out;
2090 }
2091
Laura Abbott02608e02016-12-21 12:32:54 -08002092 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002093 acomp_request_free(req);
2094 }
2095
2096 for (i = 0; i < dtcount; i++) {
2097 unsigned int dlen = COMP_BUF_SIZE;
2098 int ilen = dtemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08002099 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002100
Eric Biggersd2110222016-12-30 14:12:00 -06002101 input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08002102 if (!input_vec) {
2103 ret = -ENOMEM;
2104 goto out;
2105 }
2106
Eric Biggerseb095592016-11-23 10:24:35 -08002107 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002108 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08002109 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002110 sg_init_one(&dst, output, dlen);
2111
2112 req = acomp_request_alloc(tfm);
2113 if (!req) {
2114 pr_err("alg: acomp: request alloc failed for %s\n",
2115 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08002116 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002117 ret = -ENOMEM;
2118 goto out;
2119 }
2120
2121 acomp_request_set_params(req, &src, &dst, ilen, dlen);
2122 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002123 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002124
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002125 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002126 if (ret) {
2127 pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
2128 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08002129 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002130 acomp_request_free(req);
2131 goto out;
2132 }
2133
2134 if (req->dlen != dtemplate[i].outlen) {
2135 pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
2136 i + 1, algo, req->dlen);
2137 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002138 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002139 acomp_request_free(req);
2140 goto out;
2141 }
2142
2143 if (memcmp(output, dtemplate[i].output, req->dlen)) {
2144 pr_err("alg: acomp: Decompression test %d failed for %s\n",
2145 i + 1, algo);
2146 hexdump(output, req->dlen);
2147 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002148 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002149 acomp_request_free(req);
2150 goto out;
2151 }
2152
Laura Abbott02608e02016-12-21 12:32:54 -08002153 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002154 acomp_request_free(req);
2155 }
2156
2157 ret = 0;
2158
2159out:
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002160 kfree(decomp_out);
Eric Biggerseb095592016-11-23 10:24:35 -08002161 kfree(output);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002162 return ret;
2163}
2164
Eric Biggersb13b1e02017-02-24 15:46:59 -08002165static int test_cprng(struct crypto_rng *tfm,
2166 const struct cprng_testvec *template,
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002167 unsigned int tcount)
2168{
2169 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08002170 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002171 u8 *seed;
2172 char result[32];
2173
2174 seedsize = crypto_rng_seedsize(tfm);
2175
2176 seed = kmalloc(seedsize, GFP_KERNEL);
2177 if (!seed) {
2178 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
2179 "for %s\n", algo);
2180 return -ENOMEM;
2181 }
2182
2183 for (i = 0; i < tcount; i++) {
2184 memset(result, 0, 32);
2185
2186 memcpy(seed, template[i].v, template[i].vlen);
2187 memcpy(seed + template[i].vlen, template[i].key,
2188 template[i].klen);
2189 memcpy(seed + template[i].vlen + template[i].klen,
2190 template[i].dt, template[i].dtlen);
2191
2192 err = crypto_rng_reset(tfm, seed, seedsize);
2193 if (err) {
2194 printk(KERN_ERR "alg: cprng: Failed to reset rng "
2195 "for %s\n", algo);
2196 goto out;
2197 }
2198
2199 for (j = 0; j < template[i].loops; j++) {
2200 err = crypto_rng_get_bytes(tfm, result,
2201 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01002202 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002203 printk(KERN_ERR "alg: cprng: Failed to obtain "
2204 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01002205 "%s (requested %d)\n", algo,
2206 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002207 goto out;
2208 }
2209 }
2210
2211 err = memcmp(result, template[i].result,
2212 template[i].rlen);
2213 if (err) {
2214 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
2215 i, algo);
2216 hexdump(result, template[i].rlen);
2217 err = -EINVAL;
2218 goto out;
2219 }
2220 }
2221
2222out:
2223 kfree(seed);
2224 return err;
2225}
2226
Herbert Xuda7f0332008-07-31 17:08:25 +08002227static int alg_test_cipher(const struct alg_test_desc *desc,
2228 const char *driver, u32 type, u32 mask)
2229{
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002230 const struct cipher_test_suite *suite = &desc->suite.cipher;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002231 struct crypto_cipher *tfm;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002232 int err;
Herbert Xuda7f0332008-07-31 17:08:25 +08002233
Herbert Xueed93e02016-11-22 20:08:31 +08002234 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08002235 if (IS_ERR(tfm)) {
2236 printk(KERN_ERR "alg: cipher: Failed to load transform for "
2237 "%s: %ld\n", driver, PTR_ERR(tfm));
2238 return PTR_ERR(tfm);
2239 }
2240
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002241 err = test_cipher(tfm, ENCRYPT, suite->vecs, suite->count);
2242 if (!err)
2243 err = test_cipher(tfm, DECRYPT, suite->vecs, suite->count);
Herbert Xuda7f0332008-07-31 17:08:25 +08002244
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002245 crypto_free_cipher(tfm);
2246 return err;
2247}
2248
Herbert Xuda7f0332008-07-31 17:08:25 +08002249static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
2250 u32 type, u32 mask)
2251{
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002252 struct crypto_comp *comp;
2253 struct crypto_acomp *acomp;
Herbert Xuda7f0332008-07-31 17:08:25 +08002254 int err;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002255 u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
Herbert Xuda7f0332008-07-31 17:08:25 +08002256
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002257 if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
2258 acomp = crypto_alloc_acomp(driver, type, mask);
2259 if (IS_ERR(acomp)) {
2260 pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
2261 driver, PTR_ERR(acomp));
2262 return PTR_ERR(acomp);
2263 }
2264 err = test_acomp(acomp, desc->suite.comp.comp.vecs,
2265 desc->suite.comp.decomp.vecs,
2266 desc->suite.comp.comp.count,
2267 desc->suite.comp.decomp.count);
2268 crypto_free_acomp(acomp);
2269 } else {
2270 comp = crypto_alloc_comp(driver, type, mask);
2271 if (IS_ERR(comp)) {
2272 pr_err("alg: comp: Failed to load transform for %s: %ld\n",
2273 driver, PTR_ERR(comp));
2274 return PTR_ERR(comp);
2275 }
2276
2277 err = test_comp(comp, desc->suite.comp.comp.vecs,
2278 desc->suite.comp.decomp.vecs,
2279 desc->suite.comp.comp.count,
2280 desc->suite.comp.decomp.count);
2281
2282 crypto_free_comp(comp);
Herbert Xuda7f0332008-07-31 17:08:25 +08002283 }
Herbert Xuda7f0332008-07-31 17:08:25 +08002284 return err;
2285}
2286
Herbert Xu8e3ee852008-11-07 14:58:52 +08002287static int alg_test_crc32c(const struct alg_test_desc *desc,
2288 const char *driver, u32 type, u32 mask)
2289{
2290 struct crypto_shash *tfm;
Eric Biggerscb9dde82019-01-10 12:17:55 -08002291 __le32 val;
Herbert Xu8e3ee852008-11-07 14:58:52 +08002292 int err;
2293
2294 err = alg_test_hash(desc, driver, type, mask);
2295 if (err)
Eric Biggerseb5e6732019-01-23 20:57:35 -08002296 return err;
Herbert Xu8e3ee852008-11-07 14:58:52 +08002297
Herbert Xueed93e02016-11-22 20:08:31 +08002298 tfm = crypto_alloc_shash(driver, type, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002299 if (IS_ERR(tfm)) {
Eric Biggerseb5e6732019-01-23 20:57:35 -08002300 if (PTR_ERR(tfm) == -ENOENT) {
2301 /*
2302 * This crc32c implementation is only available through
2303 * ahash API, not the shash API, so the remaining part
2304 * of the test is not applicable to it.
2305 */
2306 return 0;
2307 }
Herbert Xu8e3ee852008-11-07 14:58:52 +08002308 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
2309 "%ld\n", driver, PTR_ERR(tfm));
Eric Biggerseb5e6732019-01-23 20:57:35 -08002310 return PTR_ERR(tfm);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002311 }
2312
2313 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02002314 SHASH_DESC_ON_STACK(shash, tfm);
2315 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002316
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02002317 shash->tfm = tfm;
2318 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08002319
Eric Biggerscb9dde82019-01-10 12:17:55 -08002320 *ctx = 420553207;
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02002321 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002322 if (err) {
2323 printk(KERN_ERR "alg: crc32c: Operation failed for "
2324 "%s: %d\n", driver, err);
2325 break;
2326 }
2327
Eric Biggerscb9dde82019-01-10 12:17:55 -08002328 if (val != cpu_to_le32(~420553207)) {
2329 pr_err("alg: crc32c: Test failed for %s: %u\n",
2330 driver, le32_to_cpu(val));
Herbert Xu8e3ee852008-11-07 14:58:52 +08002331 err = -EINVAL;
2332 }
2333 } while (0);
2334
2335 crypto_free_shash(tfm);
2336
Herbert Xu8e3ee852008-11-07 14:58:52 +08002337 return err;
2338}
2339
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002340static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
2341 u32 type, u32 mask)
2342{
2343 struct crypto_rng *rng;
2344 int err;
2345
Herbert Xueed93e02016-11-22 20:08:31 +08002346 rng = crypto_alloc_rng(driver, type, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002347 if (IS_ERR(rng)) {
2348 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
2349 "%ld\n", driver, PTR_ERR(rng));
2350 return PTR_ERR(rng);
2351 }
2352
2353 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
2354
2355 crypto_free_rng(rng);
2356
2357 return err;
2358}
2359
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002360
Eric Biggersb13b1e02017-02-24 15:46:59 -08002361static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002362 const char *driver, u32 type, u32 mask)
2363{
2364 int ret = -EAGAIN;
2365 struct crypto_rng *drng;
2366 struct drbg_test_data test_data;
2367 struct drbg_string addtl, pers, testentropy;
2368 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
2369
2370 if (!buf)
2371 return -ENOMEM;
2372
Herbert Xueed93e02016-11-22 20:08:31 +08002373 drng = crypto_alloc_rng(driver, type, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002374 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002375 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002376 "%s\n", driver);
2377 kzfree(buf);
2378 return -ENOMEM;
2379 }
2380
2381 test_data.testentropy = &testentropy;
2382 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
2383 drbg_string_fill(&pers, test->pers, test->perslen);
2384 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
2385 if (ret) {
2386 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
2387 goto outbuf;
2388 }
2389
2390 drbg_string_fill(&addtl, test->addtla, test->addtllen);
2391 if (pr) {
2392 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
2393 ret = crypto_drbg_get_bytes_addtl_test(drng,
2394 buf, test->expectedlen, &addtl, &test_data);
2395 } else {
2396 ret = crypto_drbg_get_bytes_addtl(drng,
2397 buf, test->expectedlen, &addtl);
2398 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01002399 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002400 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002401 "driver %s\n", driver);
2402 goto outbuf;
2403 }
2404
2405 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
2406 if (pr) {
2407 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
2408 ret = crypto_drbg_get_bytes_addtl_test(drng,
2409 buf, test->expectedlen, &addtl, &test_data);
2410 } else {
2411 ret = crypto_drbg_get_bytes_addtl(drng,
2412 buf, test->expectedlen, &addtl);
2413 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01002414 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002415 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002416 "driver %s\n", driver);
2417 goto outbuf;
2418 }
2419
2420 ret = memcmp(test->expected, buf, test->expectedlen);
2421
2422outbuf:
2423 crypto_free_rng(drng);
2424 kzfree(buf);
2425 return ret;
2426}
2427
2428
2429static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
2430 u32 type, u32 mask)
2431{
2432 int err = 0;
2433 int pr = 0;
2434 int i = 0;
Eric Biggersb13b1e02017-02-24 15:46:59 -08002435 const struct drbg_testvec *template = desc->suite.drbg.vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002436 unsigned int tcount = desc->suite.drbg.count;
2437
2438 if (0 == memcmp(driver, "drbg_pr_", 8))
2439 pr = 1;
2440
2441 for (i = 0; i < tcount; i++) {
2442 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
2443 if (err) {
2444 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
2445 i, driver);
2446 err = -EINVAL;
2447 break;
2448 }
2449 }
2450 return err;
2451
2452}
2453
Eric Biggersb13b1e02017-02-24 15:46:59 -08002454static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002455 const char *alg)
2456{
2457 struct kpp_request *req;
2458 void *input_buf = NULL;
2459 void *output_buf = NULL;
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002460 void *a_public = NULL;
2461 void *a_ss = NULL;
2462 void *shared_secret = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002463 struct crypto_wait wait;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002464 unsigned int out_len_max;
2465 int err = -ENOMEM;
2466 struct scatterlist src, dst;
2467
2468 req = kpp_request_alloc(tfm, GFP_KERNEL);
2469 if (!req)
2470 return err;
2471
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002472 crypto_init_wait(&wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002473
2474 err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
2475 if (err < 0)
2476 goto free_req;
2477
2478 out_len_max = crypto_kpp_maxsize(tfm);
2479 output_buf = kzalloc(out_len_max, GFP_KERNEL);
2480 if (!output_buf) {
2481 err = -ENOMEM;
2482 goto free_req;
2483 }
2484
2485 /* Use appropriate parameter as base */
2486 kpp_request_set_input(req, NULL, 0);
2487 sg_init_one(&dst, output_buf, out_len_max);
2488 kpp_request_set_output(req, &dst, out_len_max);
2489 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002490 crypto_req_done, &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002491
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002492 /* Compute party A's public key */
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002493 err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002494 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002495 pr_err("alg: %s: Party A: generate public key test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002496 alg, err);
2497 goto free_output;
2498 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002499
2500 if (vec->genkey) {
2501 /* Save party A's public key */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05002502 a_public = kmemdup(sg_virt(req->dst), out_len_max, GFP_KERNEL);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002503 if (!a_public) {
2504 err = -ENOMEM;
2505 goto free_output;
2506 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002507 } else {
2508 /* Verify calculated public key */
2509 if (memcmp(vec->expected_a_public, sg_virt(req->dst),
2510 vec->expected_a_public_size)) {
2511 pr_err("alg: %s: Party A: generate public key test failed. Invalid output\n",
2512 alg);
2513 err = -EINVAL;
2514 goto free_output;
2515 }
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002516 }
2517
2518 /* Calculate shared secret key by using counter part (b) public key. */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05002519 input_buf = kmemdup(vec->b_public, vec->b_public_size, GFP_KERNEL);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002520 if (!input_buf) {
2521 err = -ENOMEM;
2522 goto free_output;
2523 }
2524
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002525 sg_init_one(&src, input_buf, vec->b_public_size);
2526 sg_init_one(&dst, output_buf, out_len_max);
2527 kpp_request_set_input(req, &src, vec->b_public_size);
2528 kpp_request_set_output(req, &dst, out_len_max);
2529 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002530 crypto_req_done, &wait);
2531 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002532 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002533 pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002534 alg, err);
2535 goto free_all;
2536 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002537
2538 if (vec->genkey) {
2539 /* Save the shared secret obtained by party A */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05002540 a_ss = kmemdup(sg_virt(req->dst), vec->expected_ss_size, GFP_KERNEL);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002541 if (!a_ss) {
2542 err = -ENOMEM;
2543 goto free_all;
2544 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002545
2546 /*
2547 * Calculate party B's shared secret by using party A's
2548 * public key.
2549 */
2550 err = crypto_kpp_set_secret(tfm, vec->b_secret,
2551 vec->b_secret_size);
2552 if (err < 0)
2553 goto free_all;
2554
2555 sg_init_one(&src, a_public, vec->expected_a_public_size);
2556 sg_init_one(&dst, output_buf, out_len_max);
2557 kpp_request_set_input(req, &src, vec->expected_a_public_size);
2558 kpp_request_set_output(req, &dst, out_len_max);
2559 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002560 crypto_req_done, &wait);
2561 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req),
2562 &wait);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002563 if (err) {
2564 pr_err("alg: %s: Party B: compute shared secret failed. err %d\n",
2565 alg, err);
2566 goto free_all;
2567 }
2568
2569 shared_secret = a_ss;
2570 } else {
2571 shared_secret = (void *)vec->expected_ss;
2572 }
2573
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002574 /*
2575 * verify shared secret from which the user will derive
2576 * secret key by executing whatever hash it has chosen
2577 */
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002578 if (memcmp(shared_secret, sg_virt(req->dst),
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002579 vec->expected_ss_size)) {
2580 pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
2581 alg);
2582 err = -EINVAL;
2583 }
2584
2585free_all:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002586 kfree(a_ss);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002587 kfree(input_buf);
2588free_output:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002589 kfree(a_public);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002590 kfree(output_buf);
2591free_req:
2592 kpp_request_free(req);
2593 return err;
2594}
2595
2596static int test_kpp(struct crypto_kpp *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002597 const struct kpp_testvec *vecs, unsigned int tcount)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002598{
2599 int ret, i;
2600
2601 for (i = 0; i < tcount; i++) {
2602 ret = do_test_kpp(tfm, vecs++, alg);
2603 if (ret) {
2604 pr_err("alg: %s: test failed on vector %d, err=%d\n",
2605 alg, i + 1, ret);
2606 return ret;
2607 }
2608 }
2609 return 0;
2610}
2611
2612static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
2613 u32 type, u32 mask)
2614{
2615 struct crypto_kpp *tfm;
2616 int err = 0;
2617
Herbert Xueed93e02016-11-22 20:08:31 +08002618 tfm = crypto_alloc_kpp(driver, type, mask);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002619 if (IS_ERR(tfm)) {
2620 pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
2621 driver, PTR_ERR(tfm));
2622 return PTR_ERR(tfm);
2623 }
2624 if (desc->suite.kpp.vecs)
2625 err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
2626 desc->suite.kpp.count);
2627
2628 crypto_free_kpp(tfm);
2629 return err;
2630}
2631
Vitaly Chikunovf1774cb2019-04-11 18:51:17 +03002632static u8 *test_pack_u32(u8 *dst, u32 val)
2633{
2634 memcpy(dst, &val, sizeof(val));
2635 return dst + sizeof(val);
2636}
2637
Herbert Xu50d2b6432016-06-29 19:32:20 +08002638static int test_akcipher_one(struct crypto_akcipher *tfm,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002639 const struct akcipher_testvec *vecs)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002640{
Herbert Xudf27b262016-05-05 16:42:49 +08002641 char *xbuf[XBUFSIZE];
Tadeusz Struk946cc462015-06-16 10:31:06 -07002642 struct akcipher_request *req;
2643 void *outbuf_enc = NULL;
2644 void *outbuf_dec = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002645 struct crypto_wait wait;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002646 unsigned int out_len_max, out_len = 0;
2647 int err = -ENOMEM;
Vitaly Chikunovc7381b02019-04-11 18:51:15 +03002648 struct scatterlist src, dst, src_tab[3];
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002649 const char *m, *c;
2650 unsigned int m_size, c_size;
2651 const char *op;
Vitaly Chikunovf1774cb2019-04-11 18:51:17 +03002652 u8 *key, *ptr;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002653
Herbert Xudf27b262016-05-05 16:42:49 +08002654 if (testmgr_alloc_buf(xbuf))
2655 return err;
2656
Tadeusz Struk946cc462015-06-16 10:31:06 -07002657 req = akcipher_request_alloc(tfm, GFP_KERNEL);
2658 if (!req)
Herbert Xudf27b262016-05-05 16:42:49 +08002659 goto free_xbuf;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002660
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002661 crypto_init_wait(&wait);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002662
Vitaly Chikunovf1774cb2019-04-11 18:51:17 +03002663 key = kmalloc(vecs->key_len + sizeof(u32) * 2 + vecs->param_len,
2664 GFP_KERNEL);
2665 if (!key)
2666 goto free_xbuf;
2667 memcpy(key, vecs->key, vecs->key_len);
2668 ptr = key + vecs->key_len;
2669 ptr = test_pack_u32(ptr, vecs->algo);
2670 ptr = test_pack_u32(ptr, vecs->param_len);
2671 memcpy(ptr, vecs->params, vecs->param_len);
2672
Tadeusz Struk22287b02015-10-08 09:26:55 -07002673 if (vecs->public_key_vec)
Vitaly Chikunovf1774cb2019-04-11 18:51:17 +03002674 err = crypto_akcipher_set_pub_key(tfm, key, vecs->key_len);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002675 else
Vitaly Chikunovf1774cb2019-04-11 18:51:17 +03002676 err = crypto_akcipher_set_priv_key(tfm, key, vecs->key_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002677 if (err)
2678 goto free_req;
2679
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002680 /*
2681 * First run test which do not require a private key, such as
2682 * encrypt or verify.
2683 */
Vitaly Chikunovc7381b02019-04-11 18:51:15 +03002684 err = -ENOMEM;
2685 out_len_max = crypto_akcipher_maxsize(tfm);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002686 outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
2687 if (!outbuf_enc)
2688 goto free_req;
2689
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002690 if (!vecs->siggen_sigver_test) {
2691 m = vecs->m;
2692 m_size = vecs->m_size;
2693 c = vecs->c;
2694 c_size = vecs->c_size;
2695 op = "encrypt";
2696 } else {
2697 /* Swap args so we could keep plaintext (digest)
2698 * in vecs->m, and cooked signature in vecs->c.
2699 */
2700 m = vecs->c; /* signature */
2701 m_size = vecs->c_size;
2702 c = vecs->m; /* digest */
2703 c_size = vecs->m_size;
2704 op = "verify";
2705 }
Herbert Xudf27b262016-05-05 16:42:49 +08002706
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002707 if (WARN_ON(m_size > PAGE_SIZE))
2708 goto free_all;
2709 memcpy(xbuf[0], m, m_size);
Herbert Xudf27b262016-05-05 16:42:49 +08002710
Vitaly Chikunovc7381b02019-04-11 18:51:15 +03002711 sg_init_table(src_tab, 3);
Herbert Xudf27b262016-05-05 16:42:49 +08002712 sg_set_buf(&src_tab[0], xbuf[0], 8);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002713 sg_set_buf(&src_tab[1], xbuf[0] + 8, m_size - 8);
Vitaly Chikunovc7381b02019-04-11 18:51:15 +03002714 if (vecs->siggen_sigver_test) {
2715 if (WARN_ON(c_size > PAGE_SIZE))
2716 goto free_all;
2717 memcpy(xbuf[1], c, c_size);
2718 sg_set_buf(&src_tab[2], xbuf[1], c_size);
2719 akcipher_request_set_crypt(req, src_tab, NULL, m_size, c_size);
2720 } else {
2721 sg_init_one(&dst, outbuf_enc, out_len_max);
2722 akcipher_request_set_crypt(req, src_tab, &dst, m_size,
2723 out_len_max);
2724 }
Tadeusz Struk946cc462015-06-16 10:31:06 -07002725 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002726 crypto_req_done, &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002727
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002728 err = crypto_wait_req(vecs->siggen_sigver_test ?
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002729 /* Run asymmetric signature verification */
2730 crypto_akcipher_verify(req) :
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002731 /* Run asymmetric encrypt */
2732 crypto_akcipher_encrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002733 if (err) {
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002734 pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002735 goto free_all;
2736 }
Vitaly Chikunovc7381b02019-04-11 18:51:15 +03002737 if (!vecs->siggen_sigver_test) {
2738 if (req->dst_len != c_size) {
2739 pr_err("alg: akcipher: %s test failed. Invalid output len\n",
2740 op);
2741 err = -EINVAL;
2742 goto free_all;
2743 }
2744 /* verify that encrypted message is equal to expected */
2745 if (memcmp(c, outbuf_enc, c_size) != 0) {
2746 pr_err("alg: akcipher: %s test failed. Invalid output\n",
2747 op);
2748 hexdump(outbuf_enc, c_size);
2749 err = -EINVAL;
2750 goto free_all;
2751 }
Tadeusz Struk946cc462015-06-16 10:31:06 -07002752 }
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002753
2754 /*
2755 * Don't invoke (decrypt or sign) test which require a private key
2756 * for vectors with only a public key.
2757 */
Tadeusz Struk946cc462015-06-16 10:31:06 -07002758 if (vecs->public_key_vec) {
2759 err = 0;
2760 goto free_all;
2761 }
2762 outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
2763 if (!outbuf_dec) {
2764 err = -ENOMEM;
2765 goto free_all;
2766 }
Herbert Xudf27b262016-05-05 16:42:49 +08002767
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002768 op = vecs->siggen_sigver_test ? "sign" : "decrypt";
2769 if (WARN_ON(c_size > PAGE_SIZE))
Herbert Xudf27b262016-05-05 16:42:49 +08002770 goto free_all;
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002771 memcpy(xbuf[0], c, c_size);
Herbert Xudf27b262016-05-05 16:42:49 +08002772
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002773 sg_init_one(&src, xbuf[0], c_size);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002774 sg_init_one(&dst, outbuf_dec, out_len_max);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002775 crypto_init_wait(&wait);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002776 akcipher_request_set_crypt(req, &src, &dst, c_size, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002777
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002778 err = crypto_wait_req(vecs->siggen_sigver_test ?
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002779 /* Run asymmetric signature generation */
2780 crypto_akcipher_sign(req) :
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002781 /* Run asymmetric decrypt */
2782 crypto_akcipher_decrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002783 if (err) {
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002784 pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002785 goto free_all;
2786 }
2787 out_len = req->dst_len;
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002788 if (out_len < m_size) {
2789 pr_err("alg: akcipher: %s test failed. Invalid output len %u\n",
2790 op, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002791 err = -EINVAL;
2792 goto free_all;
2793 }
2794 /* verify that decrypted message is equal to the original msg */
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002795 if (memchr_inv(outbuf_dec, 0, out_len - m_size) ||
2796 memcmp(m, outbuf_dec + out_len - m_size, m_size)) {
2797 pr_err("alg: akcipher: %s test failed. Invalid output\n", op);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002798 hexdump(outbuf_dec, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002799 err = -EINVAL;
2800 }
2801free_all:
2802 kfree(outbuf_dec);
2803 kfree(outbuf_enc);
2804free_req:
2805 akcipher_request_free(req);
Vitaly Chikunovf1774cb2019-04-11 18:51:17 +03002806 kfree(key);
Herbert Xudf27b262016-05-05 16:42:49 +08002807free_xbuf:
2808 testmgr_free_buf(xbuf);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002809 return err;
2810}
2811
Herbert Xu50d2b6432016-06-29 19:32:20 +08002812static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002813 const struct akcipher_testvec *vecs,
2814 unsigned int tcount)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002815{
Herbert Xu15226e42016-07-18 18:20:10 +08002816 const char *algo =
2817 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
Tadeusz Struk946cc462015-06-16 10:31:06 -07002818 int ret, i;
2819
2820 for (i = 0; i < tcount; i++) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002821 ret = test_akcipher_one(tfm, vecs++);
2822 if (!ret)
2823 continue;
2824
Herbert Xu15226e42016-07-18 18:20:10 +08002825 pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
2826 i + 1, algo, ret);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002827 return ret;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002828 }
2829 return 0;
2830}
2831
Tadeusz Struk946cc462015-06-16 10:31:06 -07002832static int alg_test_akcipher(const struct alg_test_desc *desc,
2833 const char *driver, u32 type, u32 mask)
2834{
2835 struct crypto_akcipher *tfm;
2836 int err = 0;
2837
Herbert Xueed93e02016-11-22 20:08:31 +08002838 tfm = crypto_alloc_akcipher(driver, type, mask);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002839 if (IS_ERR(tfm)) {
2840 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
2841 driver, PTR_ERR(tfm));
2842 return PTR_ERR(tfm);
2843 }
2844 if (desc->suite.akcipher.vecs)
2845 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
2846 desc->suite.akcipher.count);
2847
2848 crypto_free_akcipher(tfm);
2849 return err;
2850}
2851
Youquan, Song863b5572009-12-23 19:45:20 +08002852static int alg_test_null(const struct alg_test_desc *desc,
2853 const char *driver, u32 type, u32 mask)
2854{
2855 return 0;
2856}
2857
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002858#define __VECS(tv) { .vecs = tv, .count = ARRAY_SIZE(tv) }
2859
Herbert Xuda7f0332008-07-31 17:08:25 +08002860/* Please keep this list sorted by algorithm name. */
2861static const struct alg_test_desc alg_test_descs[] = {
2862 {
Eric Biggers059c2a42018-11-16 17:26:31 -08002863 .alg = "adiantum(xchacha12,aes)",
2864 .test = alg_test_skcipher,
2865 .suite = {
2866 .cipher = __VECS(adiantum_xchacha12_aes_tv_template)
2867 },
2868 }, {
2869 .alg = "adiantum(xchacha20,aes)",
2870 .test = alg_test_skcipher,
2871 .suite = {
2872 .cipher = __VECS(adiantum_xchacha20_aes_tv_template)
2873 },
2874 }, {
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002875 .alg = "aegis128",
2876 .test = alg_test_aead,
2877 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002878 .aead = __VECS(aegis128_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002879 }
2880 }, {
2881 .alg = "aegis128l",
2882 .test = alg_test_aead,
2883 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002884 .aead = __VECS(aegis128l_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002885 }
2886 }, {
2887 .alg = "aegis256",
2888 .test = alg_test_aead,
2889 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002890 .aead = __VECS(aegis256_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002891 }
2892 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002893 .alg = "ansi_cprng",
2894 .test = alg_test_cprng,
2895 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002896 .cprng = __VECS(ansi_cprng_aes_tv_template)
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002897 }
2898 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002899 .alg = "authenc(hmac(md5),ecb(cipher_null))",
2900 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002901 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002902 .aead = __VECS(hmac_md5_ecb_cipher_null_tv_template)
Horia Geantabca4feb2014-03-14 17:46:51 +02002903 }
2904 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002905 .alg = "authenc(hmac(sha1),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002906 .test = alg_test_aead,
Herbert Xubcf741c2017-06-28 19:09:07 +08002907 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002908 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002909 .aead = __VECS(hmac_sha1_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302910 }
2911 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002912 .alg = "authenc(hmac(sha1),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302913 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302914 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002915 .aead = __VECS(hmac_sha1_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302916 }
2917 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002918 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302919 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002920 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302921 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002922 .aead = __VECS(hmac_sha1_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002923 }
2924 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002925 .alg = "authenc(hmac(sha1),ctr(aes))",
2926 .test = alg_test_null,
2927 .fips_allowed = 1,
2928 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002929 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
2930 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002931 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002932 .aead = __VECS(hmac_sha1_ecb_cipher_null_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302933 }
2934 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002935 .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
2936 .test = alg_test_null,
2937 .fips_allowed = 1,
2938 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002939 .alg = "authenc(hmac(sha224),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302940 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302941 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002942 .aead = __VECS(hmac_sha224_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302943 }
2944 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002945 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302946 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002947 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302948 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002949 .aead = __VECS(hmac_sha224_des3_ede_cbc_tv_temp)
Horia Geantabca4feb2014-03-14 17:46:51 +02002950 }
2951 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002952 .alg = "authenc(hmac(sha256),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002953 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002954 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002955 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002956 .aead = __VECS(hmac_sha256_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302957 }
2958 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002959 .alg = "authenc(hmac(sha256),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302960 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302961 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002962 .aead = __VECS(hmac_sha256_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302963 }
2964 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002965 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302966 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002967 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302968 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002969 .aead = __VECS(hmac_sha256_des3_ede_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302970 }
2971 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002972 .alg = "authenc(hmac(sha256),ctr(aes))",
2973 .test = alg_test_null,
2974 .fips_allowed = 1,
2975 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002976 .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
2977 .test = alg_test_null,
2978 .fips_allowed = 1,
2979 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002980 .alg = "authenc(hmac(sha384),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302981 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302982 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002983 .aead = __VECS(hmac_sha384_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302984 }
2985 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002986 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302987 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002988 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302989 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002990 .aead = __VECS(hmac_sha384_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002991 }
2992 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002993 .alg = "authenc(hmac(sha384),ctr(aes))",
2994 .test = alg_test_null,
2995 .fips_allowed = 1,
2996 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002997 .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
2998 .test = alg_test_null,
2999 .fips_allowed = 1,
3000 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003001 .alg = "authenc(hmac(sha512),cbc(aes))",
Marcus Meissnered1afac2016-02-05 14:23:33 +01003002 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03003003 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03003004 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003005 .aead = __VECS(hmac_sha512_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303006 }
3007 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003008 .alg = "authenc(hmac(sha512),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303009 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303010 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003011 .aead = __VECS(hmac_sha512_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303012 }
3013 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003014 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303015 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01003016 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303017 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003018 .aead = __VECS(hmac_sha512_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03003019 }
3020 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01003021 .alg = "authenc(hmac(sha512),ctr(aes))",
3022 .test = alg_test_null,
3023 .fips_allowed = 1,
3024 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01003025 .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
3026 .test = alg_test_null,
3027 .fips_allowed = 1,
3028 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003029 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003030 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003031 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003032 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003033 .cipher = __VECS(aes_cbc_tv_template)
3034 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003035 }, {
3036 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003037 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003038 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003039 .cipher = __VECS(anubis_cbc_tv_template)
3040 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003041 }, {
3042 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003043 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003044 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003045 .cipher = __VECS(bf_cbc_tv_template)
3046 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003047 }, {
3048 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003049 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003050 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003051 .cipher = __VECS(camellia_cbc_tv_template)
3052 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003053 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003054 .alg = "cbc(cast5)",
3055 .test = alg_test_skcipher,
3056 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003057 .cipher = __VECS(cast5_cbc_tv_template)
3058 },
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003059 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003060 .alg = "cbc(cast6)",
3061 .test = alg_test_skcipher,
3062 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003063 .cipher = __VECS(cast6_cbc_tv_template)
3064 },
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003065 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003066 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003067 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003068 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003069 .cipher = __VECS(des_cbc_tv_template)
3070 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003071 }, {
3072 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003073 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003074 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003075 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003076 .cipher = __VECS(des3_ede_cbc_tv_template)
3077 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003078 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003079 /* Same as cbc(aes) except the key is stored in
3080 * hardware secure memory which we reference by index
3081 */
3082 .alg = "cbc(paes)",
3083 .test = alg_test_null,
3084 .fips_allowed = 1,
3085 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003086 .alg = "cbc(serpent)",
3087 .test = alg_test_skcipher,
3088 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003089 .cipher = __VECS(serpent_cbc_tv_template)
3090 },
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003091 }, {
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01003092 .alg = "cbc(sm4)",
3093 .test = alg_test_skcipher,
3094 .suite = {
3095 .cipher = __VECS(sm4_cbc_tv_template)
3096 }
3097 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003098 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003099 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003100 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003101 .cipher = __VECS(tf_cbc_tv_template)
3102 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003103 }, {
Ard Biesheuvel092acf02017-02-03 14:49:35 +00003104 .alg = "cbcmac(aes)",
3105 .fips_allowed = 1,
3106 .test = alg_test_hash,
3107 .suite = {
3108 .hash = __VECS(aes_cbcmac_tv_template)
3109 }
3110 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003111 .alg = "ccm(aes)",
3112 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003113 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003114 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003115 .aead = __VECS(aes_ccm_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003116 }
3117 }, {
Dmitry Eremin-Solenikov7da66672018-10-20 02:01:53 +03003118 .alg = "cfb(aes)",
3119 .test = alg_test_skcipher,
3120 .fips_allowed = 1,
3121 .suite = {
3122 .cipher = __VECS(aes_cfb_tv_template)
3123 },
3124 }, {
Martin Willi3590ebf2015-06-01 13:43:57 +02003125 .alg = "chacha20",
3126 .test = alg_test_skcipher,
3127 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003128 .cipher = __VECS(chacha20_tv_template)
3129 },
Martin Willi3590ebf2015-06-01 13:43:57 +02003130 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003131 .alg = "cmac(aes)",
Stephan Mueller8f183752015-08-19 08:42:07 +02003132 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003133 .test = alg_test_hash,
3134 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003135 .hash = __VECS(aes_cmac128_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003136 }
3137 }, {
3138 .alg = "cmac(des3_ede)",
Stephan Mueller8f183752015-08-19 08:42:07 +02003139 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003140 .test = alg_test_hash,
3141 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003142 .hash = __VECS(des3_ede_cmac64_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003143 }
3144 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003145 .alg = "compress_null",
3146 .test = alg_test_null,
3147 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003148 .alg = "crc32",
3149 .test = alg_test_hash,
Milan Broza8a34412019-01-25 10:31:47 +01003150 .fips_allowed = 1,
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003151 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003152 .hash = __VECS(crc32_tv_template)
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003153 }
3154 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003155 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08003156 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003157 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003158 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003159 .hash = __VECS(crc32c_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003160 }
3161 }, {
Herbert Xu684115212013-09-07 12:56:26 +10003162 .alg = "crct10dif",
3163 .test = alg_test_hash,
3164 .fips_allowed = 1,
3165 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003166 .hash = __VECS(crct10dif_tv_template)
Herbert Xu684115212013-09-07 12:56:26 +10003167 }
3168 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003169 .alg = "ctr(aes)",
3170 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003171 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003172 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003173 .cipher = __VECS(aes_ctr_tv_template)
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003174 }
3175 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03003176 .alg = "ctr(blowfish)",
3177 .test = alg_test_skcipher,
3178 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003179 .cipher = __VECS(bf_ctr_tv_template)
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03003180 }
3181 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003182 .alg = "ctr(camellia)",
3183 .test = alg_test_skcipher,
3184 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003185 .cipher = __VECS(camellia_ctr_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003186 }
3187 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003188 .alg = "ctr(cast5)",
3189 .test = alg_test_skcipher,
3190 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003191 .cipher = __VECS(cast5_ctr_tv_template)
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003192 }
3193 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003194 .alg = "ctr(cast6)",
3195 .test = alg_test_skcipher,
3196 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003197 .cipher = __VECS(cast6_ctr_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003198 }
3199 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03003200 .alg = "ctr(des)",
3201 .test = alg_test_skcipher,
3202 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003203 .cipher = __VECS(des_ctr_tv_template)
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03003204 }
3205 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003206 .alg = "ctr(des3_ede)",
3207 .test = alg_test_skcipher,
Marcelo Cerri0d8da102017-03-20 17:28:05 -03003208 .fips_allowed = 1,
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003209 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003210 .cipher = __VECS(des3_ede_ctr_tv_template)
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003211 }
3212 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003213 /* Same as ctr(aes) except the key is stored in
3214 * hardware secure memory which we reference by index
3215 */
3216 .alg = "ctr(paes)",
3217 .test = alg_test_null,
3218 .fips_allowed = 1,
3219 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003220 .alg = "ctr(serpent)",
3221 .test = alg_test_skcipher,
3222 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003223 .cipher = __VECS(serpent_ctr_tv_template)
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003224 }
3225 }, {
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01003226 .alg = "ctr(sm4)",
3227 .test = alg_test_skcipher,
3228 .suite = {
3229 .cipher = __VECS(sm4_ctr_tv_template)
3230 }
3231 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03003232 .alg = "ctr(twofish)",
3233 .test = alg_test_skcipher,
3234 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003235 .cipher = __VECS(tf_ctr_tv_template)
Jussi Kivilinna573da622011-10-10 23:03:12 +03003236 }
3237 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003238 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003239 .test = alg_test_skcipher,
Gilad Ben-Yossef196ad602018-11-04 10:05:24 +00003240 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003241 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003242 .cipher = __VECS(cts_mode_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003243 }
3244 }, {
3245 .alg = "deflate",
3246 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003247 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003248 .suite = {
3249 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003250 .comp = __VECS(deflate_comp_tv_template),
3251 .decomp = __VECS(deflate_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003252 }
3253 }
3254 }, {
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003255 .alg = "dh",
3256 .test = alg_test_kpp,
3257 .fips_allowed = 1,
3258 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003259 .kpp = __VECS(dh_tv_template)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003260 }
3261 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003262 .alg = "digest_null",
3263 .test = alg_test_null,
3264 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003265 .alg = "drbg_nopr_ctr_aes128",
3266 .test = alg_test_drbg,
3267 .fips_allowed = 1,
3268 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003269 .drbg = __VECS(drbg_nopr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003270 }
3271 }, {
3272 .alg = "drbg_nopr_ctr_aes192",
3273 .test = alg_test_drbg,
3274 .fips_allowed = 1,
3275 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003276 .drbg = __VECS(drbg_nopr_ctr_aes192_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003277 }
3278 }, {
3279 .alg = "drbg_nopr_ctr_aes256",
3280 .test = alg_test_drbg,
3281 .fips_allowed = 1,
3282 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003283 .drbg = __VECS(drbg_nopr_ctr_aes256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003284 }
3285 }, {
3286 /*
3287 * There is no need to specifically test the DRBG with every
3288 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
3289 */
3290 .alg = "drbg_nopr_hmac_sha1",
3291 .fips_allowed = 1,
3292 .test = alg_test_null,
3293 }, {
3294 .alg = "drbg_nopr_hmac_sha256",
3295 .test = alg_test_drbg,
3296 .fips_allowed = 1,
3297 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003298 .drbg = __VECS(drbg_nopr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003299 }
3300 }, {
3301 /* covered by drbg_nopr_hmac_sha256 test */
3302 .alg = "drbg_nopr_hmac_sha384",
3303 .fips_allowed = 1,
3304 .test = alg_test_null,
3305 }, {
3306 .alg = "drbg_nopr_hmac_sha512",
3307 .test = alg_test_null,
3308 .fips_allowed = 1,
3309 }, {
3310 .alg = "drbg_nopr_sha1",
3311 .fips_allowed = 1,
3312 .test = alg_test_null,
3313 }, {
3314 .alg = "drbg_nopr_sha256",
3315 .test = alg_test_drbg,
3316 .fips_allowed = 1,
3317 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003318 .drbg = __VECS(drbg_nopr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003319 }
3320 }, {
3321 /* covered by drbg_nopr_sha256 test */
3322 .alg = "drbg_nopr_sha384",
3323 .fips_allowed = 1,
3324 .test = alg_test_null,
3325 }, {
3326 .alg = "drbg_nopr_sha512",
3327 .fips_allowed = 1,
3328 .test = alg_test_null,
3329 }, {
3330 .alg = "drbg_pr_ctr_aes128",
3331 .test = alg_test_drbg,
3332 .fips_allowed = 1,
3333 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003334 .drbg = __VECS(drbg_pr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003335 }
3336 }, {
3337 /* covered by drbg_pr_ctr_aes128 test */
3338 .alg = "drbg_pr_ctr_aes192",
3339 .fips_allowed = 1,
3340 .test = alg_test_null,
3341 }, {
3342 .alg = "drbg_pr_ctr_aes256",
3343 .fips_allowed = 1,
3344 .test = alg_test_null,
3345 }, {
3346 .alg = "drbg_pr_hmac_sha1",
3347 .fips_allowed = 1,
3348 .test = alg_test_null,
3349 }, {
3350 .alg = "drbg_pr_hmac_sha256",
3351 .test = alg_test_drbg,
3352 .fips_allowed = 1,
3353 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003354 .drbg = __VECS(drbg_pr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003355 }
3356 }, {
3357 /* covered by drbg_pr_hmac_sha256 test */
3358 .alg = "drbg_pr_hmac_sha384",
3359 .fips_allowed = 1,
3360 .test = alg_test_null,
3361 }, {
3362 .alg = "drbg_pr_hmac_sha512",
3363 .test = alg_test_null,
3364 .fips_allowed = 1,
3365 }, {
3366 .alg = "drbg_pr_sha1",
3367 .fips_allowed = 1,
3368 .test = alg_test_null,
3369 }, {
3370 .alg = "drbg_pr_sha256",
3371 .test = alg_test_drbg,
3372 .fips_allowed = 1,
3373 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003374 .drbg = __VECS(drbg_pr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003375 }
3376 }, {
3377 /* covered by drbg_pr_sha256 test */
3378 .alg = "drbg_pr_sha384",
3379 .fips_allowed = 1,
3380 .test = alg_test_null,
3381 }, {
3382 .alg = "drbg_pr_sha512",
3383 .fips_allowed = 1,
3384 .test = alg_test_null,
3385 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003386 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003387 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003388 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003389 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003390 .cipher = __VECS(aes_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003391 }
3392 }, {
3393 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003394 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003395 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003396 .cipher = __VECS(anubis_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003397 }
3398 }, {
3399 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003400 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003401 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003402 .cipher = __VECS(arc4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003403 }
3404 }, {
3405 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003406 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003407 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003408 .cipher = __VECS(bf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003409 }
3410 }, {
3411 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003412 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003413 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003414 .cipher = __VECS(camellia_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003415 }
3416 }, {
3417 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003418 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003419 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003420 .cipher = __VECS(cast5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003421 }
3422 }, {
3423 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003424 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003425 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003426 .cipher = __VECS(cast6_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003427 }
3428 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003429 .alg = "ecb(cipher_null)",
3430 .test = alg_test_null,
Milan Broz6175ca22017-04-21 13:03:06 +02003431 .fips_allowed = 1,
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003432 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003433 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003434 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003435 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003436 .cipher = __VECS(des_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003437 }
3438 }, {
3439 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003440 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003441 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003442 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003443 .cipher = __VECS(des3_ede_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003444 }
3445 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003446 .alg = "ecb(fcrypt)",
3447 .test = alg_test_skcipher,
3448 .suite = {
3449 .cipher = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003450 .vecs = fcrypt_pcbc_tv_template,
3451 .count = 1
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003452 }
3453 }
3454 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003455 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003456 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003457 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003458 .cipher = __VECS(khazad_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003459 }
3460 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003461 /* Same as ecb(aes) except the key is stored in
3462 * hardware secure memory which we reference by index
3463 */
3464 .alg = "ecb(paes)",
3465 .test = alg_test_null,
3466 .fips_allowed = 1,
3467 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003468 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003469 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003470 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003471 .cipher = __VECS(seed_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003472 }
3473 }, {
3474 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003475 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003476 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003477 .cipher = __VECS(serpent_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003478 }
3479 }, {
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00003480 .alg = "ecb(sm4)",
3481 .test = alg_test_skcipher,
3482 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003483 .cipher = __VECS(sm4_tv_template)
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00003484 }
3485 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003486 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003487 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003488 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003489 .cipher = __VECS(tea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003490 }
3491 }, {
3492 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003493 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003494 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003495 .cipher = __VECS(tnepres_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003496 }
3497 }, {
3498 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003499 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003500 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003501 .cipher = __VECS(tf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003502 }
3503 }, {
3504 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003505 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003506 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003507 .cipher = __VECS(xeta_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003508 }
3509 }, {
3510 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003511 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003512 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003513 .cipher = __VECS(xtea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003514 }
3515 }, {
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003516 .alg = "ecdh",
3517 .test = alg_test_kpp,
3518 .fips_allowed = 1,
3519 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003520 .kpp = __VECS(ecdh_tv_template)
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003521 }
3522 }, {
Vitaly Chikunov32fbdbd2019-04-11 18:51:21 +03003523 .alg = "ecrdsa",
3524 .test = alg_test_akcipher,
3525 .suite = {
3526 .akcipher = __VECS(ecrdsa_tv_template)
3527 }
3528 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003529 .alg = "gcm(aes)",
3530 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003531 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003532 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003533 .aead = __VECS(aes_gcm_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003534 }
3535 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003536 .alg = "ghash",
3537 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003538 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003539 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003540 .hash = __VECS(ghash_tv_template)
Youquan, Song507069c2009-11-23 20:23:04 +08003541 }
3542 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003543 .alg = "hmac(md5)",
3544 .test = alg_test_hash,
3545 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003546 .hash = __VECS(hmac_md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003547 }
3548 }, {
3549 .alg = "hmac(rmd128)",
3550 .test = alg_test_hash,
3551 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003552 .hash = __VECS(hmac_rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003553 }
3554 }, {
3555 .alg = "hmac(rmd160)",
3556 .test = alg_test_hash,
3557 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003558 .hash = __VECS(hmac_rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003559 }
3560 }, {
3561 .alg = "hmac(sha1)",
3562 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003563 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003564 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003565 .hash = __VECS(hmac_sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003566 }
3567 }, {
3568 .alg = "hmac(sha224)",
3569 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003570 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003571 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003572 .hash = __VECS(hmac_sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003573 }
3574 }, {
3575 .alg = "hmac(sha256)",
3576 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003577 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003578 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003579 .hash = __VECS(hmac_sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003580 }
3581 }, {
raveendra padasalagi98eca722016-07-01 11:16:54 +05303582 .alg = "hmac(sha3-224)",
3583 .test = alg_test_hash,
3584 .fips_allowed = 1,
3585 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003586 .hash = __VECS(hmac_sha3_224_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303587 }
3588 }, {
3589 .alg = "hmac(sha3-256)",
3590 .test = alg_test_hash,
3591 .fips_allowed = 1,
3592 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003593 .hash = __VECS(hmac_sha3_256_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303594 }
3595 }, {
3596 .alg = "hmac(sha3-384)",
3597 .test = alg_test_hash,
3598 .fips_allowed = 1,
3599 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003600 .hash = __VECS(hmac_sha3_384_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303601 }
3602 }, {
3603 .alg = "hmac(sha3-512)",
3604 .test = alg_test_hash,
3605 .fips_allowed = 1,
3606 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003607 .hash = __VECS(hmac_sha3_512_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303608 }
3609 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003610 .alg = "hmac(sha384)",
3611 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003612 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003613 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003614 .hash = __VECS(hmac_sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003615 }
3616 }, {
3617 .alg = "hmac(sha512)",
3618 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003619 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003620 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003621 .hash = __VECS(hmac_sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003622 }
3623 }, {
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03003624 .alg = "hmac(streebog256)",
3625 .test = alg_test_hash,
3626 .suite = {
3627 .hash = __VECS(hmac_streebog256_tv_template)
3628 }
3629 }, {
3630 .alg = "hmac(streebog512)",
3631 .test = alg_test_hash,
3632 .suite = {
3633 .hash = __VECS(hmac_streebog512_tv_template)
3634 }
3635 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003636 .alg = "jitterentropy_rng",
3637 .fips_allowed = 1,
3638 .test = alg_test_null,
3639 }, {
Stephan Mueller35351982015-09-21 20:59:56 +02003640 .alg = "kw(aes)",
3641 .test = alg_test_skcipher,
3642 .fips_allowed = 1,
3643 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003644 .cipher = __VECS(aes_kw_tv_template)
Stephan Mueller35351982015-09-21 20:59:56 +02003645 }
3646 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003647 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003648 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003649 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003650 .cipher = __VECS(aes_lrw_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003651 }
3652 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003653 .alg = "lrw(camellia)",
3654 .test = alg_test_skcipher,
3655 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003656 .cipher = __VECS(camellia_lrw_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003657 }
3658 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003659 .alg = "lrw(cast6)",
3660 .test = alg_test_skcipher,
3661 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003662 .cipher = __VECS(cast6_lrw_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003663 }
3664 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003665 .alg = "lrw(serpent)",
3666 .test = alg_test_skcipher,
3667 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003668 .cipher = __VECS(serpent_lrw_tv_template)
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003669 }
3670 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003671 .alg = "lrw(twofish)",
3672 .test = alg_test_skcipher,
3673 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003674 .cipher = __VECS(tf_lrw_tv_template)
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003675 }
3676 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003677 .alg = "lz4",
3678 .test = alg_test_comp,
3679 .fips_allowed = 1,
3680 .suite = {
3681 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003682 .comp = __VECS(lz4_comp_tv_template),
3683 .decomp = __VECS(lz4_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003684 }
3685 }
3686 }, {
3687 .alg = "lz4hc",
3688 .test = alg_test_comp,
3689 .fips_allowed = 1,
3690 .suite = {
3691 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003692 .comp = __VECS(lz4hc_comp_tv_template),
3693 .decomp = __VECS(lz4hc_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003694 }
3695 }
3696 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003697 .alg = "lzo",
3698 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003699 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003700 .suite = {
3701 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003702 .comp = __VECS(lzo_comp_tv_template),
3703 .decomp = __VECS(lzo_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003704 }
3705 }
3706 }, {
3707 .alg = "md4",
3708 .test = alg_test_hash,
3709 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003710 .hash = __VECS(md4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003711 }
3712 }, {
3713 .alg = "md5",
3714 .test = alg_test_hash,
3715 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003716 .hash = __VECS(md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003717 }
3718 }, {
3719 .alg = "michael_mic",
3720 .test = alg_test_hash,
3721 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003722 .hash = __VECS(michael_mic_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003723 }
3724 }, {
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003725 .alg = "morus1280",
3726 .test = alg_test_aead,
3727 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003728 .aead = __VECS(morus1280_tv_template)
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003729 }
3730 }, {
3731 .alg = "morus640",
3732 .test = alg_test_aead,
3733 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003734 .aead = __VECS(morus640_tv_template)
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003735 }
3736 }, {
Eric Biggers26609a22018-11-16 17:26:29 -08003737 .alg = "nhpoly1305",
3738 .test = alg_test_hash,
3739 .suite = {
3740 .hash = __VECS(nhpoly1305_tv_template)
3741 }
3742 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003743 .alg = "ofb(aes)",
3744 .test = alg_test_skcipher,
3745 .fips_allowed = 1,
3746 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003747 .cipher = __VECS(aes_ofb_tv_template)
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003748 }
3749 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003750 /* Same as ofb(aes) except the key is stored in
3751 * hardware secure memory which we reference by index
3752 */
3753 .alg = "ofb(paes)",
3754 .test = alg_test_null,
3755 .fips_allowed = 1,
3756 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003757 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003758 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003759 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003760 .cipher = __VECS(fcrypt_pcbc_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003761 }
3762 }, {
Stephan Mueller12071072017-06-12 23:27:51 +02003763 .alg = "pkcs1pad(rsa,sha224)",
3764 .test = alg_test_null,
3765 .fips_allowed = 1,
3766 }, {
3767 .alg = "pkcs1pad(rsa,sha256)",
3768 .test = alg_test_akcipher,
3769 .fips_allowed = 1,
3770 .suite = {
3771 .akcipher = __VECS(pkcs1pad_rsa_tv_template)
3772 }
3773 }, {
3774 .alg = "pkcs1pad(rsa,sha384)",
3775 .test = alg_test_null,
3776 .fips_allowed = 1,
3777 }, {
3778 .alg = "pkcs1pad(rsa,sha512)",
3779 .test = alg_test_null,
3780 .fips_allowed = 1,
3781 }, {
Martin Willieee9dc62015-06-01 13:43:59 +02003782 .alg = "poly1305",
3783 .test = alg_test_hash,
3784 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003785 .hash = __VECS(poly1305_tv_template)
Martin Willieee9dc62015-06-01 13:43:59 +02003786 }
3787 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003788 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003789 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003790 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003791 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003792 .cipher = __VECS(aes_ctr_rfc3686_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003793 }
3794 }, {
Herbert Xu3f31a742015-07-09 07:17:34 +08003795 .alg = "rfc4106(gcm(aes))",
Adrian Hoban69435b92010-11-04 15:02:04 -04003796 .test = alg_test_aead,
Jarod Wilsondb71f29a2015-01-23 12:42:15 -05003797 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003798 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003799 .aead = __VECS(aes_gcm_rfc4106_tv_template)
Adrian Hoban69435b92010-11-04 15:02:04 -04003800 }
3801 }, {
Herbert Xu544c4362015-07-14 16:53:22 +08003802 .alg = "rfc4309(ccm(aes))",
Jarod Wilson5d667322009-05-04 19:23:40 +08003803 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003804 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003805 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003806 .aead = __VECS(aes_ccm_rfc4309_tv_template)
Jarod Wilson5d667322009-05-04 19:23:40 +08003807 }
3808 }, {
Herbert Xubb687452015-06-16 13:54:24 +08003809 .alg = "rfc4543(gcm(aes))",
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003810 .test = alg_test_aead,
3811 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003812 .aead = __VECS(aes_gcm_rfc4543_tv_template)
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003813 }
3814 }, {
Martin Williaf2b76b2015-06-01 13:44:01 +02003815 .alg = "rfc7539(chacha20,poly1305)",
3816 .test = alg_test_aead,
3817 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003818 .aead = __VECS(rfc7539_tv_template)
Martin Williaf2b76b2015-06-01 13:44:01 +02003819 }
3820 }, {
Martin Willi59007582015-06-01 13:44:03 +02003821 .alg = "rfc7539esp(chacha20,poly1305)",
3822 .test = alg_test_aead,
3823 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003824 .aead = __VECS(rfc7539esp_tv_template)
Martin Willi59007582015-06-01 13:44:03 +02003825 }
3826 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003827 .alg = "rmd128",
3828 .test = alg_test_hash,
3829 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003830 .hash = __VECS(rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003831 }
3832 }, {
3833 .alg = "rmd160",
3834 .test = alg_test_hash,
3835 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003836 .hash = __VECS(rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003837 }
3838 }, {
3839 .alg = "rmd256",
3840 .test = alg_test_hash,
3841 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003842 .hash = __VECS(rmd256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003843 }
3844 }, {
3845 .alg = "rmd320",
3846 .test = alg_test_hash,
3847 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003848 .hash = __VECS(rmd320_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003849 }
3850 }, {
Tadeusz Struk946cc462015-06-16 10:31:06 -07003851 .alg = "rsa",
3852 .test = alg_test_akcipher,
3853 .fips_allowed = 1,
3854 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003855 .akcipher = __VECS(rsa_tv_template)
Tadeusz Struk946cc462015-06-16 10:31:06 -07003856 }
3857 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003858 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003859 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003860 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003861 .cipher = __VECS(salsa20_stream_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003862 }
3863 }, {
3864 .alg = "sha1",
3865 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003866 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003867 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003868 .hash = __VECS(sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003869 }
3870 }, {
3871 .alg = "sha224",
3872 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003873 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003874 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003875 .hash = __VECS(sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003876 }
3877 }, {
3878 .alg = "sha256",
3879 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003880 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003881 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003882 .hash = __VECS(sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003883 }
3884 }, {
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303885 .alg = "sha3-224",
3886 .test = alg_test_hash,
3887 .fips_allowed = 1,
3888 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003889 .hash = __VECS(sha3_224_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303890 }
3891 }, {
3892 .alg = "sha3-256",
3893 .test = alg_test_hash,
3894 .fips_allowed = 1,
3895 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003896 .hash = __VECS(sha3_256_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303897 }
3898 }, {
3899 .alg = "sha3-384",
3900 .test = alg_test_hash,
3901 .fips_allowed = 1,
3902 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003903 .hash = __VECS(sha3_384_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303904 }
3905 }, {
3906 .alg = "sha3-512",
3907 .test = alg_test_hash,
3908 .fips_allowed = 1,
3909 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003910 .hash = __VECS(sha3_512_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303911 }
3912 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003913 .alg = "sha384",
3914 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003915 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003916 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003917 .hash = __VECS(sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003918 }
3919 }, {
3920 .alg = "sha512",
3921 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003922 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003923 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003924 .hash = __VECS(sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003925 }
3926 }, {
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03003927 .alg = "sm3",
3928 .test = alg_test_hash,
3929 .suite = {
3930 .hash = __VECS(sm3_tv_template)
3931 }
3932 }, {
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03003933 .alg = "streebog256",
3934 .test = alg_test_hash,
3935 .suite = {
3936 .hash = __VECS(streebog256_tv_template)
3937 }
3938 }, {
3939 .alg = "streebog512",
3940 .test = alg_test_hash,
3941 .suite = {
3942 .hash = __VECS(streebog512_tv_template)
3943 }
3944 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003945 .alg = "tgr128",
3946 .test = alg_test_hash,
3947 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003948 .hash = __VECS(tgr128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003949 }
3950 }, {
3951 .alg = "tgr160",
3952 .test = alg_test_hash,
3953 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003954 .hash = __VECS(tgr160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003955 }
3956 }, {
3957 .alg = "tgr192",
3958 .test = alg_test_hash,
3959 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003960 .hash = __VECS(tgr192_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003961 }
3962 }, {
Eric Biggersed331ad2018-06-18 10:22:39 -07003963 .alg = "vmac64(aes)",
3964 .test = alg_test_hash,
3965 .suite = {
3966 .hash = __VECS(vmac64_aes_tv_template)
3967 }
3968 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003969 .alg = "wp256",
3970 .test = alg_test_hash,
3971 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003972 .hash = __VECS(wp256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003973 }
3974 }, {
3975 .alg = "wp384",
3976 .test = alg_test_hash,
3977 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003978 .hash = __VECS(wp384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003979 }
3980 }, {
3981 .alg = "wp512",
3982 .test = alg_test_hash,
3983 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003984 .hash = __VECS(wp512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003985 }
3986 }, {
3987 .alg = "xcbc(aes)",
3988 .test = alg_test_hash,
3989 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003990 .hash = __VECS(aes_xcbc128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003991 }
3992 }, {
Eric Biggersaa762402018-11-16 17:26:22 -08003993 .alg = "xchacha12",
3994 .test = alg_test_skcipher,
3995 .suite = {
3996 .cipher = __VECS(xchacha12_tv_template)
3997 },
3998 }, {
Eric Biggersde61d7a2018-11-16 17:26:20 -08003999 .alg = "xchacha20",
4000 .test = alg_test_skcipher,
4001 .suite = {
4002 .cipher = __VECS(xchacha20_tv_template)
4003 },
4004 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004005 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004006 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11004007 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004008 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004009 .cipher = __VECS(aes_xts_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004010 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08004011 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02004012 .alg = "xts(camellia)",
4013 .test = alg_test_skcipher,
4014 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004015 .cipher = __VECS(camellia_xts_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02004016 }
4017 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02004018 .alg = "xts(cast6)",
4019 .test = alg_test_skcipher,
4020 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004021 .cipher = __VECS(cast6_xts_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02004022 }
4023 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01004024 /* Same as xts(aes) except the key is stored in
4025 * hardware secure memory which we reference by index
4026 */
4027 .alg = "xts(paes)",
4028 .test = alg_test_null,
4029 .fips_allowed = 1,
4030 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03004031 .alg = "xts(serpent)",
4032 .test = alg_test_skcipher,
4033 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004034 .cipher = __VECS(serpent_xts_tv_template)
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03004035 }
4036 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03004037 .alg = "xts(twofish)",
4038 .test = alg_test_skcipher,
4039 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004040 .cipher = __VECS(tf_xts_tv_template)
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03004041 }
Giovanni Cabiddua368f432017-04-21 21:54:30 +01004042 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01004043 .alg = "xts4096(paes)",
4044 .test = alg_test_null,
4045 .fips_allowed = 1,
4046 }, {
4047 .alg = "xts512(paes)",
4048 .test = alg_test_null,
4049 .fips_allowed = 1,
4050 }, {
Giovanni Cabiddua368f432017-04-21 21:54:30 +01004051 .alg = "zlib-deflate",
4052 .test = alg_test_comp,
4053 .fips_allowed = 1,
4054 .suite = {
4055 .comp = {
4056 .comp = __VECS(zlib_deflate_comp_tv_template),
4057 .decomp = __VECS(zlib_deflate_decomp_tv_template)
4058 }
4059 }
Nick Terrelld28fc3d2018-03-30 12:14:53 -07004060 }, {
4061 .alg = "zstd",
4062 .test = alg_test_comp,
4063 .fips_allowed = 1,
4064 .suite = {
4065 .comp = {
4066 .comp = __VECS(zstd_comp_tv_template),
4067 .decomp = __VECS(zstd_decomp_tv_template)
4068 }
4069 }
Herbert Xuda7f0332008-07-31 17:08:25 +08004070 }
4071};
4072
Eric Biggers3f47a032019-01-31 23:51:43 -08004073static void alg_check_test_descs_order(void)
Jussi Kivilinna57147582013-06-13 17:37:40 +03004074{
4075 int i;
4076
Jussi Kivilinna57147582013-06-13 17:37:40 +03004077 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
4078 int diff = strcmp(alg_test_descs[i - 1].alg,
4079 alg_test_descs[i].alg);
4080
4081 if (WARN_ON(diff > 0)) {
4082 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
4083 alg_test_descs[i - 1].alg,
4084 alg_test_descs[i].alg);
4085 }
4086
4087 if (WARN_ON(diff == 0)) {
4088 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
4089 alg_test_descs[i].alg);
4090 }
4091 }
4092}
4093
Eric Biggers3f47a032019-01-31 23:51:43 -08004094static void alg_check_testvec_configs(void)
4095{
Eric Biggers4e7babba2019-01-31 23:51:46 -08004096 int i;
4097
4098 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++)
4099 WARN_ON(!valid_testvec_config(
4100 &default_cipher_testvec_configs[i]));
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08004101
4102 for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++)
4103 WARN_ON(!valid_testvec_config(
4104 &default_hash_testvec_configs[i]));
Eric Biggers3f47a032019-01-31 23:51:43 -08004105}
4106
4107static void testmgr_onetime_init(void)
4108{
4109 alg_check_test_descs_order();
4110 alg_check_testvec_configs();
Eric Biggers5b2706a2019-01-31 23:51:44 -08004111
4112#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
4113 pr_warn("alg: extra crypto tests enabled. This is intended for developer use only.\n");
4114#endif
Eric Biggers3f47a032019-01-31 23:51:43 -08004115}
4116
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004117static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08004118{
4119 int start = 0;
4120 int end = ARRAY_SIZE(alg_test_descs);
4121
4122 while (start < end) {
4123 int i = (start + end) / 2;
4124 int diff = strcmp(alg_test_descs[i].alg, alg);
4125
4126 if (diff > 0) {
4127 end = i;
4128 continue;
4129 }
4130
4131 if (diff < 0) {
4132 start = i + 1;
4133 continue;
4134 }
4135
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004136 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08004137 }
4138
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004139 return -1;
4140}
4141
4142int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
4143{
4144 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08004145 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08004146 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004147
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +01004148 if (!fips_enabled && notests) {
4149 printk_once(KERN_INFO "alg: self-tests disabled\n");
4150 return 0;
4151 }
4152
Eric Biggers3f47a032019-01-31 23:51:43 -08004153 DO_ONCE(testmgr_onetime_init);
Jussi Kivilinna57147582013-06-13 17:37:40 +03004154
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004155 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
4156 char nalg[CRYPTO_MAX_ALG_NAME];
4157
4158 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
4159 sizeof(nalg))
4160 return -ENAMETOOLONG;
4161
4162 i = alg_find_test(nalg);
4163 if (i < 0)
4164 goto notest;
4165
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004166 if (fips_enabled && !alg_test_descs[i].fips_allowed)
4167 goto non_fips_alg;
4168
Jarod Wilson941fb322009-05-04 19:49:23 +08004169 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
4170 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004171 }
4172
4173 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08004174 j = alg_find_test(driver);
4175 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004176 goto notest;
4177
Herbert Xua68f6612009-07-02 16:32:12 +08004178 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
4179 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004180 goto non_fips_alg;
4181
Herbert Xua68f6612009-07-02 16:32:12 +08004182 rc = 0;
4183 if (i >= 0)
4184 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
4185 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03004186 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08004187 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
4188 type, mask);
4189
Jarod Wilson941fb322009-05-04 19:49:23 +08004190test_done:
Eric Biggerseda69b02019-03-31 13:09:14 -07004191 if (rc && (fips_enabled || panic_on_fail))
4192 panic("alg: self-tests for %s (%s) failed in %s mode!\n",
4193 driver, alg, fips_enabled ? "fips" : "panic_on_fail");
Neil Hormand12d6b62008-10-12 20:36:51 +08004194
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004195 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09004196 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004197
Neil Hormand12d6b62008-10-12 20:36:51 +08004198 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004199
4200notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08004201 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
4202 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004203non_fips_alg:
4204 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08004205}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004206
Herbert Xu326a6342010-08-06 09:40:28 +08004207#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004208
Herbert Xuda7f0332008-07-31 17:08:25 +08004209EXPORT_SYMBOL_GPL(alg_test);