blob: ca3fd5f0c09453811644d117bae05fb3525d02d0 [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
287static unsigned int count_test_sg_divisions(const struct test_sg_division *divs)
288{
289 unsigned int remaining = TEST_SG_TOTAL;
290 unsigned int ndivs = 0;
291
292 do {
293 remaining -= divs[ndivs++].proportion_of_total;
294 } while (remaining);
295
296 return ndivs;
297}
298
299static bool valid_sg_divisions(const struct test_sg_division *divs,
300 unsigned int count, bool *any_flushes_ret)
301{
302 unsigned int total = 0;
303 unsigned int i;
304
305 for (i = 0; i < count && total != TEST_SG_TOTAL; i++) {
306 if (divs[i].proportion_of_total <= 0 ||
307 divs[i].proportion_of_total > TEST_SG_TOTAL - total)
308 return false;
309 total += divs[i].proportion_of_total;
310 if (divs[i].flush_type != FLUSH_TYPE_NONE)
311 *any_flushes_ret = true;
312 }
313 return total == TEST_SG_TOTAL &&
314 memchr_inv(&divs[i], 0, (count - i) * sizeof(divs[0])) == NULL;
315}
316
317/*
318 * Check whether the given testvec_config is valid. This isn't strictly needed
319 * since every testvec_config should be valid, but check anyway so that people
320 * don't unknowingly add broken configs that don't do what they wanted.
321 */
322static bool valid_testvec_config(const struct testvec_config *cfg)
323{
324 bool any_flushes = false;
325
326 if (cfg->name == NULL)
327 return false;
328
329 if (!valid_sg_divisions(cfg->src_divs, ARRAY_SIZE(cfg->src_divs),
330 &any_flushes))
331 return false;
332
333 if (cfg->dst_divs[0].proportion_of_total) {
334 if (!valid_sg_divisions(cfg->dst_divs,
335 ARRAY_SIZE(cfg->dst_divs),
336 &any_flushes))
337 return false;
338 } else {
339 if (memchr_inv(cfg->dst_divs, 0, sizeof(cfg->dst_divs)))
340 return false;
341 /* defaults to dst_divs=src_divs */
342 }
343
344 if (cfg->iv_offset +
345 (cfg->iv_offset_relative_to_alignmask ? MAX_ALGAPI_ALIGNMASK : 0) >
346 MAX_ALGAPI_ALIGNMASK + 1)
347 return false;
348
349 if (any_flushes && cfg->finalization_type == FINALIZATION_TYPE_DIGEST)
350 return false;
351
352 return true;
353}
354
355struct test_sglist {
356 char *bufs[XBUFSIZE];
357 struct scatterlist sgl[XBUFSIZE];
358 struct scatterlist sgl_saved[XBUFSIZE];
359 struct scatterlist *sgl_ptr;
360 unsigned int nents;
361};
362
363static int init_test_sglist(struct test_sglist *tsgl)
364{
365 return __testmgr_alloc_buf(tsgl->bufs, 1 /* two pages per buffer */);
366}
367
368static void destroy_test_sglist(struct test_sglist *tsgl)
369{
370 return __testmgr_free_buf(tsgl->bufs, 1 /* two pages per buffer */);
371}
372
373/**
374 * build_test_sglist() - build a scatterlist for a crypto test
375 *
376 * @tsgl: the scatterlist to build. @tsgl->bufs[] contains an array of 2-page
377 * buffers which the scatterlist @tsgl->sgl[] will be made to point into.
378 * @divs: the layout specification on which the scatterlist will be based
379 * @alignmask: the algorithm's alignmask
380 * @total_len: the total length of the scatterlist to build in bytes
381 * @data: if non-NULL, the buffers will be filled with this data until it ends.
382 * Otherwise the buffers will be poisoned. In both cases, some bytes
383 * past the end of each buffer will be poisoned to help detect overruns.
384 * @out_divs: if non-NULL, the test_sg_division to which each scatterlist entry
385 * corresponds will be returned here. This will match @divs except
386 * that divisions resolving to a length of 0 are omitted as they are
387 * not included in the scatterlist.
388 *
389 * Return: 0 or a -errno value
390 */
391static int build_test_sglist(struct test_sglist *tsgl,
392 const struct test_sg_division *divs,
393 const unsigned int alignmask,
394 const unsigned int total_len,
395 struct iov_iter *data,
396 const struct test_sg_division *out_divs[XBUFSIZE])
397{
398 struct {
399 const struct test_sg_division *div;
400 size_t length;
401 } partitions[XBUFSIZE];
402 const unsigned int ndivs = count_test_sg_divisions(divs);
403 unsigned int len_remaining = total_len;
404 unsigned int i;
405
406 BUILD_BUG_ON(ARRAY_SIZE(partitions) != ARRAY_SIZE(tsgl->sgl));
407 if (WARN_ON(ndivs > ARRAY_SIZE(partitions)))
408 return -EINVAL;
409
410 /* Calculate the (div, length) pairs */
411 tsgl->nents = 0;
412 for (i = 0; i < ndivs; i++) {
413 unsigned int len_this_sg =
414 min(len_remaining,
415 (total_len * divs[i].proportion_of_total +
416 TEST_SG_TOTAL / 2) / TEST_SG_TOTAL);
417
418 if (len_this_sg != 0) {
419 partitions[tsgl->nents].div = &divs[i];
420 partitions[tsgl->nents].length = len_this_sg;
421 tsgl->nents++;
422 len_remaining -= len_this_sg;
423 }
424 }
425 if (tsgl->nents == 0) {
426 partitions[tsgl->nents].div = &divs[0];
427 partitions[tsgl->nents].length = 0;
428 tsgl->nents++;
429 }
430 partitions[tsgl->nents - 1].length += len_remaining;
431
432 /* Set up the sgl entries and fill the data or poison */
433 sg_init_table(tsgl->sgl, tsgl->nents);
434 for (i = 0; i < tsgl->nents; i++) {
435 unsigned int offset = partitions[i].div->offset;
436 void *addr;
437
438 if (partitions[i].div->offset_relative_to_alignmask)
439 offset += alignmask;
440
441 while (offset + partitions[i].length + TESTMGR_POISON_LEN >
442 2 * PAGE_SIZE) {
443 if (WARN_ON(offset <= 0))
444 return -EINVAL;
445 offset /= 2;
446 }
447
448 addr = &tsgl->bufs[i][offset];
449 sg_set_buf(&tsgl->sgl[i], addr, partitions[i].length);
450
451 if (out_divs)
452 out_divs[i] = partitions[i].div;
453
454 if (data) {
455 size_t copy_len, copied;
456
457 copy_len = min(partitions[i].length, data->count);
458 copied = copy_from_iter(addr, copy_len, data);
459 if (WARN_ON(copied != copy_len))
460 return -EINVAL;
461 testmgr_poison(addr + copy_len, partitions[i].length +
462 TESTMGR_POISON_LEN - copy_len);
463 } else {
464 testmgr_poison(addr, partitions[i].length +
465 TESTMGR_POISON_LEN);
466 }
467 }
468
469 sg_mark_end(&tsgl->sgl[tsgl->nents - 1]);
470 tsgl->sgl_ptr = tsgl->sgl;
471 memcpy(tsgl->sgl_saved, tsgl->sgl, tsgl->nents * sizeof(tsgl->sgl[0]));
472 return 0;
473}
474
475/*
476 * Verify that a scatterlist crypto operation produced the correct output.
477 *
478 * @tsgl: scatterlist containing the actual output
479 * @expected_output: buffer containing the expected output
480 * @len_to_check: length of @expected_output in bytes
481 * @unchecked_prefix_len: number of ignored bytes in @tsgl prior to real result
482 * @check_poison: verify that the poison bytes after each chunk are intact?
483 *
484 * Return: 0 if correct, -EINVAL if incorrect, -EOVERFLOW if buffer overrun.
485 */
486static int verify_correct_output(const struct test_sglist *tsgl,
487 const char *expected_output,
488 unsigned int len_to_check,
489 unsigned int unchecked_prefix_len,
490 bool check_poison)
491{
492 unsigned int i;
493
494 for (i = 0; i < tsgl->nents; i++) {
495 struct scatterlist *sg = &tsgl->sgl_ptr[i];
496 unsigned int len = sg->length;
497 unsigned int offset = sg->offset;
498 const char *actual_output;
499
500 if (unchecked_prefix_len) {
501 if (unchecked_prefix_len >= len) {
502 unchecked_prefix_len -= len;
503 continue;
504 }
505 offset += unchecked_prefix_len;
506 len -= unchecked_prefix_len;
507 unchecked_prefix_len = 0;
508 }
509 len = min(len, len_to_check);
510 actual_output = page_address(sg_page(sg)) + offset;
511 if (memcmp(expected_output, actual_output, len) != 0)
512 return -EINVAL;
513 if (check_poison &&
514 !testmgr_is_poison(actual_output + len, TESTMGR_POISON_LEN))
515 return -EOVERFLOW;
516 len_to_check -= len;
517 expected_output += len;
518 }
519 if (WARN_ON(len_to_check != 0))
520 return -EINVAL;
521 return 0;
522}
523
524static bool is_test_sglist_corrupted(const struct test_sglist *tsgl)
525{
526 unsigned int i;
527
528 for (i = 0; i < tsgl->nents; i++) {
529 if (tsgl->sgl[i].page_link != tsgl->sgl_saved[i].page_link)
530 return true;
531 if (tsgl->sgl[i].offset != tsgl->sgl_saved[i].offset)
532 return true;
533 if (tsgl->sgl[i].length != tsgl->sgl_saved[i].length)
534 return true;
535 }
536 return false;
537}
538
539struct cipher_test_sglists {
540 struct test_sglist src;
541 struct test_sglist dst;
542};
543
544static struct cipher_test_sglists *alloc_cipher_test_sglists(void)
545{
546 struct cipher_test_sglists *tsgls;
547
548 tsgls = kmalloc(sizeof(*tsgls), GFP_KERNEL);
549 if (!tsgls)
550 return NULL;
551
552 if (init_test_sglist(&tsgls->src) != 0)
553 goto fail_kfree;
554 if (init_test_sglist(&tsgls->dst) != 0)
555 goto fail_destroy_src;
556
557 return tsgls;
558
559fail_destroy_src:
560 destroy_test_sglist(&tsgls->src);
561fail_kfree:
562 kfree(tsgls);
563 return NULL;
564}
565
566static void free_cipher_test_sglists(struct cipher_test_sglists *tsgls)
567{
568 if (tsgls) {
569 destroy_test_sglist(&tsgls->src);
570 destroy_test_sglist(&tsgls->dst);
571 kfree(tsgls);
572 }
573}
574
575/* Build the src and dst scatterlists for an skcipher or AEAD test */
576static int build_cipher_test_sglists(struct cipher_test_sglists *tsgls,
577 const struct testvec_config *cfg,
578 unsigned int alignmask,
579 unsigned int src_total_len,
580 unsigned int dst_total_len,
581 const struct kvec *inputs,
582 unsigned int nr_inputs)
583{
584 struct iov_iter input;
585 int err;
586
587 iov_iter_kvec(&input, WRITE, inputs, nr_inputs, src_total_len);
588 err = build_test_sglist(&tsgls->src, cfg->src_divs, alignmask,
589 cfg->inplace ?
590 max(dst_total_len, src_total_len) :
591 src_total_len,
592 &input, NULL);
593 if (err)
594 return err;
595
596 if (cfg->inplace) {
597 tsgls->dst.sgl_ptr = tsgls->src.sgl;
598 tsgls->dst.nents = tsgls->src.nents;
599 return 0;
600 }
601 return build_test_sglist(&tsgls->dst,
602 cfg->dst_divs[0].proportion_of_total ?
603 cfg->dst_divs : cfg->src_divs,
604 alignmask, dst_total_len, NULL, NULL);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800605}
606
Eric Biggers25f9ddd2019-01-31 23:51:45 -0800607#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
608static char *generate_random_sgl_divisions(struct test_sg_division *divs,
609 size_t max_divs, char *p, char *end,
610 bool gen_flushes)
611{
612 struct test_sg_division *div = divs;
613 unsigned int remaining = TEST_SG_TOTAL;
614
615 do {
616 unsigned int this_len;
617
618 if (div == &divs[max_divs - 1] || prandom_u32() % 2 == 0)
619 this_len = remaining;
620 else
621 this_len = 1 + (prandom_u32() % remaining);
622 div->proportion_of_total = this_len;
623
624 if (prandom_u32() % 4 == 0)
625 div->offset = (PAGE_SIZE - 128) + (prandom_u32() % 128);
626 else if (prandom_u32() % 2 == 0)
627 div->offset = prandom_u32() % 32;
628 else
629 div->offset = prandom_u32() % PAGE_SIZE;
630 if (prandom_u32() % 8 == 0)
631 div->offset_relative_to_alignmask = true;
632
633 div->flush_type = FLUSH_TYPE_NONE;
634 if (gen_flushes) {
635 switch (prandom_u32() % 4) {
636 case 0:
637 div->flush_type = FLUSH_TYPE_REIMPORT;
638 break;
639 case 1:
640 div->flush_type = FLUSH_TYPE_FLUSH;
641 break;
642 }
643 }
644
645 BUILD_BUG_ON(TEST_SG_TOTAL != 10000); /* for "%u.%u%%" */
646 p += scnprintf(p, end - p, "%s%u.%u%%@%s+%u%s",
647 div->flush_type == FLUSH_TYPE_NONE ? "" :
648 div->flush_type == FLUSH_TYPE_FLUSH ?
649 "<flush> " : "<reimport> ",
650 this_len / 100, this_len % 100,
651 div->offset_relative_to_alignmask ?
652 "alignmask" : "",
653 div->offset, this_len == remaining ? "" : ", ");
654 remaining -= this_len;
655 div++;
656 } while (remaining);
657
658 return p;
659}
660
661/* Generate a random testvec_config for fuzz testing */
662static void generate_random_testvec_config(struct testvec_config *cfg,
663 char *name, size_t max_namelen)
664{
665 char *p = name;
666 char * const end = name + max_namelen;
667
668 memset(cfg, 0, sizeof(*cfg));
669
670 cfg->name = name;
671
672 p += scnprintf(p, end - p, "random:");
673
674 if (prandom_u32() % 2 == 0) {
675 cfg->inplace = true;
676 p += scnprintf(p, end - p, " inplace");
677 }
678
679 if (prandom_u32() % 2 == 0) {
680 cfg->req_flags |= CRYPTO_TFM_REQ_MAY_SLEEP;
681 p += scnprintf(p, end - p, " may_sleep");
682 }
683
684 switch (prandom_u32() % 4) {
685 case 0:
686 cfg->finalization_type = FINALIZATION_TYPE_FINAL;
687 p += scnprintf(p, end - p, " use_final");
688 break;
689 case 1:
690 cfg->finalization_type = FINALIZATION_TYPE_FINUP;
691 p += scnprintf(p, end - p, " use_finup");
692 break;
693 default:
694 cfg->finalization_type = FINALIZATION_TYPE_DIGEST;
695 p += scnprintf(p, end - p, " use_digest");
696 break;
697 }
698
699 p += scnprintf(p, end - p, " src_divs=[");
700 p = generate_random_sgl_divisions(cfg->src_divs,
701 ARRAY_SIZE(cfg->src_divs), p, end,
702 (cfg->finalization_type !=
703 FINALIZATION_TYPE_DIGEST));
704 p += scnprintf(p, end - p, "]");
705
706 if (!cfg->inplace && prandom_u32() % 2 == 0) {
707 p += scnprintf(p, end - p, " dst_divs=[");
708 p = generate_random_sgl_divisions(cfg->dst_divs,
709 ARRAY_SIZE(cfg->dst_divs),
710 p, end, false);
711 p += scnprintf(p, end - p, "]");
712 }
713
714 if (prandom_u32() % 2 == 0) {
715 cfg->iv_offset = 1 + (prandom_u32() % MAX_ALGAPI_ALIGNMASK);
716 p += scnprintf(p, end - p, " iv_offset=%u", cfg->iv_offset);
717 }
718
719 WARN_ON_ONCE(!valid_testvec_config(cfg));
720}
721#endif /* CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
722
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100723static int ahash_guard_result(char *result, char c, int size)
724{
725 int i;
726
727 for (i = 0; i < size; i++) {
728 if (result[i] != c)
729 return -EINVAL;
730 }
731
732 return 0;
733}
734
Wang, Rui Y018ba952016-02-03 18:26:57 +0800735static int ahash_partial_update(struct ahash_request **preq,
Eric Biggersb13b1e02017-02-24 15:46:59 -0800736 struct crypto_ahash *tfm, const struct hash_testvec *template,
Wang, Rui Y018ba952016-02-03 18:26:57 +0800737 void *hash_buff, int k, int temp, struct scatterlist *sg,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100738 const char *algo, char *result, struct crypto_wait *wait)
Wang, Rui Y018ba952016-02-03 18:26:57 +0800739{
740 char *state;
741 struct ahash_request *req;
742 int statesize, ret = -EINVAL;
Joey Pabalinasda1729c2018-01-01 10:40:14 -1000743 static const unsigned char guard[] = { 0x00, 0xba, 0xad, 0x00 };
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100744 int digestsize = crypto_ahash_digestsize(tfm);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800745
746 req = *preq;
747 statesize = crypto_ahash_statesize(
748 crypto_ahash_reqtfm(req));
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200749 state = kmalloc(statesize + sizeof(guard), GFP_KERNEL);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800750 if (!state) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300751 pr_err("alg: hash: Failed to alloc state for %s\n", algo);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800752 goto out_nostate;
753 }
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200754 memcpy(state + statesize, guard, sizeof(guard));
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100755 memset(result, 1, digestsize);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800756 ret = crypto_ahash_export(req, state);
Jan Stancek7bcb87b2016-09-28 16:38:37 +0200757 WARN_ON(memcmp(state + statesize, guard, sizeof(guard)));
Wang, Rui Y018ba952016-02-03 18:26:57 +0800758 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300759 pr_err("alg: hash: Failed to export() for %s\n", algo);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800760 goto out;
761 }
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100762 ret = ahash_guard_result(result, 1, digestsize);
763 if (ret) {
764 pr_err("alg: hash: Failed, export used req->result for %s\n",
765 algo);
766 goto out;
767 }
Wang, Rui Y018ba952016-02-03 18:26:57 +0800768 ahash_request_free(req);
769 req = ahash_request_alloc(tfm, GFP_KERNEL);
770 if (!req) {
771 pr_err("alg: hash: Failed to alloc request for %s\n", algo);
772 goto out_noreq;
773 }
774 ahash_request_set_callback(req,
775 CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100776 crypto_req_done, wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800777
778 memcpy(hash_buff, template->plaintext + temp,
779 template->tap[k]);
780 sg_init_one(&sg[0], hash_buff, template->tap[k]);
781 ahash_request_set_crypt(req, sg, result, template->tap[k]);
782 ret = crypto_ahash_import(req, state);
783 if (ret) {
784 pr_err("alg: hash: Failed to import() for %s\n", algo);
785 goto out;
786 }
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100787 ret = ahash_guard_result(result, 1, digestsize);
788 if (ret) {
789 pr_err("alg: hash: Failed, import used req->result for %s\n",
790 algo);
791 goto out;
792 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100793 ret = crypto_wait_req(crypto_ahash_update(req), wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +0800794 if (ret)
795 goto out;
796 *preq = req;
797 ret = 0;
798 goto out_noreq;
799out:
800 ahash_request_free(req);
801out_noreq:
802 kfree(state);
803out_nostate:
804 return ret;
805}
806
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100807enum hash_test {
808 HASH_TEST_DIGEST,
809 HASH_TEST_FINAL,
810 HASH_TEST_FINUP
811};
812
Eric Biggersb13b1e02017-02-24 15:46:59 -0800813static int __test_hash(struct crypto_ahash *tfm,
814 const struct hash_testvec *template, unsigned int tcount,
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100815 enum hash_test test_type, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800816{
817 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800818 size_t digest_size = crypto_ahash_digestsize(tfm);
Herbert Xuda7f0332008-07-31 17:08:25 +0800819 unsigned int i, j, k, temp;
820 struct scatterlist sg[8];
Horia Geanta29b77e52014-07-23 11:59:38 +0300821 char *result;
822 char *key;
Herbert Xuda7f0332008-07-31 17:08:25 +0800823 struct ahash_request *req;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100824 struct crypto_wait wait;
Herbert Xuda7f0332008-07-31 17:08:25 +0800825 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800826 char *xbuf[XBUFSIZE];
827 int ret = -ENOMEM;
828
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800829 result = kmalloc(digest_size, GFP_KERNEL);
Horia Geanta29b77e52014-07-23 11:59:38 +0300830 if (!result)
831 return ret;
832 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
833 if (!key)
834 goto out_nobuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800835 if (testmgr_alloc_buf(xbuf))
836 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800837
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100838 crypto_init_wait(&wait);
Herbert Xuda7f0332008-07-31 17:08:25 +0800839
840 req = ahash_request_alloc(tfm, GFP_KERNEL);
841 if (!req) {
842 printk(KERN_ERR "alg: hash: Failed to allocate request for "
843 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800844 goto out_noreq;
845 }
846 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100847 crypto_req_done, &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +0800848
Herbert Xua0cfae52009-05-29 16:23:12 +1000849 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800850 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000851 if (template[i].np)
852 continue;
853
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300854 ret = -EINVAL;
855 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
856 goto out;
857
Herbert Xua0cfae52009-05-29 16:23:12 +1000858 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800859 memset(result, 0, digest_size);
Herbert Xuda7f0332008-07-31 17:08:25 +0800860
861 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300862 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800863
864 memcpy(hash_buff, template[i].plaintext, template[i].psize);
865 sg_init_one(&sg[0], hash_buff, template[i].psize);
866
867 if (template[i].ksize) {
868 crypto_ahash_clear_flags(tfm, ~0);
Horia Geanta29b77e52014-07-23 11:59:38 +0300869 if (template[i].ksize > MAX_KEYLEN) {
870 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
871 j, algo, template[i].ksize, MAX_KEYLEN);
872 ret = -EINVAL;
873 goto out;
874 }
875 memcpy(key, template[i].key, template[i].ksize);
876 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
Herbert Xuda7f0332008-07-31 17:08:25 +0800877 if (ret) {
878 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000879 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800880 -ret);
881 goto out;
882 }
883 }
884
885 ahash_request_set_crypt(req, sg, result, template[i].psize);
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100886 switch (test_type) {
887 case HASH_TEST_DIGEST:
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100888 ret = crypto_wait_req(crypto_ahash_digest(req), &wait);
David S. Millera8f1a052010-05-19 14:12:03 +1000889 if (ret) {
890 pr_err("alg: hash: digest failed on test %d "
891 "for %s: ret=%d\n", j, algo, -ret);
892 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800893 }
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100894 break;
895
896 case HASH_TEST_FINAL:
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100897 memset(result, 1, digest_size);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100898 ret = crypto_wait_req(crypto_ahash_init(req), &wait);
David S. Millera8f1a052010-05-19 14:12:03 +1000899 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300900 pr_err("alg: hash: init failed on test %d "
David S. Millera8f1a052010-05-19 14:12:03 +1000901 "for %s: ret=%d\n", j, algo, -ret);
902 goto out;
903 }
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100904 ret = ahash_guard_result(result, 1, digest_size);
905 if (ret) {
906 pr_err("alg: hash: init failed on test %d "
907 "for %s: used req->result\n", j, algo);
908 goto out;
909 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100910 ret = crypto_wait_req(crypto_ahash_update(req), &wait);
David S. Millera8f1a052010-05-19 14:12:03 +1000911 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300912 pr_err("alg: hash: update failed on test %d "
David S. Millera8f1a052010-05-19 14:12:03 +1000913 "for %s: ret=%d\n", j, algo, -ret);
914 goto out;
915 }
Kamil Konieczny466d7b92018-01-16 15:26:13 +0100916 ret = ahash_guard_result(result, 1, digest_size);
917 if (ret) {
918 pr_err("alg: hash: update failed on test %d "
919 "for %s: used req->result\n", j, algo);
920 goto out;
921 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +0100922 ret = crypto_wait_req(crypto_ahash_final(req), &wait);
David S. Millera8f1a052010-05-19 14:12:03 +1000923 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +0300924 pr_err("alg: hash: final failed on test %d "
David S. Millera8f1a052010-05-19 14:12:03 +1000925 "for %s: ret=%d\n", j, algo, -ret);
926 goto out;
927 }
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100928 break;
929
930 case HASH_TEST_FINUP:
931 memset(result, 1, digest_size);
932 ret = crypto_wait_req(crypto_ahash_init(req), &wait);
933 if (ret) {
934 pr_err("alg: hash: init failed on test %d "
935 "for %s: ret=%d\n", j, algo, -ret);
936 goto out;
937 }
938 ret = ahash_guard_result(result, 1, digest_size);
939 if (ret) {
940 pr_err("alg: hash: init failed on test %d "
941 "for %s: used req->result\n", j, algo);
942 goto out;
943 }
944 ret = crypto_wait_req(crypto_ahash_finup(req), &wait);
945 if (ret) {
946 pr_err("alg: hash: final failed on test %d "
947 "for %s: ret=%d\n", j, algo, -ret);
948 goto out;
949 }
950 break;
Herbert Xuda7f0332008-07-31 17:08:25 +0800951 }
952
953 if (memcmp(result, template[i].digest,
954 crypto_ahash_digestsize(tfm))) {
955 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000956 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800957 hexdump(result, crypto_ahash_digestsize(tfm));
958 ret = -EINVAL;
959 goto out;
960 }
961 }
962
Gilad Ben-Yossef76715092018-07-01 08:02:35 +0100963 if (test_type)
964 goto out;
965
Herbert Xuda7f0332008-07-31 17:08:25 +0800966 j = 0;
967 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300968 /* alignment tests are only done with continuous buffers */
969 if (align_offset != 0)
970 break;
971
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300972 if (!template[i].np)
973 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800974
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300975 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -0800976 memset(result, 0, digest_size);
Herbert Xuda7f0332008-07-31 17:08:25 +0800977
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300978 temp = 0;
979 sg_init_table(sg, template[i].np);
980 ret = -EINVAL;
981 for (k = 0; k < template[i].np; k++) {
982 if (WARN_ON(offset_in_page(IDX[k]) +
983 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +0800984 goto out;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300985 sg_set_buf(&sg[k],
986 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
987 offset_in_page(IDX[k]),
988 template[i].plaintext + temp,
989 template[i].tap[k]),
990 template[i].tap[k]);
991 temp += template[i].tap[k];
992 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800993
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300994 if (template[i].ksize) {
995 if (template[i].ksize > MAX_KEYLEN) {
996 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
997 j, algo, template[i].ksize, MAX_KEYLEN);
Herbert Xuda7f0332008-07-31 17:08:25 +0800998 ret = -EINVAL;
999 goto out;
1000 }
Cristian Stoica5f2b4242014-08-08 14:27:50 +03001001 crypto_ahash_clear_flags(tfm, ~0);
1002 memcpy(key, template[i].key, template[i].ksize);
1003 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
1004
1005 if (ret) {
1006 printk(KERN_ERR "alg: hash: setkey "
1007 "failed on chunking test %d "
1008 "for %s: ret=%d\n", j, algo, -ret);
1009 goto out;
1010 }
1011 }
1012
1013 ahash_request_set_crypt(req, sg, result, template[i].psize);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001014 ret = crypto_wait_req(crypto_ahash_digest(req), &wait);
1015 if (ret) {
1016 pr_err("alg: hash: digest failed on chunking test %d for %s: ret=%d\n",
1017 j, algo, -ret);
Cristian Stoica5f2b4242014-08-08 14:27:50 +03001018 goto out;
1019 }
1020
1021 if (memcmp(result, template[i].digest,
1022 crypto_ahash_digestsize(tfm))) {
1023 printk(KERN_ERR "alg: hash: Chunking test %d "
1024 "failed for %s\n", j, algo);
1025 hexdump(result, crypto_ahash_digestsize(tfm));
1026 ret = -EINVAL;
1027 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001028 }
1029 }
1030
Wang, Rui Y018ba952016-02-03 18:26:57 +08001031 /* partial update exercise */
1032 j = 0;
1033 for (i = 0; i < tcount; i++) {
1034 /* alignment tests are only done with continuous buffers */
1035 if (align_offset != 0)
1036 break;
1037
1038 if (template[i].np < 2)
1039 continue;
1040
1041 j++;
Andrew Lutomirskie93acd62017-01-10 15:24:46 -08001042 memset(result, 0, digest_size);
Wang, Rui Y018ba952016-02-03 18:26:57 +08001043
1044 ret = -EINVAL;
1045 hash_buff = xbuf[0];
1046 memcpy(hash_buff, template[i].plaintext,
1047 template[i].tap[0]);
1048 sg_init_one(&sg[0], hash_buff, template[i].tap[0]);
1049
1050 if (template[i].ksize) {
1051 crypto_ahash_clear_flags(tfm, ~0);
1052 if (template[i].ksize > MAX_KEYLEN) {
1053 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
1054 j, algo, template[i].ksize, MAX_KEYLEN);
1055 ret = -EINVAL;
1056 goto out;
1057 }
1058 memcpy(key, template[i].key, template[i].ksize);
1059 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
1060 if (ret) {
1061 pr_err("alg: hash: setkey failed on test %d for %s: ret=%d\n",
1062 j, algo, -ret);
1063 goto out;
1064 }
1065 }
1066
1067 ahash_request_set_crypt(req, sg, result, template[i].tap[0]);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001068 ret = crypto_wait_req(crypto_ahash_init(req), &wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +08001069 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +03001070 pr_err("alg: hash: init failed on test %d for %s: ret=%d\n",
Wang, Rui Y018ba952016-02-03 18:26:57 +08001071 j, algo, -ret);
1072 goto out;
1073 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001074 ret = crypto_wait_req(crypto_ahash_update(req), &wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +08001075 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +03001076 pr_err("alg: hash: update failed on test %d for %s: ret=%d\n",
Wang, Rui Y018ba952016-02-03 18:26:57 +08001077 j, algo, -ret);
1078 goto out;
1079 }
1080
1081 temp = template[i].tap[0];
1082 for (k = 1; k < template[i].np; k++) {
1083 ret = ahash_partial_update(&req, tfm, &template[i],
1084 hash_buff, k, temp, &sg[0], algo, result,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001085 &wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +08001086 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +03001087 pr_err("alg: hash: partial update failed on test %d for %s: ret=%d\n",
Wang, Rui Y018ba952016-02-03 18:26:57 +08001088 j, algo, -ret);
1089 goto out_noreq;
1090 }
1091 temp += template[i].tap[k];
1092 }
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001093 ret = crypto_wait_req(crypto_ahash_final(req), &wait);
Wang, Rui Y018ba952016-02-03 18:26:57 +08001094 if (ret) {
Gilad Ben-Yossefcf3f9602017-06-05 08:33:43 +03001095 pr_err("alg: hash: final failed on test %d for %s: ret=%d\n",
Wang, Rui Y018ba952016-02-03 18:26:57 +08001096 j, algo, -ret);
1097 goto out;
1098 }
1099 if (memcmp(result, template[i].digest,
1100 crypto_ahash_digestsize(tfm))) {
1101 pr_err("alg: hash: Partial Test %d failed for %s\n",
1102 j, algo);
1103 hexdump(result, crypto_ahash_digestsize(tfm));
1104 ret = -EINVAL;
1105 goto out;
1106 }
1107 }
1108
Herbert Xuda7f0332008-07-31 17:08:25 +08001109 ret = 0;
1110
1111out:
1112 ahash_request_free(req);
1113out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001114 testmgr_free_buf(xbuf);
1115out_nobuf:
Horia Geanta29b77e52014-07-23 11:59:38 +03001116 kfree(key);
1117 kfree(result);
Herbert Xuda7f0332008-07-31 17:08:25 +08001118 return ret;
1119}
1120
Eric Biggersb13b1e02017-02-24 15:46:59 -08001121static int test_hash(struct crypto_ahash *tfm,
1122 const struct hash_testvec *template,
Gilad Ben-Yossef76715092018-07-01 08:02:35 +01001123 unsigned int tcount, enum hash_test test_type)
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +03001124{
1125 unsigned int alignmask;
1126 int ret;
1127
Gilad Ben-Yossef76715092018-07-01 08:02:35 +01001128 ret = __test_hash(tfm, template, tcount, test_type, 0);
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +03001129 if (ret)
1130 return ret;
1131
1132 /* test unaligned buffers, check with one byte offset */
Gilad Ben-Yossef76715092018-07-01 08:02:35 +01001133 ret = __test_hash(tfm, template, tcount, test_type, 1);
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +03001134 if (ret)
1135 return ret;
1136
1137 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1138 if (alignmask) {
1139 /* Check if alignment mask for tfm is correctly set. */
Gilad Ben-Yossef76715092018-07-01 08:02:35 +01001140 ret = __test_hash(tfm, template, tcount, test_type,
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +03001141 alignmask + 1);
1142 if (ret)
1143 return ret;
1144 }
1145
1146 return 0;
1147}
1148
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001149static int __test_aead(struct crypto_aead *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001150 const struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +03001151 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +08001152{
1153 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
1154 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001155 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +08001156 char *q;
1157 char *key;
1158 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001159 struct scatterlist *sg;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001160 struct scatterlist *sgout;
1161 const char *e, *d;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001162 struct crypto_wait wait;
Cristian Stoica424a5da2015-01-28 11:03:05 +02001163 unsigned int authsize, iv_len;
Tadeusz Struk9bac0192014-05-19 09:51:33 -07001164 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001165 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001166 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001167 char *axbuf[XBUFSIZE];
1168
Tadeusz Struk9bac0192014-05-19 09:51:33 -07001169 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
1170 if (!iv)
1171 return ret;
Horia Geanta29b77e52014-07-23 11:59:38 +03001172 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
1173 if (!key)
1174 goto out_noxbuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001175 if (testmgr_alloc_buf(xbuf))
1176 goto out_noxbuf;
1177 if (testmgr_alloc_buf(axbuf))
1178 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001179 if (diff_dst && testmgr_alloc_buf(xoutbuf))
1180 goto out_nooutbuf;
1181
1182 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
Kees Cook6da2ec52018-06-12 13:55:00 -07001183 sg = kmalloc(array3_size(sizeof(*sg), 8, (diff_dst ? 4 : 2)),
1184 GFP_KERNEL);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001185 if (!sg)
1186 goto out_nosg;
Herbert Xu8a525fcd2015-05-27 16:03:43 +08001187 sgout = &sg[16];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001188
1189 if (diff_dst)
1190 d = "-ddst";
1191 else
1192 d = "";
1193
Herbert Xuda7f0332008-07-31 17:08:25 +08001194 if (enc == ENCRYPT)
1195 e = "encryption";
1196 else
1197 e = "decryption";
1198
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001199 crypto_init_wait(&wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001200
1201 req = aead_request_alloc(tfm, GFP_KERNEL);
1202 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001203 pr_err("alg: aead%s: Failed to allocate request for %s\n",
1204 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +08001205 goto out;
1206 }
1207
1208 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001209 crypto_req_done, &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001210
Jerome Marchandabfa7f42016-02-03 13:58:12 +01001211 iv_len = crypto_aead_ivsize(tfm);
1212
Herbert Xuda7f0332008-07-31 17:08:25 +08001213 for (i = 0, j = 0; i < tcount; i++) {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001214 const char *input, *expected_output;
1215 unsigned int inlen, outlen;
1216 char *inbuf, *outbuf, *assocbuf;
1217
Cristian Stoica05b1d332014-07-28 13:11:23 +03001218 if (template[i].np)
1219 continue;
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001220 if (enc) {
1221 if (template[i].novrfy)
1222 continue;
1223 input = template[i].ptext;
1224 inlen = template[i].plen;
1225 expected_output = template[i].ctext;
1226 outlen = template[i].clen;
1227 } else {
1228 input = template[i].ctext;
1229 inlen = template[i].clen;
1230 expected_output = template[i].ptext;
1231 outlen = template[i].plen;
1232 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001233
Cristian Stoica05b1d332014-07-28 13:11:23 +03001234 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +08001235
Cristian Stoica05b1d332014-07-28 13:11:23 +03001236 /* some templates have no input data but they will
1237 * touch input
1238 */
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001239 inbuf = xbuf[0] + align_offset;
1240 assocbuf = axbuf[0];
Cristian Stoica05b1d332014-07-28 13:11:23 +03001241
1242 ret = -EINVAL;
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001243 if (WARN_ON(align_offset + template[i].clen > PAGE_SIZE ||
1244 template[i].alen > PAGE_SIZE))
Cristian Stoica05b1d332014-07-28 13:11:23 +03001245 goto out;
1246
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001247 memcpy(inbuf, input, inlen);
1248 memcpy(assocbuf, template[i].assoc, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001249 if (template[i].iv)
Cristian Stoica424a5da2015-01-28 11:03:05 +02001250 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001251 else
Cristian Stoica424a5da2015-01-28 11:03:05 +02001252 memset(iv, 0, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001253
1254 crypto_aead_clear_flags(tfm, ~0);
1255 if (template[i].wk)
Eric Biggers231baec2019-01-18 22:48:00 -08001256 crypto_aead_set_flags(tfm,
1257 CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001258
1259 if (template[i].klen > MAX_KEYLEN) {
1260 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
1261 d, j, algo, template[i].klen,
1262 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +10001263 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +03001264 goto out;
1265 }
1266 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +10001267
Cristian Stoica05b1d332014-07-28 13:11:23 +03001268 ret = crypto_aead_setkey(tfm, key, template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001269 if (template[i].fail == !ret) {
Cristian Stoica05b1d332014-07-28 13:11:23 +03001270 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
1271 d, j, algo, crypto_aead_get_flags(tfm));
1272 goto out;
1273 } else if (ret)
1274 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +08001275
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001276 authsize = template[i].clen - template[i].plen;
Cristian Stoica05b1d332014-07-28 13:11:23 +03001277 ret = crypto_aead_setauthsize(tfm, authsize);
1278 if (ret) {
1279 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
1280 d, authsize, j, algo);
1281 goto out;
1282 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001283
Herbert Xu8a525fcd2015-05-27 16:03:43 +08001284 k = !!template[i].alen;
1285 sg_init_table(sg, k + 1);
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001286 sg_set_buf(&sg[0], assocbuf, template[i].alen);
1287 sg_set_buf(&sg[k], inbuf, template[i].clen);
1288 outbuf = inbuf;
Herbert Xu8a525fcd2015-05-27 16:03:43 +08001289
Cristian Stoica05b1d332014-07-28 13:11:23 +03001290 if (diff_dst) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +08001291 sg_init_table(sgout, k + 1);
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001292 sg_set_buf(&sgout[0], assocbuf, template[i].alen);
Herbert Xu8a525fcd2015-05-27 16:03:43 +08001293
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001294 outbuf = xoutbuf[0] + align_offset;
1295 sg_set_buf(&sgout[k], outbuf, template[i].clen);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001296 }
1297
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001298 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, inlen,
1299 iv);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001300
Herbert Xu8a525fcd2015-05-27 16:03:43 +08001301 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001302
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001303 ret = crypto_wait_req(enc ? crypto_aead_encrypt(req)
1304 : crypto_aead_decrypt(req), &wait);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001305
1306 switch (ret) {
1307 case 0:
1308 if (template[i].novrfy) {
1309 /* verification was supposed to fail */
1310 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
1311 d, e, j, algo);
1312 /* so really, we got a bad message */
1313 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +03001314 goto out;
1315 }
Cristian Stoica05b1d332014-07-28 13:11:23 +03001316 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +03001317 case -EBADMSG:
1318 if (template[i].novrfy)
1319 /* verification failure was expected */
1320 continue;
1321 /* fall through */
1322 default:
1323 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
1324 d, e, j, algo, -ret);
1325 goto out;
1326 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001327
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001328 if (memcmp(outbuf, expected_output, outlen)) {
Cristian Stoica05b1d332014-07-28 13:11:23 +03001329 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
1330 d, j, e, algo);
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001331 hexdump(outbuf, outlen);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001332 ret = -EINVAL;
1333 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001334 }
1335 }
1336
1337 for (i = 0, j = 0; i < tcount; i++) {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001338 const char *input, *expected_output;
1339 unsigned int inlen, outlen;
1340
Jussi Kivilinna58dcf542013-06-13 17:37:50 +03001341 /* alignment tests are only done with continuous buffers */
1342 if (align_offset != 0)
1343 break;
1344
Cristian Stoica05b1d332014-07-28 13:11:23 +03001345 if (!template[i].np)
1346 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +08001347
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001348 if (enc) {
1349 if (template[i].novrfy)
1350 continue;
1351 input = template[i].ptext;
1352 inlen = template[i].plen;
1353 expected_output = template[i].ctext;
1354 outlen = template[i].clen;
1355 } else {
1356 input = template[i].ctext;
1357 inlen = template[i].clen;
1358 expected_output = template[i].ptext;
1359 outlen = template[i].plen;
1360 }
Eric Biggers5bc3de52019-01-13 15:32:24 -08001361
Cristian Stoica05b1d332014-07-28 13:11:23 +03001362 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +08001363
Cristian Stoica05b1d332014-07-28 13:11:23 +03001364 if (template[i].iv)
Jerome Marchandabfa7f42016-02-03 13:58:12 +01001365 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001366 else
1367 memset(iv, 0, MAX_IVLEN);
1368
1369 crypto_aead_clear_flags(tfm, ~0);
1370 if (template[i].wk)
Eric Biggers231baec2019-01-18 22:48:00 -08001371 crypto_aead_set_flags(tfm,
1372 CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001373 if (template[i].klen > MAX_KEYLEN) {
1374 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
1375 d, j, algo, template[i].klen, MAX_KEYLEN);
1376 ret = -EINVAL;
1377 goto out;
1378 }
1379 memcpy(key, template[i].key, template[i].klen);
1380
1381 ret = crypto_aead_setkey(tfm, key, template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001382 if (template[i].fail == !ret) {
Cristian Stoica05b1d332014-07-28 13:11:23 +03001383 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
1384 d, j, algo, crypto_aead_get_flags(tfm));
1385 goto out;
1386 } else if (ret)
1387 continue;
1388
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001389 authsize = template[i].clen - template[i].plen;
Cristian Stoica05b1d332014-07-28 13:11:23 +03001390
1391 ret = -EINVAL;
Herbert Xu8a525fcd2015-05-27 16:03:43 +08001392 sg_init_table(sg, template[i].anp + template[i].np);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001393 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +08001394 sg_init_table(sgout, template[i].anp + template[i].np);
1395
1396 ret = -EINVAL;
1397 for (k = 0, temp = 0; k < template[i].anp; k++) {
1398 if (WARN_ON(offset_in_page(IDX[k]) +
1399 template[i].atap[k] > PAGE_SIZE))
1400 goto out;
1401 sg_set_buf(&sg[k],
1402 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
1403 offset_in_page(IDX[k]),
1404 template[i].assoc + temp,
1405 template[i].atap[k]),
1406 template[i].atap[k]);
1407 if (diff_dst)
1408 sg_set_buf(&sgout[k],
1409 axbuf[IDX[k] >> PAGE_SHIFT] +
1410 offset_in_page(IDX[k]),
1411 template[i].atap[k]);
1412 temp += template[i].atap[k];
1413 }
1414
Cristian Stoica05b1d332014-07-28 13:11:23 +03001415 for (k = 0, temp = 0; k < template[i].np; k++) {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001416 n = template[i].tap[k];
1417 if (k == template[i].np - 1 && !enc)
1418 n += authsize;
1419
1420 if (WARN_ON(offset_in_page(IDX[k]) + n > PAGE_SIZE))
Cristian Stoica05b1d332014-07-28 13:11:23 +03001421 goto out;
1422
1423 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001424 memcpy(q, input + temp, n);
1425 sg_set_buf(&sg[template[i].anp + k], q, n);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001426
1427 if (diff_dst) {
1428 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1429 offset_in_page(IDX[k]);
1430
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001431 memset(q, 0, n);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001432
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001433 sg_set_buf(&sgout[template[i].anp + k], q, n);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001434 }
1435
Cristian Stoica05b1d332014-07-28 13:11:23 +03001436 if (k == template[i].np - 1 && enc)
1437 n += authsize;
1438 if (offset_in_page(q) + n < PAGE_SIZE)
1439 q[n] = 0;
1440
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001441 temp += n;
Cristian Stoica05b1d332014-07-28 13:11:23 +03001442 }
1443
1444 ret = crypto_aead_setauthsize(tfm, authsize);
1445 if (ret) {
1446 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
1447 d, authsize, j, algo);
1448 goto out;
1449 }
1450
1451 if (enc) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +08001452 if (WARN_ON(sg[template[i].anp + k - 1].offset +
1453 sg[template[i].anp + k - 1].length +
1454 authsize > PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +03001455 ret = -EINVAL;
1456 goto out;
1457 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001458
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001459 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +08001460 sgout[template[i].anp + k - 1].length +=
1461 authsize;
1462 sg[template[i].anp + k - 1].length += authsize;
Cristian Stoica05b1d332014-07-28 13:11:23 +03001463 }
1464
1465 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001466 inlen, iv);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001467
Herbert Xu8a525fcd2015-05-27 16:03:43 +08001468 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001469
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001470 ret = crypto_wait_req(enc ? crypto_aead_encrypt(req)
1471 : crypto_aead_decrypt(req), &wait);
Cristian Stoica05b1d332014-07-28 13:11:23 +03001472
1473 switch (ret) {
1474 case 0:
1475 if (template[i].novrfy) {
1476 /* verification was supposed to fail */
1477 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
1478 d, e, j, algo);
1479 /* so really, we got a bad message */
1480 ret = -EBADMSG;
1481 goto out;
1482 }
1483 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +03001484 case -EBADMSG:
1485 if (template[i].novrfy)
1486 /* verification failure was expected */
1487 continue;
1488 /* fall through */
1489 default:
1490 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
1491 d, e, j, algo, -ret);
1492 goto out;
1493 }
1494
1495 ret = -EINVAL;
1496 for (k = 0, temp = 0; k < template[i].np; k++) {
1497 if (diff_dst)
1498 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1499 offset_in_page(IDX[k]);
1500 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001501 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1502 offset_in_page(IDX[k]);
1503
Cristian Stoica05b1d332014-07-28 13:11:23 +03001504 n = template[i].tap[k];
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001505 if (k == template[i].np - 1 && enc)
1506 n += authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +08001507
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001508 if (memcmp(q, expected_output + temp, n)) {
Cristian Stoica05b1d332014-07-28 13:11:23 +03001509 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
1510 d, j, e, k, algo);
1511 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +08001512 goto out;
1513 }
1514
Cristian Stoica05b1d332014-07-28 13:11:23 +03001515 q += n;
1516 if (k == template[i].np - 1 && !enc) {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08001517 if (!diff_dst && memcmp(q, input + temp + n,
1518 authsize))
Cristian Stoica05b1d332014-07-28 13:11:23 +03001519 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +02001520 else
Cristian Stoica05b1d332014-07-28 13:11:23 +03001521 n = 0;
1522 } else {
1523 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1524 ;
Herbert Xuda7f0332008-07-31 17:08:25 +08001525 }
Cristian Stoica05b1d332014-07-28 13:11:23 +03001526 if (n) {
1527 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1528 d, j, e, k, algo, n);
1529 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +08001530 goto out;
1531 }
1532
Cristian Stoica05b1d332014-07-28 13:11:23 +03001533 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001534 }
1535 }
1536
1537 ret = 0;
1538
1539out:
1540 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001541 kfree(sg);
1542out_nosg:
1543 if (diff_dst)
1544 testmgr_free_buf(xoutbuf);
1545out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001546 testmgr_free_buf(axbuf);
1547out_noaxbuf:
1548 testmgr_free_buf(xbuf);
1549out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +03001550 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -07001551 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +08001552 return ret;
1553}
1554
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001555static int test_aead(struct crypto_aead *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001556 const struct aead_testvec *template, unsigned int tcount)
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001557{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +03001558 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001559 int ret;
1560
1561 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +03001562 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001563 if (ret)
1564 return ret;
1565
1566 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +03001567 ret = __test_aead(tfm, enc, template, tcount, true, 0);
1568 if (ret)
1569 return ret;
1570
1571 /* test unaligned buffers, check with one byte offset */
1572 ret = __test_aead(tfm, enc, template, tcount, true, 1);
1573 if (ret)
1574 return ret;
1575
1576 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1577 if (alignmask) {
1578 /* Check if alignment mask for tfm is correctly set. */
1579 ret = __test_aead(tfm, enc, template, tcount, true,
1580 alignmask + 1);
1581 if (ret)
1582 return ret;
1583 }
1584
1585 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +03001586}
1587
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001588static int test_cipher(struct crypto_cipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001589 const struct cipher_testvec *template,
1590 unsigned int tcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08001591{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001592 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
1593 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001594 char *q;
1595 const char *e;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001596 const char *input, *result;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001597 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001598 char *xbuf[XBUFSIZE];
1599 int ret = -ENOMEM;
1600
1601 if (testmgr_alloc_buf(xbuf))
1602 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001603
1604 if (enc == ENCRYPT)
1605 e = "encryption";
1606 else
1607 e = "decryption";
1608
1609 j = 0;
1610 for (i = 0; i < tcount; i++) {
1611 if (template[i].np)
1612 continue;
1613
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001614 if (fips_enabled && template[i].fips_skip)
1615 continue;
1616
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001617 input = enc ? template[i].ptext : template[i].ctext;
1618 result = enc ? template[i].ctext : template[i].ptext;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001619 j++;
1620
Herbert Xufd57f222009-05-29 16:05:42 +10001621 ret = -EINVAL;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001622 if (WARN_ON(template[i].len > PAGE_SIZE))
Herbert Xufd57f222009-05-29 16:05:42 +10001623 goto out;
1624
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001625 data = xbuf[0];
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001626 memcpy(data, input, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001627
1628 crypto_cipher_clear_flags(tfm, ~0);
1629 if (template[i].wk)
Eric Biggers231baec2019-01-18 22:48:00 -08001630 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001631
1632 ret = crypto_cipher_setkey(tfm, template[i].key,
1633 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001634 if (template[i].fail == !ret) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001635 printk(KERN_ERR "alg: cipher: setkey failed "
1636 "on test %d for %s: flags=%x\n", j,
1637 algo, crypto_cipher_get_flags(tfm));
1638 goto out;
1639 } else if (ret)
1640 continue;
1641
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001642 for (k = 0; k < template[i].len;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001643 k += crypto_cipher_blocksize(tfm)) {
1644 if (enc)
1645 crypto_cipher_encrypt_one(tfm, data + k,
1646 data + k);
1647 else
1648 crypto_cipher_decrypt_one(tfm, data + k,
1649 data + k);
1650 }
1651
1652 q = data;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001653 if (memcmp(q, result, template[i].len)) {
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001654 printk(KERN_ERR "alg: cipher: Test %d failed "
1655 "on %s for %s\n", j, e, algo);
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001656 hexdump(q, template[i].len);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001657 ret = -EINVAL;
1658 goto out;
1659 }
1660 }
1661
1662 ret = 0;
1663
1664out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001665 testmgr_free_buf(xbuf);
1666out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001667 return ret;
1668}
1669
Herbert Xu12773d92015-08-20 15:21:46 +08001670static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001671 const struct cipher_testvec *template,
1672 unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001673 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001674{
Herbert Xuda7f0332008-07-31 17:08:25 +08001675 const char *algo =
Herbert Xu12773d92015-08-20 15:21:46 +08001676 crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +08001677 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +08001678 char *q;
Herbert Xu12773d92015-08-20 15:21:46 +08001679 struct skcipher_request *req;
Herbert Xuda7f0332008-07-31 17:08:25 +08001680 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001681 struct scatterlist sgout[8];
1682 const char *e, *d;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001683 struct crypto_wait wait;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001684 const char *input, *result;
Herbert Xuda7f0332008-07-31 17:08:25 +08001685 void *data;
1686 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001687 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001688 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001689 int ret = -ENOMEM;
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001690 unsigned int ivsize = crypto_skcipher_ivsize(tfm);
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001691
1692 if (testmgr_alloc_buf(xbuf))
1693 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +08001694
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001695 if (diff_dst && testmgr_alloc_buf(xoutbuf))
1696 goto out_nooutbuf;
1697
1698 if (diff_dst)
1699 d = "-ddst";
1700 else
1701 d = "";
1702
Herbert Xuda7f0332008-07-31 17:08:25 +08001703 if (enc == ENCRYPT)
1704 e = "encryption";
1705 else
1706 e = "decryption";
1707
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001708 crypto_init_wait(&wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001709
Herbert Xu12773d92015-08-20 15:21:46 +08001710 req = skcipher_request_alloc(tfm, GFP_KERNEL);
Herbert Xuda7f0332008-07-31 17:08:25 +08001711 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001712 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
1713 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +08001714 goto out;
1715 }
1716
Herbert Xu12773d92015-08-20 15:21:46 +08001717 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001718 crypto_req_done, &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001719
1720 j = 0;
1721 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001722 if (template[i].np && !template[i].also_non_np)
1723 continue;
1724
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001725 if (fips_enabled && template[i].fips_skip)
1726 continue;
1727
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001728 if (template[i].iv && !(template[i].generates_iv && enc))
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001729 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001730 else
1731 memset(iv, 0, MAX_IVLEN);
1732
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001733 input = enc ? template[i].ptext : template[i].ctext;
1734 result = enc ? template[i].ctext : template[i].ptext;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001735 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001736 ret = -EINVAL;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001737 if (WARN_ON(align_offset + template[i].len > PAGE_SIZE))
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001738 goto out;
1739
1740 data = xbuf[0];
1741 data += align_offset;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001742 memcpy(data, input, template[i].len);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001743
Herbert Xu12773d92015-08-20 15:21:46 +08001744 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001745 if (template[i].wk)
Eric Biggers231baec2019-01-18 22:48:00 -08001746 crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001747
Herbert Xu12773d92015-08-20 15:21:46 +08001748 ret = crypto_skcipher_setkey(tfm, template[i].key,
1749 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001750 if (template[i].fail == !ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001751 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001752 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001753 goto out;
1754 } else if (ret)
1755 continue;
1756
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001757 sg_init_one(&sg[0], data, template[i].len);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001758 if (diff_dst) {
1759 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001760 data += align_offset;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001761 sg_init_one(&sgout[0], data, template[i].len);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001762 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001763
Herbert Xu12773d92015-08-20 15:21:46 +08001764 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001765 template[i].len, iv);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001766 ret = crypto_wait_req(enc ? crypto_skcipher_encrypt(req) :
1767 crypto_skcipher_decrypt(req), &wait);
Herbert Xuda7f0332008-07-31 17:08:25 +08001768
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001769 if (ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001770 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1771 d, e, j, algo, -ret);
1772 goto out;
1773 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001774
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001775 q = data;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001776 if (memcmp(q, result, template[i].len)) {
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001777 pr_err("alg: skcipher%s: Test %d failed (invalid result) on %s for %s\n",
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001778 d, j, e, algo);
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001779 hexdump(q, template[i].len);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001780 ret = -EINVAL;
1781 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001782 }
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001783
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001784 if (template[i].generates_iv && enc &&
1785 memcmp(iv, template[i].iv, crypto_skcipher_ivsize(tfm))) {
Boris BREZILLON8a826a32015-06-16 11:46:46 +02001786 pr_err("alg: skcipher%s: Test %d failed (invalid output IV) on %s for %s\n",
1787 d, j, e, algo);
1788 hexdump(iv, crypto_skcipher_ivsize(tfm));
1789 ret = -EINVAL;
1790 goto out;
1791 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001792 }
1793
1794 j = 0;
1795 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001796 /* alignment tests are only done with continuous buffers */
1797 if (align_offset != 0)
1798 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001799
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001800 if (!template[i].np)
1801 continue;
1802
Stephan Mueller10faa8c2016-08-25 15:15:01 +02001803 if (fips_enabled && template[i].fips_skip)
1804 continue;
1805
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001806 if (template[i].iv && !(template[i].generates_iv && enc))
Andrey Ryabinin84cba172015-09-10 13:11:55 +03001807 memcpy(iv, template[i].iv, ivsize);
Herbert Xuda7f0332008-07-31 17:08:25 +08001808 else
1809 memset(iv, 0, MAX_IVLEN);
1810
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001811 input = enc ? template[i].ptext : template[i].ctext;
1812 result = enc ? template[i].ctext : template[i].ptext;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001813 j++;
Herbert Xu12773d92015-08-20 15:21:46 +08001814 crypto_skcipher_clear_flags(tfm, ~0);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001815 if (template[i].wk)
Eric Biggers231baec2019-01-18 22:48:00 -08001816 crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001817
Herbert Xu12773d92015-08-20 15:21:46 +08001818 ret = crypto_skcipher_setkey(tfm, template[i].key,
1819 template[i].klen);
Yanjiang Jin0fae0c12016-07-29 16:32:09 +08001820 if (template[i].fail == !ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001821 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
Herbert Xu12773d92015-08-20 15:21:46 +08001822 d, j, algo, crypto_skcipher_get_flags(tfm));
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001823 goto out;
1824 } else if (ret)
1825 continue;
1826
1827 temp = 0;
1828 ret = -EINVAL;
1829 sg_init_table(sg, template[i].np);
1830 if (diff_dst)
1831 sg_init_table(sgout, template[i].np);
1832 for (k = 0; k < template[i].np; k++) {
1833 if (WARN_ON(offset_in_page(IDX[k]) +
1834 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001835 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001836
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001837 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1838
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001839 memcpy(q, input + temp, template[i].tap[k]);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001840
1841 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1842 q[template[i].tap[k]] = 0;
1843
1844 sg_set_buf(&sg[k], q, template[i].tap[k]);
1845 if (diff_dst) {
1846 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1847 offset_in_page(IDX[k]);
1848
1849 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1850
1851 memset(q, 0, template[i].tap[k]);
1852 if (offset_in_page(q) +
1853 template[i].tap[k] < PAGE_SIZE)
1854 q[template[i].tap[k]] = 0;
1855 }
1856
1857 temp += template[i].tap[k];
1858 }
1859
Herbert Xu12773d92015-08-20 15:21:46 +08001860 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001861 template[i].len, iv);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001862
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001863 ret = crypto_wait_req(enc ? crypto_skcipher_encrypt(req) :
1864 crypto_skcipher_decrypt(req), &wait);
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001865
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01001866 if (ret) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001867 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1868 d, e, j, algo, -ret);
1869 goto out;
1870 }
1871
1872 temp = 0;
1873 ret = -EINVAL;
1874 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001875 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001876 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1877 offset_in_page(IDX[k]);
1878 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001879 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1880 offset_in_page(IDX[k]);
1881
Eric Biggers92a4c9f2018-05-20 22:50:29 -07001882 if (memcmp(q, result + temp, template[i].tap[k])) {
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001883 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1884 d, j, e, k, algo);
1885 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001886 goto out;
1887 }
1888
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001889 q += template[i].tap[k];
1890 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1891 ;
1892 if (n) {
1893 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1894 d, j, e, k, algo, n);
1895 hexdump(q, n);
1896 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001897 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001898 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001899 }
1900 }
1901
1902 ret = 0;
1903
1904out:
Herbert Xu12773d92015-08-20 15:21:46 +08001905 skcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001906 if (diff_dst)
1907 testmgr_free_buf(xoutbuf);
1908out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001909 testmgr_free_buf(xbuf);
1910out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001911 return ret;
1912}
1913
Herbert Xu12773d92015-08-20 15:21:46 +08001914static int test_skcipher(struct crypto_skcipher *tfm, int enc,
Eric Biggersb13b1e02017-02-24 15:46:59 -08001915 const struct cipher_testvec *template,
1916 unsigned int tcount)
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001917{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001918 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001919 int ret;
1920
1921 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001922 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001923 if (ret)
1924 return ret;
1925
1926 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001927 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1928 if (ret)
1929 return ret;
1930
1931 /* test unaligned buffers, check with one byte offset */
1932 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1933 if (ret)
1934 return ret;
1935
1936 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1937 if (alignmask) {
1938 /* Check if alignment mask for tfm is correctly set. */
1939 ret = __test_skcipher(tfm, enc, template, tcount, true,
1940 alignmask + 1);
1941 if (ret)
1942 return ret;
1943 }
1944
1945 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001946}
1947
Eric Biggersb13b1e02017-02-24 15:46:59 -08001948static int test_comp(struct crypto_comp *tfm,
1949 const struct comp_testvec *ctemplate,
1950 const struct comp_testvec *dtemplate,
1951 int ctcount, int dtcount)
Herbert Xuda7f0332008-07-31 17:08:25 +08001952{
1953 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
Mahipal Challa33607382018-04-11 20:28:32 +02001954 char *output, *decomp_output;
Herbert Xuda7f0332008-07-31 17:08:25 +08001955 unsigned int i;
Herbert Xuda7f0332008-07-31 17:08:25 +08001956 int ret;
1957
Mahipal Challa33607382018-04-11 20:28:32 +02001958 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1959 if (!output)
1960 return -ENOMEM;
1961
1962 decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1963 if (!decomp_output) {
1964 kfree(output);
1965 return -ENOMEM;
1966 }
1967
Herbert Xuda7f0332008-07-31 17:08:25 +08001968 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001969 int ilen;
1970 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001971
Michael Schupikov22a81182018-10-07 13:58:10 +02001972 memset(output, 0, COMP_BUF_SIZE);
1973 memset(decomp_output, 0, COMP_BUF_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +08001974
1975 ilen = ctemplate[i].inlen;
1976 ret = crypto_comp_compress(tfm, ctemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02001977 ilen, output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08001978 if (ret) {
1979 printk(KERN_ERR "alg: comp: compression failed "
1980 "on test %d for %s: ret=%d\n", i + 1, algo,
1981 -ret);
1982 goto out;
1983 }
1984
Mahipal Challa33607382018-04-11 20:28:32 +02001985 ilen = dlen;
1986 dlen = COMP_BUF_SIZE;
1987 ret = crypto_comp_decompress(tfm, output,
1988 ilen, decomp_output, &dlen);
1989 if (ret) {
1990 pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n",
1991 i + 1, algo, -ret);
1992 goto out;
1993 }
1994
1995 if (dlen != ctemplate[i].inlen) {
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001996 printk(KERN_ERR "alg: comp: Compression test %d "
1997 "failed for %s: output len = %d\n", i + 1, algo,
1998 dlen);
1999 ret = -EINVAL;
2000 goto out;
2001 }
2002
Mahipal Challa33607382018-04-11 20:28:32 +02002003 if (memcmp(decomp_output, ctemplate[i].input,
2004 ctemplate[i].inlen)) {
2005 pr_err("alg: comp: compression failed: output differs: on test %d for %s\n",
2006 i + 1, algo);
2007 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08002008 ret = -EINVAL;
2009 goto out;
2010 }
2011 }
2012
2013 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08002014 int ilen;
2015 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08002016
Michael Schupikov22a81182018-10-07 13:58:10 +02002017 memset(decomp_output, 0, COMP_BUF_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +08002018
2019 ilen = dtemplate[i].inlen;
2020 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
Mahipal Challa33607382018-04-11 20:28:32 +02002021 ilen, decomp_output, &dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08002022 if (ret) {
2023 printk(KERN_ERR "alg: comp: decompression failed "
2024 "on test %d for %s: ret=%d\n", i + 1, algo,
2025 -ret);
2026 goto out;
2027 }
2028
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08002029 if (dlen != dtemplate[i].outlen) {
2030 printk(KERN_ERR "alg: comp: Decompression test %d "
2031 "failed for %s: output len = %d\n", i + 1, algo,
2032 dlen);
2033 ret = -EINVAL;
2034 goto out;
2035 }
2036
Mahipal Challa33607382018-04-11 20:28:32 +02002037 if (memcmp(decomp_output, dtemplate[i].output, dlen)) {
Herbert Xuda7f0332008-07-31 17:08:25 +08002038 printk(KERN_ERR "alg: comp: Decompression test %d "
2039 "failed for %s\n", i + 1, algo);
Mahipal Challa33607382018-04-11 20:28:32 +02002040 hexdump(decomp_output, dlen);
Herbert Xuda7f0332008-07-31 17:08:25 +08002041 ret = -EINVAL;
2042 goto out;
2043 }
2044 }
2045
2046 ret = 0;
2047
2048out:
Mahipal Challa33607382018-04-11 20:28:32 +02002049 kfree(decomp_output);
2050 kfree(output);
Herbert Xuda7f0332008-07-31 17:08:25 +08002051 return ret;
2052}
2053
Eric Biggersb13b1e02017-02-24 15:46:59 -08002054static int test_acomp(struct crypto_acomp *tfm,
Mahipal Challa33607382018-04-11 20:28:32 +02002055 const struct comp_testvec *ctemplate,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002056 const struct comp_testvec *dtemplate,
2057 int ctcount, int dtcount)
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002058{
2059 const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
2060 unsigned int i;
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002061 char *output, *decomp_out;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002062 int ret;
2063 struct scatterlist src, dst;
2064 struct acomp_req *req;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002065 struct crypto_wait wait;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002066
Eric Biggerseb095592016-11-23 10:24:35 -08002067 output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
2068 if (!output)
2069 return -ENOMEM;
2070
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002071 decomp_out = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
2072 if (!decomp_out) {
2073 kfree(output);
2074 return -ENOMEM;
2075 }
2076
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002077 for (i = 0; i < ctcount; i++) {
2078 unsigned int dlen = COMP_BUF_SIZE;
2079 int ilen = ctemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08002080 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002081
Eric Biggersd2110222016-12-30 14:12:00 -06002082 input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08002083 if (!input_vec) {
2084 ret = -ENOMEM;
2085 goto out;
2086 }
2087
Eric Biggerseb095592016-11-23 10:24:35 -08002088 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002089 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08002090 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002091 sg_init_one(&dst, output, dlen);
2092
2093 req = acomp_request_alloc(tfm);
2094 if (!req) {
2095 pr_err("alg: acomp: request alloc failed for %s\n",
2096 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08002097 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002098 ret = -ENOMEM;
2099 goto out;
2100 }
2101
2102 acomp_request_set_params(req, &src, &dst, ilen, dlen);
2103 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002104 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002105
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002106 ret = crypto_wait_req(crypto_acomp_compress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002107 if (ret) {
2108 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
2109 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08002110 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002111 acomp_request_free(req);
2112 goto out;
2113 }
2114
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002115 ilen = req->dlen;
2116 dlen = COMP_BUF_SIZE;
2117 sg_init_one(&src, output, ilen);
2118 sg_init_one(&dst, decomp_out, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002119 crypto_init_wait(&wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002120 acomp_request_set_params(req, &src, &dst, ilen, dlen);
2121
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002122 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002123 if (ret) {
2124 pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
2125 i + 1, algo, -ret);
2126 kfree(input_vec);
2127 acomp_request_free(req);
2128 goto out;
2129 }
2130
2131 if (req->dlen != ctemplate[i].inlen) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002132 pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
2133 i + 1, algo, req->dlen);
2134 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002135 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002136 acomp_request_free(req);
2137 goto out;
2138 }
2139
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002140 if (memcmp(input_vec, decomp_out, req->dlen)) {
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002141 pr_err("alg: acomp: Compression test %d failed for %s\n",
2142 i + 1, algo);
2143 hexdump(output, req->dlen);
2144 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002145 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002146 acomp_request_free(req);
2147 goto out;
2148 }
2149
Laura Abbott02608e02016-12-21 12:32:54 -08002150 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002151 acomp_request_free(req);
2152 }
2153
2154 for (i = 0; i < dtcount; i++) {
2155 unsigned int dlen = COMP_BUF_SIZE;
2156 int ilen = dtemplate[i].inlen;
Laura Abbott02608e02016-12-21 12:32:54 -08002157 void *input_vec;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002158
Eric Biggersd2110222016-12-30 14:12:00 -06002159 input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
Laura Abbott02608e02016-12-21 12:32:54 -08002160 if (!input_vec) {
2161 ret = -ENOMEM;
2162 goto out;
2163 }
2164
Eric Biggerseb095592016-11-23 10:24:35 -08002165 memset(output, 0, dlen);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002166 crypto_init_wait(&wait);
Laura Abbott02608e02016-12-21 12:32:54 -08002167 sg_init_one(&src, input_vec, ilen);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002168 sg_init_one(&dst, output, dlen);
2169
2170 req = acomp_request_alloc(tfm);
2171 if (!req) {
2172 pr_err("alg: acomp: request alloc failed for %s\n",
2173 algo);
Laura Abbott02608e02016-12-21 12:32:54 -08002174 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002175 ret = -ENOMEM;
2176 goto out;
2177 }
2178
2179 acomp_request_set_params(req, &src, &dst, ilen, dlen);
2180 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002181 crypto_req_done, &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002182
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002183 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002184 if (ret) {
2185 pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
2186 i + 1, algo, -ret);
Laura Abbott02608e02016-12-21 12:32:54 -08002187 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002188 acomp_request_free(req);
2189 goto out;
2190 }
2191
2192 if (req->dlen != dtemplate[i].outlen) {
2193 pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
2194 i + 1, algo, req->dlen);
2195 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002196 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002197 acomp_request_free(req);
2198 goto out;
2199 }
2200
2201 if (memcmp(output, dtemplate[i].output, req->dlen)) {
2202 pr_err("alg: acomp: Decompression test %d failed for %s\n",
2203 i + 1, algo);
2204 hexdump(output, req->dlen);
2205 ret = -EINVAL;
Laura Abbott02608e02016-12-21 12:32:54 -08002206 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002207 acomp_request_free(req);
2208 goto out;
2209 }
2210
Laura Abbott02608e02016-12-21 12:32:54 -08002211 kfree(input_vec);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002212 acomp_request_free(req);
2213 }
2214
2215 ret = 0;
2216
2217out:
Giovanni Cabiddua9943a02017-04-19 14:27:18 +01002218 kfree(decomp_out);
Eric Biggerseb095592016-11-23 10:24:35 -08002219 kfree(output);
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002220 return ret;
2221}
2222
Eric Biggersb13b1e02017-02-24 15:46:59 -08002223static int test_cprng(struct crypto_rng *tfm,
2224 const struct cprng_testvec *template,
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002225 unsigned int tcount)
2226{
2227 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08002228 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002229 u8 *seed;
2230 char result[32];
2231
2232 seedsize = crypto_rng_seedsize(tfm);
2233
2234 seed = kmalloc(seedsize, GFP_KERNEL);
2235 if (!seed) {
2236 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
2237 "for %s\n", algo);
2238 return -ENOMEM;
2239 }
2240
2241 for (i = 0; i < tcount; i++) {
2242 memset(result, 0, 32);
2243
2244 memcpy(seed, template[i].v, template[i].vlen);
2245 memcpy(seed + template[i].vlen, template[i].key,
2246 template[i].klen);
2247 memcpy(seed + template[i].vlen + template[i].klen,
2248 template[i].dt, template[i].dtlen);
2249
2250 err = crypto_rng_reset(tfm, seed, seedsize);
2251 if (err) {
2252 printk(KERN_ERR "alg: cprng: Failed to reset rng "
2253 "for %s\n", algo);
2254 goto out;
2255 }
2256
2257 for (j = 0; j < template[i].loops; j++) {
2258 err = crypto_rng_get_bytes(tfm, result,
2259 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01002260 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002261 printk(KERN_ERR "alg: cprng: Failed to obtain "
2262 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01002263 "%s (requested %d)\n", algo,
2264 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002265 goto out;
2266 }
2267 }
2268
2269 err = memcmp(result, template[i].result,
2270 template[i].rlen);
2271 if (err) {
2272 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
2273 i, algo);
2274 hexdump(result, template[i].rlen);
2275 err = -EINVAL;
2276 goto out;
2277 }
2278 }
2279
2280out:
2281 kfree(seed);
2282 return err;
2283}
2284
Herbert Xuda7f0332008-07-31 17:08:25 +08002285static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
2286 u32 type, u32 mask)
2287{
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002288 const struct aead_test_suite *suite = &desc->suite.aead;
Herbert Xuda7f0332008-07-31 17:08:25 +08002289 struct crypto_aead *tfm;
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002290 int err;
Herbert Xuda7f0332008-07-31 17:08:25 +08002291
Herbert Xueed93e02016-11-22 20:08:31 +08002292 tfm = crypto_alloc_aead(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08002293 if (IS_ERR(tfm)) {
2294 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
2295 "%ld\n", driver, PTR_ERR(tfm));
2296 return PTR_ERR(tfm);
2297 }
2298
Eric Biggersa0d608ee2019-01-13 15:32:28 -08002299 err = test_aead(tfm, ENCRYPT, suite->vecs, suite->count);
2300 if (!err)
2301 err = test_aead(tfm, DECRYPT, suite->vecs, suite->count);
Herbert Xuda7f0332008-07-31 17:08:25 +08002302
Herbert Xuda7f0332008-07-31 17:08:25 +08002303 crypto_free_aead(tfm);
2304 return err;
2305}
2306
2307static int alg_test_cipher(const struct alg_test_desc *desc,
2308 const char *driver, u32 type, u32 mask)
2309{
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002310 const struct cipher_test_suite *suite = &desc->suite.cipher;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002311 struct crypto_cipher *tfm;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002312 int err;
Herbert Xuda7f0332008-07-31 17:08:25 +08002313
Herbert Xueed93e02016-11-22 20:08:31 +08002314 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08002315 if (IS_ERR(tfm)) {
2316 printk(KERN_ERR "alg: cipher: Failed to load transform for "
2317 "%s: %ld\n", driver, PTR_ERR(tfm));
2318 return PTR_ERR(tfm);
2319 }
2320
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002321 err = test_cipher(tfm, ENCRYPT, suite->vecs, suite->count);
2322 if (!err)
2323 err = test_cipher(tfm, DECRYPT, suite->vecs, suite->count);
Herbert Xuda7f0332008-07-31 17:08:25 +08002324
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002325 crypto_free_cipher(tfm);
2326 return err;
2327}
2328
2329static int alg_test_skcipher(const struct alg_test_desc *desc,
2330 const char *driver, u32 type, u32 mask)
2331{
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002332 const struct cipher_test_suite *suite = &desc->suite.cipher;
Herbert Xu12773d92015-08-20 15:21:46 +08002333 struct crypto_skcipher *tfm;
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002334 int err;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002335
Herbert Xueed93e02016-11-22 20:08:31 +08002336 tfm = crypto_alloc_skcipher(driver, type, mask);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002337 if (IS_ERR(tfm)) {
2338 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
2339 "%s: %ld\n", driver, PTR_ERR(tfm));
2340 return PTR_ERR(tfm);
2341 }
2342
Eric Biggers92a4c9f2018-05-20 22:50:29 -07002343 err = test_skcipher(tfm, ENCRYPT, suite->vecs, suite->count);
2344 if (!err)
2345 err = test_skcipher(tfm, DECRYPT, suite->vecs, suite->count);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002346
Herbert Xu12773d92015-08-20 15:21:46 +08002347 crypto_free_skcipher(tfm);
Herbert Xuda7f0332008-07-31 17:08:25 +08002348 return err;
2349}
2350
2351static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
2352 u32 type, u32 mask)
2353{
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002354 struct crypto_comp *comp;
2355 struct crypto_acomp *acomp;
Herbert Xuda7f0332008-07-31 17:08:25 +08002356 int err;
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002357 u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
Herbert Xuda7f0332008-07-31 17:08:25 +08002358
Giovanni Cabiddud7db7a82016-10-21 13:19:54 +01002359 if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
2360 acomp = crypto_alloc_acomp(driver, type, mask);
2361 if (IS_ERR(acomp)) {
2362 pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
2363 driver, PTR_ERR(acomp));
2364 return PTR_ERR(acomp);
2365 }
2366 err = test_acomp(acomp, desc->suite.comp.comp.vecs,
2367 desc->suite.comp.decomp.vecs,
2368 desc->suite.comp.comp.count,
2369 desc->suite.comp.decomp.count);
2370 crypto_free_acomp(acomp);
2371 } else {
2372 comp = crypto_alloc_comp(driver, type, mask);
2373 if (IS_ERR(comp)) {
2374 pr_err("alg: comp: Failed to load transform for %s: %ld\n",
2375 driver, PTR_ERR(comp));
2376 return PTR_ERR(comp);
2377 }
2378
2379 err = test_comp(comp, desc->suite.comp.comp.vecs,
2380 desc->suite.comp.decomp.vecs,
2381 desc->suite.comp.comp.count,
2382 desc->suite.comp.decomp.count);
2383
2384 crypto_free_comp(comp);
Herbert Xuda7f0332008-07-31 17:08:25 +08002385 }
Herbert Xuda7f0332008-07-31 17:08:25 +08002386 return err;
2387}
2388
Eric Biggers9b3abc0162018-05-19 22:07:41 -07002389static int __alg_test_hash(const struct hash_testvec *template,
2390 unsigned int tcount, const char *driver,
2391 u32 type, u32 mask)
Herbert Xuda7f0332008-07-31 17:08:25 +08002392{
2393 struct crypto_ahash *tfm;
2394 int err;
2395
Herbert Xueed93e02016-11-22 20:08:31 +08002396 tfm = crypto_alloc_ahash(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08002397 if (IS_ERR(tfm)) {
2398 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
2399 "%ld\n", driver, PTR_ERR(tfm));
2400 return PTR_ERR(tfm);
2401 }
2402
Gilad Ben-Yossef76715092018-07-01 08:02:35 +01002403 err = test_hash(tfm, template, tcount, HASH_TEST_DIGEST);
David S. Millera8f1a052010-05-19 14:12:03 +10002404 if (!err)
Gilad Ben-Yossef76715092018-07-01 08:02:35 +01002405 err = test_hash(tfm, template, tcount, HASH_TEST_FINAL);
2406 if (!err)
2407 err = test_hash(tfm, template, tcount, HASH_TEST_FINUP);
Herbert Xuda7f0332008-07-31 17:08:25 +08002408 crypto_free_ahash(tfm);
2409 return err;
2410}
2411
Eric Biggers9b3abc0162018-05-19 22:07:41 -07002412static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
2413 u32 type, u32 mask)
2414{
2415 const struct hash_testvec *template = desc->suite.hash.vecs;
2416 unsigned int tcount = desc->suite.hash.count;
2417 unsigned int nr_unkeyed, nr_keyed;
2418 int err;
2419
2420 /*
2421 * For OPTIONAL_KEY algorithms, we have to do all the unkeyed tests
2422 * first, before setting a key on the tfm. To make this easier, we
2423 * require that the unkeyed test vectors (if any) are listed first.
2424 */
2425
2426 for (nr_unkeyed = 0; nr_unkeyed < tcount; nr_unkeyed++) {
2427 if (template[nr_unkeyed].ksize)
2428 break;
2429 }
2430 for (nr_keyed = 0; nr_unkeyed + nr_keyed < tcount; nr_keyed++) {
2431 if (!template[nr_unkeyed + nr_keyed].ksize) {
2432 pr_err("alg: hash: test vectors for %s out of order, "
2433 "unkeyed ones must come first\n", desc->alg);
2434 return -EINVAL;
2435 }
2436 }
2437
2438 err = 0;
2439 if (nr_unkeyed) {
2440 err = __alg_test_hash(template, nr_unkeyed, driver, type, mask);
2441 template += nr_unkeyed;
2442 }
2443
2444 if (!err && nr_keyed)
2445 err = __alg_test_hash(template, nr_keyed, driver, type, mask);
2446
2447 return err;
2448}
2449
Herbert Xu8e3ee852008-11-07 14:58:52 +08002450static int alg_test_crc32c(const struct alg_test_desc *desc,
2451 const char *driver, u32 type, u32 mask)
2452{
2453 struct crypto_shash *tfm;
Eric Biggerscb9dde82019-01-10 12:17:55 -08002454 __le32 val;
Herbert Xu8e3ee852008-11-07 14:58:52 +08002455 int err;
2456
2457 err = alg_test_hash(desc, driver, type, mask);
2458 if (err)
Eric Biggerseb5e6732019-01-23 20:57:35 -08002459 return err;
Herbert Xu8e3ee852008-11-07 14:58:52 +08002460
Herbert Xueed93e02016-11-22 20:08:31 +08002461 tfm = crypto_alloc_shash(driver, type, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002462 if (IS_ERR(tfm)) {
Eric Biggerseb5e6732019-01-23 20:57:35 -08002463 if (PTR_ERR(tfm) == -ENOENT) {
2464 /*
2465 * This crc32c implementation is only available through
2466 * ahash API, not the shash API, so the remaining part
2467 * of the test is not applicable to it.
2468 */
2469 return 0;
2470 }
Herbert Xu8e3ee852008-11-07 14:58:52 +08002471 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
2472 "%ld\n", driver, PTR_ERR(tfm));
Eric Biggerseb5e6732019-01-23 20:57:35 -08002473 return PTR_ERR(tfm);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002474 }
2475
2476 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02002477 SHASH_DESC_ON_STACK(shash, tfm);
2478 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002479
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02002480 shash->tfm = tfm;
2481 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08002482
Eric Biggerscb9dde82019-01-10 12:17:55 -08002483 *ctx = 420553207;
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02002484 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08002485 if (err) {
2486 printk(KERN_ERR "alg: crc32c: Operation failed for "
2487 "%s: %d\n", driver, err);
2488 break;
2489 }
2490
Eric Biggerscb9dde82019-01-10 12:17:55 -08002491 if (val != cpu_to_le32(~420553207)) {
2492 pr_err("alg: crc32c: Test failed for %s: %u\n",
2493 driver, le32_to_cpu(val));
Herbert Xu8e3ee852008-11-07 14:58:52 +08002494 err = -EINVAL;
2495 }
2496 } while (0);
2497
2498 crypto_free_shash(tfm);
2499
Herbert Xu8e3ee852008-11-07 14:58:52 +08002500 return err;
2501}
2502
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002503static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
2504 u32 type, u32 mask)
2505{
2506 struct crypto_rng *rng;
2507 int err;
2508
Herbert Xueed93e02016-11-22 20:08:31 +08002509 rng = crypto_alloc_rng(driver, type, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08002510 if (IS_ERR(rng)) {
2511 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
2512 "%ld\n", driver, PTR_ERR(rng));
2513 return PTR_ERR(rng);
2514 }
2515
2516 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
2517
2518 crypto_free_rng(rng);
2519
2520 return err;
2521}
2522
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002523
Eric Biggersb13b1e02017-02-24 15:46:59 -08002524static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002525 const char *driver, u32 type, u32 mask)
2526{
2527 int ret = -EAGAIN;
2528 struct crypto_rng *drng;
2529 struct drbg_test_data test_data;
2530 struct drbg_string addtl, pers, testentropy;
2531 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
2532
2533 if (!buf)
2534 return -ENOMEM;
2535
Herbert Xueed93e02016-11-22 20:08:31 +08002536 drng = crypto_alloc_rng(driver, type, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002537 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002538 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002539 "%s\n", driver);
2540 kzfree(buf);
2541 return -ENOMEM;
2542 }
2543
2544 test_data.testentropy = &testentropy;
2545 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
2546 drbg_string_fill(&pers, test->pers, test->perslen);
2547 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
2548 if (ret) {
2549 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
2550 goto outbuf;
2551 }
2552
2553 drbg_string_fill(&addtl, test->addtla, test->addtllen);
2554 if (pr) {
2555 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
2556 ret = crypto_drbg_get_bytes_addtl_test(drng,
2557 buf, test->expectedlen, &addtl, &test_data);
2558 } else {
2559 ret = crypto_drbg_get_bytes_addtl(drng,
2560 buf, test->expectedlen, &addtl);
2561 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01002562 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002563 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002564 "driver %s\n", driver);
2565 goto outbuf;
2566 }
2567
2568 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
2569 if (pr) {
2570 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
2571 ret = crypto_drbg_get_bytes_addtl_test(drng,
2572 buf, test->expectedlen, &addtl, &test_data);
2573 } else {
2574 ret = crypto_drbg_get_bytes_addtl(drng,
2575 buf, test->expectedlen, &addtl);
2576 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01002577 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04002578 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002579 "driver %s\n", driver);
2580 goto outbuf;
2581 }
2582
2583 ret = memcmp(test->expected, buf, test->expectedlen);
2584
2585outbuf:
2586 crypto_free_rng(drng);
2587 kzfree(buf);
2588 return ret;
2589}
2590
2591
2592static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
2593 u32 type, u32 mask)
2594{
2595 int err = 0;
2596 int pr = 0;
2597 int i = 0;
Eric Biggersb13b1e02017-02-24 15:46:59 -08002598 const struct drbg_testvec *template = desc->suite.drbg.vecs;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002599 unsigned int tcount = desc->suite.drbg.count;
2600
2601 if (0 == memcmp(driver, "drbg_pr_", 8))
2602 pr = 1;
2603
2604 for (i = 0; i < tcount; i++) {
2605 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
2606 if (err) {
2607 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
2608 i, driver);
2609 err = -EINVAL;
2610 break;
2611 }
2612 }
2613 return err;
2614
2615}
2616
Eric Biggersb13b1e02017-02-24 15:46:59 -08002617static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002618 const char *alg)
2619{
2620 struct kpp_request *req;
2621 void *input_buf = NULL;
2622 void *output_buf = NULL;
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002623 void *a_public = NULL;
2624 void *a_ss = NULL;
2625 void *shared_secret = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002626 struct crypto_wait wait;
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002627 unsigned int out_len_max;
2628 int err = -ENOMEM;
2629 struct scatterlist src, dst;
2630
2631 req = kpp_request_alloc(tfm, GFP_KERNEL);
2632 if (!req)
2633 return err;
2634
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002635 crypto_init_wait(&wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002636
2637 err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
2638 if (err < 0)
2639 goto free_req;
2640
2641 out_len_max = crypto_kpp_maxsize(tfm);
2642 output_buf = kzalloc(out_len_max, GFP_KERNEL);
2643 if (!output_buf) {
2644 err = -ENOMEM;
2645 goto free_req;
2646 }
2647
2648 /* Use appropriate parameter as base */
2649 kpp_request_set_input(req, NULL, 0);
2650 sg_init_one(&dst, output_buf, out_len_max);
2651 kpp_request_set_output(req, &dst, out_len_max);
2652 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002653 crypto_req_done, &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002654
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002655 /* Compute party A's public key */
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002656 err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002657 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002658 pr_err("alg: %s: Party A: generate public key test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002659 alg, err);
2660 goto free_output;
2661 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002662
2663 if (vec->genkey) {
2664 /* Save party A's public key */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05002665 a_public = kmemdup(sg_virt(req->dst), out_len_max, GFP_KERNEL);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002666 if (!a_public) {
2667 err = -ENOMEM;
2668 goto free_output;
2669 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002670 } else {
2671 /* Verify calculated public key */
2672 if (memcmp(vec->expected_a_public, sg_virt(req->dst),
2673 vec->expected_a_public_size)) {
2674 pr_err("alg: %s: Party A: generate public key test failed. Invalid output\n",
2675 alg);
2676 err = -EINVAL;
2677 goto free_output;
2678 }
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002679 }
2680
2681 /* Calculate shared secret key by using counter part (b) public key. */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05002682 input_buf = kmemdup(vec->b_public, vec->b_public_size, GFP_KERNEL);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002683 if (!input_buf) {
2684 err = -ENOMEM;
2685 goto free_output;
2686 }
2687
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002688 sg_init_one(&src, input_buf, vec->b_public_size);
2689 sg_init_one(&dst, output_buf, out_len_max);
2690 kpp_request_set_input(req, &src, vec->b_public_size);
2691 kpp_request_set_output(req, &dst, out_len_max);
2692 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002693 crypto_req_done, &wait);
2694 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002695 if (err) {
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002696 pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n",
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002697 alg, err);
2698 goto free_all;
2699 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002700
2701 if (vec->genkey) {
2702 /* Save the shared secret obtained by party A */
Christopher Diaz Riverose3d90e522019-01-28 19:01:18 -05002703 a_ss = kmemdup(sg_virt(req->dst), vec->expected_ss_size, GFP_KERNEL);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002704 if (!a_ss) {
2705 err = -ENOMEM;
2706 goto free_all;
2707 }
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002708
2709 /*
2710 * Calculate party B's shared secret by using party A's
2711 * public key.
2712 */
2713 err = crypto_kpp_set_secret(tfm, vec->b_secret,
2714 vec->b_secret_size);
2715 if (err < 0)
2716 goto free_all;
2717
2718 sg_init_one(&src, a_public, vec->expected_a_public_size);
2719 sg_init_one(&dst, output_buf, out_len_max);
2720 kpp_request_set_input(req, &src, vec->expected_a_public_size);
2721 kpp_request_set_output(req, &dst, out_len_max);
2722 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002723 crypto_req_done, &wait);
2724 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req),
2725 &wait);
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002726 if (err) {
2727 pr_err("alg: %s: Party B: compute shared secret failed. err %d\n",
2728 alg, err);
2729 goto free_all;
2730 }
2731
2732 shared_secret = a_ss;
2733 } else {
2734 shared_secret = (void *)vec->expected_ss;
2735 }
2736
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002737 /*
2738 * verify shared secret from which the user will derive
2739 * secret key by executing whatever hash it has chosen
2740 */
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002741 if (memcmp(shared_secret, sg_virt(req->dst),
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002742 vec->expected_ss_size)) {
2743 pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
2744 alg);
2745 err = -EINVAL;
2746 }
2747
2748free_all:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002749 kfree(a_ss);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002750 kfree(input_buf);
2751free_output:
Tudor-Dan Ambarus47d3fd32017-05-30 17:52:49 +03002752 kfree(a_public);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002753 kfree(output_buf);
2754free_req:
2755 kpp_request_free(req);
2756 return err;
2757}
2758
2759static int test_kpp(struct crypto_kpp *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002760 const struct kpp_testvec *vecs, unsigned int tcount)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002761{
2762 int ret, i;
2763
2764 for (i = 0; i < tcount; i++) {
2765 ret = do_test_kpp(tfm, vecs++, alg);
2766 if (ret) {
2767 pr_err("alg: %s: test failed on vector %d, err=%d\n",
2768 alg, i + 1, ret);
2769 return ret;
2770 }
2771 }
2772 return 0;
2773}
2774
2775static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
2776 u32 type, u32 mask)
2777{
2778 struct crypto_kpp *tfm;
2779 int err = 0;
2780
Herbert Xueed93e02016-11-22 20:08:31 +08002781 tfm = crypto_alloc_kpp(driver, type, mask);
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01002782 if (IS_ERR(tfm)) {
2783 pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
2784 driver, PTR_ERR(tfm));
2785 return PTR_ERR(tfm);
2786 }
2787 if (desc->suite.kpp.vecs)
2788 err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
2789 desc->suite.kpp.count);
2790
2791 crypto_free_kpp(tfm);
2792 return err;
2793}
2794
Herbert Xu50d2b6432016-06-29 19:32:20 +08002795static int test_akcipher_one(struct crypto_akcipher *tfm,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002796 const struct akcipher_testvec *vecs)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002797{
Herbert Xudf27b262016-05-05 16:42:49 +08002798 char *xbuf[XBUFSIZE];
Tadeusz Struk946cc462015-06-16 10:31:06 -07002799 struct akcipher_request *req;
2800 void *outbuf_enc = NULL;
2801 void *outbuf_dec = NULL;
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002802 struct crypto_wait wait;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002803 unsigned int out_len_max, out_len = 0;
2804 int err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002805 struct scatterlist src, dst, src_tab[2];
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002806 const char *m, *c;
2807 unsigned int m_size, c_size;
2808 const char *op;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002809
Herbert Xudf27b262016-05-05 16:42:49 +08002810 if (testmgr_alloc_buf(xbuf))
2811 return err;
2812
Tadeusz Struk946cc462015-06-16 10:31:06 -07002813 req = akcipher_request_alloc(tfm, GFP_KERNEL);
2814 if (!req)
Herbert Xudf27b262016-05-05 16:42:49 +08002815 goto free_xbuf;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002816
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002817 crypto_init_wait(&wait);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002818
2819 if (vecs->public_key_vec)
2820 err = crypto_akcipher_set_pub_key(tfm, vecs->key,
2821 vecs->key_len);
2822 else
2823 err = crypto_akcipher_set_priv_key(tfm, vecs->key,
2824 vecs->key_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002825 if (err)
2826 goto free_req;
2827
Salvatore Benedetto57763f52016-07-04 10:52:34 +01002828 err = -ENOMEM;
Tadeusz Struk22287b02015-10-08 09:26:55 -07002829 out_len_max = crypto_akcipher_maxsize(tfm);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002830
2831 /*
2832 * First run test which do not require a private key, such as
2833 * encrypt or verify.
2834 */
Tadeusz Struk946cc462015-06-16 10:31:06 -07002835 outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
2836 if (!outbuf_enc)
2837 goto free_req;
2838
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002839 if (!vecs->siggen_sigver_test) {
2840 m = vecs->m;
2841 m_size = vecs->m_size;
2842 c = vecs->c;
2843 c_size = vecs->c_size;
2844 op = "encrypt";
2845 } else {
2846 /* Swap args so we could keep plaintext (digest)
2847 * in vecs->m, and cooked signature in vecs->c.
2848 */
2849 m = vecs->c; /* signature */
2850 m_size = vecs->c_size;
2851 c = vecs->m; /* digest */
2852 c_size = vecs->m_size;
2853 op = "verify";
2854 }
Herbert Xudf27b262016-05-05 16:42:49 +08002855
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002856 if (WARN_ON(m_size > PAGE_SIZE))
2857 goto free_all;
2858 memcpy(xbuf[0], m, m_size);
Herbert Xudf27b262016-05-05 16:42:49 +08002859
Tadeusz Struk22287b02015-10-08 09:26:55 -07002860 sg_init_table(src_tab, 2);
Herbert Xudf27b262016-05-05 16:42:49 +08002861 sg_set_buf(&src_tab[0], xbuf[0], 8);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002862 sg_set_buf(&src_tab[1], xbuf[0] + 8, m_size - 8);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002863 sg_init_one(&dst, outbuf_enc, out_len_max);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002864 akcipher_request_set_crypt(req, src_tab, &dst, m_size,
Tadeusz Struk22287b02015-10-08 09:26:55 -07002865 out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002866 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002867 crypto_req_done, &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002868
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002869 err = crypto_wait_req(vecs->siggen_sigver_test ?
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002870 /* Run asymmetric signature verification */
2871 crypto_akcipher_verify(req) :
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002872 /* Run asymmetric encrypt */
2873 crypto_akcipher_encrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002874 if (err) {
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002875 pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002876 goto free_all;
2877 }
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002878 if (req->dst_len != c_size) {
2879 pr_err("alg: akcipher: %s test failed. Invalid output len\n",
2880 op);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002881 err = -EINVAL;
2882 goto free_all;
2883 }
2884 /* verify that encrypted message is equal to expected */
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002885 if (memcmp(c, outbuf_enc, c_size)) {
2886 pr_err("alg: akcipher: %s test failed. Invalid output\n", op);
2887 hexdump(outbuf_enc, c_size);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002888 err = -EINVAL;
2889 goto free_all;
2890 }
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002891
2892 /*
2893 * Don't invoke (decrypt or sign) test which require a private key
2894 * for vectors with only a public key.
2895 */
Tadeusz Struk946cc462015-06-16 10:31:06 -07002896 if (vecs->public_key_vec) {
2897 err = 0;
2898 goto free_all;
2899 }
2900 outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
2901 if (!outbuf_dec) {
2902 err = -ENOMEM;
2903 goto free_all;
2904 }
Herbert Xudf27b262016-05-05 16:42:49 +08002905
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002906 op = vecs->siggen_sigver_test ? "sign" : "decrypt";
2907 if (WARN_ON(c_size > PAGE_SIZE))
Herbert Xudf27b262016-05-05 16:42:49 +08002908 goto free_all;
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002909 memcpy(xbuf[0], c, c_size);
Herbert Xudf27b262016-05-05 16:42:49 +08002910
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002911 sg_init_one(&src, xbuf[0], c_size);
Tadeusz Struk22287b02015-10-08 09:26:55 -07002912 sg_init_one(&dst, outbuf_dec, out_len_max);
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002913 crypto_init_wait(&wait);
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002914 akcipher_request_set_crypt(req, &src, &dst, c_size, out_len_max);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002915
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002916 err = crypto_wait_req(vecs->siggen_sigver_test ?
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002917 /* Run asymmetric signature generation */
2918 crypto_akcipher_sign(req) :
Gilad Ben-Yossef7f397132017-10-18 08:00:43 +01002919 /* Run asymmetric decrypt */
2920 crypto_akcipher_decrypt(req), &wait);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002921 if (err) {
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002922 pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002923 goto free_all;
2924 }
2925 out_len = req->dst_len;
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002926 if (out_len < m_size) {
2927 pr_err("alg: akcipher: %s test failed. Invalid output len %u\n",
2928 op, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002929 err = -EINVAL;
2930 goto free_all;
2931 }
2932 /* verify that decrypted message is equal to the original msg */
Vitaly Chikunov0507de92019-01-07 20:54:27 +03002933 if (memchr_inv(outbuf_dec, 0, out_len - m_size) ||
2934 memcmp(m, outbuf_dec + out_len - m_size, m_size)) {
2935 pr_err("alg: akcipher: %s test failed. Invalid output\n", op);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002936 hexdump(outbuf_dec, out_len);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002937 err = -EINVAL;
2938 }
2939free_all:
2940 kfree(outbuf_dec);
2941 kfree(outbuf_enc);
2942free_req:
2943 akcipher_request_free(req);
Herbert Xudf27b262016-05-05 16:42:49 +08002944free_xbuf:
2945 testmgr_free_buf(xbuf);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002946 return err;
2947}
2948
Herbert Xu50d2b6432016-06-29 19:32:20 +08002949static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
Eric Biggersb13b1e02017-02-24 15:46:59 -08002950 const struct akcipher_testvec *vecs,
2951 unsigned int tcount)
Tadeusz Struk946cc462015-06-16 10:31:06 -07002952{
Herbert Xu15226e42016-07-18 18:20:10 +08002953 const char *algo =
2954 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
Tadeusz Struk946cc462015-06-16 10:31:06 -07002955 int ret, i;
2956
2957 for (i = 0; i < tcount; i++) {
Herbert Xu50d2b6432016-06-29 19:32:20 +08002958 ret = test_akcipher_one(tfm, vecs++);
2959 if (!ret)
2960 continue;
2961
Herbert Xu15226e42016-07-18 18:20:10 +08002962 pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
2963 i + 1, algo, ret);
Herbert Xu50d2b6432016-06-29 19:32:20 +08002964 return ret;
Tadeusz Struk946cc462015-06-16 10:31:06 -07002965 }
2966 return 0;
2967}
2968
Tadeusz Struk946cc462015-06-16 10:31:06 -07002969static int alg_test_akcipher(const struct alg_test_desc *desc,
2970 const char *driver, u32 type, u32 mask)
2971{
2972 struct crypto_akcipher *tfm;
2973 int err = 0;
2974
Herbert Xueed93e02016-11-22 20:08:31 +08002975 tfm = crypto_alloc_akcipher(driver, type, mask);
Tadeusz Struk946cc462015-06-16 10:31:06 -07002976 if (IS_ERR(tfm)) {
2977 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
2978 driver, PTR_ERR(tfm));
2979 return PTR_ERR(tfm);
2980 }
2981 if (desc->suite.akcipher.vecs)
2982 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
2983 desc->suite.akcipher.count);
2984
2985 crypto_free_akcipher(tfm);
2986 return err;
2987}
2988
Youquan, Song863b5572009-12-23 19:45:20 +08002989static int alg_test_null(const struct alg_test_desc *desc,
2990 const char *driver, u32 type, u32 mask)
2991{
2992 return 0;
2993}
2994
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00002995#define __VECS(tv) { .vecs = tv, .count = ARRAY_SIZE(tv) }
2996
Herbert Xuda7f0332008-07-31 17:08:25 +08002997/* Please keep this list sorted by algorithm name. */
2998static const struct alg_test_desc alg_test_descs[] = {
2999 {
Eric Biggers059c2a42018-11-16 17:26:31 -08003000 .alg = "adiantum(xchacha12,aes)",
3001 .test = alg_test_skcipher,
3002 .suite = {
3003 .cipher = __VECS(adiantum_xchacha12_aes_tv_template)
3004 },
3005 }, {
3006 .alg = "adiantum(xchacha20,aes)",
3007 .test = alg_test_skcipher,
3008 .suite = {
3009 .cipher = __VECS(adiantum_xchacha20_aes_tv_template)
3010 },
3011 }, {
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02003012 .alg = "aegis128",
3013 .test = alg_test_aead,
3014 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003015 .aead = __VECS(aegis128_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02003016 }
3017 }, {
3018 .alg = "aegis128l",
3019 .test = alg_test_aead,
3020 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003021 .aead = __VECS(aegis128l_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02003022 }
3023 }, {
3024 .alg = "aegis256",
3025 .test = alg_test_aead,
3026 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003027 .aead = __VECS(aegis256_tv_template)
Ondrej Mosnacekb87dc202018-05-11 14:12:50 +02003028 }
3029 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08003030 .alg = "ansi_cprng",
3031 .test = alg_test_cprng,
3032 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003033 .cprng = __VECS(ansi_cprng_aes_tv_template)
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08003034 }
3035 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02003036 .alg = "authenc(hmac(md5),ecb(cipher_null))",
3037 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02003038 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003039 .aead = __VECS(hmac_md5_ecb_cipher_null_tv_template)
Horia Geantabca4feb2014-03-14 17:46:51 +02003040 }
3041 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003042 .alg = "authenc(hmac(sha1),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03003043 .test = alg_test_aead,
Herbert Xubcf741c2017-06-28 19:09:07 +08003044 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03003045 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003046 .aead = __VECS(hmac_sha1_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303047 }
3048 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003049 .alg = "authenc(hmac(sha1),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303050 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303051 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003052 .aead = __VECS(hmac_sha1_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303053 }
3054 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003055 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303056 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01003057 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303058 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003059 .aead = __VECS(hmac_sha1_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03003060 }
3061 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01003062 .alg = "authenc(hmac(sha1),ctr(aes))",
3063 .test = alg_test_null,
3064 .fips_allowed = 1,
3065 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02003066 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
3067 .test = alg_test_aead,
Horia Geantabca4feb2014-03-14 17:46:51 +02003068 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003069 .aead = __VECS(hmac_sha1_ecb_cipher_null_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303070 }
3071 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01003072 .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
3073 .test = alg_test_null,
3074 .fips_allowed = 1,
3075 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003076 .alg = "authenc(hmac(sha224),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303077 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303078 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003079 .aead = __VECS(hmac_sha224_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303080 }
3081 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003082 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303083 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01003084 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303085 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003086 .aead = __VECS(hmac_sha224_des3_ede_cbc_tv_temp)
Horia Geantabca4feb2014-03-14 17:46:51 +02003087 }
3088 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003089 .alg = "authenc(hmac(sha256),cbc(aes))",
Horia Geantae46e9a42012-07-03 19:16:54 +03003090 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01003091 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03003092 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003093 .aead = __VECS(hmac_sha256_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303094 }
3095 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003096 .alg = "authenc(hmac(sha256),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303097 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303098 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003099 .aead = __VECS(hmac_sha256_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303100 }
3101 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003102 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303103 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01003104 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303105 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003106 .aead = __VECS(hmac_sha256_des3_ede_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303107 }
3108 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01003109 .alg = "authenc(hmac(sha256),ctr(aes))",
3110 .test = alg_test_null,
3111 .fips_allowed = 1,
3112 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01003113 .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
3114 .test = alg_test_null,
3115 .fips_allowed = 1,
3116 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003117 .alg = "authenc(hmac(sha384),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303118 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303119 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003120 .aead = __VECS(hmac_sha384_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303121 }
3122 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003123 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303124 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01003125 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303126 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003127 .aead = __VECS(hmac_sha384_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03003128 }
3129 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01003130 .alg = "authenc(hmac(sha384),ctr(aes))",
3131 .test = alg_test_null,
3132 .fips_allowed = 1,
3133 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01003134 .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
3135 .test = alg_test_null,
3136 .fips_allowed = 1,
3137 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003138 .alg = "authenc(hmac(sha512),cbc(aes))",
Marcus Meissnered1afac2016-02-05 14:23:33 +01003139 .fips_allowed = 1,
Horia Geantae46e9a42012-07-03 19:16:54 +03003140 .test = alg_test_aead,
Horia Geantae46e9a42012-07-03 19:16:54 +03003141 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003142 .aead = __VECS(hmac_sha512_aes_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303143 }
3144 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003145 .alg = "authenc(hmac(sha512),cbc(des))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303146 .test = alg_test_aead,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303147 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003148 .aead = __VECS(hmac_sha512_des_cbc_tv_temp)
Nitesh Lal5208ed22014-05-21 17:09:08 +05303149 }
3150 }, {
Herbert Xua4198fd2015-07-30 17:53:23 +08003151 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
Nitesh Lal5208ed22014-05-21 17:09:08 +05303152 .test = alg_test_aead,
Marcus Meissnered1afac2016-02-05 14:23:33 +01003153 .fips_allowed = 1,
Nitesh Lal5208ed22014-05-21 17:09:08 +05303154 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003155 .aead = __VECS(hmac_sha512_des3_ede_cbc_tv_temp)
Horia Geantae46e9a42012-07-03 19:16:54 +03003156 }
3157 }, {
Marcus Meissnerfb16abc2016-02-06 11:53:07 +01003158 .alg = "authenc(hmac(sha512),ctr(aes))",
3159 .test = alg_test_null,
3160 .fips_allowed = 1,
3161 }, {
Marcus Meissner88886902016-02-19 13:34:28 +01003162 .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
3163 .test = alg_test_null,
3164 .fips_allowed = 1,
3165 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003166 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003167 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003168 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003169 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003170 .cipher = __VECS(aes_cbc_tv_template)
3171 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003172 }, {
3173 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003174 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003175 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003176 .cipher = __VECS(anubis_cbc_tv_template)
3177 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003178 }, {
3179 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003180 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003181 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003182 .cipher = __VECS(bf_cbc_tv_template)
3183 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003184 }, {
3185 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003186 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003187 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003188 .cipher = __VECS(camellia_cbc_tv_template)
3189 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003190 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003191 .alg = "cbc(cast5)",
3192 .test = alg_test_skcipher,
3193 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003194 .cipher = __VECS(cast5_cbc_tv_template)
3195 },
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003196 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003197 .alg = "cbc(cast6)",
3198 .test = alg_test_skcipher,
3199 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003200 .cipher = __VECS(cast6_cbc_tv_template)
3201 },
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003202 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003203 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003204 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003205 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003206 .cipher = __VECS(des_cbc_tv_template)
3207 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003208 }, {
3209 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003210 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003211 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003212 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003213 .cipher = __VECS(des3_ede_cbc_tv_template)
3214 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003215 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003216 /* Same as cbc(aes) except the key is stored in
3217 * hardware secure memory which we reference by index
3218 */
3219 .alg = "cbc(paes)",
3220 .test = alg_test_null,
3221 .fips_allowed = 1,
3222 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003223 .alg = "cbc(serpent)",
3224 .test = alg_test_skcipher,
3225 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003226 .cipher = __VECS(serpent_cbc_tv_template)
3227 },
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003228 }, {
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01003229 .alg = "cbc(sm4)",
3230 .test = alg_test_skcipher,
3231 .suite = {
3232 .cipher = __VECS(sm4_cbc_tv_template)
3233 }
3234 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003235 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003236 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003237 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003238 .cipher = __VECS(tf_cbc_tv_template)
3239 },
Herbert Xuda7f0332008-07-31 17:08:25 +08003240 }, {
Ard Biesheuvel092acf02017-02-03 14:49:35 +00003241 .alg = "cbcmac(aes)",
3242 .fips_allowed = 1,
3243 .test = alg_test_hash,
3244 .suite = {
3245 .hash = __VECS(aes_cbcmac_tv_template)
3246 }
3247 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003248 .alg = "ccm(aes)",
3249 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003250 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003251 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003252 .aead = __VECS(aes_ccm_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003253 }
3254 }, {
Dmitry Eremin-Solenikov7da66672018-10-20 02:01:53 +03003255 .alg = "cfb(aes)",
3256 .test = alg_test_skcipher,
3257 .fips_allowed = 1,
3258 .suite = {
3259 .cipher = __VECS(aes_cfb_tv_template)
3260 },
3261 }, {
Martin Willi3590ebf2015-06-01 13:43:57 +02003262 .alg = "chacha20",
3263 .test = alg_test_skcipher,
3264 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003265 .cipher = __VECS(chacha20_tv_template)
3266 },
Martin Willi3590ebf2015-06-01 13:43:57 +02003267 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003268 .alg = "cmac(aes)",
Stephan Mueller8f183752015-08-19 08:42:07 +02003269 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003270 .test = alg_test_hash,
3271 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003272 .hash = __VECS(aes_cmac128_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003273 }
3274 }, {
3275 .alg = "cmac(des3_ede)",
Stephan Mueller8f183752015-08-19 08:42:07 +02003276 .fips_allowed = 1,
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003277 .test = alg_test_hash,
3278 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003279 .hash = __VECS(des3_ede_cmac64_tv_template)
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03003280 }
3281 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003282 .alg = "compress_null",
3283 .test = alg_test_null,
3284 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003285 .alg = "crc32",
3286 .test = alg_test_hash,
Milan Broza8a34412019-01-25 10:31:47 +01003287 .fips_allowed = 1,
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003288 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003289 .hash = __VECS(crc32_tv_template)
Ard Biesheuvelebb34722015-05-04 11:00:17 +02003290 }
3291 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003292 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08003293 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003294 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003295 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003296 .hash = __VECS(crc32c_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003297 }
3298 }, {
Herbert Xu684115212013-09-07 12:56:26 +10003299 .alg = "crct10dif",
3300 .test = alg_test_hash,
3301 .fips_allowed = 1,
3302 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003303 .hash = __VECS(crct10dif_tv_template)
Herbert Xu684115212013-09-07 12:56:26 +10003304 }
3305 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003306 .alg = "ctr(aes)",
3307 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003308 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003309 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003310 .cipher = __VECS(aes_ctr_tv_template)
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003311 }
3312 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03003313 .alg = "ctr(blowfish)",
3314 .test = alg_test_skcipher,
3315 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003316 .cipher = __VECS(bf_ctr_tv_template)
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03003317 }
3318 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003319 .alg = "ctr(camellia)",
3320 .test = alg_test_skcipher,
3321 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003322 .cipher = __VECS(camellia_ctr_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003323 }
3324 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003325 .alg = "ctr(cast5)",
3326 .test = alg_test_skcipher,
3327 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003328 .cipher = __VECS(cast5_ctr_tv_template)
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02003329 }
3330 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003331 .alg = "ctr(cast6)",
3332 .test = alg_test_skcipher,
3333 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003334 .cipher = __VECS(cast6_ctr_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003335 }
3336 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03003337 .alg = "ctr(des)",
3338 .test = alg_test_skcipher,
3339 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003340 .cipher = __VECS(des_ctr_tv_template)
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03003341 }
3342 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003343 .alg = "ctr(des3_ede)",
3344 .test = alg_test_skcipher,
Marcelo Cerri0d8da102017-03-20 17:28:05 -03003345 .fips_allowed = 1,
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003346 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003347 .cipher = __VECS(des3_ede_ctr_tv_template)
Jussi Kivilinnae080b172012-10-20 14:53:12 +03003348 }
3349 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003350 /* Same as ctr(aes) except the key is stored in
3351 * hardware secure memory which we reference by index
3352 */
3353 .alg = "ctr(paes)",
3354 .test = alg_test_null,
3355 .fips_allowed = 1,
3356 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003357 .alg = "ctr(serpent)",
3358 .test = alg_test_skcipher,
3359 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003360 .cipher = __VECS(serpent_ctr_tv_template)
Jussi Kivilinna9d259172011-10-18 00:02:53 +03003361 }
3362 }, {
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01003363 .alg = "ctr(sm4)",
3364 .test = alg_test_skcipher,
3365 .suite = {
3366 .cipher = __VECS(sm4_ctr_tv_template)
3367 }
3368 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03003369 .alg = "ctr(twofish)",
3370 .test = alg_test_skcipher,
3371 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003372 .cipher = __VECS(tf_ctr_tv_template)
Jussi Kivilinna573da622011-10-10 23:03:12 +03003373 }
3374 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003375 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003376 .test = alg_test_skcipher,
Gilad Ben-Yossef196ad602018-11-04 10:05:24 +00003377 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003378 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003379 .cipher = __VECS(cts_mode_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003380 }
3381 }, {
3382 .alg = "deflate",
3383 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003384 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003385 .suite = {
3386 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003387 .comp = __VECS(deflate_comp_tv_template),
3388 .decomp = __VECS(deflate_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003389 }
3390 }
3391 }, {
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003392 .alg = "dh",
3393 .test = alg_test_kpp,
3394 .fips_allowed = 1,
3395 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003396 .kpp = __VECS(dh_tv_template)
Salvatore Benedetto802c7f12016-06-22 17:49:14 +01003397 }
3398 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003399 .alg = "digest_null",
3400 .test = alg_test_null,
3401 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003402 .alg = "drbg_nopr_ctr_aes128",
3403 .test = alg_test_drbg,
3404 .fips_allowed = 1,
3405 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003406 .drbg = __VECS(drbg_nopr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003407 }
3408 }, {
3409 .alg = "drbg_nopr_ctr_aes192",
3410 .test = alg_test_drbg,
3411 .fips_allowed = 1,
3412 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003413 .drbg = __VECS(drbg_nopr_ctr_aes192_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003414 }
3415 }, {
3416 .alg = "drbg_nopr_ctr_aes256",
3417 .test = alg_test_drbg,
3418 .fips_allowed = 1,
3419 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003420 .drbg = __VECS(drbg_nopr_ctr_aes256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003421 }
3422 }, {
3423 /*
3424 * There is no need to specifically test the DRBG with every
3425 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
3426 */
3427 .alg = "drbg_nopr_hmac_sha1",
3428 .fips_allowed = 1,
3429 .test = alg_test_null,
3430 }, {
3431 .alg = "drbg_nopr_hmac_sha256",
3432 .test = alg_test_drbg,
3433 .fips_allowed = 1,
3434 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003435 .drbg = __VECS(drbg_nopr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003436 }
3437 }, {
3438 /* covered by drbg_nopr_hmac_sha256 test */
3439 .alg = "drbg_nopr_hmac_sha384",
3440 .fips_allowed = 1,
3441 .test = alg_test_null,
3442 }, {
3443 .alg = "drbg_nopr_hmac_sha512",
3444 .test = alg_test_null,
3445 .fips_allowed = 1,
3446 }, {
3447 .alg = "drbg_nopr_sha1",
3448 .fips_allowed = 1,
3449 .test = alg_test_null,
3450 }, {
3451 .alg = "drbg_nopr_sha256",
3452 .test = alg_test_drbg,
3453 .fips_allowed = 1,
3454 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003455 .drbg = __VECS(drbg_nopr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003456 }
3457 }, {
3458 /* covered by drbg_nopr_sha256 test */
3459 .alg = "drbg_nopr_sha384",
3460 .fips_allowed = 1,
3461 .test = alg_test_null,
3462 }, {
3463 .alg = "drbg_nopr_sha512",
3464 .fips_allowed = 1,
3465 .test = alg_test_null,
3466 }, {
3467 .alg = "drbg_pr_ctr_aes128",
3468 .test = alg_test_drbg,
3469 .fips_allowed = 1,
3470 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003471 .drbg = __VECS(drbg_pr_ctr_aes128_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003472 }
3473 }, {
3474 /* covered by drbg_pr_ctr_aes128 test */
3475 .alg = "drbg_pr_ctr_aes192",
3476 .fips_allowed = 1,
3477 .test = alg_test_null,
3478 }, {
3479 .alg = "drbg_pr_ctr_aes256",
3480 .fips_allowed = 1,
3481 .test = alg_test_null,
3482 }, {
3483 .alg = "drbg_pr_hmac_sha1",
3484 .fips_allowed = 1,
3485 .test = alg_test_null,
3486 }, {
3487 .alg = "drbg_pr_hmac_sha256",
3488 .test = alg_test_drbg,
3489 .fips_allowed = 1,
3490 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003491 .drbg = __VECS(drbg_pr_hmac_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003492 }
3493 }, {
3494 /* covered by drbg_pr_hmac_sha256 test */
3495 .alg = "drbg_pr_hmac_sha384",
3496 .fips_allowed = 1,
3497 .test = alg_test_null,
3498 }, {
3499 .alg = "drbg_pr_hmac_sha512",
3500 .test = alg_test_null,
3501 .fips_allowed = 1,
3502 }, {
3503 .alg = "drbg_pr_sha1",
3504 .fips_allowed = 1,
3505 .test = alg_test_null,
3506 }, {
3507 .alg = "drbg_pr_sha256",
3508 .test = alg_test_drbg,
3509 .fips_allowed = 1,
3510 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003511 .drbg = __VECS(drbg_pr_sha256_tv_template)
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02003512 }
3513 }, {
3514 /* covered by drbg_pr_sha256 test */
3515 .alg = "drbg_pr_sha384",
3516 .fips_allowed = 1,
3517 .test = alg_test_null,
3518 }, {
3519 .alg = "drbg_pr_sha512",
3520 .fips_allowed = 1,
3521 .test = alg_test_null,
3522 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003523 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003524 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003525 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003526 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003527 .cipher = __VECS(aes_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003528 }
3529 }, {
3530 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003531 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003532 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003533 .cipher = __VECS(anubis_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003534 }
3535 }, {
3536 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003537 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003538 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003539 .cipher = __VECS(arc4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003540 }
3541 }, {
3542 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003543 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003544 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003545 .cipher = __VECS(bf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003546 }
3547 }, {
3548 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003549 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003550 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003551 .cipher = __VECS(camellia_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003552 }
3553 }, {
3554 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003555 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003556 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003557 .cipher = __VECS(cast5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003558 }
3559 }, {
3560 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003561 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003562 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003563 .cipher = __VECS(cast6_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003564 }
3565 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003566 .alg = "ecb(cipher_null)",
3567 .test = alg_test_null,
Milan Broz6175ca22017-04-21 13:03:06 +02003568 .fips_allowed = 1,
Jussi Kivilinnae4483702013-04-07 16:43:56 +03003569 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003570 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003571 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003572 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003573 .cipher = __VECS(des_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003574 }
3575 }, {
3576 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003577 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003578 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003579 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003580 .cipher = __VECS(des3_ede_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003581 }
3582 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003583 .alg = "ecb(fcrypt)",
3584 .test = alg_test_skcipher,
3585 .suite = {
3586 .cipher = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003587 .vecs = fcrypt_pcbc_tv_template,
3588 .count = 1
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02003589 }
3590 }
3591 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003592 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003593 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003594 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003595 .cipher = __VECS(khazad_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003596 }
3597 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01003598 /* Same as ecb(aes) except the key is stored in
3599 * hardware secure memory which we reference by index
3600 */
3601 .alg = "ecb(paes)",
3602 .test = alg_test_null,
3603 .fips_allowed = 1,
3604 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003605 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003606 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003607 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003608 .cipher = __VECS(seed_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003609 }
3610 }, {
3611 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003612 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003613 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003614 .cipher = __VECS(serpent_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003615 }
3616 }, {
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00003617 .alg = "ecb(sm4)",
3618 .test = alg_test_skcipher,
3619 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003620 .cipher = __VECS(sm4_tv_template)
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00003621 }
3622 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003623 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003624 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003625 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003626 .cipher = __VECS(tea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003627 }
3628 }, {
3629 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003630 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003631 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003632 .cipher = __VECS(tnepres_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003633 }
3634 }, {
3635 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003636 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003637 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003638 .cipher = __VECS(tf_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003639 }
3640 }, {
3641 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003642 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003643 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003644 .cipher = __VECS(xeta_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003645 }
3646 }, {
3647 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003648 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003649 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003650 .cipher = __VECS(xtea_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003651 }
3652 }, {
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003653 .alg = "ecdh",
3654 .test = alg_test_kpp,
3655 .fips_allowed = 1,
3656 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003657 .kpp = __VECS(ecdh_tv_template)
Salvatore Benedetto3c4b2392016-06-22 17:49:15 +01003658 }
3659 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003660 .alg = "gcm(aes)",
3661 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003662 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003663 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003664 .aead = __VECS(aes_gcm_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003665 }
3666 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003667 .alg = "ghash",
3668 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003669 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003670 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003671 .hash = __VECS(ghash_tv_template)
Youquan, Song507069c2009-11-23 20:23:04 +08003672 }
3673 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003674 .alg = "hmac(md5)",
3675 .test = alg_test_hash,
3676 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003677 .hash = __VECS(hmac_md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003678 }
3679 }, {
3680 .alg = "hmac(rmd128)",
3681 .test = alg_test_hash,
3682 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003683 .hash = __VECS(hmac_rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003684 }
3685 }, {
3686 .alg = "hmac(rmd160)",
3687 .test = alg_test_hash,
3688 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003689 .hash = __VECS(hmac_rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003690 }
3691 }, {
3692 .alg = "hmac(sha1)",
3693 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003694 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003695 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003696 .hash = __VECS(hmac_sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003697 }
3698 }, {
3699 .alg = "hmac(sha224)",
3700 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003701 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003702 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003703 .hash = __VECS(hmac_sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003704 }
3705 }, {
3706 .alg = "hmac(sha256)",
3707 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003708 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003709 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003710 .hash = __VECS(hmac_sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003711 }
3712 }, {
raveendra padasalagi98eca722016-07-01 11:16:54 +05303713 .alg = "hmac(sha3-224)",
3714 .test = alg_test_hash,
3715 .fips_allowed = 1,
3716 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003717 .hash = __VECS(hmac_sha3_224_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303718 }
3719 }, {
3720 .alg = "hmac(sha3-256)",
3721 .test = alg_test_hash,
3722 .fips_allowed = 1,
3723 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003724 .hash = __VECS(hmac_sha3_256_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303725 }
3726 }, {
3727 .alg = "hmac(sha3-384)",
3728 .test = alg_test_hash,
3729 .fips_allowed = 1,
3730 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003731 .hash = __VECS(hmac_sha3_384_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303732 }
3733 }, {
3734 .alg = "hmac(sha3-512)",
3735 .test = alg_test_hash,
3736 .fips_allowed = 1,
3737 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003738 .hash = __VECS(hmac_sha3_512_tv_template)
raveendra padasalagi98eca722016-07-01 11:16:54 +05303739 }
3740 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003741 .alg = "hmac(sha384)",
3742 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003743 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003744 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003745 .hash = __VECS(hmac_sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003746 }
3747 }, {
3748 .alg = "hmac(sha512)",
3749 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003750 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003751 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003752 .hash = __VECS(hmac_sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003753 }
3754 }, {
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03003755 .alg = "hmac(streebog256)",
3756 .test = alg_test_hash,
3757 .suite = {
3758 .hash = __VECS(hmac_streebog256_tv_template)
3759 }
3760 }, {
3761 .alg = "hmac(streebog512)",
3762 .test = alg_test_hash,
3763 .suite = {
3764 .hash = __VECS(hmac_streebog512_tv_template)
3765 }
3766 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003767 .alg = "jitterentropy_rng",
3768 .fips_allowed = 1,
3769 .test = alg_test_null,
3770 }, {
Stephan Mueller35351982015-09-21 20:59:56 +02003771 .alg = "kw(aes)",
3772 .test = alg_test_skcipher,
3773 .fips_allowed = 1,
3774 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003775 .cipher = __VECS(aes_kw_tv_template)
Stephan Mueller35351982015-09-21 20:59:56 +02003776 }
3777 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003778 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003779 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003780 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003781 .cipher = __VECS(aes_lrw_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003782 }
3783 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003784 .alg = "lrw(camellia)",
3785 .test = alg_test_skcipher,
3786 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003787 .cipher = __VECS(camellia_lrw_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02003788 }
3789 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003790 .alg = "lrw(cast6)",
3791 .test = alg_test_skcipher,
3792 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003793 .cipher = __VECS(cast6_lrw_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003794 }
3795 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003796 .alg = "lrw(serpent)",
3797 .test = alg_test_skcipher,
3798 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003799 .cipher = __VECS(serpent_lrw_tv_template)
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003800 }
3801 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003802 .alg = "lrw(twofish)",
3803 .test = alg_test_skcipher,
3804 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003805 .cipher = __VECS(tf_lrw_tv_template)
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003806 }
3807 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003808 .alg = "lz4",
3809 .test = alg_test_comp,
3810 .fips_allowed = 1,
3811 .suite = {
3812 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003813 .comp = __VECS(lz4_comp_tv_template),
3814 .decomp = __VECS(lz4_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003815 }
3816 }
3817 }, {
3818 .alg = "lz4hc",
3819 .test = alg_test_comp,
3820 .fips_allowed = 1,
3821 .suite = {
3822 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003823 .comp = __VECS(lz4hc_comp_tv_template),
3824 .decomp = __VECS(lz4hc_decomp_tv_template)
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003825 }
3826 }
3827 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003828 .alg = "lzo",
3829 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003830 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003831 .suite = {
3832 .comp = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003833 .comp = __VECS(lzo_comp_tv_template),
3834 .decomp = __VECS(lzo_decomp_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003835 }
3836 }
3837 }, {
3838 .alg = "md4",
3839 .test = alg_test_hash,
3840 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003841 .hash = __VECS(md4_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003842 }
3843 }, {
3844 .alg = "md5",
3845 .test = alg_test_hash,
3846 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003847 .hash = __VECS(md5_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003848 }
3849 }, {
3850 .alg = "michael_mic",
3851 .test = alg_test_hash,
3852 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003853 .hash = __VECS(michael_mic_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003854 }
3855 }, {
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003856 .alg = "morus1280",
3857 .test = alg_test_aead,
3858 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003859 .aead = __VECS(morus1280_tv_template)
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003860 }
3861 }, {
3862 .alg = "morus640",
3863 .test = alg_test_aead,
3864 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003865 .aead = __VECS(morus640_tv_template)
Ondrej Mosnacek4feb4c52018-05-11 14:19:10 +02003866 }
3867 }, {
Eric Biggers26609a22018-11-16 17:26:29 -08003868 .alg = "nhpoly1305",
3869 .test = alg_test_hash,
3870 .suite = {
3871 .hash = __VECS(nhpoly1305_tv_template)
3872 }
3873 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003874 .alg = "ofb(aes)",
3875 .test = alg_test_skcipher,
3876 .fips_allowed = 1,
3877 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003878 .cipher = __VECS(aes_ofb_tv_template)
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003879 }
3880 }, {
Gilad Ben-Yossefa794d8d2018-04-23 08:25:14 +01003881 /* Same as ofb(aes) except the key is stored in
3882 * hardware secure memory which we reference by index
3883 */
3884 .alg = "ofb(paes)",
3885 .test = alg_test_null,
3886 .fips_allowed = 1,
3887 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003888 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003889 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003890 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003891 .cipher = __VECS(fcrypt_pcbc_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003892 }
3893 }, {
Stephan Mueller12071072017-06-12 23:27:51 +02003894 .alg = "pkcs1pad(rsa,sha224)",
3895 .test = alg_test_null,
3896 .fips_allowed = 1,
3897 }, {
3898 .alg = "pkcs1pad(rsa,sha256)",
3899 .test = alg_test_akcipher,
3900 .fips_allowed = 1,
3901 .suite = {
3902 .akcipher = __VECS(pkcs1pad_rsa_tv_template)
3903 }
3904 }, {
3905 .alg = "pkcs1pad(rsa,sha384)",
3906 .test = alg_test_null,
3907 .fips_allowed = 1,
3908 }, {
3909 .alg = "pkcs1pad(rsa,sha512)",
3910 .test = alg_test_null,
3911 .fips_allowed = 1,
3912 }, {
Martin Willieee9dc62015-06-01 13:43:59 +02003913 .alg = "poly1305",
3914 .test = alg_test_hash,
3915 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003916 .hash = __VECS(poly1305_tv_template)
Martin Willieee9dc62015-06-01 13:43:59 +02003917 }
3918 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003919 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003920 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003921 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003922 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003923 .cipher = __VECS(aes_ctr_rfc3686_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003924 }
3925 }, {
Herbert Xu3f31a742015-07-09 07:17:34 +08003926 .alg = "rfc4106(gcm(aes))",
Adrian Hoban69435b92010-11-04 15:02:04 -04003927 .test = alg_test_aead,
Jarod Wilsondb71f29a2015-01-23 12:42:15 -05003928 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003929 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003930 .aead = __VECS(aes_gcm_rfc4106_tv_template)
Adrian Hoban69435b92010-11-04 15:02:04 -04003931 }
3932 }, {
Herbert Xu544c4362015-07-14 16:53:22 +08003933 .alg = "rfc4309(ccm(aes))",
Jarod Wilson5d667322009-05-04 19:23:40 +08003934 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003935 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003936 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003937 .aead = __VECS(aes_ccm_rfc4309_tv_template)
Jarod Wilson5d667322009-05-04 19:23:40 +08003938 }
3939 }, {
Herbert Xubb687452015-06-16 13:54:24 +08003940 .alg = "rfc4543(gcm(aes))",
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003941 .test = alg_test_aead,
3942 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003943 .aead = __VECS(aes_gcm_rfc4543_tv_template)
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003944 }
3945 }, {
Martin Williaf2b76b2015-06-01 13:44:01 +02003946 .alg = "rfc7539(chacha20,poly1305)",
3947 .test = alg_test_aead,
3948 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003949 .aead = __VECS(rfc7539_tv_template)
Martin Williaf2b76b2015-06-01 13:44:01 +02003950 }
3951 }, {
Martin Willi59007582015-06-01 13:44:03 +02003952 .alg = "rfc7539esp(chacha20,poly1305)",
3953 .test = alg_test_aead,
3954 .suite = {
Eric Biggersa0d608ee2019-01-13 15:32:28 -08003955 .aead = __VECS(rfc7539esp_tv_template)
Martin Willi59007582015-06-01 13:44:03 +02003956 }
3957 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003958 .alg = "rmd128",
3959 .test = alg_test_hash,
3960 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003961 .hash = __VECS(rmd128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003962 }
3963 }, {
3964 .alg = "rmd160",
3965 .test = alg_test_hash,
3966 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003967 .hash = __VECS(rmd160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003968 }
3969 }, {
3970 .alg = "rmd256",
3971 .test = alg_test_hash,
3972 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003973 .hash = __VECS(rmd256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003974 }
3975 }, {
3976 .alg = "rmd320",
3977 .test = alg_test_hash,
3978 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003979 .hash = __VECS(rmd320_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003980 }
3981 }, {
Tadeusz Struk946cc462015-06-16 10:31:06 -07003982 .alg = "rsa",
3983 .test = alg_test_akcipher,
3984 .fips_allowed = 1,
3985 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003986 .akcipher = __VECS(rsa_tv_template)
Tadeusz Struk946cc462015-06-16 10:31:06 -07003987 }
3988 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003989 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003990 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003991 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07003992 .cipher = __VECS(salsa20_stream_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08003993 }
3994 }, {
3995 .alg = "sha1",
3996 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003997 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003998 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00003999 .hash = __VECS(sha1_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004000 }
4001 }, {
4002 .alg = "sha224",
4003 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004004 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004005 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004006 .hash = __VECS(sha224_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004007 }
4008 }, {
4009 .alg = "sha256",
4010 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004011 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004012 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004013 .hash = __VECS(sha256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004014 }
4015 }, {
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05304016 .alg = "sha3-224",
4017 .test = alg_test_hash,
4018 .fips_allowed = 1,
4019 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004020 .hash = __VECS(sha3_224_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05304021 }
4022 }, {
4023 .alg = "sha3-256",
4024 .test = alg_test_hash,
4025 .fips_allowed = 1,
4026 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004027 .hash = __VECS(sha3_256_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05304028 }
4029 }, {
4030 .alg = "sha3-384",
4031 .test = alg_test_hash,
4032 .fips_allowed = 1,
4033 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004034 .hash = __VECS(sha3_384_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05304035 }
4036 }, {
4037 .alg = "sha3-512",
4038 .test = alg_test_hash,
4039 .fips_allowed = 1,
4040 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004041 .hash = __VECS(sha3_512_tv_template)
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05304042 }
4043 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004044 .alg = "sha384",
4045 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004046 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004047 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004048 .hash = __VECS(sha384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004049 }
4050 }, {
4051 .alg = "sha512",
4052 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10004053 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004054 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004055 .hash = __VECS(sha512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004056 }
4057 }, {
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03004058 .alg = "sm3",
4059 .test = alg_test_hash,
4060 .suite = {
4061 .hash = __VECS(sm3_tv_template)
4062 }
4063 }, {
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03004064 .alg = "streebog256",
4065 .test = alg_test_hash,
4066 .suite = {
4067 .hash = __VECS(streebog256_tv_template)
4068 }
4069 }, {
4070 .alg = "streebog512",
4071 .test = alg_test_hash,
4072 .suite = {
4073 .hash = __VECS(streebog512_tv_template)
4074 }
4075 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004076 .alg = "tgr128",
4077 .test = alg_test_hash,
4078 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004079 .hash = __VECS(tgr128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004080 }
4081 }, {
4082 .alg = "tgr160",
4083 .test = alg_test_hash,
4084 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004085 .hash = __VECS(tgr160_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004086 }
4087 }, {
4088 .alg = "tgr192",
4089 .test = alg_test_hash,
4090 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004091 .hash = __VECS(tgr192_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004092 }
4093 }, {
Eric Biggersed331ad2018-06-18 10:22:39 -07004094 .alg = "vmac64(aes)",
4095 .test = alg_test_hash,
4096 .suite = {
4097 .hash = __VECS(vmac64_aes_tv_template)
4098 }
4099 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004100 .alg = "wp256",
4101 .test = alg_test_hash,
4102 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004103 .hash = __VECS(wp256_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004104 }
4105 }, {
4106 .alg = "wp384",
4107 .test = alg_test_hash,
4108 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004109 .hash = __VECS(wp384_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004110 }
4111 }, {
4112 .alg = "wp512",
4113 .test = alg_test_hash,
4114 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004115 .hash = __VECS(wp512_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004116 }
4117 }, {
4118 .alg = "xcbc(aes)",
4119 .test = alg_test_hash,
4120 .suite = {
Ard Biesheuvel21c8e722017-01-12 13:40:39 +00004121 .hash = __VECS(aes_xcbc128_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004122 }
4123 }, {
Eric Biggersaa762402018-11-16 17:26:22 -08004124 .alg = "xchacha12",
4125 .test = alg_test_skcipher,
4126 .suite = {
4127 .cipher = __VECS(xchacha12_tv_template)
4128 },
4129 }, {
Eric Biggersde61d7a2018-11-16 17:26:20 -08004130 .alg = "xchacha20",
4131 .test = alg_test_skcipher,
4132 .suite = {
4133 .cipher = __VECS(xchacha20_tv_template)
4134 },
4135 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08004136 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004137 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11004138 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08004139 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004140 .cipher = __VECS(aes_xts_tv_template)
Herbert Xuda7f0332008-07-31 17:08:25 +08004141 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08004142 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02004143 .alg = "xts(camellia)",
4144 .test = alg_test_skcipher,
4145 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004146 .cipher = __VECS(camellia_xts_tv_template)
Jussi Kivilinna08406052012-03-05 20:26:21 +02004147 }
4148 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02004149 .alg = "xts(cast6)",
4150 .test = alg_test_skcipher,
4151 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004152 .cipher = __VECS(cast6_xts_tv_template)
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02004153 }
4154 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01004155 /* Same as xts(aes) except the key is stored in
4156 * hardware secure memory which we reference by index
4157 */
4158 .alg = "xts(paes)",
4159 .test = alg_test_null,
4160 .fips_allowed = 1,
4161 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03004162 .alg = "xts(serpent)",
4163 .test = alg_test_skcipher,
4164 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004165 .cipher = __VECS(serpent_xts_tv_template)
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03004166 }
4167 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03004168 .alg = "xts(twofish)",
4169 .test = alg_test_skcipher,
4170 .suite = {
Eric Biggers92a4c9f2018-05-20 22:50:29 -07004171 .cipher = __VECS(tf_xts_tv_template)
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03004172 }
Giovanni Cabiddua368f432017-04-21 21:54:30 +01004173 }, {
Gilad Ben-Yossef15f47ce2018-05-11 09:04:06 +01004174 .alg = "xts4096(paes)",
4175 .test = alg_test_null,
4176 .fips_allowed = 1,
4177 }, {
4178 .alg = "xts512(paes)",
4179 .test = alg_test_null,
4180 .fips_allowed = 1,
4181 }, {
Giovanni Cabiddua368f432017-04-21 21:54:30 +01004182 .alg = "zlib-deflate",
4183 .test = alg_test_comp,
4184 .fips_allowed = 1,
4185 .suite = {
4186 .comp = {
4187 .comp = __VECS(zlib_deflate_comp_tv_template),
4188 .decomp = __VECS(zlib_deflate_decomp_tv_template)
4189 }
4190 }
Nick Terrelld28fc3d2018-03-30 12:14:53 -07004191 }, {
4192 .alg = "zstd",
4193 .test = alg_test_comp,
4194 .fips_allowed = 1,
4195 .suite = {
4196 .comp = {
4197 .comp = __VECS(zstd_comp_tv_template),
4198 .decomp = __VECS(zstd_decomp_tv_template)
4199 }
4200 }
Herbert Xuda7f0332008-07-31 17:08:25 +08004201 }
4202};
4203
Eric Biggers3f47a032019-01-31 23:51:43 -08004204static void alg_check_test_descs_order(void)
Jussi Kivilinna57147582013-06-13 17:37:40 +03004205{
4206 int i;
4207
Jussi Kivilinna57147582013-06-13 17:37:40 +03004208 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
4209 int diff = strcmp(alg_test_descs[i - 1].alg,
4210 alg_test_descs[i].alg);
4211
4212 if (WARN_ON(diff > 0)) {
4213 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
4214 alg_test_descs[i - 1].alg,
4215 alg_test_descs[i].alg);
4216 }
4217
4218 if (WARN_ON(diff == 0)) {
4219 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
4220 alg_test_descs[i].alg);
4221 }
4222 }
4223}
4224
Eric Biggers3f47a032019-01-31 23:51:43 -08004225static void alg_check_testvec_configs(void)
4226{
4227}
4228
4229static void testmgr_onetime_init(void)
4230{
4231 alg_check_test_descs_order();
4232 alg_check_testvec_configs();
Eric Biggers5b2706a2019-01-31 23:51:44 -08004233
4234#ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
4235 pr_warn("alg: extra crypto tests enabled. This is intended for developer use only.\n");
4236#endif
Eric Biggers3f47a032019-01-31 23:51:43 -08004237}
4238
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004239static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08004240{
4241 int start = 0;
4242 int end = ARRAY_SIZE(alg_test_descs);
4243
4244 while (start < end) {
4245 int i = (start + end) / 2;
4246 int diff = strcmp(alg_test_descs[i].alg, alg);
4247
4248 if (diff > 0) {
4249 end = i;
4250 continue;
4251 }
4252
4253 if (diff < 0) {
4254 start = i + 1;
4255 continue;
4256 }
4257
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004258 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08004259 }
4260
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004261 return -1;
4262}
4263
4264int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
4265{
4266 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08004267 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08004268 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004269
Richard W.M. Jones9e5c9fe2016-05-03 10:00:17 +01004270 if (!fips_enabled && notests) {
4271 printk_once(KERN_INFO "alg: self-tests disabled\n");
4272 return 0;
4273 }
4274
Eric Biggers3f47a032019-01-31 23:51:43 -08004275 DO_ONCE(testmgr_onetime_init);
Jussi Kivilinna57147582013-06-13 17:37:40 +03004276
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004277 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
4278 char nalg[CRYPTO_MAX_ALG_NAME];
4279
4280 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
4281 sizeof(nalg))
4282 return -ENAMETOOLONG;
4283
4284 i = alg_find_test(nalg);
4285 if (i < 0)
4286 goto notest;
4287
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004288 if (fips_enabled && !alg_test_descs[i].fips_allowed)
4289 goto non_fips_alg;
4290
Jarod Wilson941fb322009-05-04 19:49:23 +08004291 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
4292 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004293 }
4294
4295 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08004296 j = alg_find_test(driver);
4297 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004298 goto notest;
4299
Herbert Xua68f6612009-07-02 16:32:12 +08004300 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
4301 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004302 goto non_fips_alg;
4303
Herbert Xua68f6612009-07-02 16:32:12 +08004304 rc = 0;
4305 if (i >= 0)
4306 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
4307 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03004308 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08004309 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
4310 type, mask);
4311
Jarod Wilson941fb322009-05-04 19:49:23 +08004312test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08004313 if (fips_enabled && rc)
4314 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
4315
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004316 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09004317 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08004318
Neil Hormand12d6b62008-10-12 20:36:51 +08004319 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10004320
4321notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08004322 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
4323 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10004324non_fips_alg:
4325 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08004326}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004327
Herbert Xu326a6342010-08-06 09:40:28 +08004328#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10004329
Herbert Xuda7f0332008-07-31 17:08:25 +08004330EXPORT_SYMBOL_GPL(alg_test);