blob: c9e67c2bd7257cc98f57e6e5a93efeea16864afd [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;
Eric Biggersf2bb770a2019-04-11 21:57:38 -0700131 const char *generic_driver;
Herbert Xuda7f0332008-07-31 17:08:25 +0800132 int (*test)(const struct alg_test_desc *desc, const char *driver,
133 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000134 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800135
136 union {
137 struct aead_test_suite aead;
138 struct cipher_test_suite cipher;
139 struct comp_test_suite comp;
140 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800141 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200142 struct drbg_test_suite drbg;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700143 struct akcipher_test_suite akcipher;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100144 struct kpp_test_suite kpp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800145 } suite;
146};
147
Herbert Xuda7f0332008-07-31 17:08:25 +0800148static void hexdump(unsigned char *buf, unsigned int len)
149{
150 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
151 16, 1,
152 buf, len, false);
153}
154
Eric Biggers3f47a032019-01-31 23:51:43 -0800155static int __testmgr_alloc_buf(char *buf[XBUFSIZE], int order)
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800156{
157 int i;
158
159 for (i = 0; i < XBUFSIZE; i++) {
Eric Biggers3f47a032019-01-31 23:51:43 -0800160 buf[i] = (char *)__get_free_pages(GFP_KERNEL, order);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800161 if (!buf[i])
162 goto err_free_buf;
163 }
164
165 return 0;
166
167err_free_buf:
168 while (i-- > 0)
Eric Biggers3f47a032019-01-31 23:51:43 -0800169 free_pages((unsigned long)buf[i], order);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800170
171 return -ENOMEM;
172}
173
Eric Biggers3f47a032019-01-31 23:51:43 -0800174static int testmgr_alloc_buf(char *buf[XBUFSIZE])
175{
176 return __testmgr_alloc_buf(buf, 0);
177}
178
179static void __testmgr_free_buf(char *buf[XBUFSIZE], int order)
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800180{
181 int i;
182
183 for (i = 0; i < XBUFSIZE; i++)
Eric Biggers3f47a032019-01-31 23:51:43 -0800184 free_pages((unsigned long)buf[i], order);
185}
186
187static void testmgr_free_buf(char *buf[XBUFSIZE])
188{
189 __testmgr_free_buf(buf, 0);
190}
191
192#define TESTMGR_POISON_BYTE 0xfe
193#define TESTMGR_POISON_LEN 16
194
195static inline void testmgr_poison(void *addr, size_t len)
196{
197 memset(addr, TESTMGR_POISON_BYTE, len);
198}
199
200/* Is the memory region still fully poisoned? */
201static inline bool testmgr_is_poison(const void *addr, size_t len)
202{
203 return memchr_inv(addr, TESTMGR_POISON_BYTE, len) == NULL;
204}
205
206/* flush type for hash algorithms */
207enum flush_type {
208 /* merge with update of previous buffer(s) */
209 FLUSH_TYPE_NONE = 0,
210
211 /* update with previous buffer(s) before doing this one */
212 FLUSH_TYPE_FLUSH,
213
214 /* likewise, but also export and re-import the intermediate state */
215 FLUSH_TYPE_REIMPORT,
216};
217
218/* finalization function for hash algorithms */
219enum finalization_type {
220 FINALIZATION_TYPE_FINAL, /* use final() */
221 FINALIZATION_TYPE_FINUP, /* use finup() */
222 FINALIZATION_TYPE_DIGEST, /* use digest() */
223};
224
225#define TEST_SG_TOTAL 10000
226
227/**
228 * struct test_sg_division - description of a scatterlist entry
229 *
230 * This struct describes one entry of a scatterlist being constructed to check a
231 * crypto test vector.
232 *
233 * @proportion_of_total: length of this chunk relative to the total length,
234 * given as a proportion out of TEST_SG_TOTAL so that it
235 * scales to fit any test vector
236 * @offset: byte offset into a 2-page buffer at which this chunk will start
237 * @offset_relative_to_alignmask: if true, add the algorithm's alignmask to the
238 * @offset
239 * @flush_type: for hashes, whether an update() should be done now vs.
240 * continuing to accumulate data
Eric Biggers65707372019-03-12 22:12:52 -0700241 * @nosimd: if doing the pending update(), do it with SIMD disabled?
Eric Biggers3f47a032019-01-31 23:51:43 -0800242 */
243struct test_sg_division {
244 unsigned int proportion_of_total;
245 unsigned int offset;
246 bool offset_relative_to_alignmask;
247 enum flush_type flush_type;
Eric Biggers65707372019-03-12 22:12:52 -0700248 bool nosimd;
Eric Biggers3f47a032019-01-31 23:51:43 -0800249};
250
251/**
252 * struct testvec_config - configuration for testing a crypto test vector
253 *
254 * This struct describes the data layout and other parameters with which each
255 * crypto test vector can be tested.
256 *
257 * @name: name of this config, logged for debugging purposes if a test fails
258 * @inplace: operate on the data in-place, if applicable for the algorithm type?
259 * @req_flags: extra request_flags, e.g. CRYPTO_TFM_REQ_MAY_SLEEP
260 * @src_divs: description of how to arrange the source scatterlist
261 * @dst_divs: description of how to arrange the dst scatterlist, if applicable
262 * for the algorithm type. Defaults to @src_divs if unset.
263 * @iv_offset: misalignment of the IV in the range [0..MAX_ALGAPI_ALIGNMASK+1],
264 * where 0 is aligned to a 2*(MAX_ALGAPI_ALIGNMASK+1) byte boundary
265 * @iv_offset_relative_to_alignmask: if true, add the algorithm's alignmask to
266 * the @iv_offset
267 * @finalization_type: what finalization function to use for hashes
Eric Biggers65707372019-03-12 22:12:52 -0700268 * @nosimd: execute with SIMD disabled? Requires !CRYPTO_TFM_REQ_MAY_SLEEP.
Eric Biggers3f47a032019-01-31 23:51:43 -0800269 */
270struct testvec_config {
271 const char *name;
272 bool inplace;
273 u32 req_flags;
274 struct test_sg_division src_divs[XBUFSIZE];
275 struct test_sg_division dst_divs[XBUFSIZE];
276 unsigned int iv_offset;
277 bool iv_offset_relative_to_alignmask;
278 enum finalization_type finalization_type;
Eric Biggers65707372019-03-12 22:12:52 -0700279 bool nosimd;
Eric Biggers3f47a032019-01-31 23:51:43 -0800280};
281
282#define TESTVEC_CONFIG_NAMELEN 192
283
Eric Biggers4e7babba2019-01-31 23:51:46 -0800284/*
285 * The following are the lists of testvec_configs to test for each algorithm
286 * type when the basic crypto self-tests are enabled, i.e. when
287 * CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is unset. They aim to provide good test
288 * coverage, while keeping the test time much shorter than the full fuzz tests
289 * so that the basic tests can be enabled in a wider range of circumstances.
290 */
291
292/* Configs for skciphers and aeads */
293static const struct testvec_config default_cipher_testvec_configs[] = {
294 {
295 .name = "in-place",
296 .inplace = true,
297 .src_divs = { { .proportion_of_total = 10000 } },
298 }, {
299 .name = "out-of-place",
300 .src_divs = { { .proportion_of_total = 10000 } },
301 }, {
302 .name = "unaligned buffer, offset=1",
303 .src_divs = { { .proportion_of_total = 10000, .offset = 1 } },
304 .iv_offset = 1,
305 }, {
306 .name = "buffer aligned only to alignmask",
307 .src_divs = {
308 {
309 .proportion_of_total = 10000,
310 .offset = 1,
311 .offset_relative_to_alignmask = true,
312 },
313 },
314 .iv_offset = 1,
315 .iv_offset_relative_to_alignmask = true,
316 }, {
317 .name = "two even aligned splits",
318 .src_divs = {
319 { .proportion_of_total = 5000 },
320 { .proportion_of_total = 5000 },
321 },
322 }, {
323 .name = "uneven misaligned splits, may sleep",
324 .req_flags = CRYPTO_TFM_REQ_MAY_SLEEP,
325 .src_divs = {
326 { .proportion_of_total = 1900, .offset = 33 },
327 { .proportion_of_total = 3300, .offset = 7 },
328 { .proportion_of_total = 4800, .offset = 18 },
329 },
330 .iv_offset = 3,
331 }, {
332 .name = "misaligned splits crossing pages, inplace",
333 .inplace = true,
334 .src_divs = {
335 {
336 .proportion_of_total = 7500,
337 .offset = PAGE_SIZE - 32
338 }, {
339 .proportion_of_total = 2500,
340 .offset = PAGE_SIZE - 7
341 },
342 },
343 }
344};
345
Eric Biggers4cc2dcf2019-01-31 23:51:48 -0800346static const struct testvec_config default_hash_testvec_configs[] = {
347 {
348 .name = "init+update+final aligned buffer",
349 .src_divs = { { .proportion_of_total = 10000 } },
350 .finalization_type = FINALIZATION_TYPE_FINAL,
351 }, {
352 .name = "init+finup aligned buffer",
353 .src_divs = { { .proportion_of_total = 10000 } },
354 .finalization_type = FINALIZATION_TYPE_FINUP,
355 }, {
356 .name = "digest aligned buffer",
357 .src_divs = { { .proportion_of_total = 10000 } },
358 .finalization_type = FINALIZATION_TYPE_DIGEST,
359 }, {
360 .name = "init+update+final misaligned buffer",
361 .src_divs = { { .proportion_of_total = 10000, .offset = 1 } },
362 .finalization_type = FINALIZATION_TYPE_FINAL,
363 }, {
364 .name = "digest buffer aligned only to alignmask",
365 .src_divs = {
366 {
367 .proportion_of_total = 10000,
368 .offset = 1,
369 .offset_relative_to_alignmask = true,
370 },
371 },
372 .finalization_type = FINALIZATION_TYPE_DIGEST,
373 }, {
374 .name = "init+update+update+final two even splits",
375 .src_divs = {
376 { .proportion_of_total = 5000 },
377 {
378 .proportion_of_total = 5000,
379 .flush_type = FLUSH_TYPE_FLUSH,
380 },
381 },
382 .finalization_type = FINALIZATION_TYPE_FINAL,
383 }, {
384 .name = "digest uneven misaligned splits, may sleep",
385 .req_flags = CRYPTO_TFM_REQ_MAY_SLEEP,
386 .src_divs = {
387 { .proportion_of_total = 1900, .offset = 33 },
388 { .proportion_of_total = 3300, .offset = 7 },
389 { .proportion_of_total = 4800, .offset = 18 },
390 },
391 .finalization_type = FINALIZATION_TYPE_DIGEST,
392 }, {
393 .name = "digest misaligned splits crossing pages",
394 .src_divs = {
395 {
396 .proportion_of_total = 7500,
397 .offset = PAGE_SIZE - 32,
398 }, {
399 .proportion_of_total = 2500,
400 .offset = PAGE_SIZE - 7,
401 },
402 },
403 .finalization_type = FINALIZATION_TYPE_DIGEST,
404 }, {
405 .name = "import/export",
406 .src_divs = {
407 {
408 .proportion_of_total = 6500,
409 .flush_type = FLUSH_TYPE_REIMPORT,
410 }, {
411 .proportion_of_total = 3500,
412 .flush_type = FLUSH_TYPE_REIMPORT,
413 },
414 },
415 .finalization_type = FINALIZATION_TYPE_FINAL,
416 }
417};
418
Eric Biggers3f47a032019-01-31 23:51:43 -0800419static unsigned int count_test_sg_divisions(const struct test_sg_division *divs)
420{
421 unsigned int remaining = TEST_SG_TOTAL;
422 unsigned int ndivs = 0;
423
424 do {
425 remaining -= divs[ndivs++].proportion_of_total;
426 } while (remaining);
427
428 return ndivs;
429}
430
Eric Biggers65707372019-03-12 22:12:52 -0700431#define SGDIVS_HAVE_FLUSHES BIT(0)
432#define SGDIVS_HAVE_NOSIMD BIT(1)
433
Eric Biggers3f47a032019-01-31 23:51:43 -0800434static bool valid_sg_divisions(const struct test_sg_division *divs,
Eric Biggers65707372019-03-12 22:12:52 -0700435 unsigned int count, int *flags_ret)
Eric Biggers3f47a032019-01-31 23:51:43 -0800436{
437 unsigned int total = 0;
438 unsigned int i;
439
440 for (i = 0; i < count && total != TEST_SG_TOTAL; i++) {
441 if (divs[i].proportion_of_total <= 0 ||
442 divs[i].proportion_of_total > TEST_SG_TOTAL - total)
443 return false;
444 total += divs[i].proportion_of_total;
445 if (divs[i].flush_type != FLUSH_TYPE_NONE)
Eric Biggers65707372019-03-12 22:12:52 -0700446 *flags_ret |= SGDIVS_HAVE_FLUSHES;
447 if (divs[i].nosimd)
448 *flags_ret |= SGDIVS_HAVE_NOSIMD;
Eric Biggers3f47a032019-01-31 23:51:43 -0800449 }
450 return total == TEST_SG_TOTAL &&
451 memchr_inv(&divs[i], 0, (count - i) * sizeof(divs[0])) == NULL;
452}
453
454/*
455 * Check whether the given testvec_config is valid. This isn't strictly needed
456 * since every testvec_config should be valid, but check anyway so that people
457 * don't unknowingly add broken configs that don't do what they wanted.
458 */
459static bool valid_testvec_config(const struct testvec_config *cfg)
460{
Eric Biggers65707372019-03-12 22:12:52 -0700461 int flags = 0;
Eric Biggers3f47a032019-01-31 23:51:43 -0800462
463 if (cfg->name == NULL)
464 return false;
465
466 if (!valid_sg_divisions(cfg->src_divs, ARRAY_SIZE(cfg->src_divs),
Eric Biggers65707372019-03-12 22:12:52 -0700467 &flags))
Eric Biggers3f47a032019-01-31 23:51:43 -0800468 return false;
469
470 if (cfg->dst_divs[0].proportion_of_total) {
471 if (!valid_sg_divisions(cfg->dst_divs,
Eric Biggers65707372019-03-12 22:12:52 -0700472 ARRAY_SIZE(cfg->dst_divs), &flags))
Eric Biggers3f47a032019-01-31 23:51:43 -0800473 return false;
474 } else {
475 if (memchr_inv(cfg->dst_divs, 0, sizeof(cfg->dst_divs)))
476 return false;
477 /* defaults to dst_divs=src_divs */
478 }
479
480 if (cfg->iv_offset +
481 (cfg->iv_offset_relative_to_alignmask ? MAX_ALGAPI_ALIGNMASK : 0) >
482 MAX_ALGAPI_ALIGNMASK + 1)
483 return false;
484
Eric Biggers65707372019-03-12 22:12:52 -0700485 if ((flags & (SGDIVS_HAVE_FLUSHES | SGDIVS_HAVE_NOSIMD)) &&
486 cfg->finalization_type == FINALIZATION_TYPE_DIGEST)
487 return false;
488
489 if ((cfg->nosimd || (flags & SGDIVS_HAVE_NOSIMD)) &&
490 (cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP))
Eric Biggers3f47a032019-01-31 23:51:43 -0800491 return false;
492
493 return true;
494}
495
496struct test_sglist {
497 char *bufs[XBUFSIZE];
498 struct scatterlist sgl[XBUFSIZE];
499 struct scatterlist sgl_saved[XBUFSIZE];
500 struct scatterlist *sgl_ptr;
501 unsigned int nents;
502};
503
504static int init_test_sglist(struct test_sglist *tsgl)
505{
506 return __testmgr_alloc_buf(tsgl->bufs, 1 /* two pages per buffer */);
507}
508
509static void destroy_test_sglist(struct test_sglist *tsgl)
510{
511 return __testmgr_free_buf(tsgl->bufs, 1 /* two pages per buffer */);
512}
513
514/**
515 * build_test_sglist() - build a scatterlist for a crypto test
516 *
517 * @tsgl: the scatterlist to build. @tsgl->bufs[] contains an array of 2-page
518 * buffers which the scatterlist @tsgl->sgl[] will be made to point into.
519 * @divs: the layout specification on which the scatterlist will be based
520 * @alignmask: the algorithm's alignmask
521 * @total_len: the total length of the scatterlist to build in bytes
522 * @data: if non-NULL, the buffers will be filled with this data until it ends.
523 * Otherwise the buffers will be poisoned. In both cases, some bytes
524 * past the end of each buffer will be poisoned to help detect overruns.
525 * @out_divs: if non-NULL, the test_sg_division to which each scatterlist entry
526 * corresponds will be returned here. This will match @divs except
527 * that divisions resolving to a length of 0 are omitted as they are
528 * not included in the scatterlist.
529 *
530 * Return: 0 or a -errno value
531 */
532static int build_test_sglist(struct test_sglist *tsgl,
533 const struct test_sg_division *divs,
534 const unsigned int alignmask,
535 const unsigned int total_len,
536 struct iov_iter *data,
537 const struct test_sg_division *out_divs[XBUFSIZE])
538{
539 struct {
540 const struct test_sg_division *div;
541 size_t length;
542 } partitions[XBUFSIZE];
543 const unsigned int ndivs = count_test_sg_divisions(divs);
544 unsigned int len_remaining = total_len;
545 unsigned int i;
546
547 BUILD_BUG_ON(ARRAY_SIZE(partitions) != ARRAY_SIZE(tsgl->sgl));
548 if (WARN_ON(ndivs > ARRAY_SIZE(partitions)))
549 return -EINVAL;
550
551 /* Calculate the (div, length) pairs */
552 tsgl->nents = 0;
553 for (i = 0; i < ndivs; i++) {
554 unsigned int len_this_sg =
555 min(len_remaining,
556 (total_len * divs[i].proportion_of_total +
557 TEST_SG_TOTAL / 2) / TEST_SG_TOTAL);
558
559 if (len_this_sg != 0) {
560 partitions[tsgl->nents].div = &divs[i];
561 partitions[tsgl->nents].length = len_this_sg;
562 tsgl->nents++;
563 len_remaining -= len_this_sg;
564 }
565 }
566 if (tsgl->nents == 0) {
567 partitions[tsgl->nents].div = &divs[0];
568 partitions[tsgl->nents].length = 0;
569 tsgl->nents++;
570 }
571 partitions[tsgl->nents - 1].length += len_remaining;
572
573 /* Set up the sgl entries and fill the data or poison */
574 sg_init_table(tsgl->sgl, tsgl->nents);
575 for (i = 0; i < tsgl->nents; i++) {
576 unsigned int offset = partitions[i].div->offset;
577 void *addr;
578
579 if (partitions[i].div->offset_relative_to_alignmask)
580 offset += alignmask;
581
582 while (offset + partitions[i].length + TESTMGR_POISON_LEN >
583 2 * PAGE_SIZE) {
584 if (WARN_ON(offset <= 0))
585 return -EINVAL;
586 offset /= 2;
587 }
588
589 addr = &tsgl->bufs[i][offset];
590 sg_set_buf(&tsgl->sgl[i], addr, partitions[i].length);
591
592 if (out_divs)
593 out_divs[i] = partitions[i].div;
594
595 if (data) {
596 size_t copy_len, copied;
597
598 copy_len = min(partitions[i].length, data->count);
599 copied = copy_from_iter(addr, copy_len, data);
600 if (WARN_ON(copied != copy_len))
601 return -EINVAL;
602 testmgr_poison(addr + copy_len, partitions[i].length +
603 TESTMGR_POISON_LEN - copy_len);
604 } else {
605 testmgr_poison(addr, partitions[i].length +
606 TESTMGR_POISON_LEN);
607 }
608 }
609
610 sg_mark_end(&tsgl->sgl[tsgl->nents - 1]);
611 tsgl->sgl_ptr = tsgl->sgl;
612 memcpy(tsgl->sgl_saved, tsgl->sgl, tsgl->nents * sizeof(tsgl->sgl[0]));
613 return 0;
614}
615
616/*
617 * Verify that a scatterlist crypto operation produced the correct output.
618 *
619 * @tsgl: scatterlist containing the actual output
620 * @expected_output: buffer containing the expected output
621 * @len_to_check: length of @expected_output in bytes
622 * @unchecked_prefix_len: number of ignored bytes in @tsgl prior to real result
623 * @check_poison: verify that the poison bytes after each chunk are intact?
624 *
625 * Return: 0 if correct, -EINVAL if incorrect, -EOVERFLOW if buffer overrun.
626 */
627static int verify_correct_output(const struct test_sglist *tsgl,
628 const char *expected_output,
629 unsigned int len_to_check,
630 unsigned int unchecked_prefix_len,
631 bool check_poison)
632{
633 unsigned int i;
634
635 for (i = 0; i < tsgl->nents; i++) {
636 struct scatterlist *sg = &tsgl->sgl_ptr[i];
637 unsigned int len = sg->length;
638 unsigned int offset = sg->offset;
639 const char *actual_output;
640
641 if (unchecked_prefix_len) {
642 if (unchecked_prefix_len >= len) {
643 unchecked_prefix_len -= len;
644 continue;
645 }
646 offset += unchecked_prefix_len;
647 len -= unchecked_prefix_len;
648 unchecked_prefix_len = 0;
649 }
650 len = min(len, len_to_check);
651 actual_output = page_address(sg_page(sg)) + offset;
652 if (memcmp(expected_output, actual_output, len) != 0)
653 return -EINVAL;
654 if (check_poison &&
655 !testmgr_is_poison(actual_output + len, TESTMGR_POISON_LEN))
656 return -EOVERFLOW;
657 len_to_check -= len;
658 expected_output += len;
659 }
660 if (WARN_ON(len_to_check != 0))
661 return -EINVAL;
662 return 0;
663}
664
665static bool is_test_sglist_corrupted(const struct test_sglist *tsgl)
666{
667 unsigned int i;
668
669 for (i = 0; i < tsgl->nents; i++) {
670 if (tsgl->sgl[i].page_link != tsgl->sgl_saved[i].page_link)
671 return true;
672 if (tsgl->sgl[i].offset != tsgl->sgl_saved[i].offset)
673 return true;
674 if (tsgl->sgl[i].length != tsgl->sgl_saved[i].length)
675 return true;
676 }
677 return false;
678}
679
680struct cipher_test_sglists {
681 struct test_sglist src;
682 struct test_sglist dst;
683};
684
685static struct cipher_test_sglists *alloc_cipher_test_sglists(void)
686{
687 struct cipher_test_sglists *tsgls;
688
689 tsgls = kmalloc(sizeof(*tsgls), GFP_KERNEL);
690 if (!tsgls)
691 return NULL;
692
693 if (init_test_sglist(&tsgls->src) != 0)
694 goto fail_kfree;
695 if (init_test_sglist(&tsgls->dst) != 0)
696 goto fail_destroy_src;
697
698 return tsgls;
699
700fail_destroy_src:
701 destroy_test_sglist(&tsgls->src);
702fail_kfree:
703 kfree(tsgls);
704 return NULL;
705}
706
707static void free_cipher_test_sglists(struct cipher_test_sglists *tsgls)
708{
709 if (tsgls) {
710 destroy_test_sglist(&tsgls->src);
711 destroy_test_sglist(&tsgls->dst);
712 kfree(tsgls);
713 }
714}
715
716/* Build the src and dst scatterlists for an skcipher or AEAD test */
717static int build_cipher_test_sglists(struct cipher_test_sglists *tsgls,
718 const struct testvec_config *cfg,
719 unsigned int alignmask,
720 unsigned int src_total_len,
721 unsigned int dst_total_len,
722 const struct kvec *inputs,
723 unsigned int nr_inputs)
724{
725 struct iov_iter input;
726 int err;
727
728 iov_iter_kvec(&input, WRITE, inputs, nr_inputs, src_total_len);
729 err = build_test_sglist(&tsgls->src, cfg->src_divs, alignmask,
730 cfg->inplace ?
731 max(dst_total_len, src_total_len) :
732 src_total_len,
733 &input, NULL);
734 if (err)
735 return err;
736
737 if (cfg->inplace) {
738 tsgls->dst.sgl_ptr = tsgls->src.sgl;
739 tsgls->dst.nents = tsgls->src.nents;
740 return 0;
741 }
742 return build_test_sglist(&tsgls->dst,
743 cfg->dst_divs[0].proportion_of_total ?
744 cfg->dst_divs : cfg->src_divs,
745 alignmask, dst_total_len, NULL, NULL);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800746}
747
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800748#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
Eric Biggersf2bb770a2019-04-11 21:57:38 -0700749
750/* Generate a random length in range [0, max_len], but prefer smaller values */
751static unsigned int generate_random_length(unsigned int max_len)
752{
753 unsigned int len = prandom_u32() % (max_len + 1);
754
755 switch (prandom_u32() % 4) {
756 case 0:
757 return len % 64;
758 case 1:
759 return len % 256;
760 case 2:
761 return len % 1024;
762 default:
763 return len;
764 }
765}
766
767/* Sometimes make some random changes to the given data buffer */
768static void mutate_buffer(u8 *buf, size_t count)
769{
770 size_t num_flips;
771 size_t i;
772 size_t pos;
773
774 /* Sometimes flip some bits */
775 if (prandom_u32() % 4 == 0) {
776 num_flips = min_t(size_t, 1 << (prandom_u32() % 8), count * 8);
777 for (i = 0; i < num_flips; i++) {
778 pos = prandom_u32() % (count * 8);
779 buf[pos / 8] ^= 1 << (pos % 8);
780 }
781 }
782
783 /* Sometimes flip some bytes */
784 if (prandom_u32() % 4 == 0) {
785 num_flips = min_t(size_t, 1 << (prandom_u32() % 8), count);
786 for (i = 0; i < num_flips; i++)
787 buf[prandom_u32() % count] ^= 0xff;
788 }
789}
790
791/* Randomly generate 'count' bytes, but sometimes make them "interesting" */
792static void generate_random_bytes(u8 *buf, size_t count)
793{
794 u8 b;
795 u8 increment;
796 size_t i;
797
798 if (count == 0)
799 return;
800
801 switch (prandom_u32() % 8) { /* Choose a generation strategy */
802 case 0:
803 case 1:
804 /* All the same byte, plus optional mutations */
805 switch (prandom_u32() % 4) {
806 case 0:
807 b = 0x00;
808 break;
809 case 1:
810 b = 0xff;
811 break;
812 default:
813 b = (u8)prandom_u32();
814 break;
815 }
816 memset(buf, b, count);
817 mutate_buffer(buf, count);
818 break;
819 case 2:
820 /* Ascending or descending bytes, plus optional mutations */
821 increment = (u8)prandom_u32();
822 b = (u8)prandom_u32();
823 for (i = 0; i < count; i++, b += increment)
824 buf[i] = b;
825 mutate_buffer(buf, count);
826 break;
827 default:
828 /* Fully random bytes */
829 for (i = 0; i < count; i++)
830 buf[i] = (u8)prandom_u32();
831 }
832}
833
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800834static char *generate_random_sgl_divisions(struct test_sg_division *divs,
835 size_t max_divs, char *p, char *end,
Eric Biggers65707372019-03-12 22:12:52 -0700836 bool gen_flushes, u32 req_flags)
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800837{
838 struct test_sg_division *div = divs;
839 unsigned int remaining = TEST_SG_TOTAL;
840
841 do {
842 unsigned int this_len;
Eric Biggers65707372019-03-12 22:12:52 -0700843 const char *flushtype_str;
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800844
845 if (div == &divs[max_divs - 1] || prandom_u32() % 2 == 0)
846 this_len = remaining;
847 else
848 this_len = 1 + (prandom_u32() % remaining);
849 div->proportion_of_total = this_len;
850
851 if (prandom_u32() % 4 == 0)
852 div->offset = (PAGE_SIZE - 128) + (prandom_u32() % 128);
853 else if (prandom_u32() % 2 == 0)
854 div->offset = prandom_u32() % 32;
855 else
856 div->offset = prandom_u32() % PAGE_SIZE;
857 if (prandom_u32() % 8 == 0)
858 div->offset_relative_to_alignmask = true;
859
860 div->flush_type = FLUSH_TYPE_NONE;
861 if (gen_flushes) {
862 switch (prandom_u32() % 4) {
863 case 0:
864 div->flush_type = FLUSH_TYPE_REIMPORT;
865 break;
866 case 1:
867 div->flush_type = FLUSH_TYPE_FLUSH;
868 break;
869 }
870 }
871
Eric Biggers65707372019-03-12 22:12:52 -0700872 if (div->flush_type != FLUSH_TYPE_NONE &&
873 !(req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) &&
874 prandom_u32() % 2 == 0)
875 div->nosimd = true;
876
877 switch (div->flush_type) {
878 case FLUSH_TYPE_FLUSH:
879 if (div->nosimd)
880 flushtype_str = "<flush,nosimd>";
881 else
882 flushtype_str = "<flush>";
883 break;
884 case FLUSH_TYPE_REIMPORT:
885 if (div->nosimd)
886 flushtype_str = "<reimport,nosimd>";
887 else
888 flushtype_str = "<reimport>";
889 break;
890 default:
891 flushtype_str = "";
892 break;
893 }
894
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800895 BUILD_BUG_ON(TEST_SG_TOTAL != 10000); /* for "%u.%u%%" */
Eric Biggers65707372019-03-12 22:12:52 -0700896 p += scnprintf(p, end - p, "%s%u.%u%%@%s+%u%s", flushtype_str,
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800897 this_len / 100, this_len % 100,
898 div->offset_relative_to_alignmask ?
899 "alignmask" : "",
900 div->offset, this_len == remaining ? "" : ", ");
901 remaining -= this_len;
902 div++;
903 } while (remaining);
904
905 return p;
906}
907
908/* Generate a random testvec_config for fuzz testing */
909static void generate_random_testvec_config(struct testvec_config *cfg,
910 char *name, size_t max_namelen)
911{
912 char *p = name;
913 char * const end = name + max_namelen;
914
915 memset(cfg, 0, sizeof(*cfg));
916
917 cfg->name = name;
918
919 p += scnprintf(p, end - p, "random:");
920
921 if (prandom_u32() % 2 == 0) {
922 cfg->inplace = true;
923 p += scnprintf(p, end - p, " inplace");
924 }
925
926 if (prandom_u32() % 2 == 0) {
927 cfg->req_flags |= CRYPTO_TFM_REQ_MAY_SLEEP;
928 p += scnprintf(p, end - p, " may_sleep");
929 }
930
931 switch (prandom_u32() % 4) {
932 case 0:
933 cfg->finalization_type = FINALIZATION_TYPE_FINAL;
934 p += scnprintf(p, end - p, " use_final");
935 break;
936 case 1:
937 cfg->finalization_type = FINALIZATION_TYPE_FINUP;
938 p += scnprintf(p, end - p, " use_finup");
939 break;
940 default:
941 cfg->finalization_type = FINALIZATION_TYPE_DIGEST;
942 p += scnprintf(p, end - p, " use_digest");
943 break;
944 }
945
Eric Biggers65707372019-03-12 22:12:52 -0700946 if (!(cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) &&
947 prandom_u32() % 2 == 0) {
948 cfg->nosimd = true;
949 p += scnprintf(p, end - p, " nosimd");
950 }
951
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800952 p += scnprintf(p, end - p, " src_divs=[");
953 p = generate_random_sgl_divisions(cfg->src_divs,
954 ARRAY_SIZE(cfg->src_divs), p, end,
955 (cfg->finalization_type !=
Eric Biggers65707372019-03-12 22:12:52 -0700956 FINALIZATION_TYPE_DIGEST),
957 cfg->req_flags);
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800958 p += scnprintf(p, end - p, "]");
959
960 if (!cfg->inplace && prandom_u32() % 2 == 0) {
961 p += scnprintf(p, end - p, " dst_divs=[");
962 p = generate_random_sgl_divisions(cfg->dst_divs,
963 ARRAY_SIZE(cfg->dst_divs),
Eric Biggers65707372019-03-12 22:12:52 -0700964 p, end, false,
965 cfg->req_flags);
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800966 p += scnprintf(p, end - p, "]");
967 }
968
969 if (prandom_u32() % 2 == 0) {
970 cfg->iv_offset = 1 + (prandom_u32() % MAX_ALGAPI_ALIGNMASK);
971 p += scnprintf(p, end - p, " iv_offset=%u", cfg->iv_offset);
972 }
973
974 WARN_ON_ONCE(!valid_testvec_config(cfg));
975}
Eric Biggersb55e1a32019-03-12 22:12:47 -0700976
977static void crypto_disable_simd_for_test(void)
978{
979 preempt_disable();
980 __this_cpu_write(crypto_simd_disabled_for_test, true);
981}
982
983static void crypto_reenable_simd_for_test(void)
984{
985 __this_cpu_write(crypto_simd_disabled_for_test, false);
986 preempt_enable();
987}
Eric Biggersf2bb770a2019-04-11 21:57:38 -0700988
989/*
990 * Given an algorithm name, build the name of the generic implementation of that
991 * algorithm, assuming the usual naming convention. Specifically, this appends
992 * "-generic" to every part of the name that is not a template name. Examples:
993 *
994 * aes => aes-generic
995 * cbc(aes) => cbc(aes-generic)
996 * cts(cbc(aes)) => cts(cbc(aes-generic))
997 * rfc7539(chacha20,poly1305) => rfc7539(chacha20-generic,poly1305-generic)
998 *
999 * Return: 0 on success, or -ENAMETOOLONG if the generic name would be too long
1000 */
1001static int build_generic_driver_name(const char *algname,
1002 char driver_name[CRYPTO_MAX_ALG_NAME])
1003{
1004 const char *in = algname;
1005 char *out = driver_name;
1006 size_t len = strlen(algname);
1007
1008 if (len >= CRYPTO_MAX_ALG_NAME)
1009 goto too_long;
1010 do {
1011 const char *in_saved = in;
1012
1013 while (*in && *in != '(' && *in != ')' && *in != ',')
1014 *out++ = *in++;
1015 if (*in != '(' && in > in_saved) {
1016 len += 8;
1017 if (len >= CRYPTO_MAX_ALG_NAME)
1018 goto too_long;
1019 memcpy(out, "-generic", 8);
1020 out += 8;
1021 }
1022 } while ((*out++ = *in++) != '\0');
1023 return 0;
1024
1025too_long:
1026 pr_err("alg: generic driver name for \"%s\" would be too long\n",
1027 algname);
1028 return -ENAMETOOLONG;
1029}
Eric Biggersb55e1a32019-03-12 22:12:47 -07001030#else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
1031static void crypto_disable_simd_for_test(void)
1032{
1033}
1034
1035static void crypto_reenable_simd_for_test(void)
1036{
1037}
1038#endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
Eric Biggers25f9ddd2019-01-31 23:51:45 -08001039
Eric Biggers65707372019-03-12 22:12:52 -07001040static int do_ahash_op(int (*op)(struct ahash_request *req),
1041 struct ahash_request *req,
1042 struct crypto_wait *wait, bool nosimd)
1043{
1044 int err;
1045
1046 if (nosimd)
1047 crypto_disable_simd_for_test();
1048
1049 err = op(req);
1050
1051 if (nosimd)
1052 crypto_reenable_simd_for_test();
1053
1054 return crypto_wait_req(err, wait);
1055}
1056
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001057static int check_nonfinal_hash_op(const char *op, int err,
1058 u8 *result, unsigned int digestsize,
Eric Biggers951d1332019-04-11 21:57:37 -07001059 const char *driver, const char *vec_name,
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001060 const struct testvec_config *cfg)
Kamil Konieczny466d7b92018-01-16 15:26:13 +01001061{
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001062 if (err) {
Eric Biggers951d1332019-04-11 21:57:37 -07001063 pr_err("alg: hash: %s %s() failed with err %d on test vector %s, cfg=\"%s\"\n",
1064 driver, op, err, vec_name, cfg->name);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001065 return err;
1066 }
1067 if (!testmgr_is_poison(result, digestsize)) {
Eric Biggers951d1332019-04-11 21:57:37 -07001068 pr_err("alg: hash: %s %s() used result buffer on test vector %s, cfg=\"%s\"\n",
1069 driver, op, vec_name, cfg->name);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001070 return -EINVAL;
1071 }
1072 return 0;
1073}
Kamil Konieczny466d7b92018-01-16 15:26:13 +01001074
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001075static int test_hash_vec_cfg(const char *driver,
1076 const struct hash_testvec *vec,
Eric Biggers951d1332019-04-11 21:57:37 -07001077 const char *vec_name,
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001078 const struct testvec_config *cfg,
1079 struct ahash_request *req,
1080 struct test_sglist *tsgl,
1081 u8 *hashstate)
1082{
1083 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
1084 const unsigned int alignmask = crypto_ahash_alignmask(tfm);
1085 const unsigned int digestsize = crypto_ahash_digestsize(tfm);
1086 const unsigned int statesize = crypto_ahash_statesize(tfm);
1087 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
1088 const struct test_sg_division *divs[XBUFSIZE];
1089 DECLARE_CRYPTO_WAIT(wait);
1090 struct kvec _input;
1091 struct iov_iter input;
1092 unsigned int i;
1093 struct scatterlist *pending_sgl;
1094 unsigned int pending_len;
1095 u8 result[HASH_MAX_DIGESTSIZE + TESTMGR_POISON_LEN];
1096 int err;
1097
1098 /* Set the key, if specified */
1099 if (vec->ksize) {
1100 err = crypto_ahash_setkey(tfm, vec->key, vec->ksize);
1101 if (err) {
Eric Biggers5283a8e2019-04-11 21:57:36 -07001102 if (err == vec->setkey_error)
1103 return 0;
Eric Biggers951d1332019-04-11 21:57:37 -07001104 pr_err("alg: hash: %s setkey failed on test vector %s; expected_error=%d, actual_error=%d, flags=%#x\n",
1105 driver, vec_name, vec->setkey_error, err,
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001106 crypto_ahash_get_flags(tfm));
1107 return err;
1108 }
Eric Biggers5283a8e2019-04-11 21:57:36 -07001109 if (vec->setkey_error) {
Eric Biggers951d1332019-04-11 21:57:37 -07001110 pr_err("alg: hash: %s setkey unexpectedly succeeded on test vector %s; expected_error=%d\n",
1111 driver, vec_name, vec->setkey_error);
Eric Biggers5283a8e2019-04-11 21:57:36 -07001112 return -EINVAL;
1113 }
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001114 }
1115
1116 /* Build the scatterlist for the source data */
1117 _input.iov_base = (void *)vec->plaintext;
1118 _input.iov_len = vec->psize;
1119 iov_iter_kvec(&input, WRITE, &_input, 1, vec->psize);
1120 err = build_test_sglist(tsgl, cfg->src_divs, alignmask, vec->psize,
1121 &input, divs);
1122 if (err) {
Eric Biggers951d1332019-04-11 21:57:37 -07001123 pr_err("alg: hash: %s: error preparing scatterlist for test vector %s, cfg=\"%s\"\n",
1124 driver, vec_name, cfg->name);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001125 return err;
1126 }
1127
1128 /* Do the actual hashing */
1129
1130 testmgr_poison(req->__ctx, crypto_ahash_reqsize(tfm));
1131 testmgr_poison(result, digestsize + TESTMGR_POISON_LEN);
1132
Eric Biggers5283a8e2019-04-11 21:57:36 -07001133 if (cfg->finalization_type == FINALIZATION_TYPE_DIGEST ||
1134 vec->digest_error) {
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001135 /* Just using digest() */
1136 ahash_request_set_callback(req, req_flags, crypto_req_done,
1137 &wait);
1138 ahash_request_set_crypt(req, tsgl->sgl, result, vec->psize);
Eric Biggers65707372019-03-12 22:12:52 -07001139 err = do_ahash_op(crypto_ahash_digest, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001140 if (err) {
Eric Biggers5283a8e2019-04-11 21:57:36 -07001141 if (err == vec->digest_error)
1142 return 0;
Eric Biggers951d1332019-04-11 21:57:37 -07001143 pr_err("alg: hash: %s digest() failed on test vector %s; expected_error=%d, actual_error=%d, cfg=\"%s\"\n",
1144 driver, vec_name, vec->digest_error, err,
Eric Biggers5283a8e2019-04-11 21:57:36 -07001145 cfg->name);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001146 return err;
1147 }
Eric Biggers5283a8e2019-04-11 21:57:36 -07001148 if (vec->digest_error) {
Eric Biggers951d1332019-04-11 21:57:37 -07001149 pr_err("alg: hash: %s digest() unexpectedly succeeded on test vector %s; expected_error=%d, cfg=\"%s\"\n",
1150 driver, vec_name, vec->digest_error, cfg->name);
Eric Biggers5283a8e2019-04-11 21:57:36 -07001151 return -EINVAL;
1152 }
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001153 goto result_ready;
1154 }
1155
1156 /* Using init(), zero or more update(), then final() or finup() */
1157
1158 ahash_request_set_callback(req, req_flags, crypto_req_done, &wait);
1159 ahash_request_set_crypt(req, NULL, result, 0);
Eric Biggers65707372019-03-12 22:12:52 -07001160 err = do_ahash_op(crypto_ahash_init, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001161 err = check_nonfinal_hash_op("init", err, result, digestsize,
Eric Biggers951d1332019-04-11 21:57:37 -07001162 driver, vec_name, cfg);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001163 if (err)
1164 return err;
1165
1166 pending_sgl = NULL;
1167 pending_len = 0;
1168 for (i = 0; i < tsgl->nents; i++) {
1169 if (divs[i]->flush_type != FLUSH_TYPE_NONE &&
1170 pending_sgl != NULL) {
1171 /* update() with the pending data */
1172 ahash_request_set_callback(req, req_flags,
1173 crypto_req_done, &wait);
1174 ahash_request_set_crypt(req, pending_sgl, result,
1175 pending_len);
Eric Biggers65707372019-03-12 22:12:52 -07001176 err = do_ahash_op(crypto_ahash_update, req, &wait,
1177 divs[i]->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001178 err = check_nonfinal_hash_op("update", err,
1179 result, digestsize,
Eric Biggers951d1332019-04-11 21:57:37 -07001180 driver, vec_name, cfg);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001181 if (err)
1182 return err;
1183 pending_sgl = NULL;
1184 pending_len = 0;
1185 }
1186 if (divs[i]->flush_type == FLUSH_TYPE_REIMPORT) {
1187 /* Test ->export() and ->import() */
1188 testmgr_poison(hashstate + statesize,
1189 TESTMGR_POISON_LEN);
1190 err = crypto_ahash_export(req, hashstate);
1191 err = check_nonfinal_hash_op("export", err,
1192 result, digestsize,
Eric Biggers951d1332019-04-11 21:57:37 -07001193 driver, vec_name, cfg);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001194 if (err)
1195 return err;
1196 if (!testmgr_is_poison(hashstate + statesize,
1197 TESTMGR_POISON_LEN)) {
Eric Biggers951d1332019-04-11 21:57:37 -07001198 pr_err("alg: hash: %s export() overran state buffer on test vector %s, cfg=\"%s\"\n",
1199 driver, vec_name, cfg->name);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001200 return -EOVERFLOW;
1201 }
1202
1203 testmgr_poison(req->__ctx, crypto_ahash_reqsize(tfm));
1204 err = crypto_ahash_import(req, hashstate);
1205 err = check_nonfinal_hash_op("import", err,
1206 result, digestsize,
Eric Biggers951d1332019-04-11 21:57:37 -07001207 driver, vec_name, cfg);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001208 if (err)
1209 return err;
1210 }
1211 if (pending_sgl == NULL)
1212 pending_sgl = &tsgl->sgl[i];
1213 pending_len += tsgl->sgl[i].length;
1214 }
1215
1216 ahash_request_set_callback(req, req_flags, crypto_req_done, &wait);
1217 ahash_request_set_crypt(req, pending_sgl, result, pending_len);
1218 if (cfg->finalization_type == FINALIZATION_TYPE_FINAL) {
1219 /* finish with update() and final() */
Eric Biggers65707372019-03-12 22:12:52 -07001220 err = do_ahash_op(crypto_ahash_update, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001221 err = check_nonfinal_hash_op("update", err, result, digestsize,
Eric Biggers951d1332019-04-11 21:57:37 -07001222 driver, vec_name, cfg);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001223 if (err)
1224 return err;
Eric Biggers65707372019-03-12 22:12:52 -07001225 err = do_ahash_op(crypto_ahash_final, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001226 if (err) {
Eric Biggers951d1332019-04-11 21:57:37 -07001227 pr_err("alg: hash: %s final() failed with err %d on test vector %s, cfg=\"%s\"\n",
1228 driver, err, vec_name, cfg->name);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001229 return err;
1230 }
1231 } else {
1232 /* finish with finup() */
Eric Biggers65707372019-03-12 22:12:52 -07001233 err = do_ahash_op(crypto_ahash_finup, req, &wait, cfg->nosimd);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001234 if (err) {
Eric Biggers951d1332019-04-11 21:57:37 -07001235 pr_err("alg: hash: %s finup() failed with err %d on test vector %s, cfg=\"%s\"\n",
1236 driver, err, vec_name, cfg->name);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001237 return err;
1238 }
1239 }
1240
1241result_ready:
1242 /* Check that the algorithm produced the correct digest */
1243 if (memcmp(result, vec->digest, digestsize) != 0) {
Eric Biggers951d1332019-04-11 21:57:37 -07001244 pr_err("alg: hash: %s test failed (wrong result) on test vector %s, cfg=\"%s\"\n",
1245 driver, vec_name, cfg->name);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001246 return -EINVAL;
1247 }
1248 if (!testmgr_is_poison(&result[digestsize], TESTMGR_POISON_LEN)) {
Eric Biggers951d1332019-04-11 21:57:37 -07001249 pr_err("alg: hash: %s overran result buffer on test vector %s, cfg=\"%s\"\n",
1250 driver, vec_name, cfg->name);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001251 return -EOVERFLOW;
1252 }
1253
1254 return 0;
1255}
1256
1257static int test_hash_vec(const char *driver, const struct hash_testvec *vec,
1258 unsigned int vec_num, struct ahash_request *req,
1259 struct test_sglist *tsgl, u8 *hashstate)
1260{
Eric Biggers951d1332019-04-11 21:57:37 -07001261 char vec_name[16];
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001262 unsigned int i;
1263 int err;
1264
Eric Biggers951d1332019-04-11 21:57:37 -07001265 sprintf(vec_name, "%u", vec_num);
1266
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001267 for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++) {
Eric Biggers951d1332019-04-11 21:57:37 -07001268 err = test_hash_vec_cfg(driver, vec, vec_name,
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001269 &default_hash_testvec_configs[i],
1270 req, tsgl, hashstate);
1271 if (err)
1272 return err;
1273 }
1274
1275#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1276 if (!noextratests) {
1277 struct testvec_config cfg;
1278 char cfgname[TESTVEC_CONFIG_NAMELEN];
1279
1280 for (i = 0; i < fuzz_iterations; i++) {
1281 generate_random_testvec_config(&cfg, cfgname,
1282 sizeof(cfgname));
Eric Biggers951d1332019-04-11 21:57:37 -07001283 err = test_hash_vec_cfg(driver, vec, vec_name, &cfg,
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001284 req, tsgl, hashstate);
1285 if (err)
1286 return err;
1287 }
1288 }
1289#endif
1290 return 0;
1291}
1292
Eric Biggers9a8a6b32019-04-11 21:57:39 -07001293#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1294/*
1295 * Generate a hash test vector from the given implementation.
1296 * Assumes the buffers in 'vec' were already allocated.
1297 */
1298static void generate_random_hash_testvec(struct crypto_shash *tfm,
1299 struct hash_testvec *vec,
1300 unsigned int maxkeysize,
1301 unsigned int maxdatasize,
1302 char *name, size_t max_namelen)
1303{
1304 SHASH_DESC_ON_STACK(desc, tfm);
1305
1306 /* Data */
1307 vec->psize = generate_random_length(maxdatasize);
1308 generate_random_bytes((u8 *)vec->plaintext, vec->psize);
1309
1310 /*
1311 * Key: length in range [1, maxkeysize], but usually choose maxkeysize.
1312 * If algorithm is unkeyed, then maxkeysize == 0 and set ksize = 0.
1313 */
1314 vec->setkey_error = 0;
1315 vec->ksize = 0;
1316 if (maxkeysize) {
1317 vec->ksize = maxkeysize;
1318 if (prandom_u32() % 4 == 0)
1319 vec->ksize = 1 + (prandom_u32() % maxkeysize);
1320 generate_random_bytes((u8 *)vec->key, vec->ksize);
1321
1322 vec->setkey_error = crypto_shash_setkey(tfm, vec->key,
1323 vec->ksize);
1324 /* If the key couldn't be set, no need to continue to digest. */
1325 if (vec->setkey_error)
1326 goto done;
1327 }
1328
1329 /* Digest */
1330 desc->tfm = tfm;
Eric Biggers9a8a6b32019-04-11 21:57:39 -07001331 vec->digest_error = crypto_shash_digest(desc, vec->plaintext,
1332 vec->psize, (u8 *)vec->digest);
1333done:
1334 snprintf(name, max_namelen, "\"random: psize=%u ksize=%u\"",
1335 vec->psize, vec->ksize);
1336}
1337
1338/*
1339 * Test the hash algorithm represented by @req against the corresponding generic
1340 * implementation, if one is available.
1341 */
1342static int test_hash_vs_generic_impl(const char *driver,
1343 const char *generic_driver,
1344 unsigned int maxkeysize,
1345 struct ahash_request *req,
1346 struct test_sglist *tsgl,
1347 u8 *hashstate)
1348{
1349 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
1350 const unsigned int digestsize = crypto_ahash_digestsize(tfm);
1351 const unsigned int blocksize = crypto_ahash_blocksize(tfm);
1352 const unsigned int maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN;
1353 const char *algname = crypto_hash_alg_common(tfm)->base.cra_name;
1354 char _generic_driver[CRYPTO_MAX_ALG_NAME];
1355 struct crypto_shash *generic_tfm = NULL;
1356 unsigned int i;
1357 struct hash_testvec vec = { 0 };
1358 char vec_name[64];
1359 struct testvec_config cfg;
1360 char cfgname[TESTVEC_CONFIG_NAMELEN];
1361 int err;
1362
1363 if (noextratests)
1364 return 0;
1365
1366 if (!generic_driver) { /* Use default naming convention? */
1367 err = build_generic_driver_name(algname, _generic_driver);
1368 if (err)
1369 return err;
1370 generic_driver = _generic_driver;
1371 }
1372
1373 if (strcmp(generic_driver, driver) == 0) /* Already the generic impl? */
1374 return 0;
1375
1376 generic_tfm = crypto_alloc_shash(generic_driver, 0, 0);
1377 if (IS_ERR(generic_tfm)) {
1378 err = PTR_ERR(generic_tfm);
1379 if (err == -ENOENT) {
1380 pr_warn("alg: hash: skipping comparison tests for %s because %s is unavailable\n",
1381 driver, generic_driver);
1382 return 0;
1383 }
1384 pr_err("alg: hash: error allocating %s (generic impl of %s): %d\n",
1385 generic_driver, algname, err);
1386 return err;
1387 }
1388
1389 /* Check the algorithm properties for consistency. */
1390
1391 if (digestsize != crypto_shash_digestsize(generic_tfm)) {
1392 pr_err("alg: hash: digestsize for %s (%u) doesn't match generic impl (%u)\n",
1393 driver, digestsize,
1394 crypto_shash_digestsize(generic_tfm));
1395 err = -EINVAL;
1396 goto out;
1397 }
1398
1399 if (blocksize != crypto_shash_blocksize(generic_tfm)) {
1400 pr_err("alg: hash: blocksize for %s (%u) doesn't match generic impl (%u)\n",
1401 driver, blocksize, crypto_shash_blocksize(generic_tfm));
1402 err = -EINVAL;
1403 goto out;
1404 }
1405
1406 /*
1407 * Now generate test vectors using the generic implementation, and test
1408 * the other implementation against them.
1409 */
1410
1411 vec.key = kmalloc(maxkeysize, GFP_KERNEL);
1412 vec.plaintext = kmalloc(maxdatasize, GFP_KERNEL);
1413 vec.digest = kmalloc(digestsize, GFP_KERNEL);
1414 if (!vec.key || !vec.plaintext || !vec.digest) {
1415 err = -ENOMEM;
1416 goto out;
1417 }
1418
1419 for (i = 0; i < fuzz_iterations * 8; i++) {
1420 generate_random_hash_testvec(generic_tfm, &vec,
1421 maxkeysize, maxdatasize,
1422 vec_name, sizeof(vec_name));
1423 generate_random_testvec_config(&cfg, cfgname, sizeof(cfgname));
1424
1425 err = test_hash_vec_cfg(driver, &vec, vec_name, &cfg,
1426 req, tsgl, hashstate);
1427 if (err)
1428 goto out;
1429 cond_resched();
1430 }
1431 err = 0;
1432out:
1433 kfree(vec.key);
1434 kfree(vec.plaintext);
1435 kfree(vec.digest);
1436 crypto_free_shash(generic_tfm);
1437 return err;
1438}
1439#else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
1440static int test_hash_vs_generic_impl(const char *driver,
1441 const char *generic_driver,
1442 unsigned int maxkeysize,
1443 struct ahash_request *req,
1444 struct test_sglist *tsgl,
1445 u8 *hashstate)
1446{
1447 return 0;
1448}
1449#endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
1450
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001451static int __alg_test_hash(const struct hash_testvec *vecs,
1452 unsigned int num_vecs, const char *driver,
Eric Biggers9a8a6b32019-04-11 21:57:39 -07001453 u32 type, u32 mask,
1454 const char *generic_driver, unsigned int maxkeysize)
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001455{
1456 struct crypto_ahash *tfm;
1457 struct ahash_request *req = NULL;
1458 struct test_sglist *tsgl = NULL;
1459 u8 *hashstate = NULL;
1460 unsigned int i;
1461 int err;
1462
1463 tfm = crypto_alloc_ahash(driver, type, mask);
1464 if (IS_ERR(tfm)) {
1465 pr_err("alg: hash: failed to allocate transform for %s: %ld\n",
1466 driver, PTR_ERR(tfm));
1467 return PTR_ERR(tfm);
1468 }
1469
1470 req = ahash_request_alloc(tfm, GFP_KERNEL);
1471 if (!req) {
1472 pr_err("alg: hash: failed to allocate request for %s\n",
1473 driver);
1474 err = -ENOMEM;
1475 goto out;
1476 }
1477
1478 tsgl = kmalloc(sizeof(*tsgl), GFP_KERNEL);
1479 if (!tsgl || init_test_sglist(tsgl) != 0) {
1480 pr_err("alg: hash: failed to allocate test buffers for %s\n",
1481 driver);
1482 kfree(tsgl);
1483 tsgl = NULL;
1484 err = -ENOMEM;
1485 goto out;
1486 }
1487
1488 hashstate = kmalloc(crypto_ahash_statesize(tfm) + TESTMGR_POISON_LEN,
1489 GFP_KERNEL);
1490 if (!hashstate) {
1491 pr_err("alg: hash: failed to allocate hash state buffer for %s\n",
1492 driver);
1493 err = -ENOMEM;
1494 goto out;
1495 }
1496
1497 for (i = 0; i < num_vecs; i++) {
1498 err = test_hash_vec(driver, &vecs[i], i, req, tsgl, hashstate);
1499 if (err)
1500 goto out;
1501 }
Eric Biggers9a8a6b32019-04-11 21:57:39 -07001502 err = test_hash_vs_generic_impl(driver, generic_driver, maxkeysize, req,
1503 tsgl, hashstate);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001504out:
1505 kfree(hashstate);
1506 if (tsgl) {
1507 destroy_test_sglist(tsgl);
1508 kfree(tsgl);
1509 }
1510 ahash_request_free(req);
1511 crypto_free_ahash(tfm);
1512 return err;
1513}
1514
1515static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1516 u32 type, u32 mask)
1517{
1518 const struct hash_testvec *template = desc->suite.hash.vecs;
1519 unsigned int tcount = desc->suite.hash.count;
1520 unsigned int nr_unkeyed, nr_keyed;
Eric Biggers9a8a6b32019-04-11 21:57:39 -07001521 unsigned int maxkeysize = 0;
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001522 int err;
1523
1524 /*
1525 * For OPTIONAL_KEY algorithms, we have to do all the unkeyed tests
1526 * first, before setting a key on the tfm. To make this easier, we
1527 * require that the unkeyed test vectors (if any) are listed first.
1528 */
1529
1530 for (nr_unkeyed = 0; nr_unkeyed < tcount; nr_unkeyed++) {
1531 if (template[nr_unkeyed].ksize)
1532 break;
1533 }
1534 for (nr_keyed = 0; nr_unkeyed + nr_keyed < tcount; nr_keyed++) {
1535 if (!template[nr_unkeyed + nr_keyed].ksize) {
1536 pr_err("alg: hash: test vectors for %s out of order, "
1537 "unkeyed ones must come first\n", desc->alg);
Kamil Konieczny466d7b92018-01-16 15:26:13 +01001538 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08001539 }
Eric Biggers9a8a6b32019-04-11 21:57:39 -07001540 maxkeysize = max_t(unsigned int, maxkeysize,
1541 template[nr_unkeyed + nr_keyed].ksize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001542 }
1543
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001544 err = 0;
1545 if (nr_unkeyed) {
Eric Biggers9a8a6b32019-04-11 21:57:39 -07001546 err = __alg_test_hash(template, nr_unkeyed, driver, type, mask,
1547 desc->generic_driver, maxkeysize);
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001548 template += nr_unkeyed;
Herbert Xuda7f0332008-07-31 17:08:25 +08001549 }
1550
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001551 if (!err && nr_keyed)
Eric Biggers9a8a6b32019-04-11 21:57:39 -07001552 err = __alg_test_hash(template, nr_keyed, driver, type, mask,
1553 desc->generic_driver, maxkeysize);
Wang, Rui Y018ba952016-02-03 18:26:57 +08001554
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08001555 return err;
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +03001556}
1557
Eric Biggersed968042019-01-31 23:51:47 -08001558static int test_aead_vec_cfg(const char *driver, int enc,
1559 const struct aead_testvec *vec,
Eric Biggers951d1332019-04-11 21:57:37 -07001560 const char *vec_name,
Eric Biggersed968042019-01-31 23:51:47 -08001561 const struct testvec_config *cfg,
1562 struct aead_request *req,
1563 struct cipher_test_sglists *tsgls)
Herbert Xuda7f0332008-07-31 17:08:25 +08001564{
Eric Biggersed968042019-01-31 23:51:47 -08001565 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1566 const unsigned int alignmask = crypto_aead_alignmask(tfm);
1567 const unsigned int ivsize = crypto_aead_ivsize(tfm);
1568 const unsigned int authsize = vec->clen - vec->plen;
1569 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
1570 const char *op = enc ? "encryption" : "decryption";
1571 DECLARE_CRYPTO_WAIT(wait);
1572 u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN];
1573 u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) +
1574 cfg->iv_offset +
1575 (cfg->iv_offset_relative_to_alignmask ? alignmask : 0);
1576 struct kvec input[2];
Eric Biggers5283a8e2019-04-11 21:57:36 -07001577 int expected_error;
Eric Biggersed968042019-01-31 23:51:47 -08001578 int err;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001579
Eric Biggersed968042019-01-31 23:51:47 -08001580 /* Set the key */
1581 if (vec->wk)
1582 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001583 else
Eric Biggersed968042019-01-31 23:51:47 -08001584 crypto_aead_clear_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
1585 err = crypto_aead_setkey(tfm, vec->key, vec->klen);
Eric Biggers5283a8e2019-04-11 21:57:36 -07001586 if (err && err != vec->setkey_error) {
Eric Biggers951d1332019-04-11 21:57:37 -07001587 pr_err("alg: aead: %s setkey failed on test vector %s; expected_error=%d, actual_error=%d, flags=%#x\n",
1588 driver, vec_name, vec->setkey_error, err,
Eric Biggers5283a8e2019-04-11 21:57:36 -07001589 crypto_aead_get_flags(tfm));
Eric Biggersed968042019-01-31 23:51:47 -08001590 return err;
1591 }
Eric Biggers5283a8e2019-04-11 21:57:36 -07001592 if (!err && vec->setkey_error) {
Eric Biggers951d1332019-04-11 21:57:37 -07001593 pr_err("alg: aead: %s setkey unexpectedly succeeded on test vector %s; expected_error=%d\n",
1594 driver, vec_name, vec->setkey_error);
Eric Biggersed968042019-01-31 23:51:47 -08001595 return -EINVAL;
1596 }
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001597
Eric Biggersed968042019-01-31 23:51:47 -08001598 /* Set the authentication tag size */
1599 err = crypto_aead_setauthsize(tfm, authsize);
Eric Biggers5283a8e2019-04-11 21:57:36 -07001600 if (err && err != vec->setauthsize_error) {
Eric Biggers951d1332019-04-11 21:57:37 -07001601 pr_err("alg: aead: %s setauthsize failed on test vector %s; expected_error=%d, actual_error=%d\n",
1602 driver, vec_name, vec->setauthsize_error, err);
Eric Biggersed968042019-01-31 23:51:47 -08001603 return err;
1604 }
Eric Biggers5283a8e2019-04-11 21:57:36 -07001605 if (!err && vec->setauthsize_error) {
Eric Biggers951d1332019-04-11 21:57:37 -07001606 pr_err("alg: aead: %s setauthsize unexpectedly succeeded on test vector %s; expected_error=%d\n",
1607 driver, vec_name, vec->setauthsize_error);
Eric Biggers5283a8e2019-04-11 21:57:36 -07001608 return -EINVAL;
1609 }
1610
1611 if (vec->setkey_error || vec->setauthsize_error)
1612 return 0;
Eric Biggersed968042019-01-31 23:51:47 -08001613
1614 /* The IV must be copied to a buffer, as the algorithm may modify it */
1615 if (WARN_ON(ivsize > MAX_IVLEN))
1616 return -EINVAL;
1617 if (vec->iv)
1618 memcpy(iv, vec->iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001619 else
Eric Biggersed968042019-01-31 23:51:47 -08001620 memset(iv, 0, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001621
Eric Biggersed968042019-01-31 23:51:47 -08001622 /* Build the src/dst scatterlists */
1623 input[0].iov_base = (void *)vec->assoc;
1624 input[0].iov_len = vec->alen;
1625 input[1].iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext;
1626 input[1].iov_len = enc ? vec->plen : vec->clen;
1627 err = build_cipher_test_sglists(tsgls, cfg, alignmask,
1628 vec->alen + (enc ? vec->plen :
1629 vec->clen),
1630 vec->alen + (enc ? vec->clen :
1631 vec->plen),
1632 input, 2);
1633 if (err) {
Eric Biggers951d1332019-04-11 21:57:37 -07001634 pr_err("alg: aead: %s %s: error preparing scatterlists for test vector %s, cfg=\"%s\"\n",
1635 driver, op, vec_name, cfg->name);
Eric Biggersed968042019-01-31 23:51:47 -08001636 return err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001637 }
1638
Eric Biggersed968042019-01-31 23:51:47 -08001639 /* Do the actual encryption or decryption */
1640 testmgr_poison(req->__ctx, crypto_aead_reqsize(tfm));
1641 aead_request_set_callback(req, req_flags, crypto_req_done, &wait);
1642 aead_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr,
1643 enc ? vec->plen : vec->clen, iv);
1644 aead_request_set_ad(req, vec->alen);
Eric Biggers65707372019-03-12 22:12:52 -07001645 if (cfg->nosimd)
1646 crypto_disable_simd_for_test();
1647 err = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
1648 if (cfg->nosimd)
1649 crypto_reenable_simd_for_test();
1650 err = crypto_wait_req(err, &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001651
Eric Biggersa6e5ef92019-01-31 23:51:50 -08001652 /* Check that the algorithm didn't overwrite things it shouldn't have */
1653 if (req->cryptlen != (enc ? vec->plen : vec->clen) ||
1654 req->assoclen != vec->alen ||
1655 req->iv != iv ||
1656 req->src != tsgls->src.sgl_ptr ||
1657 req->dst != tsgls->dst.sgl_ptr ||
1658 crypto_aead_reqtfm(req) != tfm ||
1659 req->base.complete != crypto_req_done ||
1660 req->base.flags != req_flags ||
1661 req->base.data != &wait) {
Eric Biggers951d1332019-04-11 21:57:37 -07001662 pr_err("alg: aead: %s %s corrupted request struct on test vector %s, cfg=\"%s\"\n",
1663 driver, op, vec_name, cfg->name);
Eric Biggersa6e5ef92019-01-31 23:51:50 -08001664 if (req->cryptlen != (enc ? vec->plen : vec->clen))
1665 pr_err("alg: aead: changed 'req->cryptlen'\n");
1666 if (req->assoclen != vec->alen)
1667 pr_err("alg: aead: changed 'req->assoclen'\n");
1668 if (req->iv != iv)
1669 pr_err("alg: aead: changed 'req->iv'\n");
1670 if (req->src != tsgls->src.sgl_ptr)
1671 pr_err("alg: aead: changed 'req->src'\n");
1672 if (req->dst != tsgls->dst.sgl_ptr)
1673 pr_err("alg: aead: changed 'req->dst'\n");
1674 if (crypto_aead_reqtfm(req) != tfm)
1675 pr_err("alg: aead: changed 'req->base.tfm'\n");
1676 if (req->base.complete != crypto_req_done)
1677 pr_err("alg: aead: changed 'req->base.complete'\n");
1678 if (req->base.flags != req_flags)
1679 pr_err("alg: aead: changed 'req->base.flags'\n");
1680 if (req->base.data != &wait)
1681 pr_err("alg: aead: changed 'req->base.data'\n");
1682 return -EINVAL;
1683 }
1684 if (is_test_sglist_corrupted(&tsgls->src)) {
Eric Biggers951d1332019-04-11 21:57:37 -07001685 pr_err("alg: aead: %s %s corrupted src sgl on test vector %s, cfg=\"%s\"\n",
1686 driver, op, vec_name, cfg->name);
Eric Biggersa6e5ef92019-01-31 23:51:50 -08001687 return -EINVAL;
1688 }
1689 if (tsgls->dst.sgl_ptr != tsgls->src.sgl &&
1690 is_test_sglist_corrupted(&tsgls->dst)) {
Eric Biggers951d1332019-04-11 21:57:37 -07001691 pr_err("alg: aead: %s %s corrupted dst sgl on test vector %s, cfg=\"%s\"\n",
1692 driver, op, vec_name, cfg->name);
Eric Biggersa6e5ef92019-01-31 23:51:50 -08001693 return -EINVAL;
1694 }
1695
Eric Biggers5283a8e2019-04-11 21:57:36 -07001696 /* Check for success or failure */
1697 expected_error = vec->novrfy ? -EBADMSG : vec->crypt_error;
1698 if (err) {
1699 if (err == expected_error)
1700 return 0;
Eric Biggers951d1332019-04-11 21:57:37 -07001701 pr_err("alg: aead: %s %s failed on test vector %s; expected_error=%d, actual_error=%d, cfg=\"%s\"\n",
1702 driver, op, vec_name, expected_error, err, cfg->name);
Eric Biggers5283a8e2019-04-11 21:57:36 -07001703 return err;
1704 }
1705 if (expected_error) {
Eric Biggers951d1332019-04-11 21:57:37 -07001706 pr_err("alg: aead: %s %s unexpectedly succeeded on test vector %s; expected_error=%d, cfg=\"%s\"\n",
1707 driver, op, vec_name, expected_error, cfg->name);
Eric Biggers5283a8e2019-04-11 21:57:36 -07001708 return -EINVAL;
1709 }
1710
Eric Biggersed968042019-01-31 23:51:47 -08001711 /* Check for the correct output (ciphertext or plaintext) */
1712 err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext,
1713 enc ? vec->clen : vec->plen,
1714 vec->alen, enc || !cfg->inplace);
1715 if (err == -EOVERFLOW) {
Eric Biggers951d1332019-04-11 21:57:37 -07001716 pr_err("alg: aead: %s %s overran dst buffer on test vector %s, cfg=\"%s\"\n",
1717 driver, op, vec_name, cfg->name);
Eric Biggersed968042019-01-31 23:51:47 -08001718 return err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001719 }
Eric Biggersed968042019-01-31 23:51:47 -08001720 if (err) {
Eric Biggers951d1332019-04-11 21:57:37 -07001721 pr_err("alg: aead: %s %s test failed (wrong result) on test vector %s, cfg=\"%s\"\n",
1722 driver, op, vec_name, cfg->name);
Eric Biggersed968042019-01-31 23:51:47 -08001723 return err;
Jussi Kivilinna58dcf542013-06-13 17:37:50 +03001724 }
1725
1726 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001727}
1728
Eric Biggersed968042019-01-31 23:51:47 -08001729static int test_aead_vec(const char *driver, int enc,
1730 const struct aead_testvec *vec, unsigned int vec_num,
1731 struct aead_request *req,
1732 struct cipher_test_sglists *tsgls)
1733{
Eric Biggers951d1332019-04-11 21:57:37 -07001734 char vec_name[16];
Eric Biggersed968042019-01-31 23:51:47 -08001735 unsigned int i;
1736 int err;
1737
1738 if (enc && vec->novrfy)
1739 return 0;
1740
Eric Biggers951d1332019-04-11 21:57:37 -07001741 sprintf(vec_name, "%u", vec_num);
1742
Eric Biggersed968042019-01-31 23:51:47 -08001743 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
Eric Biggers951d1332019-04-11 21:57:37 -07001744 err = test_aead_vec_cfg(driver, enc, vec, vec_name,
Eric Biggersed968042019-01-31 23:51:47 -08001745 &default_cipher_testvec_configs[i],
1746 req, tsgls);
1747 if (err)
1748 return err;
1749 }
1750
1751#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1752 if (!noextratests) {
1753 struct testvec_config cfg;
1754 char cfgname[TESTVEC_CONFIG_NAMELEN];
1755
1756 for (i = 0; i < fuzz_iterations; i++) {
1757 generate_random_testvec_config(&cfg, cfgname,
1758 sizeof(cfgname));
Eric Biggers951d1332019-04-11 21:57:37 -07001759 err = test_aead_vec_cfg(driver, enc, vec, vec_name,
Eric Biggersed968042019-01-31 23:51:47 -08001760 &cfg, req, tsgls);
1761 if (err)
1762 return err;
1763 }
1764 }
1765#endif
1766 return 0;
1767}
1768
Eric Biggers40153b12019-04-11 21:57:41 -07001769#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1770/*
1771 * Generate an AEAD test vector from the given implementation.
1772 * Assumes the buffers in 'vec' were already allocated.
1773 */
1774static void generate_random_aead_testvec(struct aead_request *req,
1775 struct aead_testvec *vec,
1776 unsigned int maxkeysize,
1777 unsigned int maxdatasize,
1778 char *name, size_t max_namelen)
1779{
1780 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1781 const unsigned int ivsize = crypto_aead_ivsize(tfm);
1782 unsigned int maxauthsize = crypto_aead_alg(tfm)->maxauthsize;
1783 unsigned int authsize;
1784 unsigned int total_len;
1785 int i;
1786 struct scatterlist src[2], dst;
1787 u8 iv[MAX_IVLEN];
1788 DECLARE_CRYPTO_WAIT(wait);
1789
1790 /* Key: length in [0, maxkeysize], but usually choose maxkeysize */
1791 vec->klen = maxkeysize;
1792 if (prandom_u32() % 4 == 0)
1793 vec->klen = prandom_u32() % (maxkeysize + 1);
1794 generate_random_bytes((u8 *)vec->key, vec->klen);
1795 vec->setkey_error = crypto_aead_setkey(tfm, vec->key, vec->klen);
1796
1797 /* IV */
1798 generate_random_bytes((u8 *)vec->iv, ivsize);
1799
1800 /* Tag length: in [0, maxauthsize], but usually choose maxauthsize */
1801 authsize = maxauthsize;
1802 if (prandom_u32() % 4 == 0)
1803 authsize = prandom_u32() % (maxauthsize + 1);
1804 if (WARN_ON(authsize > maxdatasize))
1805 authsize = maxdatasize;
1806 maxdatasize -= authsize;
1807 vec->setauthsize_error = crypto_aead_setauthsize(tfm, authsize);
1808
1809 /* Plaintext and associated data */
1810 total_len = generate_random_length(maxdatasize);
1811 if (prandom_u32() % 4 == 0)
1812 vec->alen = 0;
1813 else
1814 vec->alen = generate_random_length(total_len);
1815 vec->plen = total_len - vec->alen;
1816 generate_random_bytes((u8 *)vec->assoc, vec->alen);
1817 generate_random_bytes((u8 *)vec->ptext, vec->plen);
1818
1819 vec->clen = vec->plen + authsize;
1820
1821 /*
1822 * If the key or authentication tag size couldn't be set, no need to
1823 * continue to encrypt.
1824 */
1825 if (vec->setkey_error || vec->setauthsize_error)
1826 goto done;
1827
1828 /* Ciphertext */
1829 sg_init_table(src, 2);
1830 i = 0;
1831 if (vec->alen)
1832 sg_set_buf(&src[i++], vec->assoc, vec->alen);
1833 if (vec->plen)
1834 sg_set_buf(&src[i++], vec->ptext, vec->plen);
1835 sg_init_one(&dst, vec->ctext, vec->alen + vec->clen);
1836 memcpy(iv, vec->iv, ivsize);
1837 aead_request_set_callback(req, 0, crypto_req_done, &wait);
1838 aead_request_set_crypt(req, src, &dst, vec->plen, iv);
1839 aead_request_set_ad(req, vec->alen);
1840 vec->crypt_error = crypto_wait_req(crypto_aead_encrypt(req), &wait);
1841 if (vec->crypt_error == 0)
1842 memmove((u8 *)vec->ctext, vec->ctext + vec->alen, vec->clen);
1843done:
1844 snprintf(name, max_namelen,
1845 "\"random: alen=%u plen=%u authsize=%u klen=%u\"",
1846 vec->alen, vec->plen, authsize, vec->klen);
1847}
1848
1849/*
1850 * Test the AEAD algorithm represented by @req against the corresponding generic
1851 * implementation, if one is available.
1852 */
1853static int test_aead_vs_generic_impl(const char *driver,
1854 const struct alg_test_desc *test_desc,
1855 struct aead_request *req,
1856 struct cipher_test_sglists *tsgls)
1857{
1858 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1859 const unsigned int ivsize = crypto_aead_ivsize(tfm);
1860 const unsigned int maxauthsize = crypto_aead_alg(tfm)->maxauthsize;
1861 const unsigned int blocksize = crypto_aead_blocksize(tfm);
1862 const unsigned int maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN;
1863 const char *algname = crypto_aead_alg(tfm)->base.cra_name;
1864 const char *generic_driver = test_desc->generic_driver;
1865 char _generic_driver[CRYPTO_MAX_ALG_NAME];
1866 struct crypto_aead *generic_tfm = NULL;
1867 struct aead_request *generic_req = NULL;
1868 unsigned int maxkeysize;
1869 unsigned int i;
1870 struct aead_testvec vec = { 0 };
1871 char vec_name[64];
1872 struct testvec_config cfg;
1873 char cfgname[TESTVEC_CONFIG_NAMELEN];
1874 int err;
1875
1876 if (noextratests)
1877 return 0;
1878
1879 if (!generic_driver) { /* Use default naming convention? */
1880 err = build_generic_driver_name(algname, _generic_driver);
1881 if (err)
1882 return err;
1883 generic_driver = _generic_driver;
1884 }
1885
1886 if (strcmp(generic_driver, driver) == 0) /* Already the generic impl? */
1887 return 0;
1888
1889 generic_tfm = crypto_alloc_aead(generic_driver, 0, 0);
1890 if (IS_ERR(generic_tfm)) {
1891 err = PTR_ERR(generic_tfm);
1892 if (err == -ENOENT) {
1893 pr_warn("alg: aead: skipping comparison tests for %s because %s is unavailable\n",
1894 driver, generic_driver);
1895 return 0;
1896 }
1897 pr_err("alg: aead: error allocating %s (generic impl of %s): %d\n",
1898 generic_driver, algname, err);
1899 return err;
1900 }
1901
1902 generic_req = aead_request_alloc(generic_tfm, GFP_KERNEL);
1903 if (!generic_req) {
1904 err = -ENOMEM;
1905 goto out;
1906 }
1907
1908 /* Check the algorithm properties for consistency. */
1909
1910 if (maxauthsize != crypto_aead_alg(generic_tfm)->maxauthsize) {
1911 pr_err("alg: aead: maxauthsize for %s (%u) doesn't match generic impl (%u)\n",
1912 driver, maxauthsize,
1913 crypto_aead_alg(generic_tfm)->maxauthsize);
1914 err = -EINVAL;
1915 goto out;
1916 }
1917
1918 if (ivsize != crypto_aead_ivsize(generic_tfm)) {
1919 pr_err("alg: aead: ivsize for %s (%u) doesn't match generic impl (%u)\n",
1920 driver, ivsize, crypto_aead_ivsize(generic_tfm));
1921 err = -EINVAL;
1922 goto out;
1923 }
1924
1925 if (blocksize != crypto_aead_blocksize(generic_tfm)) {
1926 pr_err("alg: aead: blocksize for %s (%u) doesn't match generic impl (%u)\n",
1927 driver, blocksize, crypto_aead_blocksize(generic_tfm));
1928 err = -EINVAL;
1929 goto out;
1930 }
1931
1932 /*
1933 * Now generate test vectors using the generic implementation, and test
1934 * the other implementation against them.
1935 */
1936
1937 maxkeysize = 0;
1938 for (i = 0; i < test_desc->suite.aead.count; i++)
1939 maxkeysize = max_t(unsigned int, maxkeysize,
1940 test_desc->suite.aead.vecs[i].klen);
1941
1942 vec.key = kmalloc(maxkeysize, GFP_KERNEL);
1943 vec.iv = kmalloc(ivsize, GFP_KERNEL);
1944 vec.assoc = kmalloc(maxdatasize, GFP_KERNEL);
1945 vec.ptext = kmalloc(maxdatasize, GFP_KERNEL);
1946 vec.ctext = kmalloc(maxdatasize, GFP_KERNEL);
1947 if (!vec.key || !vec.iv || !vec.assoc || !vec.ptext || !vec.ctext) {
1948 err = -ENOMEM;
1949 goto out;
1950 }
1951
1952 for (i = 0; i < fuzz_iterations * 8; i++) {
1953 generate_random_aead_testvec(generic_req, &vec,
1954 maxkeysize, maxdatasize,
1955 vec_name, sizeof(vec_name));
1956 generate_random_testvec_config(&cfg, cfgname, sizeof(cfgname));
1957
1958 err = test_aead_vec_cfg(driver, ENCRYPT, &vec, vec_name, &cfg,
1959 req, tsgls);
1960 if (err)
1961 goto out;
1962 err = test_aead_vec_cfg(driver, DECRYPT, &vec, vec_name, &cfg,
1963 req, tsgls);
1964 if (err)
1965 goto out;
1966 cond_resched();
1967 }
1968 err = 0;
1969out:
1970 kfree(vec.key);
1971 kfree(vec.iv);
1972 kfree(vec.assoc);
1973 kfree(vec.ptext);
1974 kfree(vec.ctext);
1975 crypto_free_aead(generic_tfm);
1976 aead_request_free(generic_req);
1977 return err;
1978}
1979#else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
1980static int test_aead_vs_generic_impl(const char *driver,
1981 const struct alg_test_desc *test_desc,
1982 struct aead_request *req,
1983 struct cipher_test_sglists *tsgls)
1984{
1985 return 0;
1986}
1987#endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
1988
Eric Biggersed968042019-01-31 23:51:47 -08001989static int test_aead(const char *driver, int enc,
1990 const struct aead_test_suite *suite,
1991 struct aead_request *req,
1992 struct cipher_test_sglists *tsgls)
1993{
1994 unsigned int i;
1995 int err;
1996
1997 for (i = 0; i < suite->count; i++) {
1998 err = test_aead_vec(driver, enc, &suite->vecs[i], i, req,
1999 tsgls);
2000 if (err)
2001 return err;
2002 }
2003 return 0;
2004}
2005
2006static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
2007 u32 type, u32 mask)
2008{
2009 const struct aead_test_suite *suite = &desc->suite.aead;
2010 struct crypto_aead *tfm;
2011 struct aead_request *req = NULL;
2012 struct cipher_test_sglists *tsgls = NULL;
2013 int err;
2014
2015 if (suite->count <= 0) {
2016 pr_err("alg: aead: empty test suite for %s\n", driver);
2017 return -EINVAL;
2018 }
2019
2020 tfm = crypto_alloc_aead(driver, type, mask);
2021 if (IS_ERR(tfm)) {
2022 pr_err("alg: aead: failed to allocate transform for %s: %ld\n",
2023 driver, PTR_ERR(tfm));
2024 return PTR_ERR(tfm);
2025 }
2026
2027 req = aead_request_alloc(tfm, GFP_KERNEL);
2028 if (!req) {
2029 pr_err("alg: aead: failed to allocate request for %s\n",
2030 driver);
2031 err = -ENOMEM;
2032 goto out;
2033 }
2034
2035 tsgls = alloc_cipher_test_sglists();
2036 if (!tsgls) {
2037 pr_err("alg: aead: failed to allocate test buffers for %s\n",
2038 driver);
2039 err = -ENOMEM;
2040 goto out;
2041 }
2042
2043 err = test_aead(driver, ENCRYPT, suite, req, tsgls);
2044 if (err)
2045 goto out;
2046
2047 err = test_aead(driver, DECRYPT, suite, req, tsgls);
Eric Biggers40153b12019-04-11 21:57:41 -07002048 if (err)
2049 goto out;
2050
2051 err = test_aead_vs_generic_impl(driver, desc, req, tsgls);
Eric Biggersed968042019-01-31 23:51:47 -08002052out:
2053 free_cipher_test_sglists(tsgls);
2054 aead_request_free(req);
2055 crypto_free_aead(tfm);
2056 return err;
2057}
2058
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002059static int test_cipher(struct crypto_cipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002060 const struct cipher_testvec *template,
2061 unsigned int tcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08002062{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002063 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
2064 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002065 char *q;
2066 const char *e;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002067 const char *input, *result;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002068 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08002069 char *xbuf[XBUFSIZE];
2070 int ret = -ENOMEM;
2071
2072 if (testmgr_alloc_buf(xbuf))
2073 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002074
2075 if (enc == ENCRYPT)
2076 e = "encryption";
2077 else
2078 e = "decryption";
2079
2080 j = 0;
2081 for (i = 0; i < tcount; i++) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002082
Stephan Mueller10faa8c2016-08-25 15:15:01 +02002083 if (fips_enabled && template[i].fips_skip)
2084 continue;
2085
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002086 input = enc ? template[i].ptext : template[i].ctext;
2087 result = enc ? template[i].ctext : template[i].ptext;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002088 j++;
2089
Herbert Xufd57f222009-05-29 16:05:42 +10002090 ret = -EINVAL;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002091 if (WARN_ON(template[i].len > PAGE_SIZE))
Herbert Xufd57f222009-05-29 16:05:42 +10002092 goto out;
2093
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002094 data = xbuf[0];
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002095 memcpy(data, input, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002096
2097 crypto_cipher_clear_flags(tfm, ~0);
2098 if (template[i].wk)
Eric Biggers231baec2019-01-18 22:48:00 -08002099 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002100
2101 ret = crypto_cipher_setkey(tfm, template[i].key,
2102 template[i].klen);
Eric Biggers5283a8e2019-04-11 21:57:36 -07002103 if (ret) {
2104 if (ret == template[i].setkey_error)
2105 continue;
2106 pr_err("alg: cipher: %s setkey failed on test vector %u; expected_error=%d, actual_error=%d, flags=%#x\n",
2107 algo, j, template[i].setkey_error, ret,
2108 crypto_cipher_get_flags(tfm));
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002109 goto out;
Eric Biggers5283a8e2019-04-11 21:57:36 -07002110 }
2111 if (template[i].setkey_error) {
2112 pr_err("alg: cipher: %s setkey unexpectedly succeeded on test vector %u; expected_error=%d\n",
2113 algo, j, template[i].setkey_error);
2114 ret = -EINVAL;
2115 goto out;
2116 }
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002117
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002118 for (k = 0; k < template[i].len;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002119 k += crypto_cipher_blocksize(tfm)) {
2120 if (enc)
2121 crypto_cipher_encrypt_one(tfm, data + k,
2122 data + k);
2123 else
2124 crypto_cipher_decrypt_one(tfm, data + k,
2125 data + k);
2126 }
2127
2128 q = data;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002129 if (memcmp(q, result, template[i].len)) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002130 printk(KERN_ERR "alg: cipher: Test %d failed "
2131 "on %s for %s\n", j, e, algo);
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002132 hexdump(q, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002133 ret = -EINVAL;
2134 goto out;
2135 }
2136 }
2137
2138 ret = 0;
2139
2140out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08002141 testmgr_free_buf(xbuf);
2142out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002143 return ret;
2144}
2145
Eric Biggers4e7babba2019-01-31 23:51:46 -08002146static int test_skcipher_vec_cfg(const char *driver, int enc,
2147 const struct cipher_testvec *vec,
Eric Biggers951d1332019-04-11 21:57:37 -07002148 const char *vec_name,
Eric Biggers4e7babba2019-01-31 23:51:46 -08002149 const struct testvec_config *cfg,
2150 struct skcipher_request *req,
2151 struct cipher_test_sglists *tsgls)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002152{
Eric Biggers4e7babba2019-01-31 23:51:46 -08002153 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
2154 const unsigned int alignmask = crypto_skcipher_alignmask(tfm);
2155 const unsigned int ivsize = crypto_skcipher_ivsize(tfm);
2156 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
2157 const char *op = enc ? "encryption" : "decryption";
2158 DECLARE_CRYPTO_WAIT(wait);
2159 u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN];
2160 u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) +
2161 cfg->iv_offset +
2162 (cfg->iv_offset_relative_to_alignmask ? alignmask : 0);
2163 struct kvec input;
2164 int err;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08002165
Eric Biggers4e7babba2019-01-31 23:51:46 -08002166 /* Set the key */
2167 if (vec->wk)
2168 crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03002169 else
Eric Biggers4e7babba2019-01-31 23:51:46 -08002170 crypto_skcipher_clear_flags(tfm,
2171 CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
2172 err = crypto_skcipher_setkey(tfm, vec->key, vec->klen);
2173 if (err) {
Eric Biggers5283a8e2019-04-11 21:57:36 -07002174 if (err == vec->setkey_error)
Eric Biggers4e7babba2019-01-31 23:51:46 -08002175 return 0;
Eric Biggers951d1332019-04-11 21:57:37 -07002176 pr_err("alg: skcipher: %s setkey failed on test vector %s; expected_error=%d, actual_error=%d, flags=%#x\n",
2177 driver, vec_name, vec->setkey_error, err,
Eric Biggers5283a8e2019-04-11 21:57:36 -07002178 crypto_skcipher_get_flags(tfm));
Eric Biggers4e7babba2019-01-31 23:51:46 -08002179 return err;
2180 }
Eric Biggers5283a8e2019-04-11 21:57:36 -07002181 if (vec->setkey_error) {
Eric Biggers951d1332019-04-11 21:57:37 -07002182 pr_err("alg: skcipher: %s setkey unexpectedly succeeded on test vector %s; expected_error=%d\n",
2183 driver, vec_name, vec->setkey_error);
Eric Biggers4e7babba2019-01-31 23:51:46 -08002184 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08002185 }
2186
Eric Biggers4e7babba2019-01-31 23:51:46 -08002187 /* The IV must be copied to a buffer, as the algorithm may modify it */
2188 if (ivsize) {
2189 if (WARN_ON(ivsize > MAX_IVLEN))
2190 return -EINVAL;
Eric Biggers8efd9722019-02-14 00:03:51 -08002191 if (vec->generates_iv && !enc)
2192 memcpy(iv, vec->iv_out, ivsize);
2193 else if (vec->iv)
Eric Biggers4e7babba2019-01-31 23:51:46 -08002194 memcpy(iv, vec->iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08002195 else
Eric Biggers4e7babba2019-01-31 23:51:46 -08002196 memset(iv, 0, ivsize);
2197 } else {
2198 if (vec->generates_iv) {
Eric Biggers951d1332019-04-11 21:57:37 -07002199 pr_err("alg: skcipher: %s has ivsize=0 but test vector %s generates IV!\n",
2200 driver, vec_name);
Eric Biggers4e7babba2019-01-31 23:51:46 -08002201 return -EINVAL;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03002202 }
Eric Biggers4e7babba2019-01-31 23:51:46 -08002203 iv = NULL;
Herbert Xuda7f0332008-07-31 17:08:25 +08002204 }
2205
Eric Biggers4e7babba2019-01-31 23:51:46 -08002206 /* Build the src/dst scatterlists */
2207 input.iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext;
2208 input.iov_len = vec->len;
2209 err = build_cipher_test_sglists(tsgls, cfg, alignmask,
2210 vec->len, vec->len, &input, 1);
2211 if (err) {
Eric Biggers951d1332019-04-11 21:57:37 -07002212 pr_err("alg: skcipher: %s %s: error preparing scatterlists for test vector %s, cfg=\"%s\"\n",
2213 driver, op, vec_name, cfg->name);
Eric Biggers4e7babba2019-01-31 23:51:46 -08002214 return err;
Herbert Xuda7f0332008-07-31 17:08:25 +08002215 }
2216
Eric Biggers4e7babba2019-01-31 23:51:46 -08002217 /* Do the actual encryption or decryption */
2218 testmgr_poison(req->__ctx, crypto_skcipher_reqsize(tfm));
2219 skcipher_request_set_callback(req, req_flags, crypto_req_done, &wait);
2220 skcipher_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr,
2221 vec->len, iv);
Eric Biggers65707372019-03-12 22:12:52 -07002222 if (cfg->nosimd)
2223 crypto_disable_simd_for_test();
2224 err = enc ? crypto_skcipher_encrypt(req) : crypto_skcipher_decrypt(req);
2225 if (cfg->nosimd)
2226 crypto_reenable_simd_for_test();
2227 err = crypto_wait_req(err, &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08002228
Eric Biggersfa353c92019-01-31 23:51:49 -08002229 /* Check that the algorithm didn't overwrite things it shouldn't have */
2230 if (req->cryptlen != vec->len ||
2231 req->iv != iv ||
2232 req->src != tsgls->src.sgl_ptr ||
2233 req->dst != tsgls->dst.sgl_ptr ||
2234 crypto_skcipher_reqtfm(req) != tfm ||
2235 req->base.complete != crypto_req_done ||
2236 req->base.flags != req_flags ||
2237 req->base.data != &wait) {
Eric Biggers951d1332019-04-11 21:57:37 -07002238 pr_err("alg: skcipher: %s %s corrupted request struct on test vector %s, cfg=\"%s\"\n",
2239 driver, op, vec_name, cfg->name);
Eric Biggersfa353c92019-01-31 23:51:49 -08002240 if (req->cryptlen != vec->len)
2241 pr_err("alg: skcipher: changed 'req->cryptlen'\n");
2242 if (req->iv != iv)
2243 pr_err("alg: skcipher: changed 'req->iv'\n");
2244 if (req->src != tsgls->src.sgl_ptr)
2245 pr_err("alg: skcipher: changed 'req->src'\n");
2246 if (req->dst != tsgls->dst.sgl_ptr)
2247 pr_err("alg: skcipher: changed 'req->dst'\n");
2248 if (crypto_skcipher_reqtfm(req) != tfm)
2249 pr_err("alg: skcipher: changed 'req->base.tfm'\n");
2250 if (req->base.complete != crypto_req_done)
2251 pr_err("alg: skcipher: changed 'req->base.complete'\n");
2252 if (req->base.flags != req_flags)
2253 pr_err("alg: skcipher: changed 'req->base.flags'\n");
2254 if (req->base.data != &wait)
2255 pr_err("alg: skcipher: changed 'req->base.data'\n");
2256 return -EINVAL;
2257 }
2258 if (is_test_sglist_corrupted(&tsgls->src)) {
Eric Biggers951d1332019-04-11 21:57:37 -07002259 pr_err("alg: skcipher: %s %s corrupted src sgl on test vector %s, cfg=\"%s\"\n",
2260 driver, op, vec_name, cfg->name);
Eric Biggersfa353c92019-01-31 23:51:49 -08002261 return -EINVAL;
2262 }
2263 if (tsgls->dst.sgl_ptr != tsgls->src.sgl &&
2264 is_test_sglist_corrupted(&tsgls->dst)) {
Eric Biggers951d1332019-04-11 21:57:37 -07002265 pr_err("alg: skcipher: %s %s corrupted dst sgl on test vector %s, cfg=\"%s\"\n",
2266 driver, op, vec_name, cfg->name);
Eric Biggersfa353c92019-01-31 23:51:49 -08002267 return -EINVAL;
2268 }
2269
Eric Biggers5283a8e2019-04-11 21:57:36 -07002270 /* Check for success or failure */
2271 if (err) {
2272 if (err == vec->crypt_error)
2273 return 0;
Eric Biggers951d1332019-04-11 21:57:37 -07002274 pr_err("alg: skcipher: %s %s failed on test vector %s; expected_error=%d, actual_error=%d, cfg=\"%s\"\n",
2275 driver, op, vec_name, vec->crypt_error, err, cfg->name);
Eric Biggers5283a8e2019-04-11 21:57:36 -07002276 return err;
2277 }
2278 if (vec->crypt_error) {
Eric Biggers951d1332019-04-11 21:57:37 -07002279 pr_err("alg: skcipher: %s %s unexpectedly succeeded on test vector %s; expected_error=%d, cfg=\"%s\"\n",
2280 driver, op, vec_name, vec->crypt_error, cfg->name);
Eric Biggers5283a8e2019-04-11 21:57:36 -07002281 return -EINVAL;
2282 }
2283
Eric Biggers4e7babba2019-01-31 23:51:46 -08002284 /* Check for the correct output (ciphertext or plaintext) */
2285 err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext,
2286 vec->len, 0, true);
2287 if (err == -EOVERFLOW) {
Eric Biggers951d1332019-04-11 21:57:37 -07002288 pr_err("alg: skcipher: %s %s overran dst buffer on test vector %s, cfg=\"%s\"\n",
2289 driver, op, vec_name, cfg->name);
Eric Biggers4e7babba2019-01-31 23:51:46 -08002290 return err;
2291 }
2292 if (err) {
Eric Biggers951d1332019-04-11 21:57:37 -07002293 pr_err("alg: skcipher: %s %s test failed (wrong result) on test vector %s, cfg=\"%s\"\n",
2294 driver, op, vec_name, cfg->name);
Eric Biggers4e7babba2019-01-31 23:51:46 -08002295 return err;
2296 }
Herbert Xuda7f0332008-07-31 17:08:25 +08002297
Eric Biggers4e7babba2019-01-31 23:51:46 -08002298 /* If applicable, check that the algorithm generated the correct IV */
Eric Biggers8efd9722019-02-14 00:03:51 -08002299 if (vec->iv_out && memcmp(iv, vec->iv_out, ivsize) != 0) {
Eric Biggers951d1332019-04-11 21:57:37 -07002300 pr_err("alg: skcipher: %s %s test failed (wrong output IV) on test vector %s, cfg=\"%s\"\n",
2301 driver, op, vec_name, cfg->name);
Eric Biggers4e7babba2019-01-31 23:51:46 -08002302 hexdump(iv, ivsize);
2303 return -EINVAL;
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03002304 }
2305
2306 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03002307}
2308
Eric Biggers4e7babba2019-01-31 23:51:46 -08002309static int test_skcipher_vec(const char *driver, int enc,
2310 const struct cipher_testvec *vec,
2311 unsigned int vec_num,
2312 struct skcipher_request *req,
2313 struct cipher_test_sglists *tsgls)
2314{
Eric Biggers951d1332019-04-11 21:57:37 -07002315 char vec_name[16];
Eric Biggers4e7babba2019-01-31 23:51:46 -08002316 unsigned int i;
2317 int err;
2318
2319 if (fips_enabled && vec->fips_skip)
2320 return 0;
2321
Eric Biggers951d1332019-04-11 21:57:37 -07002322 sprintf(vec_name, "%u", vec_num);
2323
Eric Biggers4e7babba2019-01-31 23:51:46 -08002324 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
Eric Biggers951d1332019-04-11 21:57:37 -07002325 err = test_skcipher_vec_cfg(driver, enc, vec, vec_name,
Eric Biggers4e7babba2019-01-31 23:51:46 -08002326 &default_cipher_testvec_configs[i],
2327 req, tsgls);
2328 if (err)
2329 return err;
2330 }
2331
2332#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
2333 if (!noextratests) {
2334 struct testvec_config cfg;
2335 char cfgname[TESTVEC_CONFIG_NAMELEN];
2336
2337 for (i = 0; i < fuzz_iterations; i++) {
2338 generate_random_testvec_config(&cfg, cfgname,
2339 sizeof(cfgname));
Eric Biggers951d1332019-04-11 21:57:37 -07002340 err = test_skcipher_vec_cfg(driver, enc, vec, vec_name,
Eric Biggers4e7babba2019-01-31 23:51:46 -08002341 &cfg, req, tsgls);
2342 if (err)
2343 return err;
2344 }
2345 }
2346#endif
2347 return 0;
2348}
2349
Eric Biggersd435e102019-04-11 21:57:40 -07002350#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
2351/*
2352 * Generate a symmetric cipher test vector from the given implementation.
2353 * Assumes the buffers in 'vec' were already allocated.
2354 */
2355static void generate_random_cipher_testvec(struct skcipher_request *req,
2356 struct cipher_testvec *vec,
2357 unsigned int maxdatasize,
2358 char *name, size_t max_namelen)
2359{
2360 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
2361 const unsigned int maxkeysize = tfm->keysize;
2362 const unsigned int ivsize = crypto_skcipher_ivsize(tfm);
2363 struct scatterlist src, dst;
2364 u8 iv[MAX_IVLEN];
2365 DECLARE_CRYPTO_WAIT(wait);
2366
2367 /* Key: length in [0, maxkeysize], but usually choose maxkeysize */
2368 vec->klen = maxkeysize;
2369 if (prandom_u32() % 4 == 0)
2370 vec->klen = prandom_u32() % (maxkeysize + 1);
2371 generate_random_bytes((u8 *)vec->key, vec->klen);
2372 vec->setkey_error = crypto_skcipher_setkey(tfm, vec->key, vec->klen);
2373
2374 /* IV */
2375 generate_random_bytes((u8 *)vec->iv, ivsize);
2376
2377 /* Plaintext */
2378 vec->len = generate_random_length(maxdatasize);
2379 generate_random_bytes((u8 *)vec->ptext, vec->len);
2380
2381 /* If the key couldn't be set, no need to continue to encrypt. */
2382 if (vec->setkey_error)
2383 goto done;
2384
2385 /* Ciphertext */
2386 sg_init_one(&src, vec->ptext, vec->len);
2387 sg_init_one(&dst, vec->ctext, vec->len);
2388 memcpy(iv, vec->iv, ivsize);
2389 skcipher_request_set_callback(req, 0, crypto_req_done, &wait);
2390 skcipher_request_set_crypt(req, &src, &dst, vec->len, iv);
2391 vec->crypt_error = crypto_wait_req(crypto_skcipher_encrypt(req), &wait);
2392done:
2393 snprintf(name, max_namelen, "\"random: len=%u klen=%u\"",
2394 vec->len, vec->klen);
2395}
2396
2397/*
2398 * Test the skcipher algorithm represented by @req against the corresponding
2399 * generic implementation, if one is available.
2400 */
2401static int test_skcipher_vs_generic_impl(const char *driver,
2402 const char *generic_driver,
2403 struct skcipher_request *req,
2404 struct cipher_test_sglists *tsgls)
2405{
2406 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
2407 const unsigned int ivsize = crypto_skcipher_ivsize(tfm);
2408 const unsigned int blocksize = crypto_skcipher_blocksize(tfm);
2409 const unsigned int maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN;
2410 const char *algname = crypto_skcipher_alg(tfm)->base.cra_name;
2411 char _generic_driver[CRYPTO_MAX_ALG_NAME];
2412 struct crypto_skcipher *generic_tfm = NULL;
2413 struct skcipher_request *generic_req = NULL;
2414 unsigned int i;
2415 struct cipher_testvec vec = { 0 };
2416 char vec_name[64];
2417 struct testvec_config cfg;
2418 char cfgname[TESTVEC_CONFIG_NAMELEN];
2419 int err;
2420
2421 if (noextratests)
2422 return 0;
2423
2424 /* Keywrap isn't supported here yet as it handles its IV differently. */
2425 if (strncmp(algname, "kw(", 3) == 0)
2426 return 0;
2427
2428 if (!generic_driver) { /* Use default naming convention? */
2429 err = build_generic_driver_name(algname, _generic_driver);
2430 if (err)
2431 return err;
2432 generic_driver = _generic_driver;
2433 }
2434
2435 if (strcmp(generic_driver, driver) == 0) /* Already the generic impl? */
2436 return 0;
2437
2438 generic_tfm = crypto_alloc_skcipher(generic_driver, 0, 0);
2439 if (IS_ERR(generic_tfm)) {
2440 err = PTR_ERR(generic_tfm);
2441 if (err == -ENOENT) {
2442 pr_warn("alg: skcipher: skipping comparison tests for %s because %s is unavailable\n",
2443 driver, generic_driver);
2444 return 0;
2445 }
2446 pr_err("alg: skcipher: error allocating %s (generic impl of %s): %d\n",
2447 generic_driver, algname, err);
2448 return err;
2449 }
2450
2451 generic_req = skcipher_request_alloc(generic_tfm, GFP_KERNEL);
2452 if (!generic_req) {
2453 err = -ENOMEM;
2454 goto out;
2455 }
2456
2457 /* Check the algorithm properties for consistency. */
2458
2459 if (tfm->keysize != generic_tfm->keysize) {
2460 pr_err("alg: skcipher: max keysize for %s (%u) doesn't match generic impl (%u)\n",
2461 driver, tfm->keysize, generic_tfm->keysize);
2462 err = -EINVAL;
2463 goto out;
2464 }
2465
2466 if (ivsize != crypto_skcipher_ivsize(generic_tfm)) {
2467 pr_err("alg: skcipher: ivsize for %s (%u) doesn't match generic impl (%u)\n",
2468 driver, ivsize, crypto_skcipher_ivsize(generic_tfm));
2469 err = -EINVAL;
2470 goto out;
2471 }
2472
2473 if (blocksize != crypto_skcipher_blocksize(generic_tfm)) {
2474 pr_err("alg: skcipher: blocksize for %s (%u) doesn't match generic impl (%u)\n",
2475 driver, blocksize,
2476 crypto_skcipher_blocksize(generic_tfm));
2477 err = -EINVAL;
2478 goto out;
2479 }
2480
2481 /*
2482 * Now generate test vectors using the generic implementation, and test
2483 * the other implementation against them.
2484 */
2485
2486 vec.key = kmalloc(tfm->keysize, GFP_KERNEL);
2487 vec.iv = kmalloc(ivsize, GFP_KERNEL);
2488 vec.ptext = kmalloc(maxdatasize, GFP_KERNEL);
2489 vec.ctext = kmalloc(maxdatasize, GFP_KERNEL);
2490 if (!vec.key || !vec.iv || !vec.ptext || !vec.ctext) {
2491 err = -ENOMEM;
2492 goto out;
2493 }
2494
2495 for (i = 0; i < fuzz_iterations * 8; i++) {
2496 generate_random_cipher_testvec(generic_req, &vec, maxdatasize,
2497 vec_name, sizeof(vec_name));
2498 generate_random_testvec_config(&cfg, cfgname, sizeof(cfgname));
2499
2500 err = test_skcipher_vec_cfg(driver, ENCRYPT, &vec, vec_name,
2501 &cfg, req, tsgls);
2502 if (err)
2503 goto out;
2504 err = test_skcipher_vec_cfg(driver, DECRYPT, &vec, vec_name,
2505 &cfg, req, tsgls);
2506 if (err)
2507 goto out;
2508 cond_resched();
2509 }
2510 err = 0;
2511out:
2512 kfree(vec.key);
2513 kfree(vec.iv);
2514 kfree(vec.ptext);
2515 kfree(vec.ctext);
2516 crypto_free_skcipher(generic_tfm);
2517 skcipher_request_free(generic_req);
2518 return err;
2519}
2520#else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
2521static int test_skcipher_vs_generic_impl(const char *driver,
2522 const char *generic_driver,
2523 struct skcipher_request *req,
2524 struct cipher_test_sglists *tsgls)
2525{
2526 return 0;
2527}
2528#endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
2529
Eric Biggers4e7babba2019-01-31 23:51:46 -08002530static int test_skcipher(const char *driver, int enc,
2531 const struct cipher_test_suite *suite,
2532 struct skcipher_request *req,
2533 struct cipher_test_sglists *tsgls)
2534{
2535 unsigned int i;
2536 int err;
2537
2538 for (i = 0; i < suite->count; i++) {
2539 err = test_skcipher_vec(driver, enc, &suite->vecs[i], i, req,
2540 tsgls);
2541 if (err)
2542 return err;
2543 }
2544 return 0;
2545}
2546
2547static int alg_test_skcipher(const struct alg_test_desc *desc,
2548 const char *driver, u32 type, u32 mask)
2549{
2550 const struct cipher_test_suite *suite = &desc->suite.cipher;
2551 struct crypto_skcipher *tfm;
2552 struct skcipher_request *req = NULL;
2553 struct cipher_test_sglists *tsgls = NULL;
2554 int err;
2555
2556 if (suite->count <= 0) {
2557 pr_err("alg: skcipher: empty test suite for %s\n", driver);
2558 return -EINVAL;
2559 }
2560
2561 tfm = crypto_alloc_skcipher(driver, type, mask);
2562 if (IS_ERR(tfm)) {
2563 pr_err("alg: skcipher: failed to allocate transform for %s: %ld\n",
2564 driver, PTR_ERR(tfm));
2565 return PTR_ERR(tfm);
2566 }
2567
2568 req = skcipher_request_alloc(tfm, GFP_KERNEL);
2569 if (!req) {
2570 pr_err("alg: skcipher: failed to allocate request for %s\n",
2571 driver);
2572 err = -ENOMEM;
2573 goto out;
2574 }
2575
2576 tsgls = alloc_cipher_test_sglists();
2577 if (!tsgls) {
2578 pr_err("alg: skcipher: failed to allocate test buffers for %s\n",
2579 driver);
2580 err = -ENOMEM;
2581 goto out;
2582 }
2583
2584 err = test_skcipher(driver, ENCRYPT, suite, req, tsgls);
2585 if (err)
2586 goto out;
2587
2588 err = test_skcipher(driver, DECRYPT, suite, req, tsgls);
Eric Biggersd435e102019-04-11 21:57:40 -07002589 if (err)
2590 goto out;
2591
2592 err = test_skcipher_vs_generic_impl(driver, desc->generic_driver, req,
2593 tsgls);
Eric Biggers4e7babba2019-01-31 23:51:46 -08002594out:
2595 free_cipher_test_sglists(tsgls);
2596 skcipher_request_free(req);
2597 crypto_free_skcipher(tfm);
2598 return err;
2599}
2600
Eric Biggersb13b1e02017-02-24 15:46:59 -08002601static int test_comp(struct crypto_comp *tfm,
2602 const struct comp_testvec *ctemplate,
2603 const struct comp_testvec *dtemplate,
2604 int ctcount, int dtcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08002605{
2606 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
Mahipal Challa33607382018-04-11 20:28:32 +02002607 char *output, *decomp_output;
Herbert Xuda7f0332008-07-31 17:08:25 +08002608 unsigned int i;
Herbert Xuda7f0332008-07-31 17:08:25 +08002609 int ret;
2610
Mahipal Challa33607382018-04-11 20:28:32 +02002611 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
2612 if (!output)
2613 return -ENOMEM;
2614
2615 decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
2616 if (!decomp_output) {
2617 kfree(output);
2618 return -ENOMEM;
2619 }
2620
Herbert Xuda7f0332008-07-31 17:08:25 +08002621 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08002622 int ilen;
2623 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08002624
Michael Schupikov22a81182018-10-07 13:58:10 +02002625 memset(output, 0, COMP_BUF_SIZE);
2626 memset(decomp_output, 0, COMP_BUF_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +08002627
2628 ilen = ctemplate[i].inlen;
2629 ret = crypto_comp_compress(tfm, ctemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02002630 ilen, output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08002631 if (ret) {
2632 printk(KERN_ERR "alg: comp: compression failed "
2633 "on test %d for %s: ret=%d\n", i + 1, algo,
2634 -ret);
2635 goto out;
2636 }
2637
Mahipal Challa33607382018-04-11 20:28:32 +02002638 ilen = dlen;
2639 dlen = COMP_BUF_SIZE;
2640 ret = crypto_comp_decompress(tfm, output,
2641 ilen, decomp_output, &dlen);
2642 if (ret) {
2643 pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n",
2644 i + 1, algo, -ret);
2645 goto out;
2646 }
2647
2648 if (dlen != ctemplate[i].inlen) {
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08002649 printk(KERN_ERR "alg: comp: Compression test %d "
2650 "failed for %s: output len = %d\n", i + 1, algo,
2651 dlen);
2652 ret = -EINVAL;
2653 goto out;
2654 }
2655
Mahipal Challa33607382018-04-11 20:28:32 +02002656 if (memcmp(decomp_output, ctemplate[i].input,
2657 ctemplate[i].inlen)) {
2658 pr_err("alg: comp: compression failed: output differs: on test %d for %s\n",
2659 i + 1, algo);
2660 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08002661 ret = -EINVAL;
2662 goto out;
2663 }
2664 }
2665
2666 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08002667 int ilen;
2668 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08002669
Michael Schupikov22a81182018-10-07 13:58:10 +02002670 memset(decomp_output, 0, COMP_BUF_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +08002671
2672 ilen = dtemplate[i].inlen;
2673 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02002674 ilen, decomp_output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08002675 if (ret) {
2676 printk(KERN_ERR "alg: comp: decompression failed "
2677 "on test %d for %s: ret=%d\n", i + 1, algo,
2678 -ret);
2679 goto out;
2680 }
2681
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08002682 if (dlen != dtemplate[i].outlen) {
2683 printk(KERN_ERR "alg: comp: Decompression test %d "
2684 "failed for %s: output len = %d\n", i + 1, algo,
2685 dlen);
2686 ret = -EINVAL;
2687 goto out;
2688 }
2689
Mahipal Challa33607382018-04-11 20:28:32 +02002690 if (memcmp(decomp_output, dtemplate[i].output, dlen)) {
Herbert Xuda7f0332008-07-31 17:08:25 +08002691 printk(KERN_ERR "alg: comp: Decompression test %d "
2692 "failed for %s\n", i + 1, algo);
Mahipal Challa33607382018-04-11 20:28:32 +02002693 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08002694 ret = -EINVAL;
2695 goto out;
2696 }
2697 }
2698
2699 ret = 0;
2700
2701out:
Mahipal Challa33607382018-04-11 20:28:32 +02002702 kfree(decomp_output);
2703 kfree(output);
Herbert Xuda7f0332008-07-31 17:08:25 +08002704 return ret;
2705}
2706
Eric Biggersb13b1e02017-02-24 15:46:59 -08002707static int test_acomp(struct crypto_acomp *tfm,
Mahipal Challa33607382018-04-11 20:28:32 +02002708 const struct comp_testvec *ctemplate,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002709 const struct comp_testvec *dtemplate,
2710 int ctcount, int dtcount)
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002711{
2712 const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
2713 unsigned int i;
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002714 char *output, *decomp_out;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002715 int ret;
2716 struct scatterlist src, dst;
2717 struct acomp_req *req;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002718 struct crypto_wait wait;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002719
Eric Biggerseb095592016-11-23 10:24:35 -08002720 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
2721 if (!output)
2722 return -ENOMEM;
2723
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002724 decomp_out = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
2725 if (!decomp_out) {
2726 kfree(output);
2727 return -ENOMEM;
2728 }
2729
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002730 for (i = 0; i < ctcount; i++) {
2731 unsigned int dlen = COMP_BUF_SIZE;
2732 int ilen = ctemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08002733 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002734
Eric Biggersd2110222016-12-30 14:12:00 -06002735 input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08002736 if (!input_vec) {
2737 ret = -ENOMEM;
2738 goto out;
2739 }
2740
Eric Biggerseb095592016-11-23 10:24:35 -08002741 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002742 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08002743 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002744 sg_init_one(&dst, output, dlen);
2745
2746 req = acomp_request_alloc(tfm);
2747 if (!req) {
2748 pr_err("alg: acomp: request alloc failed for %s\n",
2749 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08002750 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002751 ret = -ENOMEM;
2752 goto out;
2753 }
2754
2755 acomp_request_set_params(req, &src, &dst, ilen, dlen);
2756 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002757 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002758
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002759 ret = crypto_wait_req(crypto_acomp_compress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002760 if (ret) {
2761 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
2762 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08002763 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002764 acomp_request_free(req);
2765 goto out;
2766 }
2767
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002768 ilen = req->dlen;
2769 dlen = COMP_BUF_SIZE;
2770 sg_init_one(&src, output, ilen);
2771 sg_init_one(&dst, decomp_out, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002772 crypto_init_wait(&wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002773 acomp_request_set_params(req, &src, &dst, ilen, dlen);
2774
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002775 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002776 if (ret) {
2777 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
2778 i + 1, algo, -ret);
2779 kfree(input_vec);
2780 acomp_request_free(req);
2781 goto out;
2782 }
2783
2784 if (req->dlen != ctemplate[i].inlen) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002785 pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
2786 i + 1, algo, req->dlen);
2787 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002788 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002789 acomp_request_free(req);
2790 goto out;
2791 }
2792
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002793 if (memcmp(input_vec, decomp_out, req->dlen)) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002794 pr_err("alg: acomp: Compression test %d failed for %s\n",
2795 i + 1, algo);
2796 hexdump(output, req->dlen);
2797 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002798 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002799 acomp_request_free(req);
2800 goto out;
2801 }
2802
Laura Abbott02608e02016-12-21 12:32:54 -08002803 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002804 acomp_request_free(req);
2805 }
2806
2807 for (i = 0; i < dtcount; i++) {
2808 unsigned int dlen = COMP_BUF_SIZE;
2809 int ilen = dtemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08002810 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002811
Eric Biggersd2110222016-12-30 14:12:00 -06002812 input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08002813 if (!input_vec) {
2814 ret = -ENOMEM;
2815 goto out;
2816 }
2817
Eric Biggerseb095592016-11-23 10:24:35 -08002818 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002819 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08002820 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002821 sg_init_one(&dst, output, dlen);
2822
2823 req = acomp_request_alloc(tfm);
2824 if (!req) {
2825 pr_err("alg: acomp: request alloc failed for %s\n",
2826 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08002827 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002828 ret = -ENOMEM;
2829 goto out;
2830 }
2831
2832 acomp_request_set_params(req, &src, &dst, ilen, dlen);
2833 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002834 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002835
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002836 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002837 if (ret) {
2838 pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
2839 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08002840 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002841 acomp_request_free(req);
2842 goto out;
2843 }
2844
2845 if (req->dlen != dtemplate[i].outlen) {
2846 pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
2847 i + 1, algo, req->dlen);
2848 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002849 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002850 acomp_request_free(req);
2851 goto out;
2852 }
2853
2854 if (memcmp(output, dtemplate[i].output, req->dlen)) {
2855 pr_err("alg: acomp: Decompression test %d failed for %s\n",
2856 i + 1, algo);
2857 hexdump(output, req->dlen);
2858 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002859 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002860 acomp_request_free(req);
2861 goto out;
2862 }
2863
Laura Abbott02608e02016-12-21 12:32:54 -08002864 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002865 acomp_request_free(req);
2866 }
2867
2868 ret = 0;
2869
2870out:
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002871 kfree(decomp_out);
Eric Biggerseb095592016-11-23 10:24:35 -08002872 kfree(output);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002873 return ret;
2874}
2875
Eric Biggersb13b1e02017-02-24 15:46:59 -08002876static int test_cprng(struct crypto_rng *tfm,
2877 const struct cprng_testvec *template,
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002878 unsigned int tcount)
2879{
2880 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08002881 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002882 u8 *seed;
2883 char result[32];
2884
2885 seedsize = crypto_rng_seedsize(tfm);
2886
2887 seed = kmalloc(seedsize, GFP_KERNEL);
2888 if (!seed) {
2889 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
2890 "for %s\n", algo);
2891 return -ENOMEM;
2892 }
2893
2894 for (i = 0; i < tcount; i++) {
2895 memset(result, 0, 32);
2896
2897 memcpy(seed, template[i].v, template[i].vlen);
2898 memcpy(seed + template[i].vlen, template[i].key,
2899 template[i].klen);
2900 memcpy(seed + template[i].vlen + template[i].klen,
2901 template[i].dt, template[i].dtlen);
2902
2903 err = crypto_rng_reset(tfm, seed, seedsize);
2904 if (err) {
2905 printk(KERN_ERR "alg: cprng: Failed to reset rng "
2906 "for %s\n", algo);
2907 goto out;
2908 }
2909
2910 for (j = 0; j < template[i].loops; j++) {
2911 err = crypto_rng_get_bytes(tfm, result,
2912 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01002913 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002914 printk(KERN_ERR "alg: cprng: Failed to obtain "
2915 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01002916 "%s (requested %d)\n", algo,
2917 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002918 goto out;
2919 }
2920 }
2921
2922 err = memcmp(result, template[i].result,
2923 template[i].rlen);
2924 if (err) {
2925 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
2926 i, algo);
2927 hexdump(result, template[i].rlen);
2928 err = -EINVAL;
2929 goto out;
2930 }
2931 }
2932
2933out:
2934 kfree(seed);
2935 return err;
2936}
2937
Herbert Xuda7f0332008-07-31 17:08:25 +08002938static int alg_test_cipher(const struct alg_test_desc *desc,
2939 const char *driver, u32 type, u32 mask)
2940{
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002941 const struct cipher_test_suite *suite = &desc->suite.cipher;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002942 struct crypto_cipher *tfm;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002943 int err;
Herbert Xuda7f0332008-07-31 17:08:25 +08002944
Herbert Xueed93e02016-11-22 20:08:31 +08002945 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08002946 if (IS_ERR(tfm)) {
2947 printk(KERN_ERR "alg: cipher: Failed to load transform for "
2948 "%s: %ld\n", driver, PTR_ERR(tfm));
2949 return PTR_ERR(tfm);
2950 }
2951
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002952 err = test_cipher(tfm, ENCRYPT, suite->vecs, suite->count);
2953 if (!err)
2954 err = test_cipher(tfm, DECRYPT, suite->vecs, suite->count);
Herbert Xuda7f0332008-07-31 17:08:25 +08002955
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002956 crypto_free_cipher(tfm);
2957 return err;
2958}
2959
Herbert Xuda7f0332008-07-31 17:08:25 +08002960static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
2961 u32 type, u32 mask)
2962{
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002963 struct crypto_comp *comp;
2964 struct crypto_acomp *acomp;
Herbert Xuda7f0332008-07-31 17:08:25 +08002965 int err;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002966 u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
Herbert Xuda7f0332008-07-31 17:08:25 +08002967
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002968 if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
2969 acomp = crypto_alloc_acomp(driver, type, mask);
2970 if (IS_ERR(acomp)) {
2971 pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
2972 driver, PTR_ERR(acomp));
2973 return PTR_ERR(acomp);
2974 }
2975 err = test_acomp(acomp, desc->suite.comp.comp.vecs,
2976 desc->suite.comp.decomp.vecs,
2977 desc->suite.comp.comp.count,
2978 desc->suite.comp.decomp.count);
2979 crypto_free_acomp(acomp);
2980 } else {
2981 comp = crypto_alloc_comp(driver, type, mask);
2982 if (IS_ERR(comp)) {
2983 pr_err("alg: comp: Failed to load transform for %s: %ld\n",
2984 driver, PTR_ERR(comp));
2985 return PTR_ERR(comp);
2986 }
2987
2988 err = test_comp(comp, desc->suite.comp.comp.vecs,
2989 desc->suite.comp.decomp.vecs,
2990 desc->suite.comp.comp.count,
2991 desc->suite.comp.decomp.count);
2992
2993 crypto_free_comp(comp);
Herbert Xuda7f0332008-07-31 17:08:25 +08002994 }
Herbert Xuda7f0332008-07-31 17:08:25 +08002995 return err;
2996}
2997
Herbert Xu8e3ee852008-11-07 14:58:52 +08002998static int alg_test_crc32c(const struct alg_test_desc *desc,
2999 const char *driver, u32 type, u32 mask)
3000{
3001 struct crypto_shash *tfm;
Eric Biggerscb9dde82019-01-10 12:17:55 -08003002 __le32 val;
Herbert Xu8e3ee852008-11-07 14:58:52 +08003003 int err;
3004
3005 err = alg_test_hash(desc, driver, type, mask);
3006 if (err)
Eric Biggerseb5e6732019-01-23 20:57:35 -08003007 return err;
Herbert Xu8e3ee852008-11-07 14:58:52 +08003008
Herbert Xueed93e02016-11-22 20:08:31 +08003009 tfm = crypto_alloc_shash(driver, type, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08003010 if (IS_ERR(tfm)) {
Eric Biggerseb5e6732019-01-23 20:57:35 -08003011 if (PTR_ERR(tfm) == -ENOENT) {
3012 /*
3013 * This crc32c implementation is only available through
3014 * ahash API, not the shash API, so the remaining part
3015 * of the test is not applicable to it.
3016 */
3017 return 0;
3018 }
Herbert Xu8e3ee852008-11-07 14:58:52 +08003019 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
3020 "%ld\n", driver, PTR_ERR(tfm));
Eric Biggerseb5e6732019-01-23 20:57:35 -08003021 return PTR_ERR(tfm);
Herbert Xu8e3ee852008-11-07 14:58:52 +08003022 }
3023
3024 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02003025 SHASH_DESC_ON_STACK(shash, tfm);
3026 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08003027
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02003028 shash->tfm = tfm;
Herbert Xu8e3ee852008-11-07 14:58:52 +08003029
Eric Biggerscb9dde82019-01-10 12:17:55 -08003030 *ctx = 420553207;
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02003031 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08003032 if (err) {
3033 printk(KERN_ERR "alg: crc32c: Operation failed for "
3034 "%s: %d\n", driver, err);
3035 break;
3036 }
3037
Eric Biggerscb9dde82019-01-10 12:17:55 -08003038 if (val != cpu_to_le32(~420553207)) {
3039 pr_err("alg: crc32c: Test failed for %s: %u\n",
3040 driver, le32_to_cpu(val));
Herbert Xu8e3ee852008-11-07 14:58:52 +08003041 err = -EINVAL;
3042 }
3043 } while (0);
3044
3045 crypto_free_shash(tfm);
3046
Herbert Xu8e3ee852008-11-07 14:58:52 +08003047 return err;
3048}
3049
Jarod Wilson7647d6c2009-05-04 19:44:50 +08003050static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
3051 u32 type, u32 mask)
3052{
3053 struct crypto_rng *rng;
3054 int err;
3055
Herbert Xueed93e02016-11-22 20:08:31 +08003056 rng = crypto_alloc_rng(driver, type, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08003057 if (IS_ERR(rng)) {
3058 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
3059 "%ld\n", driver, PTR_ERR(rng));
3060 return PTR_ERR(rng);
3061 }
3062
3063 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
3064
3065 crypto_free_rng(rng);
3066
3067 return err;
3068}
3069
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003070
Eric Biggersb13b1e02017-02-24 15:46:59 -08003071static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003072 const char *driver, u32 type, u32 mask)
3073{
3074 int ret = -EAGAIN;
3075 struct crypto_rng *drng;
3076 struct drbg_test_data test_data;
3077 struct drbg_string addtl, pers, testentropy;
3078 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
3079
3080 if (!buf)
3081 return -ENOMEM;
3082
Herbert Xueed93e02016-11-22 20:08:31 +08003083 drng = crypto_alloc_rng(driver, type, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003084 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04003085 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003086 "%s\n", driver);
3087 kzfree(buf);
3088 return -ENOMEM;
3089 }
3090
3091 test_data.testentropy = &testentropy;
3092 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
3093 drbg_string_fill(&pers, test->pers, test->perslen);
3094 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
3095 if (ret) {
3096 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
3097 goto outbuf;
3098 }
3099
3100 drbg_string_fill(&addtl, test->addtla, test->addtllen);
3101 if (pr) {
3102 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
3103 ret = crypto_drbg_get_bytes_addtl_test(drng,
3104 buf, test->expectedlen, &addtl, &test_data);
3105 } else {
3106 ret = crypto_drbg_get_bytes_addtl(drng,
3107 buf, test->expectedlen, &addtl);
3108 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01003109 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04003110 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003111 "driver %s\n", driver);
3112 goto outbuf;
3113 }
3114
3115 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
3116 if (pr) {
3117 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
3118 ret = crypto_drbg_get_bytes_addtl_test(drng,
3119 buf, test->expectedlen, &addtl, &test_data);
3120 } else {
3121 ret = crypto_drbg_get_bytes_addtl(drng,
3122 buf, test->expectedlen, &addtl);
3123 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01003124 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04003125 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003126 "driver %s\n", driver);
3127 goto outbuf;
3128 }
3129
3130 ret = memcmp(test->expected, buf, test->expectedlen);
3131
3132outbuf:
3133 crypto_free_rng(drng);
3134 kzfree(buf);
3135 return ret;
3136}
3137
3138
3139static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
3140 u32 type, u32 mask)
3141{
3142 int err = 0;
3143 int pr = 0;
3144 int i = 0;
Eric Biggersb13b1e02017-02-24 15:46:59 -08003145 const struct drbg_testvec *template = desc->suite.drbg.vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003146 unsigned int tcount = desc->suite.drbg.count;
3147
3148 if (0 == memcmp(driver, "drbg_pr_", 8))
3149 pr = 1;
3150
3151 for (i = 0; i < tcount; i++) {
3152 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
3153 if (err) {
3154 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
3155 i, driver);
3156 err = -EINVAL;
3157 break;
3158 }
3159 }
3160 return err;
3161
3162}
3163
Eric Biggersb13b1e02017-02-24 15:46:59 -08003164static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003165 const char *alg)
3166{
3167 struct kpp_request *req;
3168 void *input_buf = NULL;
3169 void *output_buf = NULL;
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03003170 void *a_public = NULL;
3171 void *a_ss = NULL;
3172 void *shared_secret = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01003173 struct crypto_wait wait;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003174 unsigned int out_len_max;
3175 int err = -ENOMEM;
3176 struct scatterlist src, dst;
3177
3178 req = kpp_request_alloc(tfm, GFP_KERNEL);
3179 if (!req)
3180 return err;
3181
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01003182 crypto_init_wait(&wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003183
3184 err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
3185 if (err < 0)
3186 goto free_req;
3187
3188 out_len_max = crypto_kpp_maxsize(tfm);
3189 output_buf = kzalloc(out_len_max, GFP_KERNEL);
3190 if (!output_buf) {
3191 err = -ENOMEM;
3192 goto free_req;
3193 }
3194
3195 /* Use appropriate parameter as base */
3196 kpp_request_set_input(req, NULL, 0);
3197 sg_init_one(&dst, output_buf, out_len_max);
3198 kpp_request_set_output(req, &dst, out_len_max);
3199 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01003200 crypto_req_done, &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003201
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03003202 /* Compute party A's public key */
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01003203 err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003204 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03003205 pr_err("alg: %s: Party A: generate public key test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003206 alg, err);
3207 goto free_output;
3208 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03003209
3210 if (vec->genkey) {
3211 /* Save party A's public key */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05003212 a_public = kmemdup(sg_virt(req->dst), out_len_max, GFP_KERNEL);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03003213 if (!a_public) {
3214 err = -ENOMEM;
3215 goto free_output;
3216 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03003217 } else {
3218 /* Verify calculated public key */
3219 if (memcmp(vec->expected_a_public, sg_virt(req->dst),
3220 vec->expected_a_public_size)) {
3221 pr_err("alg: %s: Party A: generate public key test failed. Invalid output\n",
3222 alg);
3223 err = -EINVAL;
3224 goto free_output;
3225 }
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003226 }
3227
3228 /* Calculate shared secret key by using counter part (b) public key. */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05003229 input_buf = kmemdup(vec->b_public, vec->b_public_size, GFP_KERNEL);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003230 if (!input_buf) {
3231 err = -ENOMEM;
3232 goto free_output;
3233 }
3234
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003235 sg_init_one(&src, input_buf, vec->b_public_size);
3236 sg_init_one(&dst, output_buf, out_len_max);
3237 kpp_request_set_input(req, &src, vec->b_public_size);
3238 kpp_request_set_output(req, &dst, out_len_max);
3239 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01003240 crypto_req_done, &wait);
3241 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003242 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03003243 pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003244 alg, err);
3245 goto free_all;
3246 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03003247
3248 if (vec->genkey) {
3249 /* Save the shared secret obtained by party A */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05003250 a_ss = kmemdup(sg_virt(req->dst), vec->expected_ss_size, GFP_KERNEL);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03003251 if (!a_ss) {
3252 err = -ENOMEM;
3253 goto free_all;
3254 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03003255
3256 /*
3257 * Calculate party B's shared secret by using party A's
3258 * public key.
3259 */
3260 err = crypto_kpp_set_secret(tfm, vec->b_secret,
3261 vec->b_secret_size);
3262 if (err < 0)
3263 goto free_all;
3264
3265 sg_init_one(&src, a_public, vec->expected_a_public_size);
3266 sg_init_one(&dst, output_buf, out_len_max);
3267 kpp_request_set_input(req, &src, vec->expected_a_public_size);
3268 kpp_request_set_output(req, &dst, out_len_max);
3269 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01003270 crypto_req_done, &wait);
3271 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req),
3272 &wait);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03003273 if (err) {
3274 pr_err("alg: %s: Party B: compute shared secret failed. err %d\n",
3275 alg, err);
3276 goto free_all;
3277 }
3278
3279 shared_secret = a_ss;
3280 } else {
3281 shared_secret = (void *)vec->expected_ss;
3282 }
3283
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003284 /*
3285 * verify shared secret from which the user will derive
3286 * secret key by executing whatever hash it has chosen
3287 */
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03003288 if (memcmp(shared_secret, sg_virt(req->dst),
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003289 vec->expected_ss_size)) {
3290 pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
3291 alg);
3292 err = -EINVAL;
3293 }
3294
3295free_all:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03003296 kfree(a_ss);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003297 kfree(input_buf);
3298free_output:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03003299 kfree(a_public);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003300 kfree(output_buf);
3301free_req:
3302 kpp_request_free(req);
3303 return err;
3304}
3305
3306static int test_kpp(struct crypto_kpp *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08003307 const struct kpp_testvec *vecs, unsigned int tcount)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003308{
3309 int ret, i;
3310
3311 for (i = 0; i < tcount; i++) {
3312 ret = do_test_kpp(tfm, vecs++, alg);
3313 if (ret) {
3314 pr_err("alg: %s: test failed on vector %d, err=%d\n",
3315 alg, i + 1, ret);
3316 return ret;
3317 }
3318 }
3319 return 0;
3320}
3321
3322static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
3323 u32 type, u32 mask)
3324{
3325 struct crypto_kpp *tfm;
3326 int err = 0;
3327
Herbert Xueed93e02016-11-22 20:08:31 +08003328 tfm = crypto_alloc_kpp(driver, type, mask);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003329 if (IS_ERR(tfm)) {
3330 pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
3331 driver, PTR_ERR(tfm));
3332 return PTR_ERR(tfm);
3333 }
3334 if (desc->suite.kpp.vecs)
3335 err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
3336 desc->suite.kpp.count);
3337
3338 crypto_free_kpp(tfm);
3339 return err;
3340}
3341
Vitaly Chikunovf1774cb2019-04-11 18:51:17 +03003342static u8 *test_pack_u32(u8 *dst, u32 val)
3343{
3344 memcpy(dst, &val, sizeof(val));
3345 return dst + sizeof(val);
3346}
3347
Herbert Xu50d2b6432016-06-29 19:32:20 +08003348static int test_akcipher_one(struct crypto_akcipher *tfm,
Eric Biggersb13b1e02017-02-24 15:46:59 -08003349 const struct akcipher_testvec *vecs)
Tadeusz Struk946cc462015-06-16 10:31:06 -07003350{
Herbert Xudf27b262016-05-05 16:42:49 +08003351 char *xbuf[XBUFSIZE];
Tadeusz Struk946cc462015-06-16 10:31:06 -07003352 struct akcipher_request *req;
3353 void *outbuf_enc = NULL;
3354 void *outbuf_dec = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01003355 struct crypto_wait wait;
Tadeusz Struk946cc462015-06-16 10:31:06 -07003356 unsigned int out_len_max, out_len = 0;
3357 int err = -ENOMEM;
Vitaly Chikunovc7381b02019-04-11 18:51:15 +03003358 struct scatterlist src, dst, src_tab[3];
Vitaly Chikunov0507de92019-01-07 20:54:27 +03003359 const char *m, *c;
3360 unsigned int m_size, c_size;
3361 const char *op;
Vitaly Chikunovf1774cb2019-04-11 18:51:17 +03003362 u8 *key, *ptr;
Tadeusz Struk946cc462015-06-16 10:31:06 -07003363
Herbert Xudf27b262016-05-05 16:42:49 +08003364 if (testmgr_alloc_buf(xbuf))
3365 return err;
3366
Tadeusz Struk946cc462015-06-16 10:31:06 -07003367 req = akcipher_request_alloc(tfm, GFP_KERNEL);
3368 if (!req)
Herbert Xudf27b262016-05-05 16:42:49 +08003369 goto free_xbuf;
Tadeusz Struk946cc462015-06-16 10:31:06 -07003370
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01003371 crypto_init_wait(&wait);
Tadeusz Struk22287b02015-10-08 09:26:55 -07003372
Vitaly Chikunovf1774cb2019-04-11 18:51:17 +03003373 key = kmalloc(vecs->key_len + sizeof(u32) * 2 + vecs->param_len,
3374 GFP_KERNEL);
3375 if (!key)
3376 goto free_xbuf;
3377 memcpy(key, vecs->key, vecs->key_len);
3378 ptr = key + vecs->key_len;
3379 ptr = test_pack_u32(ptr, vecs->algo);
3380 ptr = test_pack_u32(ptr, vecs->param_len);
3381 memcpy(ptr, vecs->params, vecs->param_len);
3382
Tadeusz Struk22287b02015-10-08 09:26:55 -07003383 if (vecs->public_key_vec)
Vitaly Chikunovf1774cb2019-04-11 18:51:17 +03003384 err = crypto_akcipher_set_pub_key(tfm, key, vecs->key_len);
Tadeusz Struk22287b02015-10-08 09:26:55 -07003385 else
Vitaly Chikunovf1774cb2019-04-11 18:51:17 +03003386 err = crypto_akcipher_set_priv_key(tfm, key, vecs->key_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07003387 if (err)
3388 goto free_req;
3389
Vitaly Chikunov0507de92019-01-07 20:54:27 +03003390 /*
3391 * First run test which do not require a private key, such as
3392 * encrypt or verify.
3393 */
Vitaly Chikunovc7381b02019-04-11 18:51:15 +03003394 err = -ENOMEM;
3395 out_len_max = crypto_akcipher_maxsize(tfm);
Tadeusz Struk946cc462015-06-16 10:31:06 -07003396 outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
3397 if (!outbuf_enc)
3398 goto free_req;
3399
Vitaly Chikunov0507de92019-01-07 20:54:27 +03003400 if (!vecs->siggen_sigver_test) {
3401 m = vecs->m;
3402 m_size = vecs->m_size;
3403 c = vecs->c;
3404 c_size = vecs->c_size;
3405 op = "encrypt";
3406 } else {
3407 /* Swap args so we could keep plaintext (digest)
3408 * in vecs->m, and cooked signature in vecs->c.
3409 */
3410 m = vecs->c; /* signature */
3411 m_size = vecs->c_size;
3412 c = vecs->m; /* digest */
3413 c_size = vecs->m_size;
3414 op = "verify";
3415 }
Herbert Xudf27b262016-05-05 16:42:49 +08003416
Vitaly Chikunov0507de92019-01-07 20:54:27 +03003417 if (WARN_ON(m_size > PAGE_SIZE))
3418 goto free_all;
3419 memcpy(xbuf[0], m, m_size);
Herbert Xudf27b262016-05-05 16:42:49 +08003420
Vitaly Chikunovc7381b02019-04-11 18:51:15 +03003421 sg_init_table(src_tab, 3);
Herbert Xudf27b262016-05-05 16:42:49 +08003422 sg_set_buf(&src_tab[0], xbuf[0], 8);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03003423 sg_set_buf(&src_tab[1], xbuf[0] + 8, m_size - 8);
Vitaly Chikunovc7381b02019-04-11 18:51:15 +03003424 if (vecs->siggen_sigver_test) {
3425 if (WARN_ON(c_size > PAGE_SIZE))
3426 goto free_all;
3427 memcpy(xbuf[1], c, c_size);
3428 sg_set_buf(&src_tab[2], xbuf[1], c_size);
3429 akcipher_request_set_crypt(req, src_tab, NULL, m_size, c_size);
3430 } else {
3431 sg_init_one(&dst, outbuf_enc, out_len_max);
3432 akcipher_request_set_crypt(req, src_tab, &dst, m_size,
3433 out_len_max);
3434 }
Tadeusz Struk946cc462015-06-16 10:31:06 -07003435 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01003436 crypto_req_done, &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07003437
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01003438 err = crypto_wait_req(vecs->siggen_sigver_test ?
Vitaly Chikunov0507de92019-01-07 20:54:27 +03003439 /* Run asymmetric signature verification */
3440 crypto_akcipher_verify(req) :
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01003441 /* Run asymmetric encrypt */
3442 crypto_akcipher_encrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07003443 if (err) {
Vitaly Chikunov0507de92019-01-07 20:54:27 +03003444 pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07003445 goto free_all;
3446 }
Vitaly Chikunovc7381b02019-04-11 18:51:15 +03003447 if (!vecs->siggen_sigver_test) {
3448 if (req->dst_len != c_size) {
3449 pr_err("alg: akcipher: %s test failed. Invalid output len\n",
3450 op);
3451 err = -EINVAL;
3452 goto free_all;
3453 }
3454 /* verify that encrypted message is equal to expected */
3455 if (memcmp(c, outbuf_enc, c_size) != 0) {
3456 pr_err("alg: akcipher: %s test failed. Invalid output\n",
3457 op);
3458 hexdump(outbuf_enc, c_size);
3459 err = -EINVAL;
3460 goto free_all;
3461 }
Tadeusz Struk946cc462015-06-16 10:31:06 -07003462 }
Vitaly Chikunov0507de92019-01-07 20:54:27 +03003463
3464 /*
3465 * Don't invoke (decrypt or sign) test which require a private key
3466 * for vectors with only a public key.
3467 */
Tadeusz Struk946cc462015-06-16 10:31:06 -07003468 if (vecs->public_key_vec) {
3469 err = 0;
3470 goto free_all;
3471 }
3472 outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
3473 if (!outbuf_dec) {
3474 err = -ENOMEM;
3475 goto free_all;
3476 }
Herbert Xudf27b262016-05-05 16:42:49 +08003477
Vitaly Chikunov0507de92019-01-07 20:54:27 +03003478 op = vecs->siggen_sigver_test ? "sign" : "decrypt";
3479 if (WARN_ON(c_size > PAGE_SIZE))
Herbert Xudf27b262016-05-05 16:42:49 +08003480 goto free_all;
Vitaly Chikunov0507de92019-01-07 20:54:27 +03003481 memcpy(xbuf[0], c, c_size);
Herbert Xudf27b262016-05-05 16:42:49 +08003482
Vitaly Chikunov0507de92019-01-07 20:54:27 +03003483 sg_init_one(&src, xbuf[0], c_size);
Tadeusz Struk22287b02015-10-08 09:26:55 -07003484 sg_init_one(&dst, outbuf_dec, out_len_max);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01003485 crypto_init_wait(&wait);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03003486 akcipher_request_set_crypt(req, &src, &dst, c_size, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07003487
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01003488 err = crypto_wait_req(vecs->siggen_sigver_test ?
Vitaly Chikunov0507de92019-01-07 20:54:27 +03003489 /* Run asymmetric signature generation */
3490 crypto_akcipher_sign(req) :
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01003491 /* Run asymmetric decrypt */
3492 crypto_akcipher_decrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07003493 if (err) {
Vitaly Chikunov0507de92019-01-07 20:54:27 +03003494 pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07003495 goto free_all;
3496 }
3497 out_len = req->dst_len;
Vitaly Chikunov0507de92019-01-07 20:54:27 +03003498 if (out_len < m_size) {
3499 pr_err("alg: akcipher: %s test failed. Invalid output len %u\n",
3500 op, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07003501 err = -EINVAL;
3502 goto free_all;
3503 }
3504 /* verify that decrypted message is equal to the original msg */
Vitaly Chikunov0507de92019-01-07 20:54:27 +03003505 if (memchr_inv(outbuf_dec, 0, out_len - m_size) ||
3506 memcmp(m, outbuf_dec + out_len - m_size, m_size)) {
3507 pr_err("alg: akcipher: %s test failed. Invalid output\n", op);
Herbert Xu50d2b6432016-06-29 19:32:20 +08003508 hexdump(outbuf_dec, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07003509 err = -EINVAL;
3510 }
3511free_all:
3512 kfree(outbuf_dec);
3513 kfree(outbuf_enc);
3514free_req:
3515 akcipher_request_free(req);
Vitaly Chikunovf1774cb2019-04-11 18:51:17 +03003516 kfree(key);
Herbert Xudf27b262016-05-05 16:42:49 +08003517free_xbuf:
3518 testmgr_free_buf(xbuf);
Tadeusz Struk946cc462015-06-16 10:31:06 -07003519 return err;
3520}
3521
Herbert Xu50d2b6432016-06-29 19:32:20 +08003522static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08003523 const struct akcipher_testvec *vecs,
3524 unsigned int tcount)
Tadeusz Struk946cc462015-06-16 10:31:06 -07003525{
Herbert Xu15226e42016-07-18 18:20:10 +08003526 const char *algo =
3527 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
Tadeusz Struk946cc462015-06-16 10:31:06 -07003528 int ret, i;
3529
3530 for (i = 0; i < tcount; i++) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08003531 ret = test_akcipher_one(tfm, vecs++);
3532 if (!ret)
3533 continue;
3534
Herbert Xu15226e42016-07-18 18:20:10 +08003535 pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
3536 i + 1, algo, ret);
Herbert Xu50d2b6432016-06-29 19:32:20 +08003537 return ret;
Tadeusz Struk946cc462015-06-16 10:31:06 -07003538 }
3539 return 0;
3540}
3541
Tadeusz Struk946cc462015-06-16 10:31:06 -07003542static int alg_test_akcipher(const struct alg_test_desc *desc,
3543 const char *driver, u32 type, u32 mask)
3544{
3545 struct crypto_akcipher *tfm;
3546 int err = 0;
3547
Herbert Xueed93e02016-11-22 20:08:31 +08003548 tfm = crypto_alloc_akcipher(driver, type, mask);
Tadeusz Struk946cc462015-06-16 10:31:06 -07003549 if (IS_ERR(tfm)) {
3550 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
3551 driver, PTR_ERR(tfm));
3552 return PTR_ERR(tfm);
3553 }
3554 if (desc->suite.akcipher.vecs)
3555 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
3556 desc->suite.akcipher.count);
3557
3558 crypto_free_akcipher(tfm);
3559 return err;
3560}
3561
Youquan, Song863b5572009-12-23 19:45:20 +08003562static int alg_test_null(const struct alg_test_desc *desc,
3563 const char *driver, u32 type, u32 mask)
3564{
3565 return 0;
3566}
3567
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003568#define __VECS(tv) { .vecs = tv, .count = ARRAY_SIZE(tv) }
3569
Herbert Xuda7f0332008-07-31 17:08:25 +08003570/* Please keep this list sorted by algorithm name. */
3571static const struct alg_test_desc alg_test_descs[] = {
3572 {
Eric Biggers059c2a42018-11-16 17:26:31 -08003573 .alg = "adiantum(xchacha12,aes)",
Eric Biggersd435e102019-04-11 21:57:40 -07003574 .generic_driver = "adiantum(xchacha12-generic,aes-generic,nhpoly1305-generic)",
Eric Biggers059c2a42018-11-16 17:26:31 -08003575 .test = alg_test_skcipher,
3576 .suite = {
3577 .cipher = __VECS(adiantum_xchacha12_aes_tv_template)
3578 },
3579 }, {
3580 .alg = "adiantum(xchacha20,aes)",
Eric Biggersd435e102019-04-11 21:57:40 -07003581 .generic_driver = "adiantum(xchacha20-generic,aes-generic,nhpoly1305-generic)",
Eric Biggers059c2a42018-11-16 17:26:31 -08003582 .test = alg_test_skcipher,
3583 .suite = {
3584 .cipher = __VECS(adiantum_xchacha20_aes_tv_template)
3585 },
3586 }, {
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02003587 .alg = "aegis128",
3588 .test = alg_test_aead,
3589 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003590 .aead = __VECS(aegis128_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02003591 }
3592 }, {
3593 .alg = "aegis128l",
3594 .test = alg_test_aead,
3595 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003596 .aead = __VECS(aegis128l_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02003597 }
3598 }, {
3599 .alg = "aegis256",
3600 .test = alg_test_aead,
3601 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003602 .aead = __VECS(aegis256_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02003603 }
3604 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08003605 .alg = "ansi_cprng",
3606 .test = alg_test_cprng,
3607 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003608 .cprng = __VECS(ansi_cprng_aes_tv_template)
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08003609 }
3610 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02003611 .alg = "authenc(hmac(md5),ecb(cipher_null))",
3612 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02003613 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003614 .aead = __VECS(hmac_md5_ecb_cipher_null_tv_template)
Horia Geantabca4feb2014-03-14 17:46:51 +02003615 }
3616 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003617 .alg = "authenc(hmac(sha1),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03003618 .test = alg_test_aead,
Herbert Xubcf741c2017-06-28 19:09:07 +08003619 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03003620 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003621 .aead = __VECS(hmac_sha1_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303622 }
3623 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003624 .alg = "authenc(hmac(sha1),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303625 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303626 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003627 .aead = __VECS(hmac_sha1_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303628 }
3629 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003630 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303631 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01003632 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303633 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003634 .aead = __VECS(hmac_sha1_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03003635 }
3636 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01003637 .alg = "authenc(hmac(sha1),ctr(aes))",
3638 .test = alg_test_null,
3639 .fips_allowed = 1,
3640 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02003641 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
3642 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02003643 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003644 .aead = __VECS(hmac_sha1_ecb_cipher_null_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303645 }
3646 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01003647 .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
3648 .test = alg_test_null,
3649 .fips_allowed = 1,
3650 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003651 .alg = "authenc(hmac(sha224),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303652 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303653 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003654 .aead = __VECS(hmac_sha224_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303655 }
3656 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003657 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303658 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01003659 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303660 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003661 .aead = __VECS(hmac_sha224_des3_ede_cbc_tv_temp)
Horia Geantabca4feb2014-03-14 17:46:51 +02003662 }
3663 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003664 .alg = "authenc(hmac(sha256),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03003665 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01003666 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03003667 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003668 .aead = __VECS(hmac_sha256_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303669 }
3670 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003671 .alg = "authenc(hmac(sha256),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303672 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303673 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003674 .aead = __VECS(hmac_sha256_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303675 }
3676 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003677 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303678 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01003679 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303680 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003681 .aead = __VECS(hmac_sha256_des3_ede_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303682 }
3683 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01003684 .alg = "authenc(hmac(sha256),ctr(aes))",
3685 .test = alg_test_null,
3686 .fips_allowed = 1,
3687 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01003688 .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
3689 .test = alg_test_null,
3690 .fips_allowed = 1,
3691 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003692 .alg = "authenc(hmac(sha384),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303693 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303694 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003695 .aead = __VECS(hmac_sha384_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303696 }
3697 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003698 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303699 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01003700 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303701 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003702 .aead = __VECS(hmac_sha384_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03003703 }
3704 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01003705 .alg = "authenc(hmac(sha384),ctr(aes))",
3706 .test = alg_test_null,
3707 .fips_allowed = 1,
3708 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01003709 .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
3710 .test = alg_test_null,
3711 .fips_allowed = 1,
3712 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003713 .alg = "authenc(hmac(sha512),cbc(aes))",
Marcus Meissnered1afac2016-02-05 14:23:33 +01003714 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03003715 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03003716 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003717 .aead = __VECS(hmac_sha512_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303718 }
3719 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003720 .alg = "authenc(hmac(sha512),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303721 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303722 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003723 .aead = __VECS(hmac_sha512_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303724 }
3725 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003726 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303727 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01003728 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303729 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003730 .aead = __VECS(hmac_sha512_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03003731 }
3732 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01003733 .alg = "authenc(hmac(sha512),ctr(aes))",
3734 .test = alg_test_null,
3735 .fips_allowed = 1,
3736 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01003737 .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
3738 .test = alg_test_null,
3739 .fips_allowed = 1,
3740 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003741 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003742 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003743 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003744 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003745 .cipher = __VECS(aes_cbc_tv_template)
3746 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003747 }, {
3748 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003749 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003750 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003751 .cipher = __VECS(anubis_cbc_tv_template)
3752 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003753 }, {
3754 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003755 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003756 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003757 .cipher = __VECS(bf_cbc_tv_template)
3758 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003759 }, {
3760 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003761 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003762 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003763 .cipher = __VECS(camellia_cbc_tv_template)
3764 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003765 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003766 .alg = "cbc(cast5)",
3767 .test = alg_test_skcipher,
3768 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003769 .cipher = __VECS(cast5_cbc_tv_template)
3770 },
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003771 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003772 .alg = "cbc(cast6)",
3773 .test = alg_test_skcipher,
3774 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003775 .cipher = __VECS(cast6_cbc_tv_template)
3776 },
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003777 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003778 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003779 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003780 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003781 .cipher = __VECS(des_cbc_tv_template)
3782 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003783 }, {
3784 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003785 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003786 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003787 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003788 .cipher = __VECS(des3_ede_cbc_tv_template)
3789 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003790 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003791 /* Same as cbc(aes) except the key is stored in
3792 * hardware secure memory which we reference by index
3793 */
3794 .alg = "cbc(paes)",
3795 .test = alg_test_null,
3796 .fips_allowed = 1,
3797 }, {
Gilad Ben-Yosseff0372c02019-04-18 16:38:36 +03003798 /* Same as cbc(sm4) except the key is stored in
3799 * hardware secure memory which we reference by index
3800 */
3801 .alg = "cbc(psm4)",
3802 .test = alg_test_null,
3803 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003804 .alg = "cbc(serpent)",
3805 .test = alg_test_skcipher,
3806 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003807 .cipher = __VECS(serpent_cbc_tv_template)
3808 },
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003809 }, {
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01003810 .alg = "cbc(sm4)",
3811 .test = alg_test_skcipher,
3812 .suite = {
3813 .cipher = __VECS(sm4_cbc_tv_template)
3814 }
3815 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003816 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003817 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003818 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003819 .cipher = __VECS(tf_cbc_tv_template)
3820 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003821 }, {
Ard Biesheuvel092acf02017-02-03 14:49:35 +00003822 .alg = "cbcmac(aes)",
3823 .fips_allowed = 1,
3824 .test = alg_test_hash,
3825 .suite = {
3826 .hash = __VECS(aes_cbcmac_tv_template)
3827 }
3828 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003829 .alg = "ccm(aes)",
Eric Biggers40153b12019-04-11 21:57:41 -07003830 .generic_driver = "ccm_base(ctr(aes-generic),cbcmac(aes-generic))",
Herbert Xuda7f0332008-07-31 17:08:25 +08003831 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003832 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003833 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003834 .aead = __VECS(aes_ccm_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003835 }
3836 }, {
Dmitry Eremin-Solenikov7da66672018-10-20 02:01:53 +03003837 .alg = "cfb(aes)",
3838 .test = alg_test_skcipher,
3839 .fips_allowed = 1,
3840 .suite = {
3841 .cipher = __VECS(aes_cfb_tv_template)
3842 },
3843 }, {
Martin Willi3590ebf2015-06-01 13:43:57 +02003844 .alg = "chacha20",
3845 .test = alg_test_skcipher,
3846 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003847 .cipher = __VECS(chacha20_tv_template)
3848 },
Martin Willi3590ebf2015-06-01 13:43:57 +02003849 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003850 .alg = "cmac(aes)",
Stephan Mueller8f183752015-08-19 08:42:07 +02003851 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003852 .test = alg_test_hash,
3853 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003854 .hash = __VECS(aes_cmac128_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003855 }
3856 }, {
3857 .alg = "cmac(des3_ede)",
Stephan Mueller8f183752015-08-19 08:42:07 +02003858 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003859 .test = alg_test_hash,
3860 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003861 .hash = __VECS(des3_ede_cmac64_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003862 }
3863 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003864 .alg = "compress_null",
3865 .test = alg_test_null,
3866 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003867 .alg = "crc32",
3868 .test = alg_test_hash,
Milan Broza8a34412019-01-25 10:31:47 +01003869 .fips_allowed = 1,
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003870 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003871 .hash = __VECS(crc32_tv_template)
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003872 }
3873 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003874 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08003875 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003876 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003877 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003878 .hash = __VECS(crc32c_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003879 }
3880 }, {
Herbert Xu684115212013-09-07 12:56:26 +10003881 .alg = "crct10dif",
3882 .test = alg_test_hash,
3883 .fips_allowed = 1,
3884 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003885 .hash = __VECS(crct10dif_tv_template)
Herbert Xu684115212013-09-07 12:56:26 +10003886 }
3887 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003888 .alg = "ctr(aes)",
3889 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003890 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003891 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003892 .cipher = __VECS(aes_ctr_tv_template)
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003893 }
3894 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03003895 .alg = "ctr(blowfish)",
3896 .test = alg_test_skcipher,
3897 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003898 .cipher = __VECS(bf_ctr_tv_template)
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03003899 }
3900 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003901 .alg = "ctr(camellia)",
3902 .test = alg_test_skcipher,
3903 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003904 .cipher = __VECS(camellia_ctr_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003905 }
3906 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003907 .alg = "ctr(cast5)",
3908 .test = alg_test_skcipher,
3909 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003910 .cipher = __VECS(cast5_ctr_tv_template)
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003911 }
3912 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003913 .alg = "ctr(cast6)",
3914 .test = alg_test_skcipher,
3915 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003916 .cipher = __VECS(cast6_ctr_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003917 }
3918 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03003919 .alg = "ctr(des)",
3920 .test = alg_test_skcipher,
3921 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003922 .cipher = __VECS(des_ctr_tv_template)
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03003923 }
3924 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003925 .alg = "ctr(des3_ede)",
3926 .test = alg_test_skcipher,
Marcelo Cerri0d8da102017-03-20 17:28:05 -03003927 .fips_allowed = 1,
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003928 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003929 .cipher = __VECS(des3_ede_ctr_tv_template)
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003930 }
3931 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003932 /* Same as ctr(aes) except the key is stored in
3933 * hardware secure memory which we reference by index
3934 */
3935 .alg = "ctr(paes)",
3936 .test = alg_test_null,
3937 .fips_allowed = 1,
3938 }, {
Gilad Ben-Yosseff0372c02019-04-18 16:38:36 +03003939
3940 /* Same as ctr(sm4) except the key is stored in
3941 * hardware secure memory which we reference by index
3942 */
3943 .alg = "ctr(psm4)",
3944 .test = alg_test_null,
3945 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003946 .alg = "ctr(serpent)",
3947 .test = alg_test_skcipher,
3948 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003949 .cipher = __VECS(serpent_ctr_tv_template)
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003950 }
3951 }, {
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01003952 .alg = "ctr(sm4)",
3953 .test = alg_test_skcipher,
3954 .suite = {
3955 .cipher = __VECS(sm4_ctr_tv_template)
3956 }
3957 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03003958 .alg = "ctr(twofish)",
3959 .test = alg_test_skcipher,
3960 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003961 .cipher = __VECS(tf_ctr_tv_template)
Jussi Kivilinna573da622011-10-10 23:03:12 +03003962 }
3963 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003964 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003965 .test = alg_test_skcipher,
Gilad Ben-Yossef196ad602018-11-04 10:05:24 +00003966 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003967 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003968 .cipher = __VECS(cts_mode_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003969 }
3970 }, {
Gilad Ben-Yosseff0372c02019-04-18 16:38:36 +03003971 /* Same as cts(cbc((aes)) except the key is stored in
3972 * hardware secure memory which we reference by index
3973 */
3974 .alg = "cts(cbc(paes))",
3975 .test = alg_test_null,
3976 .fips_allowed = 1,
3977 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003978 .alg = "deflate",
3979 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003980 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003981 .suite = {
3982 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003983 .comp = __VECS(deflate_comp_tv_template),
3984 .decomp = __VECS(deflate_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003985 }
3986 }
3987 }, {
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003988 .alg = "dh",
3989 .test = alg_test_kpp,
3990 .fips_allowed = 1,
3991 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003992 .kpp = __VECS(dh_tv_template)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003993 }
3994 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003995 .alg = "digest_null",
3996 .test = alg_test_null,
3997 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003998 .alg = "drbg_nopr_ctr_aes128",
3999 .test = alg_test_drbg,
4000 .fips_allowed = 1,
4001 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004002 .drbg = __VECS(drbg_nopr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02004003 }
4004 }, {
4005 .alg = "drbg_nopr_ctr_aes192",
4006 .test = alg_test_drbg,
4007 .fips_allowed = 1,
4008 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004009 .drbg = __VECS(drbg_nopr_ctr_aes192_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02004010 }
4011 }, {
4012 .alg = "drbg_nopr_ctr_aes256",
4013 .test = alg_test_drbg,
4014 .fips_allowed = 1,
4015 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004016 .drbg = __VECS(drbg_nopr_ctr_aes256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02004017 }
4018 }, {
4019 /*
4020 * There is no need to specifically test the DRBG with every
4021 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
4022 */
4023 .alg = "drbg_nopr_hmac_sha1",
4024 .fips_allowed = 1,
4025 .test = alg_test_null,
4026 }, {
4027 .alg = "drbg_nopr_hmac_sha256",
4028 .test = alg_test_drbg,
4029 .fips_allowed = 1,
4030 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004031 .drbg = __VECS(drbg_nopr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02004032 }
4033 }, {
4034 /* covered by drbg_nopr_hmac_sha256 test */
4035 .alg = "drbg_nopr_hmac_sha384",
4036 .fips_allowed = 1,
4037 .test = alg_test_null,
4038 }, {
4039 .alg = "drbg_nopr_hmac_sha512",
4040 .test = alg_test_null,
4041 .fips_allowed = 1,
4042 }, {
4043 .alg = "drbg_nopr_sha1",
4044 .fips_allowed = 1,
4045 .test = alg_test_null,
4046 }, {
4047 .alg = "drbg_nopr_sha256",
4048 .test = alg_test_drbg,
4049 .fips_allowed = 1,
4050 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004051 .drbg = __VECS(drbg_nopr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02004052 }
4053 }, {
4054 /* covered by drbg_nopr_sha256 test */
4055 .alg = "drbg_nopr_sha384",
4056 .fips_allowed = 1,
4057 .test = alg_test_null,
4058 }, {
4059 .alg = "drbg_nopr_sha512",
4060 .fips_allowed = 1,
4061 .test = alg_test_null,
4062 }, {
4063 .alg = "drbg_pr_ctr_aes128",
4064 .test = alg_test_drbg,
4065 .fips_allowed = 1,
4066 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004067 .drbg = __VECS(drbg_pr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02004068 }
4069 }, {
4070 /* covered by drbg_pr_ctr_aes128 test */
4071 .alg = "drbg_pr_ctr_aes192",
4072 .fips_allowed = 1,
4073 .test = alg_test_null,
4074 }, {
4075 .alg = "drbg_pr_ctr_aes256",
4076 .fips_allowed = 1,
4077 .test = alg_test_null,
4078 }, {
4079 .alg = "drbg_pr_hmac_sha1",
4080 .fips_allowed = 1,
4081 .test = alg_test_null,
4082 }, {
4083 .alg = "drbg_pr_hmac_sha256",
4084 .test = alg_test_drbg,
4085 .fips_allowed = 1,
4086 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004087 .drbg = __VECS(drbg_pr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02004088 }
4089 }, {
4090 /* covered by drbg_pr_hmac_sha256 test */
4091 .alg = "drbg_pr_hmac_sha384",
4092 .fips_allowed = 1,
4093 .test = alg_test_null,
4094 }, {
4095 .alg = "drbg_pr_hmac_sha512",
4096 .test = alg_test_null,
4097 .fips_allowed = 1,
4098 }, {
4099 .alg = "drbg_pr_sha1",
4100 .fips_allowed = 1,
4101 .test = alg_test_null,
4102 }, {
4103 .alg = "drbg_pr_sha256",
4104 .test = alg_test_drbg,
4105 .fips_allowed = 1,
4106 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004107 .drbg = __VECS(drbg_pr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02004108 }
4109 }, {
4110 /* covered by drbg_pr_sha256 test */
4111 .alg = "drbg_pr_sha384",
4112 .fips_allowed = 1,
4113 .test = alg_test_null,
4114 }, {
4115 .alg = "drbg_pr_sha512",
4116 .fips_allowed = 1,
4117 .test = alg_test_null,
4118 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004119 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004120 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004121 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004122 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004123 .cipher = __VECS(aes_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004124 }
4125 }, {
4126 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004127 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004128 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004129 .cipher = __VECS(anubis_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004130 }
4131 }, {
4132 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004133 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004134 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004135 .cipher = __VECS(arc4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004136 }
4137 }, {
4138 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004139 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004140 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004141 .cipher = __VECS(bf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004142 }
4143 }, {
4144 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004145 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004146 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004147 .cipher = __VECS(camellia_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004148 }
4149 }, {
4150 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004151 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004152 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004153 .cipher = __VECS(cast5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004154 }
4155 }, {
4156 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004157 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004158 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004159 .cipher = __VECS(cast6_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004160 }
4161 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03004162 .alg = "ecb(cipher_null)",
4163 .test = alg_test_null,
Milan Broz6175ca22017-04-21 13:03:06 +02004164 .fips_allowed = 1,
Jussi Kivilinnae4483702013-04-07 16:43:56 +03004165 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004166 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004167 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004168 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004169 .cipher = __VECS(des_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004170 }
4171 }, {
4172 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004173 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004174 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004175 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004176 .cipher = __VECS(des3_ede_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004177 }
4178 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02004179 .alg = "ecb(fcrypt)",
4180 .test = alg_test_skcipher,
4181 .suite = {
4182 .cipher = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004183 .vecs = fcrypt_pcbc_tv_template,
4184 .count = 1
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02004185 }
4186 }
4187 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004188 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004189 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004190 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004191 .cipher = __VECS(khazad_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004192 }
4193 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01004194 /* Same as ecb(aes) except the key is stored in
4195 * hardware secure memory which we reference by index
4196 */
4197 .alg = "ecb(paes)",
4198 .test = alg_test_null,
4199 .fips_allowed = 1,
4200 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004201 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004202 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004203 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004204 .cipher = __VECS(seed_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004205 }
4206 }, {
4207 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004208 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004209 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004210 .cipher = __VECS(serpent_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004211 }
4212 }, {
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00004213 .alg = "ecb(sm4)",
4214 .test = alg_test_skcipher,
4215 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004216 .cipher = __VECS(sm4_tv_template)
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00004217 }
4218 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004219 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004220 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004221 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004222 .cipher = __VECS(tea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004223 }
4224 }, {
4225 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004226 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004227 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004228 .cipher = __VECS(tnepres_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004229 }
4230 }, {
4231 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004232 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004233 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004234 .cipher = __VECS(tf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004235 }
4236 }, {
4237 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004238 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004239 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004240 .cipher = __VECS(xeta_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004241 }
4242 }, {
4243 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004244 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004245 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004246 .cipher = __VECS(xtea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004247 }
4248 }, {
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01004249 .alg = "ecdh",
4250 .test = alg_test_kpp,
4251 .fips_allowed = 1,
4252 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004253 .kpp = __VECS(ecdh_tv_template)
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01004254 }
4255 }, {
Vitaly Chikunov32fbdbd2019-04-11 18:51:21 +03004256 .alg = "ecrdsa",
4257 .test = alg_test_akcipher,
4258 .suite = {
4259 .akcipher = __VECS(ecrdsa_tv_template)
4260 }
4261 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004262 .alg = "gcm(aes)",
Eric Biggers40153b12019-04-11 21:57:41 -07004263 .generic_driver = "gcm_base(ctr(aes-generic),ghash-generic)",
Herbert Xuda7f0332008-07-31 17:08:25 +08004264 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004265 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004266 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08004267 .aead = __VECS(aes_gcm_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004268 }
4269 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08004270 .alg = "ghash",
4271 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11004272 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08004273 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004274 .hash = __VECS(ghash_tv_template)
Youquan, Song507069c2009-11-23 20:23:04 +08004275 }
4276 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004277 .alg = "hmac(md5)",
4278 .test = alg_test_hash,
4279 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004280 .hash = __VECS(hmac_md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004281 }
4282 }, {
4283 .alg = "hmac(rmd128)",
4284 .test = alg_test_hash,
4285 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004286 .hash = __VECS(hmac_rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004287 }
4288 }, {
4289 .alg = "hmac(rmd160)",
4290 .test = alg_test_hash,
4291 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004292 .hash = __VECS(hmac_rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004293 }
4294 }, {
4295 .alg = "hmac(sha1)",
4296 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004297 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004298 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004299 .hash = __VECS(hmac_sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004300 }
4301 }, {
4302 .alg = "hmac(sha224)",
4303 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004304 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004305 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004306 .hash = __VECS(hmac_sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004307 }
4308 }, {
4309 .alg = "hmac(sha256)",
4310 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004311 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004312 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004313 .hash = __VECS(hmac_sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004314 }
4315 }, {
raveendra padasalagi98eca722016-07-01 11:16:54 +05304316 .alg = "hmac(sha3-224)",
4317 .test = alg_test_hash,
4318 .fips_allowed = 1,
4319 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004320 .hash = __VECS(hmac_sha3_224_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05304321 }
4322 }, {
4323 .alg = "hmac(sha3-256)",
4324 .test = alg_test_hash,
4325 .fips_allowed = 1,
4326 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004327 .hash = __VECS(hmac_sha3_256_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05304328 }
4329 }, {
4330 .alg = "hmac(sha3-384)",
4331 .test = alg_test_hash,
4332 .fips_allowed = 1,
4333 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004334 .hash = __VECS(hmac_sha3_384_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05304335 }
4336 }, {
4337 .alg = "hmac(sha3-512)",
4338 .test = alg_test_hash,
4339 .fips_allowed = 1,
4340 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004341 .hash = __VECS(hmac_sha3_512_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05304342 }
4343 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004344 .alg = "hmac(sha384)",
4345 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004346 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004347 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004348 .hash = __VECS(hmac_sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004349 }
4350 }, {
4351 .alg = "hmac(sha512)",
4352 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004353 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004354 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004355 .hash = __VECS(hmac_sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004356 }
4357 }, {
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03004358 .alg = "hmac(streebog256)",
4359 .test = alg_test_hash,
4360 .suite = {
4361 .hash = __VECS(hmac_streebog256_tv_template)
4362 }
4363 }, {
4364 .alg = "hmac(streebog512)",
4365 .test = alg_test_hash,
4366 .suite = {
4367 .hash = __VECS(hmac_streebog512_tv_template)
4368 }
4369 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02004370 .alg = "jitterentropy_rng",
4371 .fips_allowed = 1,
4372 .test = alg_test_null,
4373 }, {
Stephan Mueller35351982015-09-21 20:59:56 +02004374 .alg = "kw(aes)",
4375 .test = alg_test_skcipher,
4376 .fips_allowed = 1,
4377 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004378 .cipher = __VECS(aes_kw_tv_template)
Stephan Mueller35351982015-09-21 20:59:56 +02004379 }
4380 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004381 .alg = "lrw(aes)",
Eric Biggersd435e102019-04-11 21:57:40 -07004382 .generic_driver = "lrw(ecb(aes-generic))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004383 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004384 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004385 .cipher = __VECS(aes_lrw_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004386 }
4387 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02004388 .alg = "lrw(camellia)",
Eric Biggersd435e102019-04-11 21:57:40 -07004389 .generic_driver = "lrw(ecb(camellia-generic))",
Jussi Kivilinna08406052012-03-05 20:26:21 +02004390 .test = alg_test_skcipher,
4391 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004392 .cipher = __VECS(camellia_lrw_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02004393 }
4394 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02004395 .alg = "lrw(cast6)",
Eric Biggersd435e102019-04-11 21:57:40 -07004396 .generic_driver = "lrw(ecb(cast6-generic))",
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02004397 .test = alg_test_skcipher,
4398 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004399 .cipher = __VECS(cast6_lrw_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02004400 }
4401 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03004402 .alg = "lrw(serpent)",
Eric Biggersd435e102019-04-11 21:57:40 -07004403 .generic_driver = "lrw(ecb(serpent-generic))",
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03004404 .test = alg_test_skcipher,
4405 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004406 .cipher = __VECS(serpent_lrw_tv_template)
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03004407 }
4408 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03004409 .alg = "lrw(twofish)",
Eric Biggersd435e102019-04-11 21:57:40 -07004410 .generic_driver = "lrw(ecb(twofish-generic))",
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03004411 .test = alg_test_skcipher,
4412 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004413 .cipher = __VECS(tf_lrw_tv_template)
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03004414 }
4415 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02004416 .alg = "lz4",
4417 .test = alg_test_comp,
4418 .fips_allowed = 1,
4419 .suite = {
4420 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004421 .comp = __VECS(lz4_comp_tv_template),
4422 .decomp = __VECS(lz4_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02004423 }
4424 }
4425 }, {
4426 .alg = "lz4hc",
4427 .test = alg_test_comp,
4428 .fips_allowed = 1,
4429 .suite = {
4430 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004431 .comp = __VECS(lz4hc_comp_tv_template),
4432 .decomp = __VECS(lz4hc_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02004433 }
4434 }
4435 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004436 .alg = "lzo",
4437 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08004438 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004439 .suite = {
4440 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004441 .comp = __VECS(lzo_comp_tv_template),
4442 .decomp = __VECS(lzo_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004443 }
4444 }
4445 }, {
4446 .alg = "md4",
4447 .test = alg_test_hash,
4448 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004449 .hash = __VECS(md4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004450 }
4451 }, {
4452 .alg = "md5",
4453 .test = alg_test_hash,
4454 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004455 .hash = __VECS(md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004456 }
4457 }, {
4458 .alg = "michael_mic",
4459 .test = alg_test_hash,
4460 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004461 .hash = __VECS(michael_mic_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004462 }
4463 }, {
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02004464 .alg = "morus1280",
4465 .test = alg_test_aead,
4466 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08004467 .aead = __VECS(morus1280_tv_template)
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02004468 }
4469 }, {
4470 .alg = "morus640",
4471 .test = alg_test_aead,
4472 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08004473 .aead = __VECS(morus640_tv_template)
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02004474 }
4475 }, {
Eric Biggers26609a22018-11-16 17:26:29 -08004476 .alg = "nhpoly1305",
4477 .test = alg_test_hash,
4478 .suite = {
4479 .hash = __VECS(nhpoly1305_tv_template)
4480 }
4481 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10004482 .alg = "ofb(aes)",
4483 .test = alg_test_skcipher,
4484 .fips_allowed = 1,
4485 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004486 .cipher = __VECS(aes_ofb_tv_template)
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10004487 }
4488 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01004489 /* Same as ofb(aes) except the key is stored in
4490 * hardware secure memory which we reference by index
4491 */
4492 .alg = "ofb(paes)",
4493 .test = alg_test_null,
4494 .fips_allowed = 1,
4495 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004496 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004497 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004498 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004499 .cipher = __VECS(fcrypt_pcbc_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004500 }
4501 }, {
Stephan Mueller12071072017-06-12 23:27:51 +02004502 .alg = "pkcs1pad(rsa,sha224)",
4503 .test = alg_test_null,
4504 .fips_allowed = 1,
4505 }, {
4506 .alg = "pkcs1pad(rsa,sha256)",
4507 .test = alg_test_akcipher,
4508 .fips_allowed = 1,
4509 .suite = {
4510 .akcipher = __VECS(pkcs1pad_rsa_tv_template)
4511 }
4512 }, {
4513 .alg = "pkcs1pad(rsa,sha384)",
4514 .test = alg_test_null,
4515 .fips_allowed = 1,
4516 }, {
4517 .alg = "pkcs1pad(rsa,sha512)",
4518 .test = alg_test_null,
4519 .fips_allowed = 1,
4520 }, {
Martin Willieee9dc62015-06-01 13:43:59 +02004521 .alg = "poly1305",
4522 .test = alg_test_hash,
4523 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004524 .hash = __VECS(poly1305_tv_template)
Martin Willieee9dc62015-06-01 13:43:59 +02004525 }
4526 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004527 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004528 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004529 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004530 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004531 .cipher = __VECS(aes_ctr_rfc3686_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004532 }
4533 }, {
Herbert Xu3f31a742015-07-09 07:17:34 +08004534 .alg = "rfc4106(gcm(aes))",
Eric Biggers40153b12019-04-11 21:57:41 -07004535 .generic_driver = "rfc4106(gcm_base(ctr(aes-generic),ghash-generic))",
Adrian Hoban69435b92010-11-04 15:02:04 -04004536 .test = alg_test_aead,
Jarod Wilsondb71f29a2015-01-23 12:42:15 -05004537 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04004538 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08004539 .aead = __VECS(aes_gcm_rfc4106_tv_template)
Adrian Hoban69435b92010-11-04 15:02:04 -04004540 }
4541 }, {
Herbert Xu544c4362015-07-14 16:53:22 +08004542 .alg = "rfc4309(ccm(aes))",
Eric Biggers40153b12019-04-11 21:57:41 -07004543 .generic_driver = "rfc4309(ccm_base(ctr(aes-generic),cbcmac(aes-generic)))",
Jarod Wilson5d667322009-05-04 19:23:40 +08004544 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004545 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08004546 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08004547 .aead = __VECS(aes_ccm_rfc4309_tv_template)
Jarod Wilson5d667322009-05-04 19:23:40 +08004548 }
4549 }, {
Herbert Xubb687452015-06-16 13:54:24 +08004550 .alg = "rfc4543(gcm(aes))",
Eric Biggers40153b12019-04-11 21:57:41 -07004551 .generic_driver = "rfc4543(gcm_base(ctr(aes-generic),ghash-generic))",
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03004552 .test = alg_test_aead,
4553 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08004554 .aead = __VECS(aes_gcm_rfc4543_tv_template)
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03004555 }
4556 }, {
Martin Williaf2b76b2015-06-01 13:44:01 +02004557 .alg = "rfc7539(chacha20,poly1305)",
4558 .test = alg_test_aead,
4559 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08004560 .aead = __VECS(rfc7539_tv_template)
Martin Williaf2b76b2015-06-01 13:44:01 +02004561 }
4562 }, {
Martin Willi59007582015-06-01 13:44:03 +02004563 .alg = "rfc7539esp(chacha20,poly1305)",
4564 .test = alg_test_aead,
4565 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08004566 .aead = __VECS(rfc7539esp_tv_template)
Martin Willi59007582015-06-01 13:44:03 +02004567 }
4568 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004569 .alg = "rmd128",
4570 .test = alg_test_hash,
4571 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004572 .hash = __VECS(rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004573 }
4574 }, {
4575 .alg = "rmd160",
4576 .test = alg_test_hash,
4577 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004578 .hash = __VECS(rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004579 }
4580 }, {
4581 .alg = "rmd256",
4582 .test = alg_test_hash,
4583 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004584 .hash = __VECS(rmd256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004585 }
4586 }, {
4587 .alg = "rmd320",
4588 .test = alg_test_hash,
4589 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004590 .hash = __VECS(rmd320_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004591 }
4592 }, {
Tadeusz Struk946cc462015-06-16 10:31:06 -07004593 .alg = "rsa",
4594 .test = alg_test_akcipher,
4595 .fips_allowed = 1,
4596 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004597 .akcipher = __VECS(rsa_tv_template)
Tadeusz Struk946cc462015-06-16 10:31:06 -07004598 }
4599 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004600 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004601 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08004602 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004603 .cipher = __VECS(salsa20_stream_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004604 }
4605 }, {
4606 .alg = "sha1",
4607 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004608 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004609 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004610 .hash = __VECS(sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004611 }
4612 }, {
4613 .alg = "sha224",
4614 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004615 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004616 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004617 .hash = __VECS(sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004618 }
4619 }, {
4620 .alg = "sha256",
4621 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004622 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004623 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004624 .hash = __VECS(sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004625 }
4626 }, {
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05304627 .alg = "sha3-224",
4628 .test = alg_test_hash,
4629 .fips_allowed = 1,
4630 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004631 .hash = __VECS(sha3_224_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05304632 }
4633 }, {
4634 .alg = "sha3-256",
4635 .test = alg_test_hash,
4636 .fips_allowed = 1,
4637 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004638 .hash = __VECS(sha3_256_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05304639 }
4640 }, {
4641 .alg = "sha3-384",
4642 .test = alg_test_hash,
4643 .fips_allowed = 1,
4644 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004645 .hash = __VECS(sha3_384_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05304646 }
4647 }, {
4648 .alg = "sha3-512",
4649 .test = alg_test_hash,
4650 .fips_allowed = 1,
4651 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004652 .hash = __VECS(sha3_512_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05304653 }
4654 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004655 .alg = "sha384",
4656 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004657 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004658 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004659 .hash = __VECS(sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004660 }
4661 }, {
4662 .alg = "sha512",
4663 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004664 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004665 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004666 .hash = __VECS(sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004667 }
4668 }, {
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03004669 .alg = "sm3",
4670 .test = alg_test_hash,
4671 .suite = {
4672 .hash = __VECS(sm3_tv_template)
4673 }
4674 }, {
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03004675 .alg = "streebog256",
4676 .test = alg_test_hash,
4677 .suite = {
4678 .hash = __VECS(streebog256_tv_template)
4679 }
4680 }, {
4681 .alg = "streebog512",
4682 .test = alg_test_hash,
4683 .suite = {
4684 .hash = __VECS(streebog512_tv_template)
4685 }
4686 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004687 .alg = "tgr128",
4688 .test = alg_test_hash,
4689 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004690 .hash = __VECS(tgr128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004691 }
4692 }, {
4693 .alg = "tgr160",
4694 .test = alg_test_hash,
4695 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004696 .hash = __VECS(tgr160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004697 }
4698 }, {
4699 .alg = "tgr192",
4700 .test = alg_test_hash,
4701 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004702 .hash = __VECS(tgr192_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004703 }
4704 }, {
Eric Biggersed331ad2018-06-18 10:22:39 -07004705 .alg = "vmac64(aes)",
4706 .test = alg_test_hash,
4707 .suite = {
4708 .hash = __VECS(vmac64_aes_tv_template)
4709 }
4710 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004711 .alg = "wp256",
4712 .test = alg_test_hash,
4713 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004714 .hash = __VECS(wp256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004715 }
4716 }, {
4717 .alg = "wp384",
4718 .test = alg_test_hash,
4719 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004720 .hash = __VECS(wp384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004721 }
4722 }, {
4723 .alg = "wp512",
4724 .test = alg_test_hash,
4725 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004726 .hash = __VECS(wp512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004727 }
4728 }, {
4729 .alg = "xcbc(aes)",
4730 .test = alg_test_hash,
4731 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004732 .hash = __VECS(aes_xcbc128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004733 }
4734 }, {
Eric Biggersaa762402018-11-16 17:26:22 -08004735 .alg = "xchacha12",
4736 .test = alg_test_skcipher,
4737 .suite = {
4738 .cipher = __VECS(xchacha12_tv_template)
4739 },
4740 }, {
Eric Biggersde61d7a2018-11-16 17:26:20 -08004741 .alg = "xchacha20",
4742 .test = alg_test_skcipher,
4743 .suite = {
4744 .cipher = __VECS(xchacha20_tv_template)
4745 },
4746 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004747 .alg = "xts(aes)",
Eric Biggersd435e102019-04-11 21:57:40 -07004748 .generic_driver = "xts(ecb(aes-generic))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004749 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11004750 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004751 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004752 .cipher = __VECS(aes_xts_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004753 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08004754 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02004755 .alg = "xts(camellia)",
Eric Biggersd435e102019-04-11 21:57:40 -07004756 .generic_driver = "xts(ecb(camellia-generic))",
Jussi Kivilinna08406052012-03-05 20:26:21 +02004757 .test = alg_test_skcipher,
4758 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004759 .cipher = __VECS(camellia_xts_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02004760 }
4761 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02004762 .alg = "xts(cast6)",
Eric Biggersd435e102019-04-11 21:57:40 -07004763 .generic_driver = "xts(ecb(cast6-generic))",
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02004764 .test = alg_test_skcipher,
4765 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004766 .cipher = __VECS(cast6_xts_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02004767 }
4768 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01004769 /* Same as xts(aes) except the key is stored in
4770 * hardware secure memory which we reference by index
4771 */
4772 .alg = "xts(paes)",
4773 .test = alg_test_null,
4774 .fips_allowed = 1,
4775 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03004776 .alg = "xts(serpent)",
Eric Biggersd435e102019-04-11 21:57:40 -07004777 .generic_driver = "xts(ecb(serpent-generic))",
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03004778 .test = alg_test_skcipher,
4779 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004780 .cipher = __VECS(serpent_xts_tv_template)
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03004781 }
4782 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03004783 .alg = "xts(twofish)",
Eric Biggersd435e102019-04-11 21:57:40 -07004784 .generic_driver = "xts(ecb(twofish-generic))",
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03004785 .test = alg_test_skcipher,
4786 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004787 .cipher = __VECS(tf_xts_tv_template)
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03004788 }
Giovanni Cabiddua368f432017-04-21 21:54:30 +01004789 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01004790 .alg = "xts4096(paes)",
4791 .test = alg_test_null,
4792 .fips_allowed = 1,
4793 }, {
4794 .alg = "xts512(paes)",
4795 .test = alg_test_null,
4796 .fips_allowed = 1,
4797 }, {
Giovanni Cabiddua368f432017-04-21 21:54:30 +01004798 .alg = "zlib-deflate",
4799 .test = alg_test_comp,
4800 .fips_allowed = 1,
4801 .suite = {
4802 .comp = {
4803 .comp = __VECS(zlib_deflate_comp_tv_template),
4804 .decomp = __VECS(zlib_deflate_decomp_tv_template)
4805 }
4806 }
Nick Terrelld28fc3d2018-03-30 12:14:53 -07004807 }, {
4808 .alg = "zstd",
4809 .test = alg_test_comp,
4810 .fips_allowed = 1,
4811 .suite = {
4812 .comp = {
4813 .comp = __VECS(zstd_comp_tv_template),
4814 .decomp = __VECS(zstd_decomp_tv_template)
4815 }
4816 }
Herbert Xuda7f0332008-07-31 17:08:25 +08004817 }
4818};
4819
Eric Biggers3f47a032019-01-31 23:51:43 -08004820static void alg_check_test_descs_order(void)
Jussi Kivilinna57147582013-06-13 17:37:40 +03004821{
4822 int i;
4823
Jussi Kivilinna57147582013-06-13 17:37:40 +03004824 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
4825 int diff = strcmp(alg_test_descs[i - 1].alg,
4826 alg_test_descs[i].alg);
4827
4828 if (WARN_ON(diff > 0)) {
4829 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
4830 alg_test_descs[i - 1].alg,
4831 alg_test_descs[i].alg);
4832 }
4833
4834 if (WARN_ON(diff == 0)) {
4835 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
4836 alg_test_descs[i].alg);
4837 }
4838 }
4839}
4840
Eric Biggers3f47a032019-01-31 23:51:43 -08004841static void alg_check_testvec_configs(void)
4842{
Eric Biggers4e7babba2019-01-31 23:51:46 -08004843 int i;
4844
4845 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++)
4846 WARN_ON(!valid_testvec_config(
4847 &default_cipher_testvec_configs[i]));
Eric Biggers4cc2dcf2019-01-31 23:51:48 -08004848
4849 for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++)
4850 WARN_ON(!valid_testvec_config(
4851 &default_hash_testvec_configs[i]));
Eric Biggers3f47a032019-01-31 23:51:43 -08004852}
4853
4854static void testmgr_onetime_init(void)
4855{
4856 alg_check_test_descs_order();
4857 alg_check_testvec_configs();
Eric Biggers5b2706a2019-01-31 23:51:44 -08004858
4859#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
4860 pr_warn("alg: extra crypto tests enabled. This is intended for developer use only.\n");
4861#endif
Eric Biggers3f47a032019-01-31 23:51:43 -08004862}
4863
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004864static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08004865{
4866 int start = 0;
4867 int end = ARRAY_SIZE(alg_test_descs);
4868
4869 while (start < end) {
4870 int i = (start + end) / 2;
4871 int diff = strcmp(alg_test_descs[i].alg, alg);
4872
4873 if (diff > 0) {
4874 end = i;
4875 continue;
4876 }
4877
4878 if (diff < 0) {
4879 start = i + 1;
4880 continue;
4881 }
4882
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004883 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08004884 }
4885
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004886 return -1;
4887}
4888
4889int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
4890{
4891 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08004892 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08004893 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004894
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +01004895 if (!fips_enabled && notests) {
4896 printk_once(KERN_INFO "alg: self-tests disabled\n");
4897 return 0;
4898 }
4899
Eric Biggers3f47a032019-01-31 23:51:43 -08004900 DO_ONCE(testmgr_onetime_init);
Jussi Kivilinna57147582013-06-13 17:37:40 +03004901
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004902 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
4903 char nalg[CRYPTO_MAX_ALG_NAME];
4904
4905 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
4906 sizeof(nalg))
4907 return -ENAMETOOLONG;
4908
4909 i = alg_find_test(nalg);
4910 if (i < 0)
4911 goto notest;
4912
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004913 if (fips_enabled && !alg_test_descs[i].fips_allowed)
4914 goto non_fips_alg;
4915
Jarod Wilson941fb322009-05-04 19:49:23 +08004916 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
4917 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004918 }
4919
4920 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08004921 j = alg_find_test(driver);
4922 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004923 goto notest;
4924
Herbert Xua68f6612009-07-02 16:32:12 +08004925 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
4926 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004927 goto non_fips_alg;
4928
Herbert Xua68f6612009-07-02 16:32:12 +08004929 rc = 0;
4930 if (i >= 0)
4931 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
4932 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03004933 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08004934 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
4935 type, mask);
4936
Jarod Wilson941fb322009-05-04 19:49:23 +08004937test_done:
Eric Biggerseda69b02019-03-31 13:09:14 -07004938 if (rc && (fips_enabled || panic_on_fail))
4939 panic("alg: self-tests for %s (%s) failed in %s mode!\n",
4940 driver, alg, fips_enabled ? "fips" : "panic_on_fail");
Neil Hormand12d6b62008-10-12 20:36:51 +08004941
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004942 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09004943 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004944
Neil Hormand12d6b62008-10-12 20:36:51 +08004945 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004946
4947notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08004948 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
4949 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004950non_fips_alg:
4951 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08004952}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004953
Herbert Xu326a6342010-08-06 09:40:28 +08004954#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004955
Herbert Xuda7f0332008-07-31 17:08:25 +08004956EXPORT_SYMBOL_GPL(alg_test);