xref: /openbmc/linux/crypto/testmgr.c (revision eda69b0c)
1da7f033dSHerbert Xu /*
2da7f033dSHerbert Xu  * Algorithm testing framework and tests.
3da7f033dSHerbert Xu  *
4da7f033dSHerbert Xu  * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
5da7f033dSHerbert Xu  * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
6da7f033dSHerbert Xu  * Copyright (c) 2007 Nokia Siemens Networks
7da7f033dSHerbert Xu  * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
83f47a03dSEric Biggers  * Copyright (c) 2019 Google LLC
9da7f033dSHerbert Xu  *
1069435b94SAdrian Hoban  * Updated RFC4106 AES-GCM testing.
1169435b94SAdrian Hoban  *    Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
1269435b94SAdrian Hoban  *             Adrian Hoban <adrian.hoban@intel.com>
1369435b94SAdrian Hoban  *             Gabriele Paoloni <gabriele.paoloni@intel.com>
1469435b94SAdrian Hoban  *             Tadeusz Struk (tadeusz.struk@intel.com)
1569435b94SAdrian Hoban  *    Copyright (c) 2010, Intel Corporation.
1669435b94SAdrian Hoban  *
17da7f033dSHerbert Xu  * This program is free software; you can redistribute it and/or modify it
18da7f033dSHerbert Xu  * under the terms of the GNU General Public License as published by the Free
19da7f033dSHerbert Xu  * Software Foundation; either version 2 of the License, or (at your option)
20da7f033dSHerbert Xu  * any later version.
21da7f033dSHerbert Xu  *
22da7f033dSHerbert Xu  */
23da7f033dSHerbert Xu 
241ce33115SHerbert Xu #include <crypto/aead.h>
25da7f033dSHerbert Xu #include <crypto/hash.h>
2612773d93SHerbert Xu #include <crypto/skcipher.h>
27da7f033dSHerbert Xu #include <linux/err.h>
281c41b882SHerbert Xu #include <linux/fips.h>
29da7f033dSHerbert Xu #include <linux/module.h>
303f47a03dSEric Biggers #include <linux/once.h>
3125f9dddbSEric Biggers #include <linux/random.h>
32da7f033dSHerbert Xu #include <linux/scatterlist.h>
33da7f033dSHerbert Xu #include <linux/slab.h>
34da7f033dSHerbert Xu #include <linux/string.h>
357647d6ceSJarod Wilson #include <crypto/rng.h>
3664d1cdfbSStephan Mueller #include <crypto/drbg.h>
37946cc463STadeusz Struk #include <crypto/akcipher.h>
38802c7f1cSSalvatore Benedetto #include <crypto/kpp.h>
39d7db7a88SGiovanni Cabiddu #include <crypto/acompress.h>
40b55e1a39SEric Biggers #include <crypto/internal/simd.h>
41da7f033dSHerbert Xu 
42da7f033dSHerbert Xu #include "internal.h"
430b767f96SAlexander Shishkin 
449e5c9fe4SRichard W.M. Jones static bool notests;
459e5c9fe4SRichard W.M. Jones module_param(notests, bool, 0644);
469e5c9fe4SRichard W.M. Jones MODULE_PARM_DESC(notests, "disable crypto self-tests");
479e5c9fe4SRichard W.M. Jones 
48eda69b0cSEric Biggers static bool panic_on_fail;
49eda69b0cSEric Biggers module_param(panic_on_fail, bool, 0444);
50eda69b0cSEric Biggers 
515b2706a4SEric Biggers #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
525b2706a4SEric Biggers static bool noextratests;
535b2706a4SEric Biggers module_param(noextratests, bool, 0644);
545b2706a4SEric Biggers MODULE_PARM_DESC(noextratests, "disable expensive crypto self-tests");
555b2706a4SEric Biggers 
565b2706a4SEric Biggers static unsigned int fuzz_iterations = 100;
575b2706a4SEric Biggers module_param(fuzz_iterations, uint, 0644);
585b2706a4SEric Biggers MODULE_PARM_DESC(fuzz_iterations, "number of fuzz test iterations");
59b55e1a39SEric Biggers 
60b55e1a39SEric Biggers DEFINE_PER_CPU(bool, crypto_simd_disabled_for_test);
61b55e1a39SEric Biggers EXPORT_PER_CPU_SYMBOL_GPL(crypto_simd_disabled_for_test);
625b2706a4SEric Biggers #endif
635b2706a4SEric Biggers 
64326a6346SHerbert Xu #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
650b767f96SAlexander Shishkin 
660b767f96SAlexander Shishkin /* a perfect nop */
670b767f96SAlexander Shishkin int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
680b767f96SAlexander Shishkin {
690b767f96SAlexander Shishkin 	return 0;
700b767f96SAlexander Shishkin }
710b767f96SAlexander Shishkin 
720b767f96SAlexander Shishkin #else
730b767f96SAlexander Shishkin 
74da7f033dSHerbert Xu #include "testmgr.h"
75da7f033dSHerbert Xu 
76da7f033dSHerbert Xu /*
77da7f033dSHerbert Xu  * Need slab memory for testing (size in number of pages).
78da7f033dSHerbert Xu  */
79da7f033dSHerbert Xu #define XBUFSIZE	8
80da7f033dSHerbert Xu 
81da7f033dSHerbert Xu /*
82da7f033dSHerbert Xu * Used by test_cipher()
83da7f033dSHerbert Xu */
84da7f033dSHerbert Xu #define ENCRYPT 1
85da7f033dSHerbert Xu #define DECRYPT 0
86da7f033dSHerbert Xu 
87da7f033dSHerbert Xu struct aead_test_suite {
88b13b1e0cSEric Biggers 	const struct aead_testvec *vecs;
89da7f033dSHerbert Xu 	unsigned int count;
90da7f033dSHerbert Xu };
91da7f033dSHerbert Xu 
92da7f033dSHerbert Xu struct cipher_test_suite {
93b13b1e0cSEric Biggers 	const struct cipher_testvec *vecs;
94da7f033dSHerbert Xu 	unsigned int count;
95da7f033dSHerbert Xu };
96da7f033dSHerbert Xu 
97da7f033dSHerbert Xu struct comp_test_suite {
98da7f033dSHerbert Xu 	struct {
99b13b1e0cSEric Biggers 		const struct comp_testvec *vecs;
100da7f033dSHerbert Xu 		unsigned int count;
101da7f033dSHerbert Xu 	} comp, decomp;
102da7f033dSHerbert Xu };
103da7f033dSHerbert Xu 
104da7f033dSHerbert Xu struct hash_test_suite {
105b13b1e0cSEric Biggers 	const struct hash_testvec *vecs;
106da7f033dSHerbert Xu 	unsigned int count;
107da7f033dSHerbert Xu };
108da7f033dSHerbert Xu 
1097647d6ceSJarod Wilson struct cprng_test_suite {
110b13b1e0cSEric Biggers 	const struct cprng_testvec *vecs;
1117647d6ceSJarod Wilson 	unsigned int count;
1127647d6ceSJarod Wilson };
1137647d6ceSJarod Wilson 
11464d1cdfbSStephan Mueller struct drbg_test_suite {
115b13b1e0cSEric Biggers 	const struct drbg_testvec *vecs;
11664d1cdfbSStephan Mueller 	unsigned int count;
11764d1cdfbSStephan Mueller };
11864d1cdfbSStephan Mueller 
119946cc463STadeusz Struk struct akcipher_test_suite {
120b13b1e0cSEric Biggers 	const struct akcipher_testvec *vecs;
121946cc463STadeusz Struk 	unsigned int count;
122946cc463STadeusz Struk };
123946cc463STadeusz Struk 
124802c7f1cSSalvatore Benedetto struct kpp_test_suite {
125b13b1e0cSEric Biggers 	const struct kpp_testvec *vecs;
126802c7f1cSSalvatore Benedetto 	unsigned int count;
127802c7f1cSSalvatore Benedetto };
128802c7f1cSSalvatore Benedetto 
129da7f033dSHerbert Xu struct alg_test_desc {
130da7f033dSHerbert Xu 	const char *alg;
131da7f033dSHerbert Xu 	int (*test)(const struct alg_test_desc *desc, const char *driver,
132da7f033dSHerbert Xu 		    u32 type, u32 mask);
133a1915d51SJarod Wilson 	int fips_allowed;	/* set if alg is allowed in fips mode */
134da7f033dSHerbert Xu 
135da7f033dSHerbert Xu 	union {
136da7f033dSHerbert Xu 		struct aead_test_suite aead;
137da7f033dSHerbert Xu 		struct cipher_test_suite cipher;
138da7f033dSHerbert Xu 		struct comp_test_suite comp;
139da7f033dSHerbert Xu 		struct hash_test_suite hash;
1407647d6ceSJarod Wilson 		struct cprng_test_suite cprng;
14164d1cdfbSStephan Mueller 		struct drbg_test_suite drbg;
142946cc463STadeusz Struk 		struct akcipher_test_suite akcipher;
143802c7f1cSSalvatore Benedetto 		struct kpp_test_suite kpp;
144da7f033dSHerbert Xu 	} suite;
145da7f033dSHerbert Xu };
146da7f033dSHerbert Xu 
147da7f033dSHerbert Xu static void hexdump(unsigned char *buf, unsigned int len)
148da7f033dSHerbert Xu {
149da7f033dSHerbert Xu 	print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
150da7f033dSHerbert Xu 			16, 1,
151da7f033dSHerbert Xu 			buf, len, false);
152da7f033dSHerbert Xu }
153da7f033dSHerbert Xu 
1543f47a03dSEric Biggers static int __testmgr_alloc_buf(char *buf[XBUFSIZE], int order)
155f8b0d4d0SHerbert Xu {
156f8b0d4d0SHerbert Xu 	int i;
157f8b0d4d0SHerbert Xu 
158f8b0d4d0SHerbert Xu 	for (i = 0; i < XBUFSIZE; i++) {
1593f47a03dSEric Biggers 		buf[i] = (char *)__get_free_pages(GFP_KERNEL, order);
160f8b0d4d0SHerbert Xu 		if (!buf[i])
161f8b0d4d0SHerbert Xu 			goto err_free_buf;
162f8b0d4d0SHerbert Xu 	}
163f8b0d4d0SHerbert Xu 
164f8b0d4d0SHerbert Xu 	return 0;
165f8b0d4d0SHerbert Xu 
166f8b0d4d0SHerbert Xu err_free_buf:
167f8b0d4d0SHerbert Xu 	while (i-- > 0)
1683f47a03dSEric Biggers 		free_pages((unsigned long)buf[i], order);
169f8b0d4d0SHerbert Xu 
170f8b0d4d0SHerbert Xu 	return -ENOMEM;
171f8b0d4d0SHerbert Xu }
172f8b0d4d0SHerbert Xu 
1733f47a03dSEric Biggers static int testmgr_alloc_buf(char *buf[XBUFSIZE])
1743f47a03dSEric Biggers {
1753f47a03dSEric Biggers 	return __testmgr_alloc_buf(buf, 0);
1763f47a03dSEric Biggers }
1773f47a03dSEric Biggers 
1783f47a03dSEric Biggers static void __testmgr_free_buf(char *buf[XBUFSIZE], int order)
179f8b0d4d0SHerbert Xu {
180f8b0d4d0SHerbert Xu 	int i;
181f8b0d4d0SHerbert Xu 
182f8b0d4d0SHerbert Xu 	for (i = 0; i < XBUFSIZE; i++)
1833f47a03dSEric Biggers 		free_pages((unsigned long)buf[i], order);
1843f47a03dSEric Biggers }
1853f47a03dSEric Biggers 
1863f47a03dSEric Biggers static void testmgr_free_buf(char *buf[XBUFSIZE])
1873f47a03dSEric Biggers {
1883f47a03dSEric Biggers 	__testmgr_free_buf(buf, 0);
1893f47a03dSEric Biggers }
1903f47a03dSEric Biggers 
1913f47a03dSEric Biggers #define TESTMGR_POISON_BYTE	0xfe
1923f47a03dSEric Biggers #define TESTMGR_POISON_LEN	16
1933f47a03dSEric Biggers 
1943f47a03dSEric Biggers static inline void testmgr_poison(void *addr, size_t len)
1953f47a03dSEric Biggers {
1963f47a03dSEric Biggers 	memset(addr, TESTMGR_POISON_BYTE, len);
1973f47a03dSEric Biggers }
1983f47a03dSEric Biggers 
1993f47a03dSEric Biggers /* Is the memory region still fully poisoned? */
2003f47a03dSEric Biggers static inline bool testmgr_is_poison(const void *addr, size_t len)
2013f47a03dSEric Biggers {
2023f47a03dSEric Biggers 	return memchr_inv(addr, TESTMGR_POISON_BYTE, len) == NULL;
2033f47a03dSEric Biggers }
2043f47a03dSEric Biggers 
2053f47a03dSEric Biggers /* flush type for hash algorithms */
2063f47a03dSEric Biggers enum flush_type {
2073f47a03dSEric Biggers 	/* merge with update of previous buffer(s) */
2083f47a03dSEric Biggers 	FLUSH_TYPE_NONE = 0,
2093f47a03dSEric Biggers 
2103f47a03dSEric Biggers 	/* update with previous buffer(s) before doing this one */
2113f47a03dSEric Biggers 	FLUSH_TYPE_FLUSH,
2123f47a03dSEric Biggers 
2133f47a03dSEric Biggers 	/* likewise, but also export and re-import the intermediate state */
2143f47a03dSEric Biggers 	FLUSH_TYPE_REIMPORT,
2153f47a03dSEric Biggers };
2163f47a03dSEric Biggers 
2173f47a03dSEric Biggers /* finalization function for hash algorithms */
2183f47a03dSEric Biggers enum finalization_type {
2193f47a03dSEric Biggers 	FINALIZATION_TYPE_FINAL,	/* use final() */
2203f47a03dSEric Biggers 	FINALIZATION_TYPE_FINUP,	/* use finup() */
2213f47a03dSEric Biggers 	FINALIZATION_TYPE_DIGEST,	/* use digest() */
2223f47a03dSEric Biggers };
2233f47a03dSEric Biggers 
2243f47a03dSEric Biggers #define TEST_SG_TOTAL	10000
2253f47a03dSEric Biggers 
2263f47a03dSEric Biggers /**
2273f47a03dSEric Biggers  * struct test_sg_division - description of a scatterlist entry
2283f47a03dSEric Biggers  *
2293f47a03dSEric Biggers  * This struct describes one entry of a scatterlist being constructed to check a
2303f47a03dSEric Biggers  * crypto test vector.
2313f47a03dSEric Biggers  *
2323f47a03dSEric Biggers  * @proportion_of_total: length of this chunk relative to the total length,
2333f47a03dSEric Biggers  *			 given as a proportion out of TEST_SG_TOTAL so that it
2343f47a03dSEric Biggers  *			 scales to fit any test vector
2353f47a03dSEric Biggers  * @offset: byte offset into a 2-page buffer at which this chunk will start
2363f47a03dSEric Biggers  * @offset_relative_to_alignmask: if true, add the algorithm's alignmask to the
2373f47a03dSEric Biggers  *				  @offset
2383f47a03dSEric Biggers  * @flush_type: for hashes, whether an update() should be done now vs.
2393f47a03dSEric Biggers  *		continuing to accumulate data
2406570737cSEric Biggers  * @nosimd: if doing the pending update(), do it with SIMD disabled?
2413f47a03dSEric Biggers  */
2423f47a03dSEric Biggers struct test_sg_division {
2433f47a03dSEric Biggers 	unsigned int proportion_of_total;
2443f47a03dSEric Biggers 	unsigned int offset;
2453f47a03dSEric Biggers 	bool offset_relative_to_alignmask;
2463f47a03dSEric Biggers 	enum flush_type flush_type;
2476570737cSEric Biggers 	bool nosimd;
2483f47a03dSEric Biggers };
2493f47a03dSEric Biggers 
2503f47a03dSEric Biggers /**
2513f47a03dSEric Biggers  * struct testvec_config - configuration for testing a crypto test vector
2523f47a03dSEric Biggers  *
2533f47a03dSEric Biggers  * This struct describes the data layout and other parameters with which each
2543f47a03dSEric Biggers  * crypto test vector can be tested.
2553f47a03dSEric Biggers  *
2563f47a03dSEric Biggers  * @name: name of this config, logged for debugging purposes if a test fails
2573f47a03dSEric Biggers  * @inplace: operate on the data in-place, if applicable for the algorithm type?
2583f47a03dSEric Biggers  * @req_flags: extra request_flags, e.g. CRYPTO_TFM_REQ_MAY_SLEEP
2593f47a03dSEric Biggers  * @src_divs: description of how to arrange the source scatterlist
2603f47a03dSEric Biggers  * @dst_divs: description of how to arrange the dst scatterlist, if applicable
2613f47a03dSEric Biggers  *	      for the algorithm type.  Defaults to @src_divs if unset.
2623f47a03dSEric Biggers  * @iv_offset: misalignment of the IV in the range [0..MAX_ALGAPI_ALIGNMASK+1],
2633f47a03dSEric Biggers  *	       where 0 is aligned to a 2*(MAX_ALGAPI_ALIGNMASK+1) byte boundary
2643f47a03dSEric Biggers  * @iv_offset_relative_to_alignmask: if true, add the algorithm's alignmask to
2653f47a03dSEric Biggers  *				     the @iv_offset
2663f47a03dSEric Biggers  * @finalization_type: what finalization function to use for hashes
2676570737cSEric Biggers  * @nosimd: execute with SIMD disabled?  Requires !CRYPTO_TFM_REQ_MAY_SLEEP.
2683f47a03dSEric Biggers  */
2693f47a03dSEric Biggers struct testvec_config {
2703f47a03dSEric Biggers 	const char *name;
2713f47a03dSEric Biggers 	bool inplace;
2723f47a03dSEric Biggers 	u32 req_flags;
2733f47a03dSEric Biggers 	struct test_sg_division src_divs[XBUFSIZE];
2743f47a03dSEric Biggers 	struct test_sg_division dst_divs[XBUFSIZE];
2753f47a03dSEric Biggers 	unsigned int iv_offset;
2763f47a03dSEric Biggers 	bool iv_offset_relative_to_alignmask;
2773f47a03dSEric Biggers 	enum finalization_type finalization_type;
2786570737cSEric Biggers 	bool nosimd;
2793f47a03dSEric Biggers };
2803f47a03dSEric Biggers 
2813f47a03dSEric Biggers #define TESTVEC_CONFIG_NAMELEN	192
2823f47a03dSEric Biggers 
2834e7babbaSEric Biggers /*
2844e7babbaSEric Biggers  * The following are the lists of testvec_configs to test for each algorithm
2854e7babbaSEric Biggers  * type when the basic crypto self-tests are enabled, i.e. when
2864e7babbaSEric Biggers  * CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is unset.  They aim to provide good test
2874e7babbaSEric Biggers  * coverage, while keeping the test time much shorter than the full fuzz tests
2884e7babbaSEric Biggers  * so that the basic tests can be enabled in a wider range of circumstances.
2894e7babbaSEric Biggers  */
2904e7babbaSEric Biggers 
2914e7babbaSEric Biggers /* Configs for skciphers and aeads */
2924e7babbaSEric Biggers static const struct testvec_config default_cipher_testvec_configs[] = {
2934e7babbaSEric Biggers 	{
2944e7babbaSEric Biggers 		.name = "in-place",
2954e7babbaSEric Biggers 		.inplace = true,
2964e7babbaSEric Biggers 		.src_divs = { { .proportion_of_total = 10000 } },
2974e7babbaSEric Biggers 	}, {
2984e7babbaSEric Biggers 		.name = "out-of-place",
2994e7babbaSEric Biggers 		.src_divs = { { .proportion_of_total = 10000 } },
3004e7babbaSEric Biggers 	}, {
3014e7babbaSEric Biggers 		.name = "unaligned buffer, offset=1",
3024e7babbaSEric Biggers 		.src_divs = { { .proportion_of_total = 10000, .offset = 1 } },
3034e7babbaSEric Biggers 		.iv_offset = 1,
3044e7babbaSEric Biggers 	}, {
3054e7babbaSEric Biggers 		.name = "buffer aligned only to alignmask",
3064e7babbaSEric Biggers 		.src_divs = {
3074e7babbaSEric Biggers 			{
3084e7babbaSEric Biggers 				.proportion_of_total = 10000,
3094e7babbaSEric Biggers 				.offset = 1,
3104e7babbaSEric Biggers 				.offset_relative_to_alignmask = true,
3114e7babbaSEric Biggers 			},
3124e7babbaSEric Biggers 		},
3134e7babbaSEric Biggers 		.iv_offset = 1,
3144e7babbaSEric Biggers 		.iv_offset_relative_to_alignmask = true,
3154e7babbaSEric Biggers 	}, {
3164e7babbaSEric Biggers 		.name = "two even aligned splits",
3174e7babbaSEric Biggers 		.src_divs = {
3184e7babbaSEric Biggers 			{ .proportion_of_total = 5000 },
3194e7babbaSEric Biggers 			{ .proportion_of_total = 5000 },
3204e7babbaSEric Biggers 		},
3214e7babbaSEric Biggers 	}, {
3224e7babbaSEric Biggers 		.name = "uneven misaligned splits, may sleep",
3234e7babbaSEric Biggers 		.req_flags = CRYPTO_TFM_REQ_MAY_SLEEP,
3244e7babbaSEric Biggers 		.src_divs = {
3254e7babbaSEric Biggers 			{ .proportion_of_total = 1900, .offset = 33 },
3264e7babbaSEric Biggers 			{ .proportion_of_total = 3300, .offset = 7  },
3274e7babbaSEric Biggers 			{ .proportion_of_total = 4800, .offset = 18 },
3284e7babbaSEric Biggers 		},
3294e7babbaSEric Biggers 		.iv_offset = 3,
3304e7babbaSEric Biggers 	}, {
3314e7babbaSEric Biggers 		.name = "misaligned splits crossing pages, inplace",
3324e7babbaSEric Biggers 		.inplace = true,
3334e7babbaSEric Biggers 		.src_divs = {
3344e7babbaSEric Biggers 			{
3354e7babbaSEric Biggers 				.proportion_of_total = 7500,
3364e7babbaSEric Biggers 				.offset = PAGE_SIZE - 32
3374e7babbaSEric Biggers 			}, {
3384e7babbaSEric Biggers 				.proportion_of_total = 2500,
3394e7babbaSEric Biggers 				.offset = PAGE_SIZE - 7
3404e7babbaSEric Biggers 			},
3414e7babbaSEric Biggers 		},
3424e7babbaSEric Biggers 	}
3434e7babbaSEric Biggers };
3444e7babbaSEric Biggers 
3454cc2dcf9SEric Biggers static const struct testvec_config default_hash_testvec_configs[] = {
3464cc2dcf9SEric Biggers 	{
3474cc2dcf9SEric Biggers 		.name = "init+update+final aligned buffer",
3484cc2dcf9SEric Biggers 		.src_divs = { { .proportion_of_total = 10000 } },
3494cc2dcf9SEric Biggers 		.finalization_type = FINALIZATION_TYPE_FINAL,
3504cc2dcf9SEric Biggers 	}, {
3514cc2dcf9SEric Biggers 		.name = "init+finup aligned buffer",
3524cc2dcf9SEric Biggers 		.src_divs = { { .proportion_of_total = 10000 } },
3534cc2dcf9SEric Biggers 		.finalization_type = FINALIZATION_TYPE_FINUP,
3544cc2dcf9SEric Biggers 	}, {
3554cc2dcf9SEric Biggers 		.name = "digest aligned buffer",
3564cc2dcf9SEric Biggers 		.src_divs = { { .proportion_of_total = 10000 } },
3574cc2dcf9SEric Biggers 		.finalization_type = FINALIZATION_TYPE_DIGEST,
3584cc2dcf9SEric Biggers 	}, {
3594cc2dcf9SEric Biggers 		.name = "init+update+final misaligned buffer",
3604cc2dcf9SEric Biggers 		.src_divs = { { .proportion_of_total = 10000, .offset = 1 } },
3614cc2dcf9SEric Biggers 		.finalization_type = FINALIZATION_TYPE_FINAL,
3624cc2dcf9SEric Biggers 	}, {
3634cc2dcf9SEric Biggers 		.name = "digest buffer aligned only to alignmask",
3644cc2dcf9SEric Biggers 		.src_divs = {
3654cc2dcf9SEric Biggers 			{
3664cc2dcf9SEric Biggers 				.proportion_of_total = 10000,
3674cc2dcf9SEric Biggers 				.offset = 1,
3684cc2dcf9SEric Biggers 				.offset_relative_to_alignmask = true,
3694cc2dcf9SEric Biggers 			},
3704cc2dcf9SEric Biggers 		},
3714cc2dcf9SEric Biggers 		.finalization_type = FINALIZATION_TYPE_DIGEST,
3724cc2dcf9SEric Biggers 	}, {
3734cc2dcf9SEric Biggers 		.name = "init+update+update+final two even splits",
3744cc2dcf9SEric Biggers 		.src_divs = {
3754cc2dcf9SEric Biggers 			{ .proportion_of_total = 5000 },
3764cc2dcf9SEric Biggers 			{
3774cc2dcf9SEric Biggers 				.proportion_of_total = 5000,
3784cc2dcf9SEric Biggers 				.flush_type = FLUSH_TYPE_FLUSH,
3794cc2dcf9SEric Biggers 			},
3804cc2dcf9SEric Biggers 		},
3814cc2dcf9SEric Biggers 		.finalization_type = FINALIZATION_TYPE_FINAL,
3824cc2dcf9SEric Biggers 	}, {
3834cc2dcf9SEric Biggers 		.name = "digest uneven misaligned splits, may sleep",
3844cc2dcf9SEric Biggers 		.req_flags = CRYPTO_TFM_REQ_MAY_SLEEP,
3854cc2dcf9SEric Biggers 		.src_divs = {
3864cc2dcf9SEric Biggers 			{ .proportion_of_total = 1900, .offset = 33 },
3874cc2dcf9SEric Biggers 			{ .proportion_of_total = 3300, .offset = 7  },
3884cc2dcf9SEric Biggers 			{ .proportion_of_total = 4800, .offset = 18 },
3894cc2dcf9SEric Biggers 		},
3904cc2dcf9SEric Biggers 		.finalization_type = FINALIZATION_TYPE_DIGEST,
3914cc2dcf9SEric Biggers 	}, {
3924cc2dcf9SEric Biggers 		.name = "digest misaligned splits crossing pages",
3934cc2dcf9SEric Biggers 		.src_divs = {
3944cc2dcf9SEric Biggers 			{
3954cc2dcf9SEric Biggers 				.proportion_of_total = 7500,
3964cc2dcf9SEric Biggers 				.offset = PAGE_SIZE - 32,
3974cc2dcf9SEric Biggers 			}, {
3984cc2dcf9SEric Biggers 				.proportion_of_total = 2500,
3994cc2dcf9SEric Biggers 				.offset = PAGE_SIZE - 7,
4004cc2dcf9SEric Biggers 			},
4014cc2dcf9SEric Biggers 		},
4024cc2dcf9SEric Biggers 		.finalization_type = FINALIZATION_TYPE_DIGEST,
4034cc2dcf9SEric Biggers 	}, {
4044cc2dcf9SEric Biggers 		.name = "import/export",
4054cc2dcf9SEric Biggers 		.src_divs = {
4064cc2dcf9SEric Biggers 			{
4074cc2dcf9SEric Biggers 				.proportion_of_total = 6500,
4084cc2dcf9SEric Biggers 				.flush_type = FLUSH_TYPE_REIMPORT,
4094cc2dcf9SEric Biggers 			}, {
4104cc2dcf9SEric Biggers 				.proportion_of_total = 3500,
4114cc2dcf9SEric Biggers 				.flush_type = FLUSH_TYPE_REIMPORT,
4124cc2dcf9SEric Biggers 			},
4134cc2dcf9SEric Biggers 		},
4144cc2dcf9SEric Biggers 		.finalization_type = FINALIZATION_TYPE_FINAL,
4154cc2dcf9SEric Biggers 	}
4164cc2dcf9SEric Biggers };
4174cc2dcf9SEric Biggers 
4183f47a03dSEric Biggers static unsigned int count_test_sg_divisions(const struct test_sg_division *divs)
4193f47a03dSEric Biggers {
4203f47a03dSEric Biggers 	unsigned int remaining = TEST_SG_TOTAL;
4213f47a03dSEric Biggers 	unsigned int ndivs = 0;
4223f47a03dSEric Biggers 
4233f47a03dSEric Biggers 	do {
4243f47a03dSEric Biggers 		remaining -= divs[ndivs++].proportion_of_total;
4253f47a03dSEric Biggers 	} while (remaining);
4263f47a03dSEric Biggers 
4273f47a03dSEric Biggers 	return ndivs;
4283f47a03dSEric Biggers }
4293f47a03dSEric Biggers 
4306570737cSEric Biggers #define SGDIVS_HAVE_FLUSHES	BIT(0)
4316570737cSEric Biggers #define SGDIVS_HAVE_NOSIMD	BIT(1)
4326570737cSEric Biggers 
4333f47a03dSEric Biggers static bool valid_sg_divisions(const struct test_sg_division *divs,
4346570737cSEric Biggers 			       unsigned int count, int *flags_ret)
4353f47a03dSEric Biggers {
4363f47a03dSEric Biggers 	unsigned int total = 0;
4373f47a03dSEric Biggers 	unsigned int i;
4383f47a03dSEric Biggers 
4393f47a03dSEric Biggers 	for (i = 0; i < count && total != TEST_SG_TOTAL; i++) {
4403f47a03dSEric Biggers 		if (divs[i].proportion_of_total <= 0 ||
4413f47a03dSEric Biggers 		    divs[i].proportion_of_total > TEST_SG_TOTAL - total)
4423f47a03dSEric Biggers 			return false;
4433f47a03dSEric Biggers 		total += divs[i].proportion_of_total;
4443f47a03dSEric Biggers 		if (divs[i].flush_type != FLUSH_TYPE_NONE)
4456570737cSEric Biggers 			*flags_ret |= SGDIVS_HAVE_FLUSHES;
4466570737cSEric Biggers 		if (divs[i].nosimd)
4476570737cSEric Biggers 			*flags_ret |= SGDIVS_HAVE_NOSIMD;
4483f47a03dSEric Biggers 	}
4493f47a03dSEric Biggers 	return total == TEST_SG_TOTAL &&
4503f47a03dSEric Biggers 		memchr_inv(&divs[i], 0, (count - i) * sizeof(divs[0])) == NULL;
4513f47a03dSEric Biggers }
4523f47a03dSEric Biggers 
4533f47a03dSEric Biggers /*
4543f47a03dSEric Biggers  * Check whether the given testvec_config is valid.  This isn't strictly needed
4553f47a03dSEric Biggers  * since every testvec_config should be valid, but check anyway so that people
4563f47a03dSEric Biggers  * don't unknowingly add broken configs that don't do what they wanted.
4573f47a03dSEric Biggers  */
4583f47a03dSEric Biggers static bool valid_testvec_config(const struct testvec_config *cfg)
4593f47a03dSEric Biggers {
4606570737cSEric Biggers 	int flags = 0;
4613f47a03dSEric Biggers 
4623f47a03dSEric Biggers 	if (cfg->name == NULL)
4633f47a03dSEric Biggers 		return false;
4643f47a03dSEric Biggers 
4653f47a03dSEric Biggers 	if (!valid_sg_divisions(cfg->src_divs, ARRAY_SIZE(cfg->src_divs),
4666570737cSEric Biggers 				&flags))
4673f47a03dSEric Biggers 		return false;
4683f47a03dSEric Biggers 
4693f47a03dSEric Biggers 	if (cfg->dst_divs[0].proportion_of_total) {
4703f47a03dSEric Biggers 		if (!valid_sg_divisions(cfg->dst_divs,
4716570737cSEric Biggers 					ARRAY_SIZE(cfg->dst_divs), &flags))
4723f47a03dSEric Biggers 			return false;
4733f47a03dSEric Biggers 	} else {
4743f47a03dSEric Biggers 		if (memchr_inv(cfg->dst_divs, 0, sizeof(cfg->dst_divs)))
4753f47a03dSEric Biggers 			return false;
4763f47a03dSEric Biggers 		/* defaults to dst_divs=src_divs */
4773f47a03dSEric Biggers 	}
4783f47a03dSEric Biggers 
4793f47a03dSEric Biggers 	if (cfg->iv_offset +
4803f47a03dSEric Biggers 	    (cfg->iv_offset_relative_to_alignmask ? MAX_ALGAPI_ALIGNMASK : 0) >
4813f47a03dSEric Biggers 	    MAX_ALGAPI_ALIGNMASK + 1)
4823f47a03dSEric Biggers 		return false;
4833f47a03dSEric Biggers 
4846570737cSEric Biggers 	if ((flags & (SGDIVS_HAVE_FLUSHES | SGDIVS_HAVE_NOSIMD)) &&
4856570737cSEric Biggers 	    cfg->finalization_type == FINALIZATION_TYPE_DIGEST)
4866570737cSEric Biggers 		return false;
4876570737cSEric Biggers 
4886570737cSEric Biggers 	if ((cfg->nosimd || (flags & SGDIVS_HAVE_NOSIMD)) &&
4896570737cSEric Biggers 	    (cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP))
4903f47a03dSEric Biggers 		return false;
4913f47a03dSEric Biggers 
4923f47a03dSEric Biggers 	return true;
4933f47a03dSEric Biggers }
4943f47a03dSEric Biggers 
4953f47a03dSEric Biggers struct test_sglist {
4963f47a03dSEric Biggers 	char *bufs[XBUFSIZE];
4973f47a03dSEric Biggers 	struct scatterlist sgl[XBUFSIZE];
4983f47a03dSEric Biggers 	struct scatterlist sgl_saved[XBUFSIZE];
4993f47a03dSEric Biggers 	struct scatterlist *sgl_ptr;
5003f47a03dSEric Biggers 	unsigned int nents;
5013f47a03dSEric Biggers };
5023f47a03dSEric Biggers 
5033f47a03dSEric Biggers static int init_test_sglist(struct test_sglist *tsgl)
5043f47a03dSEric Biggers {
5053f47a03dSEric Biggers 	return __testmgr_alloc_buf(tsgl->bufs, 1 /* two pages per buffer */);
5063f47a03dSEric Biggers }
5073f47a03dSEric Biggers 
5083f47a03dSEric Biggers static void destroy_test_sglist(struct test_sglist *tsgl)
5093f47a03dSEric Biggers {
5103f47a03dSEric Biggers 	return __testmgr_free_buf(tsgl->bufs, 1 /* two pages per buffer */);
5113f47a03dSEric Biggers }
5123f47a03dSEric Biggers 
5133f47a03dSEric Biggers /**
5143f47a03dSEric Biggers  * build_test_sglist() - build a scatterlist for a crypto test
5153f47a03dSEric Biggers  *
5163f47a03dSEric Biggers  * @tsgl: the scatterlist to build.  @tsgl->bufs[] contains an array of 2-page
5173f47a03dSEric Biggers  *	  buffers which the scatterlist @tsgl->sgl[] will be made to point into.
5183f47a03dSEric Biggers  * @divs: the layout specification on which the scatterlist will be based
5193f47a03dSEric Biggers  * @alignmask: the algorithm's alignmask
5203f47a03dSEric Biggers  * @total_len: the total length of the scatterlist to build in bytes
5213f47a03dSEric Biggers  * @data: if non-NULL, the buffers will be filled with this data until it ends.
5223f47a03dSEric Biggers  *	  Otherwise the buffers will be poisoned.  In both cases, some bytes
5233f47a03dSEric Biggers  *	  past the end of each buffer will be poisoned to help detect overruns.
5243f47a03dSEric Biggers  * @out_divs: if non-NULL, the test_sg_division to which each scatterlist entry
5253f47a03dSEric Biggers  *	      corresponds will be returned here.  This will match @divs except
5263f47a03dSEric Biggers  *	      that divisions resolving to a length of 0 are omitted as they are
5273f47a03dSEric Biggers  *	      not included in the scatterlist.
5283f47a03dSEric Biggers  *
5293f47a03dSEric Biggers  * Return: 0 or a -errno value
5303f47a03dSEric Biggers  */
5313f47a03dSEric Biggers static int build_test_sglist(struct test_sglist *tsgl,
5323f47a03dSEric Biggers 			     const struct test_sg_division *divs,
5333f47a03dSEric Biggers 			     const unsigned int alignmask,
5343f47a03dSEric Biggers 			     const unsigned int total_len,
5353f47a03dSEric Biggers 			     struct iov_iter *data,
5363f47a03dSEric Biggers 			     const struct test_sg_division *out_divs[XBUFSIZE])
5373f47a03dSEric Biggers {
5383f47a03dSEric Biggers 	struct {
5393f47a03dSEric Biggers 		const struct test_sg_division *div;
5403f47a03dSEric Biggers 		size_t length;
5413f47a03dSEric Biggers 	} partitions[XBUFSIZE];
5423f47a03dSEric Biggers 	const unsigned int ndivs = count_test_sg_divisions(divs);
5433f47a03dSEric Biggers 	unsigned int len_remaining = total_len;
5443f47a03dSEric Biggers 	unsigned int i;
5453f47a03dSEric Biggers 
5463f47a03dSEric Biggers 	BUILD_BUG_ON(ARRAY_SIZE(partitions) != ARRAY_SIZE(tsgl->sgl));
5473f47a03dSEric Biggers 	if (WARN_ON(ndivs > ARRAY_SIZE(partitions)))
5483f47a03dSEric Biggers 		return -EINVAL;
5493f47a03dSEric Biggers 
5503f47a03dSEric Biggers 	/* Calculate the (div, length) pairs */
5513f47a03dSEric Biggers 	tsgl->nents = 0;
5523f47a03dSEric Biggers 	for (i = 0; i < ndivs; i++) {
5533f47a03dSEric Biggers 		unsigned int len_this_sg =
5543f47a03dSEric Biggers 			min(len_remaining,
5553f47a03dSEric Biggers 			    (total_len * divs[i].proportion_of_total +
5563f47a03dSEric Biggers 			     TEST_SG_TOTAL / 2) / TEST_SG_TOTAL);
5573f47a03dSEric Biggers 
5583f47a03dSEric Biggers 		if (len_this_sg != 0) {
5593f47a03dSEric Biggers 			partitions[tsgl->nents].div = &divs[i];
5603f47a03dSEric Biggers 			partitions[tsgl->nents].length = len_this_sg;
5613f47a03dSEric Biggers 			tsgl->nents++;
5623f47a03dSEric Biggers 			len_remaining -= len_this_sg;
5633f47a03dSEric Biggers 		}
5643f47a03dSEric Biggers 	}
5653f47a03dSEric Biggers 	if (tsgl->nents == 0) {
5663f47a03dSEric Biggers 		partitions[tsgl->nents].div = &divs[0];
5673f47a03dSEric Biggers 		partitions[tsgl->nents].length = 0;
5683f47a03dSEric Biggers 		tsgl->nents++;
5693f47a03dSEric Biggers 	}
5703f47a03dSEric Biggers 	partitions[tsgl->nents - 1].length += len_remaining;
5713f47a03dSEric Biggers 
5723f47a03dSEric Biggers 	/* Set up the sgl entries and fill the data or poison */
5733f47a03dSEric Biggers 	sg_init_table(tsgl->sgl, tsgl->nents);
5743f47a03dSEric Biggers 	for (i = 0; i < tsgl->nents; i++) {
5753f47a03dSEric Biggers 		unsigned int offset = partitions[i].div->offset;
5763f47a03dSEric Biggers 		void *addr;
5773f47a03dSEric Biggers 
5783f47a03dSEric Biggers 		if (partitions[i].div->offset_relative_to_alignmask)
5793f47a03dSEric Biggers 			offset += alignmask;
5803f47a03dSEric Biggers 
5813f47a03dSEric Biggers 		while (offset + partitions[i].length + TESTMGR_POISON_LEN >
5823f47a03dSEric Biggers 		       2 * PAGE_SIZE) {
5833f47a03dSEric Biggers 			if (WARN_ON(offset <= 0))
5843f47a03dSEric Biggers 				return -EINVAL;
5853f47a03dSEric Biggers 			offset /= 2;
5863f47a03dSEric Biggers 		}
5873f47a03dSEric Biggers 
5883f47a03dSEric Biggers 		addr = &tsgl->bufs[i][offset];
5893f47a03dSEric Biggers 		sg_set_buf(&tsgl->sgl[i], addr, partitions[i].length);
5903f47a03dSEric Biggers 
5913f47a03dSEric Biggers 		if (out_divs)
5923f47a03dSEric Biggers 			out_divs[i] = partitions[i].div;
5933f47a03dSEric Biggers 
5943f47a03dSEric Biggers 		if (data) {
5953f47a03dSEric Biggers 			size_t copy_len, copied;
5963f47a03dSEric Biggers 
5973f47a03dSEric Biggers 			copy_len = min(partitions[i].length, data->count);
5983f47a03dSEric Biggers 			copied = copy_from_iter(addr, copy_len, data);
5993f47a03dSEric Biggers 			if (WARN_ON(copied != copy_len))
6003f47a03dSEric Biggers 				return -EINVAL;
6013f47a03dSEric Biggers 			testmgr_poison(addr + copy_len, partitions[i].length +
6023f47a03dSEric Biggers 				       TESTMGR_POISON_LEN - copy_len);
6033f47a03dSEric Biggers 		} else {
6043f47a03dSEric Biggers 			testmgr_poison(addr, partitions[i].length +
6053f47a03dSEric Biggers 				       TESTMGR_POISON_LEN);
6063f47a03dSEric Biggers 		}
6073f47a03dSEric Biggers 	}
6083f47a03dSEric Biggers 
6093f47a03dSEric Biggers 	sg_mark_end(&tsgl->sgl[tsgl->nents - 1]);
6103f47a03dSEric Biggers 	tsgl->sgl_ptr = tsgl->sgl;
6113f47a03dSEric Biggers 	memcpy(tsgl->sgl_saved, tsgl->sgl, tsgl->nents * sizeof(tsgl->sgl[0]));
6123f47a03dSEric Biggers 	return 0;
6133f47a03dSEric Biggers }
6143f47a03dSEric Biggers 
6153f47a03dSEric Biggers /*
6163f47a03dSEric Biggers  * Verify that a scatterlist crypto operation produced the correct output.
6173f47a03dSEric Biggers  *
6183f47a03dSEric Biggers  * @tsgl: scatterlist containing the actual output
6193f47a03dSEric Biggers  * @expected_output: buffer containing the expected output
6203f47a03dSEric Biggers  * @len_to_check: length of @expected_output in bytes
6213f47a03dSEric Biggers  * @unchecked_prefix_len: number of ignored bytes in @tsgl prior to real result
6223f47a03dSEric Biggers  * @check_poison: verify that the poison bytes after each chunk are intact?
6233f47a03dSEric Biggers  *
6243f47a03dSEric Biggers  * Return: 0 if correct, -EINVAL if incorrect, -EOVERFLOW if buffer overrun.
6253f47a03dSEric Biggers  */
6263f47a03dSEric Biggers static int verify_correct_output(const struct test_sglist *tsgl,
6273f47a03dSEric Biggers 				 const char *expected_output,
6283f47a03dSEric Biggers 				 unsigned int len_to_check,
6293f47a03dSEric Biggers 				 unsigned int unchecked_prefix_len,
6303f47a03dSEric Biggers 				 bool check_poison)
6313f47a03dSEric Biggers {
6323f47a03dSEric Biggers 	unsigned int i;
6333f47a03dSEric Biggers 
6343f47a03dSEric Biggers 	for (i = 0; i < tsgl->nents; i++) {
6353f47a03dSEric Biggers 		struct scatterlist *sg = &tsgl->sgl_ptr[i];
6363f47a03dSEric Biggers 		unsigned int len = sg->length;
6373f47a03dSEric Biggers 		unsigned int offset = sg->offset;
6383f47a03dSEric Biggers 		const char *actual_output;
6393f47a03dSEric Biggers 
6403f47a03dSEric Biggers 		if (unchecked_prefix_len) {
6413f47a03dSEric Biggers 			if (unchecked_prefix_len >= len) {
6423f47a03dSEric Biggers 				unchecked_prefix_len -= len;
6433f47a03dSEric Biggers 				continue;
6443f47a03dSEric Biggers 			}
6453f47a03dSEric Biggers 			offset += unchecked_prefix_len;
6463f47a03dSEric Biggers 			len -= unchecked_prefix_len;
6473f47a03dSEric Biggers 			unchecked_prefix_len = 0;
6483f47a03dSEric Biggers 		}
6493f47a03dSEric Biggers 		len = min(len, len_to_check);
6503f47a03dSEric Biggers 		actual_output = page_address(sg_page(sg)) + offset;
6513f47a03dSEric Biggers 		if (memcmp(expected_output, actual_output, len) != 0)
6523f47a03dSEric Biggers 			return -EINVAL;
6533f47a03dSEric Biggers 		if (check_poison &&
6543f47a03dSEric Biggers 		    !testmgr_is_poison(actual_output + len, TESTMGR_POISON_LEN))
6553f47a03dSEric Biggers 			return -EOVERFLOW;
6563f47a03dSEric Biggers 		len_to_check -= len;
6573f47a03dSEric Biggers 		expected_output += len;
6583f47a03dSEric Biggers 	}
6593f47a03dSEric Biggers 	if (WARN_ON(len_to_check != 0))
6603f47a03dSEric Biggers 		return -EINVAL;
6613f47a03dSEric Biggers 	return 0;
6623f47a03dSEric Biggers }
6633f47a03dSEric Biggers 
6643f47a03dSEric Biggers static bool is_test_sglist_corrupted(const struct test_sglist *tsgl)
6653f47a03dSEric Biggers {
6663f47a03dSEric Biggers 	unsigned int i;
6673f47a03dSEric Biggers 
6683f47a03dSEric Biggers 	for (i = 0; i < tsgl->nents; i++) {
6693f47a03dSEric Biggers 		if (tsgl->sgl[i].page_link != tsgl->sgl_saved[i].page_link)
6703f47a03dSEric Biggers 			return true;
6713f47a03dSEric Biggers 		if (tsgl->sgl[i].offset != tsgl->sgl_saved[i].offset)
6723f47a03dSEric Biggers 			return true;
6733f47a03dSEric Biggers 		if (tsgl->sgl[i].length != tsgl->sgl_saved[i].length)
6743f47a03dSEric Biggers 			return true;
6753f47a03dSEric Biggers 	}
6763f47a03dSEric Biggers 	return false;
6773f47a03dSEric Biggers }
6783f47a03dSEric Biggers 
6793f47a03dSEric Biggers struct cipher_test_sglists {
6803f47a03dSEric Biggers 	struct test_sglist src;
6813f47a03dSEric Biggers 	struct test_sglist dst;
6823f47a03dSEric Biggers };
6833f47a03dSEric Biggers 
6843f47a03dSEric Biggers static struct cipher_test_sglists *alloc_cipher_test_sglists(void)
6853f47a03dSEric Biggers {
6863f47a03dSEric Biggers 	struct cipher_test_sglists *tsgls;
6873f47a03dSEric Biggers 
6883f47a03dSEric Biggers 	tsgls = kmalloc(sizeof(*tsgls), GFP_KERNEL);
6893f47a03dSEric Biggers 	if (!tsgls)
6903f47a03dSEric Biggers 		return NULL;
6913f47a03dSEric Biggers 
6923f47a03dSEric Biggers 	if (init_test_sglist(&tsgls->src) != 0)
6933f47a03dSEric Biggers 		goto fail_kfree;
6943f47a03dSEric Biggers 	if (init_test_sglist(&tsgls->dst) != 0)
6953f47a03dSEric Biggers 		goto fail_destroy_src;
6963f47a03dSEric Biggers 
6973f47a03dSEric Biggers 	return tsgls;
6983f47a03dSEric Biggers 
6993f47a03dSEric Biggers fail_destroy_src:
7003f47a03dSEric Biggers 	destroy_test_sglist(&tsgls->src);
7013f47a03dSEric Biggers fail_kfree:
7023f47a03dSEric Biggers 	kfree(tsgls);
7033f47a03dSEric Biggers 	return NULL;
7043f47a03dSEric Biggers }
7053f47a03dSEric Biggers 
7063f47a03dSEric Biggers static void free_cipher_test_sglists(struct cipher_test_sglists *tsgls)
7073f47a03dSEric Biggers {
7083f47a03dSEric Biggers 	if (tsgls) {
7093f47a03dSEric Biggers 		destroy_test_sglist(&tsgls->src);
7103f47a03dSEric Biggers 		destroy_test_sglist(&tsgls->dst);
7113f47a03dSEric Biggers 		kfree(tsgls);
7123f47a03dSEric Biggers 	}
7133f47a03dSEric Biggers }
7143f47a03dSEric Biggers 
7153f47a03dSEric Biggers /* Build the src and dst scatterlists for an skcipher or AEAD test */
7163f47a03dSEric Biggers static int build_cipher_test_sglists(struct cipher_test_sglists *tsgls,
7173f47a03dSEric Biggers 				     const struct testvec_config *cfg,
7183f47a03dSEric Biggers 				     unsigned int alignmask,
7193f47a03dSEric Biggers 				     unsigned int src_total_len,
7203f47a03dSEric Biggers 				     unsigned int dst_total_len,
7213f47a03dSEric Biggers 				     const struct kvec *inputs,
7223f47a03dSEric Biggers 				     unsigned int nr_inputs)
7233f47a03dSEric Biggers {
7243f47a03dSEric Biggers 	struct iov_iter input;
7253f47a03dSEric Biggers 	int err;
7263f47a03dSEric Biggers 
7273f47a03dSEric Biggers 	iov_iter_kvec(&input, WRITE, inputs, nr_inputs, src_total_len);
7283f47a03dSEric Biggers 	err = build_test_sglist(&tsgls->src, cfg->src_divs, alignmask,
7293f47a03dSEric Biggers 				cfg->inplace ?
7303f47a03dSEric Biggers 					max(dst_total_len, src_total_len) :
7313f47a03dSEric Biggers 					src_total_len,
7323f47a03dSEric Biggers 				&input, NULL);
7333f47a03dSEric Biggers 	if (err)
7343f47a03dSEric Biggers 		return err;
7353f47a03dSEric Biggers 
7363f47a03dSEric Biggers 	if (cfg->inplace) {
7373f47a03dSEric Biggers 		tsgls->dst.sgl_ptr = tsgls->src.sgl;
7383f47a03dSEric Biggers 		tsgls->dst.nents = tsgls->src.nents;
7393f47a03dSEric Biggers 		return 0;
7403f47a03dSEric Biggers 	}
7413f47a03dSEric Biggers 	return build_test_sglist(&tsgls->dst,
7423f47a03dSEric Biggers 				 cfg->dst_divs[0].proportion_of_total ?
7433f47a03dSEric Biggers 					cfg->dst_divs : cfg->src_divs,
7443f47a03dSEric Biggers 				 alignmask, dst_total_len, NULL, NULL);
745f8b0d4d0SHerbert Xu }
746f8b0d4d0SHerbert Xu 
74725f9dddbSEric Biggers #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
74825f9dddbSEric Biggers static char *generate_random_sgl_divisions(struct test_sg_division *divs,
74925f9dddbSEric Biggers 					   size_t max_divs, char *p, char *end,
7506570737cSEric Biggers 					   bool gen_flushes, u32 req_flags)
75125f9dddbSEric Biggers {
75225f9dddbSEric Biggers 	struct test_sg_division *div = divs;
75325f9dddbSEric Biggers 	unsigned int remaining = TEST_SG_TOTAL;
75425f9dddbSEric Biggers 
75525f9dddbSEric Biggers 	do {
75625f9dddbSEric Biggers 		unsigned int this_len;
7576570737cSEric Biggers 		const char *flushtype_str;
75825f9dddbSEric Biggers 
75925f9dddbSEric Biggers 		if (div == &divs[max_divs - 1] || prandom_u32() % 2 == 0)
76025f9dddbSEric Biggers 			this_len = remaining;
76125f9dddbSEric Biggers 		else
76225f9dddbSEric Biggers 			this_len = 1 + (prandom_u32() % remaining);
76325f9dddbSEric Biggers 		div->proportion_of_total = this_len;
76425f9dddbSEric Biggers 
76525f9dddbSEric Biggers 		if (prandom_u32() % 4 == 0)
76625f9dddbSEric Biggers 			div->offset = (PAGE_SIZE - 128) + (prandom_u32() % 128);
76725f9dddbSEric Biggers 		else if (prandom_u32() % 2 == 0)
76825f9dddbSEric Biggers 			div->offset = prandom_u32() % 32;
76925f9dddbSEric Biggers 		else
77025f9dddbSEric Biggers 			div->offset = prandom_u32() % PAGE_SIZE;
77125f9dddbSEric Biggers 		if (prandom_u32() % 8 == 0)
77225f9dddbSEric Biggers 			div->offset_relative_to_alignmask = true;
77325f9dddbSEric Biggers 
77425f9dddbSEric Biggers 		div->flush_type = FLUSH_TYPE_NONE;
77525f9dddbSEric Biggers 		if (gen_flushes) {
77625f9dddbSEric Biggers 			switch (prandom_u32() % 4) {
77725f9dddbSEric Biggers 			case 0:
77825f9dddbSEric Biggers 				div->flush_type = FLUSH_TYPE_REIMPORT;
77925f9dddbSEric Biggers 				break;
78025f9dddbSEric Biggers 			case 1:
78125f9dddbSEric Biggers 				div->flush_type = FLUSH_TYPE_FLUSH;
78225f9dddbSEric Biggers 				break;
78325f9dddbSEric Biggers 			}
78425f9dddbSEric Biggers 		}
78525f9dddbSEric Biggers 
7866570737cSEric Biggers 		if (div->flush_type != FLUSH_TYPE_NONE &&
7876570737cSEric Biggers 		    !(req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) &&
7886570737cSEric Biggers 		    prandom_u32() % 2 == 0)
7896570737cSEric Biggers 			div->nosimd = true;
7906570737cSEric Biggers 
7916570737cSEric Biggers 		switch (div->flush_type) {
7926570737cSEric Biggers 		case FLUSH_TYPE_FLUSH:
7936570737cSEric Biggers 			if (div->nosimd)
7946570737cSEric Biggers 				flushtype_str = "<flush,nosimd>";
7956570737cSEric Biggers 			else
7966570737cSEric Biggers 				flushtype_str = "<flush>";
7976570737cSEric Biggers 			break;
7986570737cSEric Biggers 		case FLUSH_TYPE_REIMPORT:
7996570737cSEric Biggers 			if (div->nosimd)
8006570737cSEric Biggers 				flushtype_str = "<reimport,nosimd>";
8016570737cSEric Biggers 			else
8026570737cSEric Biggers 				flushtype_str = "<reimport>";
8036570737cSEric Biggers 			break;
8046570737cSEric Biggers 		default:
8056570737cSEric Biggers 			flushtype_str = "";
8066570737cSEric Biggers 			break;
8076570737cSEric Biggers 		}
8086570737cSEric Biggers 
80925f9dddbSEric Biggers 		BUILD_BUG_ON(TEST_SG_TOTAL != 10000); /* for "%u.%u%%" */
8106570737cSEric Biggers 		p += scnprintf(p, end - p, "%s%u.%u%%@%s+%u%s", flushtype_str,
81125f9dddbSEric Biggers 			       this_len / 100, this_len % 100,
81225f9dddbSEric Biggers 			       div->offset_relative_to_alignmask ?
81325f9dddbSEric Biggers 					"alignmask" : "",
81425f9dddbSEric Biggers 			       div->offset, this_len == remaining ? "" : ", ");
81525f9dddbSEric Biggers 		remaining -= this_len;
81625f9dddbSEric Biggers 		div++;
81725f9dddbSEric Biggers 	} while (remaining);
81825f9dddbSEric Biggers 
81925f9dddbSEric Biggers 	return p;
82025f9dddbSEric Biggers }
82125f9dddbSEric Biggers 
82225f9dddbSEric Biggers /* Generate a random testvec_config for fuzz testing */
82325f9dddbSEric Biggers static void generate_random_testvec_config(struct testvec_config *cfg,
82425f9dddbSEric Biggers 					   char *name, size_t max_namelen)
82525f9dddbSEric Biggers {
82625f9dddbSEric Biggers 	char *p = name;
82725f9dddbSEric Biggers 	char * const end = name + max_namelen;
82825f9dddbSEric Biggers 
82925f9dddbSEric Biggers 	memset(cfg, 0, sizeof(*cfg));
83025f9dddbSEric Biggers 
83125f9dddbSEric Biggers 	cfg->name = name;
83225f9dddbSEric Biggers 
83325f9dddbSEric Biggers 	p += scnprintf(p, end - p, "random:");
83425f9dddbSEric Biggers 
83525f9dddbSEric Biggers 	if (prandom_u32() % 2 == 0) {
83625f9dddbSEric Biggers 		cfg->inplace = true;
83725f9dddbSEric Biggers 		p += scnprintf(p, end - p, " inplace");
83825f9dddbSEric Biggers 	}
83925f9dddbSEric Biggers 
84025f9dddbSEric Biggers 	if (prandom_u32() % 2 == 0) {
84125f9dddbSEric Biggers 		cfg->req_flags |= CRYPTO_TFM_REQ_MAY_SLEEP;
84225f9dddbSEric Biggers 		p += scnprintf(p, end - p, " may_sleep");
84325f9dddbSEric Biggers 	}
84425f9dddbSEric Biggers 
84525f9dddbSEric Biggers 	switch (prandom_u32() % 4) {
84625f9dddbSEric Biggers 	case 0:
84725f9dddbSEric Biggers 		cfg->finalization_type = FINALIZATION_TYPE_FINAL;
84825f9dddbSEric Biggers 		p += scnprintf(p, end - p, " use_final");
84925f9dddbSEric Biggers 		break;
85025f9dddbSEric Biggers 	case 1:
85125f9dddbSEric Biggers 		cfg->finalization_type = FINALIZATION_TYPE_FINUP;
85225f9dddbSEric Biggers 		p += scnprintf(p, end - p, " use_finup");
85325f9dddbSEric Biggers 		break;
85425f9dddbSEric Biggers 	default:
85525f9dddbSEric Biggers 		cfg->finalization_type = FINALIZATION_TYPE_DIGEST;
85625f9dddbSEric Biggers 		p += scnprintf(p, end - p, " use_digest");
85725f9dddbSEric Biggers 		break;
85825f9dddbSEric Biggers 	}
85925f9dddbSEric Biggers 
8606570737cSEric Biggers 	if (!(cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) &&
8616570737cSEric Biggers 	    prandom_u32() % 2 == 0) {
8626570737cSEric Biggers 		cfg->nosimd = true;
8636570737cSEric Biggers 		p += scnprintf(p, end - p, " nosimd");
8646570737cSEric Biggers 	}
8656570737cSEric Biggers 
86625f9dddbSEric Biggers 	p += scnprintf(p, end - p, " src_divs=[");
86725f9dddbSEric Biggers 	p = generate_random_sgl_divisions(cfg->src_divs,
86825f9dddbSEric Biggers 					  ARRAY_SIZE(cfg->src_divs), p, end,
86925f9dddbSEric Biggers 					  (cfg->finalization_type !=
8706570737cSEric Biggers 					   FINALIZATION_TYPE_DIGEST),
8716570737cSEric Biggers 					  cfg->req_flags);
87225f9dddbSEric Biggers 	p += scnprintf(p, end - p, "]");
87325f9dddbSEric Biggers 
87425f9dddbSEric Biggers 	if (!cfg->inplace && prandom_u32() % 2 == 0) {
87525f9dddbSEric Biggers 		p += scnprintf(p, end - p, " dst_divs=[");
87625f9dddbSEric Biggers 		p = generate_random_sgl_divisions(cfg->dst_divs,
87725f9dddbSEric Biggers 						  ARRAY_SIZE(cfg->dst_divs),
8786570737cSEric Biggers 						  p, end, false,
8796570737cSEric Biggers 						  cfg->req_flags);
88025f9dddbSEric Biggers 		p += scnprintf(p, end - p, "]");
88125f9dddbSEric Biggers 	}
88225f9dddbSEric Biggers 
88325f9dddbSEric Biggers 	if (prandom_u32() % 2 == 0) {
88425f9dddbSEric Biggers 		cfg->iv_offset = 1 + (prandom_u32() % MAX_ALGAPI_ALIGNMASK);
88525f9dddbSEric Biggers 		p += scnprintf(p, end - p, " iv_offset=%u", cfg->iv_offset);
88625f9dddbSEric Biggers 	}
88725f9dddbSEric Biggers 
88825f9dddbSEric Biggers 	WARN_ON_ONCE(!valid_testvec_config(cfg));
88925f9dddbSEric Biggers }
890b55e1a39SEric Biggers 
891b55e1a39SEric Biggers static void crypto_disable_simd_for_test(void)
892b55e1a39SEric Biggers {
893b55e1a39SEric Biggers 	preempt_disable();
894b55e1a39SEric Biggers 	__this_cpu_write(crypto_simd_disabled_for_test, true);
895b55e1a39SEric Biggers }
896b55e1a39SEric Biggers 
897b55e1a39SEric Biggers static void crypto_reenable_simd_for_test(void)
898b55e1a39SEric Biggers {
899b55e1a39SEric Biggers 	__this_cpu_write(crypto_simd_disabled_for_test, false);
900b55e1a39SEric Biggers 	preempt_enable();
901b55e1a39SEric Biggers }
902b55e1a39SEric Biggers #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
903b55e1a39SEric Biggers static void crypto_disable_simd_for_test(void)
904b55e1a39SEric Biggers {
905b55e1a39SEric Biggers }
906b55e1a39SEric Biggers 
907b55e1a39SEric Biggers static void crypto_reenable_simd_for_test(void)
908b55e1a39SEric Biggers {
909b55e1a39SEric Biggers }
910b55e1a39SEric Biggers #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
91125f9dddbSEric Biggers 
9126570737cSEric Biggers static int do_ahash_op(int (*op)(struct ahash_request *req),
9136570737cSEric Biggers 		       struct ahash_request *req,
9146570737cSEric Biggers 		       struct crypto_wait *wait, bool nosimd)
9156570737cSEric Biggers {
9166570737cSEric Biggers 	int err;
9176570737cSEric Biggers 
9186570737cSEric Biggers 	if (nosimd)
9196570737cSEric Biggers 		crypto_disable_simd_for_test();
9206570737cSEric Biggers 
9216570737cSEric Biggers 	err = op(req);
9226570737cSEric Biggers 
9236570737cSEric Biggers 	if (nosimd)
9246570737cSEric Biggers 		crypto_reenable_simd_for_test();
9256570737cSEric Biggers 
9266570737cSEric Biggers 	return crypto_wait_req(err, wait);
9276570737cSEric Biggers }
9286570737cSEric Biggers 
9294cc2dcf9SEric Biggers static int check_nonfinal_hash_op(const char *op, int err,
9304cc2dcf9SEric Biggers 				  u8 *result, unsigned int digestsize,
9314cc2dcf9SEric Biggers 				  const char *driver, unsigned int vec_num,
9324cc2dcf9SEric Biggers 				  const struct testvec_config *cfg)
933466d7b9fSKamil Konieczny {
9344cc2dcf9SEric Biggers 	if (err) {
9354cc2dcf9SEric Biggers 		pr_err("alg: hash: %s %s() failed with err %d on test vector %u, cfg=\"%s\"\n",
9364cc2dcf9SEric Biggers 		       driver, op, err, vec_num, cfg->name);
9374cc2dcf9SEric Biggers 		return err;
9384cc2dcf9SEric Biggers 	}
9394cc2dcf9SEric Biggers 	if (!testmgr_is_poison(result, digestsize)) {
9404cc2dcf9SEric Biggers 		pr_err("alg: hash: %s %s() used result buffer on test vector %u, cfg=\"%s\"\n",
9414cc2dcf9SEric Biggers 		       driver, op, vec_num, cfg->name);
942466d7b9fSKamil Konieczny 		return -EINVAL;
943466d7b9fSKamil Konieczny 	}
944466d7b9fSKamil Konieczny 	return 0;
945466d7b9fSKamil Konieczny }
946466d7b9fSKamil Konieczny 
9474cc2dcf9SEric Biggers static int test_hash_vec_cfg(const char *driver,
9484cc2dcf9SEric Biggers 			     const struct hash_testvec *vec,
9494cc2dcf9SEric Biggers 			     unsigned int vec_num,
9504cc2dcf9SEric Biggers 			     const struct testvec_config *cfg,
9514cc2dcf9SEric Biggers 			     struct ahash_request *req,
9524cc2dcf9SEric Biggers 			     struct test_sglist *tsgl,
9534cc2dcf9SEric Biggers 			     u8 *hashstate)
954018ba95cSWang, Rui Y {
9554cc2dcf9SEric Biggers 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
9564cc2dcf9SEric Biggers 	const unsigned int alignmask = crypto_ahash_alignmask(tfm);
9574cc2dcf9SEric Biggers 	const unsigned int digestsize = crypto_ahash_digestsize(tfm);
9584cc2dcf9SEric Biggers 	const unsigned int statesize = crypto_ahash_statesize(tfm);
9594cc2dcf9SEric Biggers 	const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
9604cc2dcf9SEric Biggers 	const struct test_sg_division *divs[XBUFSIZE];
9614cc2dcf9SEric Biggers 	DECLARE_CRYPTO_WAIT(wait);
9624cc2dcf9SEric Biggers 	struct kvec _input;
9634cc2dcf9SEric Biggers 	struct iov_iter input;
9644cc2dcf9SEric Biggers 	unsigned int i;
9654cc2dcf9SEric Biggers 	struct scatterlist *pending_sgl;
9664cc2dcf9SEric Biggers 	unsigned int pending_len;
9674cc2dcf9SEric Biggers 	u8 result[HASH_MAX_DIGESTSIZE + TESTMGR_POISON_LEN];
9684cc2dcf9SEric Biggers 	int err;
969018ba95cSWang, Rui Y 
9704cc2dcf9SEric Biggers 	/* Set the key, if specified */
9714cc2dcf9SEric Biggers 	if (vec->ksize) {
9724cc2dcf9SEric Biggers 		err = crypto_ahash_setkey(tfm, vec->key, vec->ksize);
9734cc2dcf9SEric Biggers 		if (err) {
9744cc2dcf9SEric Biggers 			pr_err("alg: hash: %s setkey failed with err %d on test vector %u; flags=%#x\n",
9754cc2dcf9SEric Biggers 			       driver, err, vec_num,
9764cc2dcf9SEric Biggers 			       crypto_ahash_get_flags(tfm));
9774cc2dcf9SEric Biggers 			return err;
978da7f033dSHerbert Xu 		}
979da7f033dSHerbert Xu 	}
980da7f033dSHerbert Xu 
9814cc2dcf9SEric Biggers 	/* Build the scatterlist for the source data */
9824cc2dcf9SEric Biggers 	_input.iov_base = (void *)vec->plaintext;
9834cc2dcf9SEric Biggers 	_input.iov_len = vec->psize;
9844cc2dcf9SEric Biggers 	iov_iter_kvec(&input, WRITE, &_input, 1, vec->psize);
9854cc2dcf9SEric Biggers 	err = build_test_sglist(tsgl, cfg->src_divs, alignmask, vec->psize,
9864cc2dcf9SEric Biggers 				&input, divs);
9874cc2dcf9SEric Biggers 	if (err) {
9884cc2dcf9SEric Biggers 		pr_err("alg: hash: %s: error preparing scatterlist for test vector %u, cfg=\"%s\"\n",
9894cc2dcf9SEric Biggers 		       driver, vec_num, cfg->name);
9904cc2dcf9SEric Biggers 		return err;
991a8f1a052SDavid S. Miller 	}
992da7f033dSHerbert Xu 
9934cc2dcf9SEric Biggers 	/* Do the actual hashing */
994da7f033dSHerbert Xu 
9954cc2dcf9SEric Biggers 	testmgr_poison(req->__ctx, crypto_ahash_reqsize(tfm));
9964cc2dcf9SEric Biggers 	testmgr_poison(result, digestsize + TESTMGR_POISON_LEN);
99776715095SGilad Ben-Yossef 
9984cc2dcf9SEric Biggers 	if (cfg->finalization_type == FINALIZATION_TYPE_DIGEST) {
9994cc2dcf9SEric Biggers 		/* Just using digest() */
10004cc2dcf9SEric Biggers 		ahash_request_set_callback(req, req_flags, crypto_req_done,
10017f397136SGilad Ben-Yossef 					   &wait);
10024cc2dcf9SEric Biggers 		ahash_request_set_crypt(req, tsgl->sgl, result, vec->psize);
10036570737cSEric Biggers 		err = do_ahash_op(crypto_ahash_digest, req, &wait, cfg->nosimd);
10044cc2dcf9SEric Biggers 		if (err) {
10054cc2dcf9SEric Biggers 			pr_err("alg: hash: %s digest() failed with err %d on test vector %u, cfg=\"%s\"\n",
10064cc2dcf9SEric Biggers 			       driver, err, vec_num, cfg->name);
10074cc2dcf9SEric Biggers 			return err;
1008018ba95cSWang, Rui Y 		}
10094cc2dcf9SEric Biggers 		goto result_ready;
1010018ba95cSWang, Rui Y 	}
10114cc2dcf9SEric Biggers 
10124cc2dcf9SEric Biggers 	/* Using init(), zero or more update(), then final() or finup() */
10134cc2dcf9SEric Biggers 
10144cc2dcf9SEric Biggers 	ahash_request_set_callback(req, req_flags, crypto_req_done, &wait);
10154cc2dcf9SEric Biggers 	ahash_request_set_crypt(req, NULL, result, 0);
10166570737cSEric Biggers 	err = do_ahash_op(crypto_ahash_init, req, &wait, cfg->nosimd);
10174cc2dcf9SEric Biggers 	err = check_nonfinal_hash_op("init", err, result, digestsize,
10184cc2dcf9SEric Biggers 				     driver, vec_num, cfg);
10194cc2dcf9SEric Biggers 	if (err)
10204cc2dcf9SEric Biggers 		return err;
10214cc2dcf9SEric Biggers 
10224cc2dcf9SEric Biggers 	pending_sgl = NULL;
10234cc2dcf9SEric Biggers 	pending_len = 0;
10244cc2dcf9SEric Biggers 	for (i = 0; i < tsgl->nents; i++) {
10254cc2dcf9SEric Biggers 		if (divs[i]->flush_type != FLUSH_TYPE_NONE &&
10264cc2dcf9SEric Biggers 		    pending_sgl != NULL) {
10274cc2dcf9SEric Biggers 			/* update() with the pending data */
10284cc2dcf9SEric Biggers 			ahash_request_set_callback(req, req_flags,
10294cc2dcf9SEric Biggers 						   crypto_req_done, &wait);
10304cc2dcf9SEric Biggers 			ahash_request_set_crypt(req, pending_sgl, result,
10314cc2dcf9SEric Biggers 						pending_len);
10326570737cSEric Biggers 			err = do_ahash_op(crypto_ahash_update, req, &wait,
10336570737cSEric Biggers 					  divs[i]->nosimd);
10344cc2dcf9SEric Biggers 			err = check_nonfinal_hash_op("update", err,
10354cc2dcf9SEric Biggers 						     result, digestsize,
10364cc2dcf9SEric Biggers 						     driver, vec_num, cfg);
10374cc2dcf9SEric Biggers 			if (err)
10384cc2dcf9SEric Biggers 				return err;
10394cc2dcf9SEric Biggers 			pending_sgl = NULL;
10404cc2dcf9SEric Biggers 			pending_len = 0;
1041018ba95cSWang, Rui Y 		}
10424cc2dcf9SEric Biggers 		if (divs[i]->flush_type == FLUSH_TYPE_REIMPORT) {
10434cc2dcf9SEric Biggers 			/* Test ->export() and ->import() */
10444cc2dcf9SEric Biggers 			testmgr_poison(hashstate + statesize,
10454cc2dcf9SEric Biggers 				       TESTMGR_POISON_LEN);
10464cc2dcf9SEric Biggers 			err = crypto_ahash_export(req, hashstate);
10474cc2dcf9SEric Biggers 			err = check_nonfinal_hash_op("export", err,
10484cc2dcf9SEric Biggers 						     result, digestsize,
10494cc2dcf9SEric Biggers 						     driver, vec_num, cfg);
10504cc2dcf9SEric Biggers 			if (err)
10514cc2dcf9SEric Biggers 				return err;
10524cc2dcf9SEric Biggers 			if (!testmgr_is_poison(hashstate + statesize,
10534cc2dcf9SEric Biggers 					       TESTMGR_POISON_LEN)) {
10544cc2dcf9SEric Biggers 				pr_err("alg: hash: %s export() overran state buffer on test vector %u, cfg=\"%s\"\n",
10554cc2dcf9SEric Biggers 				       driver, vec_num, cfg->name);
10564cc2dcf9SEric Biggers 				return -EOVERFLOW;
10574cc2dcf9SEric Biggers 			}
10584cc2dcf9SEric Biggers 
10594cc2dcf9SEric Biggers 			testmgr_poison(req->__ctx, crypto_ahash_reqsize(tfm));
10604cc2dcf9SEric Biggers 			err = crypto_ahash_import(req, hashstate);
10614cc2dcf9SEric Biggers 			err = check_nonfinal_hash_op("import", err,
10624cc2dcf9SEric Biggers 						     result, digestsize,
10634cc2dcf9SEric Biggers 						     driver, vec_num, cfg);
10644cc2dcf9SEric Biggers 			if (err)
10654cc2dcf9SEric Biggers 				return err;
10664cc2dcf9SEric Biggers 		}
10674cc2dcf9SEric Biggers 		if (pending_sgl == NULL)
10684cc2dcf9SEric Biggers 			pending_sgl = &tsgl->sgl[i];
10694cc2dcf9SEric Biggers 		pending_len += tsgl->sgl[i].length;
10704cc2dcf9SEric Biggers 	}
10714cc2dcf9SEric Biggers 
10724cc2dcf9SEric Biggers 	ahash_request_set_callback(req, req_flags, crypto_req_done, &wait);
10734cc2dcf9SEric Biggers 	ahash_request_set_crypt(req, pending_sgl, result, pending_len);
10744cc2dcf9SEric Biggers 	if (cfg->finalization_type == FINALIZATION_TYPE_FINAL) {
10754cc2dcf9SEric Biggers 		/* finish with update() and final() */
10766570737cSEric Biggers 		err = do_ahash_op(crypto_ahash_update, req, &wait, cfg->nosimd);
10774cc2dcf9SEric Biggers 		err = check_nonfinal_hash_op("update", err, result, digestsize,
10784cc2dcf9SEric Biggers 					     driver, vec_num, cfg);
10794cc2dcf9SEric Biggers 		if (err)
10804cc2dcf9SEric Biggers 			return err;
10816570737cSEric Biggers 		err = do_ahash_op(crypto_ahash_final, req, &wait, cfg->nosimd);
10824cc2dcf9SEric Biggers 		if (err) {
10834cc2dcf9SEric Biggers 			pr_err("alg: hash: %s final() failed with err %d on test vector %u, cfg=\"%s\"\n",
10844cc2dcf9SEric Biggers 			       driver, err, vec_num, cfg->name);
10854cc2dcf9SEric Biggers 			return err;
10864cc2dcf9SEric Biggers 		}
10874cc2dcf9SEric Biggers 	} else {
10884cc2dcf9SEric Biggers 		/* finish with finup() */
10896570737cSEric Biggers 		err = do_ahash_op(crypto_ahash_finup, req, &wait, cfg->nosimd);
10904cc2dcf9SEric Biggers 		if (err) {
10914cc2dcf9SEric Biggers 			pr_err("alg: hash: %s finup() failed with err %d on test vector %u, cfg=\"%s\"\n",
10924cc2dcf9SEric Biggers 			       driver, err, vec_num, cfg->name);
10934cc2dcf9SEric Biggers 			return err;
1094018ba95cSWang, Rui Y 		}
1095018ba95cSWang, Rui Y 	}
1096018ba95cSWang, Rui Y 
10974cc2dcf9SEric Biggers result_ready:
10984cc2dcf9SEric Biggers 	/* Check that the algorithm produced the correct digest */
10994cc2dcf9SEric Biggers 	if (memcmp(result, vec->digest, digestsize) != 0) {
11004cc2dcf9SEric Biggers 		pr_err("alg: hash: %s test failed (wrong result) on test vector %u, cfg=\"%s\"\n",
11014cc2dcf9SEric Biggers 		       driver, vec_num, cfg->name);
11024cc2dcf9SEric Biggers 		return -EINVAL;
1103da7f033dSHerbert Xu 	}
11044cc2dcf9SEric Biggers 	if (!testmgr_is_poison(&result[digestsize], TESTMGR_POISON_LEN)) {
11054cc2dcf9SEric Biggers 		pr_err("alg: hash: %s overran result buffer on test vector %u, cfg=\"%s\"\n",
11064cc2dcf9SEric Biggers 		       driver, vec_num, cfg->name);
11074cc2dcf9SEric Biggers 		return -EOVERFLOW;
1108da5ffe11SJussi Kivilinna 	}
1109da5ffe11SJussi Kivilinna 
1110da5ffe11SJussi Kivilinna 	return 0;
1111da5ffe11SJussi Kivilinna }
1112da5ffe11SJussi Kivilinna 
11134cc2dcf9SEric Biggers static int test_hash_vec(const char *driver, const struct hash_testvec *vec,
11144cc2dcf9SEric Biggers 			 unsigned int vec_num, struct ahash_request *req,
11154cc2dcf9SEric Biggers 			 struct test_sglist *tsgl, u8 *hashstate)
11164cc2dcf9SEric Biggers {
11174cc2dcf9SEric Biggers 	unsigned int i;
11184cc2dcf9SEric Biggers 	int err;
11194cc2dcf9SEric Biggers 
11204cc2dcf9SEric Biggers 	for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++) {
11214cc2dcf9SEric Biggers 		err = test_hash_vec_cfg(driver, vec, vec_num,
11224cc2dcf9SEric Biggers 					&default_hash_testvec_configs[i],
11234cc2dcf9SEric Biggers 					req, tsgl, hashstate);
11244cc2dcf9SEric Biggers 		if (err)
11254cc2dcf9SEric Biggers 			return err;
11264cc2dcf9SEric Biggers 	}
11274cc2dcf9SEric Biggers 
11284cc2dcf9SEric Biggers #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
11294cc2dcf9SEric Biggers 	if (!noextratests) {
11304cc2dcf9SEric Biggers 		struct testvec_config cfg;
11314cc2dcf9SEric Biggers 		char cfgname[TESTVEC_CONFIG_NAMELEN];
11324cc2dcf9SEric Biggers 
11334cc2dcf9SEric Biggers 		for (i = 0; i < fuzz_iterations; i++) {
11344cc2dcf9SEric Biggers 			generate_random_testvec_config(&cfg, cfgname,
11354cc2dcf9SEric Biggers 						       sizeof(cfgname));
11364cc2dcf9SEric Biggers 			err = test_hash_vec_cfg(driver, vec, vec_num, &cfg,
11374cc2dcf9SEric Biggers 						req, tsgl, hashstate);
11384cc2dcf9SEric Biggers 			if (err)
11394cc2dcf9SEric Biggers 				return err;
11404cc2dcf9SEric Biggers 		}
11414cc2dcf9SEric Biggers 	}
11424cc2dcf9SEric Biggers #endif
11434cc2dcf9SEric Biggers 	return 0;
11444cc2dcf9SEric Biggers }
11454cc2dcf9SEric Biggers 
11464cc2dcf9SEric Biggers static int __alg_test_hash(const struct hash_testvec *vecs,
11474cc2dcf9SEric Biggers 			   unsigned int num_vecs, const char *driver,
11484cc2dcf9SEric Biggers 			   u32 type, u32 mask)
11494cc2dcf9SEric Biggers {
11504cc2dcf9SEric Biggers 	struct crypto_ahash *tfm;
11514cc2dcf9SEric Biggers 	struct ahash_request *req = NULL;
11524cc2dcf9SEric Biggers 	struct test_sglist *tsgl = NULL;
11534cc2dcf9SEric Biggers 	u8 *hashstate = NULL;
11544cc2dcf9SEric Biggers 	unsigned int i;
11554cc2dcf9SEric Biggers 	int err;
11564cc2dcf9SEric Biggers 
11574cc2dcf9SEric Biggers 	tfm = crypto_alloc_ahash(driver, type, mask);
11584cc2dcf9SEric Biggers 	if (IS_ERR(tfm)) {
11594cc2dcf9SEric Biggers 		pr_err("alg: hash: failed to allocate transform for %s: %ld\n",
11604cc2dcf9SEric Biggers 		       driver, PTR_ERR(tfm));
11614cc2dcf9SEric Biggers 		return PTR_ERR(tfm);
11624cc2dcf9SEric Biggers 	}
11634cc2dcf9SEric Biggers 
11644cc2dcf9SEric Biggers 	req = ahash_request_alloc(tfm, GFP_KERNEL);
11654cc2dcf9SEric Biggers 	if (!req) {
11664cc2dcf9SEric Biggers 		pr_err("alg: hash: failed to allocate request for %s\n",
11674cc2dcf9SEric Biggers 		       driver);
11684cc2dcf9SEric Biggers 		err = -ENOMEM;
11694cc2dcf9SEric Biggers 		goto out;
11704cc2dcf9SEric Biggers 	}
11714cc2dcf9SEric Biggers 
11724cc2dcf9SEric Biggers 	tsgl = kmalloc(sizeof(*tsgl), GFP_KERNEL);
11734cc2dcf9SEric Biggers 	if (!tsgl || init_test_sglist(tsgl) != 0) {
11744cc2dcf9SEric Biggers 		pr_err("alg: hash: failed to allocate test buffers for %s\n",
11754cc2dcf9SEric Biggers 		       driver);
11764cc2dcf9SEric Biggers 		kfree(tsgl);
11774cc2dcf9SEric Biggers 		tsgl = NULL;
11784cc2dcf9SEric Biggers 		err = -ENOMEM;
11794cc2dcf9SEric Biggers 		goto out;
11804cc2dcf9SEric Biggers 	}
11814cc2dcf9SEric Biggers 
11824cc2dcf9SEric Biggers 	hashstate = kmalloc(crypto_ahash_statesize(tfm) + TESTMGR_POISON_LEN,
11834cc2dcf9SEric Biggers 			    GFP_KERNEL);
11844cc2dcf9SEric Biggers 	if (!hashstate) {
11854cc2dcf9SEric Biggers 		pr_err("alg: hash: failed to allocate hash state buffer for %s\n",
11864cc2dcf9SEric Biggers 		       driver);
11874cc2dcf9SEric Biggers 		err = -ENOMEM;
11884cc2dcf9SEric Biggers 		goto out;
11894cc2dcf9SEric Biggers 	}
11904cc2dcf9SEric Biggers 
11914cc2dcf9SEric Biggers 	for (i = 0; i < num_vecs; i++) {
11924cc2dcf9SEric Biggers 		err = test_hash_vec(driver, &vecs[i], i, req, tsgl, hashstate);
11934cc2dcf9SEric Biggers 		if (err)
11944cc2dcf9SEric Biggers 			goto out;
11954cc2dcf9SEric Biggers 	}
11964cc2dcf9SEric Biggers 	err = 0;
11974cc2dcf9SEric Biggers out:
11984cc2dcf9SEric Biggers 	kfree(hashstate);
11994cc2dcf9SEric Biggers 	if (tsgl) {
12004cc2dcf9SEric Biggers 		destroy_test_sglist(tsgl);
12014cc2dcf9SEric Biggers 		kfree(tsgl);
12024cc2dcf9SEric Biggers 	}
12034cc2dcf9SEric Biggers 	ahash_request_free(req);
12044cc2dcf9SEric Biggers 	crypto_free_ahash(tfm);
12054cc2dcf9SEric Biggers 	return err;
12064cc2dcf9SEric Biggers }
12074cc2dcf9SEric Biggers 
12084cc2dcf9SEric Biggers static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
12094cc2dcf9SEric Biggers 			 u32 type, u32 mask)
12104cc2dcf9SEric Biggers {
12114cc2dcf9SEric Biggers 	const struct hash_testvec *template = desc->suite.hash.vecs;
12124cc2dcf9SEric Biggers 	unsigned int tcount = desc->suite.hash.count;
12134cc2dcf9SEric Biggers 	unsigned int nr_unkeyed, nr_keyed;
12144cc2dcf9SEric Biggers 	int err;
12154cc2dcf9SEric Biggers 
12164cc2dcf9SEric Biggers 	/*
12174cc2dcf9SEric Biggers 	 * For OPTIONAL_KEY algorithms, we have to do all the unkeyed tests
12184cc2dcf9SEric Biggers 	 * first, before setting a key on the tfm.  To make this easier, we
12194cc2dcf9SEric Biggers 	 * require that the unkeyed test vectors (if any) are listed first.
12204cc2dcf9SEric Biggers 	 */
12214cc2dcf9SEric Biggers 
12224cc2dcf9SEric Biggers 	for (nr_unkeyed = 0; nr_unkeyed < tcount; nr_unkeyed++) {
12234cc2dcf9SEric Biggers 		if (template[nr_unkeyed].ksize)
12244cc2dcf9SEric Biggers 			break;
12254cc2dcf9SEric Biggers 	}
12264cc2dcf9SEric Biggers 	for (nr_keyed = 0; nr_unkeyed + nr_keyed < tcount; nr_keyed++) {
12274cc2dcf9SEric Biggers 		if (!template[nr_unkeyed + nr_keyed].ksize) {
12284cc2dcf9SEric Biggers 			pr_err("alg: hash: test vectors for %s out of order, "
12294cc2dcf9SEric Biggers 			       "unkeyed ones must come first\n", desc->alg);
12304cc2dcf9SEric Biggers 			return -EINVAL;
12314cc2dcf9SEric Biggers 		}
12324cc2dcf9SEric Biggers 	}
12334cc2dcf9SEric Biggers 
12344cc2dcf9SEric Biggers 	err = 0;
12354cc2dcf9SEric Biggers 	if (nr_unkeyed) {
12364cc2dcf9SEric Biggers 		err = __alg_test_hash(template, nr_unkeyed, driver, type, mask);
12374cc2dcf9SEric Biggers 		template += nr_unkeyed;
12384cc2dcf9SEric Biggers 	}
12394cc2dcf9SEric Biggers 
12404cc2dcf9SEric Biggers 	if (!err && nr_keyed)
12414cc2dcf9SEric Biggers 		err = __alg_test_hash(template, nr_keyed, driver, type, mask);
12424cc2dcf9SEric Biggers 
12434cc2dcf9SEric Biggers 	return err;
12444cc2dcf9SEric Biggers }
12454cc2dcf9SEric Biggers 
1246ed96804fSEric Biggers static int test_aead_vec_cfg(const char *driver, int enc,
1247ed96804fSEric Biggers 			     const struct aead_testvec *vec,
1248ed96804fSEric Biggers 			     unsigned int vec_num,
1249ed96804fSEric Biggers 			     const struct testvec_config *cfg,
1250ed96804fSEric Biggers 			     struct aead_request *req,
1251ed96804fSEric Biggers 			     struct cipher_test_sglists *tsgls)
1252da7f033dSHerbert Xu {
1253ed96804fSEric Biggers 	struct crypto_aead *tfm = crypto_aead_reqtfm(req);
1254ed96804fSEric Biggers 	const unsigned int alignmask = crypto_aead_alignmask(tfm);
1255ed96804fSEric Biggers 	const unsigned int ivsize = crypto_aead_ivsize(tfm);
1256ed96804fSEric Biggers 	const unsigned int authsize = vec->clen - vec->plen;
1257ed96804fSEric Biggers 	const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
1258ed96804fSEric Biggers 	const char *op = enc ? "encryption" : "decryption";
1259ed96804fSEric Biggers 	DECLARE_CRYPTO_WAIT(wait);
1260ed96804fSEric Biggers 	u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN];
1261ed96804fSEric Biggers 	u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) +
1262ed96804fSEric Biggers 		 cfg->iv_offset +
1263ed96804fSEric Biggers 		 (cfg->iv_offset_relative_to_alignmask ? alignmask : 0);
1264ed96804fSEric Biggers 	struct kvec input[2];
1265ed96804fSEric Biggers 	int err;
1266f8b0d4d0SHerbert Xu 
1267ed96804fSEric Biggers 	/* Set the key */
1268ed96804fSEric Biggers 	if (vec->wk)
1269ed96804fSEric Biggers 		crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
1270d8a32ac2SJussi Kivilinna 	else
1271ed96804fSEric Biggers 		crypto_aead_clear_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
1272ed96804fSEric Biggers 	err = crypto_aead_setkey(tfm, vec->key, vec->klen);
1273ed96804fSEric Biggers 	if (err) {
1274ed96804fSEric Biggers 		if (vec->fail) /* expectedly failed to set key? */
1275ed96804fSEric Biggers 			return 0;
1276ed96804fSEric Biggers 		pr_err("alg: aead: %s setkey failed with err %d on test vector %u; flags=%#x\n",
1277ed96804fSEric Biggers 		       driver, err, vec_num, crypto_aead_get_flags(tfm));
1278ed96804fSEric Biggers 		return err;
1279ed96804fSEric Biggers 	}
1280ed96804fSEric Biggers 	if (vec->fail) {
1281ed96804fSEric Biggers 		pr_err("alg: aead: %s setkey unexpectedly succeeded on test vector %u\n",
1282ed96804fSEric Biggers 		       driver, vec_num);
1283ed96804fSEric Biggers 		return -EINVAL;
1284ed96804fSEric Biggers 	}
1285d8a32ac2SJussi Kivilinna 
1286ed96804fSEric Biggers 	/* Set the authentication tag size */
1287ed96804fSEric Biggers 	err = crypto_aead_setauthsize(tfm, authsize);
1288ed96804fSEric Biggers 	if (err) {
1289ed96804fSEric Biggers 		pr_err("alg: aead: %s setauthsize failed with err %d on test vector %u\n",
1290ed96804fSEric Biggers 		       driver, err, vec_num);
1291ed96804fSEric Biggers 		return err;
1292ed96804fSEric Biggers 	}
1293ed96804fSEric Biggers 
1294ed96804fSEric Biggers 	/* The IV must be copied to a buffer, as the algorithm may modify it */
1295ed96804fSEric Biggers 	if (WARN_ON(ivsize > MAX_IVLEN))
1296ed96804fSEric Biggers 		return -EINVAL;
1297ed96804fSEric Biggers 	if (vec->iv)
1298ed96804fSEric Biggers 		memcpy(iv, vec->iv, ivsize);
1299da7f033dSHerbert Xu 	else
1300ed96804fSEric Biggers 		memset(iv, 0, ivsize);
1301da7f033dSHerbert Xu 
1302ed96804fSEric Biggers 	/* Build the src/dst scatterlists */
1303ed96804fSEric Biggers 	input[0].iov_base = (void *)vec->assoc;
1304ed96804fSEric Biggers 	input[0].iov_len = vec->alen;
1305ed96804fSEric Biggers 	input[1].iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext;
1306ed96804fSEric Biggers 	input[1].iov_len = enc ? vec->plen : vec->clen;
1307ed96804fSEric Biggers 	err = build_cipher_test_sglists(tsgls, cfg, alignmask,
1308ed96804fSEric Biggers 					vec->alen + (enc ? vec->plen :
1309ed96804fSEric Biggers 						     vec->clen),
1310ed96804fSEric Biggers 					vec->alen + (enc ? vec->clen :
1311ed96804fSEric Biggers 						     vec->plen),
1312ed96804fSEric Biggers 					input, 2);
1313ed96804fSEric Biggers 	if (err) {
1314ed96804fSEric Biggers 		pr_err("alg: aead: %s %s: error preparing scatterlists for test vector %u, cfg=\"%s\"\n",
1315ed96804fSEric Biggers 		       driver, op, vec_num, cfg->name);
1316ed96804fSEric Biggers 		return err;
1317da7f033dSHerbert Xu 	}
1318da7f033dSHerbert Xu 
1319ed96804fSEric Biggers 	/* Do the actual encryption or decryption */
1320ed96804fSEric Biggers 	testmgr_poison(req->__ctx, crypto_aead_reqsize(tfm));
1321ed96804fSEric Biggers 	aead_request_set_callback(req, req_flags, crypto_req_done, &wait);
1322ed96804fSEric Biggers 	aead_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr,
1323ed96804fSEric Biggers 			       enc ? vec->plen : vec->clen, iv);
1324ed96804fSEric Biggers 	aead_request_set_ad(req, vec->alen);
13256570737cSEric Biggers 	if (cfg->nosimd)
13266570737cSEric Biggers 		crypto_disable_simd_for_test();
13276570737cSEric Biggers 	err = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
13286570737cSEric Biggers 	if (cfg->nosimd)
13296570737cSEric Biggers 		crypto_reenable_simd_for_test();
13306570737cSEric Biggers 	err = crypto_wait_req(err, &wait);
1331ed96804fSEric Biggers 	if (err) {
1332ed96804fSEric Biggers 		if (err == -EBADMSG && vec->novrfy)
1333ed96804fSEric Biggers 			return 0;
1334ed96804fSEric Biggers 		pr_err("alg: aead: %s %s failed with err %d on test vector %u, cfg=\"%s\"\n",
1335ed96804fSEric Biggers 		       driver, op, err, vec_num, cfg->name);
1336ed96804fSEric Biggers 		return err;
1337ed96804fSEric Biggers 	}
1338ed96804fSEric Biggers 	if (vec->novrfy) {
1339ed96804fSEric Biggers 		pr_err("alg: aead: %s %s unexpectedly succeeded on test vector %u, cfg=\"%s\"\n",
1340ed96804fSEric Biggers 		       driver, op, vec_num, cfg->name);
1341ed96804fSEric Biggers 		return -EINVAL;
1342a0d608eeSEric Biggers 	}
134305b1d338SCristian Stoica 
1344a6e5ef9bSEric Biggers 	/* Check that the algorithm didn't overwrite things it shouldn't have */
1345a6e5ef9bSEric Biggers 	if (req->cryptlen != (enc ? vec->plen : vec->clen) ||
1346a6e5ef9bSEric Biggers 	    req->assoclen != vec->alen ||
1347a6e5ef9bSEric Biggers 	    req->iv != iv ||
1348a6e5ef9bSEric Biggers 	    req->src != tsgls->src.sgl_ptr ||
1349a6e5ef9bSEric Biggers 	    req->dst != tsgls->dst.sgl_ptr ||
1350a6e5ef9bSEric Biggers 	    crypto_aead_reqtfm(req) != tfm ||
1351a6e5ef9bSEric Biggers 	    req->base.complete != crypto_req_done ||
1352a6e5ef9bSEric Biggers 	    req->base.flags != req_flags ||
1353a6e5ef9bSEric Biggers 	    req->base.data != &wait) {
1354a6e5ef9bSEric Biggers 		pr_err("alg: aead: %s %s corrupted request struct on test vector %u, cfg=\"%s\"\n",
1355a6e5ef9bSEric Biggers 		       driver, op, vec_num, cfg->name);
1356a6e5ef9bSEric Biggers 		if (req->cryptlen != (enc ? vec->plen : vec->clen))
1357a6e5ef9bSEric Biggers 			pr_err("alg: aead: changed 'req->cryptlen'\n");
1358a6e5ef9bSEric Biggers 		if (req->assoclen != vec->alen)
1359a6e5ef9bSEric Biggers 			pr_err("alg: aead: changed 'req->assoclen'\n");
1360a6e5ef9bSEric Biggers 		if (req->iv != iv)
1361a6e5ef9bSEric Biggers 			pr_err("alg: aead: changed 'req->iv'\n");
1362a6e5ef9bSEric Biggers 		if (req->src != tsgls->src.sgl_ptr)
1363a6e5ef9bSEric Biggers 			pr_err("alg: aead: changed 'req->src'\n");
1364a6e5ef9bSEric Biggers 		if (req->dst != tsgls->dst.sgl_ptr)
1365a6e5ef9bSEric Biggers 			pr_err("alg: aead: changed 'req->dst'\n");
1366a6e5ef9bSEric Biggers 		if (crypto_aead_reqtfm(req) != tfm)
1367a6e5ef9bSEric Biggers 			pr_err("alg: aead: changed 'req->base.tfm'\n");
1368a6e5ef9bSEric Biggers 		if (req->base.complete != crypto_req_done)
1369a6e5ef9bSEric Biggers 			pr_err("alg: aead: changed 'req->base.complete'\n");
1370a6e5ef9bSEric Biggers 		if (req->base.flags != req_flags)
1371a6e5ef9bSEric Biggers 			pr_err("alg: aead: changed 'req->base.flags'\n");
1372a6e5ef9bSEric Biggers 		if (req->base.data != &wait)
1373a6e5ef9bSEric Biggers 			pr_err("alg: aead: changed 'req->base.data'\n");
1374a6e5ef9bSEric Biggers 		return -EINVAL;
1375a6e5ef9bSEric Biggers 	}
1376a6e5ef9bSEric Biggers 	if (is_test_sglist_corrupted(&tsgls->src)) {
1377a6e5ef9bSEric Biggers 		pr_err("alg: aead: %s %s corrupted src sgl on test vector %u, cfg=\"%s\"\n",
1378a6e5ef9bSEric Biggers 		       driver, op, vec_num, cfg->name);
1379a6e5ef9bSEric Biggers 		return -EINVAL;
1380a6e5ef9bSEric Biggers 	}
1381a6e5ef9bSEric Biggers 	if (tsgls->dst.sgl_ptr != tsgls->src.sgl &&
1382a6e5ef9bSEric Biggers 	    is_test_sglist_corrupted(&tsgls->dst)) {
1383a6e5ef9bSEric Biggers 		pr_err("alg: aead: %s %s corrupted dst sgl on test vector %u, cfg=\"%s\"\n",
1384a6e5ef9bSEric Biggers 		       driver, op, vec_num, cfg->name);
1385a6e5ef9bSEric Biggers 		return -EINVAL;
1386a6e5ef9bSEric Biggers 	}
1387a6e5ef9bSEric Biggers 
1388ed96804fSEric Biggers 	/* Check for the correct output (ciphertext or plaintext) */
1389ed96804fSEric Biggers 	err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext,
1390ed96804fSEric Biggers 				    enc ? vec->clen : vec->plen,
1391ed96804fSEric Biggers 				    vec->alen, enc || !cfg->inplace);
1392ed96804fSEric Biggers 	if (err == -EOVERFLOW) {
1393ed96804fSEric Biggers 		pr_err("alg: aead: %s %s overran dst buffer on test vector %u, cfg=\"%s\"\n",
1394ed96804fSEric Biggers 		       driver, op, vec_num, cfg->name);
1395ed96804fSEric Biggers 		return err;
139629b77e5dSHoria Geanta 	}
1397ed96804fSEric Biggers 	if (err) {
1398ed96804fSEric Biggers 		pr_err("alg: aead: %s %s test failed (wrong result) on test vector %u, cfg=\"%s\"\n",
1399ed96804fSEric Biggers 		       driver, op, vec_num, cfg->name);
1400ed96804fSEric Biggers 		return err;
140158dcf548SJussi Kivilinna 	}
140258dcf548SJussi Kivilinna 
140358dcf548SJussi Kivilinna 	return 0;
1404d8a32ac2SJussi Kivilinna }
1405d8a32ac2SJussi Kivilinna 
1406ed96804fSEric Biggers static int test_aead_vec(const char *driver, int enc,
1407ed96804fSEric Biggers 			 const struct aead_testvec *vec, unsigned int vec_num,
1408ed96804fSEric Biggers 			 struct aead_request *req,
1409ed96804fSEric Biggers 			 struct cipher_test_sglists *tsgls)
1410ed96804fSEric Biggers {
1411ed96804fSEric Biggers 	unsigned int i;
1412ed96804fSEric Biggers 	int err;
1413ed96804fSEric Biggers 
1414ed96804fSEric Biggers 	if (enc && vec->novrfy)
1415ed96804fSEric Biggers 		return 0;
1416ed96804fSEric Biggers 
1417ed96804fSEric Biggers 	for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
1418ed96804fSEric Biggers 		err = test_aead_vec_cfg(driver, enc, vec, vec_num,
1419ed96804fSEric Biggers 					&default_cipher_testvec_configs[i],
1420ed96804fSEric Biggers 					req, tsgls);
1421ed96804fSEric Biggers 		if (err)
1422ed96804fSEric Biggers 			return err;
1423ed96804fSEric Biggers 	}
1424ed96804fSEric Biggers 
1425ed96804fSEric Biggers #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1426ed96804fSEric Biggers 	if (!noextratests) {
1427ed96804fSEric Biggers 		struct testvec_config cfg;
1428ed96804fSEric Biggers 		char cfgname[TESTVEC_CONFIG_NAMELEN];
1429ed96804fSEric Biggers 
1430ed96804fSEric Biggers 		for (i = 0; i < fuzz_iterations; i++) {
1431ed96804fSEric Biggers 			generate_random_testvec_config(&cfg, cfgname,
1432ed96804fSEric Biggers 						       sizeof(cfgname));
1433ed96804fSEric Biggers 			err = test_aead_vec_cfg(driver, enc, vec, vec_num,
1434ed96804fSEric Biggers 						&cfg, req, tsgls);
1435ed96804fSEric Biggers 			if (err)
1436ed96804fSEric Biggers 				return err;
1437ed96804fSEric Biggers 		}
1438ed96804fSEric Biggers 	}
1439ed96804fSEric Biggers #endif
1440ed96804fSEric Biggers 	return 0;
1441ed96804fSEric Biggers }
1442ed96804fSEric Biggers 
1443ed96804fSEric Biggers static int test_aead(const char *driver, int enc,
1444ed96804fSEric Biggers 		     const struct aead_test_suite *suite,
1445ed96804fSEric Biggers 		     struct aead_request *req,
1446ed96804fSEric Biggers 		     struct cipher_test_sglists *tsgls)
1447ed96804fSEric Biggers {
1448ed96804fSEric Biggers 	unsigned int i;
1449ed96804fSEric Biggers 	int err;
1450ed96804fSEric Biggers 
1451ed96804fSEric Biggers 	for (i = 0; i < suite->count; i++) {
1452ed96804fSEric Biggers 		err = test_aead_vec(driver, enc, &suite->vecs[i], i, req,
1453ed96804fSEric Biggers 				    tsgls);
1454ed96804fSEric Biggers 		if (err)
1455ed96804fSEric Biggers 			return err;
1456ed96804fSEric Biggers 	}
1457ed96804fSEric Biggers 	return 0;
1458ed96804fSEric Biggers }
1459ed96804fSEric Biggers 
1460ed96804fSEric Biggers static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1461ed96804fSEric Biggers 			 u32 type, u32 mask)
1462ed96804fSEric Biggers {
1463ed96804fSEric Biggers 	const struct aead_test_suite *suite = &desc->suite.aead;
1464ed96804fSEric Biggers 	struct crypto_aead *tfm;
1465ed96804fSEric Biggers 	struct aead_request *req = NULL;
1466ed96804fSEric Biggers 	struct cipher_test_sglists *tsgls = NULL;
1467ed96804fSEric Biggers 	int err;
1468ed96804fSEric Biggers 
1469ed96804fSEric Biggers 	if (suite->count <= 0) {
1470ed96804fSEric Biggers 		pr_err("alg: aead: empty test suite for %s\n", driver);
1471ed96804fSEric Biggers 		return -EINVAL;
1472ed96804fSEric Biggers 	}
1473ed96804fSEric Biggers 
1474ed96804fSEric Biggers 	tfm = crypto_alloc_aead(driver, type, mask);
1475ed96804fSEric Biggers 	if (IS_ERR(tfm)) {
1476ed96804fSEric Biggers 		pr_err("alg: aead: failed to allocate transform for %s: %ld\n",
1477ed96804fSEric Biggers 		       driver, PTR_ERR(tfm));
1478ed96804fSEric Biggers 		return PTR_ERR(tfm);
1479ed96804fSEric Biggers 	}
1480ed96804fSEric Biggers 
1481ed96804fSEric Biggers 	req = aead_request_alloc(tfm, GFP_KERNEL);
1482ed96804fSEric Biggers 	if (!req) {
1483ed96804fSEric Biggers 		pr_err("alg: aead: failed to allocate request for %s\n",
1484ed96804fSEric Biggers 		       driver);
1485ed96804fSEric Biggers 		err = -ENOMEM;
1486ed96804fSEric Biggers 		goto out;
1487ed96804fSEric Biggers 	}
1488ed96804fSEric Biggers 
1489ed96804fSEric Biggers 	tsgls = alloc_cipher_test_sglists();
1490ed96804fSEric Biggers 	if (!tsgls) {
1491ed96804fSEric Biggers 		pr_err("alg: aead: failed to allocate test buffers for %s\n",
1492ed96804fSEric Biggers 		       driver);
1493ed96804fSEric Biggers 		err = -ENOMEM;
1494ed96804fSEric Biggers 		goto out;
1495ed96804fSEric Biggers 	}
1496ed96804fSEric Biggers 
1497ed96804fSEric Biggers 	err = test_aead(driver, ENCRYPT, suite, req, tsgls);
1498ed96804fSEric Biggers 	if (err)
1499ed96804fSEric Biggers 		goto out;
1500ed96804fSEric Biggers 
1501ed96804fSEric Biggers 	err = test_aead(driver, DECRYPT, suite, req, tsgls);
1502ed96804fSEric Biggers out:
1503ed96804fSEric Biggers 	free_cipher_test_sglists(tsgls);
1504ed96804fSEric Biggers 	aead_request_free(req);
1505ed96804fSEric Biggers 	crypto_free_aead(tfm);
1506ed96804fSEric Biggers 	return err;
1507ed96804fSEric Biggers }
1508ed96804fSEric Biggers 
15091aa4ecd9SHerbert Xu static int test_cipher(struct crypto_cipher *tfm, int enc,
1510b13b1e0cSEric Biggers 		       const struct cipher_testvec *template,
1511b13b1e0cSEric Biggers 		       unsigned int tcount)
15121aa4ecd9SHerbert Xu {
15131aa4ecd9SHerbert Xu 	const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
15141aa4ecd9SHerbert Xu 	unsigned int i, j, k;
15151aa4ecd9SHerbert Xu 	char *q;
15161aa4ecd9SHerbert Xu 	const char *e;
151792a4c9feSEric Biggers 	const char *input, *result;
15181aa4ecd9SHerbert Xu 	void *data;
1519f8b0d4d0SHerbert Xu 	char *xbuf[XBUFSIZE];
1520f8b0d4d0SHerbert Xu 	int ret = -ENOMEM;
1521f8b0d4d0SHerbert Xu 
1522f8b0d4d0SHerbert Xu 	if (testmgr_alloc_buf(xbuf))
1523f8b0d4d0SHerbert Xu 		goto out_nobuf;
15241aa4ecd9SHerbert Xu 
15251aa4ecd9SHerbert Xu 	if (enc == ENCRYPT)
15261aa4ecd9SHerbert Xu 	        e = "encryption";
15271aa4ecd9SHerbert Xu 	else
15281aa4ecd9SHerbert Xu 		e = "decryption";
15291aa4ecd9SHerbert Xu 
15301aa4ecd9SHerbert Xu 	j = 0;
15311aa4ecd9SHerbert Xu 	for (i = 0; i < tcount; i++) {
15321aa4ecd9SHerbert Xu 
153310faa8c0SStephan Mueller 		if (fips_enabled && template[i].fips_skip)
153410faa8c0SStephan Mueller 			continue;
153510faa8c0SStephan Mueller 
153692a4c9feSEric Biggers 		input  = enc ? template[i].ptext : template[i].ctext;
153792a4c9feSEric Biggers 		result = enc ? template[i].ctext : template[i].ptext;
15381aa4ecd9SHerbert Xu 		j++;
15391aa4ecd9SHerbert Xu 
1540fd57f22aSHerbert Xu 		ret = -EINVAL;
154192a4c9feSEric Biggers 		if (WARN_ON(template[i].len > PAGE_SIZE))
1542fd57f22aSHerbert Xu 			goto out;
1543fd57f22aSHerbert Xu 
15441aa4ecd9SHerbert Xu 		data = xbuf[0];
154592a4c9feSEric Biggers 		memcpy(data, input, template[i].len);
15461aa4ecd9SHerbert Xu 
15471aa4ecd9SHerbert Xu 		crypto_cipher_clear_flags(tfm, ~0);
15481aa4ecd9SHerbert Xu 		if (template[i].wk)
1549231baecdSEric Biggers 			crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
15501aa4ecd9SHerbert Xu 
15511aa4ecd9SHerbert Xu 		ret = crypto_cipher_setkey(tfm, template[i].key,
15521aa4ecd9SHerbert Xu 					   template[i].klen);
15530fae0c1eSYanjiang Jin 		if (template[i].fail == !ret) {
15541aa4ecd9SHerbert Xu 			printk(KERN_ERR "alg: cipher: setkey failed "
15551aa4ecd9SHerbert Xu 			       "on test %d for %s: flags=%x\n", j,
15561aa4ecd9SHerbert Xu 			       algo, crypto_cipher_get_flags(tfm));
15571aa4ecd9SHerbert Xu 			goto out;
15581aa4ecd9SHerbert Xu 		} else if (ret)
15591aa4ecd9SHerbert Xu 			continue;
15601aa4ecd9SHerbert Xu 
156192a4c9feSEric Biggers 		for (k = 0; k < template[i].len;
15621aa4ecd9SHerbert Xu 		     k += crypto_cipher_blocksize(tfm)) {
15631aa4ecd9SHerbert Xu 			if (enc)
15641aa4ecd9SHerbert Xu 				crypto_cipher_encrypt_one(tfm, data + k,
15651aa4ecd9SHerbert Xu 							  data + k);
15661aa4ecd9SHerbert Xu 			else
15671aa4ecd9SHerbert Xu 				crypto_cipher_decrypt_one(tfm, data + k,
15681aa4ecd9SHerbert Xu 							  data + k);
15691aa4ecd9SHerbert Xu 		}
15701aa4ecd9SHerbert Xu 
15711aa4ecd9SHerbert Xu 		q = data;
157292a4c9feSEric Biggers 		if (memcmp(q, result, template[i].len)) {
15731aa4ecd9SHerbert Xu 			printk(KERN_ERR "alg: cipher: Test %d failed "
15741aa4ecd9SHerbert Xu 			       "on %s for %s\n", j, e, algo);
157592a4c9feSEric Biggers 			hexdump(q, template[i].len);
15761aa4ecd9SHerbert Xu 			ret = -EINVAL;
15771aa4ecd9SHerbert Xu 			goto out;
15781aa4ecd9SHerbert Xu 		}
15791aa4ecd9SHerbert Xu 	}
15801aa4ecd9SHerbert Xu 
15811aa4ecd9SHerbert Xu 	ret = 0;
15821aa4ecd9SHerbert Xu 
15831aa4ecd9SHerbert Xu out:
1584f8b0d4d0SHerbert Xu 	testmgr_free_buf(xbuf);
1585f8b0d4d0SHerbert Xu out_nobuf:
15861aa4ecd9SHerbert Xu 	return ret;
15871aa4ecd9SHerbert Xu }
15881aa4ecd9SHerbert Xu 
15894e7babbaSEric Biggers static int test_skcipher_vec_cfg(const char *driver, int enc,
15904e7babbaSEric Biggers 				 const struct cipher_testvec *vec,
15914e7babbaSEric Biggers 				 unsigned int vec_num,
15924e7babbaSEric Biggers 				 const struct testvec_config *cfg,
15934e7babbaSEric Biggers 				 struct skcipher_request *req,
15944e7babbaSEric Biggers 				 struct cipher_test_sglists *tsgls)
1595da7f033dSHerbert Xu {
15964e7babbaSEric Biggers 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
15974e7babbaSEric Biggers 	const unsigned int alignmask = crypto_skcipher_alignmask(tfm);
15984e7babbaSEric Biggers 	const unsigned int ivsize = crypto_skcipher_ivsize(tfm);
15994e7babbaSEric Biggers 	const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
16004e7babbaSEric Biggers 	const char *op = enc ? "encryption" : "decryption";
16014e7babbaSEric Biggers 	DECLARE_CRYPTO_WAIT(wait);
16024e7babbaSEric Biggers 	u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN];
16034e7babbaSEric Biggers 	u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) +
16044e7babbaSEric Biggers 		 cfg->iv_offset +
16054e7babbaSEric Biggers 		 (cfg->iv_offset_relative_to_alignmask ? alignmask : 0);
16064e7babbaSEric Biggers 	struct kvec input;
16074e7babbaSEric Biggers 	int err;
1608f8b0d4d0SHerbert Xu 
16094e7babbaSEric Biggers 	/* Set the key */
16104e7babbaSEric Biggers 	if (vec->wk)
1611231baecdSEric Biggers 		crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
1612da7f033dSHerbert Xu 	else
16134e7babbaSEric Biggers 		crypto_skcipher_clear_flags(tfm,
16144e7babbaSEric Biggers 					    CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
16154e7babbaSEric Biggers 	err = crypto_skcipher_setkey(tfm, vec->key, vec->klen);
16164e7babbaSEric Biggers 	if (err) {
16174e7babbaSEric Biggers 		if (vec->fail) /* expectedly failed to set key? */
16184e7babbaSEric Biggers 			return 0;
16194e7babbaSEric Biggers 		pr_err("alg: skcipher: %s setkey failed with err %d on test vector %u; flags=%#x\n",
16204e7babbaSEric Biggers 		       driver, err, vec_num, crypto_skcipher_get_flags(tfm));
16214e7babbaSEric Biggers 		return err;
16224e7babbaSEric Biggers 	}
16234e7babbaSEric Biggers 	if (vec->fail) {
16244e7babbaSEric Biggers 		pr_err("alg: skcipher: %s setkey unexpectedly succeeded on test vector %u\n",
16254e7babbaSEric Biggers 		       driver, vec_num);
16264e7babbaSEric Biggers 		return -EINVAL;
162708d6af8cSJussi Kivilinna 	}
1628da7f033dSHerbert Xu 
16294e7babbaSEric Biggers 	/* The IV must be copied to a buffer, as the algorithm may modify it */
16304e7babbaSEric Biggers 	if (ivsize) {
16314e7babbaSEric Biggers 		if (WARN_ON(ivsize > MAX_IVLEN))
16324e7babbaSEric Biggers 			return -EINVAL;
16338efd972eSEric Biggers 		if (vec->generates_iv && !enc)
16348efd972eSEric Biggers 			memcpy(iv, vec->iv_out, ivsize);
16358efd972eSEric Biggers 		else if (vec->iv)
16364e7babbaSEric Biggers 			memcpy(iv, vec->iv, ivsize);
163708d6af8cSJussi Kivilinna 		else
16384e7babbaSEric Biggers 			memset(iv, 0, ivsize);
16394e7babbaSEric Biggers 	} else {
16404e7babbaSEric Biggers 		if (vec->generates_iv) {
16414e7babbaSEric Biggers 			pr_err("alg: skcipher: %s has ivsize=0 but test vector %u generates IV!\n",
16424e7babbaSEric Biggers 			       driver, vec_num);
16434e7babbaSEric Biggers 			return -EINVAL;
16444e7babbaSEric Biggers 		}
16454e7babbaSEric Biggers 		iv = NULL;
1646da7f033dSHerbert Xu 	}
1647da7f033dSHerbert Xu 
16484e7babbaSEric Biggers 	/* Build the src/dst scatterlists */
16494e7babbaSEric Biggers 	input.iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext;
16504e7babbaSEric Biggers 	input.iov_len = vec->len;
16514e7babbaSEric Biggers 	err = build_cipher_test_sglists(tsgls, cfg, alignmask,
16524e7babbaSEric Biggers 					vec->len, vec->len, &input, 1);
16534e7babbaSEric Biggers 	if (err) {
16544e7babbaSEric Biggers 		pr_err("alg: skcipher: %s %s: error preparing scatterlists for test vector %u, cfg=\"%s\"\n",
16554e7babbaSEric Biggers 		       driver, op, vec_num, cfg->name);
16564e7babbaSEric Biggers 		return err;
1657da7f033dSHerbert Xu 	}
1658da7f033dSHerbert Xu 
16594e7babbaSEric Biggers 	/* Do the actual encryption or decryption */
16604e7babbaSEric Biggers 	testmgr_poison(req->__ctx, crypto_skcipher_reqsize(tfm));
16614e7babbaSEric Biggers 	skcipher_request_set_callback(req, req_flags, crypto_req_done, &wait);
16624e7babbaSEric Biggers 	skcipher_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr,
16634e7babbaSEric Biggers 				   vec->len, iv);
16646570737cSEric Biggers 	if (cfg->nosimd)
16656570737cSEric Biggers 		crypto_disable_simd_for_test();
16666570737cSEric Biggers 	err = enc ? crypto_skcipher_encrypt(req) : crypto_skcipher_decrypt(req);
16676570737cSEric Biggers 	if (cfg->nosimd)
16686570737cSEric Biggers 		crypto_reenable_simd_for_test();
16696570737cSEric Biggers 	err = crypto_wait_req(err, &wait);
16704e7babbaSEric Biggers 	if (err) {
16714e7babbaSEric Biggers 		pr_err("alg: skcipher: %s %s failed with err %d on test vector %u, cfg=\"%s\"\n",
16724e7babbaSEric Biggers 		       driver, op, err, vec_num, cfg->name);
16734e7babbaSEric Biggers 		return err;
1674da7f033dSHerbert Xu 	}
1675da7f033dSHerbert Xu 
1676fa353c99SEric Biggers 	/* Check that the algorithm didn't overwrite things it shouldn't have */
1677fa353c99SEric Biggers 	if (req->cryptlen != vec->len ||
1678fa353c99SEric Biggers 	    req->iv != iv ||
1679fa353c99SEric Biggers 	    req->src != tsgls->src.sgl_ptr ||
1680fa353c99SEric Biggers 	    req->dst != tsgls->dst.sgl_ptr ||
1681fa353c99SEric Biggers 	    crypto_skcipher_reqtfm(req) != tfm ||
1682fa353c99SEric Biggers 	    req->base.complete != crypto_req_done ||
1683fa353c99SEric Biggers 	    req->base.flags != req_flags ||
1684fa353c99SEric Biggers 	    req->base.data != &wait) {
1685fa353c99SEric Biggers 		pr_err("alg: skcipher: %s %s corrupted request struct on test vector %u, cfg=\"%s\"\n",
1686fa353c99SEric Biggers 		       driver, op, vec_num, cfg->name);
1687fa353c99SEric Biggers 		if (req->cryptlen != vec->len)
1688fa353c99SEric Biggers 			pr_err("alg: skcipher: changed 'req->cryptlen'\n");
1689fa353c99SEric Biggers 		if (req->iv != iv)
1690fa353c99SEric Biggers 			pr_err("alg: skcipher: changed 'req->iv'\n");
1691fa353c99SEric Biggers 		if (req->src != tsgls->src.sgl_ptr)
1692fa353c99SEric Biggers 			pr_err("alg: skcipher: changed 'req->src'\n");
1693fa353c99SEric Biggers 		if (req->dst != tsgls->dst.sgl_ptr)
1694fa353c99SEric Biggers 			pr_err("alg: skcipher: changed 'req->dst'\n");
1695fa353c99SEric Biggers 		if (crypto_skcipher_reqtfm(req) != tfm)
1696fa353c99SEric Biggers 			pr_err("alg: skcipher: changed 'req->base.tfm'\n");
1697fa353c99SEric Biggers 		if (req->base.complete != crypto_req_done)
1698fa353c99SEric Biggers 			pr_err("alg: skcipher: changed 'req->base.complete'\n");
1699fa353c99SEric Biggers 		if (req->base.flags != req_flags)
1700fa353c99SEric Biggers 			pr_err("alg: skcipher: changed 'req->base.flags'\n");
1701fa353c99SEric Biggers 		if (req->base.data != &wait)
1702fa353c99SEric Biggers 			pr_err("alg: skcipher: changed 'req->base.data'\n");
1703fa353c99SEric Biggers 		return -EINVAL;
1704fa353c99SEric Biggers 	}
1705fa353c99SEric Biggers 	if (is_test_sglist_corrupted(&tsgls->src)) {
1706fa353c99SEric Biggers 		pr_err("alg: skcipher: %s %s corrupted src sgl on test vector %u, cfg=\"%s\"\n",
1707fa353c99SEric Biggers 		       driver, op, vec_num, cfg->name);
1708fa353c99SEric Biggers 		return -EINVAL;
1709fa353c99SEric Biggers 	}
1710fa353c99SEric Biggers 	if (tsgls->dst.sgl_ptr != tsgls->src.sgl &&
1711fa353c99SEric Biggers 	    is_test_sglist_corrupted(&tsgls->dst)) {
1712fa353c99SEric Biggers 		pr_err("alg: skcipher: %s %s corrupted dst sgl on test vector %u, cfg=\"%s\"\n",
1713fa353c99SEric Biggers 		       driver, op, vec_num, cfg->name);
1714fa353c99SEric Biggers 		return -EINVAL;
1715fa353c99SEric Biggers 	}
1716fa353c99SEric Biggers 
17174e7babbaSEric Biggers 	/* Check for the correct output (ciphertext or plaintext) */
17184e7babbaSEric Biggers 	err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext,
17194e7babbaSEric Biggers 				    vec->len, 0, true);
17204e7babbaSEric Biggers 	if (err == -EOVERFLOW) {
17214e7babbaSEric Biggers 		pr_err("alg: skcipher: %s %s overran dst buffer on test vector %u, cfg=\"%s\"\n",
17224e7babbaSEric Biggers 		       driver, op, vec_num, cfg->name);
17234e7babbaSEric Biggers 		return err;
17244e7babbaSEric Biggers 	}
17254e7babbaSEric Biggers 	if (err) {
17264e7babbaSEric Biggers 		pr_err("alg: skcipher: %s %s test failed (wrong result) on test vector %u, cfg=\"%s\"\n",
17274e7babbaSEric Biggers 		       driver, op, vec_num, cfg->name);
17284e7babbaSEric Biggers 		return err;
17294e7babbaSEric Biggers 	}
173008d6af8cSJussi Kivilinna 
17314e7babbaSEric Biggers 	/* If applicable, check that the algorithm generated the correct IV */
17328efd972eSEric Biggers 	if (vec->iv_out && memcmp(iv, vec->iv_out, ivsize) != 0) {
17334e7babbaSEric Biggers 		pr_err("alg: skcipher: %s %s test failed (wrong output IV) on test vector %u, cfg=\"%s\"\n",
17344e7babbaSEric Biggers 		       driver, op, vec_num, cfg->name);
17354e7babbaSEric Biggers 		hexdump(iv, ivsize);
17364e7babbaSEric Biggers 		return -EINVAL;
17373a338f20SJussi Kivilinna 	}
17383a338f20SJussi Kivilinna 
17393a338f20SJussi Kivilinna 	return 0;
174008d6af8cSJussi Kivilinna }
174108d6af8cSJussi Kivilinna 
17424e7babbaSEric Biggers static int test_skcipher_vec(const char *driver, int enc,
17434e7babbaSEric Biggers 			     const struct cipher_testvec *vec,
17444e7babbaSEric Biggers 			     unsigned int vec_num,
17454e7babbaSEric Biggers 			     struct skcipher_request *req,
17464e7babbaSEric Biggers 			     struct cipher_test_sglists *tsgls)
17474e7babbaSEric Biggers {
17484e7babbaSEric Biggers 	unsigned int i;
17494e7babbaSEric Biggers 	int err;
17504e7babbaSEric Biggers 
17514e7babbaSEric Biggers 	if (fips_enabled && vec->fips_skip)
17524e7babbaSEric Biggers 		return 0;
17534e7babbaSEric Biggers 
17544e7babbaSEric Biggers 	for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
17554e7babbaSEric Biggers 		err = test_skcipher_vec_cfg(driver, enc, vec, vec_num,
17564e7babbaSEric Biggers 					    &default_cipher_testvec_configs[i],
17574e7babbaSEric Biggers 					    req, tsgls);
17584e7babbaSEric Biggers 		if (err)
17594e7babbaSEric Biggers 			return err;
17604e7babbaSEric Biggers 	}
17614e7babbaSEric Biggers 
17624e7babbaSEric Biggers #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
17634e7babbaSEric Biggers 	if (!noextratests) {
17644e7babbaSEric Biggers 		struct testvec_config cfg;
17654e7babbaSEric Biggers 		char cfgname[TESTVEC_CONFIG_NAMELEN];
17664e7babbaSEric Biggers 
17674e7babbaSEric Biggers 		for (i = 0; i < fuzz_iterations; i++) {
17684e7babbaSEric Biggers 			generate_random_testvec_config(&cfg, cfgname,
17694e7babbaSEric Biggers 						       sizeof(cfgname));
17704e7babbaSEric Biggers 			err = test_skcipher_vec_cfg(driver, enc, vec, vec_num,
17714e7babbaSEric Biggers 						    &cfg, req, tsgls);
17724e7babbaSEric Biggers 			if (err)
17734e7babbaSEric Biggers 				return err;
17744e7babbaSEric Biggers 		}
17754e7babbaSEric Biggers 	}
17764e7babbaSEric Biggers #endif
17774e7babbaSEric Biggers 	return 0;
17784e7babbaSEric Biggers }
17794e7babbaSEric Biggers 
17804e7babbaSEric Biggers static int test_skcipher(const char *driver, int enc,
17814e7babbaSEric Biggers 			 const struct cipher_test_suite *suite,
17824e7babbaSEric Biggers 			 struct skcipher_request *req,
17834e7babbaSEric Biggers 			 struct cipher_test_sglists *tsgls)
17844e7babbaSEric Biggers {
17854e7babbaSEric Biggers 	unsigned int i;
17864e7babbaSEric Biggers 	int err;
17874e7babbaSEric Biggers 
17884e7babbaSEric Biggers 	for (i = 0; i < suite->count; i++) {
17894e7babbaSEric Biggers 		err = test_skcipher_vec(driver, enc, &suite->vecs[i], i, req,
17904e7babbaSEric Biggers 					tsgls);
17914e7babbaSEric Biggers 		if (err)
17924e7babbaSEric Biggers 			return err;
17934e7babbaSEric Biggers 	}
17944e7babbaSEric Biggers 	return 0;
17954e7babbaSEric Biggers }
17964e7babbaSEric Biggers 
17974e7babbaSEric Biggers static int alg_test_skcipher(const struct alg_test_desc *desc,
17984e7babbaSEric Biggers 			     const char *driver, u32 type, u32 mask)
17994e7babbaSEric Biggers {
18004e7babbaSEric Biggers 	const struct cipher_test_suite *suite = &desc->suite.cipher;
18014e7babbaSEric Biggers 	struct crypto_skcipher *tfm;
18024e7babbaSEric Biggers 	struct skcipher_request *req = NULL;
18034e7babbaSEric Biggers 	struct cipher_test_sglists *tsgls = NULL;
18044e7babbaSEric Biggers 	int err;
18054e7babbaSEric Biggers 
18064e7babbaSEric Biggers 	if (suite->count <= 0) {
18074e7babbaSEric Biggers 		pr_err("alg: skcipher: empty test suite for %s\n", driver);
18084e7babbaSEric Biggers 		return -EINVAL;
18094e7babbaSEric Biggers 	}
18104e7babbaSEric Biggers 
18114e7babbaSEric Biggers 	tfm = crypto_alloc_skcipher(driver, type, mask);
18124e7babbaSEric Biggers 	if (IS_ERR(tfm)) {
18134e7babbaSEric Biggers 		pr_err("alg: skcipher: failed to allocate transform for %s: %ld\n",
18144e7babbaSEric Biggers 		       driver, PTR_ERR(tfm));
18154e7babbaSEric Biggers 		return PTR_ERR(tfm);
18164e7babbaSEric Biggers 	}
18174e7babbaSEric Biggers 
18184e7babbaSEric Biggers 	req = skcipher_request_alloc(tfm, GFP_KERNEL);
18194e7babbaSEric Biggers 	if (!req) {
18204e7babbaSEric Biggers 		pr_err("alg: skcipher: failed to allocate request for %s\n",
18214e7babbaSEric Biggers 		       driver);
18224e7babbaSEric Biggers 		err = -ENOMEM;
18234e7babbaSEric Biggers 		goto out;
18244e7babbaSEric Biggers 	}
18254e7babbaSEric Biggers 
18264e7babbaSEric Biggers 	tsgls = alloc_cipher_test_sglists();
18274e7babbaSEric Biggers 	if (!tsgls) {
18284e7babbaSEric Biggers 		pr_err("alg: skcipher: failed to allocate test buffers for %s\n",
18294e7babbaSEric Biggers 		       driver);
18304e7babbaSEric Biggers 		err = -ENOMEM;
18314e7babbaSEric Biggers 		goto out;
18324e7babbaSEric Biggers 	}
18334e7babbaSEric Biggers 
18344e7babbaSEric Biggers 	err = test_skcipher(driver, ENCRYPT, suite, req, tsgls);
18354e7babbaSEric Biggers 	if (err)
18364e7babbaSEric Biggers 		goto out;
18374e7babbaSEric Biggers 
18384e7babbaSEric Biggers 	err = test_skcipher(driver, DECRYPT, suite, req, tsgls);
18394e7babbaSEric Biggers out:
18404e7babbaSEric Biggers 	free_cipher_test_sglists(tsgls);
18414e7babbaSEric Biggers 	skcipher_request_free(req);
18424e7babbaSEric Biggers 	crypto_free_skcipher(tfm);
18434e7babbaSEric Biggers 	return err;
18444e7babbaSEric Biggers }
18454e7babbaSEric Biggers 
1846b13b1e0cSEric Biggers static int test_comp(struct crypto_comp *tfm,
1847b13b1e0cSEric Biggers 		     const struct comp_testvec *ctemplate,
1848b13b1e0cSEric Biggers 		     const struct comp_testvec *dtemplate,
1849b13b1e0cSEric Biggers 		     int ctcount, int dtcount)
1850da7f033dSHerbert Xu {
1851da7f033dSHerbert Xu 	const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
185233607384SMahipal Challa 	char *output, *decomp_output;
1853da7f033dSHerbert Xu 	unsigned int i;
1854da7f033dSHerbert Xu 	int ret;
1855da7f033dSHerbert Xu 
185633607384SMahipal Challa 	output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
185733607384SMahipal Challa 	if (!output)
185833607384SMahipal Challa 		return -ENOMEM;
185933607384SMahipal Challa 
186033607384SMahipal Challa 	decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
186133607384SMahipal Challa 	if (!decomp_output) {
186233607384SMahipal Challa 		kfree(output);
186333607384SMahipal Challa 		return -ENOMEM;
186433607384SMahipal Challa 	}
186533607384SMahipal Challa 
1866da7f033dSHerbert Xu 	for (i = 0; i < ctcount; i++) {
1867c79cf910SGeert Uytterhoeven 		int ilen;
1868c79cf910SGeert Uytterhoeven 		unsigned int dlen = COMP_BUF_SIZE;
1869da7f033dSHerbert Xu 
187022a8118dSMichael Schupikov 		memset(output, 0, COMP_BUF_SIZE);
187122a8118dSMichael Schupikov 		memset(decomp_output, 0, COMP_BUF_SIZE);
1872da7f033dSHerbert Xu 
1873da7f033dSHerbert Xu 		ilen = ctemplate[i].inlen;
1874da7f033dSHerbert Xu 		ret = crypto_comp_compress(tfm, ctemplate[i].input,
187533607384SMahipal Challa 					   ilen, output, &dlen);
1876da7f033dSHerbert Xu 		if (ret) {
1877da7f033dSHerbert Xu 			printk(KERN_ERR "alg: comp: compression failed "
1878da7f033dSHerbert Xu 			       "on test %d for %s: ret=%d\n", i + 1, algo,
1879da7f033dSHerbert Xu 			       -ret);
1880da7f033dSHerbert Xu 			goto out;
1881da7f033dSHerbert Xu 		}
1882da7f033dSHerbert Xu 
188333607384SMahipal Challa 		ilen = dlen;
188433607384SMahipal Challa 		dlen = COMP_BUF_SIZE;
188533607384SMahipal Challa 		ret = crypto_comp_decompress(tfm, output,
188633607384SMahipal Challa 					     ilen, decomp_output, &dlen);
188733607384SMahipal Challa 		if (ret) {
188833607384SMahipal Challa 			pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n",
188933607384SMahipal Challa 			       i + 1, algo, -ret);
189033607384SMahipal Challa 			goto out;
189133607384SMahipal Challa 		}
189233607384SMahipal Challa 
189333607384SMahipal Challa 		if (dlen != ctemplate[i].inlen) {
1894b812eb00SGeert Uytterhoeven 			printk(KERN_ERR "alg: comp: Compression test %d "
1895b812eb00SGeert Uytterhoeven 			       "failed for %s: output len = %d\n", i + 1, algo,
1896b812eb00SGeert Uytterhoeven 			       dlen);
1897b812eb00SGeert Uytterhoeven 			ret = -EINVAL;
1898b812eb00SGeert Uytterhoeven 			goto out;
1899b812eb00SGeert Uytterhoeven 		}
1900b812eb00SGeert Uytterhoeven 
190133607384SMahipal Challa 		if (memcmp(decomp_output, ctemplate[i].input,
190233607384SMahipal Challa 			   ctemplate[i].inlen)) {
190333607384SMahipal Challa 			pr_err("alg: comp: compression failed: output differs: on test %d for %s\n",
190433607384SMahipal Challa 			       i + 1, algo);
190533607384SMahipal Challa 			hexdump(decomp_output, dlen);
1906da7f033dSHerbert Xu 			ret = -EINVAL;
1907da7f033dSHerbert Xu 			goto out;
1908da7f033dSHerbert Xu 		}
1909da7f033dSHerbert Xu 	}
1910da7f033dSHerbert Xu 
1911da7f033dSHerbert Xu 	for (i = 0; i < dtcount; i++) {
1912c79cf910SGeert Uytterhoeven 		int ilen;
1913c79cf910SGeert Uytterhoeven 		unsigned int dlen = COMP_BUF_SIZE;
1914da7f033dSHerbert Xu 
191522a8118dSMichael Schupikov 		memset(decomp_output, 0, COMP_BUF_SIZE);
1916da7f033dSHerbert Xu 
1917da7f033dSHerbert Xu 		ilen = dtemplate[i].inlen;
1918da7f033dSHerbert Xu 		ret = crypto_comp_decompress(tfm, dtemplate[i].input,
191933607384SMahipal Challa 					     ilen, decomp_output, &dlen);
1920da7f033dSHerbert Xu 		if (ret) {
1921da7f033dSHerbert Xu 			printk(KERN_ERR "alg: comp: decompression failed "
1922da7f033dSHerbert Xu 			       "on test %d for %s: ret=%d\n", i + 1, algo,
1923da7f033dSHerbert Xu 			       -ret);
1924da7f033dSHerbert Xu 			goto out;
1925da7f033dSHerbert Xu 		}
1926da7f033dSHerbert Xu 
1927b812eb00SGeert Uytterhoeven 		if (dlen != dtemplate[i].outlen) {
1928b812eb00SGeert Uytterhoeven 			printk(KERN_ERR "alg: comp: Decompression test %d "
1929b812eb00SGeert Uytterhoeven 			       "failed for %s: output len = %d\n", i + 1, algo,
1930b812eb00SGeert Uytterhoeven 			       dlen);
1931b812eb00SGeert Uytterhoeven 			ret = -EINVAL;
1932b812eb00SGeert Uytterhoeven 			goto out;
1933b812eb00SGeert Uytterhoeven 		}
1934b812eb00SGeert Uytterhoeven 
193533607384SMahipal Challa 		if (memcmp(decomp_output, dtemplate[i].output, dlen)) {
1936da7f033dSHerbert Xu 			printk(KERN_ERR "alg: comp: Decompression test %d "
1937da7f033dSHerbert Xu 			       "failed for %s\n", i + 1, algo);
193833607384SMahipal Challa 			hexdump(decomp_output, dlen);
1939da7f033dSHerbert Xu 			ret = -EINVAL;
1940da7f033dSHerbert Xu 			goto out;
1941da7f033dSHerbert Xu 		}
1942da7f033dSHerbert Xu 	}
1943da7f033dSHerbert Xu 
1944da7f033dSHerbert Xu 	ret = 0;
1945da7f033dSHerbert Xu 
1946da7f033dSHerbert Xu out:
194733607384SMahipal Challa 	kfree(decomp_output);
194833607384SMahipal Challa 	kfree(output);
1949da7f033dSHerbert Xu 	return ret;
1950da7f033dSHerbert Xu }
1951da7f033dSHerbert Xu 
1952b13b1e0cSEric Biggers static int test_acomp(struct crypto_acomp *tfm,
1953b13b1e0cSEric Biggers 			      const struct comp_testvec *ctemplate,
1954b13b1e0cSEric Biggers 		      const struct comp_testvec *dtemplate,
1955b13b1e0cSEric Biggers 		      int ctcount, int dtcount)
1956d7db7a88SGiovanni Cabiddu {
1957d7db7a88SGiovanni Cabiddu 	const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
1958d7db7a88SGiovanni Cabiddu 	unsigned int i;
1959a9943a0aSGiovanni Cabiddu 	char *output, *decomp_out;
1960d7db7a88SGiovanni Cabiddu 	int ret;
1961d7db7a88SGiovanni Cabiddu 	struct scatterlist src, dst;
1962d7db7a88SGiovanni Cabiddu 	struct acomp_req *req;
19637f397136SGilad Ben-Yossef 	struct crypto_wait wait;
1964d7db7a88SGiovanni Cabiddu 
1965eb095593SEric Biggers 	output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1966eb095593SEric Biggers 	if (!output)
1967eb095593SEric Biggers 		return -ENOMEM;
1968eb095593SEric Biggers 
1969a9943a0aSGiovanni Cabiddu 	decomp_out = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
1970a9943a0aSGiovanni Cabiddu 	if (!decomp_out) {
1971a9943a0aSGiovanni Cabiddu 		kfree(output);
1972a9943a0aSGiovanni Cabiddu 		return -ENOMEM;
1973a9943a0aSGiovanni Cabiddu 	}
1974a9943a0aSGiovanni Cabiddu 
1975d7db7a88SGiovanni Cabiddu 	for (i = 0; i < ctcount; i++) {
1976d7db7a88SGiovanni Cabiddu 		unsigned int dlen = COMP_BUF_SIZE;
1977d7db7a88SGiovanni Cabiddu 		int ilen = ctemplate[i].inlen;
197802608e02SLaura Abbott 		void *input_vec;
1979d7db7a88SGiovanni Cabiddu 
1980d2110224SEric Biggers 		input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
198102608e02SLaura Abbott 		if (!input_vec) {
198202608e02SLaura Abbott 			ret = -ENOMEM;
198302608e02SLaura Abbott 			goto out;
198402608e02SLaura Abbott 		}
198502608e02SLaura Abbott 
1986eb095593SEric Biggers 		memset(output, 0, dlen);
19877f397136SGilad Ben-Yossef 		crypto_init_wait(&wait);
198802608e02SLaura Abbott 		sg_init_one(&src, input_vec, ilen);
1989d7db7a88SGiovanni Cabiddu 		sg_init_one(&dst, output, dlen);
1990d7db7a88SGiovanni Cabiddu 
1991d7db7a88SGiovanni Cabiddu 		req = acomp_request_alloc(tfm);
1992d7db7a88SGiovanni Cabiddu 		if (!req) {
1993d7db7a88SGiovanni Cabiddu 			pr_err("alg: acomp: request alloc failed for %s\n",
1994d7db7a88SGiovanni Cabiddu 			       algo);
199502608e02SLaura Abbott 			kfree(input_vec);
1996d7db7a88SGiovanni Cabiddu 			ret = -ENOMEM;
1997d7db7a88SGiovanni Cabiddu 			goto out;
1998d7db7a88SGiovanni Cabiddu 		}
1999d7db7a88SGiovanni Cabiddu 
2000d7db7a88SGiovanni Cabiddu 		acomp_request_set_params(req, &src, &dst, ilen, dlen);
2001d7db7a88SGiovanni Cabiddu 		acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
20027f397136SGilad Ben-Yossef 					   crypto_req_done, &wait);
2003d7db7a88SGiovanni Cabiddu 
20047f397136SGilad Ben-Yossef 		ret = crypto_wait_req(crypto_acomp_compress(req), &wait);
2005d7db7a88SGiovanni Cabiddu 		if (ret) {
2006d7db7a88SGiovanni Cabiddu 			pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
2007d7db7a88SGiovanni Cabiddu 			       i + 1, algo, -ret);
200802608e02SLaura Abbott 			kfree(input_vec);
2009d7db7a88SGiovanni Cabiddu 			acomp_request_free(req);
2010d7db7a88SGiovanni Cabiddu 			goto out;
2011d7db7a88SGiovanni Cabiddu 		}
2012d7db7a88SGiovanni Cabiddu 
2013a9943a0aSGiovanni Cabiddu 		ilen = req->dlen;
2014a9943a0aSGiovanni Cabiddu 		dlen = COMP_BUF_SIZE;
2015a9943a0aSGiovanni Cabiddu 		sg_init_one(&src, output, ilen);
2016a9943a0aSGiovanni Cabiddu 		sg_init_one(&dst, decomp_out, dlen);
20177f397136SGilad Ben-Yossef 		crypto_init_wait(&wait);
2018a9943a0aSGiovanni Cabiddu 		acomp_request_set_params(req, &src, &dst, ilen, dlen);
2019a9943a0aSGiovanni Cabiddu 
20207f397136SGilad Ben-Yossef 		ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
2021a9943a0aSGiovanni Cabiddu 		if (ret) {
2022a9943a0aSGiovanni Cabiddu 			pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
2023a9943a0aSGiovanni Cabiddu 			       i + 1, algo, -ret);
2024a9943a0aSGiovanni Cabiddu 			kfree(input_vec);
2025a9943a0aSGiovanni Cabiddu 			acomp_request_free(req);
2026a9943a0aSGiovanni Cabiddu 			goto out;
2027a9943a0aSGiovanni Cabiddu 		}
2028a9943a0aSGiovanni Cabiddu 
2029a9943a0aSGiovanni Cabiddu 		if (req->dlen != ctemplate[i].inlen) {
2030d7db7a88SGiovanni Cabiddu 			pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
2031d7db7a88SGiovanni Cabiddu 			       i + 1, algo, req->dlen);
2032d7db7a88SGiovanni Cabiddu 			ret = -EINVAL;
203302608e02SLaura Abbott 			kfree(input_vec);
2034d7db7a88SGiovanni Cabiddu 			acomp_request_free(req);
2035d7db7a88SGiovanni Cabiddu 			goto out;
2036d7db7a88SGiovanni Cabiddu 		}
2037d7db7a88SGiovanni Cabiddu 
2038a9943a0aSGiovanni Cabiddu 		if (memcmp(input_vec, decomp_out, req->dlen)) {
2039d7db7a88SGiovanni Cabiddu 			pr_err("alg: acomp: Compression test %d failed for %s\n",
2040d7db7a88SGiovanni Cabiddu 			       i + 1, algo);
2041d7db7a88SGiovanni Cabiddu 			hexdump(output, req->dlen);
2042d7db7a88SGiovanni Cabiddu 			ret = -EINVAL;
204302608e02SLaura Abbott 			kfree(input_vec);
2044d7db7a88SGiovanni Cabiddu 			acomp_request_free(req);
2045d7db7a88SGiovanni Cabiddu 			goto out;
2046d7db7a88SGiovanni Cabiddu 		}
2047d7db7a88SGiovanni Cabiddu 
204802608e02SLaura Abbott 		kfree(input_vec);
2049d7db7a88SGiovanni Cabiddu 		acomp_request_free(req);
2050d7db7a88SGiovanni Cabiddu 	}
2051d7db7a88SGiovanni Cabiddu 
2052d7db7a88SGiovanni Cabiddu 	for (i = 0; i < dtcount; i++) {
2053d7db7a88SGiovanni Cabiddu 		unsigned int dlen = COMP_BUF_SIZE;
2054d7db7a88SGiovanni Cabiddu 		int ilen = dtemplate[i].inlen;
205502608e02SLaura Abbott 		void *input_vec;
2056d7db7a88SGiovanni Cabiddu 
2057d2110224SEric Biggers 		input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
205802608e02SLaura Abbott 		if (!input_vec) {
205902608e02SLaura Abbott 			ret = -ENOMEM;
206002608e02SLaura Abbott 			goto out;
206102608e02SLaura Abbott 		}
206202608e02SLaura Abbott 
2063eb095593SEric Biggers 		memset(output, 0, dlen);
20647f397136SGilad Ben-Yossef 		crypto_init_wait(&wait);
206502608e02SLaura Abbott 		sg_init_one(&src, input_vec, ilen);
2066d7db7a88SGiovanni Cabiddu 		sg_init_one(&dst, output, dlen);
2067d7db7a88SGiovanni Cabiddu 
2068d7db7a88SGiovanni Cabiddu 		req = acomp_request_alloc(tfm);
2069d7db7a88SGiovanni Cabiddu 		if (!req) {
2070d7db7a88SGiovanni Cabiddu 			pr_err("alg: acomp: request alloc failed for %s\n",
2071d7db7a88SGiovanni Cabiddu 			       algo);
207202608e02SLaura Abbott 			kfree(input_vec);
2073d7db7a88SGiovanni Cabiddu 			ret = -ENOMEM;
2074d7db7a88SGiovanni Cabiddu 			goto out;
2075d7db7a88SGiovanni Cabiddu 		}
2076d7db7a88SGiovanni Cabiddu 
2077d7db7a88SGiovanni Cabiddu 		acomp_request_set_params(req, &src, &dst, ilen, dlen);
2078d7db7a88SGiovanni Cabiddu 		acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
20797f397136SGilad Ben-Yossef 					   crypto_req_done, &wait);
2080d7db7a88SGiovanni Cabiddu 
20817f397136SGilad Ben-Yossef 		ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
2082d7db7a88SGiovanni Cabiddu 		if (ret) {
2083d7db7a88SGiovanni Cabiddu 			pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
2084d7db7a88SGiovanni Cabiddu 			       i + 1, algo, -ret);
208502608e02SLaura Abbott 			kfree(input_vec);
2086d7db7a88SGiovanni Cabiddu 			acomp_request_free(req);
2087d7db7a88SGiovanni Cabiddu 			goto out;
2088d7db7a88SGiovanni Cabiddu 		}
2089d7db7a88SGiovanni Cabiddu 
2090d7db7a88SGiovanni Cabiddu 		if (req->dlen != dtemplate[i].outlen) {
2091d7db7a88SGiovanni Cabiddu 			pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
2092d7db7a88SGiovanni Cabiddu 			       i + 1, algo, req->dlen);
2093d7db7a88SGiovanni Cabiddu 			ret = -EINVAL;
209402608e02SLaura Abbott 			kfree(input_vec);
2095d7db7a88SGiovanni Cabiddu 			acomp_request_free(req);
2096d7db7a88SGiovanni Cabiddu 			goto out;
2097d7db7a88SGiovanni Cabiddu 		}
2098d7db7a88SGiovanni Cabiddu 
2099d7db7a88SGiovanni Cabiddu 		if (memcmp(output, dtemplate[i].output, req->dlen)) {
2100d7db7a88SGiovanni Cabiddu 			pr_err("alg: acomp: Decompression test %d failed for %s\n",
2101d7db7a88SGiovanni Cabiddu 			       i + 1, algo);
2102d7db7a88SGiovanni Cabiddu 			hexdump(output, req->dlen);
2103d7db7a88SGiovanni Cabiddu 			ret = -EINVAL;
210402608e02SLaura Abbott 			kfree(input_vec);
2105d7db7a88SGiovanni Cabiddu 			acomp_request_free(req);
2106d7db7a88SGiovanni Cabiddu 			goto out;
2107d7db7a88SGiovanni Cabiddu 		}
2108d7db7a88SGiovanni Cabiddu 
210902608e02SLaura Abbott 		kfree(input_vec);
2110d7db7a88SGiovanni Cabiddu 		acomp_request_free(req);
2111d7db7a88SGiovanni Cabiddu 	}
2112d7db7a88SGiovanni Cabiddu 
2113d7db7a88SGiovanni Cabiddu 	ret = 0;
2114d7db7a88SGiovanni Cabiddu 
2115d7db7a88SGiovanni Cabiddu out:
2116a9943a0aSGiovanni Cabiddu 	kfree(decomp_out);
2117eb095593SEric Biggers 	kfree(output);
2118d7db7a88SGiovanni Cabiddu 	return ret;
2119d7db7a88SGiovanni Cabiddu }
2120d7db7a88SGiovanni Cabiddu 
2121b13b1e0cSEric Biggers static int test_cprng(struct crypto_rng *tfm,
2122b13b1e0cSEric Biggers 		      const struct cprng_testvec *template,
21237647d6ceSJarod Wilson 		      unsigned int tcount)
21247647d6ceSJarod Wilson {
21257647d6ceSJarod Wilson 	const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
2126fa4ef8a6SFelipe Contreras 	int err = 0, i, j, seedsize;
21277647d6ceSJarod Wilson 	u8 *seed;
21287647d6ceSJarod Wilson 	char result[32];
21297647d6ceSJarod Wilson 
21307647d6ceSJarod Wilson 	seedsize = crypto_rng_seedsize(tfm);
21317647d6ceSJarod Wilson 
21327647d6ceSJarod Wilson 	seed = kmalloc(seedsize, GFP_KERNEL);
21337647d6ceSJarod Wilson 	if (!seed) {
21347647d6ceSJarod Wilson 		printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
21357647d6ceSJarod Wilson 		       "for %s\n", algo);
21367647d6ceSJarod Wilson 		return -ENOMEM;
21377647d6ceSJarod Wilson 	}
21387647d6ceSJarod Wilson 
21397647d6ceSJarod Wilson 	for (i = 0; i < tcount; i++) {
21407647d6ceSJarod Wilson 		memset(result, 0, 32);
21417647d6ceSJarod Wilson 
21427647d6ceSJarod Wilson 		memcpy(seed, template[i].v, template[i].vlen);
21437647d6ceSJarod Wilson 		memcpy(seed + template[i].vlen, template[i].key,
21447647d6ceSJarod Wilson 		       template[i].klen);
21457647d6ceSJarod Wilson 		memcpy(seed + template[i].vlen + template[i].klen,
21467647d6ceSJarod Wilson 		       template[i].dt, template[i].dtlen);
21477647d6ceSJarod Wilson 
21487647d6ceSJarod Wilson 		err = crypto_rng_reset(tfm, seed, seedsize);
21497647d6ceSJarod Wilson 		if (err) {
21507647d6ceSJarod Wilson 			printk(KERN_ERR "alg: cprng: Failed to reset rng "
21517647d6ceSJarod Wilson 			       "for %s\n", algo);
21527647d6ceSJarod Wilson 			goto out;
21537647d6ceSJarod Wilson 		}
21547647d6ceSJarod Wilson 
21557647d6ceSJarod Wilson 		for (j = 0; j < template[i].loops; j++) {
21567647d6ceSJarod Wilson 			err = crypto_rng_get_bytes(tfm, result,
21577647d6ceSJarod Wilson 						   template[i].rlen);
215819e60e13SStephan Mueller 			if (err < 0) {
21597647d6ceSJarod Wilson 				printk(KERN_ERR "alg: cprng: Failed to obtain "
21607647d6ceSJarod Wilson 				       "the correct amount of random data for "
216119e60e13SStephan Mueller 				       "%s (requested %d)\n", algo,
216219e60e13SStephan Mueller 				       template[i].rlen);
21637647d6ceSJarod Wilson 				goto out;
21647647d6ceSJarod Wilson 			}
21657647d6ceSJarod Wilson 		}
21667647d6ceSJarod Wilson 
21677647d6ceSJarod Wilson 		err = memcmp(result, template[i].result,
21687647d6ceSJarod Wilson 			     template[i].rlen);
21697647d6ceSJarod Wilson 		if (err) {
21707647d6ceSJarod Wilson 			printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
21717647d6ceSJarod Wilson 			       i, algo);
21727647d6ceSJarod Wilson 			hexdump(result, template[i].rlen);
21737647d6ceSJarod Wilson 			err = -EINVAL;
21747647d6ceSJarod Wilson 			goto out;
21757647d6ceSJarod Wilson 		}
21767647d6ceSJarod Wilson 	}
21777647d6ceSJarod Wilson 
21787647d6ceSJarod Wilson out:
21797647d6ceSJarod Wilson 	kfree(seed);
21807647d6ceSJarod Wilson 	return err;
21817647d6ceSJarod Wilson }
21827647d6ceSJarod Wilson 
2183da7f033dSHerbert Xu static int alg_test_cipher(const struct alg_test_desc *desc,
2184da7f033dSHerbert Xu 			   const char *driver, u32 type, u32 mask)
2185da7f033dSHerbert Xu {
218692a4c9feSEric Biggers 	const struct cipher_test_suite *suite = &desc->suite.cipher;
21871aa4ecd9SHerbert Xu 	struct crypto_cipher *tfm;
218892a4c9feSEric Biggers 	int err;
2189da7f033dSHerbert Xu 
2190eed93e0cSHerbert Xu 	tfm = crypto_alloc_cipher(driver, type, mask);
2191da7f033dSHerbert Xu 	if (IS_ERR(tfm)) {
2192da7f033dSHerbert Xu 		printk(KERN_ERR "alg: cipher: Failed to load transform for "
2193da7f033dSHerbert Xu 		       "%s: %ld\n", driver, PTR_ERR(tfm));
2194da7f033dSHerbert Xu 		return PTR_ERR(tfm);
2195da7f033dSHerbert Xu 	}
2196da7f033dSHerbert Xu 
219792a4c9feSEric Biggers 	err = test_cipher(tfm, ENCRYPT, suite->vecs, suite->count);
219892a4c9feSEric Biggers 	if (!err)
219992a4c9feSEric Biggers 		err = test_cipher(tfm, DECRYPT, suite->vecs, suite->count);
2200da7f033dSHerbert Xu 
22011aa4ecd9SHerbert Xu 	crypto_free_cipher(tfm);
22021aa4ecd9SHerbert Xu 	return err;
22031aa4ecd9SHerbert Xu }
22041aa4ecd9SHerbert Xu 
2205da7f033dSHerbert Xu static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
2206da7f033dSHerbert Xu 			 u32 type, u32 mask)
2207da7f033dSHerbert Xu {
2208d7db7a88SGiovanni Cabiddu 	struct crypto_comp *comp;
2209d7db7a88SGiovanni Cabiddu 	struct crypto_acomp *acomp;
2210da7f033dSHerbert Xu 	int err;
2211d7db7a88SGiovanni Cabiddu 	u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
2212da7f033dSHerbert Xu 
2213d7db7a88SGiovanni Cabiddu 	if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
2214d7db7a88SGiovanni Cabiddu 		acomp = crypto_alloc_acomp(driver, type, mask);
2215d7db7a88SGiovanni Cabiddu 		if (IS_ERR(acomp)) {
2216d7db7a88SGiovanni Cabiddu 			pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
2217d7db7a88SGiovanni Cabiddu 			       driver, PTR_ERR(acomp));
2218d7db7a88SGiovanni Cabiddu 			return PTR_ERR(acomp);
2219d7db7a88SGiovanni Cabiddu 		}
2220d7db7a88SGiovanni Cabiddu 		err = test_acomp(acomp, desc->suite.comp.comp.vecs,
2221d7db7a88SGiovanni Cabiddu 				 desc->suite.comp.decomp.vecs,
2222d7db7a88SGiovanni Cabiddu 				 desc->suite.comp.comp.count,
2223d7db7a88SGiovanni Cabiddu 				 desc->suite.comp.decomp.count);
2224d7db7a88SGiovanni Cabiddu 		crypto_free_acomp(acomp);
2225d7db7a88SGiovanni Cabiddu 	} else {
2226d7db7a88SGiovanni Cabiddu 		comp = crypto_alloc_comp(driver, type, mask);
2227d7db7a88SGiovanni Cabiddu 		if (IS_ERR(comp)) {
2228d7db7a88SGiovanni Cabiddu 			pr_err("alg: comp: Failed to load transform for %s: %ld\n",
2229d7db7a88SGiovanni Cabiddu 			       driver, PTR_ERR(comp));
2230d7db7a88SGiovanni Cabiddu 			return PTR_ERR(comp);
2231da7f033dSHerbert Xu 		}
2232da7f033dSHerbert Xu 
2233d7db7a88SGiovanni Cabiddu 		err = test_comp(comp, desc->suite.comp.comp.vecs,
2234da7f033dSHerbert Xu 				desc->suite.comp.decomp.vecs,
2235da7f033dSHerbert Xu 				desc->suite.comp.comp.count,
2236da7f033dSHerbert Xu 				desc->suite.comp.decomp.count);
2237da7f033dSHerbert Xu 
2238d7db7a88SGiovanni Cabiddu 		crypto_free_comp(comp);
2239d7db7a88SGiovanni Cabiddu 	}
2240da7f033dSHerbert Xu 	return err;
2241da7f033dSHerbert Xu }
2242da7f033dSHerbert Xu 
22438e3ee85eSHerbert Xu static int alg_test_crc32c(const struct alg_test_desc *desc,
22448e3ee85eSHerbert Xu 			   const char *driver, u32 type, u32 mask)
22458e3ee85eSHerbert Xu {
22468e3ee85eSHerbert Xu 	struct crypto_shash *tfm;
2247cb9dde88SEric Biggers 	__le32 val;
22488e3ee85eSHerbert Xu 	int err;
22498e3ee85eSHerbert Xu 
22508e3ee85eSHerbert Xu 	err = alg_test_hash(desc, driver, type, mask);
22518e3ee85eSHerbert Xu 	if (err)
2252eb5e6730SEric Biggers 		return err;
22538e3ee85eSHerbert Xu 
2254eed93e0cSHerbert Xu 	tfm = crypto_alloc_shash(driver, type, mask);
22558e3ee85eSHerbert Xu 	if (IS_ERR(tfm)) {
2256eb5e6730SEric Biggers 		if (PTR_ERR(tfm) == -ENOENT) {
2257eb5e6730SEric Biggers 			/*
2258eb5e6730SEric Biggers 			 * This crc32c implementation is only available through
2259eb5e6730SEric Biggers 			 * ahash API, not the shash API, so the remaining part
2260eb5e6730SEric Biggers 			 * of the test is not applicable to it.
2261eb5e6730SEric Biggers 			 */
2262eb5e6730SEric Biggers 			return 0;
2263eb5e6730SEric Biggers 		}
22648e3ee85eSHerbert Xu 		printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
22658e3ee85eSHerbert Xu 		       "%ld\n", driver, PTR_ERR(tfm));
2266eb5e6730SEric Biggers 		return PTR_ERR(tfm);
22678e3ee85eSHerbert Xu 	}
22688e3ee85eSHerbert Xu 
22698e3ee85eSHerbert Xu 	do {
22704c5c3024SJan-Simon Möller 		SHASH_DESC_ON_STACK(shash, tfm);
22714c5c3024SJan-Simon Möller 		u32 *ctx = (u32 *)shash_desc_ctx(shash);
22728e3ee85eSHerbert Xu 
22734c5c3024SJan-Simon Möller 		shash->tfm = tfm;
22744c5c3024SJan-Simon Möller 		shash->flags = 0;
22758e3ee85eSHerbert Xu 
2276cb9dde88SEric Biggers 		*ctx = 420553207;
22774c5c3024SJan-Simon Möller 		err = crypto_shash_final(shash, (u8 *)&val);
22788e3ee85eSHerbert Xu 		if (err) {
22798e3ee85eSHerbert Xu 			printk(KERN_ERR "alg: crc32c: Operation failed for "
22808e3ee85eSHerbert Xu 			       "%s: %d\n", driver, err);
22818e3ee85eSHerbert Xu 			break;
22828e3ee85eSHerbert Xu 		}
22838e3ee85eSHerbert Xu 
2284cb9dde88SEric Biggers 		if (val != cpu_to_le32(~420553207)) {
2285cb9dde88SEric Biggers 			pr_err("alg: crc32c: Test failed for %s: %u\n",
2286cb9dde88SEric Biggers 			       driver, le32_to_cpu(val));
22878e3ee85eSHerbert Xu 			err = -EINVAL;
22888e3ee85eSHerbert Xu 		}
22898e3ee85eSHerbert Xu 	} while (0);
22908e3ee85eSHerbert Xu 
22918e3ee85eSHerbert Xu 	crypto_free_shash(tfm);
22928e3ee85eSHerbert Xu 
22938e3ee85eSHerbert Xu 	return err;
22948e3ee85eSHerbert Xu }
22958e3ee85eSHerbert Xu 
22967647d6ceSJarod Wilson static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
22977647d6ceSJarod Wilson 			  u32 type, u32 mask)
22987647d6ceSJarod Wilson {
22997647d6ceSJarod Wilson 	struct crypto_rng *rng;
23007647d6ceSJarod Wilson 	int err;
23017647d6ceSJarod Wilson 
2302eed93e0cSHerbert Xu 	rng = crypto_alloc_rng(driver, type, mask);
23037647d6ceSJarod Wilson 	if (IS_ERR(rng)) {
23047647d6ceSJarod Wilson 		printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
23057647d6ceSJarod Wilson 		       "%ld\n", driver, PTR_ERR(rng));
23067647d6ceSJarod Wilson 		return PTR_ERR(rng);
23077647d6ceSJarod Wilson 	}
23087647d6ceSJarod Wilson 
23097647d6ceSJarod Wilson 	err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
23107647d6ceSJarod Wilson 
23117647d6ceSJarod Wilson 	crypto_free_rng(rng);
23127647d6ceSJarod Wilson 
23137647d6ceSJarod Wilson 	return err;
23147647d6ceSJarod Wilson }
23157647d6ceSJarod Wilson 
231664d1cdfbSStephan Mueller 
2317b13b1e0cSEric Biggers static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
231864d1cdfbSStephan Mueller 			  const char *driver, u32 type, u32 mask)
231964d1cdfbSStephan Mueller {
232064d1cdfbSStephan Mueller 	int ret = -EAGAIN;
232164d1cdfbSStephan Mueller 	struct crypto_rng *drng;
232264d1cdfbSStephan Mueller 	struct drbg_test_data test_data;
232364d1cdfbSStephan Mueller 	struct drbg_string addtl, pers, testentropy;
232464d1cdfbSStephan Mueller 	unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
232564d1cdfbSStephan Mueller 
232664d1cdfbSStephan Mueller 	if (!buf)
232764d1cdfbSStephan Mueller 		return -ENOMEM;
232864d1cdfbSStephan Mueller 
2329eed93e0cSHerbert Xu 	drng = crypto_alloc_rng(driver, type, mask);
233064d1cdfbSStephan Mueller 	if (IS_ERR(drng)) {
233164d1cdfbSStephan Mueller 		printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
233264d1cdfbSStephan Mueller 		       "%s\n", driver);
233364d1cdfbSStephan Mueller 		kzfree(buf);
233464d1cdfbSStephan Mueller 		return -ENOMEM;
233564d1cdfbSStephan Mueller 	}
233664d1cdfbSStephan Mueller 
233764d1cdfbSStephan Mueller 	test_data.testentropy = &testentropy;
233864d1cdfbSStephan Mueller 	drbg_string_fill(&testentropy, test->entropy, test->entropylen);
233964d1cdfbSStephan Mueller 	drbg_string_fill(&pers, test->pers, test->perslen);
234064d1cdfbSStephan Mueller 	ret = crypto_drbg_reset_test(drng, &pers, &test_data);
234164d1cdfbSStephan Mueller 	if (ret) {
234264d1cdfbSStephan Mueller 		printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
234364d1cdfbSStephan Mueller 		goto outbuf;
234464d1cdfbSStephan Mueller 	}
234564d1cdfbSStephan Mueller 
234664d1cdfbSStephan Mueller 	drbg_string_fill(&addtl, test->addtla, test->addtllen);
234764d1cdfbSStephan Mueller 	if (pr) {
234864d1cdfbSStephan Mueller 		drbg_string_fill(&testentropy, test->entpra, test->entprlen);
234964d1cdfbSStephan Mueller 		ret = crypto_drbg_get_bytes_addtl_test(drng,
235064d1cdfbSStephan Mueller 			buf, test->expectedlen, &addtl,	&test_data);
235164d1cdfbSStephan Mueller 	} else {
235264d1cdfbSStephan Mueller 		ret = crypto_drbg_get_bytes_addtl(drng,
235364d1cdfbSStephan Mueller 			buf, test->expectedlen, &addtl);
235464d1cdfbSStephan Mueller 	}
235519e60e13SStephan Mueller 	if (ret < 0) {
235664d1cdfbSStephan Mueller 		printk(KERN_ERR "alg: drbg: could not obtain random data for "
235764d1cdfbSStephan Mueller 		       "driver %s\n", driver);
235864d1cdfbSStephan Mueller 		goto outbuf;
235964d1cdfbSStephan Mueller 	}
236064d1cdfbSStephan Mueller 
236164d1cdfbSStephan Mueller 	drbg_string_fill(&addtl, test->addtlb, test->addtllen);
236264d1cdfbSStephan Mueller 	if (pr) {
236364d1cdfbSStephan Mueller 		drbg_string_fill(&testentropy, test->entprb, test->entprlen);
236464d1cdfbSStephan Mueller 		ret = crypto_drbg_get_bytes_addtl_test(drng,
236564d1cdfbSStephan Mueller 			buf, test->expectedlen, &addtl, &test_data);
236664d1cdfbSStephan Mueller 	} else {
236764d1cdfbSStephan Mueller 		ret = crypto_drbg_get_bytes_addtl(drng,
236864d1cdfbSStephan Mueller 			buf, test->expectedlen, &addtl);
236964d1cdfbSStephan Mueller 	}
237019e60e13SStephan Mueller 	if (ret < 0) {
237164d1cdfbSStephan Mueller 		printk(KERN_ERR "alg: drbg: could not obtain random data for "
237264d1cdfbSStephan Mueller 		       "driver %s\n", driver);
237364d1cdfbSStephan Mueller 		goto outbuf;
237464d1cdfbSStephan Mueller 	}
237564d1cdfbSStephan Mueller 
237664d1cdfbSStephan Mueller 	ret = memcmp(test->expected, buf, test->expectedlen);
237764d1cdfbSStephan Mueller 
237864d1cdfbSStephan Mueller outbuf:
237964d1cdfbSStephan Mueller 	crypto_free_rng(drng);
238064d1cdfbSStephan Mueller 	kzfree(buf);
238164d1cdfbSStephan Mueller 	return ret;
238264d1cdfbSStephan Mueller }
238364d1cdfbSStephan Mueller 
238464d1cdfbSStephan Mueller 
238564d1cdfbSStephan Mueller static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
238664d1cdfbSStephan Mueller 			 u32 type, u32 mask)
238764d1cdfbSStephan Mueller {
238864d1cdfbSStephan Mueller 	int err = 0;
238964d1cdfbSStephan Mueller 	int pr = 0;
239064d1cdfbSStephan Mueller 	int i = 0;
2391b13b1e0cSEric Biggers 	const struct drbg_testvec *template = desc->suite.drbg.vecs;
239264d1cdfbSStephan Mueller 	unsigned int tcount = desc->suite.drbg.count;
239364d1cdfbSStephan Mueller 
239464d1cdfbSStephan Mueller 	if (0 == memcmp(driver, "drbg_pr_", 8))
239564d1cdfbSStephan Mueller 		pr = 1;
239664d1cdfbSStephan Mueller 
239764d1cdfbSStephan Mueller 	for (i = 0; i < tcount; i++) {
239864d1cdfbSStephan Mueller 		err = drbg_cavs_test(&template[i], pr, driver, type, mask);
239964d1cdfbSStephan Mueller 		if (err) {
240064d1cdfbSStephan Mueller 			printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
240164d1cdfbSStephan Mueller 			       i, driver);
240264d1cdfbSStephan Mueller 			err = -EINVAL;
240364d1cdfbSStephan Mueller 			break;
240464d1cdfbSStephan Mueller 		}
240564d1cdfbSStephan Mueller 	}
240664d1cdfbSStephan Mueller 	return err;
240764d1cdfbSStephan Mueller 
240864d1cdfbSStephan Mueller }
240964d1cdfbSStephan Mueller 
2410b13b1e0cSEric Biggers static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
2411802c7f1cSSalvatore Benedetto 		       const char *alg)
2412802c7f1cSSalvatore Benedetto {
2413802c7f1cSSalvatore Benedetto 	struct kpp_request *req;
2414802c7f1cSSalvatore Benedetto 	void *input_buf = NULL;
2415802c7f1cSSalvatore Benedetto 	void *output_buf = NULL;
241647d3fd39STudor-Dan Ambarus 	void *a_public = NULL;
241747d3fd39STudor-Dan Ambarus 	void *a_ss = NULL;
241847d3fd39STudor-Dan Ambarus 	void *shared_secret = NULL;
24197f397136SGilad Ben-Yossef 	struct crypto_wait wait;
2420802c7f1cSSalvatore Benedetto 	unsigned int out_len_max;
2421802c7f1cSSalvatore Benedetto 	int err = -ENOMEM;
2422802c7f1cSSalvatore Benedetto 	struct scatterlist src, dst;
2423802c7f1cSSalvatore Benedetto 
2424802c7f1cSSalvatore Benedetto 	req = kpp_request_alloc(tfm, GFP_KERNEL);
2425802c7f1cSSalvatore Benedetto 	if (!req)
2426802c7f1cSSalvatore Benedetto 		return err;
2427802c7f1cSSalvatore Benedetto 
24287f397136SGilad Ben-Yossef 	crypto_init_wait(&wait);
2429802c7f1cSSalvatore Benedetto 
2430802c7f1cSSalvatore Benedetto 	err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
2431802c7f1cSSalvatore Benedetto 	if (err < 0)
2432802c7f1cSSalvatore Benedetto 		goto free_req;
2433802c7f1cSSalvatore Benedetto 
2434802c7f1cSSalvatore Benedetto 	out_len_max = crypto_kpp_maxsize(tfm);
2435802c7f1cSSalvatore Benedetto 	output_buf = kzalloc(out_len_max, GFP_KERNEL);
2436802c7f1cSSalvatore Benedetto 	if (!output_buf) {
2437802c7f1cSSalvatore Benedetto 		err = -ENOMEM;
2438802c7f1cSSalvatore Benedetto 		goto free_req;
2439802c7f1cSSalvatore Benedetto 	}
2440802c7f1cSSalvatore Benedetto 
2441802c7f1cSSalvatore Benedetto 	/* Use appropriate parameter as base */
2442802c7f1cSSalvatore Benedetto 	kpp_request_set_input(req, NULL, 0);
2443802c7f1cSSalvatore Benedetto 	sg_init_one(&dst, output_buf, out_len_max);
2444802c7f1cSSalvatore Benedetto 	kpp_request_set_output(req, &dst, out_len_max);
2445802c7f1cSSalvatore Benedetto 	kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
24467f397136SGilad Ben-Yossef 				 crypto_req_done, &wait);
2447802c7f1cSSalvatore Benedetto 
244847d3fd39STudor-Dan Ambarus 	/* Compute party A's public key */
24497f397136SGilad Ben-Yossef 	err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait);
2450802c7f1cSSalvatore Benedetto 	if (err) {
245147d3fd39STudor-Dan Ambarus 		pr_err("alg: %s: Party A: generate public key test failed. err %d\n",
2452802c7f1cSSalvatore Benedetto 		       alg, err);
2453802c7f1cSSalvatore Benedetto 		goto free_output;
2454802c7f1cSSalvatore Benedetto 	}
245547d3fd39STudor-Dan Ambarus 
245647d3fd39STudor-Dan Ambarus 	if (vec->genkey) {
245747d3fd39STudor-Dan Ambarus 		/* Save party A's public key */
2458e3d90e52SChristopher Diaz Riveros 		a_public = kmemdup(sg_virt(req->dst), out_len_max, GFP_KERNEL);
245947d3fd39STudor-Dan Ambarus 		if (!a_public) {
246047d3fd39STudor-Dan Ambarus 			err = -ENOMEM;
246147d3fd39STudor-Dan Ambarus 			goto free_output;
246247d3fd39STudor-Dan Ambarus 		}
246347d3fd39STudor-Dan Ambarus 	} else {
2464802c7f1cSSalvatore Benedetto 		/* Verify calculated public key */
2465802c7f1cSSalvatore Benedetto 		if (memcmp(vec->expected_a_public, sg_virt(req->dst),
2466802c7f1cSSalvatore Benedetto 			   vec->expected_a_public_size)) {
246747d3fd39STudor-Dan Ambarus 			pr_err("alg: %s: Party A: generate public key test failed. Invalid output\n",
2468802c7f1cSSalvatore Benedetto 			       alg);
2469802c7f1cSSalvatore Benedetto 			err = -EINVAL;
2470802c7f1cSSalvatore Benedetto 			goto free_output;
2471802c7f1cSSalvatore Benedetto 		}
247247d3fd39STudor-Dan Ambarus 	}
2473802c7f1cSSalvatore Benedetto 
2474802c7f1cSSalvatore Benedetto 	/* Calculate shared secret key by using counter part (b) public key. */
2475e3d90e52SChristopher Diaz Riveros 	input_buf = kmemdup(vec->b_public, vec->b_public_size, GFP_KERNEL);
2476802c7f1cSSalvatore Benedetto 	if (!input_buf) {
2477802c7f1cSSalvatore Benedetto 		err = -ENOMEM;
2478802c7f1cSSalvatore Benedetto 		goto free_output;
2479802c7f1cSSalvatore Benedetto 	}
2480802c7f1cSSalvatore Benedetto 
2481802c7f1cSSalvatore Benedetto 	sg_init_one(&src, input_buf, vec->b_public_size);
2482802c7f1cSSalvatore Benedetto 	sg_init_one(&dst, output_buf, out_len_max);
2483802c7f1cSSalvatore Benedetto 	kpp_request_set_input(req, &src, vec->b_public_size);
2484802c7f1cSSalvatore Benedetto 	kpp_request_set_output(req, &dst, out_len_max);
2485802c7f1cSSalvatore Benedetto 	kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
24867f397136SGilad Ben-Yossef 				 crypto_req_done, &wait);
24877f397136SGilad Ben-Yossef 	err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait);
2488802c7f1cSSalvatore Benedetto 	if (err) {
248947d3fd39STudor-Dan Ambarus 		pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n",
2490802c7f1cSSalvatore Benedetto 		       alg, err);
2491802c7f1cSSalvatore Benedetto 		goto free_all;
2492802c7f1cSSalvatore Benedetto 	}
249347d3fd39STudor-Dan Ambarus 
249447d3fd39STudor-Dan Ambarus 	if (vec->genkey) {
249547d3fd39STudor-Dan Ambarus 		/* Save the shared secret obtained by party A */
2496e3d90e52SChristopher Diaz Riveros 		a_ss = kmemdup(sg_virt(req->dst), vec->expected_ss_size, GFP_KERNEL);
249747d3fd39STudor-Dan Ambarus 		if (!a_ss) {
249847d3fd39STudor-Dan Ambarus 			err = -ENOMEM;
249947d3fd39STudor-Dan Ambarus 			goto free_all;
250047d3fd39STudor-Dan Ambarus 		}
250147d3fd39STudor-Dan Ambarus 
250247d3fd39STudor-Dan Ambarus 		/*
250347d3fd39STudor-Dan Ambarus 		 * Calculate party B's shared secret by using party A's
250447d3fd39STudor-Dan Ambarus 		 * public key.
250547d3fd39STudor-Dan Ambarus 		 */
250647d3fd39STudor-Dan Ambarus 		err = crypto_kpp_set_secret(tfm, vec->b_secret,
250747d3fd39STudor-Dan Ambarus 					    vec->b_secret_size);
250847d3fd39STudor-Dan Ambarus 		if (err < 0)
250947d3fd39STudor-Dan Ambarus 			goto free_all;
251047d3fd39STudor-Dan Ambarus 
251147d3fd39STudor-Dan Ambarus 		sg_init_one(&src, a_public, vec->expected_a_public_size);
251247d3fd39STudor-Dan Ambarus 		sg_init_one(&dst, output_buf, out_len_max);
251347d3fd39STudor-Dan Ambarus 		kpp_request_set_input(req, &src, vec->expected_a_public_size);
251447d3fd39STudor-Dan Ambarus 		kpp_request_set_output(req, &dst, out_len_max);
251547d3fd39STudor-Dan Ambarus 		kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
25167f397136SGilad Ben-Yossef 					 crypto_req_done, &wait);
25177f397136SGilad Ben-Yossef 		err = crypto_wait_req(crypto_kpp_compute_shared_secret(req),
25187f397136SGilad Ben-Yossef 				      &wait);
251947d3fd39STudor-Dan Ambarus 		if (err) {
252047d3fd39STudor-Dan Ambarus 			pr_err("alg: %s: Party B: compute shared secret failed. err %d\n",
252147d3fd39STudor-Dan Ambarus 			       alg, err);
252247d3fd39STudor-Dan Ambarus 			goto free_all;
252347d3fd39STudor-Dan Ambarus 		}
252447d3fd39STudor-Dan Ambarus 
252547d3fd39STudor-Dan Ambarus 		shared_secret = a_ss;
252647d3fd39STudor-Dan Ambarus 	} else {
252747d3fd39STudor-Dan Ambarus 		shared_secret = (void *)vec->expected_ss;
252847d3fd39STudor-Dan Ambarus 	}
252947d3fd39STudor-Dan Ambarus 
2530802c7f1cSSalvatore Benedetto 	/*
2531802c7f1cSSalvatore Benedetto 	 * verify shared secret from which the user will derive
2532802c7f1cSSalvatore Benedetto 	 * secret key by executing whatever hash it has chosen
2533802c7f1cSSalvatore Benedetto 	 */
253447d3fd39STudor-Dan Ambarus 	if (memcmp(shared_secret, sg_virt(req->dst),
2535802c7f1cSSalvatore Benedetto 		   vec->expected_ss_size)) {
2536802c7f1cSSalvatore Benedetto 		pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
2537802c7f1cSSalvatore Benedetto 		       alg);
2538802c7f1cSSalvatore Benedetto 		err = -EINVAL;
2539802c7f1cSSalvatore Benedetto 	}
2540802c7f1cSSalvatore Benedetto 
2541802c7f1cSSalvatore Benedetto free_all:
254247d3fd39STudor-Dan Ambarus 	kfree(a_ss);
2543802c7f1cSSalvatore Benedetto 	kfree(input_buf);
2544802c7f1cSSalvatore Benedetto free_output:
254547d3fd39STudor-Dan Ambarus 	kfree(a_public);
2546802c7f1cSSalvatore Benedetto 	kfree(output_buf);
2547802c7f1cSSalvatore Benedetto free_req:
2548802c7f1cSSalvatore Benedetto 	kpp_request_free(req);
2549802c7f1cSSalvatore Benedetto 	return err;
2550802c7f1cSSalvatore Benedetto }
2551802c7f1cSSalvatore Benedetto 
2552802c7f1cSSalvatore Benedetto static int test_kpp(struct crypto_kpp *tfm, const char *alg,
2553b13b1e0cSEric Biggers 		    const struct kpp_testvec *vecs, unsigned int tcount)
2554802c7f1cSSalvatore Benedetto {
2555802c7f1cSSalvatore Benedetto 	int ret, i;
2556802c7f1cSSalvatore Benedetto 
2557802c7f1cSSalvatore Benedetto 	for (i = 0; i < tcount; i++) {
2558802c7f1cSSalvatore Benedetto 		ret = do_test_kpp(tfm, vecs++, alg);
2559802c7f1cSSalvatore Benedetto 		if (ret) {
2560802c7f1cSSalvatore Benedetto 			pr_err("alg: %s: test failed on vector %d, err=%d\n",
2561802c7f1cSSalvatore Benedetto 			       alg, i + 1, ret);
2562802c7f1cSSalvatore Benedetto 			return ret;
2563802c7f1cSSalvatore Benedetto 		}
2564802c7f1cSSalvatore Benedetto 	}
2565802c7f1cSSalvatore Benedetto 	return 0;
2566802c7f1cSSalvatore Benedetto }
2567802c7f1cSSalvatore Benedetto 
2568802c7f1cSSalvatore Benedetto static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
2569802c7f1cSSalvatore Benedetto 			u32 type, u32 mask)
2570802c7f1cSSalvatore Benedetto {
2571802c7f1cSSalvatore Benedetto 	struct crypto_kpp *tfm;
2572802c7f1cSSalvatore Benedetto 	int err = 0;
2573802c7f1cSSalvatore Benedetto 
2574eed93e0cSHerbert Xu 	tfm = crypto_alloc_kpp(driver, type, mask);
2575802c7f1cSSalvatore Benedetto 	if (IS_ERR(tfm)) {
2576802c7f1cSSalvatore Benedetto 		pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
2577802c7f1cSSalvatore Benedetto 		       driver, PTR_ERR(tfm));
2578802c7f1cSSalvatore Benedetto 		return PTR_ERR(tfm);
2579802c7f1cSSalvatore Benedetto 	}
2580802c7f1cSSalvatore Benedetto 	if (desc->suite.kpp.vecs)
2581802c7f1cSSalvatore Benedetto 		err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
2582802c7f1cSSalvatore Benedetto 			       desc->suite.kpp.count);
2583802c7f1cSSalvatore Benedetto 
2584802c7f1cSSalvatore Benedetto 	crypto_free_kpp(tfm);
2585802c7f1cSSalvatore Benedetto 	return err;
2586802c7f1cSSalvatore Benedetto }
2587802c7f1cSSalvatore Benedetto 
258850d2b643SHerbert Xu static int test_akcipher_one(struct crypto_akcipher *tfm,
2589b13b1e0cSEric Biggers 			     const struct akcipher_testvec *vecs)
2590946cc463STadeusz Struk {
2591df27b26fSHerbert Xu 	char *xbuf[XBUFSIZE];
2592946cc463STadeusz Struk 	struct akcipher_request *req;
2593946cc463STadeusz Struk 	void *outbuf_enc = NULL;
2594946cc463STadeusz Struk 	void *outbuf_dec = NULL;
25957f397136SGilad Ben-Yossef 	struct crypto_wait wait;
2596946cc463STadeusz Struk 	unsigned int out_len_max, out_len = 0;
2597946cc463STadeusz Struk 	int err = -ENOMEM;
259822287b0bSTadeusz Struk 	struct scatterlist src, dst, src_tab[2];
25990507de94SVitaly Chikunov 	const char *m, *c;
26000507de94SVitaly Chikunov 	unsigned int m_size, c_size;
26010507de94SVitaly Chikunov 	const char *op;
2602946cc463STadeusz Struk 
2603df27b26fSHerbert Xu 	if (testmgr_alloc_buf(xbuf))
2604df27b26fSHerbert Xu 		return err;
2605df27b26fSHerbert Xu 
2606946cc463STadeusz Struk 	req = akcipher_request_alloc(tfm, GFP_KERNEL);
2607946cc463STadeusz Struk 	if (!req)
2608df27b26fSHerbert Xu 		goto free_xbuf;
2609946cc463STadeusz Struk 
26107f397136SGilad Ben-Yossef 	crypto_init_wait(&wait);
261122287b0bSTadeusz Struk 
261222287b0bSTadeusz Struk 	if (vecs->public_key_vec)
261322287b0bSTadeusz Struk 		err = crypto_akcipher_set_pub_key(tfm, vecs->key,
261422287b0bSTadeusz Struk 						  vecs->key_len);
261522287b0bSTadeusz Struk 	else
261622287b0bSTadeusz Struk 		err = crypto_akcipher_set_priv_key(tfm, vecs->key,
261722287b0bSTadeusz Struk 						   vecs->key_len);
2618946cc463STadeusz Struk 	if (err)
2619946cc463STadeusz Struk 		goto free_req;
2620946cc463STadeusz Struk 
262157763f5eSSalvatore Benedetto 	err = -ENOMEM;
262222287b0bSTadeusz Struk 	out_len_max = crypto_akcipher_maxsize(tfm);
26230507de94SVitaly Chikunov 
26240507de94SVitaly Chikunov 	/*
26250507de94SVitaly Chikunov 	 * First run test which do not require a private key, such as
26260507de94SVitaly Chikunov 	 * encrypt or verify.
26270507de94SVitaly Chikunov 	 */
2628946cc463STadeusz Struk 	outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
2629946cc463STadeusz Struk 	if (!outbuf_enc)
2630946cc463STadeusz Struk 		goto free_req;
2631946cc463STadeusz Struk 
26320507de94SVitaly Chikunov 	if (!vecs->siggen_sigver_test) {
26330507de94SVitaly Chikunov 		m = vecs->m;
26340507de94SVitaly Chikunov 		m_size = vecs->m_size;
26350507de94SVitaly Chikunov 		c = vecs->c;
26360507de94SVitaly Chikunov 		c_size = vecs->c_size;
26370507de94SVitaly Chikunov 		op = "encrypt";
26380507de94SVitaly Chikunov 	} else {
26390507de94SVitaly Chikunov 		/* Swap args so we could keep plaintext (digest)
26400507de94SVitaly Chikunov 		 * in vecs->m, and cooked signature in vecs->c.
26410507de94SVitaly Chikunov 		 */
26420507de94SVitaly Chikunov 		m = vecs->c; /* signature */
26430507de94SVitaly Chikunov 		m_size = vecs->c_size;
26440507de94SVitaly Chikunov 		c = vecs->m; /* digest */
26450507de94SVitaly Chikunov 		c_size = vecs->m_size;
26460507de94SVitaly Chikunov 		op = "verify";
26470507de94SVitaly Chikunov 	}
2648df27b26fSHerbert Xu 
26490507de94SVitaly Chikunov 	if (WARN_ON(m_size > PAGE_SIZE))
26500507de94SVitaly Chikunov 		goto free_all;
26510507de94SVitaly Chikunov 	memcpy(xbuf[0], m, m_size);
2652df27b26fSHerbert Xu 
265322287b0bSTadeusz Struk 	sg_init_table(src_tab, 2);
2654df27b26fSHerbert Xu 	sg_set_buf(&src_tab[0], xbuf[0], 8);
26550507de94SVitaly Chikunov 	sg_set_buf(&src_tab[1], xbuf[0] + 8, m_size - 8);
265622287b0bSTadeusz Struk 	sg_init_one(&dst, outbuf_enc, out_len_max);
26570507de94SVitaly Chikunov 	akcipher_request_set_crypt(req, src_tab, &dst, m_size,
265822287b0bSTadeusz Struk 				   out_len_max);
2659946cc463STadeusz Struk 	akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
26607f397136SGilad Ben-Yossef 				      crypto_req_done, &wait);
2661946cc463STadeusz Struk 
26627f397136SGilad Ben-Yossef 	err = crypto_wait_req(vecs->siggen_sigver_test ?
26630507de94SVitaly Chikunov 			      /* Run asymmetric signature verification */
26640507de94SVitaly Chikunov 			      crypto_akcipher_verify(req) :
26651207107cSStephan Mueller 			      /* Run asymmetric encrypt */
26667f397136SGilad Ben-Yossef 			      crypto_akcipher_encrypt(req), &wait);
2667946cc463STadeusz Struk 	if (err) {
26680507de94SVitaly Chikunov 		pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
2669946cc463STadeusz Struk 		goto free_all;
2670946cc463STadeusz Struk 	}
26710507de94SVitaly Chikunov 	if (req->dst_len != c_size) {
26720507de94SVitaly Chikunov 		pr_err("alg: akcipher: %s test failed. Invalid output len\n",
26730507de94SVitaly Chikunov 		       op);
2674946cc463STadeusz Struk 		err = -EINVAL;
2675946cc463STadeusz Struk 		goto free_all;
2676946cc463STadeusz Struk 	}
2677946cc463STadeusz Struk 	/* verify that encrypted message is equal to expected */
26780507de94SVitaly Chikunov 	if (memcmp(c, outbuf_enc, c_size)) {
26790507de94SVitaly Chikunov 		pr_err("alg: akcipher: %s test failed. Invalid output\n", op);
26800507de94SVitaly Chikunov 		hexdump(outbuf_enc, c_size);
2681946cc463STadeusz Struk 		err = -EINVAL;
2682946cc463STadeusz Struk 		goto free_all;
2683946cc463STadeusz Struk 	}
26840507de94SVitaly Chikunov 
26850507de94SVitaly Chikunov 	/*
26860507de94SVitaly Chikunov 	 * Don't invoke (decrypt or sign) test which require a private key
26870507de94SVitaly Chikunov 	 * for vectors with only a public key.
26880507de94SVitaly Chikunov 	 */
2689946cc463STadeusz Struk 	if (vecs->public_key_vec) {
2690946cc463STadeusz Struk 		err = 0;
2691946cc463STadeusz Struk 		goto free_all;
2692946cc463STadeusz Struk 	}
2693946cc463STadeusz Struk 	outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
2694946cc463STadeusz Struk 	if (!outbuf_dec) {
2695946cc463STadeusz Struk 		err = -ENOMEM;
2696946cc463STadeusz Struk 		goto free_all;
2697946cc463STadeusz Struk 	}
2698df27b26fSHerbert Xu 
26990507de94SVitaly Chikunov 	op = vecs->siggen_sigver_test ? "sign" : "decrypt";
27000507de94SVitaly Chikunov 	if (WARN_ON(c_size > PAGE_SIZE))
2701df27b26fSHerbert Xu 		goto free_all;
27020507de94SVitaly Chikunov 	memcpy(xbuf[0], c, c_size);
2703df27b26fSHerbert Xu 
27040507de94SVitaly Chikunov 	sg_init_one(&src, xbuf[0], c_size);
270522287b0bSTadeusz Struk 	sg_init_one(&dst, outbuf_dec, out_len_max);
27067f397136SGilad Ben-Yossef 	crypto_init_wait(&wait);
27070507de94SVitaly Chikunov 	akcipher_request_set_crypt(req, &src, &dst, c_size, out_len_max);
2708946cc463STadeusz Struk 
27097f397136SGilad Ben-Yossef 	err = crypto_wait_req(vecs->siggen_sigver_test ?
27100507de94SVitaly Chikunov 			      /* Run asymmetric signature generation */
27110507de94SVitaly Chikunov 			      crypto_akcipher_sign(req) :
27121207107cSStephan Mueller 			      /* Run asymmetric decrypt */
27137f397136SGilad Ben-Yossef 			      crypto_akcipher_decrypt(req), &wait);
2714946cc463STadeusz Struk 	if (err) {
27150507de94SVitaly Chikunov 		pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
2716946cc463STadeusz Struk 		goto free_all;
2717946cc463STadeusz Struk 	}
2718946cc463STadeusz Struk 	out_len = req->dst_len;
27190507de94SVitaly Chikunov 	if (out_len < m_size) {
27200507de94SVitaly Chikunov 		pr_err("alg: akcipher: %s test failed. Invalid output len %u\n",
27210507de94SVitaly Chikunov 		       op, out_len);
2722946cc463STadeusz Struk 		err = -EINVAL;
2723946cc463STadeusz Struk 		goto free_all;
2724946cc463STadeusz Struk 	}
2725946cc463STadeusz Struk 	/* verify that decrypted message is equal to the original msg */
27260507de94SVitaly Chikunov 	if (memchr_inv(outbuf_dec, 0, out_len - m_size) ||
27270507de94SVitaly Chikunov 	    memcmp(m, outbuf_dec + out_len - m_size, m_size)) {
27280507de94SVitaly Chikunov 		pr_err("alg: akcipher: %s test failed. Invalid output\n", op);
272950d2b643SHerbert Xu 		hexdump(outbuf_dec, out_len);
2730946cc463STadeusz Struk 		err = -EINVAL;
2731946cc463STadeusz Struk 	}
2732946cc463STadeusz Struk free_all:
2733946cc463STadeusz Struk 	kfree(outbuf_dec);
2734946cc463STadeusz Struk 	kfree(outbuf_enc);
2735946cc463STadeusz Struk free_req:
2736946cc463STadeusz Struk 	akcipher_request_free(req);
2737df27b26fSHerbert Xu free_xbuf:
2738df27b26fSHerbert Xu 	testmgr_free_buf(xbuf);
2739946cc463STadeusz Struk 	return err;
2740946cc463STadeusz Struk }
2741946cc463STadeusz Struk 
274250d2b643SHerbert Xu static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
2743b13b1e0cSEric Biggers 			 const struct akcipher_testvec *vecs,
2744b13b1e0cSEric Biggers 			 unsigned int tcount)
2745946cc463STadeusz Struk {
274615226e48SHerbert Xu 	const char *algo =
274715226e48SHerbert Xu 		crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
2748946cc463STadeusz Struk 	int ret, i;
2749946cc463STadeusz Struk 
2750946cc463STadeusz Struk 	for (i = 0; i < tcount; i++) {
275150d2b643SHerbert Xu 		ret = test_akcipher_one(tfm, vecs++);
275250d2b643SHerbert Xu 		if (!ret)
275350d2b643SHerbert Xu 			continue;
275450d2b643SHerbert Xu 
275515226e48SHerbert Xu 		pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
275615226e48SHerbert Xu 		       i + 1, algo, ret);
2757946cc463STadeusz Struk 		return ret;
2758946cc463STadeusz Struk 	}
2759946cc463STadeusz Struk 	return 0;
2760946cc463STadeusz Struk }
2761946cc463STadeusz Struk 
2762946cc463STadeusz Struk static int alg_test_akcipher(const struct alg_test_desc *desc,
2763946cc463STadeusz Struk 			     const char *driver, u32 type, u32 mask)
2764946cc463STadeusz Struk {
2765946cc463STadeusz Struk 	struct crypto_akcipher *tfm;
2766946cc463STadeusz Struk 	int err = 0;
2767946cc463STadeusz Struk 
2768eed93e0cSHerbert Xu 	tfm = crypto_alloc_akcipher(driver, type, mask);
2769946cc463STadeusz Struk 	if (IS_ERR(tfm)) {
2770946cc463STadeusz Struk 		pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
2771946cc463STadeusz Struk 		       driver, PTR_ERR(tfm));
2772946cc463STadeusz Struk 		return PTR_ERR(tfm);
2773946cc463STadeusz Struk 	}
2774946cc463STadeusz Struk 	if (desc->suite.akcipher.vecs)
2775946cc463STadeusz Struk 		err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
2776946cc463STadeusz Struk 				    desc->suite.akcipher.count);
2777946cc463STadeusz Struk 
2778946cc463STadeusz Struk 	crypto_free_akcipher(tfm);
2779946cc463STadeusz Struk 	return err;
2780946cc463STadeusz Struk }
2781946cc463STadeusz Struk 
2782863b557aSYouquan, Song static int alg_test_null(const struct alg_test_desc *desc,
2783863b557aSYouquan, Song 			     const char *driver, u32 type, u32 mask)
2784863b557aSYouquan, Song {
2785863b557aSYouquan, Song 	return 0;
2786863b557aSYouquan, Song }
2787863b557aSYouquan, Song 
278821c8e720SArd Biesheuvel #define __VECS(tv)	{ .vecs = tv, .count = ARRAY_SIZE(tv) }
278921c8e720SArd Biesheuvel 
2790da7f033dSHerbert Xu /* Please keep this list sorted by algorithm name. */
2791da7f033dSHerbert Xu static const struct alg_test_desc alg_test_descs[] = {
2792da7f033dSHerbert Xu 	{
2793059c2a4dSEric Biggers 		.alg = "adiantum(xchacha12,aes)",
2794059c2a4dSEric Biggers 		.test = alg_test_skcipher,
2795059c2a4dSEric Biggers 		.suite = {
2796059c2a4dSEric Biggers 			.cipher = __VECS(adiantum_xchacha12_aes_tv_template)
2797059c2a4dSEric Biggers 		},
2798059c2a4dSEric Biggers 	}, {
2799059c2a4dSEric Biggers 		.alg = "adiantum(xchacha20,aes)",
2800059c2a4dSEric Biggers 		.test = alg_test_skcipher,
2801059c2a4dSEric Biggers 		.suite = {
2802059c2a4dSEric Biggers 			.cipher = __VECS(adiantum_xchacha20_aes_tv_template)
2803059c2a4dSEric Biggers 		},
2804059c2a4dSEric Biggers 	}, {
2805b87dc203SOndrej Mosnacek 		.alg = "aegis128",
2806b87dc203SOndrej Mosnacek 		.test = alg_test_aead,
2807b87dc203SOndrej Mosnacek 		.suite = {
2808a0d608eeSEric Biggers 			.aead = __VECS(aegis128_tv_template)
2809b87dc203SOndrej Mosnacek 		}
2810b87dc203SOndrej Mosnacek 	}, {
2811b87dc203SOndrej Mosnacek 		.alg = "aegis128l",
2812b87dc203SOndrej Mosnacek 		.test = alg_test_aead,
2813b87dc203SOndrej Mosnacek 		.suite = {
2814a0d608eeSEric Biggers 			.aead = __VECS(aegis128l_tv_template)
2815b87dc203SOndrej Mosnacek 		}
2816b87dc203SOndrej Mosnacek 	}, {
2817b87dc203SOndrej Mosnacek 		.alg = "aegis256",
2818b87dc203SOndrej Mosnacek 		.test = alg_test_aead,
2819b87dc203SOndrej Mosnacek 		.suite = {
2820a0d608eeSEric Biggers 			.aead = __VECS(aegis256_tv_template)
2821b87dc203SOndrej Mosnacek 		}
2822b87dc203SOndrej Mosnacek 	}, {
2823e08ca2daSJarod Wilson 		.alg = "ansi_cprng",
2824e08ca2daSJarod Wilson 		.test = alg_test_cprng,
2825e08ca2daSJarod Wilson 		.suite = {
282621c8e720SArd Biesheuvel 			.cprng = __VECS(ansi_cprng_aes_tv_template)
2827e08ca2daSJarod Wilson 		}
2828e08ca2daSJarod Wilson 	}, {
2829bca4feb0SHoria Geanta 		.alg = "authenc(hmac(md5),ecb(cipher_null))",
2830bca4feb0SHoria Geanta 		.test = alg_test_aead,
2831bca4feb0SHoria Geanta 		.suite = {
2832a0d608eeSEric Biggers 			.aead = __VECS(hmac_md5_ecb_cipher_null_tv_template)
2833bca4feb0SHoria Geanta 		}
2834bca4feb0SHoria Geanta 	}, {
2835a4198fd4SHerbert Xu 		.alg = "authenc(hmac(sha1),cbc(aes))",
2836e46e9a46SHoria Geanta 		.test = alg_test_aead,
2837bcf741cbSHerbert Xu 		.fips_allowed = 1,
2838e46e9a46SHoria Geanta 		.suite = {
2839a0d608eeSEric Biggers 			.aead = __VECS(hmac_sha1_aes_cbc_tv_temp)
28405208ed2cSNitesh Lal 		}
28415208ed2cSNitesh Lal 	}, {
2842a4198fd4SHerbert Xu 		.alg = "authenc(hmac(sha1),cbc(des))",
28435208ed2cSNitesh Lal 		.test = alg_test_aead,
28445208ed2cSNitesh Lal 		.suite = {
2845a0d608eeSEric Biggers 			.aead = __VECS(hmac_sha1_des_cbc_tv_temp)
28465208ed2cSNitesh Lal 		}
28475208ed2cSNitesh Lal 	}, {
2848a4198fd4SHerbert Xu 		.alg = "authenc(hmac(sha1),cbc(des3_ede))",
28495208ed2cSNitesh Lal 		.test = alg_test_aead,
2850ed1afac9SMarcus Meissner 		.fips_allowed = 1,
28515208ed2cSNitesh Lal 		.suite = {
2852a0d608eeSEric Biggers 			.aead = __VECS(hmac_sha1_des3_ede_cbc_tv_temp)
2853e46e9a46SHoria Geanta 		}
2854e46e9a46SHoria Geanta 	}, {
2855fb16abc2SMarcus Meissner 		.alg = "authenc(hmac(sha1),ctr(aes))",
2856fb16abc2SMarcus Meissner 		.test = alg_test_null,
2857fb16abc2SMarcus Meissner 		.fips_allowed = 1,
2858fb16abc2SMarcus Meissner 	}, {
2859bca4feb0SHoria Geanta 		.alg = "authenc(hmac(sha1),ecb(cipher_null))",
2860bca4feb0SHoria Geanta 		.test = alg_test_aead,
2861bca4feb0SHoria Geanta 		.suite = {
2862a0d608eeSEric Biggers 			.aead = __VECS(hmac_sha1_ecb_cipher_null_tv_temp)
28635208ed2cSNitesh Lal 		}
28645208ed2cSNitesh Lal 	}, {
28658888690eSMarcus Meissner 		.alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
28668888690eSMarcus Meissner 		.test = alg_test_null,
28678888690eSMarcus Meissner 		.fips_allowed = 1,
28688888690eSMarcus Meissner 	}, {
2869a4198fd4SHerbert Xu 		.alg = "authenc(hmac(sha224),cbc(des))",
28705208ed2cSNitesh Lal 		.test = alg_test_aead,
28715208ed2cSNitesh Lal 		.suite = {
2872a0d608eeSEric Biggers 			.aead = __VECS(hmac_sha224_des_cbc_tv_temp)
28735208ed2cSNitesh Lal 		}
28745208ed2cSNitesh Lal 	}, {
2875a4198fd4SHerbert Xu 		.alg = "authenc(hmac(sha224),cbc(des3_ede))",
28765208ed2cSNitesh Lal 		.test = alg_test_aead,
2877ed1afac9SMarcus Meissner 		.fips_allowed = 1,
28785208ed2cSNitesh Lal 		.suite = {
2879a0d608eeSEric Biggers 			.aead = __VECS(hmac_sha224_des3_ede_cbc_tv_temp)
2880bca4feb0SHoria Geanta 		}
2881bca4feb0SHoria Geanta 	}, {
2882a4198fd4SHerbert Xu 		.alg = "authenc(hmac(sha256),cbc(aes))",
2883e46e9a46SHoria Geanta 		.test = alg_test_aead,
2884ed1afac9SMarcus Meissner 		.fips_allowed = 1,
2885e46e9a46SHoria Geanta 		.suite = {
2886a0d608eeSEric Biggers 			.aead = __VECS(hmac_sha256_aes_cbc_tv_temp)
28875208ed2cSNitesh Lal 		}
28885208ed2cSNitesh Lal 	}, {
2889a4198fd4SHerbert Xu 		.alg = "authenc(hmac(sha256),cbc(des))",
28905208ed2cSNitesh Lal 		.test = alg_test_aead,
28915208ed2cSNitesh Lal 		.suite = {
2892a0d608eeSEric Biggers 			.aead = __VECS(hmac_sha256_des_cbc_tv_temp)
28935208ed2cSNitesh Lal 		}
28945208ed2cSNitesh Lal 	}, {
2895a4198fd4SHerbert Xu 		.alg = "authenc(hmac(sha256),cbc(des3_ede))",
28965208ed2cSNitesh Lal 		.test = alg_test_aead,
2897ed1afac9SMarcus Meissner 		.fips_allowed = 1,
28985208ed2cSNitesh Lal 		.suite = {
2899a0d608eeSEric Biggers 			.aead = __VECS(hmac_sha256_des3_ede_cbc_tv_temp)
29005208ed2cSNitesh Lal 		}
29015208ed2cSNitesh Lal 	}, {
2902fb16abc2SMarcus Meissner 		.alg = "authenc(hmac(sha256),ctr(aes))",
2903fb16abc2SMarcus Meissner 		.test = alg_test_null,
2904fb16abc2SMarcus Meissner 		.fips_allowed = 1,
2905fb16abc2SMarcus Meissner 	}, {
29068888690eSMarcus Meissner 		.alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
29078888690eSMarcus Meissner 		.test = alg_test_null,
29088888690eSMarcus Meissner 		.fips_allowed = 1,
29098888690eSMarcus Meissner 	}, {
2910a4198fd4SHerbert Xu 		.alg = "authenc(hmac(sha384),cbc(des))",
29115208ed2cSNitesh Lal 		.test = alg_test_aead,
29125208ed2cSNitesh Lal 		.suite = {
2913a0d608eeSEric Biggers 			.aead = __VECS(hmac_sha384_des_cbc_tv_temp)
29145208ed2cSNitesh Lal 		}
29155208ed2cSNitesh Lal 	}, {
2916a4198fd4SHerbert Xu 		.alg = "authenc(hmac(sha384),cbc(des3_ede))",
29175208ed2cSNitesh Lal 		.test = alg_test_aead,
2918ed1afac9SMarcus Meissner 		.fips_allowed = 1,
29195208ed2cSNitesh Lal 		.suite = {
2920a0d608eeSEric Biggers 			.aead = __VECS(hmac_sha384_des3_ede_cbc_tv_temp)
2921e46e9a46SHoria Geanta 		}
2922e46e9a46SHoria Geanta 	}, {
2923fb16abc2SMarcus Meissner 		.alg = "authenc(hmac(sha384),ctr(aes))",
2924fb16abc2SMarcus Meissner 		.test = alg_test_null,
2925fb16abc2SMarcus Meissner 		.fips_allowed = 1,
2926fb16abc2SMarcus Meissner 	}, {
29278888690eSMarcus Meissner 		.alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
29288888690eSMarcus Meissner 		.test = alg_test_null,
29298888690eSMarcus Meissner 		.fips_allowed = 1,
29308888690eSMarcus Meissner 	}, {
2931a4198fd4SHerbert Xu 		.alg = "authenc(hmac(sha512),cbc(aes))",
2932ed1afac9SMarcus Meissner 		.fips_allowed = 1,
2933e46e9a46SHoria Geanta 		.test = alg_test_aead,
2934e46e9a46SHoria Geanta 		.suite = {
2935a0d608eeSEric Biggers 			.aead = __VECS(hmac_sha512_aes_cbc_tv_temp)
29365208ed2cSNitesh Lal 		}
29375208ed2cSNitesh Lal 	}, {
2938a4198fd4SHerbert Xu 		.alg = "authenc(hmac(sha512),cbc(des))",
29395208ed2cSNitesh Lal 		.test = alg_test_aead,
29405208ed2cSNitesh Lal 		.suite = {
2941a0d608eeSEric Biggers 			.aead = __VECS(hmac_sha512_des_cbc_tv_temp)
29425208ed2cSNitesh Lal 		}
29435208ed2cSNitesh Lal 	}, {
2944a4198fd4SHerbert Xu 		.alg = "authenc(hmac(sha512),cbc(des3_ede))",
29455208ed2cSNitesh Lal 		.test = alg_test_aead,
2946ed1afac9SMarcus Meissner 		.fips_allowed = 1,
29475208ed2cSNitesh Lal 		.suite = {
2948a0d608eeSEric Biggers 			.aead = __VECS(hmac_sha512_des3_ede_cbc_tv_temp)
2949e46e9a46SHoria Geanta 		}
2950e46e9a46SHoria Geanta 	}, {
2951fb16abc2SMarcus Meissner 		.alg = "authenc(hmac(sha512),ctr(aes))",
2952fb16abc2SMarcus Meissner 		.test = alg_test_null,
2953fb16abc2SMarcus Meissner 		.fips_allowed = 1,
2954fb16abc2SMarcus Meissner 	}, {
29558888690eSMarcus Meissner 		.alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
29568888690eSMarcus Meissner 		.test = alg_test_null,
29578888690eSMarcus Meissner 		.fips_allowed = 1,
29588888690eSMarcus Meissner 	}, {
2959da7f033dSHerbert Xu 		.alg = "cbc(aes)",
29601aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
2961a1915d51SJarod Wilson 		.fips_allowed = 1,
2962da7f033dSHerbert Xu 		.suite = {
296392a4c9feSEric Biggers 			.cipher = __VECS(aes_cbc_tv_template)
296492a4c9feSEric Biggers 		},
2965da7f033dSHerbert Xu 	}, {
2966da7f033dSHerbert Xu 		.alg = "cbc(anubis)",
29671aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
2968da7f033dSHerbert Xu 		.suite = {
296992a4c9feSEric Biggers 			.cipher = __VECS(anubis_cbc_tv_template)
297092a4c9feSEric Biggers 		},
2971da7f033dSHerbert Xu 	}, {
2972da7f033dSHerbert Xu 		.alg = "cbc(blowfish)",
29731aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
2974da7f033dSHerbert Xu 		.suite = {
297592a4c9feSEric Biggers 			.cipher = __VECS(bf_cbc_tv_template)
297692a4c9feSEric Biggers 		},
2977da7f033dSHerbert Xu 	}, {
2978da7f033dSHerbert Xu 		.alg = "cbc(camellia)",
29791aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
2980da7f033dSHerbert Xu 		.suite = {
298192a4c9feSEric Biggers 			.cipher = __VECS(camellia_cbc_tv_template)
298292a4c9feSEric Biggers 		},
2983da7f033dSHerbert Xu 	}, {
2984a2c58260SJohannes Goetzfried 		.alg = "cbc(cast5)",
2985a2c58260SJohannes Goetzfried 		.test = alg_test_skcipher,
2986a2c58260SJohannes Goetzfried 		.suite = {
298792a4c9feSEric Biggers 			.cipher = __VECS(cast5_cbc_tv_template)
298892a4c9feSEric Biggers 		},
2989a2c58260SJohannes Goetzfried 	}, {
29909b8b0405SJohannes Goetzfried 		.alg = "cbc(cast6)",
29919b8b0405SJohannes Goetzfried 		.test = alg_test_skcipher,
29929b8b0405SJohannes Goetzfried 		.suite = {
299392a4c9feSEric Biggers 			.cipher = __VECS(cast6_cbc_tv_template)
299492a4c9feSEric Biggers 		},
29959b8b0405SJohannes Goetzfried 	}, {
2996da7f033dSHerbert Xu 		.alg = "cbc(des)",
29971aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
2998da7f033dSHerbert Xu 		.suite = {
299992a4c9feSEric Biggers 			.cipher = __VECS(des_cbc_tv_template)
300092a4c9feSEric Biggers 		},
3001da7f033dSHerbert Xu 	}, {
3002da7f033dSHerbert Xu 		.alg = "cbc(des3_ede)",
30031aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3004a1915d51SJarod Wilson 		.fips_allowed = 1,
3005da7f033dSHerbert Xu 		.suite = {
300692a4c9feSEric Biggers 			.cipher = __VECS(des3_ede_cbc_tv_template)
300792a4c9feSEric Biggers 		},
3008da7f033dSHerbert Xu 	}, {
3009a794d8d8SGilad Ben-Yossef 		/* Same as cbc(aes) except the key is stored in
3010a794d8d8SGilad Ben-Yossef 		 * hardware secure memory which we reference by index
3011a794d8d8SGilad Ben-Yossef 		 */
3012a794d8d8SGilad Ben-Yossef 		.alg = "cbc(paes)",
3013a794d8d8SGilad Ben-Yossef 		.test = alg_test_null,
3014a794d8d8SGilad Ben-Yossef 		.fips_allowed = 1,
3015a794d8d8SGilad Ben-Yossef 	}, {
30169d25917dSJussi Kivilinna 		.alg = "cbc(serpent)",
30179d25917dSJussi Kivilinna 		.test = alg_test_skcipher,
30189d25917dSJussi Kivilinna 		.suite = {
301992a4c9feSEric Biggers 			.cipher = __VECS(serpent_cbc_tv_template)
302092a4c9feSEric Biggers 		},
30219d25917dSJussi Kivilinna 	}, {
302295ba5973SGilad Ben-Yossef 		.alg = "cbc(sm4)",
302395ba5973SGilad Ben-Yossef 		.test = alg_test_skcipher,
302495ba5973SGilad Ben-Yossef 		.suite = {
302595ba5973SGilad Ben-Yossef 			.cipher = __VECS(sm4_cbc_tv_template)
302695ba5973SGilad Ben-Yossef 		}
302795ba5973SGilad Ben-Yossef 	}, {
3028da7f033dSHerbert Xu 		.alg = "cbc(twofish)",
30291aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3030da7f033dSHerbert Xu 		.suite = {
303192a4c9feSEric Biggers 			.cipher = __VECS(tf_cbc_tv_template)
303292a4c9feSEric Biggers 		},
3033da7f033dSHerbert Xu 	}, {
3034092acf06SArd Biesheuvel 		.alg = "cbcmac(aes)",
3035092acf06SArd Biesheuvel 		.fips_allowed = 1,
3036092acf06SArd Biesheuvel 		.test = alg_test_hash,
3037092acf06SArd Biesheuvel 		.suite = {
3038092acf06SArd Biesheuvel 			.hash = __VECS(aes_cbcmac_tv_template)
3039092acf06SArd Biesheuvel 		}
3040092acf06SArd Biesheuvel 	}, {
3041da7f033dSHerbert Xu 		.alg = "ccm(aes)",
3042da7f033dSHerbert Xu 		.test = alg_test_aead,
3043a1915d51SJarod Wilson 		.fips_allowed = 1,
3044da7f033dSHerbert Xu 		.suite = {
3045a0d608eeSEric Biggers 			.aead = __VECS(aes_ccm_tv_template)
3046da7f033dSHerbert Xu 		}
3047da7f033dSHerbert Xu 	}, {
30487da66670SDmitry Eremin-Solenikov 		.alg = "cfb(aes)",
30497da66670SDmitry Eremin-Solenikov 		.test = alg_test_skcipher,
30507da66670SDmitry Eremin-Solenikov 		.fips_allowed = 1,
30517da66670SDmitry Eremin-Solenikov 		.suite = {
30527da66670SDmitry Eremin-Solenikov 			.cipher = __VECS(aes_cfb_tv_template)
30537da66670SDmitry Eremin-Solenikov 		},
30547da66670SDmitry Eremin-Solenikov 	}, {
30553590ebf2SMartin Willi 		.alg = "chacha20",
30563590ebf2SMartin Willi 		.test = alg_test_skcipher,
30573590ebf2SMartin Willi 		.suite = {
305892a4c9feSEric Biggers 			.cipher = __VECS(chacha20_tv_template)
305992a4c9feSEric Biggers 		},
30603590ebf2SMartin Willi 	}, {
306193b5e86aSJussi Kivilinna 		.alg = "cmac(aes)",
30628f183751SStephan Mueller 		.fips_allowed = 1,
306393b5e86aSJussi Kivilinna 		.test = alg_test_hash,
306493b5e86aSJussi Kivilinna 		.suite = {
306521c8e720SArd Biesheuvel 			.hash = __VECS(aes_cmac128_tv_template)
306693b5e86aSJussi Kivilinna 		}
306793b5e86aSJussi Kivilinna 	}, {
306893b5e86aSJussi Kivilinna 		.alg = "cmac(des3_ede)",
30698f183751SStephan Mueller 		.fips_allowed = 1,
307093b5e86aSJussi Kivilinna 		.test = alg_test_hash,
307193b5e86aSJussi Kivilinna 		.suite = {
307221c8e720SArd Biesheuvel 			.hash = __VECS(des3_ede_cmac64_tv_template)
307393b5e86aSJussi Kivilinna 		}
307493b5e86aSJussi Kivilinna 	}, {
3075e448370dSJussi Kivilinna 		.alg = "compress_null",
3076e448370dSJussi Kivilinna 		.test = alg_test_null,
3077e448370dSJussi Kivilinna 	}, {
3078ebb3472fSArd Biesheuvel 		.alg = "crc32",
3079ebb3472fSArd Biesheuvel 		.test = alg_test_hash,
3080a8a34416SMilan Broz 		.fips_allowed = 1,
3081ebb3472fSArd Biesheuvel 		.suite = {
308221c8e720SArd Biesheuvel 			.hash = __VECS(crc32_tv_template)
3083ebb3472fSArd Biesheuvel 		}
3084ebb3472fSArd Biesheuvel 	}, {
3085da7f033dSHerbert Xu 		.alg = "crc32c",
30868e3ee85eSHerbert Xu 		.test = alg_test_crc32c,
3087a1915d51SJarod Wilson 		.fips_allowed = 1,
3088da7f033dSHerbert Xu 		.suite = {
308921c8e720SArd Biesheuvel 			.hash = __VECS(crc32c_tv_template)
3090da7f033dSHerbert Xu 		}
3091da7f033dSHerbert Xu 	}, {
309268411521SHerbert Xu 		.alg = "crct10dif",
309368411521SHerbert Xu 		.test = alg_test_hash,
309468411521SHerbert Xu 		.fips_allowed = 1,
309568411521SHerbert Xu 		.suite = {
309621c8e720SArd Biesheuvel 			.hash = __VECS(crct10dif_tv_template)
309768411521SHerbert Xu 		}
309868411521SHerbert Xu 	}, {
3099f7cb80f2SJarod Wilson 		.alg = "ctr(aes)",
3100f7cb80f2SJarod Wilson 		.test = alg_test_skcipher,
3101a1915d51SJarod Wilson 		.fips_allowed = 1,
3102f7cb80f2SJarod Wilson 		.suite = {
310392a4c9feSEric Biggers 			.cipher = __VECS(aes_ctr_tv_template)
3104f7cb80f2SJarod Wilson 		}
3105f7cb80f2SJarod Wilson 	}, {
310685b63e34SJussi Kivilinna 		.alg = "ctr(blowfish)",
310785b63e34SJussi Kivilinna 		.test = alg_test_skcipher,
310885b63e34SJussi Kivilinna 		.suite = {
310992a4c9feSEric Biggers 			.cipher = __VECS(bf_ctr_tv_template)
311085b63e34SJussi Kivilinna 		}
311185b63e34SJussi Kivilinna 	}, {
31120840605eSJussi Kivilinna 		.alg = "ctr(camellia)",
31130840605eSJussi Kivilinna 		.test = alg_test_skcipher,
31140840605eSJussi Kivilinna 		.suite = {
311592a4c9feSEric Biggers 			.cipher = __VECS(camellia_ctr_tv_template)
31160840605eSJussi Kivilinna 		}
31170840605eSJussi Kivilinna 	}, {
3118a2c58260SJohannes Goetzfried 		.alg = "ctr(cast5)",
3119a2c58260SJohannes Goetzfried 		.test = alg_test_skcipher,
3120a2c58260SJohannes Goetzfried 		.suite = {
312192a4c9feSEric Biggers 			.cipher = __VECS(cast5_ctr_tv_template)
3122a2c58260SJohannes Goetzfried 		}
3123a2c58260SJohannes Goetzfried 	}, {
31249b8b0405SJohannes Goetzfried 		.alg = "ctr(cast6)",
31259b8b0405SJohannes Goetzfried 		.test = alg_test_skcipher,
31269b8b0405SJohannes Goetzfried 		.suite = {
312792a4c9feSEric Biggers 			.cipher = __VECS(cast6_ctr_tv_template)
31289b8b0405SJohannes Goetzfried 		}
31299b8b0405SJohannes Goetzfried 	}, {
31308163fc30SJussi Kivilinna 		.alg = "ctr(des)",
31318163fc30SJussi Kivilinna 		.test = alg_test_skcipher,
31328163fc30SJussi Kivilinna 		.suite = {
313392a4c9feSEric Biggers 			.cipher = __VECS(des_ctr_tv_template)
31348163fc30SJussi Kivilinna 		}
31358163fc30SJussi Kivilinna 	}, {
3136e080b17aSJussi Kivilinna 		.alg = "ctr(des3_ede)",
3137e080b17aSJussi Kivilinna 		.test = alg_test_skcipher,
31380d8da104SMarcelo Cerri 		.fips_allowed = 1,
3139e080b17aSJussi Kivilinna 		.suite = {
314092a4c9feSEric Biggers 			.cipher = __VECS(des3_ede_ctr_tv_template)
3141e080b17aSJussi Kivilinna 		}
3142e080b17aSJussi Kivilinna 	}, {
3143a794d8d8SGilad Ben-Yossef 		/* Same as ctr(aes) except the key is stored in
3144a794d8d8SGilad Ben-Yossef 		 * hardware secure memory which we reference by index
3145a794d8d8SGilad Ben-Yossef 		 */
3146a794d8d8SGilad Ben-Yossef 		.alg = "ctr(paes)",
3147a794d8d8SGilad Ben-Yossef 		.test = alg_test_null,
3148a794d8d8SGilad Ben-Yossef 		.fips_allowed = 1,
3149a794d8d8SGilad Ben-Yossef 	}, {
31509d25917dSJussi Kivilinna 		.alg = "ctr(serpent)",
31519d25917dSJussi Kivilinna 		.test = alg_test_skcipher,
31529d25917dSJussi Kivilinna 		.suite = {
315392a4c9feSEric Biggers 			.cipher = __VECS(serpent_ctr_tv_template)
31549d25917dSJussi Kivilinna 		}
31559d25917dSJussi Kivilinna 	}, {
315695ba5973SGilad Ben-Yossef 		.alg = "ctr(sm4)",
315795ba5973SGilad Ben-Yossef 		.test = alg_test_skcipher,
315895ba5973SGilad Ben-Yossef 		.suite = {
315995ba5973SGilad Ben-Yossef 			.cipher = __VECS(sm4_ctr_tv_template)
316095ba5973SGilad Ben-Yossef 		}
316195ba5973SGilad Ben-Yossef 	}, {
3162573da620SJussi Kivilinna 		.alg = "ctr(twofish)",
3163573da620SJussi Kivilinna 		.test = alg_test_skcipher,
3164573da620SJussi Kivilinna 		.suite = {
316592a4c9feSEric Biggers 			.cipher = __VECS(tf_ctr_tv_template)
3166573da620SJussi Kivilinna 		}
3167573da620SJussi Kivilinna 	}, {
3168da7f033dSHerbert Xu 		.alg = "cts(cbc(aes))",
31691aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3170196ad604SGilad Ben-Yossef 		.fips_allowed = 1,
3171da7f033dSHerbert Xu 		.suite = {
317292a4c9feSEric Biggers 			.cipher = __VECS(cts_mode_tv_template)
3173da7f033dSHerbert Xu 		}
3174da7f033dSHerbert Xu 	}, {
3175da7f033dSHerbert Xu 		.alg = "deflate",
3176da7f033dSHerbert Xu 		.test = alg_test_comp,
31770818904dSMilan Broz 		.fips_allowed = 1,
3178da7f033dSHerbert Xu 		.suite = {
3179da7f033dSHerbert Xu 			.comp = {
318021c8e720SArd Biesheuvel 				.comp = __VECS(deflate_comp_tv_template),
318121c8e720SArd Biesheuvel 				.decomp = __VECS(deflate_decomp_tv_template)
3182da7f033dSHerbert Xu 			}
3183da7f033dSHerbert Xu 		}
3184da7f033dSHerbert Xu 	}, {
3185802c7f1cSSalvatore Benedetto 		.alg = "dh",
3186802c7f1cSSalvatore Benedetto 		.test = alg_test_kpp,
3187802c7f1cSSalvatore Benedetto 		.fips_allowed = 1,
3188802c7f1cSSalvatore Benedetto 		.suite = {
318921c8e720SArd Biesheuvel 			.kpp = __VECS(dh_tv_template)
3190802c7f1cSSalvatore Benedetto 		}
3191802c7f1cSSalvatore Benedetto 	}, {
3192e448370dSJussi Kivilinna 		.alg = "digest_null",
3193e448370dSJussi Kivilinna 		.test = alg_test_null,
3194e448370dSJussi Kivilinna 	}, {
319564d1cdfbSStephan Mueller 		.alg = "drbg_nopr_ctr_aes128",
319664d1cdfbSStephan Mueller 		.test = alg_test_drbg,
319764d1cdfbSStephan Mueller 		.fips_allowed = 1,
319864d1cdfbSStephan Mueller 		.suite = {
319921c8e720SArd Biesheuvel 			.drbg = __VECS(drbg_nopr_ctr_aes128_tv_template)
320064d1cdfbSStephan Mueller 		}
320164d1cdfbSStephan Mueller 	}, {
320264d1cdfbSStephan Mueller 		.alg = "drbg_nopr_ctr_aes192",
320364d1cdfbSStephan Mueller 		.test = alg_test_drbg,
320464d1cdfbSStephan Mueller 		.fips_allowed = 1,
320564d1cdfbSStephan Mueller 		.suite = {
320621c8e720SArd Biesheuvel 			.drbg = __VECS(drbg_nopr_ctr_aes192_tv_template)
320764d1cdfbSStephan Mueller 		}
320864d1cdfbSStephan Mueller 	}, {
320964d1cdfbSStephan Mueller 		.alg = "drbg_nopr_ctr_aes256",
321064d1cdfbSStephan Mueller 		.test = alg_test_drbg,
321164d1cdfbSStephan Mueller 		.fips_allowed = 1,
321264d1cdfbSStephan Mueller 		.suite = {
321321c8e720SArd Biesheuvel 			.drbg = __VECS(drbg_nopr_ctr_aes256_tv_template)
321464d1cdfbSStephan Mueller 		}
321564d1cdfbSStephan Mueller 	}, {
321664d1cdfbSStephan Mueller 		/*
321764d1cdfbSStephan Mueller 		 * There is no need to specifically test the DRBG with every
321864d1cdfbSStephan Mueller 		 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
321964d1cdfbSStephan Mueller 		 */
322064d1cdfbSStephan Mueller 		.alg = "drbg_nopr_hmac_sha1",
322164d1cdfbSStephan Mueller 		.fips_allowed = 1,
322264d1cdfbSStephan Mueller 		.test = alg_test_null,
322364d1cdfbSStephan Mueller 	}, {
322464d1cdfbSStephan Mueller 		.alg = "drbg_nopr_hmac_sha256",
322564d1cdfbSStephan Mueller 		.test = alg_test_drbg,
322664d1cdfbSStephan Mueller 		.fips_allowed = 1,
322764d1cdfbSStephan Mueller 		.suite = {
322821c8e720SArd Biesheuvel 			.drbg = __VECS(drbg_nopr_hmac_sha256_tv_template)
322964d1cdfbSStephan Mueller 		}
323064d1cdfbSStephan Mueller 	}, {
323164d1cdfbSStephan Mueller 		/* covered by drbg_nopr_hmac_sha256 test */
323264d1cdfbSStephan Mueller 		.alg = "drbg_nopr_hmac_sha384",
323364d1cdfbSStephan Mueller 		.fips_allowed = 1,
323464d1cdfbSStephan Mueller 		.test = alg_test_null,
323564d1cdfbSStephan Mueller 	}, {
323664d1cdfbSStephan Mueller 		.alg = "drbg_nopr_hmac_sha512",
323764d1cdfbSStephan Mueller 		.test = alg_test_null,
323864d1cdfbSStephan Mueller 		.fips_allowed = 1,
323964d1cdfbSStephan Mueller 	}, {
324064d1cdfbSStephan Mueller 		.alg = "drbg_nopr_sha1",
324164d1cdfbSStephan Mueller 		.fips_allowed = 1,
324264d1cdfbSStephan Mueller 		.test = alg_test_null,
324364d1cdfbSStephan Mueller 	}, {
324464d1cdfbSStephan Mueller 		.alg = "drbg_nopr_sha256",
324564d1cdfbSStephan Mueller 		.test = alg_test_drbg,
324664d1cdfbSStephan Mueller 		.fips_allowed = 1,
324764d1cdfbSStephan Mueller 		.suite = {
324821c8e720SArd Biesheuvel 			.drbg = __VECS(drbg_nopr_sha256_tv_template)
324964d1cdfbSStephan Mueller 		}
325064d1cdfbSStephan Mueller 	}, {
325164d1cdfbSStephan Mueller 		/* covered by drbg_nopr_sha256 test */
325264d1cdfbSStephan Mueller 		.alg = "drbg_nopr_sha384",
325364d1cdfbSStephan Mueller 		.fips_allowed = 1,
325464d1cdfbSStephan Mueller 		.test = alg_test_null,
325564d1cdfbSStephan Mueller 	}, {
325664d1cdfbSStephan Mueller 		.alg = "drbg_nopr_sha512",
325764d1cdfbSStephan Mueller 		.fips_allowed = 1,
325864d1cdfbSStephan Mueller 		.test = alg_test_null,
325964d1cdfbSStephan Mueller 	}, {
326064d1cdfbSStephan Mueller 		.alg = "drbg_pr_ctr_aes128",
326164d1cdfbSStephan Mueller 		.test = alg_test_drbg,
326264d1cdfbSStephan Mueller 		.fips_allowed = 1,
326364d1cdfbSStephan Mueller 		.suite = {
326421c8e720SArd Biesheuvel 			.drbg = __VECS(drbg_pr_ctr_aes128_tv_template)
326564d1cdfbSStephan Mueller 		}
326664d1cdfbSStephan Mueller 	}, {
326764d1cdfbSStephan Mueller 		/* covered by drbg_pr_ctr_aes128 test */
326864d1cdfbSStephan Mueller 		.alg = "drbg_pr_ctr_aes192",
326964d1cdfbSStephan Mueller 		.fips_allowed = 1,
327064d1cdfbSStephan Mueller 		.test = alg_test_null,
327164d1cdfbSStephan Mueller 	}, {
327264d1cdfbSStephan Mueller 		.alg = "drbg_pr_ctr_aes256",
327364d1cdfbSStephan Mueller 		.fips_allowed = 1,
327464d1cdfbSStephan Mueller 		.test = alg_test_null,
327564d1cdfbSStephan Mueller 	}, {
327664d1cdfbSStephan Mueller 		.alg = "drbg_pr_hmac_sha1",
327764d1cdfbSStephan Mueller 		.fips_allowed = 1,
327864d1cdfbSStephan Mueller 		.test = alg_test_null,
327964d1cdfbSStephan Mueller 	}, {
328064d1cdfbSStephan Mueller 		.alg = "drbg_pr_hmac_sha256",
328164d1cdfbSStephan Mueller 		.test = alg_test_drbg,
328264d1cdfbSStephan Mueller 		.fips_allowed = 1,
328364d1cdfbSStephan Mueller 		.suite = {
328421c8e720SArd Biesheuvel 			.drbg = __VECS(drbg_pr_hmac_sha256_tv_template)
328564d1cdfbSStephan Mueller 		}
328664d1cdfbSStephan Mueller 	}, {
328764d1cdfbSStephan Mueller 		/* covered by drbg_pr_hmac_sha256 test */
328864d1cdfbSStephan Mueller 		.alg = "drbg_pr_hmac_sha384",
328964d1cdfbSStephan Mueller 		.fips_allowed = 1,
329064d1cdfbSStephan Mueller 		.test = alg_test_null,
329164d1cdfbSStephan Mueller 	}, {
329264d1cdfbSStephan Mueller 		.alg = "drbg_pr_hmac_sha512",
329364d1cdfbSStephan Mueller 		.test = alg_test_null,
329464d1cdfbSStephan Mueller 		.fips_allowed = 1,
329564d1cdfbSStephan Mueller 	}, {
329664d1cdfbSStephan Mueller 		.alg = "drbg_pr_sha1",
329764d1cdfbSStephan Mueller 		.fips_allowed = 1,
329864d1cdfbSStephan Mueller 		.test = alg_test_null,
329964d1cdfbSStephan Mueller 	}, {
330064d1cdfbSStephan Mueller 		.alg = "drbg_pr_sha256",
330164d1cdfbSStephan Mueller 		.test = alg_test_drbg,
330264d1cdfbSStephan Mueller 		.fips_allowed = 1,
330364d1cdfbSStephan Mueller 		.suite = {
330421c8e720SArd Biesheuvel 			.drbg = __VECS(drbg_pr_sha256_tv_template)
330564d1cdfbSStephan Mueller 		}
330664d1cdfbSStephan Mueller 	}, {
330764d1cdfbSStephan Mueller 		/* covered by drbg_pr_sha256 test */
330864d1cdfbSStephan Mueller 		.alg = "drbg_pr_sha384",
330964d1cdfbSStephan Mueller 		.fips_allowed = 1,
331064d1cdfbSStephan Mueller 		.test = alg_test_null,
331164d1cdfbSStephan Mueller 	}, {
331264d1cdfbSStephan Mueller 		.alg = "drbg_pr_sha512",
331364d1cdfbSStephan Mueller 		.fips_allowed = 1,
331464d1cdfbSStephan Mueller 		.test = alg_test_null,
331564d1cdfbSStephan Mueller 	}, {
3316da7f033dSHerbert Xu 		.alg = "ecb(aes)",
33171aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3318a1915d51SJarod Wilson 		.fips_allowed = 1,
3319da7f033dSHerbert Xu 		.suite = {
332092a4c9feSEric Biggers 			.cipher = __VECS(aes_tv_template)
3321da7f033dSHerbert Xu 		}
3322da7f033dSHerbert Xu 	}, {
3323da7f033dSHerbert Xu 		.alg = "ecb(anubis)",
33241aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3325da7f033dSHerbert Xu 		.suite = {
332692a4c9feSEric Biggers 			.cipher = __VECS(anubis_tv_template)
3327da7f033dSHerbert Xu 		}
3328da7f033dSHerbert Xu 	}, {
3329da7f033dSHerbert Xu 		.alg = "ecb(arc4)",
33301aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3331da7f033dSHerbert Xu 		.suite = {
333292a4c9feSEric Biggers 			.cipher = __VECS(arc4_tv_template)
3333da7f033dSHerbert Xu 		}
3334da7f033dSHerbert Xu 	}, {
3335da7f033dSHerbert Xu 		.alg = "ecb(blowfish)",
33361aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3337da7f033dSHerbert Xu 		.suite = {
333892a4c9feSEric Biggers 			.cipher = __VECS(bf_tv_template)
3339da7f033dSHerbert Xu 		}
3340da7f033dSHerbert Xu 	}, {
3341da7f033dSHerbert Xu 		.alg = "ecb(camellia)",
33421aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3343da7f033dSHerbert Xu 		.suite = {
334492a4c9feSEric Biggers 			.cipher = __VECS(camellia_tv_template)
3345da7f033dSHerbert Xu 		}
3346da7f033dSHerbert Xu 	}, {
3347da7f033dSHerbert Xu 		.alg = "ecb(cast5)",
33481aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3349da7f033dSHerbert Xu 		.suite = {
335092a4c9feSEric Biggers 			.cipher = __VECS(cast5_tv_template)
3351da7f033dSHerbert Xu 		}
3352da7f033dSHerbert Xu 	}, {
3353da7f033dSHerbert Xu 		.alg = "ecb(cast6)",
33541aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3355da7f033dSHerbert Xu 		.suite = {
335692a4c9feSEric Biggers 			.cipher = __VECS(cast6_tv_template)
3357da7f033dSHerbert Xu 		}
3358da7f033dSHerbert Xu 	}, {
3359e448370dSJussi Kivilinna 		.alg = "ecb(cipher_null)",
3360e448370dSJussi Kivilinna 		.test = alg_test_null,
33616175ca2bSMilan Broz 		.fips_allowed = 1,
3362e448370dSJussi Kivilinna 	}, {
3363da7f033dSHerbert Xu 		.alg = "ecb(des)",
33641aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3365da7f033dSHerbert Xu 		.suite = {
336692a4c9feSEric Biggers 			.cipher = __VECS(des_tv_template)
3367da7f033dSHerbert Xu 		}
3368da7f033dSHerbert Xu 	}, {
3369da7f033dSHerbert Xu 		.alg = "ecb(des3_ede)",
33701aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3371a1915d51SJarod Wilson 		.fips_allowed = 1,
3372da7f033dSHerbert Xu 		.suite = {
337392a4c9feSEric Biggers 			.cipher = __VECS(des3_ede_tv_template)
3374da7f033dSHerbert Xu 		}
3375da7f033dSHerbert Xu 	}, {
337666e5bd00SJussi Kivilinna 		.alg = "ecb(fcrypt)",
337766e5bd00SJussi Kivilinna 		.test = alg_test_skcipher,
337866e5bd00SJussi Kivilinna 		.suite = {
337966e5bd00SJussi Kivilinna 			.cipher = {
338092a4c9feSEric Biggers 				.vecs = fcrypt_pcbc_tv_template,
338166e5bd00SJussi Kivilinna 				.count = 1
338266e5bd00SJussi Kivilinna 			}
338366e5bd00SJussi Kivilinna 		}
338466e5bd00SJussi Kivilinna 	}, {
3385da7f033dSHerbert Xu 		.alg = "ecb(khazad)",
33861aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3387da7f033dSHerbert Xu 		.suite = {
338892a4c9feSEric Biggers 			.cipher = __VECS(khazad_tv_template)
3389da7f033dSHerbert Xu 		}
3390da7f033dSHerbert Xu 	}, {
339115f47ce5SGilad Ben-Yossef 		/* Same as ecb(aes) except the key is stored in
339215f47ce5SGilad Ben-Yossef 		 * hardware secure memory which we reference by index
339315f47ce5SGilad Ben-Yossef 		 */
339415f47ce5SGilad Ben-Yossef 		.alg = "ecb(paes)",
339515f47ce5SGilad Ben-Yossef 		.test = alg_test_null,
339615f47ce5SGilad Ben-Yossef 		.fips_allowed = 1,
339715f47ce5SGilad Ben-Yossef 	}, {
3398da7f033dSHerbert Xu 		.alg = "ecb(seed)",
33991aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3400da7f033dSHerbert Xu 		.suite = {
340192a4c9feSEric Biggers 			.cipher = __VECS(seed_tv_template)
3402da7f033dSHerbert Xu 		}
3403da7f033dSHerbert Xu 	}, {
3404da7f033dSHerbert Xu 		.alg = "ecb(serpent)",
34051aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3406da7f033dSHerbert Xu 		.suite = {
340792a4c9feSEric Biggers 			.cipher = __VECS(serpent_tv_template)
3408da7f033dSHerbert Xu 		}
3409da7f033dSHerbert Xu 	}, {
3410cd83a8a7SGilad Ben-Yossef 		.alg = "ecb(sm4)",
3411cd83a8a7SGilad Ben-Yossef 		.test = alg_test_skcipher,
3412cd83a8a7SGilad Ben-Yossef 		.suite = {
341392a4c9feSEric Biggers 			.cipher = __VECS(sm4_tv_template)
3414cd83a8a7SGilad Ben-Yossef 		}
3415cd83a8a7SGilad Ben-Yossef 	}, {
3416da7f033dSHerbert Xu 		.alg = "ecb(tea)",
34171aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3418da7f033dSHerbert Xu 		.suite = {
341992a4c9feSEric Biggers 			.cipher = __VECS(tea_tv_template)
3420da7f033dSHerbert Xu 		}
3421da7f033dSHerbert Xu 	}, {
3422da7f033dSHerbert Xu 		.alg = "ecb(tnepres)",
34231aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3424da7f033dSHerbert Xu 		.suite = {
342592a4c9feSEric Biggers 			.cipher = __VECS(tnepres_tv_template)
3426da7f033dSHerbert Xu 		}
3427da7f033dSHerbert Xu 	}, {
3428da7f033dSHerbert Xu 		.alg = "ecb(twofish)",
34291aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3430da7f033dSHerbert Xu 		.suite = {
343192a4c9feSEric Biggers 			.cipher = __VECS(tf_tv_template)
3432da7f033dSHerbert Xu 		}
3433da7f033dSHerbert Xu 	}, {
3434da7f033dSHerbert Xu 		.alg = "ecb(xeta)",
34351aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3436da7f033dSHerbert Xu 		.suite = {
343792a4c9feSEric Biggers 			.cipher = __VECS(xeta_tv_template)
3438da7f033dSHerbert Xu 		}
3439da7f033dSHerbert Xu 	}, {
3440da7f033dSHerbert Xu 		.alg = "ecb(xtea)",
34411aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3442da7f033dSHerbert Xu 		.suite = {
344392a4c9feSEric Biggers 			.cipher = __VECS(xtea_tv_template)
3444da7f033dSHerbert Xu 		}
3445da7f033dSHerbert Xu 	}, {
34463c4b2390SSalvatore Benedetto 		.alg = "ecdh",
34473c4b2390SSalvatore Benedetto 		.test = alg_test_kpp,
34483c4b2390SSalvatore Benedetto 		.fips_allowed = 1,
34493c4b2390SSalvatore Benedetto 		.suite = {
345021c8e720SArd Biesheuvel 			.kpp = __VECS(ecdh_tv_template)
34513c4b2390SSalvatore Benedetto 		}
34523c4b2390SSalvatore Benedetto 	}, {
3453da7f033dSHerbert Xu 		.alg = "gcm(aes)",
3454da7f033dSHerbert Xu 		.test = alg_test_aead,
3455a1915d51SJarod Wilson 		.fips_allowed = 1,
3456da7f033dSHerbert Xu 		.suite = {
3457a0d608eeSEric Biggers 			.aead = __VECS(aes_gcm_tv_template)
3458da7f033dSHerbert Xu 		}
3459da7f033dSHerbert Xu 	}, {
3460507069c9SYouquan, Song 		.alg = "ghash",
3461507069c9SYouquan, Song 		.test = alg_test_hash,
346218c0ebd2SJarod Wilson 		.fips_allowed = 1,
3463507069c9SYouquan, Song 		.suite = {
346421c8e720SArd Biesheuvel 			.hash = __VECS(ghash_tv_template)
3465507069c9SYouquan, Song 		}
3466507069c9SYouquan, Song 	}, {
3467da7f033dSHerbert Xu 		.alg = "hmac(md5)",
3468da7f033dSHerbert Xu 		.test = alg_test_hash,
3469da7f033dSHerbert Xu 		.suite = {
347021c8e720SArd Biesheuvel 			.hash = __VECS(hmac_md5_tv_template)
3471da7f033dSHerbert Xu 		}
3472da7f033dSHerbert Xu 	}, {
3473da7f033dSHerbert Xu 		.alg = "hmac(rmd128)",
3474da7f033dSHerbert Xu 		.test = alg_test_hash,
3475da7f033dSHerbert Xu 		.suite = {
347621c8e720SArd Biesheuvel 			.hash = __VECS(hmac_rmd128_tv_template)
3477da7f033dSHerbert Xu 		}
3478da7f033dSHerbert Xu 	}, {
3479da7f033dSHerbert Xu 		.alg = "hmac(rmd160)",
3480da7f033dSHerbert Xu 		.test = alg_test_hash,
3481da7f033dSHerbert Xu 		.suite = {
348221c8e720SArd Biesheuvel 			.hash = __VECS(hmac_rmd160_tv_template)
3483da7f033dSHerbert Xu 		}
3484da7f033dSHerbert Xu 	}, {
3485da7f033dSHerbert Xu 		.alg = "hmac(sha1)",
3486da7f033dSHerbert Xu 		.test = alg_test_hash,
3487a1915d51SJarod Wilson 		.fips_allowed = 1,
3488da7f033dSHerbert Xu 		.suite = {
348921c8e720SArd Biesheuvel 			.hash = __VECS(hmac_sha1_tv_template)
3490da7f033dSHerbert Xu 		}
3491da7f033dSHerbert Xu 	}, {
3492da7f033dSHerbert Xu 		.alg = "hmac(sha224)",
3493da7f033dSHerbert Xu 		.test = alg_test_hash,
3494a1915d51SJarod Wilson 		.fips_allowed = 1,
3495da7f033dSHerbert Xu 		.suite = {
349621c8e720SArd Biesheuvel 			.hash = __VECS(hmac_sha224_tv_template)
3497da7f033dSHerbert Xu 		}
3498da7f033dSHerbert Xu 	}, {
3499da7f033dSHerbert Xu 		.alg = "hmac(sha256)",
3500da7f033dSHerbert Xu 		.test = alg_test_hash,
3501a1915d51SJarod Wilson 		.fips_allowed = 1,
3502da7f033dSHerbert Xu 		.suite = {
350321c8e720SArd Biesheuvel 			.hash = __VECS(hmac_sha256_tv_template)
3504da7f033dSHerbert Xu 		}
3505da7f033dSHerbert Xu 	}, {
350698eca72fSraveendra padasalagi 		.alg = "hmac(sha3-224)",
350798eca72fSraveendra padasalagi 		.test = alg_test_hash,
350898eca72fSraveendra padasalagi 		.fips_allowed = 1,
350998eca72fSraveendra padasalagi 		.suite = {
351021c8e720SArd Biesheuvel 			.hash = __VECS(hmac_sha3_224_tv_template)
351198eca72fSraveendra padasalagi 		}
351298eca72fSraveendra padasalagi 	}, {
351398eca72fSraveendra padasalagi 		.alg = "hmac(sha3-256)",
351498eca72fSraveendra padasalagi 		.test = alg_test_hash,
351598eca72fSraveendra padasalagi 		.fips_allowed = 1,
351698eca72fSraveendra padasalagi 		.suite = {
351721c8e720SArd Biesheuvel 			.hash = __VECS(hmac_sha3_256_tv_template)
351898eca72fSraveendra padasalagi 		}
351998eca72fSraveendra padasalagi 	}, {
352098eca72fSraveendra padasalagi 		.alg = "hmac(sha3-384)",
352198eca72fSraveendra padasalagi 		.test = alg_test_hash,
352298eca72fSraveendra padasalagi 		.fips_allowed = 1,
352398eca72fSraveendra padasalagi 		.suite = {
352421c8e720SArd Biesheuvel 			.hash = __VECS(hmac_sha3_384_tv_template)
352598eca72fSraveendra padasalagi 		}
352698eca72fSraveendra padasalagi 	}, {
352798eca72fSraveendra padasalagi 		.alg = "hmac(sha3-512)",
352898eca72fSraveendra padasalagi 		.test = alg_test_hash,
352998eca72fSraveendra padasalagi 		.fips_allowed = 1,
353098eca72fSraveendra padasalagi 		.suite = {
353121c8e720SArd Biesheuvel 			.hash = __VECS(hmac_sha3_512_tv_template)
353298eca72fSraveendra padasalagi 		}
353398eca72fSraveendra padasalagi 	}, {
3534da7f033dSHerbert Xu 		.alg = "hmac(sha384)",
3535da7f033dSHerbert Xu 		.test = alg_test_hash,
3536a1915d51SJarod Wilson 		.fips_allowed = 1,
3537da7f033dSHerbert Xu 		.suite = {
353821c8e720SArd Biesheuvel 			.hash = __VECS(hmac_sha384_tv_template)
3539da7f033dSHerbert Xu 		}
3540da7f033dSHerbert Xu 	}, {
3541da7f033dSHerbert Xu 		.alg = "hmac(sha512)",
3542da7f033dSHerbert Xu 		.test = alg_test_hash,
3543a1915d51SJarod Wilson 		.fips_allowed = 1,
3544da7f033dSHerbert Xu 		.suite = {
354521c8e720SArd Biesheuvel 			.hash = __VECS(hmac_sha512_tv_template)
3546da7f033dSHerbert Xu 		}
3547da7f033dSHerbert Xu 	}, {
354825a0b9d4SVitaly Chikunov 		.alg = "hmac(streebog256)",
354925a0b9d4SVitaly Chikunov 		.test = alg_test_hash,
355025a0b9d4SVitaly Chikunov 		.suite = {
355125a0b9d4SVitaly Chikunov 			.hash = __VECS(hmac_streebog256_tv_template)
355225a0b9d4SVitaly Chikunov 		}
355325a0b9d4SVitaly Chikunov 	}, {
355425a0b9d4SVitaly Chikunov 		.alg = "hmac(streebog512)",
355525a0b9d4SVitaly Chikunov 		.test = alg_test_hash,
355625a0b9d4SVitaly Chikunov 		.suite = {
355725a0b9d4SVitaly Chikunov 			.hash = __VECS(hmac_streebog512_tv_template)
355825a0b9d4SVitaly Chikunov 		}
355925a0b9d4SVitaly Chikunov 	}, {
3560bb5530e4SStephan Mueller 		.alg = "jitterentropy_rng",
3561bb5530e4SStephan Mueller 		.fips_allowed = 1,
3562bb5530e4SStephan Mueller 		.test = alg_test_null,
3563bb5530e4SStephan Mueller 	}, {
356435351988SStephan Mueller 		.alg = "kw(aes)",
356535351988SStephan Mueller 		.test = alg_test_skcipher,
356635351988SStephan Mueller 		.fips_allowed = 1,
356735351988SStephan Mueller 		.suite = {
356892a4c9feSEric Biggers 			.cipher = __VECS(aes_kw_tv_template)
356935351988SStephan Mueller 		}
357035351988SStephan Mueller 	}, {
3571da7f033dSHerbert Xu 		.alg = "lrw(aes)",
35721aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3573da7f033dSHerbert Xu 		.suite = {
357492a4c9feSEric Biggers 			.cipher = __VECS(aes_lrw_tv_template)
3575da7f033dSHerbert Xu 		}
3576da7f033dSHerbert Xu 	}, {
35770840605eSJussi Kivilinna 		.alg = "lrw(camellia)",
35780840605eSJussi Kivilinna 		.test = alg_test_skcipher,
35790840605eSJussi Kivilinna 		.suite = {
358092a4c9feSEric Biggers 			.cipher = __VECS(camellia_lrw_tv_template)
35810840605eSJussi Kivilinna 		}
35820840605eSJussi Kivilinna 	}, {
35839b8b0405SJohannes Goetzfried 		.alg = "lrw(cast6)",
35849b8b0405SJohannes Goetzfried 		.test = alg_test_skcipher,
35859b8b0405SJohannes Goetzfried 		.suite = {
358692a4c9feSEric Biggers 			.cipher = __VECS(cast6_lrw_tv_template)
35879b8b0405SJohannes Goetzfried 		}
35889b8b0405SJohannes Goetzfried 	}, {
3589d7bfc0faSJussi Kivilinna 		.alg = "lrw(serpent)",
3590d7bfc0faSJussi Kivilinna 		.test = alg_test_skcipher,
3591d7bfc0faSJussi Kivilinna 		.suite = {
359292a4c9feSEric Biggers 			.cipher = __VECS(serpent_lrw_tv_template)
3593d7bfc0faSJussi Kivilinna 		}
3594d7bfc0faSJussi Kivilinna 	}, {
35950b2a1551SJussi Kivilinna 		.alg = "lrw(twofish)",
35960b2a1551SJussi Kivilinna 		.test = alg_test_skcipher,
35970b2a1551SJussi Kivilinna 		.suite = {
359892a4c9feSEric Biggers 			.cipher = __VECS(tf_lrw_tv_template)
35990b2a1551SJussi Kivilinna 		}
36000b2a1551SJussi Kivilinna 	}, {
36011443cc9bSKOVACS Krisztian 		.alg = "lz4",
36021443cc9bSKOVACS Krisztian 		.test = alg_test_comp,
36031443cc9bSKOVACS Krisztian 		.fips_allowed = 1,
36041443cc9bSKOVACS Krisztian 		.suite = {
36051443cc9bSKOVACS Krisztian 			.comp = {
360621c8e720SArd Biesheuvel 				.comp = __VECS(lz4_comp_tv_template),
360721c8e720SArd Biesheuvel 				.decomp = __VECS(lz4_decomp_tv_template)
36081443cc9bSKOVACS Krisztian 			}
36091443cc9bSKOVACS Krisztian 		}
36101443cc9bSKOVACS Krisztian 	}, {
36111443cc9bSKOVACS Krisztian 		.alg = "lz4hc",
36121443cc9bSKOVACS Krisztian 		.test = alg_test_comp,
36131443cc9bSKOVACS Krisztian 		.fips_allowed = 1,
36141443cc9bSKOVACS Krisztian 		.suite = {
36151443cc9bSKOVACS Krisztian 			.comp = {
361621c8e720SArd Biesheuvel 				.comp = __VECS(lz4hc_comp_tv_template),
361721c8e720SArd Biesheuvel 				.decomp = __VECS(lz4hc_decomp_tv_template)
36181443cc9bSKOVACS Krisztian 			}
36191443cc9bSKOVACS Krisztian 		}
36201443cc9bSKOVACS Krisztian 	}, {
3621da7f033dSHerbert Xu 		.alg = "lzo",
3622da7f033dSHerbert Xu 		.test = alg_test_comp,
36230818904dSMilan Broz 		.fips_allowed = 1,
3624da7f033dSHerbert Xu 		.suite = {
3625da7f033dSHerbert Xu 			.comp = {
362621c8e720SArd Biesheuvel 				.comp = __VECS(lzo_comp_tv_template),
362721c8e720SArd Biesheuvel 				.decomp = __VECS(lzo_decomp_tv_template)
3628da7f033dSHerbert Xu 			}
3629da7f033dSHerbert Xu 		}
3630da7f033dSHerbert Xu 	}, {
3631da7f033dSHerbert Xu 		.alg = "md4",
3632da7f033dSHerbert Xu 		.test = alg_test_hash,
3633da7f033dSHerbert Xu 		.suite = {
363421c8e720SArd Biesheuvel 			.hash = __VECS(md4_tv_template)
3635da7f033dSHerbert Xu 		}
3636da7f033dSHerbert Xu 	}, {
3637da7f033dSHerbert Xu 		.alg = "md5",
3638da7f033dSHerbert Xu 		.test = alg_test_hash,
3639da7f033dSHerbert Xu 		.suite = {
364021c8e720SArd Biesheuvel 			.hash = __VECS(md5_tv_template)
3641da7f033dSHerbert Xu 		}
3642da7f033dSHerbert Xu 	}, {
3643da7f033dSHerbert Xu 		.alg = "michael_mic",
3644da7f033dSHerbert Xu 		.test = alg_test_hash,
3645da7f033dSHerbert Xu 		.suite = {
364621c8e720SArd Biesheuvel 			.hash = __VECS(michael_mic_tv_template)
3647da7f033dSHerbert Xu 		}
3648da7f033dSHerbert Xu 	}, {
36494feb4c59SOndrej Mosnacek 		.alg = "morus1280",
36504feb4c59SOndrej Mosnacek 		.test = alg_test_aead,
36514feb4c59SOndrej Mosnacek 		.suite = {
3652a0d608eeSEric Biggers 			.aead = __VECS(morus1280_tv_template)
36534feb4c59SOndrej Mosnacek 		}
36544feb4c59SOndrej Mosnacek 	}, {
36554feb4c59SOndrej Mosnacek 		.alg = "morus640",
36564feb4c59SOndrej Mosnacek 		.test = alg_test_aead,
36574feb4c59SOndrej Mosnacek 		.suite = {
3658a0d608eeSEric Biggers 			.aead = __VECS(morus640_tv_template)
36594feb4c59SOndrej Mosnacek 		}
36604feb4c59SOndrej Mosnacek 	}, {
366126609a21SEric Biggers 		.alg = "nhpoly1305",
366226609a21SEric Biggers 		.test = alg_test_hash,
366326609a21SEric Biggers 		.suite = {
366426609a21SEric Biggers 			.hash = __VECS(nhpoly1305_tv_template)
366526609a21SEric Biggers 		}
366626609a21SEric Biggers 	}, {
3667ba0e14acSPuneet Saxena 		.alg = "ofb(aes)",
3668ba0e14acSPuneet Saxena 		.test = alg_test_skcipher,
3669ba0e14acSPuneet Saxena 		.fips_allowed = 1,
3670ba0e14acSPuneet Saxena 		.suite = {
367192a4c9feSEric Biggers 			.cipher = __VECS(aes_ofb_tv_template)
3672ba0e14acSPuneet Saxena 		}
3673ba0e14acSPuneet Saxena 	}, {
3674a794d8d8SGilad Ben-Yossef 		/* Same as ofb(aes) except the key is stored in
3675a794d8d8SGilad Ben-Yossef 		 * hardware secure memory which we reference by index
3676a794d8d8SGilad Ben-Yossef 		 */
3677a794d8d8SGilad Ben-Yossef 		.alg = "ofb(paes)",
3678a794d8d8SGilad Ben-Yossef 		.test = alg_test_null,
3679a794d8d8SGilad Ben-Yossef 		.fips_allowed = 1,
3680a794d8d8SGilad Ben-Yossef 	}, {
3681da7f033dSHerbert Xu 		.alg = "pcbc(fcrypt)",
36821aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3683da7f033dSHerbert Xu 		.suite = {
368492a4c9feSEric Biggers 			.cipher = __VECS(fcrypt_pcbc_tv_template)
3685da7f033dSHerbert Xu 		}
3686da7f033dSHerbert Xu 	}, {
36871207107cSStephan Mueller 		.alg = "pkcs1pad(rsa,sha224)",
36881207107cSStephan Mueller 		.test = alg_test_null,
36891207107cSStephan Mueller 		.fips_allowed = 1,
36901207107cSStephan Mueller 	}, {
36911207107cSStephan Mueller 		.alg = "pkcs1pad(rsa,sha256)",
36921207107cSStephan Mueller 		.test = alg_test_akcipher,
36931207107cSStephan Mueller 		.fips_allowed = 1,
36941207107cSStephan Mueller 		.suite = {
36951207107cSStephan Mueller 			.akcipher = __VECS(pkcs1pad_rsa_tv_template)
36961207107cSStephan Mueller 		}
36971207107cSStephan Mueller 	}, {
36981207107cSStephan Mueller 		.alg = "pkcs1pad(rsa,sha384)",
36991207107cSStephan Mueller 		.test = alg_test_null,
37001207107cSStephan Mueller 		.fips_allowed = 1,
37011207107cSStephan Mueller 	}, {
37021207107cSStephan Mueller 		.alg = "pkcs1pad(rsa,sha512)",
37031207107cSStephan Mueller 		.test = alg_test_null,
37041207107cSStephan Mueller 		.fips_allowed = 1,
37051207107cSStephan Mueller 	}, {
3706eee9dc61SMartin Willi 		.alg = "poly1305",
3707eee9dc61SMartin Willi 		.test = alg_test_hash,
3708eee9dc61SMartin Willi 		.suite = {
370921c8e720SArd Biesheuvel 			.hash = __VECS(poly1305_tv_template)
3710eee9dc61SMartin Willi 		}
3711eee9dc61SMartin Willi 	}, {
3712da7f033dSHerbert Xu 		.alg = "rfc3686(ctr(aes))",
37131aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3714a1915d51SJarod Wilson 		.fips_allowed = 1,
3715da7f033dSHerbert Xu 		.suite = {
371692a4c9feSEric Biggers 			.cipher = __VECS(aes_ctr_rfc3686_tv_template)
3717da7f033dSHerbert Xu 		}
3718da7f033dSHerbert Xu 	}, {
37193f31a740SHerbert Xu 		.alg = "rfc4106(gcm(aes))",
372069435b94SAdrian Hoban 		.test = alg_test_aead,
3721db71f29aSJarod Wilson 		.fips_allowed = 1,
372269435b94SAdrian Hoban 		.suite = {
3723a0d608eeSEric Biggers 			.aead = __VECS(aes_gcm_rfc4106_tv_template)
372469435b94SAdrian Hoban 		}
372569435b94SAdrian Hoban 	}, {
3726544c436aSHerbert Xu 		.alg = "rfc4309(ccm(aes))",
37275d667322SJarod Wilson 		.test = alg_test_aead,
3728a1915d51SJarod Wilson 		.fips_allowed = 1,
37295d667322SJarod Wilson 		.suite = {
3730a0d608eeSEric Biggers 			.aead = __VECS(aes_ccm_rfc4309_tv_template)
37315d667322SJarod Wilson 		}
37325d667322SJarod Wilson 	}, {
3733bb68745eSHerbert Xu 		.alg = "rfc4543(gcm(aes))",
3734e9b7441aSJussi Kivilinna 		.test = alg_test_aead,
3735e9b7441aSJussi Kivilinna 		.suite = {
3736a0d608eeSEric Biggers 			.aead = __VECS(aes_gcm_rfc4543_tv_template)
3737e9b7441aSJussi Kivilinna 		}
3738e9b7441aSJussi Kivilinna 	}, {
3739af2b76b5SMartin Willi 		.alg = "rfc7539(chacha20,poly1305)",
3740af2b76b5SMartin Willi 		.test = alg_test_aead,
3741af2b76b5SMartin Willi 		.suite = {
3742a0d608eeSEric Biggers 			.aead = __VECS(rfc7539_tv_template)
3743af2b76b5SMartin Willi 		}
3744af2b76b5SMartin Willi 	}, {
37455900758dSMartin Willi 		.alg = "rfc7539esp(chacha20,poly1305)",
37465900758dSMartin Willi 		.test = alg_test_aead,
37475900758dSMartin Willi 		.suite = {
3748a0d608eeSEric Biggers 			.aead = __VECS(rfc7539esp_tv_template)
37495900758dSMartin Willi 		}
37505900758dSMartin Willi 	}, {
3751da7f033dSHerbert Xu 		.alg = "rmd128",
3752da7f033dSHerbert Xu 		.test = alg_test_hash,
3753da7f033dSHerbert Xu 		.suite = {
375421c8e720SArd Biesheuvel 			.hash = __VECS(rmd128_tv_template)
3755da7f033dSHerbert Xu 		}
3756da7f033dSHerbert Xu 	}, {
3757da7f033dSHerbert Xu 		.alg = "rmd160",
3758da7f033dSHerbert Xu 		.test = alg_test_hash,
3759da7f033dSHerbert Xu 		.suite = {
376021c8e720SArd Biesheuvel 			.hash = __VECS(rmd160_tv_template)
3761da7f033dSHerbert Xu 		}
3762da7f033dSHerbert Xu 	}, {
3763da7f033dSHerbert Xu 		.alg = "rmd256",
3764da7f033dSHerbert Xu 		.test = alg_test_hash,
3765da7f033dSHerbert Xu 		.suite = {
376621c8e720SArd Biesheuvel 			.hash = __VECS(rmd256_tv_template)
3767da7f033dSHerbert Xu 		}
3768da7f033dSHerbert Xu 	}, {
3769da7f033dSHerbert Xu 		.alg = "rmd320",
3770da7f033dSHerbert Xu 		.test = alg_test_hash,
3771da7f033dSHerbert Xu 		.suite = {
377221c8e720SArd Biesheuvel 			.hash = __VECS(rmd320_tv_template)
3773da7f033dSHerbert Xu 		}
3774da7f033dSHerbert Xu 	}, {
3775946cc463STadeusz Struk 		.alg = "rsa",
3776946cc463STadeusz Struk 		.test = alg_test_akcipher,
3777946cc463STadeusz Struk 		.fips_allowed = 1,
3778946cc463STadeusz Struk 		.suite = {
377921c8e720SArd Biesheuvel 			.akcipher = __VECS(rsa_tv_template)
3780946cc463STadeusz Struk 		}
3781946cc463STadeusz Struk 	}, {
3782da7f033dSHerbert Xu 		.alg = "salsa20",
37831aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
3784da7f033dSHerbert Xu 		.suite = {
378592a4c9feSEric Biggers 			.cipher = __VECS(salsa20_stream_tv_template)
3786da7f033dSHerbert Xu 		}
3787da7f033dSHerbert Xu 	}, {
3788da7f033dSHerbert Xu 		.alg = "sha1",
3789da7f033dSHerbert Xu 		.test = alg_test_hash,
3790a1915d51SJarod Wilson 		.fips_allowed = 1,
3791da7f033dSHerbert Xu 		.suite = {
379221c8e720SArd Biesheuvel 			.hash = __VECS(sha1_tv_template)
3793da7f033dSHerbert Xu 		}
3794da7f033dSHerbert Xu 	}, {
3795da7f033dSHerbert Xu 		.alg = "sha224",
3796da7f033dSHerbert Xu 		.test = alg_test_hash,
3797a1915d51SJarod Wilson 		.fips_allowed = 1,
3798da7f033dSHerbert Xu 		.suite = {
379921c8e720SArd Biesheuvel 			.hash = __VECS(sha224_tv_template)
3800da7f033dSHerbert Xu 		}
3801da7f033dSHerbert Xu 	}, {
3802da7f033dSHerbert Xu 		.alg = "sha256",
3803da7f033dSHerbert Xu 		.test = alg_test_hash,
3804a1915d51SJarod Wilson 		.fips_allowed = 1,
3805da7f033dSHerbert Xu 		.suite = {
380621c8e720SArd Biesheuvel 			.hash = __VECS(sha256_tv_template)
3807da7f033dSHerbert Xu 		}
3808da7f033dSHerbert Xu 	}, {
380979cc6ab8Sraveendra padasalagi 		.alg = "sha3-224",
381079cc6ab8Sraveendra padasalagi 		.test = alg_test_hash,
381179cc6ab8Sraveendra padasalagi 		.fips_allowed = 1,
381279cc6ab8Sraveendra padasalagi 		.suite = {
381321c8e720SArd Biesheuvel 			.hash = __VECS(sha3_224_tv_template)
381479cc6ab8Sraveendra padasalagi 		}
381579cc6ab8Sraveendra padasalagi 	}, {
381679cc6ab8Sraveendra padasalagi 		.alg = "sha3-256",
381779cc6ab8Sraveendra padasalagi 		.test = alg_test_hash,
381879cc6ab8Sraveendra padasalagi 		.fips_allowed = 1,
381979cc6ab8Sraveendra padasalagi 		.suite = {
382021c8e720SArd Biesheuvel 			.hash = __VECS(sha3_256_tv_template)
382179cc6ab8Sraveendra padasalagi 		}
382279cc6ab8Sraveendra padasalagi 	}, {
382379cc6ab8Sraveendra padasalagi 		.alg = "sha3-384",
382479cc6ab8Sraveendra padasalagi 		.test = alg_test_hash,
382579cc6ab8Sraveendra padasalagi 		.fips_allowed = 1,
382679cc6ab8Sraveendra padasalagi 		.suite = {
382721c8e720SArd Biesheuvel 			.hash = __VECS(sha3_384_tv_template)
382879cc6ab8Sraveendra padasalagi 		}
382979cc6ab8Sraveendra padasalagi 	}, {
383079cc6ab8Sraveendra padasalagi 		.alg = "sha3-512",
383179cc6ab8Sraveendra padasalagi 		.test = alg_test_hash,
383279cc6ab8Sraveendra padasalagi 		.fips_allowed = 1,
383379cc6ab8Sraveendra padasalagi 		.suite = {
383421c8e720SArd Biesheuvel 			.hash = __VECS(sha3_512_tv_template)
383579cc6ab8Sraveendra padasalagi 		}
383679cc6ab8Sraveendra padasalagi 	}, {
3837da7f033dSHerbert Xu 		.alg = "sha384",
3838da7f033dSHerbert Xu 		.test = alg_test_hash,
3839a1915d51SJarod Wilson 		.fips_allowed = 1,
3840da7f033dSHerbert Xu 		.suite = {
384121c8e720SArd Biesheuvel 			.hash = __VECS(sha384_tv_template)
3842da7f033dSHerbert Xu 		}
3843da7f033dSHerbert Xu 	}, {
3844da7f033dSHerbert Xu 		.alg = "sha512",
3845da7f033dSHerbert Xu 		.test = alg_test_hash,
3846a1915d51SJarod Wilson 		.fips_allowed = 1,
3847da7f033dSHerbert Xu 		.suite = {
384821c8e720SArd Biesheuvel 			.hash = __VECS(sha512_tv_template)
3849da7f033dSHerbert Xu 		}
3850da7f033dSHerbert Xu 	}, {
3851b7e27530SGilad Ben-Yossef 		.alg = "sm3",
3852b7e27530SGilad Ben-Yossef 		.test = alg_test_hash,
3853b7e27530SGilad Ben-Yossef 		.suite = {
3854b7e27530SGilad Ben-Yossef 			.hash = __VECS(sm3_tv_template)
3855b7e27530SGilad Ben-Yossef 		}
3856b7e27530SGilad Ben-Yossef 	}, {
385725a0b9d4SVitaly Chikunov 		.alg = "streebog256",
385825a0b9d4SVitaly Chikunov 		.test = alg_test_hash,
385925a0b9d4SVitaly Chikunov 		.suite = {
386025a0b9d4SVitaly Chikunov 			.hash = __VECS(streebog256_tv_template)
386125a0b9d4SVitaly Chikunov 		}
386225a0b9d4SVitaly Chikunov 	}, {
386325a0b9d4SVitaly Chikunov 		.alg = "streebog512",
386425a0b9d4SVitaly Chikunov 		.test = alg_test_hash,
386525a0b9d4SVitaly Chikunov 		.suite = {
386625a0b9d4SVitaly Chikunov 			.hash = __VECS(streebog512_tv_template)
386725a0b9d4SVitaly Chikunov 		}
386825a0b9d4SVitaly Chikunov 	}, {
3869da7f033dSHerbert Xu 		.alg = "tgr128",
3870da7f033dSHerbert Xu 		.test = alg_test_hash,
3871da7f033dSHerbert Xu 		.suite = {
387221c8e720SArd Biesheuvel 			.hash = __VECS(tgr128_tv_template)
3873da7f033dSHerbert Xu 		}
3874da7f033dSHerbert Xu 	}, {
3875da7f033dSHerbert Xu 		.alg = "tgr160",
3876da7f033dSHerbert Xu 		.test = alg_test_hash,
3877da7f033dSHerbert Xu 		.suite = {
387821c8e720SArd Biesheuvel 			.hash = __VECS(tgr160_tv_template)
3879da7f033dSHerbert Xu 		}
3880da7f033dSHerbert Xu 	}, {
3881da7f033dSHerbert Xu 		.alg = "tgr192",
3882da7f033dSHerbert Xu 		.test = alg_test_hash,
3883da7f033dSHerbert Xu 		.suite = {
388421c8e720SArd Biesheuvel 			.hash = __VECS(tgr192_tv_template)
3885da7f033dSHerbert Xu 		}
3886da7f033dSHerbert Xu 	}, {
3887ed331adaSEric Biggers 		.alg = "vmac64(aes)",
3888ed331adaSEric Biggers 		.test = alg_test_hash,
3889ed331adaSEric Biggers 		.suite = {
3890ed331adaSEric Biggers 			.hash = __VECS(vmac64_aes_tv_template)
3891ed331adaSEric Biggers 		}
3892ed331adaSEric Biggers 	}, {
3893da7f033dSHerbert Xu 		.alg = "wp256",
3894da7f033dSHerbert Xu 		.test = alg_test_hash,
3895da7f033dSHerbert Xu 		.suite = {
389621c8e720SArd Biesheuvel 			.hash = __VECS(wp256_tv_template)
3897da7f033dSHerbert Xu 		}
3898da7f033dSHerbert Xu 	}, {
3899da7f033dSHerbert Xu 		.alg = "wp384",
3900da7f033dSHerbert Xu 		.test = alg_test_hash,
3901da7f033dSHerbert Xu 		.suite = {
390221c8e720SArd Biesheuvel 			.hash = __VECS(wp384_tv_template)
3903da7f033dSHerbert Xu 		}
3904da7f033dSHerbert Xu 	}, {
3905da7f033dSHerbert Xu 		.alg = "wp512",
3906da7f033dSHerbert Xu 		.test = alg_test_hash,
3907da7f033dSHerbert Xu 		.suite = {
390821c8e720SArd Biesheuvel 			.hash = __VECS(wp512_tv_template)
3909da7f033dSHerbert Xu 		}
3910da7f033dSHerbert Xu 	}, {
3911da7f033dSHerbert Xu 		.alg = "xcbc(aes)",
3912da7f033dSHerbert Xu 		.test = alg_test_hash,
3913da7f033dSHerbert Xu 		.suite = {
391421c8e720SArd Biesheuvel 			.hash = __VECS(aes_xcbc128_tv_template)
3915da7f033dSHerbert Xu 		}
3916da7f033dSHerbert Xu 	}, {
3917aa762409SEric Biggers 		.alg = "xchacha12",
3918aa762409SEric Biggers 		.test = alg_test_skcipher,
3919aa762409SEric Biggers 		.suite = {
3920aa762409SEric Biggers 			.cipher = __VECS(xchacha12_tv_template)
3921aa762409SEric Biggers 		},
3922aa762409SEric Biggers 	}, {
3923de61d7aeSEric Biggers 		.alg = "xchacha20",
3924de61d7aeSEric Biggers 		.test = alg_test_skcipher,
3925de61d7aeSEric Biggers 		.suite = {
3926de61d7aeSEric Biggers 			.cipher = __VECS(xchacha20_tv_template)
3927de61d7aeSEric Biggers 		},
3928de61d7aeSEric Biggers 	}, {
3929da7f033dSHerbert Xu 		.alg = "xts(aes)",
39301aa4ecd9SHerbert Xu 		.test = alg_test_skcipher,
39312918aa8dSJarod Wilson 		.fips_allowed = 1,
3932da7f033dSHerbert Xu 		.suite = {
393392a4c9feSEric Biggers 			.cipher = __VECS(aes_xts_tv_template)
3934da7f033dSHerbert Xu 		}
39350c01aed5SGeert Uytterhoeven 	}, {
39360840605eSJussi Kivilinna 		.alg = "xts(camellia)",
39370840605eSJussi Kivilinna 		.test = alg_test_skcipher,
39380840605eSJussi Kivilinna 		.suite = {
393992a4c9feSEric Biggers 			.cipher = __VECS(camellia_xts_tv_template)
39400840605eSJussi Kivilinna 		}
39410840605eSJussi Kivilinna 	}, {
39429b8b0405SJohannes Goetzfried 		.alg = "xts(cast6)",
39439b8b0405SJohannes Goetzfried 		.test = alg_test_skcipher,
39449b8b0405SJohannes Goetzfried 		.suite = {
394592a4c9feSEric Biggers 			.cipher = __VECS(cast6_xts_tv_template)
39469b8b0405SJohannes Goetzfried 		}
39479b8b0405SJohannes Goetzfried 	}, {
394815f47ce5SGilad Ben-Yossef 		/* Same as xts(aes) except the key is stored in
394915f47ce5SGilad Ben-Yossef 		 * hardware secure memory which we reference by index
395015f47ce5SGilad Ben-Yossef 		 */
395115f47ce5SGilad Ben-Yossef 		.alg = "xts(paes)",
395215f47ce5SGilad Ben-Yossef 		.test = alg_test_null,
395315f47ce5SGilad Ben-Yossef 		.fips_allowed = 1,
395415f47ce5SGilad Ben-Yossef 	}, {
395518be20b9SJussi Kivilinna 		.alg = "xts(serpent)",
395618be20b9SJussi Kivilinna 		.test = alg_test_skcipher,
395718be20b9SJussi Kivilinna 		.suite = {
395892a4c9feSEric Biggers 			.cipher = __VECS(serpent_xts_tv_template)
395918be20b9SJussi Kivilinna 		}
396018be20b9SJussi Kivilinna 	}, {
3961aed265b9SJussi Kivilinna 		.alg = "xts(twofish)",
3962aed265b9SJussi Kivilinna 		.test = alg_test_skcipher,
3963aed265b9SJussi Kivilinna 		.suite = {
396492a4c9feSEric Biggers 			.cipher = __VECS(tf_xts_tv_template)
3965aed265b9SJussi Kivilinna 		}
3966a368f43dSGiovanni Cabiddu 	}, {
396715f47ce5SGilad Ben-Yossef 		.alg = "xts4096(paes)",
396815f47ce5SGilad Ben-Yossef 		.test = alg_test_null,
396915f47ce5SGilad Ben-Yossef 		.fips_allowed = 1,
397015f47ce5SGilad Ben-Yossef 	}, {
397115f47ce5SGilad Ben-Yossef 		.alg = "xts512(paes)",
397215f47ce5SGilad Ben-Yossef 		.test = alg_test_null,
397315f47ce5SGilad Ben-Yossef 		.fips_allowed = 1,
397415f47ce5SGilad Ben-Yossef 	}, {
3975a368f43dSGiovanni Cabiddu 		.alg = "zlib-deflate",
3976a368f43dSGiovanni Cabiddu 		.test = alg_test_comp,
3977a368f43dSGiovanni Cabiddu 		.fips_allowed = 1,
3978a368f43dSGiovanni Cabiddu 		.suite = {
3979a368f43dSGiovanni Cabiddu 			.comp = {
3980a368f43dSGiovanni Cabiddu 				.comp = __VECS(zlib_deflate_comp_tv_template),
3981a368f43dSGiovanni Cabiddu 				.decomp = __VECS(zlib_deflate_decomp_tv_template)
3982a368f43dSGiovanni Cabiddu 			}
3983a368f43dSGiovanni Cabiddu 		}
3984d28fc3dbSNick Terrell 	}, {
3985d28fc3dbSNick Terrell 		.alg = "zstd",
3986d28fc3dbSNick Terrell 		.test = alg_test_comp,
3987d28fc3dbSNick Terrell 		.fips_allowed = 1,
3988d28fc3dbSNick Terrell 		.suite = {
3989d28fc3dbSNick Terrell 			.comp = {
3990d28fc3dbSNick Terrell 				.comp = __VECS(zstd_comp_tv_template),
3991d28fc3dbSNick Terrell 				.decomp = __VECS(zstd_decomp_tv_template)
3992d28fc3dbSNick Terrell 			}
3993d28fc3dbSNick Terrell 		}
3994da7f033dSHerbert Xu 	}
3995da7f033dSHerbert Xu };
3996da7f033dSHerbert Xu 
39973f47a03dSEric Biggers static void alg_check_test_descs_order(void)
39985714758bSJussi Kivilinna {
39995714758bSJussi Kivilinna 	int i;
40005714758bSJussi Kivilinna 
40015714758bSJussi Kivilinna 	for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
40025714758bSJussi Kivilinna 		int diff = strcmp(alg_test_descs[i - 1].alg,
40035714758bSJussi Kivilinna 				  alg_test_descs[i].alg);
40045714758bSJussi Kivilinna 
40055714758bSJussi Kivilinna 		if (WARN_ON(diff > 0)) {
40065714758bSJussi Kivilinna 			pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
40075714758bSJussi Kivilinna 				alg_test_descs[i - 1].alg,
40085714758bSJussi Kivilinna 				alg_test_descs[i].alg);
40095714758bSJussi Kivilinna 		}
40105714758bSJussi Kivilinna 
40115714758bSJussi Kivilinna 		if (WARN_ON(diff == 0)) {
40125714758bSJussi Kivilinna 			pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
40135714758bSJussi Kivilinna 				alg_test_descs[i].alg);
40145714758bSJussi Kivilinna 		}
40155714758bSJussi Kivilinna 	}
40165714758bSJussi Kivilinna }
40175714758bSJussi Kivilinna 
40183f47a03dSEric Biggers static void alg_check_testvec_configs(void)
40193f47a03dSEric Biggers {
40204e7babbaSEric Biggers 	int i;
40214e7babbaSEric Biggers 
40224e7babbaSEric Biggers 	for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++)
40234e7babbaSEric Biggers 		WARN_ON(!valid_testvec_config(
40244e7babbaSEric Biggers 				&default_cipher_testvec_configs[i]));
40254cc2dcf9SEric Biggers 
40264cc2dcf9SEric Biggers 	for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++)
40274cc2dcf9SEric Biggers 		WARN_ON(!valid_testvec_config(
40284cc2dcf9SEric Biggers 				&default_hash_testvec_configs[i]));
40293f47a03dSEric Biggers }
40303f47a03dSEric Biggers 
40313f47a03dSEric Biggers static void testmgr_onetime_init(void)
40323f47a03dSEric Biggers {
40333f47a03dSEric Biggers 	alg_check_test_descs_order();
40343f47a03dSEric Biggers 	alg_check_testvec_configs();
40355b2706a4SEric Biggers 
40365b2706a4SEric Biggers #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
40375b2706a4SEric Biggers 	pr_warn("alg: extra crypto tests enabled.  This is intended for developer use only.\n");
40385b2706a4SEric Biggers #endif
40393f47a03dSEric Biggers }
40403f47a03dSEric Biggers 
40411aa4ecd9SHerbert Xu static int alg_find_test(const char *alg)
4042da7f033dSHerbert Xu {
4043da7f033dSHerbert Xu 	int start = 0;
4044da7f033dSHerbert Xu 	int end = ARRAY_SIZE(alg_test_descs);
4045da7f033dSHerbert Xu 
4046da7f033dSHerbert Xu 	while (start < end) {
4047da7f033dSHerbert Xu 		int i = (start + end) / 2;
4048da7f033dSHerbert Xu 		int diff = strcmp(alg_test_descs[i].alg, alg);
4049da7f033dSHerbert Xu 
4050da7f033dSHerbert Xu 		if (diff > 0) {
4051da7f033dSHerbert Xu 			end = i;
4052da7f033dSHerbert Xu 			continue;
4053da7f033dSHerbert Xu 		}
4054da7f033dSHerbert Xu 
4055da7f033dSHerbert Xu 		if (diff < 0) {
4056da7f033dSHerbert Xu 			start = i + 1;
4057da7f033dSHerbert Xu 			continue;
4058da7f033dSHerbert Xu 		}
4059da7f033dSHerbert Xu 
40601aa4ecd9SHerbert Xu 		return i;
4061da7f033dSHerbert Xu 	}
4062da7f033dSHerbert Xu 
40631aa4ecd9SHerbert Xu 	return -1;
40641aa4ecd9SHerbert Xu }
40651aa4ecd9SHerbert Xu 
40661aa4ecd9SHerbert Xu int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
40671aa4ecd9SHerbert Xu {
40681aa4ecd9SHerbert Xu 	int i;
4069a68f6610SHerbert Xu 	int j;
4070d12d6b6dSNeil Horman 	int rc;
40711aa4ecd9SHerbert Xu 
40729e5c9fe4SRichard W.M. Jones 	if (!fips_enabled && notests) {
40739e5c9fe4SRichard W.M. Jones 		printk_once(KERN_INFO "alg: self-tests disabled\n");
40749e5c9fe4SRichard W.M. Jones 		return 0;
40759e5c9fe4SRichard W.M. Jones 	}
40769e5c9fe4SRichard W.M. Jones 
40773f47a03dSEric Biggers 	DO_ONCE(testmgr_onetime_init);
40785714758bSJussi Kivilinna 
40791aa4ecd9SHerbert Xu 	if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
40801aa4ecd9SHerbert Xu 		char nalg[CRYPTO_MAX_ALG_NAME];
40811aa4ecd9SHerbert Xu 
40821aa4ecd9SHerbert Xu 		if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
40831aa4ecd9SHerbert Xu 		    sizeof(nalg))
40841aa4ecd9SHerbert Xu 			return -ENAMETOOLONG;
40851aa4ecd9SHerbert Xu 
40861aa4ecd9SHerbert Xu 		i = alg_find_test(nalg);
40871aa4ecd9SHerbert Xu 		if (i < 0)
40881aa4ecd9SHerbert Xu 			goto notest;
40891aa4ecd9SHerbert Xu 
4090a3bef3a3SJarod Wilson 		if (fips_enabled && !alg_test_descs[i].fips_allowed)
4091a3bef3a3SJarod Wilson 			goto non_fips_alg;
4092a3bef3a3SJarod Wilson 
4093941fb328SJarod Wilson 		rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
4094941fb328SJarod Wilson 		goto test_done;
40951aa4ecd9SHerbert Xu 	}
40961aa4ecd9SHerbert Xu 
40971aa4ecd9SHerbert Xu 	i = alg_find_test(alg);
4098a68f6610SHerbert Xu 	j = alg_find_test(driver);
4099a68f6610SHerbert Xu 	if (i < 0 && j < 0)
41001aa4ecd9SHerbert Xu 		goto notest;
41011aa4ecd9SHerbert Xu 
4102a68f6610SHerbert Xu 	if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
4103a68f6610SHerbert Xu 			     (j >= 0 && !alg_test_descs[j].fips_allowed)))
4104a3bef3a3SJarod Wilson 		goto non_fips_alg;
4105a3bef3a3SJarod Wilson 
4106a68f6610SHerbert Xu 	rc = 0;
4107a68f6610SHerbert Xu 	if (i >= 0)
4108a68f6610SHerbert Xu 		rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
41091aa4ecd9SHerbert Xu 					     type, mask);
4110032c8cacSCristian Stoica 	if (j >= 0 && j != i)
4111a68f6610SHerbert Xu 		rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
4112a68f6610SHerbert Xu 					     type, mask);
4113a68f6610SHerbert Xu 
4114941fb328SJarod Wilson test_done:
4115eda69b0cSEric Biggers 	if (rc && (fips_enabled || panic_on_fail))
4116eda69b0cSEric Biggers 		panic("alg: self-tests for %s (%s) failed in %s mode!\n",
4117eda69b0cSEric Biggers 		      driver, alg, fips_enabled ? "fips" : "panic_on_fail");
4118d12d6b6dSNeil Horman 
411929ecd4abSJarod Wilson 	if (fips_enabled && !rc)
41203e8cffd4SMasanari Iida 		pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
412129ecd4abSJarod Wilson 
4122d12d6b6dSNeil Horman 	return rc;
41231aa4ecd9SHerbert Xu 
41241aa4ecd9SHerbert Xu notest:
4125da7f033dSHerbert Xu 	printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
4126da7f033dSHerbert Xu 	return 0;
4127a3bef3a3SJarod Wilson non_fips_alg:
4128a3bef3a3SJarod Wilson 	return -EINVAL;
4129da7f033dSHerbert Xu }
41300b767f96SAlexander Shishkin 
4131326a6346SHerbert Xu #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
41320b767f96SAlexander Shishkin 
4133da7f033dSHerbert Xu EXPORT_SYMBOL_GPL(alg_test);
4134