blob: 6a870e21b0cf45acb327df217ba0f0631cf38c56 [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>
Herbert Xuda7f0332008-07-31 17:08:25 +080040
41#include "internal.h"
Alexander Shishkin0b767f92010-06-03 20:53:43 +100042
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +010043static bool notests;
44module_param(notests, bool, 0644);
45MODULE_PARM_DESC(notests, "disable crypto self-tests");
46
Eric Biggers5b2706a2019-01-31 23:51:44 -080047#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
48static bool noextratests;
49module_param(noextratests, bool, 0644);
50MODULE_PARM_DESC(noextratests, "disable expensive crypto self-tests");
51
52static unsigned int fuzz_iterations = 100;
53module_param(fuzz_iterations, uint, 0644);
54MODULE_PARM_DESC(fuzz_iterations, "number of fuzz test iterations");
55#endif
56
Herbert Xu326a6342010-08-06 09:40:28 +080057#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
Alexander Shishkin0b767f92010-06-03 20:53:43 +100058
59/* a perfect nop */
60int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
61{
62 return 0;
63}
64
65#else
66
Herbert Xuda7f0332008-07-31 17:08:25 +080067#include "testmgr.h"
68
69/*
70 * Need slab memory for testing (size in number of pages).
71 */
72#define XBUFSIZE 8
73
74/*
75 * Indexes into the xbuf to simulate cross-page access.
76 */
77#define IDX1 32
78#define IDX2 32400
Ard Biesheuvel04b46fb2016-12-08 08:23:52 +000079#define IDX3 1511
Herbert Xuda7f0332008-07-31 17:08:25 +080080#define IDX4 8193
81#define IDX5 22222
82#define IDX6 17101
83#define IDX7 27333
84#define IDX8 3000
85
86/*
87* Used by test_cipher()
88*/
89#define ENCRYPT 1
90#define DECRYPT 0
91
Herbert Xuda7f0332008-07-31 17:08:25 +080092struct aead_test_suite {
Eric Biggersa0d608ee2019-01-13 15:32:28 -080093 const struct aead_testvec *vecs;
94 unsigned int count;
Herbert Xuda7f0332008-07-31 17:08:25 +080095};
96
97struct cipher_test_suite {
Eric Biggers92a4c9f2018-05-20 22:50:29 -070098 const struct cipher_testvec *vecs;
99 unsigned int count;
Herbert Xuda7f0332008-07-31 17:08:25 +0800100};
101
102struct comp_test_suite {
103 struct {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800104 const struct comp_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +0800105 unsigned int count;
106 } comp, decomp;
107};
108
109struct hash_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800110 const struct hash_testvec *vecs;
Herbert Xuda7f0332008-07-31 17:08:25 +0800111 unsigned int count;
112};
113
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800114struct cprng_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800115 const struct cprng_testvec *vecs;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800116 unsigned int count;
117};
118
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200119struct drbg_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800120 const struct drbg_testvec *vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200121 unsigned int count;
122};
123
Tadeusz Struk946cc462015-06-16 10:31:06 -0700124struct akcipher_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800125 const struct akcipher_testvec *vecs;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700126 unsigned int count;
127};
128
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100129struct kpp_test_suite {
Eric Biggersb13b1e02017-02-24 15:46:59 -0800130 const struct kpp_testvec *vecs;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100131 unsigned int count;
132};
133
Herbert Xuda7f0332008-07-31 17:08:25 +0800134struct alg_test_desc {
135 const char *alg;
136 int (*test)(const struct alg_test_desc *desc, const char *driver,
137 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000138 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800139
140 union {
141 struct aead_test_suite aead;
142 struct cipher_test_suite cipher;
143 struct comp_test_suite comp;
144 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800145 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200146 struct drbg_test_suite drbg;
Tadeusz Struk946cc462015-06-16 10:31:06 -0700147 struct akcipher_test_suite akcipher;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +0100148 struct kpp_test_suite kpp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800149 } suite;
150};
151
Eric Biggersb13b1e02017-02-24 15:46:59 -0800152static const unsigned int IDX[8] = {
153 IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
Herbert Xuda7f0332008-07-31 17:08:25 +0800154
Herbert Xuda7f0332008-07-31 17:08:25 +0800155static void hexdump(unsigned char *buf, unsigned int len)
156{
157 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
158 16, 1,
159 buf, len, false);
160}
161
Eric Biggers3f47a032019-01-31 23:51:43 -0800162static int __testmgr_alloc_buf(char *buf[XBUFSIZE], int order)
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800163{
164 int i;
165
166 for (i = 0; i < XBUFSIZE; i++) {
Eric Biggers3f47a032019-01-31 23:51:43 -0800167 buf[i] = (char *)__get_free_pages(GFP_KERNEL, order);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800168 if (!buf[i])
169 goto err_free_buf;
170 }
171
172 return 0;
173
174err_free_buf:
175 while (i-- > 0)
Eric Biggers3f47a032019-01-31 23:51:43 -0800176 free_pages((unsigned long)buf[i], order);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800177
178 return -ENOMEM;
179}
180
Eric Biggers3f47a032019-01-31 23:51:43 -0800181static int testmgr_alloc_buf(char *buf[XBUFSIZE])
182{
183 return __testmgr_alloc_buf(buf, 0);
184}
185
186static void __testmgr_free_buf(char *buf[XBUFSIZE], int order)
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800187{
188 int i;
189
190 for (i = 0; i < XBUFSIZE; i++)
Eric Biggers3f47a032019-01-31 23:51:43 -0800191 free_pages((unsigned long)buf[i], order);
192}
193
194static void testmgr_free_buf(char *buf[XBUFSIZE])
195{
196 __testmgr_free_buf(buf, 0);
197}
198
199#define TESTMGR_POISON_BYTE 0xfe
200#define TESTMGR_POISON_LEN 16
201
202static inline void testmgr_poison(void *addr, size_t len)
203{
204 memset(addr, TESTMGR_POISON_BYTE, len);
205}
206
207/* Is the memory region still fully poisoned? */
208static inline bool testmgr_is_poison(const void *addr, size_t len)
209{
210 return memchr_inv(addr, TESTMGR_POISON_BYTE, len) == NULL;
211}
212
213/* flush type for hash algorithms */
214enum flush_type {
215 /* merge with update of previous buffer(s) */
216 FLUSH_TYPE_NONE = 0,
217
218 /* update with previous buffer(s) before doing this one */
219 FLUSH_TYPE_FLUSH,
220
221 /* likewise, but also export and re-import the intermediate state */
222 FLUSH_TYPE_REIMPORT,
223};
224
225/* finalization function for hash algorithms */
226enum finalization_type {
227 FINALIZATION_TYPE_FINAL, /* use final() */
228 FINALIZATION_TYPE_FINUP, /* use finup() */
229 FINALIZATION_TYPE_DIGEST, /* use digest() */
230};
231
232#define TEST_SG_TOTAL 10000
233
234/**
235 * struct test_sg_division - description of a scatterlist entry
236 *
237 * This struct describes one entry of a scatterlist being constructed to check a
238 * crypto test vector.
239 *
240 * @proportion_of_total: length of this chunk relative to the total length,
241 * given as a proportion out of TEST_SG_TOTAL so that it
242 * scales to fit any test vector
243 * @offset: byte offset into a 2-page buffer at which this chunk will start
244 * @offset_relative_to_alignmask: if true, add the algorithm's alignmask to the
245 * @offset
246 * @flush_type: for hashes, whether an update() should be done now vs.
247 * continuing to accumulate data
248 */
249struct test_sg_division {
250 unsigned int proportion_of_total;
251 unsigned int offset;
252 bool offset_relative_to_alignmask;
253 enum flush_type flush_type;
254};
255
256/**
257 * struct testvec_config - configuration for testing a crypto test vector
258 *
259 * This struct describes the data layout and other parameters with which each
260 * crypto test vector can be tested.
261 *
262 * @name: name of this config, logged for debugging purposes if a test fails
263 * @inplace: operate on the data in-place, if applicable for the algorithm type?
264 * @req_flags: extra request_flags, e.g. CRYPTO_TFM_REQ_MAY_SLEEP
265 * @src_divs: description of how to arrange the source scatterlist
266 * @dst_divs: description of how to arrange the dst scatterlist, if applicable
267 * for the algorithm type. Defaults to @src_divs if unset.
268 * @iv_offset: misalignment of the IV in the range [0..MAX_ALGAPI_ALIGNMASK+1],
269 * where 0 is aligned to a 2*(MAX_ALGAPI_ALIGNMASK+1) byte boundary
270 * @iv_offset_relative_to_alignmask: if true, add the algorithm's alignmask to
271 * the @iv_offset
272 * @finalization_type: what finalization function to use for hashes
273 */
274struct testvec_config {
275 const char *name;
276 bool inplace;
277 u32 req_flags;
278 struct test_sg_division src_divs[XBUFSIZE];
279 struct test_sg_division dst_divs[XBUFSIZE];
280 unsigned int iv_offset;
281 bool iv_offset_relative_to_alignmask;
282 enum finalization_type finalization_type;
283};
284
285#define TESTVEC_CONFIG_NAMELEN 192
286
Eric Biggers4e7babba2019-01-31 23:51:46 -0800287/*
288 * The following are the lists of testvec_configs to test for each algorithm
289 * type when the basic crypto self-tests are enabled, i.e. when
290 * CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is unset. They aim to provide good test
291 * coverage, while keeping the test time much shorter than the full fuzz tests
292 * so that the basic tests can be enabled in a wider range of circumstances.
293 */
294
295/* Configs for skciphers and aeads */
296static const struct testvec_config default_cipher_testvec_configs[] = {
297 {
298 .name = "in-place",
299 .inplace = true,
300 .src_divs = { { .proportion_of_total = 10000 } },
301 }, {
302 .name = "out-of-place",
303 .src_divs = { { .proportion_of_total = 10000 } },
304 }, {
305 .name = "unaligned buffer, offset=1",
306 .src_divs = { { .proportion_of_total = 10000, .offset = 1 } },
307 .iv_offset = 1,
308 }, {
309 .name = "buffer aligned only to alignmask",
310 .src_divs = {
311 {
312 .proportion_of_total = 10000,
313 .offset = 1,
314 .offset_relative_to_alignmask = true,
315 },
316 },
317 .iv_offset = 1,
318 .iv_offset_relative_to_alignmask = true,
319 }, {
320 .name = "two even aligned splits",
321 .src_divs = {
322 { .proportion_of_total = 5000 },
323 { .proportion_of_total = 5000 },
324 },
325 }, {
326 .name = "uneven misaligned splits, may sleep",
327 .req_flags = CRYPTO_TFM_REQ_MAY_SLEEP,
328 .src_divs = {
329 { .proportion_of_total = 1900, .offset = 33 },
330 { .proportion_of_total = 3300, .offset = 7 },
331 { .proportion_of_total = 4800, .offset = 18 },
332 },
333 .iv_offset = 3,
334 }, {
335 .name = "misaligned splits crossing pages, inplace",
336 .inplace = true,
337 .src_divs = {
338 {
339 .proportion_of_total = 7500,
340 .offset = PAGE_SIZE - 32
341 }, {
342 .proportion_of_total = 2500,
343 .offset = PAGE_SIZE - 7
344 },
345 },
346 }
347};
348
Eric Biggers3f47a032019-01-31 23:51:43 -0800349static unsigned int count_test_sg_divisions(const struct test_sg_division *divs)
350{
351 unsigned int remaining = TEST_SG_TOTAL;
352 unsigned int ndivs = 0;
353
354 do {
355 remaining -= divs[ndivs++].proportion_of_total;
356 } while (remaining);
357
358 return ndivs;
359}
360
361static bool valid_sg_divisions(const struct test_sg_division *divs,
362 unsigned int count, bool *any_flushes_ret)
363{
364 unsigned int total = 0;
365 unsigned int i;
366
367 for (i = 0; i < count && total != TEST_SG_TOTAL; i++) {
368 if (divs[i].proportion_of_total <= 0 ||
369 divs[i].proportion_of_total > TEST_SG_TOTAL - total)
370 return false;
371 total += divs[i].proportion_of_total;
372 if (divs[i].flush_type != FLUSH_TYPE_NONE)
373 *any_flushes_ret = true;
374 }
375 return total == TEST_SG_TOTAL &&
376 memchr_inv(&divs[i], 0, (count - i) * sizeof(divs[0])) == NULL;
377}
378
379/*
380 * Check whether the given testvec_config is valid. This isn't strictly needed
381 * since every testvec_config should be valid, but check anyway so that people
382 * don't unknowingly add broken configs that don't do what they wanted.
383 */
384static bool valid_testvec_config(const struct testvec_config *cfg)
385{
386 bool any_flushes = false;
387
388 if (cfg->name == NULL)
389 return false;
390
391 if (!valid_sg_divisions(cfg->src_divs, ARRAY_SIZE(cfg->src_divs),
392 &any_flushes))
393 return false;
394
395 if (cfg->dst_divs[0].proportion_of_total) {
396 if (!valid_sg_divisions(cfg->dst_divs,
397 ARRAY_SIZE(cfg->dst_divs),
398 &any_flushes))
399 return false;
400 } else {
401 if (memchr_inv(cfg->dst_divs, 0, sizeof(cfg->dst_divs)))
402 return false;
403 /* defaults to dst_divs=src_divs */
404 }
405
406 if (cfg->iv_offset +
407 (cfg->iv_offset_relative_to_alignmask ? MAX_ALGAPI_ALIGNMASK : 0) >
408 MAX_ALGAPI_ALIGNMASK + 1)
409 return false;
410
411 if (any_flushes && cfg->finalization_type == FINALIZATION_TYPE_DIGEST)
412 return false;
413
414 return true;
415}
416
417struct test_sglist {
418 char *bufs[XBUFSIZE];
419 struct scatterlist sgl[XBUFSIZE];
420 struct scatterlist sgl_saved[XBUFSIZE];
421 struct scatterlist *sgl_ptr;
422 unsigned int nents;
423};
424
425static int init_test_sglist(struct test_sglist *tsgl)
426{
427 return __testmgr_alloc_buf(tsgl->bufs, 1 /* two pages per buffer */);
428}
429
430static void destroy_test_sglist(struct test_sglist *tsgl)
431{
432 return __testmgr_free_buf(tsgl->bufs, 1 /* two pages per buffer */);
433}
434
435/**
436 * build_test_sglist() - build a scatterlist for a crypto test
437 *
438 * @tsgl: the scatterlist to build. @tsgl->bufs[] contains an array of 2-page
439 * buffers which the scatterlist @tsgl->sgl[] will be made to point into.
440 * @divs: the layout specification on which the scatterlist will be based
441 * @alignmask: the algorithm's alignmask
442 * @total_len: the total length of the scatterlist to build in bytes
443 * @data: if non-NULL, the buffers will be filled with this data until it ends.
444 * Otherwise the buffers will be poisoned. In both cases, some bytes
445 * past the end of each buffer will be poisoned to help detect overruns.
446 * @out_divs: if non-NULL, the test_sg_division to which each scatterlist entry
447 * corresponds will be returned here. This will match @divs except
448 * that divisions resolving to a length of 0 are omitted as they are
449 * not included in the scatterlist.
450 *
451 * Return: 0 or a -errno value
452 */
453static int build_test_sglist(struct test_sglist *tsgl,
454 const struct test_sg_division *divs,
455 const unsigned int alignmask,
456 const unsigned int total_len,
457 struct iov_iter *data,
458 const struct test_sg_division *out_divs[XBUFSIZE])
459{
460 struct {
461 const struct test_sg_division *div;
462 size_t length;
463 } partitions[XBUFSIZE];
464 const unsigned int ndivs = count_test_sg_divisions(divs);
465 unsigned int len_remaining = total_len;
466 unsigned int i;
467
468 BUILD_BUG_ON(ARRAY_SIZE(partitions) != ARRAY_SIZE(tsgl->sgl));
469 if (WARN_ON(ndivs > ARRAY_SIZE(partitions)))
470 return -EINVAL;
471
472 /* Calculate the (div, length) pairs */
473 tsgl->nents = 0;
474 for (i = 0; i < ndivs; i++) {
475 unsigned int len_this_sg =
476 min(len_remaining,
477 (total_len * divs[i].proportion_of_total +
478 TEST_SG_TOTAL / 2) / TEST_SG_TOTAL);
479
480 if (len_this_sg != 0) {
481 partitions[tsgl->nents].div = &divs[i];
482 partitions[tsgl->nents].length = len_this_sg;
483 tsgl->nents++;
484 len_remaining -= len_this_sg;
485 }
486 }
487 if (tsgl->nents == 0) {
488 partitions[tsgl->nents].div = &divs[0];
489 partitions[tsgl->nents].length = 0;
490 tsgl->nents++;
491 }
492 partitions[tsgl->nents - 1].length += len_remaining;
493
494 /* Set up the sgl entries and fill the data or poison */
495 sg_init_table(tsgl->sgl, tsgl->nents);
496 for (i = 0; i < tsgl->nents; i++) {
497 unsigned int offset = partitions[i].div->offset;
498 void *addr;
499
500 if (partitions[i].div->offset_relative_to_alignmask)
501 offset += alignmask;
502
503 while (offset + partitions[i].length + TESTMGR_POISON_LEN >
504 2 * PAGE_SIZE) {
505 if (WARN_ON(offset <= 0))
506 return -EINVAL;
507 offset /= 2;
508 }
509
510 addr = &tsgl->bufs[i][offset];
511 sg_set_buf(&tsgl->sgl[i], addr, partitions[i].length);
512
513 if (out_divs)
514 out_divs[i] = partitions[i].div;
515
516 if (data) {
517 size_t copy_len, copied;
518
519 copy_len = min(partitions[i].length, data->count);
520 copied = copy_from_iter(addr, copy_len, data);
521 if (WARN_ON(copied != copy_len))
522 return -EINVAL;
523 testmgr_poison(addr + copy_len, partitions[i].length +
524 TESTMGR_POISON_LEN - copy_len);
525 } else {
526 testmgr_poison(addr, partitions[i].length +
527 TESTMGR_POISON_LEN);
528 }
529 }
530
531 sg_mark_end(&tsgl->sgl[tsgl->nents - 1]);
532 tsgl->sgl_ptr = tsgl->sgl;
533 memcpy(tsgl->sgl_saved, tsgl->sgl, tsgl->nents * sizeof(tsgl->sgl[0]));
534 return 0;
535}
536
537/*
538 * Verify that a scatterlist crypto operation produced the correct output.
539 *
540 * @tsgl: scatterlist containing the actual output
541 * @expected_output: buffer containing the expected output
542 * @len_to_check: length of @expected_output in bytes
543 * @unchecked_prefix_len: number of ignored bytes in @tsgl prior to real result
544 * @check_poison: verify that the poison bytes after each chunk are intact?
545 *
546 * Return: 0 if correct, -EINVAL if incorrect, -EOVERFLOW if buffer overrun.
547 */
548static int verify_correct_output(const struct test_sglist *tsgl,
549 const char *expected_output,
550 unsigned int len_to_check,
551 unsigned int unchecked_prefix_len,
552 bool check_poison)
553{
554 unsigned int i;
555
556 for (i = 0; i < tsgl->nents; i++) {
557 struct scatterlist *sg = &tsgl->sgl_ptr[i];
558 unsigned int len = sg->length;
559 unsigned int offset = sg->offset;
560 const char *actual_output;
561
562 if (unchecked_prefix_len) {
563 if (unchecked_prefix_len >= len) {
564 unchecked_prefix_len -= len;
565 continue;
566 }
567 offset += unchecked_prefix_len;
568 len -= unchecked_prefix_len;
569 unchecked_prefix_len = 0;
570 }
571 len = min(len, len_to_check);
572 actual_output = page_address(sg_page(sg)) + offset;
573 if (memcmp(expected_output, actual_output, len) != 0)
574 return -EINVAL;
575 if (check_poison &&
576 !testmgr_is_poison(actual_output + len, TESTMGR_POISON_LEN))
577 return -EOVERFLOW;
578 len_to_check -= len;
579 expected_output += len;
580 }
581 if (WARN_ON(len_to_check != 0))
582 return -EINVAL;
583 return 0;
584}
585
586static bool is_test_sglist_corrupted(const struct test_sglist *tsgl)
587{
588 unsigned int i;
589
590 for (i = 0; i < tsgl->nents; i++) {
591 if (tsgl->sgl[i].page_link != tsgl->sgl_saved[i].page_link)
592 return true;
593 if (tsgl->sgl[i].offset != tsgl->sgl_saved[i].offset)
594 return true;
595 if (tsgl->sgl[i].length != tsgl->sgl_saved[i].length)
596 return true;
597 }
598 return false;
599}
600
601struct cipher_test_sglists {
602 struct test_sglist src;
603 struct test_sglist dst;
604};
605
606static struct cipher_test_sglists *alloc_cipher_test_sglists(void)
607{
608 struct cipher_test_sglists *tsgls;
609
610 tsgls = kmalloc(sizeof(*tsgls), GFP_KERNEL);
611 if (!tsgls)
612 return NULL;
613
614 if (init_test_sglist(&tsgls->src) != 0)
615 goto fail_kfree;
616 if (init_test_sglist(&tsgls->dst) != 0)
617 goto fail_destroy_src;
618
619 return tsgls;
620
621fail_destroy_src:
622 destroy_test_sglist(&tsgls->src);
623fail_kfree:
624 kfree(tsgls);
625 return NULL;
626}
627
628static void free_cipher_test_sglists(struct cipher_test_sglists *tsgls)
629{
630 if (tsgls) {
631 destroy_test_sglist(&tsgls->src);
632 destroy_test_sglist(&tsgls->dst);
633 kfree(tsgls);
634 }
635}
636
637/* Build the src and dst scatterlists for an skcipher or AEAD test */
638static int build_cipher_test_sglists(struct cipher_test_sglists *tsgls,
639 const struct testvec_config *cfg,
640 unsigned int alignmask,
641 unsigned int src_total_len,
642 unsigned int dst_total_len,
643 const struct kvec *inputs,
644 unsigned int nr_inputs)
645{
646 struct iov_iter input;
647 int err;
648
649 iov_iter_kvec(&input, WRITE, inputs, nr_inputs, src_total_len);
650 err = build_test_sglist(&tsgls->src, cfg->src_divs, alignmask,
651 cfg->inplace ?
652 max(dst_total_len, src_total_len) :
653 src_total_len,
654 &input, NULL);
655 if (err)
656 return err;
657
658 if (cfg->inplace) {
659 tsgls->dst.sgl_ptr = tsgls->src.sgl;
660 tsgls->dst.nents = tsgls->src.nents;
661 return 0;
662 }
663 return build_test_sglist(&tsgls->dst,
664 cfg->dst_divs[0].proportion_of_total ?
665 cfg->dst_divs : cfg->src_divs,
666 alignmask, dst_total_len, NULL, NULL);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800667}
668
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800669#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
670static char *generate_random_sgl_divisions(struct test_sg_division *divs,
671 size_t max_divs, char *p, char *end,
672 bool gen_flushes)
673{
674 struct test_sg_division *div = divs;
675 unsigned int remaining = TEST_SG_TOTAL;
676
677 do {
678 unsigned int this_len;
679
680 if (div == &divs[max_divs - 1] || prandom_u32() % 2 == 0)
681 this_len = remaining;
682 else
683 this_len = 1 + (prandom_u32() % remaining);
684 div->proportion_of_total = this_len;
685
686 if (prandom_u32() % 4 == 0)
687 div->offset = (PAGE_SIZE - 128) + (prandom_u32() % 128);
688 else if (prandom_u32() % 2 == 0)
689 div->offset = prandom_u32() % 32;
690 else
691 div->offset = prandom_u32() % PAGE_SIZE;
692 if (prandom_u32() % 8 == 0)
693 div->offset_relative_to_alignmask = true;
694
695 div->flush_type = FLUSH_TYPE_NONE;
696 if (gen_flushes) {
697 switch (prandom_u32() % 4) {
698 case 0:
699 div->flush_type = FLUSH_TYPE_REIMPORT;
700 break;
701 case 1:
702 div->flush_type = FLUSH_TYPE_FLUSH;
703 break;
704 }
705 }
706
707 BUILD_BUG_ON(TEST_SG_TOTAL != 10000); /* for "%u.%u%%" */
708 p += scnprintf(p, end - p, "%s%u.%u%%@%s+%u%s",
709 div->flush_type == FLUSH_TYPE_NONE ? "" :
710 div->flush_type == FLUSH_TYPE_FLUSH ?
711 "<flush> " : "<reimport> ",
712 this_len / 100, this_len % 100,
713 div->offset_relative_to_alignmask ?
714 "alignmask" : "",
715 div->offset, this_len == remaining ? "" : ", ");
716 remaining -= this_len;
717 div++;
718 } while (remaining);
719
720 return p;
721}
722
723/* Generate a random testvec_config for fuzz testing */
724static void generate_random_testvec_config(struct testvec_config *cfg,
725 char *name, size_t max_namelen)
726{
727 char *p = name;
728 char * const end = name + max_namelen;
729
730 memset(cfg, 0, sizeof(*cfg));
731
732 cfg->name = name;
733
734 p += scnprintf(p, end - p, "random:");
735
736 if (prandom_u32() % 2 == 0) {
737 cfg->inplace = true;
738 p += scnprintf(p, end - p, " inplace");
739 }
740
741 if (prandom_u32() % 2 == 0) {
742 cfg->req_flags |= CRYPTO_TFM_REQ_MAY_SLEEP;
743 p += scnprintf(p, end - p, " may_sleep");
744 }
745
746 switch (prandom_u32() % 4) {
747 case 0:
748 cfg->finalization_type = FINALIZATION_TYPE_FINAL;
749 p += scnprintf(p, end - p, " use_final");
750 break;
751 case 1:
752 cfg->finalization_type = FINALIZATION_TYPE_FINUP;
753 p += scnprintf(p, end - p, " use_finup");
754 break;
755 default:
756 cfg->finalization_type = FINALIZATION_TYPE_DIGEST;
757 p += scnprintf(p, end - p, " use_digest");
758 break;
759 }
760
761 p += scnprintf(p, end - p, " src_divs=[");
762 p = generate_random_sgl_divisions(cfg->src_divs,
763 ARRAY_SIZE(cfg->src_divs), p, end,
764 (cfg->finalization_type !=
765 FINALIZATION_TYPE_DIGEST));
766 p += scnprintf(p, end - p, "]");
767
768 if (!cfg->inplace && prandom_u32() % 2 == 0) {
769 p += scnprintf(p, end - p, " dst_divs=[");
770 p = generate_random_sgl_divisions(cfg->dst_divs,
771 ARRAY_SIZE(cfg->dst_divs),
772 p, end, false);
773 p += scnprintf(p, end - p, "]");
774 }
775
776 if (prandom_u32() % 2 == 0) {
777 cfg->iv_offset = 1 + (prandom_u32() % MAX_ALGAPI_ALIGNMASK);
778 p += scnprintf(p, end - p, " iv_offset=%u", cfg->iv_offset);
779 }
780
781 WARN_ON_ONCE(!valid_testvec_config(cfg));
782}
783#endif /* CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
784
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100785static int ahash_guard_result(char *result, char c, int size)
786{
787 int i;
788
789 for (i = 0; i < size; i++) {
790 if (result[i] != c)
791 return -EINVAL;
792 }
793
794 return 0;
795}
796
Wang, Rui Y018ba952016-02-03 18:26:57 +0800797static int ahash_partial_update(struct ahash_request **preq,
Eric Biggersb13b1e02017-02-24 15:46:59 -0800798 struct crypto_ahash *tfm, const struct hash_testvec *template,
Wang, Rui Y018ba952016-02-03 18:26:57 +0800799 void *hash_buff, int k, int temp, struct scatterlist *sg,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100800 const char *algo, char *result, struct crypto_wait *wait)
Wang, Rui Y018ba952016-02-03 18:26:57 +0800801{
802 char *state;
803 struct ahash_request *req;
804 int statesize, ret = -EINVAL;
Joey Pabalinasda1729c2018-01-01 10:40:14 -1000805 static const unsigned char guard[] = { 0x00, 0xba, 0xad, 0x00 };
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100806 int digestsize = crypto_ahash_digestsize(tfm);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800807
808 req = *preq;
809 statesize = crypto_ahash_statesize(
810 crypto_ahash_reqtfm(req));
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200811 state = kmalloc(statesize + sizeof(guard), GFP_KERNEL);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800812 if (!state) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300813 pr_err("alg: hash: Failed to alloc state for %s\n", algo);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800814 goto out_nostate;
815 }
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200816 memcpy(state + statesize, guard, sizeof(guard));
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100817 memset(result, 1, digestsize);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800818 ret = crypto_ahash_export(req, state);
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200819 WARN_ON(memcmp(state + statesize, guard, sizeof(guard)));
Wang, Rui Y018ba952016-02-03 18:26:57 +0800820 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300821 pr_err("alg: hash: Failed to export() for %s\n", algo);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800822 goto out;
823 }
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100824 ret = ahash_guard_result(result, 1, digestsize);
825 if (ret) {
826 pr_err("alg: hash: Failed, export used req->result for %s\n",
827 algo);
828 goto out;
829 }
Wang, Rui Y018ba952016-02-03 18:26:57 +0800830 ahash_request_free(req);
831 req = ahash_request_alloc(tfm, GFP_KERNEL);
832 if (!req) {
833 pr_err("alg: hash: Failed to alloc request for %s\n", algo);
834 goto out_noreq;
835 }
836 ahash_request_set_callback(req,
837 CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100838 crypto_req_done, wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800839
840 memcpy(hash_buff, template->plaintext + temp,
841 template->tap[k]);
842 sg_init_one(&sg[0], hash_buff, template->tap[k]);
843 ahash_request_set_crypt(req, sg, result, template->tap[k]);
844 ret = crypto_ahash_import(req, state);
845 if (ret) {
846 pr_err("alg: hash: Failed to import() for %s\n", algo);
847 goto out;
848 }
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100849 ret = ahash_guard_result(result, 1, digestsize);
850 if (ret) {
851 pr_err("alg: hash: Failed, import used req->result for %s\n",
852 algo);
853 goto out;
854 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100855 ret = crypto_wait_req(crypto_ahash_update(req), wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800856 if (ret)
857 goto out;
858 *preq = req;
859 ret = 0;
860 goto out_noreq;
861out:
862 ahash_request_free(req);
863out_noreq:
864 kfree(state);
865out_nostate:
866 return ret;
867}
868
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100869enum hash_test {
870 HASH_TEST_DIGEST,
871 HASH_TEST_FINAL,
872 HASH_TEST_FINUP
873};
874
Eric Biggersb13b1e02017-02-24 15:46:59 -0800875static int __test_hash(struct crypto_ahash *tfm,
876 const struct hash_testvec *template, unsigned int tcount,
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100877 enum hash_test test_type, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800878{
879 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800880 size_t digest_size = crypto_ahash_digestsize(tfm);
Herbert Xuda7f0332008-07-31 17:08:25 +0800881 unsigned int i, j, k, temp;
882 struct scatterlist sg[8];
Horia Geanta29b77e52014-07-23 11:59:38 +0300883 char *result;
884 char *key;
Herbert Xuda7f0332008-07-31 17:08:25 +0800885 struct ahash_request *req;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100886 struct crypto_wait wait;
Herbert Xuda7f0332008-07-31 17:08:25 +0800887 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800888 char *xbuf[XBUFSIZE];
889 int ret = -ENOMEM;
890
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800891 result = kmalloc(digest_size, GFP_KERNEL);
Horia Geanta29b77e52014-07-23 11:59:38 +0300892 if (!result)
893 return ret;
894 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
895 if (!key)
896 goto out_nobuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800897 if (testmgr_alloc_buf(xbuf))
898 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800899
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100900 crypto_init_wait(&wait);
Herbert Xuda7f0332008-07-31 17:08:25 +0800901
902 req = ahash_request_alloc(tfm, GFP_KERNEL);
903 if (!req) {
904 printk(KERN_ERR "alg: hash: Failed to allocate request for "
905 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800906 goto out_noreq;
907 }
908 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100909 crypto_req_done, &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +0800910
Herbert Xua0cfae52009-05-29 16:23:12 +1000911 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800912 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000913 if (template[i].np)
914 continue;
915
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300916 ret = -EINVAL;
917 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
918 goto out;
919
Herbert Xua0cfae52009-05-29 16:23:12 +1000920 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800921 memset(result, 0, digest_size);
Herbert Xuda7f0332008-07-31 17:08:25 +0800922
923 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300924 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800925
926 memcpy(hash_buff, template[i].plaintext, template[i].psize);
927 sg_init_one(&sg[0], hash_buff, template[i].psize);
928
929 if (template[i].ksize) {
930 crypto_ahash_clear_flags(tfm, ~0);
Horia Geanta29b77e52014-07-23 11:59:38 +0300931 if (template[i].ksize > MAX_KEYLEN) {
932 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
933 j, algo, template[i].ksize, MAX_KEYLEN);
934 ret = -EINVAL;
935 goto out;
936 }
937 memcpy(key, template[i].key, template[i].ksize);
938 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
Herbert Xuda7f0332008-07-31 17:08:25 +0800939 if (ret) {
940 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000941 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800942 -ret);
943 goto out;
944 }
945 }
946
947 ahash_request_set_crypt(req, sg, result, template[i].psize);
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100948 switch (test_type) {
949 case HASH_TEST_DIGEST:
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100950 ret = crypto_wait_req(crypto_ahash_digest(req), &wait);
David S. Millera8f1a052010-05-19 14:12:03 +1000951 if (ret) {
952 pr_err("alg: hash: digest failed on test %d "
953 "for %s: ret=%d\n", j, algo, -ret);
954 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800955 }
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100956 break;
957
958 case HASH_TEST_FINAL:
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100959 memset(result, 1, digest_size);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100960 ret = crypto_wait_req(crypto_ahash_init(req), &wait);
David S. Millera8f1a052010-05-19 14:12:03 +1000961 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300962 pr_err("alg: hash: init failed on test %d "
David S. Millera8f1a052010-05-19 14:12:03 +1000963 "for %s: ret=%d\n", j, algo, -ret);
964 goto out;
965 }
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100966 ret = ahash_guard_result(result, 1, digest_size);
967 if (ret) {
968 pr_err("alg: hash: init failed on test %d "
969 "for %s: used req->result\n", j, algo);
970 goto out;
971 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100972 ret = crypto_wait_req(crypto_ahash_update(req), &wait);
David S. Millera8f1a052010-05-19 14:12:03 +1000973 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300974 pr_err("alg: hash: update failed on test %d "
David S. Millera8f1a052010-05-19 14:12:03 +1000975 "for %s: ret=%d\n", j, algo, -ret);
976 goto out;
977 }
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100978 ret = ahash_guard_result(result, 1, digest_size);
979 if (ret) {
980 pr_err("alg: hash: update failed on test %d "
981 "for %s: used req->result\n", j, algo);
982 goto out;
983 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100984 ret = crypto_wait_req(crypto_ahash_final(req), &wait);
David S. Millera8f1a052010-05-19 14:12:03 +1000985 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300986 pr_err("alg: hash: final failed on test %d "
David S. Millera8f1a052010-05-19 14:12:03 +1000987 "for %s: ret=%d\n", j, algo, -ret);
988 goto out;
989 }
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100990 break;
991
992 case HASH_TEST_FINUP:
993 memset(result, 1, digest_size);
994 ret = crypto_wait_req(crypto_ahash_init(req), &wait);
995 if (ret) {
996 pr_err("alg: hash: init failed on test %d "
997 "for %s: ret=%d\n", j, algo, -ret);
998 goto out;
999 }
1000 ret = ahash_guard_result(result, 1, digest_size);
1001 if (ret) {
1002 pr_err("alg: hash: init failed on test %d "
1003 "for %s: used req->result\n", j, algo);
1004 goto out;
1005 }
1006 ret = crypto_wait_req(crypto_ahash_finup(req), &wait);
1007 if (ret) {
1008 pr_err("alg: hash: final failed on test %d "
1009 "for %s: ret=%d\n", j, algo, -ret);
1010 goto out;
1011 }
1012 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001013 }
1014
1015 if (memcmp(result, template[i].digest,
1016 crypto_ahash_digestsize(tfm))) {
1017 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +10001018 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +08001019 hexdump(result, crypto_ahash_digestsize(tfm));
1020 ret = -EINVAL;
1021 goto out;
1022 }
1023 }
1024
Gilad Ben-Yossef76715092018-07-01 08:02:35 +01001025 if (test_type)
1026 goto out;
1027
Herbert Xuda7f0332008-07-31 17:08:25 +08001028 j = 0;
1029 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +03001030 /* alignment tests are only done with continuous buffers */
1031 if (align_offset != 0)
1032 break;
1033
Cristian Stoica5f2b4242014-08-08 14:27:50 +03001034 if (!template[i].np)
1035 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +08001036
Cristian Stoica5f2b4242014-08-08 14:27:50 +03001037 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -08001038 memset(result, 0, digest_size);
Herbert Xuda7f0332008-07-31 17:08:25 +08001039
Cristian Stoica5f2b4242014-08-08 14:27:50 +03001040 temp = 0;
1041 sg_init_table(sg, template[i].np);
1042 ret = -EINVAL;
1043 for (k = 0; k < template[i].np; k++) {
1044 if (WARN_ON(offset_in_page(IDX[k]) +
1045 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001046 goto out;
Cristian Stoica5f2b4242014-08-08 14:27:50 +03001047 sg_set_buf(&sg[k],
1048 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
1049 offset_in_page(IDX[k]),
1050 template[i].plaintext + temp,
1051 template[i].tap[k]),
1052 template[i].tap[k]);
1053 temp += template[i].tap[k];
1054 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001055
Cristian Stoica5f2b4242014-08-08 14:27:50 +03001056 if (template[i].ksize) {
1057 if (template[i].ksize > MAX_KEYLEN) {
1058 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
1059 j, algo, template[i].ksize, MAX_KEYLEN);
Herbert Xuda7f0332008-07-31 17:08:25 +08001060 ret = -EINVAL;
1061 goto out;
1062 }
Cristian Stoica5f2b4242014-08-08 14:27:50 +03001063 crypto_ahash_clear_flags(tfm, ~0);
1064 memcpy(key, template[i].key, template[i].ksize);
1065 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
1066
1067 if (ret) {
1068 printk(KERN_ERR "alg: hash: setkey "
1069 "failed on chunking test %d "
1070 "for %s: ret=%d\n", j, algo, -ret);
1071 goto out;
1072 }
1073 }
1074
1075 ahash_request_set_crypt(req, sg, result, template[i].psize);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001076 ret = crypto_wait_req(crypto_ahash_digest(req), &wait);
1077 if (ret) {
1078 pr_err("alg: hash: digest failed on chunking test %d for %s: ret=%d\n",
1079 j, algo, -ret);
Cristian Stoica5f2b4242014-08-08 14:27:50 +03001080 goto out;
1081 }
1082
1083 if (memcmp(result, template[i].digest,
1084 crypto_ahash_digestsize(tfm))) {
1085 printk(KERN_ERR "alg: hash: Chunking test %d "
1086 "failed for %s\n", j, algo);
1087 hexdump(result, crypto_ahash_digestsize(tfm));
1088 ret = -EINVAL;
1089 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001090 }
1091 }
1092
Wang, Rui Y018ba952016-02-03 18:26:57 +08001093 /* partial update exercise */
1094 j = 0;
1095 for (i = 0; i < tcount; i++) {
1096 /* alignment tests are only done with continuous buffers */
1097 if (align_offset != 0)
1098 break;
1099
1100 if (template[i].np < 2)
1101 continue;
1102
1103 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -08001104 memset(result, 0, digest_size);
Wang, Rui Y018ba952016-02-03 18:26:57 +08001105
1106 ret = -EINVAL;
1107 hash_buff = xbuf[0];
1108 memcpy(hash_buff, template[i].plaintext,
1109 template[i].tap[0]);
1110 sg_init_one(&sg[0], hash_buff, template[i].tap[0]);
1111
1112 if (template[i].ksize) {
1113 crypto_ahash_clear_flags(tfm, ~0);
1114 if (template[i].ksize > MAX_KEYLEN) {
1115 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
1116 j, algo, template[i].ksize, MAX_KEYLEN);
1117 ret = -EINVAL;
1118 goto out;
1119 }
1120 memcpy(key, template[i].key, template[i].ksize);
1121 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
1122 if (ret) {
1123 pr_err("alg: hash: setkey failed on test %d for %s: ret=%d\n",
1124 j, algo, -ret);
1125 goto out;
1126 }
1127 }
1128
1129 ahash_request_set_crypt(req, sg, result, template[i].tap[0]);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001130 ret = crypto_wait_req(crypto_ahash_init(req), &wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +08001131 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +03001132 pr_err("alg: hash: init failed on test %d for %s: ret=%d\n",
Wang, Rui Y018ba952016-02-03 18:26:57 +08001133 j, algo, -ret);
1134 goto out;
1135 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001136 ret = crypto_wait_req(crypto_ahash_update(req), &wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +08001137 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +03001138 pr_err("alg: hash: update failed on test %d for %s: ret=%d\n",
Wang, Rui Y018ba952016-02-03 18:26:57 +08001139 j, algo, -ret);
1140 goto out;
1141 }
1142
1143 temp = template[i].tap[0];
1144 for (k = 1; k < template[i].np; k++) {
1145 ret = ahash_partial_update(&req, tfm, &template[i],
1146 hash_buff, k, temp, &sg[0], algo, result,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001147 &wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +08001148 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +03001149 pr_err("alg: hash: partial update failed on test %d for %s: ret=%d\n",
Wang, Rui Y018ba952016-02-03 18:26:57 +08001150 j, algo, -ret);
1151 goto out_noreq;
1152 }
1153 temp += template[i].tap[k];
1154 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001155 ret = crypto_wait_req(crypto_ahash_final(req), &wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +08001156 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +03001157 pr_err("alg: hash: final failed on test %d for %s: ret=%d\n",
Wang, Rui Y018ba952016-02-03 18:26:57 +08001158 j, algo, -ret);
1159 goto out;
1160 }
1161 if (memcmp(result, template[i].digest,
1162 crypto_ahash_digestsize(tfm))) {
1163 pr_err("alg: hash: Partial Test %d failed for %s\n",
1164 j, algo);
1165 hexdump(result, crypto_ahash_digestsize(tfm));
1166 ret = -EINVAL;
1167 goto out;
1168 }
1169 }
1170
Herbert Xuda7f0332008-07-31 17:08:25 +08001171 ret = 0;
1172
1173out:
1174 ahash_request_free(req);
1175out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001176 testmgr_free_buf(xbuf);
1177out_nobuf:
Horia Geanta29b77e52014-07-23 11:59:38 +03001178 kfree(key);
1179 kfree(result);
Herbert Xuda7f0332008-07-31 17:08:25 +08001180 return ret;
1181}
1182
Eric Biggersb13b1e02017-02-24 15:46:59 -08001183static int test_hash(struct crypto_ahash *tfm,
1184 const struct hash_testvec *template,
Gilad Ben-Yossef76715092018-07-01 08:02:35 +01001185 unsigned int tcount, enum hash_test test_type)
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +03001186{
1187 unsigned int alignmask;
1188 int ret;
1189
Gilad Ben-Yossef76715092018-07-01 08:02:35 +01001190 ret = __test_hash(tfm, template, tcount, test_type, 0);
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +03001191 if (ret)
1192 return ret;
1193
1194 /* test unaligned buffers, check with one byte offset */
Gilad Ben-Yossef76715092018-07-01 08:02:35 +01001195 ret = __test_hash(tfm, template, tcount, test_type, 1);
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +03001196 if (ret)
1197 return ret;
1198
1199 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1200 if (alignmask) {
1201 /* Check if alignment mask for tfm is correctly set. */
Gilad Ben-Yossef76715092018-07-01 08:02:35 +01001202 ret = __test_hash(tfm, template, tcount, test_type,
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +03001203 alignmask + 1);
1204 if (ret)
1205 return ret;
1206 }
1207
1208 return 0;
1209}
1210
Eric Biggersed968042019-01-31 23:51:47 -08001211static int test_aead_vec_cfg(const char *driver, int enc,
1212 const struct aead_testvec *vec,
1213 unsigned int vec_num,
1214 const struct testvec_config *cfg,
1215 struct aead_request *req,
1216 struct cipher_test_sglists *tsgls)
Herbert Xuda7f0332008-07-31 17:08:25 +08001217{
Eric Biggersed968042019-01-31 23:51:47 -08001218 struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1219 const unsigned int alignmask = crypto_aead_alignmask(tfm);
1220 const unsigned int ivsize = crypto_aead_ivsize(tfm);
1221 const unsigned int authsize = vec->clen - vec->plen;
1222 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
1223 const char *op = enc ? "encryption" : "decryption";
1224 DECLARE_CRYPTO_WAIT(wait);
1225 u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN];
1226 u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) +
1227 cfg->iv_offset +
1228 (cfg->iv_offset_relative_to_alignmask ? alignmask : 0);
1229 struct kvec input[2];
1230 int err;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001231
Eric Biggersed968042019-01-31 23:51:47 -08001232 /* Set the key */
1233 if (vec->wk)
1234 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001235 else
Eric Biggersed968042019-01-31 23:51:47 -08001236 crypto_aead_clear_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
1237 err = crypto_aead_setkey(tfm, vec->key, vec->klen);
1238 if (err) {
1239 if (vec->fail) /* expectedly failed to set key? */
1240 return 0;
1241 pr_err("alg: aead: %s setkey failed with err %d on test vector %u; flags=%#x\n",
1242 driver, err, vec_num, crypto_aead_get_flags(tfm));
1243 return err;
1244 }
1245 if (vec->fail) {
1246 pr_err("alg: aead: %s setkey unexpectedly succeeded on test vector %u\n",
1247 driver, vec_num);
1248 return -EINVAL;
1249 }
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001250
Eric Biggersed968042019-01-31 23:51:47 -08001251 /* Set the authentication tag size */
1252 err = crypto_aead_setauthsize(tfm, authsize);
1253 if (err) {
1254 pr_err("alg: aead: %s setauthsize failed with err %d on test vector %u\n",
1255 driver, err, vec_num);
1256 return err;
1257 }
1258
1259 /* The IV must be copied to a buffer, as the algorithm may modify it */
1260 if (WARN_ON(ivsize > MAX_IVLEN))
1261 return -EINVAL;
1262 if (vec->iv)
1263 memcpy(iv, vec->iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001264 else
Eric Biggersed968042019-01-31 23:51:47 -08001265 memset(iv, 0, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001266
Eric Biggersed968042019-01-31 23:51:47 -08001267 /* Build the src/dst scatterlists */
1268 input[0].iov_base = (void *)vec->assoc;
1269 input[0].iov_len = vec->alen;
1270 input[1].iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext;
1271 input[1].iov_len = enc ? vec->plen : vec->clen;
1272 err = build_cipher_test_sglists(tsgls, cfg, alignmask,
1273 vec->alen + (enc ? vec->plen :
1274 vec->clen),
1275 vec->alen + (enc ? vec->clen :
1276 vec->plen),
1277 input, 2);
1278 if (err) {
1279 pr_err("alg: aead: %s %s: error preparing scatterlists for test vector %u, cfg=\"%s\"\n",
1280 driver, op, vec_num, cfg->name);
1281 return err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001282 }
1283
Eric Biggersed968042019-01-31 23:51:47 -08001284 /* Do the actual encryption or decryption */
1285 testmgr_poison(req->__ctx, crypto_aead_reqsize(tfm));
1286 aead_request_set_callback(req, req_flags, crypto_req_done, &wait);
1287 aead_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr,
1288 enc ? vec->plen : vec->clen, iv);
1289 aead_request_set_ad(req, vec->alen);
1290 err = crypto_wait_req(enc ? crypto_aead_encrypt(req) :
1291 crypto_aead_decrypt(req), &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001292
Eric Biggersed968042019-01-31 23:51:47 -08001293 aead_request_set_tfm(req, tfm); /* TODO: get rid of this */
Jerome Marchandabfa7f42016-02-03 13:58:12 +01001294
Eric Biggersed968042019-01-31 23:51:47 -08001295 if (err) {
1296 if (err == -EBADMSG && vec->novrfy)
1297 return 0;
1298 pr_err("alg: aead: %s %s failed with err %d on test vector %u, cfg=\"%s\"\n",
1299 driver, op, err, vec_num, cfg->name);
1300 return err;
1301 }
1302 if (vec->novrfy) {
1303 pr_err("alg: aead: %s %s unexpectedly succeeded on test vector %u, cfg=\"%s\"\n",
1304 driver, op, vec_num, cfg->name);
1305 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08001306 }
1307
Eric Biggersed968042019-01-31 23:51:47 -08001308 /* Check for the correct output (ciphertext or plaintext) */
1309 err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext,
1310 enc ? vec->clen : vec->plen,
1311 vec->alen, enc || !cfg->inplace);
1312 if (err == -EOVERFLOW) {
1313 pr_err("alg: aead: %s %s overran dst buffer on test vector %u, cfg=\"%s\"\n",
1314 driver, op, vec_num, cfg->name);
1315 return err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001316 }
Eric Biggersed968042019-01-31 23:51:47 -08001317 if (err) {
1318 pr_err("alg: aead: %s %s test failed (wrong result) on test vector %u, cfg=\"%s\"\n",
1319 driver, op, vec_num, cfg->name);
1320 return err;
Jussi Kivilinna58dcf542013-06-13 17:37:50 +03001321 }
1322
1323 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001324}
1325
Eric Biggersed968042019-01-31 23:51:47 -08001326static int test_aead_vec(const char *driver, int enc,
1327 const struct aead_testvec *vec, unsigned int vec_num,
1328 struct aead_request *req,
1329 struct cipher_test_sglists *tsgls)
1330{
1331 unsigned int i;
1332 int err;
1333
1334 if (enc && vec->novrfy)
1335 return 0;
1336
1337 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
1338 err = test_aead_vec_cfg(driver, enc, vec, vec_num,
1339 &default_cipher_testvec_configs[i],
1340 req, tsgls);
1341 if (err)
1342 return err;
1343 }
1344
1345#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1346 if (!noextratests) {
1347 struct testvec_config cfg;
1348 char cfgname[TESTVEC_CONFIG_NAMELEN];
1349
1350 for (i = 0; i < fuzz_iterations; i++) {
1351 generate_random_testvec_config(&cfg, cfgname,
1352 sizeof(cfgname));
1353 err = test_aead_vec_cfg(driver, enc, vec, vec_num,
1354 &cfg, req, tsgls);
1355 if (err)
1356 return err;
1357 }
1358 }
1359#endif
1360 return 0;
1361}
1362
1363static int test_aead(const char *driver, int enc,
1364 const struct aead_test_suite *suite,
1365 struct aead_request *req,
1366 struct cipher_test_sglists *tsgls)
1367{
1368 unsigned int i;
1369 int err;
1370
1371 for (i = 0; i < suite->count; i++) {
1372 err = test_aead_vec(driver, enc, &suite->vecs[i], i, req,
1373 tsgls);
1374 if (err)
1375 return err;
1376 }
1377 return 0;
1378}
1379
1380static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1381 u32 type, u32 mask)
1382{
1383 const struct aead_test_suite *suite = &desc->suite.aead;
1384 struct crypto_aead *tfm;
1385 struct aead_request *req = NULL;
1386 struct cipher_test_sglists *tsgls = NULL;
1387 int err;
1388
1389 if (suite->count <= 0) {
1390 pr_err("alg: aead: empty test suite for %s\n", driver);
1391 return -EINVAL;
1392 }
1393
1394 tfm = crypto_alloc_aead(driver, type, mask);
1395 if (IS_ERR(tfm)) {
1396 pr_err("alg: aead: failed to allocate transform for %s: %ld\n",
1397 driver, PTR_ERR(tfm));
1398 return PTR_ERR(tfm);
1399 }
1400
1401 req = aead_request_alloc(tfm, GFP_KERNEL);
1402 if (!req) {
1403 pr_err("alg: aead: failed to allocate request for %s\n",
1404 driver);
1405 err = -ENOMEM;
1406 goto out;
1407 }
1408
1409 tsgls = alloc_cipher_test_sglists();
1410 if (!tsgls) {
1411 pr_err("alg: aead: failed to allocate test buffers for %s\n",
1412 driver);
1413 err = -ENOMEM;
1414 goto out;
1415 }
1416
1417 err = test_aead(driver, ENCRYPT, suite, req, tsgls);
1418 if (err)
1419 goto out;
1420
1421 err = test_aead(driver, DECRYPT, suite, req, tsgls);
1422out:
1423 free_cipher_test_sglists(tsgls);
1424 aead_request_free(req);
1425 crypto_free_aead(tfm);
1426 return err;
1427}
1428
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001429static int test_cipher(struct crypto_cipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001430 const struct cipher_testvec *template,
1431 unsigned int tcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08001432{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001433 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
1434 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001435 char *q;
1436 const char *e;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001437 const char *input, *result;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001438 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001439 char *xbuf[XBUFSIZE];
1440 int ret = -ENOMEM;
1441
1442 if (testmgr_alloc_buf(xbuf))
1443 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001444
1445 if (enc == ENCRYPT)
1446 e = "encryption";
1447 else
1448 e = "decryption";
1449
1450 j = 0;
1451 for (i = 0; i < tcount; i++) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001452
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001453 if (fips_enabled && template[i].fips_skip)
1454 continue;
1455
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001456 input = enc ? template[i].ptext : template[i].ctext;
1457 result = enc ? template[i].ctext : template[i].ptext;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001458 j++;
1459
Herbert Xufd57f222009-05-29 16:05:42 +10001460 ret = -EINVAL;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001461 if (WARN_ON(template[i].len > PAGE_SIZE))
Herbert Xufd57f222009-05-29 16:05:42 +10001462 goto out;
1463
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001464 data = xbuf[0];
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001465 memcpy(data, input, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001466
1467 crypto_cipher_clear_flags(tfm, ~0);
1468 if (template[i].wk)
Eric Biggers231baec2019-01-18 22:48:00 -08001469 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001470
1471 ret = crypto_cipher_setkey(tfm, template[i].key,
1472 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001473 if (template[i].fail == !ret) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001474 printk(KERN_ERR "alg: cipher: setkey failed "
1475 "on test %d for %s: flags=%x\n", j,
1476 algo, crypto_cipher_get_flags(tfm));
1477 goto out;
1478 } else if (ret)
1479 continue;
1480
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001481 for (k = 0; k < template[i].len;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001482 k += crypto_cipher_blocksize(tfm)) {
1483 if (enc)
1484 crypto_cipher_encrypt_one(tfm, data + k,
1485 data + k);
1486 else
1487 crypto_cipher_decrypt_one(tfm, data + k,
1488 data + k);
1489 }
1490
1491 q = data;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001492 if (memcmp(q, result, template[i].len)) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001493 printk(KERN_ERR "alg: cipher: Test %d failed "
1494 "on %s for %s\n", j, e, algo);
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001495 hexdump(q, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001496 ret = -EINVAL;
1497 goto out;
1498 }
1499 }
1500
1501 ret = 0;
1502
1503out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001504 testmgr_free_buf(xbuf);
1505out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001506 return ret;
1507}
1508
Eric Biggers4e7babba2019-01-31 23:51:46 -08001509static int test_skcipher_vec_cfg(const char *driver, int enc,
1510 const struct cipher_testvec *vec,
1511 unsigned int vec_num,
1512 const struct testvec_config *cfg,
1513 struct skcipher_request *req,
1514 struct cipher_test_sglists *tsgls)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001515{
Eric Biggers4e7babba2019-01-31 23:51:46 -08001516 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
1517 const unsigned int alignmask = crypto_skcipher_alignmask(tfm);
1518 const unsigned int ivsize = crypto_skcipher_ivsize(tfm);
1519 const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
1520 const char *op = enc ? "encryption" : "decryption";
1521 DECLARE_CRYPTO_WAIT(wait);
1522 u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN];
1523 u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) +
1524 cfg->iv_offset +
1525 (cfg->iv_offset_relative_to_alignmask ? alignmask : 0);
1526 struct kvec input;
1527 int err;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001528
Eric Biggers4e7babba2019-01-31 23:51:46 -08001529 /* Set the key */
1530 if (vec->wk)
1531 crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001532 else
Eric Biggers4e7babba2019-01-31 23:51:46 -08001533 crypto_skcipher_clear_flags(tfm,
1534 CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
1535 err = crypto_skcipher_setkey(tfm, vec->key, vec->klen);
1536 if (err) {
1537 if (vec->fail) /* expectedly failed to set key? */
1538 return 0;
1539 pr_err("alg: skcipher: %s setkey failed with err %d on test vector %u; flags=%#x\n",
1540 driver, err, vec_num, crypto_skcipher_get_flags(tfm));
1541 return err;
1542 }
1543 if (vec->fail) {
1544 pr_err("alg: skcipher: %s setkey unexpectedly succeeded on test vector %u\n",
1545 driver, vec_num);
1546 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08001547 }
1548
Eric Biggers4e7babba2019-01-31 23:51:46 -08001549 /* The IV must be copied to a buffer, as the algorithm may modify it */
1550 if (ivsize) {
1551 if (WARN_ON(ivsize > MAX_IVLEN))
1552 return -EINVAL;
1553 if (vec->iv && !(vec->generates_iv && enc))
1554 memcpy(iv, vec->iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001555 else
Eric Biggers4e7babba2019-01-31 23:51:46 -08001556 memset(iv, 0, ivsize);
1557 } else {
1558 if (vec->generates_iv) {
1559 pr_err("alg: skcipher: %s has ivsize=0 but test vector %u generates IV!\n",
1560 driver, vec_num);
1561 return -EINVAL;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001562 }
Eric Biggers4e7babba2019-01-31 23:51:46 -08001563 iv = NULL;
Herbert Xuda7f0332008-07-31 17:08:25 +08001564 }
1565
Eric Biggers4e7babba2019-01-31 23:51:46 -08001566 /* Build the src/dst scatterlists */
1567 input.iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext;
1568 input.iov_len = vec->len;
1569 err = build_cipher_test_sglists(tsgls, cfg, alignmask,
1570 vec->len, vec->len, &input, 1);
1571 if (err) {
1572 pr_err("alg: skcipher: %s %s: error preparing scatterlists for test vector %u, cfg=\"%s\"\n",
1573 driver, op, vec_num, cfg->name);
1574 return err;
Herbert Xuda7f0332008-07-31 17:08:25 +08001575 }
1576
Eric Biggers4e7babba2019-01-31 23:51:46 -08001577 /* Do the actual encryption or decryption */
1578 testmgr_poison(req->__ctx, crypto_skcipher_reqsize(tfm));
1579 skcipher_request_set_callback(req, req_flags, crypto_req_done, &wait);
1580 skcipher_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr,
1581 vec->len, iv);
1582 err = crypto_wait_req(enc ? crypto_skcipher_encrypt(req) :
1583 crypto_skcipher_decrypt(req), &wait);
1584 if (err) {
1585 pr_err("alg: skcipher: %s %s failed with err %d on test vector %u, cfg=\"%s\"\n",
1586 driver, op, err, vec_num, cfg->name);
1587 return err;
1588 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001589
Eric Biggers4e7babba2019-01-31 23:51:46 -08001590 /* Check for the correct output (ciphertext or plaintext) */
1591 err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext,
1592 vec->len, 0, true);
1593 if (err == -EOVERFLOW) {
1594 pr_err("alg: skcipher: %s %s overran dst buffer on test vector %u, cfg=\"%s\"\n",
1595 driver, op, vec_num, cfg->name);
1596 return err;
1597 }
1598 if (err) {
1599 pr_err("alg: skcipher: %s %s test failed (wrong result) on test vector %u, cfg=\"%s\"\n",
1600 driver, op, vec_num, cfg->name);
1601 return err;
1602 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001603
Eric Biggers4e7babba2019-01-31 23:51:46 -08001604 /* If applicable, check that the algorithm generated the correct IV */
1605 if (vec->generates_iv && enc && memcmp(iv, vec->iv, ivsize) != 0) {
1606 pr_err("alg: skcipher: %s %s test failed (wrong output IV) on test vector %u, cfg=\"%s\"\n",
1607 driver, op, vec_num, cfg->name);
1608 hexdump(iv, ivsize);
1609 return -EINVAL;
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001610 }
1611
1612 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001613}
1614
Eric Biggers4e7babba2019-01-31 23:51:46 -08001615static int test_skcipher_vec(const char *driver, int enc,
1616 const struct cipher_testvec *vec,
1617 unsigned int vec_num,
1618 struct skcipher_request *req,
1619 struct cipher_test_sglists *tsgls)
1620{
1621 unsigned int i;
1622 int err;
1623
1624 if (fips_enabled && vec->fips_skip)
1625 return 0;
1626
1627 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
1628 err = test_skcipher_vec_cfg(driver, enc, vec, vec_num,
1629 &default_cipher_testvec_configs[i],
1630 req, tsgls);
1631 if (err)
1632 return err;
1633 }
1634
1635#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1636 if (!noextratests) {
1637 struct testvec_config cfg;
1638 char cfgname[TESTVEC_CONFIG_NAMELEN];
1639
1640 for (i = 0; i < fuzz_iterations; i++) {
1641 generate_random_testvec_config(&cfg, cfgname,
1642 sizeof(cfgname));
1643 err = test_skcipher_vec_cfg(driver, enc, vec, vec_num,
1644 &cfg, req, tsgls);
1645 if (err)
1646 return err;
1647 }
1648 }
1649#endif
1650 return 0;
1651}
1652
1653static int test_skcipher(const char *driver, int enc,
1654 const struct cipher_test_suite *suite,
1655 struct skcipher_request *req,
1656 struct cipher_test_sglists *tsgls)
1657{
1658 unsigned int i;
1659 int err;
1660
1661 for (i = 0; i < suite->count; i++) {
1662 err = test_skcipher_vec(driver, enc, &suite->vecs[i], i, req,
1663 tsgls);
1664 if (err)
1665 return err;
1666 }
1667 return 0;
1668}
1669
1670static int alg_test_skcipher(const struct alg_test_desc *desc,
1671 const char *driver, u32 type, u32 mask)
1672{
1673 const struct cipher_test_suite *suite = &desc->suite.cipher;
1674 struct crypto_skcipher *tfm;
1675 struct skcipher_request *req = NULL;
1676 struct cipher_test_sglists *tsgls = NULL;
1677 int err;
1678
1679 if (suite->count <= 0) {
1680 pr_err("alg: skcipher: empty test suite for %s\n", driver);
1681 return -EINVAL;
1682 }
1683
1684 tfm = crypto_alloc_skcipher(driver, type, mask);
1685 if (IS_ERR(tfm)) {
1686 pr_err("alg: skcipher: failed to allocate transform for %s: %ld\n",
1687 driver, PTR_ERR(tfm));
1688 return PTR_ERR(tfm);
1689 }
1690
1691 req = skcipher_request_alloc(tfm, GFP_KERNEL);
1692 if (!req) {
1693 pr_err("alg: skcipher: failed to allocate request for %s\n",
1694 driver);
1695 err = -ENOMEM;
1696 goto out;
1697 }
1698
1699 tsgls = alloc_cipher_test_sglists();
1700 if (!tsgls) {
1701 pr_err("alg: skcipher: failed to allocate test buffers for %s\n",
1702 driver);
1703 err = -ENOMEM;
1704 goto out;
1705 }
1706
1707 err = test_skcipher(driver, ENCRYPT, suite, req, tsgls);
1708 if (err)
1709 goto out;
1710
1711 err = test_skcipher(driver, DECRYPT, suite, req, tsgls);
1712out:
1713 free_cipher_test_sglists(tsgls);
1714 skcipher_request_free(req);
1715 crypto_free_skcipher(tfm);
1716 return err;
1717}
1718
Eric Biggersb13b1e02017-02-24 15:46:59 -08001719static int test_comp(struct crypto_comp *tfm,
1720 const struct comp_testvec *ctemplate,
1721 const struct comp_testvec *dtemplate,
1722 int ctcount, int dtcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08001723{
1724 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
Mahipal Challa33607382018-04-11 20:28:32 +02001725 char *output, *decomp_output;
Herbert Xuda7f0332008-07-31 17:08:25 +08001726 unsigned int i;
Herbert Xuda7f0332008-07-31 17:08:25 +08001727 int ret;
1728
Mahipal Challa33607382018-04-11 20:28:32 +02001729 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1730 if (!output)
1731 return -ENOMEM;
1732
1733 decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1734 if (!decomp_output) {
1735 kfree(output);
1736 return -ENOMEM;
1737 }
1738
Herbert Xuda7f0332008-07-31 17:08:25 +08001739 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001740 int ilen;
1741 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001742
Michael Schupikov22a81182018-10-07 13:58:10 +02001743 memset(output, 0, COMP_BUF_SIZE);
1744 memset(decomp_output, 0, COMP_BUF_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +08001745
1746 ilen = ctemplate[i].inlen;
1747 ret = crypto_comp_compress(tfm, ctemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02001748 ilen, output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001749 if (ret) {
1750 printk(KERN_ERR "alg: comp: compression failed "
1751 "on test %d for %s: ret=%d\n", i + 1, algo,
1752 -ret);
1753 goto out;
1754 }
1755
Mahipal Challa33607382018-04-11 20:28:32 +02001756 ilen = dlen;
1757 dlen = COMP_BUF_SIZE;
1758 ret = crypto_comp_decompress(tfm, output,
1759 ilen, decomp_output, &dlen);
1760 if (ret) {
1761 pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n",
1762 i + 1, algo, -ret);
1763 goto out;
1764 }
1765
1766 if (dlen != ctemplate[i].inlen) {
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001767 printk(KERN_ERR "alg: comp: Compression test %d "
1768 "failed for %s: output len = %d\n", i + 1, algo,
1769 dlen);
1770 ret = -EINVAL;
1771 goto out;
1772 }
1773
Mahipal Challa33607382018-04-11 20:28:32 +02001774 if (memcmp(decomp_output, ctemplate[i].input,
1775 ctemplate[i].inlen)) {
1776 pr_err("alg: comp: compression failed: output differs: on test %d for %s\n",
1777 i + 1, algo);
1778 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001779 ret = -EINVAL;
1780 goto out;
1781 }
1782 }
1783
1784 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001785 int ilen;
1786 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001787
Michael Schupikov22a81182018-10-07 13:58:10 +02001788 memset(decomp_output, 0, COMP_BUF_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +08001789
1790 ilen = dtemplate[i].inlen;
1791 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02001792 ilen, decomp_output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001793 if (ret) {
1794 printk(KERN_ERR "alg: comp: decompression failed "
1795 "on test %d for %s: ret=%d\n", i + 1, algo,
1796 -ret);
1797 goto out;
1798 }
1799
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001800 if (dlen != dtemplate[i].outlen) {
1801 printk(KERN_ERR "alg: comp: Decompression test %d "
1802 "failed for %s: output len = %d\n", i + 1, algo,
1803 dlen);
1804 ret = -EINVAL;
1805 goto out;
1806 }
1807
Mahipal Challa33607382018-04-11 20:28:32 +02001808 if (memcmp(decomp_output, dtemplate[i].output, dlen)) {
Herbert Xuda7f0332008-07-31 17:08:25 +08001809 printk(KERN_ERR "alg: comp: Decompression test %d "
1810 "failed for %s\n", i + 1, algo);
Mahipal Challa33607382018-04-11 20:28:32 +02001811 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001812 ret = -EINVAL;
1813 goto out;
1814 }
1815 }
1816
1817 ret = 0;
1818
1819out:
Mahipal Challa33607382018-04-11 20:28:32 +02001820 kfree(decomp_output);
1821 kfree(output);
Herbert Xuda7f0332008-07-31 17:08:25 +08001822 return ret;
1823}
1824
Eric Biggersb13b1e02017-02-24 15:46:59 -08001825static int test_acomp(struct crypto_acomp *tfm,
Mahipal Challa33607382018-04-11 20:28:32 +02001826 const struct comp_testvec *ctemplate,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001827 const struct comp_testvec *dtemplate,
1828 int ctcount, int dtcount)
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001829{
1830 const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
1831 unsigned int i;
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001832 char *output, *decomp_out;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001833 int ret;
1834 struct scatterlist src, dst;
1835 struct acomp_req *req;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001836 struct crypto_wait wait;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001837
Eric Biggerseb095592016-11-23 10:24:35 -08001838 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1839 if (!output)
1840 return -ENOMEM;
1841
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001842 decomp_out = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1843 if (!decomp_out) {
1844 kfree(output);
1845 return -ENOMEM;
1846 }
1847
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001848 for (i = 0; i < ctcount; i++) {
1849 unsigned int dlen = COMP_BUF_SIZE;
1850 int ilen = ctemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08001851 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001852
Eric Biggersd2110222016-12-30 14:12:00 -06001853 input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08001854 if (!input_vec) {
1855 ret = -ENOMEM;
1856 goto out;
1857 }
1858
Eric Biggerseb095592016-11-23 10:24:35 -08001859 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001860 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08001861 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001862 sg_init_one(&dst, output, dlen);
1863
1864 req = acomp_request_alloc(tfm);
1865 if (!req) {
1866 pr_err("alg: acomp: request alloc failed for %s\n",
1867 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08001868 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001869 ret = -ENOMEM;
1870 goto out;
1871 }
1872
1873 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1874 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001875 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001876
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001877 ret = crypto_wait_req(crypto_acomp_compress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001878 if (ret) {
1879 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
1880 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08001881 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001882 acomp_request_free(req);
1883 goto out;
1884 }
1885
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001886 ilen = req->dlen;
1887 dlen = COMP_BUF_SIZE;
1888 sg_init_one(&src, output, ilen);
1889 sg_init_one(&dst, decomp_out, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001890 crypto_init_wait(&wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001891 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1892
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001893 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001894 if (ret) {
1895 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
1896 i + 1, algo, -ret);
1897 kfree(input_vec);
1898 acomp_request_free(req);
1899 goto out;
1900 }
1901
1902 if (req->dlen != ctemplate[i].inlen) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001903 pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
1904 i + 1, algo, req->dlen);
1905 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001906 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001907 acomp_request_free(req);
1908 goto out;
1909 }
1910
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001911 if (memcmp(input_vec, decomp_out, req->dlen)) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001912 pr_err("alg: acomp: Compression test %d failed for %s\n",
1913 i + 1, algo);
1914 hexdump(output, req->dlen);
1915 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001916 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001917 acomp_request_free(req);
1918 goto out;
1919 }
1920
Laura Abbott02608e02016-12-21 12:32:54 -08001921 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001922 acomp_request_free(req);
1923 }
1924
1925 for (i = 0; i < dtcount; i++) {
1926 unsigned int dlen = COMP_BUF_SIZE;
1927 int ilen = dtemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08001928 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001929
Eric Biggersd2110222016-12-30 14:12:00 -06001930 input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08001931 if (!input_vec) {
1932 ret = -ENOMEM;
1933 goto out;
1934 }
1935
Eric Biggerseb095592016-11-23 10:24:35 -08001936 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001937 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08001938 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001939 sg_init_one(&dst, output, dlen);
1940
1941 req = acomp_request_alloc(tfm);
1942 if (!req) {
1943 pr_err("alg: acomp: request alloc failed for %s\n",
1944 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08001945 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001946 ret = -ENOMEM;
1947 goto out;
1948 }
1949
1950 acomp_request_set_params(req, &src, &dst, ilen, dlen);
1951 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001952 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001953
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001954 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001955 if (ret) {
1956 pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
1957 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08001958 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001959 acomp_request_free(req);
1960 goto out;
1961 }
1962
1963 if (req->dlen != dtemplate[i].outlen) {
1964 pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
1965 i + 1, algo, req->dlen);
1966 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001967 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001968 acomp_request_free(req);
1969 goto out;
1970 }
1971
1972 if (memcmp(output, dtemplate[i].output, req->dlen)) {
1973 pr_err("alg: acomp: Decompression test %d failed for %s\n",
1974 i + 1, algo);
1975 hexdump(output, req->dlen);
1976 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08001977 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001978 acomp_request_free(req);
1979 goto out;
1980 }
1981
Laura Abbott02608e02016-12-21 12:32:54 -08001982 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001983 acomp_request_free(req);
1984 }
1985
1986 ret = 0;
1987
1988out:
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01001989 kfree(decomp_out);
Eric Biggerseb095592016-11-23 10:24:35 -08001990 kfree(output);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01001991 return ret;
1992}
1993
Eric Biggersb13b1e02017-02-24 15:46:59 -08001994static int test_cprng(struct crypto_rng *tfm,
1995 const struct cprng_testvec *template,
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001996 unsigned int tcount)
1997{
1998 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001999 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002000 u8 *seed;
2001 char result[32];
2002
2003 seedsize = crypto_rng_seedsize(tfm);
2004
2005 seed = kmalloc(seedsize, GFP_KERNEL);
2006 if (!seed) {
2007 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
2008 "for %s\n", algo);
2009 return -ENOMEM;
2010 }
2011
2012 for (i = 0; i < tcount; i++) {
2013 memset(result, 0, 32);
2014
2015 memcpy(seed, template[i].v, template[i].vlen);
2016 memcpy(seed + template[i].vlen, template[i].key,
2017 template[i].klen);
2018 memcpy(seed + template[i].vlen + template[i].klen,
2019 template[i].dt, template[i].dtlen);
2020
2021 err = crypto_rng_reset(tfm, seed, seedsize);
2022 if (err) {
2023 printk(KERN_ERR "alg: cprng: Failed to reset rng "
2024 "for %s\n", algo);
2025 goto out;
2026 }
2027
2028 for (j = 0; j < template[i].loops; j++) {
2029 err = crypto_rng_get_bytes(tfm, result,
2030 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01002031 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002032 printk(KERN_ERR "alg: cprng: Failed to obtain "
2033 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01002034 "%s (requested %d)\n", algo,
2035 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002036 goto out;
2037 }
2038 }
2039
2040 err = memcmp(result, template[i].result,
2041 template[i].rlen);
2042 if (err) {
2043 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
2044 i, algo);
2045 hexdump(result, template[i].rlen);
2046 err = -EINVAL;
2047 goto out;
2048 }
2049 }
2050
2051out:
2052 kfree(seed);
2053 return err;
2054}
2055
Herbert Xuda7f0332008-07-31 17:08:25 +08002056static int alg_test_cipher(const struct alg_test_desc *desc,
2057 const char *driver, u32 type, u32 mask)
2058{
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002059 const struct cipher_test_suite *suite = &desc->suite.cipher;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002060 struct crypto_cipher *tfm;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002061 int err;
Herbert Xuda7f0332008-07-31 17:08:25 +08002062
Herbert Xueed93e02016-11-22 20:08:31 +08002063 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08002064 if (IS_ERR(tfm)) {
2065 printk(KERN_ERR "alg: cipher: Failed to load transform for "
2066 "%s: %ld\n", driver, PTR_ERR(tfm));
2067 return PTR_ERR(tfm);
2068 }
2069
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002070 err = test_cipher(tfm, ENCRYPT, suite->vecs, suite->count);
2071 if (!err)
2072 err = test_cipher(tfm, DECRYPT, suite->vecs, suite->count);
Herbert Xuda7f0332008-07-31 17:08:25 +08002073
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002074 crypto_free_cipher(tfm);
2075 return err;
2076}
2077
Herbert Xuda7f0332008-07-31 17:08:25 +08002078static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
2079 u32 type, u32 mask)
2080{
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002081 struct crypto_comp *comp;
2082 struct crypto_acomp *acomp;
Herbert Xuda7f0332008-07-31 17:08:25 +08002083 int err;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002084 u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
Herbert Xuda7f0332008-07-31 17:08:25 +08002085
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002086 if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
2087 acomp = crypto_alloc_acomp(driver, type, mask);
2088 if (IS_ERR(acomp)) {
2089 pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
2090 driver, PTR_ERR(acomp));
2091 return PTR_ERR(acomp);
2092 }
2093 err = test_acomp(acomp, desc->suite.comp.comp.vecs,
2094 desc->suite.comp.decomp.vecs,
2095 desc->suite.comp.comp.count,
2096 desc->suite.comp.decomp.count);
2097 crypto_free_acomp(acomp);
2098 } else {
2099 comp = crypto_alloc_comp(driver, type, mask);
2100 if (IS_ERR(comp)) {
2101 pr_err("alg: comp: Failed to load transform for %s: %ld\n",
2102 driver, PTR_ERR(comp));
2103 return PTR_ERR(comp);
2104 }
2105
2106 err = test_comp(comp, desc->suite.comp.comp.vecs,
2107 desc->suite.comp.decomp.vecs,
2108 desc->suite.comp.comp.count,
2109 desc->suite.comp.decomp.count);
2110
2111 crypto_free_comp(comp);
Herbert Xuda7f0332008-07-31 17:08:25 +08002112 }
Herbert Xuda7f0332008-07-31 17:08:25 +08002113 return err;
2114}
2115
Eric Biggers9b3abc0162018-05-19 22:07:41 -07002116static int __alg_test_hash(const struct hash_testvec *template,
2117 unsigned int tcount, const char *driver,
2118 u32 type, u32 mask)
Herbert Xuda7f0332008-07-31 17:08:25 +08002119{
2120 struct crypto_ahash *tfm;
2121 int err;
2122
Herbert Xueed93e02016-11-22 20:08:31 +08002123 tfm = crypto_alloc_ahash(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08002124 if (IS_ERR(tfm)) {
2125 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
2126 "%ld\n", driver, PTR_ERR(tfm));
2127 return PTR_ERR(tfm);
2128 }
2129
Gilad Ben-Yossef76715092018-07-01 08:02:35 +01002130 err = test_hash(tfm, template, tcount, HASH_TEST_DIGEST);
David S. Millera8f1a052010-05-19 14:12:03 +10002131 if (!err)
Gilad Ben-Yossef76715092018-07-01 08:02:35 +01002132 err = test_hash(tfm, template, tcount, HASH_TEST_FINAL);
2133 if (!err)
2134 err = test_hash(tfm, template, tcount, HASH_TEST_FINUP);
Herbert Xuda7f0332008-07-31 17:08:25 +08002135 crypto_free_ahash(tfm);
2136 return err;
2137}
2138
Eric Biggers9b3abc0162018-05-19 22:07:41 -07002139static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
2140 u32 type, u32 mask)
2141{
2142 const struct hash_testvec *template = desc->suite.hash.vecs;
2143 unsigned int tcount = desc->suite.hash.count;
2144 unsigned int nr_unkeyed, nr_keyed;
2145 int err;
2146
2147 /*
2148 * For OPTIONAL_KEY algorithms, we have to do all the unkeyed tests
2149 * first, before setting a key on the tfm. To make this easier, we
2150 * require that the unkeyed test vectors (if any) are listed first.
2151 */
2152
2153 for (nr_unkeyed = 0; nr_unkeyed < tcount; nr_unkeyed++) {
2154 if (template[nr_unkeyed].ksize)
2155 break;
2156 }
2157 for (nr_keyed = 0; nr_unkeyed + nr_keyed < tcount; nr_keyed++) {
2158 if (!template[nr_unkeyed + nr_keyed].ksize) {
2159 pr_err("alg: hash: test vectors for %s out of order, "
2160 "unkeyed ones must come first\n", desc->alg);
2161 return -EINVAL;
2162 }
2163 }
2164
2165 err = 0;
2166 if (nr_unkeyed) {
2167 err = __alg_test_hash(template, nr_unkeyed, driver, type, mask);
2168 template += nr_unkeyed;
2169 }
2170
2171 if (!err && nr_keyed)
2172 err = __alg_test_hash(template, nr_keyed, driver, type, mask);
2173
2174 return err;
2175}
2176
Herbert Xu8e3ee852008-11-07 14:58:52 +08002177static int alg_test_crc32c(const struct alg_test_desc *desc,
2178 const char *driver, u32 type, u32 mask)
2179{
2180 struct crypto_shash *tfm;
Eric Biggerscb9dde82019-01-10 12:17:55 -08002181 __le32 val;
Herbert Xu8e3ee852008-11-07 14:58:52 +08002182 int err;
2183
2184 err = alg_test_hash(desc, driver, type, mask);
2185 if (err)
Eric Biggerseb5e6732019-01-23 20:57:35 -08002186 return err;
Herbert Xu8e3ee852008-11-07 14:58:52 +08002187
Herbert Xueed93e02016-11-22 20:08:31 +08002188 tfm = crypto_alloc_shash(driver, type, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002189 if (IS_ERR(tfm)) {
Eric Biggerseb5e6732019-01-23 20:57:35 -08002190 if (PTR_ERR(tfm) == -ENOENT) {
2191 /*
2192 * This crc32c implementation is only available through
2193 * ahash API, not the shash API, so the remaining part
2194 * of the test is not applicable to it.
2195 */
2196 return 0;
2197 }
Herbert Xu8e3ee852008-11-07 14:58:52 +08002198 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
2199 "%ld\n", driver, PTR_ERR(tfm));
Eric Biggerseb5e6732019-01-23 20:57:35 -08002200 return PTR_ERR(tfm);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002201 }
2202
2203 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02002204 SHASH_DESC_ON_STACK(shash, tfm);
2205 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002206
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02002207 shash->tfm = tfm;
2208 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08002209
Eric Biggerscb9dde82019-01-10 12:17:55 -08002210 *ctx = 420553207;
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02002211 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002212 if (err) {
2213 printk(KERN_ERR "alg: crc32c: Operation failed for "
2214 "%s: %d\n", driver, err);
2215 break;
2216 }
2217
Eric Biggerscb9dde82019-01-10 12:17:55 -08002218 if (val != cpu_to_le32(~420553207)) {
2219 pr_err("alg: crc32c: Test failed for %s: %u\n",
2220 driver, le32_to_cpu(val));
Herbert Xu8e3ee852008-11-07 14:58:52 +08002221 err = -EINVAL;
2222 }
2223 } while (0);
2224
2225 crypto_free_shash(tfm);
2226
Herbert Xu8e3ee852008-11-07 14:58:52 +08002227 return err;
2228}
2229
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002230static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
2231 u32 type, u32 mask)
2232{
2233 struct crypto_rng *rng;
2234 int err;
2235
Herbert Xueed93e02016-11-22 20:08:31 +08002236 rng = crypto_alloc_rng(driver, type, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002237 if (IS_ERR(rng)) {
2238 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
2239 "%ld\n", driver, PTR_ERR(rng));
2240 return PTR_ERR(rng);
2241 }
2242
2243 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
2244
2245 crypto_free_rng(rng);
2246
2247 return err;
2248}
2249
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002250
Eric Biggersb13b1e02017-02-24 15:46:59 -08002251static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002252 const char *driver, u32 type, u32 mask)
2253{
2254 int ret = -EAGAIN;
2255 struct crypto_rng *drng;
2256 struct drbg_test_data test_data;
2257 struct drbg_string addtl, pers, testentropy;
2258 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
2259
2260 if (!buf)
2261 return -ENOMEM;
2262
Herbert Xueed93e02016-11-22 20:08:31 +08002263 drng = crypto_alloc_rng(driver, type, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002264 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002265 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002266 "%s\n", driver);
2267 kzfree(buf);
2268 return -ENOMEM;
2269 }
2270
2271 test_data.testentropy = &testentropy;
2272 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
2273 drbg_string_fill(&pers, test->pers, test->perslen);
2274 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
2275 if (ret) {
2276 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
2277 goto outbuf;
2278 }
2279
2280 drbg_string_fill(&addtl, test->addtla, test->addtllen);
2281 if (pr) {
2282 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
2283 ret = crypto_drbg_get_bytes_addtl_test(drng,
2284 buf, test->expectedlen, &addtl, &test_data);
2285 } else {
2286 ret = crypto_drbg_get_bytes_addtl(drng,
2287 buf, test->expectedlen, &addtl);
2288 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01002289 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002290 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002291 "driver %s\n", driver);
2292 goto outbuf;
2293 }
2294
2295 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
2296 if (pr) {
2297 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
2298 ret = crypto_drbg_get_bytes_addtl_test(drng,
2299 buf, test->expectedlen, &addtl, &test_data);
2300 } else {
2301 ret = crypto_drbg_get_bytes_addtl(drng,
2302 buf, test->expectedlen, &addtl);
2303 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01002304 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002305 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002306 "driver %s\n", driver);
2307 goto outbuf;
2308 }
2309
2310 ret = memcmp(test->expected, buf, test->expectedlen);
2311
2312outbuf:
2313 crypto_free_rng(drng);
2314 kzfree(buf);
2315 return ret;
2316}
2317
2318
2319static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
2320 u32 type, u32 mask)
2321{
2322 int err = 0;
2323 int pr = 0;
2324 int i = 0;
Eric Biggersb13b1e02017-02-24 15:46:59 -08002325 const struct drbg_testvec *template = desc->suite.drbg.vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002326 unsigned int tcount = desc->suite.drbg.count;
2327
2328 if (0 == memcmp(driver, "drbg_pr_", 8))
2329 pr = 1;
2330
2331 for (i = 0; i < tcount; i++) {
2332 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
2333 if (err) {
2334 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
2335 i, driver);
2336 err = -EINVAL;
2337 break;
2338 }
2339 }
2340 return err;
2341
2342}
2343
Eric Biggersb13b1e02017-02-24 15:46:59 -08002344static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002345 const char *alg)
2346{
2347 struct kpp_request *req;
2348 void *input_buf = NULL;
2349 void *output_buf = NULL;
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002350 void *a_public = NULL;
2351 void *a_ss = NULL;
2352 void *shared_secret = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002353 struct crypto_wait wait;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002354 unsigned int out_len_max;
2355 int err = -ENOMEM;
2356 struct scatterlist src, dst;
2357
2358 req = kpp_request_alloc(tfm, GFP_KERNEL);
2359 if (!req)
2360 return err;
2361
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002362 crypto_init_wait(&wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002363
2364 err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
2365 if (err < 0)
2366 goto free_req;
2367
2368 out_len_max = crypto_kpp_maxsize(tfm);
2369 output_buf = kzalloc(out_len_max, GFP_KERNEL);
2370 if (!output_buf) {
2371 err = -ENOMEM;
2372 goto free_req;
2373 }
2374
2375 /* Use appropriate parameter as base */
2376 kpp_request_set_input(req, NULL, 0);
2377 sg_init_one(&dst, output_buf, out_len_max);
2378 kpp_request_set_output(req, &dst, out_len_max);
2379 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002380 crypto_req_done, &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002381
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002382 /* Compute party A's public key */
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002383 err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002384 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002385 pr_err("alg: %s: Party A: generate public key test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002386 alg, err);
2387 goto free_output;
2388 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002389
2390 if (vec->genkey) {
2391 /* Save party A's public key */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05002392 a_public = kmemdup(sg_virt(req->dst), out_len_max, GFP_KERNEL);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002393 if (!a_public) {
2394 err = -ENOMEM;
2395 goto free_output;
2396 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002397 } else {
2398 /* Verify calculated public key */
2399 if (memcmp(vec->expected_a_public, sg_virt(req->dst),
2400 vec->expected_a_public_size)) {
2401 pr_err("alg: %s: Party A: generate public key test failed. Invalid output\n",
2402 alg);
2403 err = -EINVAL;
2404 goto free_output;
2405 }
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002406 }
2407
2408 /* Calculate shared secret key by using counter part (b) public key. */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05002409 input_buf = kmemdup(vec->b_public, vec->b_public_size, GFP_KERNEL);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002410 if (!input_buf) {
2411 err = -ENOMEM;
2412 goto free_output;
2413 }
2414
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002415 sg_init_one(&src, input_buf, vec->b_public_size);
2416 sg_init_one(&dst, output_buf, out_len_max);
2417 kpp_request_set_input(req, &src, vec->b_public_size);
2418 kpp_request_set_output(req, &dst, out_len_max);
2419 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002420 crypto_req_done, &wait);
2421 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002422 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002423 pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002424 alg, err);
2425 goto free_all;
2426 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002427
2428 if (vec->genkey) {
2429 /* Save the shared secret obtained by party A */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05002430 a_ss = kmemdup(sg_virt(req->dst), vec->expected_ss_size, GFP_KERNEL);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002431 if (!a_ss) {
2432 err = -ENOMEM;
2433 goto free_all;
2434 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002435
2436 /*
2437 * Calculate party B's shared secret by using party A's
2438 * public key.
2439 */
2440 err = crypto_kpp_set_secret(tfm, vec->b_secret,
2441 vec->b_secret_size);
2442 if (err < 0)
2443 goto free_all;
2444
2445 sg_init_one(&src, a_public, vec->expected_a_public_size);
2446 sg_init_one(&dst, output_buf, out_len_max);
2447 kpp_request_set_input(req, &src, vec->expected_a_public_size);
2448 kpp_request_set_output(req, &dst, out_len_max);
2449 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002450 crypto_req_done, &wait);
2451 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req),
2452 &wait);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002453 if (err) {
2454 pr_err("alg: %s: Party B: compute shared secret failed. err %d\n",
2455 alg, err);
2456 goto free_all;
2457 }
2458
2459 shared_secret = a_ss;
2460 } else {
2461 shared_secret = (void *)vec->expected_ss;
2462 }
2463
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002464 /*
2465 * verify shared secret from which the user will derive
2466 * secret key by executing whatever hash it has chosen
2467 */
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002468 if (memcmp(shared_secret, sg_virt(req->dst),
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002469 vec->expected_ss_size)) {
2470 pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
2471 alg);
2472 err = -EINVAL;
2473 }
2474
2475free_all:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002476 kfree(a_ss);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002477 kfree(input_buf);
2478free_output:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002479 kfree(a_public);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002480 kfree(output_buf);
2481free_req:
2482 kpp_request_free(req);
2483 return err;
2484}
2485
2486static int test_kpp(struct crypto_kpp *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002487 const struct kpp_testvec *vecs, unsigned int tcount)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002488{
2489 int ret, i;
2490
2491 for (i = 0; i < tcount; i++) {
2492 ret = do_test_kpp(tfm, vecs++, alg);
2493 if (ret) {
2494 pr_err("alg: %s: test failed on vector %d, err=%d\n",
2495 alg, i + 1, ret);
2496 return ret;
2497 }
2498 }
2499 return 0;
2500}
2501
2502static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
2503 u32 type, u32 mask)
2504{
2505 struct crypto_kpp *tfm;
2506 int err = 0;
2507
Herbert Xueed93e02016-11-22 20:08:31 +08002508 tfm = crypto_alloc_kpp(driver, type, mask);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002509 if (IS_ERR(tfm)) {
2510 pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
2511 driver, PTR_ERR(tfm));
2512 return PTR_ERR(tfm);
2513 }
2514 if (desc->suite.kpp.vecs)
2515 err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
2516 desc->suite.kpp.count);
2517
2518 crypto_free_kpp(tfm);
2519 return err;
2520}
2521
Herbert Xu50d2b6432016-06-29 19:32:20 +08002522static int test_akcipher_one(struct crypto_akcipher *tfm,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002523 const struct akcipher_testvec *vecs)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002524{
Herbert Xudf27b262016-05-05 16:42:49 +08002525 char *xbuf[XBUFSIZE];
Tadeusz Struk946cc462015-06-16 10:31:06 -07002526 struct akcipher_request *req;
2527 void *outbuf_enc = NULL;
2528 void *outbuf_dec = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002529 struct crypto_wait wait;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002530 unsigned int out_len_max, out_len = 0;
2531 int err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002532 struct scatterlist src, dst, src_tab[2];
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002533 const char *m, *c;
2534 unsigned int m_size, c_size;
2535 const char *op;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002536
Herbert Xudf27b262016-05-05 16:42:49 +08002537 if (testmgr_alloc_buf(xbuf))
2538 return err;
2539
Tadeusz Struk946cc462015-06-16 10:31:06 -07002540 req = akcipher_request_alloc(tfm, GFP_KERNEL);
2541 if (!req)
Herbert Xudf27b262016-05-05 16:42:49 +08002542 goto free_xbuf;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002543
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002544 crypto_init_wait(&wait);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002545
2546 if (vecs->public_key_vec)
2547 err = crypto_akcipher_set_pub_key(tfm, vecs->key,
2548 vecs->key_len);
2549 else
2550 err = crypto_akcipher_set_priv_key(tfm, vecs->key,
2551 vecs->key_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002552 if (err)
2553 goto free_req;
2554
Salvatore Benedetto57763f52016-07-04 10:52:34 +01002555 err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002556 out_len_max = crypto_akcipher_maxsize(tfm);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002557
2558 /*
2559 * First run test which do not require a private key, such as
2560 * encrypt or verify.
2561 */
Tadeusz Struk946cc462015-06-16 10:31:06 -07002562 outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
2563 if (!outbuf_enc)
2564 goto free_req;
2565
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002566 if (!vecs->siggen_sigver_test) {
2567 m = vecs->m;
2568 m_size = vecs->m_size;
2569 c = vecs->c;
2570 c_size = vecs->c_size;
2571 op = "encrypt";
2572 } else {
2573 /* Swap args so we could keep plaintext (digest)
2574 * in vecs->m, and cooked signature in vecs->c.
2575 */
2576 m = vecs->c; /* signature */
2577 m_size = vecs->c_size;
2578 c = vecs->m; /* digest */
2579 c_size = vecs->m_size;
2580 op = "verify";
2581 }
Herbert Xudf27b262016-05-05 16:42:49 +08002582
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002583 if (WARN_ON(m_size > PAGE_SIZE))
2584 goto free_all;
2585 memcpy(xbuf[0], m, m_size);
Herbert Xudf27b262016-05-05 16:42:49 +08002586
Tadeusz Struk22287b02015-10-08 09:26:55 -07002587 sg_init_table(src_tab, 2);
Herbert Xudf27b262016-05-05 16:42:49 +08002588 sg_set_buf(&src_tab[0], xbuf[0], 8);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002589 sg_set_buf(&src_tab[1], xbuf[0] + 8, m_size - 8);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002590 sg_init_one(&dst, outbuf_enc, out_len_max);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002591 akcipher_request_set_crypt(req, src_tab, &dst, m_size,
Tadeusz Struk22287b02015-10-08 09:26:55 -07002592 out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002593 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002594 crypto_req_done, &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002595
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002596 err = crypto_wait_req(vecs->siggen_sigver_test ?
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002597 /* Run asymmetric signature verification */
2598 crypto_akcipher_verify(req) :
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002599 /* Run asymmetric encrypt */
2600 crypto_akcipher_encrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002601 if (err) {
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002602 pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002603 goto free_all;
2604 }
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002605 if (req->dst_len != c_size) {
2606 pr_err("alg: akcipher: %s test failed. Invalid output len\n",
2607 op);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002608 err = -EINVAL;
2609 goto free_all;
2610 }
2611 /* verify that encrypted message is equal to expected */
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002612 if (memcmp(c, outbuf_enc, c_size)) {
2613 pr_err("alg: akcipher: %s test failed. Invalid output\n", op);
2614 hexdump(outbuf_enc, c_size);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002615 err = -EINVAL;
2616 goto free_all;
2617 }
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002618
2619 /*
2620 * Don't invoke (decrypt or sign) test which require a private key
2621 * for vectors with only a public key.
2622 */
Tadeusz Struk946cc462015-06-16 10:31:06 -07002623 if (vecs->public_key_vec) {
2624 err = 0;
2625 goto free_all;
2626 }
2627 outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
2628 if (!outbuf_dec) {
2629 err = -ENOMEM;
2630 goto free_all;
2631 }
Herbert Xudf27b262016-05-05 16:42:49 +08002632
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002633 op = vecs->siggen_sigver_test ? "sign" : "decrypt";
2634 if (WARN_ON(c_size > PAGE_SIZE))
Herbert Xudf27b262016-05-05 16:42:49 +08002635 goto free_all;
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002636 memcpy(xbuf[0], c, c_size);
Herbert Xudf27b262016-05-05 16:42:49 +08002637
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002638 sg_init_one(&src, xbuf[0], c_size);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002639 sg_init_one(&dst, outbuf_dec, out_len_max);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002640 crypto_init_wait(&wait);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002641 akcipher_request_set_crypt(req, &src, &dst, c_size, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002642
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002643 err = crypto_wait_req(vecs->siggen_sigver_test ?
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002644 /* Run asymmetric signature generation */
2645 crypto_akcipher_sign(req) :
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002646 /* Run asymmetric decrypt */
2647 crypto_akcipher_decrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002648 if (err) {
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002649 pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002650 goto free_all;
2651 }
2652 out_len = req->dst_len;
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002653 if (out_len < m_size) {
2654 pr_err("alg: akcipher: %s test failed. Invalid output len %u\n",
2655 op, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002656 err = -EINVAL;
2657 goto free_all;
2658 }
2659 /* verify that decrypted message is equal to the original msg */
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002660 if (memchr_inv(outbuf_dec, 0, out_len - m_size) ||
2661 memcmp(m, outbuf_dec + out_len - m_size, m_size)) {
2662 pr_err("alg: akcipher: %s test failed. Invalid output\n", op);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002663 hexdump(outbuf_dec, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002664 err = -EINVAL;
2665 }
2666free_all:
2667 kfree(outbuf_dec);
2668 kfree(outbuf_enc);
2669free_req:
2670 akcipher_request_free(req);
Herbert Xudf27b262016-05-05 16:42:49 +08002671free_xbuf:
2672 testmgr_free_buf(xbuf);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002673 return err;
2674}
2675
Herbert Xu50d2b6432016-06-29 19:32:20 +08002676static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002677 const struct akcipher_testvec *vecs,
2678 unsigned int tcount)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002679{
Herbert Xu15226e42016-07-18 18:20:10 +08002680 const char *algo =
2681 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
Tadeusz Struk946cc462015-06-16 10:31:06 -07002682 int ret, i;
2683
2684 for (i = 0; i < tcount; i++) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002685 ret = test_akcipher_one(tfm, vecs++);
2686 if (!ret)
2687 continue;
2688
Herbert Xu15226e42016-07-18 18:20:10 +08002689 pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
2690 i + 1, algo, ret);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002691 return ret;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002692 }
2693 return 0;
2694}
2695
Tadeusz Struk946cc462015-06-16 10:31:06 -07002696static int alg_test_akcipher(const struct alg_test_desc *desc,
2697 const char *driver, u32 type, u32 mask)
2698{
2699 struct crypto_akcipher *tfm;
2700 int err = 0;
2701
Herbert Xueed93e02016-11-22 20:08:31 +08002702 tfm = crypto_alloc_akcipher(driver, type, mask);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002703 if (IS_ERR(tfm)) {
2704 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
2705 driver, PTR_ERR(tfm));
2706 return PTR_ERR(tfm);
2707 }
2708 if (desc->suite.akcipher.vecs)
2709 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
2710 desc->suite.akcipher.count);
2711
2712 crypto_free_akcipher(tfm);
2713 return err;
2714}
2715
Youquan, Song863b5572009-12-23 19:45:20 +08002716static int alg_test_null(const struct alg_test_desc *desc,
2717 const char *driver, u32 type, u32 mask)
2718{
2719 return 0;
2720}
2721
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002722#define __VECS(tv) { .vecs = tv, .count = ARRAY_SIZE(tv) }
2723
Herbert Xuda7f0332008-07-31 17:08:25 +08002724/* Please keep this list sorted by algorithm name. */
2725static const struct alg_test_desc alg_test_descs[] = {
2726 {
Eric Biggers059c2a42018-11-16 17:26:31 -08002727 .alg = "adiantum(xchacha12,aes)",
2728 .test = alg_test_skcipher,
2729 .suite = {
2730 .cipher = __VECS(adiantum_xchacha12_aes_tv_template)
2731 },
2732 }, {
2733 .alg = "adiantum(xchacha20,aes)",
2734 .test = alg_test_skcipher,
2735 .suite = {
2736 .cipher = __VECS(adiantum_xchacha20_aes_tv_template)
2737 },
2738 }, {
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002739 .alg = "aegis128",
2740 .test = alg_test_aead,
2741 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002742 .aead = __VECS(aegis128_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002743 }
2744 }, {
2745 .alg = "aegis128l",
2746 .test = alg_test_aead,
2747 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002748 .aead = __VECS(aegis128l_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002749 }
2750 }, {
2751 .alg = "aegis256",
2752 .test = alg_test_aead,
2753 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002754 .aead = __VECS(aegis256_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02002755 }
2756 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002757 .alg = "ansi_cprng",
2758 .test = alg_test_cprng,
2759 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002760 .cprng = __VECS(ansi_cprng_aes_tv_template)
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08002761 }
2762 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002763 .alg = "authenc(hmac(md5),ecb(cipher_null))",
2764 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002765 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002766 .aead = __VECS(hmac_md5_ecb_cipher_null_tv_template)
Horia Geantabca4feb2014-03-14 17:46:51 +02002767 }
2768 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002769 .alg = "authenc(hmac(sha1),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002770 .test = alg_test_aead,
Herbert Xubcf741c2017-06-28 19:09:07 +08002771 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002772 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002773 .aead = __VECS(hmac_sha1_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302774 }
2775 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002776 .alg = "authenc(hmac(sha1),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302777 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302778 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002779 .aead = __VECS(hmac_sha1_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302780 }
2781 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002782 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302783 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002784 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302785 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002786 .aead = __VECS(hmac_sha1_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002787 }
2788 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002789 .alg = "authenc(hmac(sha1),ctr(aes))",
2790 .test = alg_test_null,
2791 .fips_allowed = 1,
2792 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02002793 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
2794 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02002795 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002796 .aead = __VECS(hmac_sha1_ecb_cipher_null_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302797 }
2798 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002799 .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
2800 .test = alg_test_null,
2801 .fips_allowed = 1,
2802 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002803 .alg = "authenc(hmac(sha224),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302804 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302805 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002806 .aead = __VECS(hmac_sha224_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302807 }
2808 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002809 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302810 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002811 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302812 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002813 .aead = __VECS(hmac_sha224_des3_ede_cbc_tv_temp)
Horia Geantabca4feb2014-03-14 17:46:51 +02002814 }
2815 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002816 .alg = "authenc(hmac(sha256),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03002817 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002818 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002819 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002820 .aead = __VECS(hmac_sha256_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302821 }
2822 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002823 .alg = "authenc(hmac(sha256),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302824 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302825 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002826 .aead = __VECS(hmac_sha256_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302827 }
2828 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002829 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302830 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002831 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302832 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002833 .aead = __VECS(hmac_sha256_des3_ede_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302834 }
2835 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002836 .alg = "authenc(hmac(sha256),ctr(aes))",
2837 .test = alg_test_null,
2838 .fips_allowed = 1,
2839 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002840 .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
2841 .test = alg_test_null,
2842 .fips_allowed = 1,
2843 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002844 .alg = "authenc(hmac(sha384),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302845 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302846 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002847 .aead = __VECS(hmac_sha384_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302848 }
2849 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002850 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302851 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002852 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302853 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002854 .aead = __VECS(hmac_sha384_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002855 }
2856 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002857 .alg = "authenc(hmac(sha384),ctr(aes))",
2858 .test = alg_test_null,
2859 .fips_allowed = 1,
2860 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002861 .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
2862 .test = alg_test_null,
2863 .fips_allowed = 1,
2864 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002865 .alg = "authenc(hmac(sha512),cbc(aes))",
Marcus Meissnered1afac2016-02-05 14:23:33 +01002866 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03002867 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03002868 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002869 .aead = __VECS(hmac_sha512_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302870 }
2871 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002872 .alg = "authenc(hmac(sha512),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302873 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302874 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002875 .aead = __VECS(hmac_sha512_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05302876 }
2877 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08002878 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05302879 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01002880 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05302881 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002882 .aead = __VECS(hmac_sha512_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03002883 }
2884 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01002885 .alg = "authenc(hmac(sha512),ctr(aes))",
2886 .test = alg_test_null,
2887 .fips_allowed = 1,
2888 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01002889 .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
2890 .test = alg_test_null,
2891 .fips_allowed = 1,
2892 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002893 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002894 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002895 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002896 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002897 .cipher = __VECS(aes_cbc_tv_template)
2898 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002899 }, {
2900 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002901 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002902 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002903 .cipher = __VECS(anubis_cbc_tv_template)
2904 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002905 }, {
2906 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002907 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002908 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002909 .cipher = __VECS(bf_cbc_tv_template)
2910 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002911 }, {
2912 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002913 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002914 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002915 .cipher = __VECS(camellia_cbc_tv_template)
2916 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002917 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002918 .alg = "cbc(cast5)",
2919 .test = alg_test_skcipher,
2920 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002921 .cipher = __VECS(cast5_cbc_tv_template)
2922 },
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002923 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002924 .alg = "cbc(cast6)",
2925 .test = alg_test_skcipher,
2926 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002927 .cipher = __VECS(cast6_cbc_tv_template)
2928 },
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002929 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002930 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002931 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002932 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002933 .cipher = __VECS(des_cbc_tv_template)
2934 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002935 }, {
2936 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002937 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002938 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002939 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002940 .cipher = __VECS(des3_ede_cbc_tv_template)
2941 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002942 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01002943 /* Same as cbc(aes) except the key is stored in
2944 * hardware secure memory which we reference by index
2945 */
2946 .alg = "cbc(paes)",
2947 .test = alg_test_null,
2948 .fips_allowed = 1,
2949 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002950 .alg = "cbc(serpent)",
2951 .test = alg_test_skcipher,
2952 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002953 .cipher = __VECS(serpent_cbc_tv_template)
2954 },
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002955 }, {
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01002956 .alg = "cbc(sm4)",
2957 .test = alg_test_skcipher,
2958 .suite = {
2959 .cipher = __VECS(sm4_cbc_tv_template)
2960 }
2961 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002962 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002963 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002964 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002965 .cipher = __VECS(tf_cbc_tv_template)
2966 },
Herbert Xuda7f0332008-07-31 17:08:25 +08002967 }, {
Ard Biesheuvel092acf02017-02-03 14:49:35 +00002968 .alg = "cbcmac(aes)",
2969 .fips_allowed = 1,
2970 .test = alg_test_hash,
2971 .suite = {
2972 .hash = __VECS(aes_cbcmac_tv_template)
2973 }
2974 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002975 .alg = "ccm(aes)",
2976 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002977 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002978 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002979 .aead = __VECS(aes_ccm_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08002980 }
2981 }, {
Dmitry Eremin-Solenikov7da66672018-10-20 02:01:53 +03002982 .alg = "cfb(aes)",
2983 .test = alg_test_skcipher,
2984 .fips_allowed = 1,
2985 .suite = {
2986 .cipher = __VECS(aes_cfb_tv_template)
2987 },
2988 }, {
Martin Willi3590ebf2015-06-01 13:43:57 +02002989 .alg = "chacha20",
2990 .test = alg_test_skcipher,
2991 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002992 .cipher = __VECS(chacha20_tv_template)
2993 },
Martin Willi3590ebf2015-06-01 13:43:57 +02002994 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002995 .alg = "cmac(aes)",
Stephan Mueller8f183752015-08-19 08:42:07 +02002996 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002997 .test = alg_test_hash,
2998 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002999 .hash = __VECS(aes_cmac128_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003000 }
3001 }, {
3002 .alg = "cmac(des3_ede)",
Stephan Mueller8f183752015-08-19 08:42:07 +02003003 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003004 .test = alg_test_hash,
3005 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003006 .hash = __VECS(des3_ede_cmac64_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003007 }
3008 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003009 .alg = "compress_null",
3010 .test = alg_test_null,
3011 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003012 .alg = "crc32",
3013 .test = alg_test_hash,
Milan Broza8a34412019-01-25 10:31:47 +01003014 .fips_allowed = 1,
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003015 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003016 .hash = __VECS(crc32_tv_template)
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003017 }
3018 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003019 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08003020 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003021 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003022 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003023 .hash = __VECS(crc32c_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003024 }
3025 }, {
Herbert Xu684115212013-09-07 12:56:26 +10003026 .alg = "crct10dif",
3027 .test = alg_test_hash,
3028 .fips_allowed = 1,
3029 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003030 .hash = __VECS(crct10dif_tv_template)
Herbert Xu684115212013-09-07 12:56:26 +10003031 }
3032 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003033 .alg = "ctr(aes)",
3034 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003035 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003036 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003037 .cipher = __VECS(aes_ctr_tv_template)
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003038 }
3039 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03003040 .alg = "ctr(blowfish)",
3041 .test = alg_test_skcipher,
3042 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003043 .cipher = __VECS(bf_ctr_tv_template)
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03003044 }
3045 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003046 .alg = "ctr(camellia)",
3047 .test = alg_test_skcipher,
3048 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003049 .cipher = __VECS(camellia_ctr_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003050 }
3051 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003052 .alg = "ctr(cast5)",
3053 .test = alg_test_skcipher,
3054 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003055 .cipher = __VECS(cast5_ctr_tv_template)
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003056 }
3057 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003058 .alg = "ctr(cast6)",
3059 .test = alg_test_skcipher,
3060 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003061 .cipher = __VECS(cast6_ctr_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003062 }
3063 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03003064 .alg = "ctr(des)",
3065 .test = alg_test_skcipher,
3066 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003067 .cipher = __VECS(des_ctr_tv_template)
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03003068 }
3069 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003070 .alg = "ctr(des3_ede)",
3071 .test = alg_test_skcipher,
Marcelo Cerri0d8da102017-03-20 17:28:05 -03003072 .fips_allowed = 1,
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003073 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003074 .cipher = __VECS(des3_ede_ctr_tv_template)
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003075 }
3076 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003077 /* Same as ctr(aes) except the key is stored in
3078 * hardware secure memory which we reference by index
3079 */
3080 .alg = "ctr(paes)",
3081 .test = alg_test_null,
3082 .fips_allowed = 1,
3083 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003084 .alg = "ctr(serpent)",
3085 .test = alg_test_skcipher,
3086 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003087 .cipher = __VECS(serpent_ctr_tv_template)
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003088 }
3089 }, {
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01003090 .alg = "ctr(sm4)",
3091 .test = alg_test_skcipher,
3092 .suite = {
3093 .cipher = __VECS(sm4_ctr_tv_template)
3094 }
3095 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03003096 .alg = "ctr(twofish)",
3097 .test = alg_test_skcipher,
3098 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003099 .cipher = __VECS(tf_ctr_tv_template)
Jussi Kivilinna573da622011-10-10 23:03:12 +03003100 }
3101 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003102 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003103 .test = alg_test_skcipher,
Gilad Ben-Yossef196ad602018-11-04 10:05:24 +00003104 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003105 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003106 .cipher = __VECS(cts_mode_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003107 }
3108 }, {
3109 .alg = "deflate",
3110 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003111 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003112 .suite = {
3113 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003114 .comp = __VECS(deflate_comp_tv_template),
3115 .decomp = __VECS(deflate_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003116 }
3117 }
3118 }, {
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003119 .alg = "dh",
3120 .test = alg_test_kpp,
3121 .fips_allowed = 1,
3122 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003123 .kpp = __VECS(dh_tv_template)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003124 }
3125 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003126 .alg = "digest_null",
3127 .test = alg_test_null,
3128 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003129 .alg = "drbg_nopr_ctr_aes128",
3130 .test = alg_test_drbg,
3131 .fips_allowed = 1,
3132 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003133 .drbg = __VECS(drbg_nopr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003134 }
3135 }, {
3136 .alg = "drbg_nopr_ctr_aes192",
3137 .test = alg_test_drbg,
3138 .fips_allowed = 1,
3139 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003140 .drbg = __VECS(drbg_nopr_ctr_aes192_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003141 }
3142 }, {
3143 .alg = "drbg_nopr_ctr_aes256",
3144 .test = alg_test_drbg,
3145 .fips_allowed = 1,
3146 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003147 .drbg = __VECS(drbg_nopr_ctr_aes256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003148 }
3149 }, {
3150 /*
3151 * There is no need to specifically test the DRBG with every
3152 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
3153 */
3154 .alg = "drbg_nopr_hmac_sha1",
3155 .fips_allowed = 1,
3156 .test = alg_test_null,
3157 }, {
3158 .alg = "drbg_nopr_hmac_sha256",
3159 .test = alg_test_drbg,
3160 .fips_allowed = 1,
3161 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003162 .drbg = __VECS(drbg_nopr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003163 }
3164 }, {
3165 /* covered by drbg_nopr_hmac_sha256 test */
3166 .alg = "drbg_nopr_hmac_sha384",
3167 .fips_allowed = 1,
3168 .test = alg_test_null,
3169 }, {
3170 .alg = "drbg_nopr_hmac_sha512",
3171 .test = alg_test_null,
3172 .fips_allowed = 1,
3173 }, {
3174 .alg = "drbg_nopr_sha1",
3175 .fips_allowed = 1,
3176 .test = alg_test_null,
3177 }, {
3178 .alg = "drbg_nopr_sha256",
3179 .test = alg_test_drbg,
3180 .fips_allowed = 1,
3181 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003182 .drbg = __VECS(drbg_nopr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003183 }
3184 }, {
3185 /* covered by drbg_nopr_sha256 test */
3186 .alg = "drbg_nopr_sha384",
3187 .fips_allowed = 1,
3188 .test = alg_test_null,
3189 }, {
3190 .alg = "drbg_nopr_sha512",
3191 .fips_allowed = 1,
3192 .test = alg_test_null,
3193 }, {
3194 .alg = "drbg_pr_ctr_aes128",
3195 .test = alg_test_drbg,
3196 .fips_allowed = 1,
3197 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003198 .drbg = __VECS(drbg_pr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003199 }
3200 }, {
3201 /* covered by drbg_pr_ctr_aes128 test */
3202 .alg = "drbg_pr_ctr_aes192",
3203 .fips_allowed = 1,
3204 .test = alg_test_null,
3205 }, {
3206 .alg = "drbg_pr_ctr_aes256",
3207 .fips_allowed = 1,
3208 .test = alg_test_null,
3209 }, {
3210 .alg = "drbg_pr_hmac_sha1",
3211 .fips_allowed = 1,
3212 .test = alg_test_null,
3213 }, {
3214 .alg = "drbg_pr_hmac_sha256",
3215 .test = alg_test_drbg,
3216 .fips_allowed = 1,
3217 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003218 .drbg = __VECS(drbg_pr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003219 }
3220 }, {
3221 /* covered by drbg_pr_hmac_sha256 test */
3222 .alg = "drbg_pr_hmac_sha384",
3223 .fips_allowed = 1,
3224 .test = alg_test_null,
3225 }, {
3226 .alg = "drbg_pr_hmac_sha512",
3227 .test = alg_test_null,
3228 .fips_allowed = 1,
3229 }, {
3230 .alg = "drbg_pr_sha1",
3231 .fips_allowed = 1,
3232 .test = alg_test_null,
3233 }, {
3234 .alg = "drbg_pr_sha256",
3235 .test = alg_test_drbg,
3236 .fips_allowed = 1,
3237 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003238 .drbg = __VECS(drbg_pr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003239 }
3240 }, {
3241 /* covered by drbg_pr_sha256 test */
3242 .alg = "drbg_pr_sha384",
3243 .fips_allowed = 1,
3244 .test = alg_test_null,
3245 }, {
3246 .alg = "drbg_pr_sha512",
3247 .fips_allowed = 1,
3248 .test = alg_test_null,
3249 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003250 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003251 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003252 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003253 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003254 .cipher = __VECS(aes_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003255 }
3256 }, {
3257 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003258 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003259 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003260 .cipher = __VECS(anubis_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003261 }
3262 }, {
3263 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003264 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003265 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003266 .cipher = __VECS(arc4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003267 }
3268 }, {
3269 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003270 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003271 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003272 .cipher = __VECS(bf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003273 }
3274 }, {
3275 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003276 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003277 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003278 .cipher = __VECS(camellia_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003279 }
3280 }, {
3281 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003282 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003283 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003284 .cipher = __VECS(cast5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003285 }
3286 }, {
3287 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003288 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003289 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003290 .cipher = __VECS(cast6_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003291 }
3292 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003293 .alg = "ecb(cipher_null)",
3294 .test = alg_test_null,
Milan Broz6175ca22017-04-21 13:03:06 +02003295 .fips_allowed = 1,
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003296 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003297 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003298 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003299 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003300 .cipher = __VECS(des_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003301 }
3302 }, {
3303 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003304 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003305 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003306 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003307 .cipher = __VECS(des3_ede_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003308 }
3309 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003310 .alg = "ecb(fcrypt)",
3311 .test = alg_test_skcipher,
3312 .suite = {
3313 .cipher = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003314 .vecs = fcrypt_pcbc_tv_template,
3315 .count = 1
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003316 }
3317 }
3318 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003319 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003320 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003321 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003322 .cipher = __VECS(khazad_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003323 }
3324 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003325 /* Same as ecb(aes) except the key is stored in
3326 * hardware secure memory which we reference by index
3327 */
3328 .alg = "ecb(paes)",
3329 .test = alg_test_null,
3330 .fips_allowed = 1,
3331 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003332 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003333 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003334 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003335 .cipher = __VECS(seed_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003336 }
3337 }, {
3338 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003339 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003340 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003341 .cipher = __VECS(serpent_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003342 }
3343 }, {
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00003344 .alg = "ecb(sm4)",
3345 .test = alg_test_skcipher,
3346 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003347 .cipher = __VECS(sm4_tv_template)
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00003348 }
3349 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003350 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003351 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003352 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003353 .cipher = __VECS(tea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003354 }
3355 }, {
3356 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003357 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003358 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003359 .cipher = __VECS(tnepres_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003360 }
3361 }, {
3362 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003363 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003364 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003365 .cipher = __VECS(tf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003366 }
3367 }, {
3368 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003369 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003370 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003371 .cipher = __VECS(xeta_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003372 }
3373 }, {
3374 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003375 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003376 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003377 .cipher = __VECS(xtea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003378 }
3379 }, {
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003380 .alg = "ecdh",
3381 .test = alg_test_kpp,
3382 .fips_allowed = 1,
3383 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003384 .kpp = __VECS(ecdh_tv_template)
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003385 }
3386 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003387 .alg = "gcm(aes)",
3388 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003389 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003390 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003391 .aead = __VECS(aes_gcm_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003392 }
3393 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003394 .alg = "ghash",
3395 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003396 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003397 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003398 .hash = __VECS(ghash_tv_template)
Youquan, Song507069c2009-11-23 20:23:04 +08003399 }
3400 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003401 .alg = "hmac(md5)",
3402 .test = alg_test_hash,
3403 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003404 .hash = __VECS(hmac_md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003405 }
3406 }, {
3407 .alg = "hmac(rmd128)",
3408 .test = alg_test_hash,
3409 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003410 .hash = __VECS(hmac_rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003411 }
3412 }, {
3413 .alg = "hmac(rmd160)",
3414 .test = alg_test_hash,
3415 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003416 .hash = __VECS(hmac_rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003417 }
3418 }, {
3419 .alg = "hmac(sha1)",
3420 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003421 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003422 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003423 .hash = __VECS(hmac_sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003424 }
3425 }, {
3426 .alg = "hmac(sha224)",
3427 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003428 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003429 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003430 .hash = __VECS(hmac_sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003431 }
3432 }, {
3433 .alg = "hmac(sha256)",
3434 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003435 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003436 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003437 .hash = __VECS(hmac_sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003438 }
3439 }, {
raveendra padasalagi98eca722016-07-01 11:16:54 +05303440 .alg = "hmac(sha3-224)",
3441 .test = alg_test_hash,
3442 .fips_allowed = 1,
3443 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003444 .hash = __VECS(hmac_sha3_224_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303445 }
3446 }, {
3447 .alg = "hmac(sha3-256)",
3448 .test = alg_test_hash,
3449 .fips_allowed = 1,
3450 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003451 .hash = __VECS(hmac_sha3_256_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303452 }
3453 }, {
3454 .alg = "hmac(sha3-384)",
3455 .test = alg_test_hash,
3456 .fips_allowed = 1,
3457 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003458 .hash = __VECS(hmac_sha3_384_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303459 }
3460 }, {
3461 .alg = "hmac(sha3-512)",
3462 .test = alg_test_hash,
3463 .fips_allowed = 1,
3464 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003465 .hash = __VECS(hmac_sha3_512_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303466 }
3467 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003468 .alg = "hmac(sha384)",
3469 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003470 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003471 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003472 .hash = __VECS(hmac_sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003473 }
3474 }, {
3475 .alg = "hmac(sha512)",
3476 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003477 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003478 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003479 .hash = __VECS(hmac_sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003480 }
3481 }, {
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03003482 .alg = "hmac(streebog256)",
3483 .test = alg_test_hash,
3484 .suite = {
3485 .hash = __VECS(hmac_streebog256_tv_template)
3486 }
3487 }, {
3488 .alg = "hmac(streebog512)",
3489 .test = alg_test_hash,
3490 .suite = {
3491 .hash = __VECS(hmac_streebog512_tv_template)
3492 }
3493 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003494 .alg = "jitterentropy_rng",
3495 .fips_allowed = 1,
3496 .test = alg_test_null,
3497 }, {
Stephan Mueller35351982015-09-21 20:59:56 +02003498 .alg = "kw(aes)",
3499 .test = alg_test_skcipher,
3500 .fips_allowed = 1,
3501 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003502 .cipher = __VECS(aes_kw_tv_template)
Stephan Mueller35351982015-09-21 20:59:56 +02003503 }
3504 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003505 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003506 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003507 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003508 .cipher = __VECS(aes_lrw_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003509 }
3510 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003511 .alg = "lrw(camellia)",
3512 .test = alg_test_skcipher,
3513 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003514 .cipher = __VECS(camellia_lrw_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003515 }
3516 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003517 .alg = "lrw(cast6)",
3518 .test = alg_test_skcipher,
3519 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003520 .cipher = __VECS(cast6_lrw_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003521 }
3522 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003523 .alg = "lrw(serpent)",
3524 .test = alg_test_skcipher,
3525 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003526 .cipher = __VECS(serpent_lrw_tv_template)
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003527 }
3528 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003529 .alg = "lrw(twofish)",
3530 .test = alg_test_skcipher,
3531 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003532 .cipher = __VECS(tf_lrw_tv_template)
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003533 }
3534 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003535 .alg = "lz4",
3536 .test = alg_test_comp,
3537 .fips_allowed = 1,
3538 .suite = {
3539 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003540 .comp = __VECS(lz4_comp_tv_template),
3541 .decomp = __VECS(lz4_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003542 }
3543 }
3544 }, {
3545 .alg = "lz4hc",
3546 .test = alg_test_comp,
3547 .fips_allowed = 1,
3548 .suite = {
3549 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003550 .comp = __VECS(lz4hc_comp_tv_template),
3551 .decomp = __VECS(lz4hc_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003552 }
3553 }
3554 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003555 .alg = "lzo",
3556 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003557 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003558 .suite = {
3559 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003560 .comp = __VECS(lzo_comp_tv_template),
3561 .decomp = __VECS(lzo_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003562 }
3563 }
3564 }, {
3565 .alg = "md4",
3566 .test = alg_test_hash,
3567 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003568 .hash = __VECS(md4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003569 }
3570 }, {
3571 .alg = "md5",
3572 .test = alg_test_hash,
3573 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003574 .hash = __VECS(md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003575 }
3576 }, {
3577 .alg = "michael_mic",
3578 .test = alg_test_hash,
3579 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003580 .hash = __VECS(michael_mic_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003581 }
3582 }, {
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003583 .alg = "morus1280",
3584 .test = alg_test_aead,
3585 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003586 .aead = __VECS(morus1280_tv_template)
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003587 }
3588 }, {
3589 .alg = "morus640",
3590 .test = alg_test_aead,
3591 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003592 .aead = __VECS(morus640_tv_template)
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003593 }
3594 }, {
Eric Biggers26609a22018-11-16 17:26:29 -08003595 .alg = "nhpoly1305",
3596 .test = alg_test_hash,
3597 .suite = {
3598 .hash = __VECS(nhpoly1305_tv_template)
3599 }
3600 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003601 .alg = "ofb(aes)",
3602 .test = alg_test_skcipher,
3603 .fips_allowed = 1,
3604 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003605 .cipher = __VECS(aes_ofb_tv_template)
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003606 }
3607 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003608 /* Same as ofb(aes) except the key is stored in
3609 * hardware secure memory which we reference by index
3610 */
3611 .alg = "ofb(paes)",
3612 .test = alg_test_null,
3613 .fips_allowed = 1,
3614 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003615 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003616 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003617 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003618 .cipher = __VECS(fcrypt_pcbc_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003619 }
3620 }, {
Stephan Mueller12071072017-06-12 23:27:51 +02003621 .alg = "pkcs1pad(rsa,sha224)",
3622 .test = alg_test_null,
3623 .fips_allowed = 1,
3624 }, {
3625 .alg = "pkcs1pad(rsa,sha256)",
3626 .test = alg_test_akcipher,
3627 .fips_allowed = 1,
3628 .suite = {
3629 .akcipher = __VECS(pkcs1pad_rsa_tv_template)
3630 }
3631 }, {
3632 .alg = "pkcs1pad(rsa,sha384)",
3633 .test = alg_test_null,
3634 .fips_allowed = 1,
3635 }, {
3636 .alg = "pkcs1pad(rsa,sha512)",
3637 .test = alg_test_null,
3638 .fips_allowed = 1,
3639 }, {
Martin Willieee9dc62015-06-01 13:43:59 +02003640 .alg = "poly1305",
3641 .test = alg_test_hash,
3642 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003643 .hash = __VECS(poly1305_tv_template)
Martin Willieee9dc62015-06-01 13:43:59 +02003644 }
3645 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003646 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003647 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003648 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003649 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003650 .cipher = __VECS(aes_ctr_rfc3686_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003651 }
3652 }, {
Herbert Xu3f31a742015-07-09 07:17:34 +08003653 .alg = "rfc4106(gcm(aes))",
Adrian Hoban69435b92010-11-04 15:02:04 -04003654 .test = alg_test_aead,
Jarod Wilsondb71f29a2015-01-23 12:42:15 -05003655 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003656 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003657 .aead = __VECS(aes_gcm_rfc4106_tv_template)
Adrian Hoban69435b92010-11-04 15:02:04 -04003658 }
3659 }, {
Herbert Xu544c4362015-07-14 16:53:22 +08003660 .alg = "rfc4309(ccm(aes))",
Jarod Wilson5d667322009-05-04 19:23:40 +08003661 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003662 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003663 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003664 .aead = __VECS(aes_ccm_rfc4309_tv_template)
Jarod Wilson5d667322009-05-04 19:23:40 +08003665 }
3666 }, {
Herbert Xubb687452015-06-16 13:54:24 +08003667 .alg = "rfc4543(gcm(aes))",
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003668 .test = alg_test_aead,
3669 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003670 .aead = __VECS(aes_gcm_rfc4543_tv_template)
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003671 }
3672 }, {
Martin Williaf2b76b2015-06-01 13:44:01 +02003673 .alg = "rfc7539(chacha20,poly1305)",
3674 .test = alg_test_aead,
3675 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003676 .aead = __VECS(rfc7539_tv_template)
Martin Williaf2b76b2015-06-01 13:44:01 +02003677 }
3678 }, {
Martin Willi59007582015-06-01 13:44:03 +02003679 .alg = "rfc7539esp(chacha20,poly1305)",
3680 .test = alg_test_aead,
3681 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003682 .aead = __VECS(rfc7539esp_tv_template)
Martin Willi59007582015-06-01 13:44:03 +02003683 }
3684 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003685 .alg = "rmd128",
3686 .test = alg_test_hash,
3687 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003688 .hash = __VECS(rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003689 }
3690 }, {
3691 .alg = "rmd160",
3692 .test = alg_test_hash,
3693 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003694 .hash = __VECS(rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003695 }
3696 }, {
3697 .alg = "rmd256",
3698 .test = alg_test_hash,
3699 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003700 .hash = __VECS(rmd256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003701 }
3702 }, {
3703 .alg = "rmd320",
3704 .test = alg_test_hash,
3705 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003706 .hash = __VECS(rmd320_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003707 }
3708 }, {
Tadeusz Struk946cc462015-06-16 10:31:06 -07003709 .alg = "rsa",
3710 .test = alg_test_akcipher,
3711 .fips_allowed = 1,
3712 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003713 .akcipher = __VECS(rsa_tv_template)
Tadeusz Struk946cc462015-06-16 10:31:06 -07003714 }
3715 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003716 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003717 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003718 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003719 .cipher = __VECS(salsa20_stream_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003720 }
3721 }, {
3722 .alg = "sha1",
3723 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003724 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003725 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003726 .hash = __VECS(sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003727 }
3728 }, {
3729 .alg = "sha224",
3730 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003731 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003732 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003733 .hash = __VECS(sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003734 }
3735 }, {
3736 .alg = "sha256",
3737 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003738 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003739 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003740 .hash = __VECS(sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003741 }
3742 }, {
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303743 .alg = "sha3-224",
3744 .test = alg_test_hash,
3745 .fips_allowed = 1,
3746 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003747 .hash = __VECS(sha3_224_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303748 }
3749 }, {
3750 .alg = "sha3-256",
3751 .test = alg_test_hash,
3752 .fips_allowed = 1,
3753 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003754 .hash = __VECS(sha3_256_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303755 }
3756 }, {
3757 .alg = "sha3-384",
3758 .test = alg_test_hash,
3759 .fips_allowed = 1,
3760 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003761 .hash = __VECS(sha3_384_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303762 }
3763 }, {
3764 .alg = "sha3-512",
3765 .test = alg_test_hash,
3766 .fips_allowed = 1,
3767 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003768 .hash = __VECS(sha3_512_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05303769 }
3770 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003771 .alg = "sha384",
3772 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003773 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003774 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003775 .hash = __VECS(sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003776 }
3777 }, {
3778 .alg = "sha512",
3779 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003780 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003781 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003782 .hash = __VECS(sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003783 }
3784 }, {
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03003785 .alg = "sm3",
3786 .test = alg_test_hash,
3787 .suite = {
3788 .hash = __VECS(sm3_tv_template)
3789 }
3790 }, {
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03003791 .alg = "streebog256",
3792 .test = alg_test_hash,
3793 .suite = {
3794 .hash = __VECS(streebog256_tv_template)
3795 }
3796 }, {
3797 .alg = "streebog512",
3798 .test = alg_test_hash,
3799 .suite = {
3800 .hash = __VECS(streebog512_tv_template)
3801 }
3802 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003803 .alg = "tgr128",
3804 .test = alg_test_hash,
3805 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003806 .hash = __VECS(tgr128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003807 }
3808 }, {
3809 .alg = "tgr160",
3810 .test = alg_test_hash,
3811 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003812 .hash = __VECS(tgr160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003813 }
3814 }, {
3815 .alg = "tgr192",
3816 .test = alg_test_hash,
3817 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003818 .hash = __VECS(tgr192_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003819 }
3820 }, {
Eric Biggersed331ad2018-06-18 10:22:39 -07003821 .alg = "vmac64(aes)",
3822 .test = alg_test_hash,
3823 .suite = {
3824 .hash = __VECS(vmac64_aes_tv_template)
3825 }
3826 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003827 .alg = "wp256",
3828 .test = alg_test_hash,
3829 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003830 .hash = __VECS(wp256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003831 }
3832 }, {
3833 .alg = "wp384",
3834 .test = alg_test_hash,
3835 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003836 .hash = __VECS(wp384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003837 }
3838 }, {
3839 .alg = "wp512",
3840 .test = alg_test_hash,
3841 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003842 .hash = __VECS(wp512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003843 }
3844 }, {
3845 .alg = "xcbc(aes)",
3846 .test = alg_test_hash,
3847 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003848 .hash = __VECS(aes_xcbc128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003849 }
3850 }, {
Eric Biggersaa762402018-11-16 17:26:22 -08003851 .alg = "xchacha12",
3852 .test = alg_test_skcipher,
3853 .suite = {
3854 .cipher = __VECS(xchacha12_tv_template)
3855 },
3856 }, {
Eric Biggersde61d7a2018-11-16 17:26:20 -08003857 .alg = "xchacha20",
3858 .test = alg_test_skcipher,
3859 .suite = {
3860 .cipher = __VECS(xchacha20_tv_template)
3861 },
3862 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003863 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003864 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003865 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003866 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003867 .cipher = __VECS(aes_xts_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003868 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003869 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003870 .alg = "xts(camellia)",
3871 .test = alg_test_skcipher,
3872 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003873 .cipher = __VECS(camellia_xts_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003874 }
3875 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003876 .alg = "xts(cast6)",
3877 .test = alg_test_skcipher,
3878 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003879 .cipher = __VECS(cast6_xts_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003880 }
3881 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003882 /* Same as xts(aes) except the key is stored in
3883 * hardware secure memory which we reference by index
3884 */
3885 .alg = "xts(paes)",
3886 .test = alg_test_null,
3887 .fips_allowed = 1,
3888 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003889 .alg = "xts(serpent)",
3890 .test = alg_test_skcipher,
3891 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003892 .cipher = __VECS(serpent_xts_tv_template)
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003893 }
3894 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003895 .alg = "xts(twofish)",
3896 .test = alg_test_skcipher,
3897 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003898 .cipher = __VECS(tf_xts_tv_template)
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003899 }
Giovanni Cabiddua368f432017-04-21 21:54:30 +01003900 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003901 .alg = "xts4096(paes)",
3902 .test = alg_test_null,
3903 .fips_allowed = 1,
3904 }, {
3905 .alg = "xts512(paes)",
3906 .test = alg_test_null,
3907 .fips_allowed = 1,
3908 }, {
Giovanni Cabiddua368f432017-04-21 21:54:30 +01003909 .alg = "zlib-deflate",
3910 .test = alg_test_comp,
3911 .fips_allowed = 1,
3912 .suite = {
3913 .comp = {
3914 .comp = __VECS(zlib_deflate_comp_tv_template),
3915 .decomp = __VECS(zlib_deflate_decomp_tv_template)
3916 }
3917 }
Nick Terrelld28fc3d2018-03-30 12:14:53 -07003918 }, {
3919 .alg = "zstd",
3920 .test = alg_test_comp,
3921 .fips_allowed = 1,
3922 .suite = {
3923 .comp = {
3924 .comp = __VECS(zstd_comp_tv_template),
3925 .decomp = __VECS(zstd_decomp_tv_template)
3926 }
3927 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003928 }
3929};
3930
Eric Biggers3f47a032019-01-31 23:51:43 -08003931static void alg_check_test_descs_order(void)
Jussi Kivilinna57147582013-06-13 17:37:40 +03003932{
3933 int i;
3934
Jussi Kivilinna57147582013-06-13 17:37:40 +03003935 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3936 int diff = strcmp(alg_test_descs[i - 1].alg,
3937 alg_test_descs[i].alg);
3938
3939 if (WARN_ON(diff > 0)) {
3940 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3941 alg_test_descs[i - 1].alg,
3942 alg_test_descs[i].alg);
3943 }
3944
3945 if (WARN_ON(diff == 0)) {
3946 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3947 alg_test_descs[i].alg);
3948 }
3949 }
3950}
3951
Eric Biggers3f47a032019-01-31 23:51:43 -08003952static void alg_check_testvec_configs(void)
3953{
Eric Biggers4e7babba2019-01-31 23:51:46 -08003954 int i;
3955
3956 for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++)
3957 WARN_ON(!valid_testvec_config(
3958 &default_cipher_testvec_configs[i]));
Eric Biggers3f47a032019-01-31 23:51:43 -08003959}
3960
3961static void testmgr_onetime_init(void)
3962{
3963 alg_check_test_descs_order();
3964 alg_check_testvec_configs();
Eric Biggers5b2706a2019-01-31 23:51:44 -08003965
3966#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
3967 pr_warn("alg: extra crypto tests enabled. This is intended for developer use only.\n");
3968#endif
Eric Biggers3f47a032019-01-31 23:51:43 -08003969}
3970
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003971static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003972{
3973 int start = 0;
3974 int end = ARRAY_SIZE(alg_test_descs);
3975
3976 while (start < end) {
3977 int i = (start + end) / 2;
3978 int diff = strcmp(alg_test_descs[i].alg, alg);
3979
3980 if (diff > 0) {
3981 end = i;
3982 continue;
3983 }
3984
3985 if (diff < 0) {
3986 start = i + 1;
3987 continue;
3988 }
3989
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003990 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003991 }
3992
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003993 return -1;
3994}
3995
3996int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3997{
3998 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003999 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08004000 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004001
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +01004002 if (!fips_enabled && notests) {
4003 printk_once(KERN_INFO "alg: self-tests disabled\n");
4004 return 0;
4005 }
4006
Eric Biggers3f47a032019-01-31 23:51:43 -08004007 DO_ONCE(testmgr_onetime_init);
Jussi Kivilinna57147582013-06-13 17:37:40 +03004008
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004009 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
4010 char nalg[CRYPTO_MAX_ALG_NAME];
4011
4012 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
4013 sizeof(nalg))
4014 return -ENAMETOOLONG;
4015
4016 i = alg_find_test(nalg);
4017 if (i < 0)
4018 goto notest;
4019
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004020 if (fips_enabled && !alg_test_descs[i].fips_allowed)
4021 goto non_fips_alg;
4022
Jarod Wilson941fb322009-05-04 19:49:23 +08004023 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
4024 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004025 }
4026
4027 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08004028 j = alg_find_test(driver);
4029 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004030 goto notest;
4031
Herbert Xua68f6612009-07-02 16:32:12 +08004032 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
4033 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004034 goto non_fips_alg;
4035
Herbert Xua68f6612009-07-02 16:32:12 +08004036 rc = 0;
4037 if (i >= 0)
4038 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
4039 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03004040 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08004041 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
4042 type, mask);
4043
Jarod Wilson941fb322009-05-04 19:49:23 +08004044test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08004045 if (fips_enabled && rc)
4046 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
4047
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004048 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09004049 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004050
Neil Hormand12d6b62008-10-12 20:36:51 +08004051 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004052
4053notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08004054 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
4055 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004056non_fips_alg:
4057 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08004058}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004059
Herbert Xu326a6342010-08-06 09:40:28 +08004060#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004061
Herbert Xuda7f0332008-07-31 17:08:25 +08004062EXPORT_SYMBOL_GPL(alg_test);