~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/crypto/testmgr.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /crypto/testmgr.c (Version linux-6.12-rc7) and /crypto/testmgr.c (Version linux-5.14.21)


  1 // SPDX-License-Identifier: GPL-2.0-or-later        1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*                                                  2 /*
  3  * Algorithm testing framework and tests.           3  * Algorithm testing framework and tests.
  4  *                                                  4  *
  5  * Copyright (c) 2002 James Morris <jmorris@in      5  * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
  6  * Copyright (c) 2002 Jean-Francois Dive <jef@      6  * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
  7  * Copyright (c) 2007 Nokia Siemens Networks        7  * Copyright (c) 2007 Nokia Siemens Networks
  8  * Copyright (c) 2008 Herbert Xu <herbert@gond      8  * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
  9  * Copyright (c) 2019 Google LLC                    9  * Copyright (c) 2019 Google LLC
 10  *                                                 10  *
 11  * Updated RFC4106 AES-GCM testing.                11  * Updated RFC4106 AES-GCM testing.
 12  *    Authors: Aidan O'Mahony (aidan.o.mahony@     12  *    Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
 13  *             Adrian Hoban <adrian.hoban@inte     13  *             Adrian Hoban <adrian.hoban@intel.com>
 14  *             Gabriele Paoloni <gabriele.paol     14  *             Gabriele Paoloni <gabriele.paoloni@intel.com>
 15  *             Tadeusz Struk (tadeusz.struk@in     15  *             Tadeusz Struk (tadeusz.struk@intel.com)
 16  *    Copyright (c) 2010, Intel Corporation.       16  *    Copyright (c) 2010, Intel Corporation.
 17  */                                                17  */
 18                                                    18 
 19 #include <crypto/aead.h>                           19 #include <crypto/aead.h>
 20 #include <crypto/hash.h>                           20 #include <crypto/hash.h>
 21 #include <crypto/skcipher.h>                       21 #include <crypto/skcipher.h>
 22 #include <linux/err.h>                             22 #include <linux/err.h>
 23 #include <linux/fips.h>                            23 #include <linux/fips.h>
 24 #include <linux/module.h>                          24 #include <linux/module.h>
 25 #include <linux/once.h>                            25 #include <linux/once.h>
 26 #include <linux/random.h>                          26 #include <linux/random.h>
 27 #include <linux/scatterlist.h>                     27 #include <linux/scatterlist.h>
 28 #include <linux/slab.h>                            28 #include <linux/slab.h>
 29 #include <linux/string.h>                          29 #include <linux/string.h>
 30 #include <linux/uio.h>                             30 #include <linux/uio.h>
 31 #include <crypto/rng.h>                            31 #include <crypto/rng.h>
 32 #include <crypto/drbg.h>                           32 #include <crypto/drbg.h>
 33 #include <crypto/akcipher.h>                       33 #include <crypto/akcipher.h>
 34 #include <crypto/kpp.h>                            34 #include <crypto/kpp.h>
 35 #include <crypto/acompress.h>                      35 #include <crypto/acompress.h>
 36 #include <crypto/internal/cipher.h>                36 #include <crypto/internal/cipher.h>
 37 #include <crypto/internal/simd.h>                  37 #include <crypto/internal/simd.h>
 38                                                    38 
 39 #include "internal.h"                              39 #include "internal.h"
 40                                                    40 
 41 MODULE_IMPORT_NS(CRYPTO_INTERNAL);                 41 MODULE_IMPORT_NS(CRYPTO_INTERNAL);
 42                                                    42 
 43 static bool notests;                               43 static bool notests;
 44 module_param(notests, bool, 0644);                 44 module_param(notests, bool, 0644);
 45 MODULE_PARM_DESC(notests, "disable crypto self     45 MODULE_PARM_DESC(notests, "disable crypto self-tests");
 46                                                    46 
 47 static bool panic_on_fail;                         47 static bool panic_on_fail;
 48 module_param(panic_on_fail, bool, 0444);           48 module_param(panic_on_fail, bool, 0444);
 49                                                    49 
 50 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS           50 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
 51 static bool noextratests;                          51 static bool noextratests;
 52 module_param(noextratests, bool, 0644);            52 module_param(noextratests, bool, 0644);
 53 MODULE_PARM_DESC(noextratests, "disable expens     53 MODULE_PARM_DESC(noextratests, "disable expensive crypto self-tests");
 54                                                    54 
 55 static unsigned int fuzz_iterations = 100;         55 static unsigned int fuzz_iterations = 100;
 56 module_param(fuzz_iterations, uint, 0644);         56 module_param(fuzz_iterations, uint, 0644);
 57 MODULE_PARM_DESC(fuzz_iterations, "number of f     57 MODULE_PARM_DESC(fuzz_iterations, "number of fuzz test iterations");
                                                   >>  58 
                                                   >>  59 DEFINE_PER_CPU(bool, crypto_simd_disabled_for_test);
                                                   >>  60 EXPORT_PER_CPU_SYMBOL_GPL(crypto_simd_disabled_for_test);
 58 #endif                                             61 #endif
 59                                                    62 
 60 #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS         63 #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
 61                                                    64 
 62 /* a perfect nop */                                65 /* a perfect nop */
 63 int alg_test(const char *driver, const char *a     66 int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
 64 {                                                  67 {
 65         return 0;                                  68         return 0;
 66 }                                                  69 }
 67                                                    70 
 68 #else                                              71 #else
 69                                                    72 
 70 #include "testmgr.h"                               73 #include "testmgr.h"
 71                                                    74 
 72 /*                                                 75 /*
 73  * Need slab memory for testing (size in numbe     76  * Need slab memory for testing (size in number of pages).
 74  */                                                77  */
 75 #define XBUFSIZE        8                          78 #define XBUFSIZE        8
 76                                                    79 
 77 /*                                                 80 /*
 78 * Used by test_cipher()                            81 * Used by test_cipher()
 79 */                                                 82 */
 80 #define ENCRYPT 1                                  83 #define ENCRYPT 1
 81 #define DECRYPT 0                                  84 #define DECRYPT 0
 82                                                    85 
 83 struct aead_test_suite {                           86 struct aead_test_suite {
 84         const struct aead_testvec *vecs;           87         const struct aead_testvec *vecs;
 85         unsigned int count;                        88         unsigned int count;
 86                                                    89 
 87         /*                                         90         /*
 88          * Set if trying to decrypt an inauthe     91          * Set if trying to decrypt an inauthentic ciphertext with this
 89          * algorithm might result in EINVAL ra     92          * algorithm might result in EINVAL rather than EBADMSG, due to other
 90          * validation the algorithm does on th     93          * validation the algorithm does on the inputs such as length checks.
 91          */                                        94          */
 92         unsigned int einval_allowed : 1;           95         unsigned int einval_allowed : 1;
 93                                                    96 
 94         /*                                         97         /*
 95          * Set if this algorithm requires that     98          * Set if this algorithm requires that the IV be located at the end of
 96          * the AAD buffer, in addition to bein     99          * the AAD buffer, in addition to being given in the normal way.  The
 97          * behavior when the two IV copies dif    100          * behavior when the two IV copies differ is implementation-defined.
 98          */                                       101          */
 99         unsigned int aad_iv : 1;                  102         unsigned int aad_iv : 1;
100 };                                                103 };
101                                                   104 
102 struct cipher_test_suite {                        105 struct cipher_test_suite {
103         const struct cipher_testvec *vecs;        106         const struct cipher_testvec *vecs;
104         unsigned int count;                       107         unsigned int count;
105 };                                                108 };
106                                                   109 
107 struct comp_test_suite {                          110 struct comp_test_suite {
108         struct {                                  111         struct {
109                 const struct comp_testvec *vec    112                 const struct comp_testvec *vecs;
110                 unsigned int count;               113                 unsigned int count;
111         } comp, decomp;                           114         } comp, decomp;
112 };                                                115 };
113                                                   116 
114 struct hash_test_suite {                          117 struct hash_test_suite {
115         const struct hash_testvec *vecs;          118         const struct hash_testvec *vecs;
116         unsigned int count;                       119         unsigned int count;
117 };                                                120 };
118                                                   121 
119 struct cprng_test_suite {                         122 struct cprng_test_suite {
120         const struct cprng_testvec *vecs;         123         const struct cprng_testvec *vecs;
121         unsigned int count;                       124         unsigned int count;
122 };                                                125 };
123                                                   126 
124 struct drbg_test_suite {                          127 struct drbg_test_suite {
125         const struct drbg_testvec *vecs;          128         const struct drbg_testvec *vecs;
126         unsigned int count;                       129         unsigned int count;
127 };                                                130 };
128                                                   131 
129 struct akcipher_test_suite {                      132 struct akcipher_test_suite {
130         const struct akcipher_testvec *vecs;      133         const struct akcipher_testvec *vecs;
131         unsigned int count;                       134         unsigned int count;
132 };                                                135 };
133                                                   136 
134 struct kpp_test_suite {                           137 struct kpp_test_suite {
135         const struct kpp_testvec *vecs;           138         const struct kpp_testvec *vecs;
136         unsigned int count;                       139         unsigned int count;
137 };                                                140 };
138                                                   141 
139 struct alg_test_desc {                            142 struct alg_test_desc {
140         const char *alg;                          143         const char *alg;
141         const char *generic_driver;               144         const char *generic_driver;
142         int (*test)(const struct alg_test_desc    145         int (*test)(const struct alg_test_desc *desc, const char *driver,
143                     u32 type, u32 mask);          146                     u32 type, u32 mask);
144         int fips_allowed;       /* set if alg     147         int fips_allowed;       /* set if alg is allowed in fips mode */
145                                                   148 
146         union {                                   149         union {
147                 struct aead_test_suite aead;      150                 struct aead_test_suite aead;
148                 struct cipher_test_suite ciphe    151                 struct cipher_test_suite cipher;
149                 struct comp_test_suite comp;      152                 struct comp_test_suite comp;
150                 struct hash_test_suite hash;      153                 struct hash_test_suite hash;
151                 struct cprng_test_suite cprng;    154                 struct cprng_test_suite cprng;
152                 struct drbg_test_suite drbg;      155                 struct drbg_test_suite drbg;
153                 struct akcipher_test_suite akc    156                 struct akcipher_test_suite akcipher;
154                 struct kpp_test_suite kpp;        157                 struct kpp_test_suite kpp;
155         } suite;                                  158         } suite;
156 };                                                159 };
157                                                   160 
158 static void hexdump(unsigned char *buf, unsign    161 static void hexdump(unsigned char *buf, unsigned int len)
159 {                                                 162 {
160         print_hex_dump(KERN_CONT, "", DUMP_PRE    163         print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
161                         16, 1,                    164                         16, 1,
162                         buf, len, false);         165                         buf, len, false);
163 }                                                 166 }
164                                                   167 
165 static int __testmgr_alloc_buf(char *buf[XBUFS    168 static int __testmgr_alloc_buf(char *buf[XBUFSIZE], int order)
166 {                                                 169 {
167         int i;                                    170         int i;
168                                                   171 
169         for (i = 0; i < XBUFSIZE; i++) {          172         for (i = 0; i < XBUFSIZE; i++) {
170                 buf[i] = (char *)__get_free_pa    173                 buf[i] = (char *)__get_free_pages(GFP_KERNEL, order);
171                 if (!buf[i])                      174                 if (!buf[i])
172                         goto err_free_buf;        175                         goto err_free_buf;
173         }                                         176         }
174                                                   177 
175         return 0;                                 178         return 0;
176                                                   179 
177 err_free_buf:                                     180 err_free_buf:
178         while (i-- > 0)                           181         while (i-- > 0)
179                 free_pages((unsigned long)buf[    182                 free_pages((unsigned long)buf[i], order);
180                                                   183 
181         return -ENOMEM;                           184         return -ENOMEM;
182 }                                                 185 }
183                                                   186 
184 static int testmgr_alloc_buf(char *buf[XBUFSIZ    187 static int testmgr_alloc_buf(char *buf[XBUFSIZE])
185 {                                                 188 {
186         return __testmgr_alloc_buf(buf, 0);       189         return __testmgr_alloc_buf(buf, 0);
187 }                                                 190 }
188                                                   191 
189 static void __testmgr_free_buf(char *buf[XBUFS    192 static void __testmgr_free_buf(char *buf[XBUFSIZE], int order)
190 {                                                 193 {
191         int i;                                    194         int i;
192                                                   195 
193         for (i = 0; i < XBUFSIZE; i++)            196         for (i = 0; i < XBUFSIZE; i++)
194                 free_pages((unsigned long)buf[    197                 free_pages((unsigned long)buf[i], order);
195 }                                                 198 }
196                                                   199 
197 static void testmgr_free_buf(char *buf[XBUFSIZ    200 static void testmgr_free_buf(char *buf[XBUFSIZE])
198 {                                                 201 {
199         __testmgr_free_buf(buf, 0);               202         __testmgr_free_buf(buf, 0);
200 }                                                 203 }
201                                                   204 
202 #define TESTMGR_POISON_BYTE     0xfe              205 #define TESTMGR_POISON_BYTE     0xfe
203 #define TESTMGR_POISON_LEN      16                206 #define TESTMGR_POISON_LEN      16
204                                                   207 
205 static inline void testmgr_poison(void *addr,     208 static inline void testmgr_poison(void *addr, size_t len)
206 {                                                 209 {
207         memset(addr, TESTMGR_POISON_BYTE, len)    210         memset(addr, TESTMGR_POISON_BYTE, len);
208 }                                                 211 }
209                                                   212 
210 /* Is the memory region still fully poisoned?     213 /* Is the memory region still fully poisoned? */
211 static inline bool testmgr_is_poison(const voi    214 static inline bool testmgr_is_poison(const void *addr, size_t len)
212 {                                                 215 {
213         return memchr_inv(addr, TESTMGR_POISON    216         return memchr_inv(addr, TESTMGR_POISON_BYTE, len) == NULL;
214 }                                                 217 }
215                                                   218 
216 /* flush type for hash algorithms */              219 /* flush type for hash algorithms */
217 enum flush_type {                                 220 enum flush_type {
218         /* merge with update of previous buffe    221         /* merge with update of previous buffer(s) */
219         FLUSH_TYPE_NONE = 0,                      222         FLUSH_TYPE_NONE = 0,
220                                                   223 
221         /* update with previous buffer(s) befo    224         /* update with previous buffer(s) before doing this one */
222         FLUSH_TYPE_FLUSH,                         225         FLUSH_TYPE_FLUSH,
223                                                   226 
224         /* likewise, but also export and re-im    227         /* likewise, but also export and re-import the intermediate state */
225         FLUSH_TYPE_REIMPORT,                      228         FLUSH_TYPE_REIMPORT,
226 };                                                229 };
227                                                   230 
228 /* finalization function for hash algorithms *    231 /* finalization function for hash algorithms */
229 enum finalization_type {                          232 enum finalization_type {
230         FINALIZATION_TYPE_FINAL,        /* use    233         FINALIZATION_TYPE_FINAL,        /* use final() */
231         FINALIZATION_TYPE_FINUP,        /* use    234         FINALIZATION_TYPE_FINUP,        /* use finup() */
232         FINALIZATION_TYPE_DIGEST,       /* use    235         FINALIZATION_TYPE_DIGEST,       /* use digest() */
233 };                                                236 };
234                                                   237 
235 /*                                             << 
236  * Whether the crypto operation will occur in- << 
237  * source and destination scatterlist pointers << 
238  * req->dst), or whether they'll merely point  << 
239  * (req->src != req->dst) that reference the s << 
240  *                                             << 
241  * This is only relevant for algorithm types t << 
242  */                                            << 
243 enum inplace_mode {                            << 
244         OUT_OF_PLACE,                          << 
245         INPLACE_ONE_SGLIST,                    << 
246         INPLACE_TWO_SGLISTS,                   << 
247 };                                             << 
248                                                << 
249 #define TEST_SG_TOTAL   10000                     238 #define TEST_SG_TOTAL   10000
250                                                   239 
251 /**                                               240 /**
252  * struct test_sg_division - description of a     241  * struct test_sg_division - description of a scatterlist entry
253  *                                                242  *
254  * This struct describes one entry of a scatte    243  * This struct describes one entry of a scatterlist being constructed to check a
255  * crypto test vector.                            244  * crypto test vector.
256  *                                                245  *
257  * @proportion_of_total: length of this chunk     246  * @proportion_of_total: length of this chunk relative to the total length,
258  *                       given as a proportion    247  *                       given as a proportion out of TEST_SG_TOTAL so that it
259  *                       scales to fit any tes    248  *                       scales to fit any test vector
260  * @offset: byte offset into a 2-page buffer a    249  * @offset: byte offset into a 2-page buffer at which this chunk will start
261  * @offset_relative_to_alignmask: if true, add    250  * @offset_relative_to_alignmask: if true, add the algorithm's alignmask to the
262  *                                @offset         251  *                                @offset
263  * @flush_type: for hashes, whether an update(    252  * @flush_type: for hashes, whether an update() should be done now vs.
264  *              continuing to accumulate data     253  *              continuing to accumulate data
265  * @nosimd: if doing the pending update(), do     254  * @nosimd: if doing the pending update(), do it with SIMD disabled?
266  */                                               255  */
267 struct test_sg_division {                         256 struct test_sg_division {
268         unsigned int proportion_of_total;         257         unsigned int proportion_of_total;
269         unsigned int offset;                      258         unsigned int offset;
270         bool offset_relative_to_alignmask;        259         bool offset_relative_to_alignmask;
271         enum flush_type flush_type;               260         enum flush_type flush_type;
272         bool nosimd;                              261         bool nosimd;
273 };                                                262 };
274                                                   263 
275 /**                                               264 /**
276  * struct testvec_config - configuration for t    265  * struct testvec_config - configuration for testing a crypto test vector
277  *                                                266  *
278  * This struct describes the data layout and o    267  * This struct describes the data layout and other parameters with which each
279  * crypto test vector can be tested.              268  * crypto test vector can be tested.
280  *                                                269  *
281  * @name: name of this config, logged for debu    270  * @name: name of this config, logged for debugging purposes if a test fails
282  * @inplace_mode: whether and how to operate o !! 271  * @inplace: operate on the data in-place, if applicable for the algorithm type?
283  * @req_flags: extra request_flags, e.g. CRYPT    272  * @req_flags: extra request_flags, e.g. CRYPTO_TFM_REQ_MAY_SLEEP
284  * @src_divs: description of how to arrange th    273  * @src_divs: description of how to arrange the source scatterlist
285  * @dst_divs: description of how to arrange th    274  * @dst_divs: description of how to arrange the dst scatterlist, if applicable
286  *            for the algorithm type.  Default    275  *            for the algorithm type.  Defaults to @src_divs if unset.
287  * @iv_offset: misalignment of the IV in the r    276  * @iv_offset: misalignment of the IV in the range [0..MAX_ALGAPI_ALIGNMASK+1],
288  *             where 0 is aligned to a 2*(MAX_    277  *             where 0 is aligned to a 2*(MAX_ALGAPI_ALIGNMASK+1) byte boundary
289  * @iv_offset_relative_to_alignmask: if true,     278  * @iv_offset_relative_to_alignmask: if true, add the algorithm's alignmask to
290  *                                   the @iv_o    279  *                                   the @iv_offset
291  * @key_offset: misalignment of the key, where    280  * @key_offset: misalignment of the key, where 0 is default alignment
292  * @key_offset_relative_to_alignmask: if true,    281  * @key_offset_relative_to_alignmask: if true, add the algorithm's alignmask to
293  *                                    the @key    282  *                                    the @key_offset
294  * @finalization_type: what finalization funct    283  * @finalization_type: what finalization function to use for hashes
295  * @nosimd: execute with SIMD disabled?  Requi    284  * @nosimd: execute with SIMD disabled?  Requires !CRYPTO_TFM_REQ_MAY_SLEEP.
296  *          This applies to the parts of the o << 
297  *          individually by @nosimd_setkey or  << 
298  * @nosimd_setkey: set the key (if applicable) << 
299  *                 !CRYPTO_TFM_REQ_MAY_SLEEP.  << 
300  */                                               285  */
301 struct testvec_config {                           286 struct testvec_config {
302         const char *name;                         287         const char *name;
303         enum inplace_mode inplace_mode;        !! 288         bool inplace;
304         u32 req_flags;                            289         u32 req_flags;
305         struct test_sg_division src_divs[XBUFS    290         struct test_sg_division src_divs[XBUFSIZE];
306         struct test_sg_division dst_divs[XBUFS    291         struct test_sg_division dst_divs[XBUFSIZE];
307         unsigned int iv_offset;                   292         unsigned int iv_offset;
308         unsigned int key_offset;                  293         unsigned int key_offset;
309         bool iv_offset_relative_to_alignmask;     294         bool iv_offset_relative_to_alignmask;
310         bool key_offset_relative_to_alignmask;    295         bool key_offset_relative_to_alignmask;
311         enum finalization_type finalization_ty    296         enum finalization_type finalization_type;
312         bool nosimd;                              297         bool nosimd;
313         bool nosimd_setkey;                    << 
314 };                                                298 };
315                                                   299 
316 #define TESTVEC_CONFIG_NAMELEN  192               300 #define TESTVEC_CONFIG_NAMELEN  192
317                                                   301 
318 /*                                                302 /*
319  * The following are the lists of testvec_conf    303  * The following are the lists of testvec_configs to test for each algorithm
320  * type when the basic crypto self-tests are e    304  * type when the basic crypto self-tests are enabled, i.e. when
321  * CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is unse    305  * CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is unset.  They aim to provide good test
322  * coverage, while keeping the test time much     306  * coverage, while keeping the test time much shorter than the full fuzz tests
323  * so that the basic tests can be enabled in a    307  * so that the basic tests can be enabled in a wider range of circumstances.
324  */                                               308  */
325                                                   309 
326 /* Configs for skciphers and aeads */             310 /* Configs for skciphers and aeads */
327 static const struct testvec_config default_cip    311 static const struct testvec_config default_cipher_testvec_configs[] = {
328         {                                         312         {
329                 .name = "in-place (one sglist) !! 313                 .name = "in-place",
330                 .inplace_mode = INPLACE_ONE_SG !! 314                 .inplace = true,
331                 .src_divs = { { .proportion_of << 
332         }, {                                   << 
333                 .name = "in-place (two sglists << 
334                 .inplace_mode = INPLACE_TWO_SG << 
335                 .src_divs = { { .proportion_of    315                 .src_divs = { { .proportion_of_total = 10000 } },
336         }, {                                      316         }, {
337                 .name = "out-of-place",           317                 .name = "out-of-place",
338                 .inplace_mode = OUT_OF_PLACE,  << 
339                 .src_divs = { { .proportion_of    318                 .src_divs = { { .proportion_of_total = 10000 } },
340         }, {                                      319         }, {
341                 .name = "unaligned buffer, off    320                 .name = "unaligned buffer, offset=1",
342                 .src_divs = { { .proportion_of    321                 .src_divs = { { .proportion_of_total = 10000, .offset = 1 } },
343                 .iv_offset = 1,                   322                 .iv_offset = 1,
344                 .key_offset = 1,                  323                 .key_offset = 1,
345         }, {                                      324         }, {
346                 .name = "buffer aligned only t    325                 .name = "buffer aligned only to alignmask",
347                 .src_divs = {                     326                 .src_divs = {
348                         {                         327                         {
349                                 .proportion_of    328                                 .proportion_of_total = 10000,
350                                 .offset = 1,      329                                 .offset = 1,
351                                 .offset_relati    330                                 .offset_relative_to_alignmask = true,
352                         },                        331                         },
353                 },                                332                 },
354                 .iv_offset = 1,                   333                 .iv_offset = 1,
355                 .iv_offset_relative_to_alignma    334                 .iv_offset_relative_to_alignmask = true,
356                 .key_offset = 1,                  335                 .key_offset = 1,
357                 .key_offset_relative_to_alignm    336                 .key_offset_relative_to_alignmask = true,
358         }, {                                      337         }, {
359                 .name = "two even aligned spli    338                 .name = "two even aligned splits",
360                 .src_divs = {                     339                 .src_divs = {
361                         { .proportion_of_total    340                         { .proportion_of_total = 5000 },
362                         { .proportion_of_total    341                         { .proportion_of_total = 5000 },
363                 },                                342                 },
364         }, {                                      343         }, {
365                 .name = "one src, two even spl << 
366                 .inplace_mode = OUT_OF_PLACE,  << 
367                 .src_divs = { { .proportion_of << 
368                 .dst_divs = {                  << 
369                         { .proportion_of_total << 
370                         { .proportion_of_total << 
371                  },                            << 
372         }, {                                   << 
373                 .name = "uneven misaligned spl    344                 .name = "uneven misaligned splits, may sleep",
374                 .req_flags = CRYPTO_TFM_REQ_MA    345                 .req_flags = CRYPTO_TFM_REQ_MAY_SLEEP,
375                 .src_divs = {                     346                 .src_divs = {
376                         { .proportion_of_total    347                         { .proportion_of_total = 1900, .offset = 33 },
377                         { .proportion_of_total    348                         { .proportion_of_total = 3300, .offset = 7  },
378                         { .proportion_of_total    349                         { .proportion_of_total = 4800, .offset = 18 },
379                 },                                350                 },
380                 .iv_offset = 3,                   351                 .iv_offset = 3,
381                 .key_offset = 3,                  352                 .key_offset = 3,
382         }, {                                      353         }, {
383                 .name = "misaligned splits cro    354                 .name = "misaligned splits crossing pages, inplace",
384                 .inplace_mode = INPLACE_ONE_SG !! 355                 .inplace = true,
385                 .src_divs = {                     356                 .src_divs = {
386                         {                         357                         {
387                                 .proportion_of    358                                 .proportion_of_total = 7500,
388                                 .offset = PAGE    359                                 .offset = PAGE_SIZE - 32
389                         }, {                      360                         }, {
390                                 .proportion_of    361                                 .proportion_of_total = 2500,
391                                 .offset = PAGE    362                                 .offset = PAGE_SIZE - 7
392                         },                        363                         },
393                 },                                364                 },
394         }                                         365         }
395 };                                                366 };
396                                                   367 
397 static const struct testvec_config default_has    368 static const struct testvec_config default_hash_testvec_configs[] = {
398         {                                         369         {
399                 .name = "init+update+final ali    370                 .name = "init+update+final aligned buffer",
400                 .src_divs = { { .proportion_of    371                 .src_divs = { { .proportion_of_total = 10000 } },
401                 .finalization_type = FINALIZAT    372                 .finalization_type = FINALIZATION_TYPE_FINAL,
402         }, {                                      373         }, {
403                 .name = "init+finup aligned bu    374                 .name = "init+finup aligned buffer",
404                 .src_divs = { { .proportion_of    375                 .src_divs = { { .proportion_of_total = 10000 } },
405                 .finalization_type = FINALIZAT    376                 .finalization_type = FINALIZATION_TYPE_FINUP,
406         }, {                                      377         }, {
407                 .name = "digest aligned buffer    378                 .name = "digest aligned buffer",
408                 .src_divs = { { .proportion_of    379                 .src_divs = { { .proportion_of_total = 10000 } },
409                 .finalization_type = FINALIZAT    380                 .finalization_type = FINALIZATION_TYPE_DIGEST,
410         }, {                                      381         }, {
411                 .name = "init+update+final mis    382                 .name = "init+update+final misaligned buffer",
412                 .src_divs = { { .proportion_of    383                 .src_divs = { { .proportion_of_total = 10000, .offset = 1 } },
413                 .finalization_type = FINALIZAT    384                 .finalization_type = FINALIZATION_TYPE_FINAL,
414                 .key_offset = 1,                  385                 .key_offset = 1,
415         }, {                                      386         }, {
416                 .name = "digest misaligned buf !! 387                 .name = "digest buffer aligned only to alignmask",
417                 .src_divs = {                     388                 .src_divs = {
418                         {                         389                         {
419                                 .proportion_of    390                                 .proportion_of_total = 10000,
420                                 .offset = 1,      391                                 .offset = 1,
                                                   >> 392                                 .offset_relative_to_alignmask = true,
421                         },                        393                         },
422                 },                                394                 },
423                 .finalization_type = FINALIZAT    395                 .finalization_type = FINALIZATION_TYPE_DIGEST,
424                 .key_offset = 1,                  396                 .key_offset = 1,
                                                   >> 397                 .key_offset_relative_to_alignmask = true,
425         }, {                                      398         }, {
426                 .name = "init+update+update+fi    399                 .name = "init+update+update+final two even splits",
427                 .src_divs = {                     400                 .src_divs = {
428                         { .proportion_of_total    401                         { .proportion_of_total = 5000 },
429                         {                         402                         {
430                                 .proportion_of    403                                 .proportion_of_total = 5000,
431                                 .flush_type =     404                                 .flush_type = FLUSH_TYPE_FLUSH,
432                         },                        405                         },
433                 },                                406                 },
434                 .finalization_type = FINALIZAT    407                 .finalization_type = FINALIZATION_TYPE_FINAL,
435         }, {                                      408         }, {
436                 .name = "digest uneven misalig    409                 .name = "digest uneven misaligned splits, may sleep",
437                 .req_flags = CRYPTO_TFM_REQ_MA    410                 .req_flags = CRYPTO_TFM_REQ_MAY_SLEEP,
438                 .src_divs = {                     411                 .src_divs = {
439                         { .proportion_of_total    412                         { .proportion_of_total = 1900, .offset = 33 },
440                         { .proportion_of_total    413                         { .proportion_of_total = 3300, .offset = 7  },
441                         { .proportion_of_total    414                         { .proportion_of_total = 4800, .offset = 18 },
442                 },                                415                 },
443                 .finalization_type = FINALIZAT    416                 .finalization_type = FINALIZATION_TYPE_DIGEST,
444         }, {                                      417         }, {
445                 .name = "digest misaligned spl    418                 .name = "digest misaligned splits crossing pages",
446                 .src_divs = {                     419                 .src_divs = {
447                         {                         420                         {
448                                 .proportion_of    421                                 .proportion_of_total = 7500,
449                                 .offset = PAGE    422                                 .offset = PAGE_SIZE - 32,
450                         }, {                      423                         }, {
451                                 .proportion_of    424                                 .proportion_of_total = 2500,
452                                 .offset = PAGE    425                                 .offset = PAGE_SIZE - 7,
453                         },                        426                         },
454                 },                                427                 },
455                 .finalization_type = FINALIZAT    428                 .finalization_type = FINALIZATION_TYPE_DIGEST,
456         }, {                                      429         }, {
457                 .name = "import/export",          430                 .name = "import/export",
458                 .src_divs = {                     431                 .src_divs = {
459                         {                         432                         {
460                                 .proportion_of    433                                 .proportion_of_total = 6500,
461                                 .flush_type =     434                                 .flush_type = FLUSH_TYPE_REIMPORT,
462                         }, {                      435                         }, {
463                                 .proportion_of    436                                 .proportion_of_total = 3500,
464                                 .flush_type =     437                                 .flush_type = FLUSH_TYPE_REIMPORT,
465                         },                        438                         },
466                 },                                439                 },
467                 .finalization_type = FINALIZAT    440                 .finalization_type = FINALIZATION_TYPE_FINAL,
468         }                                         441         }
469 };                                                442 };
470                                                   443 
471 static unsigned int count_test_sg_divisions(co    444 static unsigned int count_test_sg_divisions(const struct test_sg_division *divs)
472 {                                                 445 {
473         unsigned int remaining = TEST_SG_TOTAL    446         unsigned int remaining = TEST_SG_TOTAL;
474         unsigned int ndivs = 0;                   447         unsigned int ndivs = 0;
475                                                   448 
476         do {                                      449         do {
477                 remaining -= divs[ndivs++].pro    450                 remaining -= divs[ndivs++].proportion_of_total;
478         } while (remaining);                      451         } while (remaining);
479                                                   452 
480         return ndivs;                             453         return ndivs;
481 }                                                 454 }
482                                                   455 
483 #define SGDIVS_HAVE_FLUSHES     BIT(0)            456 #define SGDIVS_HAVE_FLUSHES     BIT(0)
484 #define SGDIVS_HAVE_NOSIMD      BIT(1)            457 #define SGDIVS_HAVE_NOSIMD      BIT(1)
485                                                   458 
486 static bool valid_sg_divisions(const struct te    459 static bool valid_sg_divisions(const struct test_sg_division *divs,
487                                unsigned int co    460                                unsigned int count, int *flags_ret)
488 {                                                 461 {
489         unsigned int total = 0;                   462         unsigned int total = 0;
490         unsigned int i;                           463         unsigned int i;
491                                                   464 
492         for (i = 0; i < count && total != TEST    465         for (i = 0; i < count && total != TEST_SG_TOTAL; i++) {
493                 if (divs[i].proportion_of_tota    466                 if (divs[i].proportion_of_total <= 0 ||
494                     divs[i].proportion_of_tota    467                     divs[i].proportion_of_total > TEST_SG_TOTAL - total)
495                         return false;             468                         return false;
496                 total += divs[i].proportion_of    469                 total += divs[i].proportion_of_total;
497                 if (divs[i].flush_type != FLUS    470                 if (divs[i].flush_type != FLUSH_TYPE_NONE)
498                         *flags_ret |= SGDIVS_H    471                         *flags_ret |= SGDIVS_HAVE_FLUSHES;
499                 if (divs[i].nosimd)               472                 if (divs[i].nosimd)
500                         *flags_ret |= SGDIVS_H    473                         *flags_ret |= SGDIVS_HAVE_NOSIMD;
501         }                                         474         }
502         return total == TEST_SG_TOTAL &&          475         return total == TEST_SG_TOTAL &&
503                 memchr_inv(&divs[i], 0, (count    476                 memchr_inv(&divs[i], 0, (count - i) * sizeof(divs[0])) == NULL;
504 }                                                 477 }
505                                                   478 
506 /*                                                479 /*
507  * Check whether the given testvec_config is v    480  * Check whether the given testvec_config is valid.  This isn't strictly needed
508  * since every testvec_config should be valid,    481  * since every testvec_config should be valid, but check anyway so that people
509  * don't unknowingly add broken configs that d    482  * don't unknowingly add broken configs that don't do what they wanted.
510  */                                               483  */
511 static bool valid_testvec_config(const struct     484 static bool valid_testvec_config(const struct testvec_config *cfg)
512 {                                                 485 {
513         int flags = 0;                            486         int flags = 0;
514                                                   487 
515         if (cfg->name == NULL)                    488         if (cfg->name == NULL)
516                 return false;                     489                 return false;
517                                                   490 
518         if (!valid_sg_divisions(cfg->src_divs,    491         if (!valid_sg_divisions(cfg->src_divs, ARRAY_SIZE(cfg->src_divs),
519                                 &flags))          492                                 &flags))
520                 return false;                     493                 return false;
521                                                   494 
522         if (cfg->dst_divs[0].proportion_of_tot    495         if (cfg->dst_divs[0].proportion_of_total) {
523                 if (!valid_sg_divisions(cfg->d    496                 if (!valid_sg_divisions(cfg->dst_divs,
524                                         ARRAY_    497                                         ARRAY_SIZE(cfg->dst_divs), &flags))
525                         return false;             498                         return false;
526         } else {                                  499         } else {
527                 if (memchr_inv(cfg->dst_divs,     500                 if (memchr_inv(cfg->dst_divs, 0, sizeof(cfg->dst_divs)))
528                         return false;             501                         return false;
529                 /* defaults to dst_divs=src_di    502                 /* defaults to dst_divs=src_divs */
530         }                                         503         }
531                                                   504 
532         if (cfg->iv_offset +                      505         if (cfg->iv_offset +
533             (cfg->iv_offset_relative_to_alignm    506             (cfg->iv_offset_relative_to_alignmask ? MAX_ALGAPI_ALIGNMASK : 0) >
534             MAX_ALGAPI_ALIGNMASK + 1)             507             MAX_ALGAPI_ALIGNMASK + 1)
535                 return false;                     508                 return false;
536                                                   509 
537         if ((flags & (SGDIVS_HAVE_FLUSHES | SG    510         if ((flags & (SGDIVS_HAVE_FLUSHES | SGDIVS_HAVE_NOSIMD)) &&
538             cfg->finalization_type == FINALIZA    511             cfg->finalization_type == FINALIZATION_TYPE_DIGEST)
539                 return false;                     512                 return false;
540                                                   513 
541         if ((cfg->nosimd || cfg->nosimd_setkey !! 514         if ((cfg->nosimd || (flags & SGDIVS_HAVE_NOSIMD)) &&
542              (flags & SGDIVS_HAVE_NOSIMD)) &&  << 
543             (cfg->req_flags & CRYPTO_TFM_REQ_M    515             (cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP))
544                 return false;                     516                 return false;
545                                                   517 
546         return true;                              518         return true;
547 }                                                 519 }
548                                                   520 
549 struct test_sglist {                              521 struct test_sglist {
550         char *bufs[XBUFSIZE];                     522         char *bufs[XBUFSIZE];
551         struct scatterlist sgl[XBUFSIZE];         523         struct scatterlist sgl[XBUFSIZE];
552         struct scatterlist sgl_saved[XBUFSIZE]    524         struct scatterlist sgl_saved[XBUFSIZE];
553         struct scatterlist *sgl_ptr;              525         struct scatterlist *sgl_ptr;
554         unsigned int nents;                       526         unsigned int nents;
555 };                                                527 };
556                                                   528 
557 static int init_test_sglist(struct test_sglist    529 static int init_test_sglist(struct test_sglist *tsgl)
558 {                                                 530 {
559         return __testmgr_alloc_buf(tsgl->bufs,    531         return __testmgr_alloc_buf(tsgl->bufs, 1 /* two pages per buffer */);
560 }                                                 532 }
561                                                   533 
562 static void destroy_test_sglist(struct test_sg    534 static void destroy_test_sglist(struct test_sglist *tsgl)
563 {                                                 535 {
564         return __testmgr_free_buf(tsgl->bufs,     536         return __testmgr_free_buf(tsgl->bufs, 1 /* two pages per buffer */);
565 }                                                 537 }
566                                                   538 
567 /**                                               539 /**
568  * build_test_sglist() - build a scatterlist f    540  * build_test_sglist() - build a scatterlist for a crypto test
569  *                                                541  *
570  * @tsgl: the scatterlist to build.  @tsgl->bu    542  * @tsgl: the scatterlist to build.  @tsgl->bufs[] contains an array of 2-page
571  *        buffers which the scatterlist @tsgl-    543  *        buffers which the scatterlist @tsgl->sgl[] will be made to point into.
572  * @divs: the layout specification on which th    544  * @divs: the layout specification on which the scatterlist will be based
573  * @alignmask: the algorithm's alignmask          545  * @alignmask: the algorithm's alignmask
574  * @total_len: the total length of the scatter    546  * @total_len: the total length of the scatterlist to build in bytes
575  * @data: if non-NULL, the buffers will be fil    547  * @data: if non-NULL, the buffers will be filled with this data until it ends.
576  *        Otherwise the buffers will be poison    548  *        Otherwise the buffers will be poisoned.  In both cases, some bytes
577  *        past the end of each buffer will be     549  *        past the end of each buffer will be poisoned to help detect overruns.
578  * @out_divs: if non-NULL, the test_sg_divisio    550  * @out_divs: if non-NULL, the test_sg_division to which each scatterlist entry
579  *            corresponds will be returned her    551  *            corresponds will be returned here.  This will match @divs except
580  *            that divisions resolving to a le    552  *            that divisions resolving to a length of 0 are omitted as they are
581  *            not included in the scatterlist.    553  *            not included in the scatterlist.
582  *                                                554  *
583  * Return: 0 or a -errno value                    555  * Return: 0 or a -errno value
584  */                                               556  */
585 static int build_test_sglist(struct test_sglis    557 static int build_test_sglist(struct test_sglist *tsgl,
586                              const struct test    558                              const struct test_sg_division *divs,
587                              const unsigned in    559                              const unsigned int alignmask,
588                              const unsigned in    560                              const unsigned int total_len,
589                              struct iov_iter *    561                              struct iov_iter *data,
590                              const struct test    562                              const struct test_sg_division *out_divs[XBUFSIZE])
591 {                                                 563 {
592         struct {                                  564         struct {
593                 const struct test_sg_division     565                 const struct test_sg_division *div;
594                 size_t length;                    566                 size_t length;
595         } partitions[XBUFSIZE];                   567         } partitions[XBUFSIZE];
596         const unsigned int ndivs = count_test_    568         const unsigned int ndivs = count_test_sg_divisions(divs);
597         unsigned int len_remaining = total_len    569         unsigned int len_remaining = total_len;
598         unsigned int i;                           570         unsigned int i;
599                                                   571 
600         BUILD_BUG_ON(ARRAY_SIZE(partitions) !=    572         BUILD_BUG_ON(ARRAY_SIZE(partitions) != ARRAY_SIZE(tsgl->sgl));
601         if (WARN_ON(ndivs > ARRAY_SIZE(partiti    573         if (WARN_ON(ndivs > ARRAY_SIZE(partitions)))
602                 return -EINVAL;                   574                 return -EINVAL;
603                                                   575 
604         /* Calculate the (div, length) pairs *    576         /* Calculate the (div, length) pairs */
605         tsgl->nents = 0;                          577         tsgl->nents = 0;
606         for (i = 0; i < ndivs; i++) {             578         for (i = 0; i < ndivs; i++) {
607                 unsigned int len_this_sg =        579                 unsigned int len_this_sg =
608                         min(len_remaining,        580                         min(len_remaining,
609                             (total_len * divs[    581                             (total_len * divs[i].proportion_of_total +
610                              TEST_SG_TOTAL / 2    582                              TEST_SG_TOTAL / 2) / TEST_SG_TOTAL);
611                                                   583 
612                 if (len_this_sg != 0) {           584                 if (len_this_sg != 0) {
613                         partitions[tsgl->nents    585                         partitions[tsgl->nents].div = &divs[i];
614                         partitions[tsgl->nents    586                         partitions[tsgl->nents].length = len_this_sg;
615                         tsgl->nents++;            587                         tsgl->nents++;
616                         len_remaining -= len_t    588                         len_remaining -= len_this_sg;
617                 }                                 589                 }
618         }                                         590         }
619         if (tsgl->nents == 0) {                   591         if (tsgl->nents == 0) {
620                 partitions[tsgl->nents].div =     592                 partitions[tsgl->nents].div = &divs[0];
621                 partitions[tsgl->nents].length    593                 partitions[tsgl->nents].length = 0;
622                 tsgl->nents++;                    594                 tsgl->nents++;
623         }                                         595         }
624         partitions[tsgl->nents - 1].length +=     596         partitions[tsgl->nents - 1].length += len_remaining;
625                                                   597 
626         /* Set up the sgl entries and fill the    598         /* Set up the sgl entries and fill the data or poison */
627         sg_init_table(tsgl->sgl, tsgl->nents);    599         sg_init_table(tsgl->sgl, tsgl->nents);
628         for (i = 0; i < tsgl->nents; i++) {       600         for (i = 0; i < tsgl->nents; i++) {
629                 unsigned int offset = partitio    601                 unsigned int offset = partitions[i].div->offset;
630                 void *addr;                       602                 void *addr;
631                                                   603 
632                 if (partitions[i].div->offset_    604                 if (partitions[i].div->offset_relative_to_alignmask)
633                         offset += alignmask;      605                         offset += alignmask;
634                                                   606 
635                 while (offset + partitions[i].    607                 while (offset + partitions[i].length + TESTMGR_POISON_LEN >
636                        2 * PAGE_SIZE) {           608                        2 * PAGE_SIZE) {
637                         if (WARN_ON(offset <=     609                         if (WARN_ON(offset <= 0))
638                                 return -EINVAL    610                                 return -EINVAL;
639                         offset /= 2;              611                         offset /= 2;
640                 }                                 612                 }
641                                                   613 
642                 addr = &tsgl->bufs[i][offset];    614                 addr = &tsgl->bufs[i][offset];
643                 sg_set_buf(&tsgl->sgl[i], addr    615                 sg_set_buf(&tsgl->sgl[i], addr, partitions[i].length);
644                                                   616 
645                 if (out_divs)                     617                 if (out_divs)
646                         out_divs[i] = partitio    618                         out_divs[i] = partitions[i].div;
647                                                   619 
648                 if (data) {                       620                 if (data) {
649                         size_t copy_len, copie    621                         size_t copy_len, copied;
650                                                   622 
651                         copy_len = min(partiti    623                         copy_len = min(partitions[i].length, data->count);
652                         copied = copy_from_ite    624                         copied = copy_from_iter(addr, copy_len, data);
653                         if (WARN_ON(copied !=     625                         if (WARN_ON(copied != copy_len))
654                                 return -EINVAL    626                                 return -EINVAL;
655                         testmgr_poison(addr +     627                         testmgr_poison(addr + copy_len, partitions[i].length +
656                                        TESTMGR    628                                        TESTMGR_POISON_LEN - copy_len);
657                 } else {                          629                 } else {
658                         testmgr_poison(addr, p    630                         testmgr_poison(addr, partitions[i].length +
659                                        TESTMGR    631                                        TESTMGR_POISON_LEN);
660                 }                                 632                 }
661         }                                         633         }
662                                                   634 
663         sg_mark_end(&tsgl->sgl[tsgl->nents - 1    635         sg_mark_end(&tsgl->sgl[tsgl->nents - 1]);
664         tsgl->sgl_ptr = tsgl->sgl;                636         tsgl->sgl_ptr = tsgl->sgl;
665         memcpy(tsgl->sgl_saved, tsgl->sgl, tsg    637         memcpy(tsgl->sgl_saved, tsgl->sgl, tsgl->nents * sizeof(tsgl->sgl[0]));
666         return 0;                                 638         return 0;
667 }                                                 639 }
668                                                   640 
669 /*                                                641 /*
670  * Verify that a scatterlist crypto operation     642  * Verify that a scatterlist crypto operation produced the correct output.
671  *                                                643  *
672  * @tsgl: scatterlist containing the actual ou    644  * @tsgl: scatterlist containing the actual output
673  * @expected_output: buffer containing the exp    645  * @expected_output: buffer containing the expected output
674  * @len_to_check: length of @expected_output i    646  * @len_to_check: length of @expected_output in bytes
675  * @unchecked_prefix_len: number of ignored by    647  * @unchecked_prefix_len: number of ignored bytes in @tsgl prior to real result
676  * @check_poison: verify that the poison bytes    648  * @check_poison: verify that the poison bytes after each chunk are intact?
677  *                                                649  *
678  * Return: 0 if correct, -EINVAL if incorrect,    650  * Return: 0 if correct, -EINVAL if incorrect, -EOVERFLOW if buffer overrun.
679  */                                               651  */
680 static int verify_correct_output(const struct     652 static int verify_correct_output(const struct test_sglist *tsgl,
681                                  const char *e    653                                  const char *expected_output,
682                                  unsigned int     654                                  unsigned int len_to_check,
683                                  unsigned int     655                                  unsigned int unchecked_prefix_len,
684                                  bool check_po    656                                  bool check_poison)
685 {                                                 657 {
686         unsigned int i;                           658         unsigned int i;
687                                                   659 
688         for (i = 0; i < tsgl->nents; i++) {       660         for (i = 0; i < tsgl->nents; i++) {
689                 struct scatterlist *sg = &tsgl    661                 struct scatterlist *sg = &tsgl->sgl_ptr[i];
690                 unsigned int len = sg->length;    662                 unsigned int len = sg->length;
691                 unsigned int offset = sg->offs    663                 unsigned int offset = sg->offset;
692                 const char *actual_output;        664                 const char *actual_output;
693                                                   665 
694                 if (unchecked_prefix_len) {       666                 if (unchecked_prefix_len) {
695                         if (unchecked_prefix_l    667                         if (unchecked_prefix_len >= len) {
696                                 unchecked_pref    668                                 unchecked_prefix_len -= len;
697                                 continue;         669                                 continue;
698                         }                         670                         }
699                         offset += unchecked_pr    671                         offset += unchecked_prefix_len;
700                         len -= unchecked_prefi    672                         len -= unchecked_prefix_len;
701                         unchecked_prefix_len =    673                         unchecked_prefix_len = 0;
702                 }                                 674                 }
703                 len = min(len, len_to_check);     675                 len = min(len, len_to_check);
704                 actual_output = page_address(s    676                 actual_output = page_address(sg_page(sg)) + offset;
705                 if (memcmp(expected_output, ac    677                 if (memcmp(expected_output, actual_output, len) != 0)
706                         return -EINVAL;           678                         return -EINVAL;
707                 if (check_poison &&               679                 if (check_poison &&
708                     !testmgr_is_poison(actual_    680                     !testmgr_is_poison(actual_output + len, TESTMGR_POISON_LEN))
709                         return -EOVERFLOW;        681                         return -EOVERFLOW;
710                 len_to_check -= len;              682                 len_to_check -= len;
711                 expected_output += len;           683                 expected_output += len;
712         }                                         684         }
713         if (WARN_ON(len_to_check != 0))           685         if (WARN_ON(len_to_check != 0))
714                 return -EINVAL;                   686                 return -EINVAL;
715         return 0;                                 687         return 0;
716 }                                                 688 }
717                                                   689 
718 static bool is_test_sglist_corrupted(const str    690 static bool is_test_sglist_corrupted(const struct test_sglist *tsgl)
719 {                                                 691 {
720         unsigned int i;                           692         unsigned int i;
721                                                   693 
722         for (i = 0; i < tsgl->nents; i++) {       694         for (i = 0; i < tsgl->nents; i++) {
723                 if (tsgl->sgl[i].page_link !=     695                 if (tsgl->sgl[i].page_link != tsgl->sgl_saved[i].page_link)
724                         return true;              696                         return true;
725                 if (tsgl->sgl[i].offset != tsg    697                 if (tsgl->sgl[i].offset != tsgl->sgl_saved[i].offset)
726                         return true;              698                         return true;
727                 if (tsgl->sgl[i].length != tsg    699                 if (tsgl->sgl[i].length != tsgl->sgl_saved[i].length)
728                         return true;              700                         return true;
729         }                                         701         }
730         return false;                             702         return false;
731 }                                                 703 }
732                                                   704 
733 struct cipher_test_sglists {                      705 struct cipher_test_sglists {
734         struct test_sglist src;                   706         struct test_sglist src;
735         struct test_sglist dst;                   707         struct test_sglist dst;
736 };                                                708 };
737                                                   709 
738 static struct cipher_test_sglists *alloc_ciphe    710 static struct cipher_test_sglists *alloc_cipher_test_sglists(void)
739 {                                                 711 {
740         struct cipher_test_sglists *tsgls;        712         struct cipher_test_sglists *tsgls;
741                                                   713 
742         tsgls = kmalloc(sizeof(*tsgls), GFP_KE    714         tsgls = kmalloc(sizeof(*tsgls), GFP_KERNEL);
743         if (!tsgls)                               715         if (!tsgls)
744                 return NULL;                      716                 return NULL;
745                                                   717 
746         if (init_test_sglist(&tsgls->src) != 0    718         if (init_test_sglist(&tsgls->src) != 0)
747                 goto fail_kfree;                  719                 goto fail_kfree;
748         if (init_test_sglist(&tsgls->dst) != 0    720         if (init_test_sglist(&tsgls->dst) != 0)
749                 goto fail_destroy_src;            721                 goto fail_destroy_src;
750                                                   722 
751         return tsgls;                             723         return tsgls;
752                                                   724 
753 fail_destroy_src:                                 725 fail_destroy_src:
754         destroy_test_sglist(&tsgls->src);         726         destroy_test_sglist(&tsgls->src);
755 fail_kfree:                                       727 fail_kfree:
756         kfree(tsgls);                             728         kfree(tsgls);
757         return NULL;                              729         return NULL;
758 }                                                 730 }
759                                                   731 
760 static void free_cipher_test_sglists(struct ci    732 static void free_cipher_test_sglists(struct cipher_test_sglists *tsgls)
761 {                                                 733 {
762         if (tsgls) {                              734         if (tsgls) {
763                 destroy_test_sglist(&tsgls->sr    735                 destroy_test_sglist(&tsgls->src);
764                 destroy_test_sglist(&tsgls->ds    736                 destroy_test_sglist(&tsgls->dst);
765                 kfree(tsgls);                     737                 kfree(tsgls);
766         }                                         738         }
767 }                                                 739 }
768                                                   740 
769 /* Build the src and dst scatterlists for an s    741 /* Build the src and dst scatterlists for an skcipher or AEAD test */
770 static int build_cipher_test_sglists(struct ci    742 static int build_cipher_test_sglists(struct cipher_test_sglists *tsgls,
771                                      const str    743                                      const struct testvec_config *cfg,
772                                      unsigned     744                                      unsigned int alignmask,
773                                      unsigned     745                                      unsigned int src_total_len,
774                                      unsigned     746                                      unsigned int dst_total_len,
775                                      const str    747                                      const struct kvec *inputs,
776                                      unsigned     748                                      unsigned int nr_inputs)
777 {                                                 749 {
778         struct iov_iter input;                    750         struct iov_iter input;
779         int err;                                  751         int err;
780                                                   752 
781         iov_iter_kvec(&input, ITER_SOURCE, inp !! 753         iov_iter_kvec(&input, WRITE, inputs, nr_inputs, src_total_len);
782         err = build_test_sglist(&tsgls->src, c    754         err = build_test_sglist(&tsgls->src, cfg->src_divs, alignmask,
783                                 cfg->inplace_m !! 755                                 cfg->inplace ?
784                                         max(ds    756                                         max(dst_total_len, src_total_len) :
785                                         src_to    757                                         src_total_len,
786                                 &input, NULL);    758                                 &input, NULL);
787         if (err)                                  759         if (err)
788                 return err;                       760                 return err;
789                                                   761 
790         /*                                     !! 762         if (cfg->inplace) {
791          * In-place crypto operations can use  << 
792          * source and destination (req->src == << 
793          * scatterlists (req->src != req->dst) << 
794          * underlying memory.  Make sure to te << 
795          */                                    << 
796         if (cfg->inplace_mode == INPLACE_ONE_S << 
797                 tsgls->dst.sgl_ptr = tsgls->sr    763                 tsgls->dst.sgl_ptr = tsgls->src.sgl;
798                 tsgls->dst.nents = tsgls->src.    764                 tsgls->dst.nents = tsgls->src.nents;
799                 return 0;                         765                 return 0;
800         }                                         766         }
801         if (cfg->inplace_mode == INPLACE_TWO_S << 
802                 /*                             << 
803                  * For now we keep it simple a << 
804                  * two scatterlists have ident << 
805                  * different entries that spli << 
806                  */                            << 
807                 memcpy(tsgls->dst.sgl, tsgls-> << 
808                        tsgls->src.nents * size << 
809                 memcpy(tsgls->dst.sgl_saved, t << 
810                        tsgls->src.nents * size << 
811                 tsgls->dst.sgl_ptr = tsgls->ds << 
812                 tsgls->dst.nents = tsgls->src. << 
813                 return 0;                      << 
814         }                                      << 
815         /* Out of place */                     << 
816         return build_test_sglist(&tsgls->dst,     767         return build_test_sglist(&tsgls->dst,
817                                  cfg->dst_divs    768                                  cfg->dst_divs[0].proportion_of_total ?
818                                         cfg->d    769                                         cfg->dst_divs : cfg->src_divs,
819                                  alignmask, ds    770                                  alignmask, dst_total_len, NULL, NULL);
820 }                                                 771 }
821                                                   772 
822 /*                                                773 /*
823  * Support for testing passing a misaligned ke    774  * Support for testing passing a misaligned key to setkey():
824  *                                                775  *
825  * If cfg->key_offset is set, copy the key int    776  * If cfg->key_offset is set, copy the key into a new buffer at that offset,
826  * optionally adding alignmask.  Else, just us    777  * optionally adding alignmask.  Else, just use the key directly.
827  */                                               778  */
828 static int prepare_keybuf(const u8 *key, unsig    779 static int prepare_keybuf(const u8 *key, unsigned int ksize,
829                           const struct testvec    780                           const struct testvec_config *cfg,
830                           unsigned int alignma    781                           unsigned int alignmask,
831                           const u8 **keybuf_re    782                           const u8 **keybuf_ret, const u8 **keyptr_ret)
832 {                                                 783 {
833         unsigned int key_offset = cfg->key_off    784         unsigned int key_offset = cfg->key_offset;
834         u8 *keybuf = NULL, *keyptr = (u8 *)key    785         u8 *keybuf = NULL, *keyptr = (u8 *)key;
835                                                   786 
836         if (key_offset != 0) {                    787         if (key_offset != 0) {
837                 if (cfg->key_offset_relative_t    788                 if (cfg->key_offset_relative_to_alignmask)
838                         key_offset += alignmas    789                         key_offset += alignmask;
839                 keybuf = kmalloc(key_offset +     790                 keybuf = kmalloc(key_offset + ksize, GFP_KERNEL);
840                 if (!keybuf)                      791                 if (!keybuf)
841                         return -ENOMEM;           792                         return -ENOMEM;
842                 keyptr = keybuf + key_offset;     793                 keyptr = keybuf + key_offset;
843                 memcpy(keyptr, key, ksize);       794                 memcpy(keyptr, key, ksize);
844         }                                         795         }
845         *keybuf_ret = keybuf;                     796         *keybuf_ret = keybuf;
846         *keyptr_ret = keyptr;                     797         *keyptr_ret = keyptr;
847         return 0;                                 798         return 0;
848 }                                                 799 }
849                                                   800 
850 /*                                             !! 801 /* Like setkey_f(tfm, key, ksize), but sometimes misalign the key */
851  * Like setkey_f(tfm, key, ksize), but sometim << 
852  * In addition, run the setkey function in no- << 
853  */                                            << 
854 #define do_setkey(setkey_f, tfm, key, ksize, c    802 #define do_setkey(setkey_f, tfm, key, ksize, cfg, alignmask)            \
855 ({                                                803 ({                                                                      \
856         const u8 *keybuf, *keyptr;                804         const u8 *keybuf, *keyptr;                                      \
857         int err;                                  805         int err;                                                        \
858                                                   806                                                                         \
859         err = prepare_keybuf((key), (ksize), (    807         err = prepare_keybuf((key), (ksize), (cfg), (alignmask),        \
860                              &keybuf, &keyptr)    808                              &keybuf, &keyptr);                         \
861         if (err == 0) {                           809         if (err == 0) {                                                 \
862                 if ((cfg)->nosimd_setkey)      << 
863                         crypto_disable_simd_fo << 
864                 err = setkey_f((tfm), keyptr,     810                 err = setkey_f((tfm), keyptr, (ksize));                 \
865                 if ((cfg)->nosimd_setkey)      << 
866                         crypto_reenable_simd_f << 
867                 kfree(keybuf);                    811                 kfree(keybuf);                                          \
868         }                                         812         }                                                               \
869         err;                                      813         err;                                                            \
870 })                                                814 })
871                                                   815 
872 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS          816 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
873                                                   817 
874 /*                                             << 
875  * The fuzz tests use prandom instead of the n << 
876  * need cryptographically secure random number << 
877  * performance of these tests, especially if t << 
878  * has been initialized or if they are run on  << 
879  */                                            << 
880                                                << 
881 static inline void init_rnd_state(struct rnd_s << 
882 {                                              << 
883         prandom_seed_state(rng, get_random_u64 << 
884 }                                              << 
885                                                << 
886 static inline u8 prandom_u8(struct rnd_state * << 
887 {                                              << 
888         return prandom_u32_state(rng);         << 
889 }                                              << 
890                                                << 
891 static inline u32 prandom_u32_below(struct rnd << 
892 {                                              << 
893         /*                                     << 
894          * This is slightly biased for non-pow << 
895          * isn't important here.               << 
896          */                                    << 
897         return prandom_u32_state(rng) % ceil;  << 
898 }                                              << 
899                                                << 
900 static inline bool prandom_bool(struct rnd_sta << 
901 {                                              << 
902         return prandom_u32_below(rng, 2);      << 
903 }                                              << 
904                                                << 
905 static inline u32 prandom_u32_inclusive(struct << 
906                                         u32 fl << 
907 {                                              << 
908         return floor + prandom_u32_below(rng,  << 
909 }                                              << 
910                                                << 
911 /* Generate a random length in range [0, max_l    818 /* Generate a random length in range [0, max_len], but prefer smaller values */
912 static unsigned int generate_random_length(str !! 819 static unsigned int generate_random_length(unsigned int max_len)
913                                            uns << 
914 {                                                 820 {
915         unsigned int len = prandom_u32_below(r !! 821         unsigned int len = prandom_u32() % (max_len + 1);
916                                                   822 
917         switch (prandom_u32_below(rng, 4)) {   !! 823         switch (prandom_u32() % 4) {
918         case 0:                                   824         case 0:
919                 len %= 64;                     !! 825                 return len % 64;
920                 break;                         << 
921         case 1:                                   826         case 1:
922                 len %= 256;                    !! 827                 return len % 256;
923                 break;                         << 
924         case 2:                                   828         case 2:
925                 len %= 1024;                   !! 829                 return len % 1024;
926                 break;                         << 
927         default:                                  830         default:
928                 break;                         !! 831                 return len;
929         }                                         832         }
930         if (len && prandom_u32_below(rng, 4) = << 
931                 len = rounddown_pow_of_two(len << 
932         return len;                            << 
933 }                                                 833 }
934                                                   834 
935 /* Flip a random bit in the given nonempty dat    835 /* Flip a random bit in the given nonempty data buffer */
936 static void flip_random_bit(struct rnd_state * !! 836 static void flip_random_bit(u8 *buf, size_t size)
937 {                                                 837 {
938         size_t bitpos;                            838         size_t bitpos;
939                                                   839 
940         bitpos = prandom_u32_below(rng, size * !! 840         bitpos = prandom_u32() % (size * 8);
941         buf[bitpos / 8] ^= 1 << (bitpos % 8);     841         buf[bitpos / 8] ^= 1 << (bitpos % 8);
942 }                                                 842 }
943                                                   843 
944 /* Flip a random byte in the given nonempty da    844 /* Flip a random byte in the given nonempty data buffer */
945 static void flip_random_byte(struct rnd_state  !! 845 static void flip_random_byte(u8 *buf, size_t size)
946 {                                                 846 {
947         buf[prandom_u32_below(rng, size)] ^= 0 !! 847         buf[prandom_u32() % size] ^= 0xff;
948 }                                                 848 }
949                                                   849 
950 /* Sometimes make some random changes to the g    850 /* Sometimes make some random changes to the given nonempty data buffer */
951 static void mutate_buffer(struct rnd_state *rn !! 851 static void mutate_buffer(u8 *buf, size_t size)
952 {                                                 852 {
953         size_t num_flips;                         853         size_t num_flips;
954         size_t i;                                 854         size_t i;
955                                                   855 
956         /* Sometimes flip some bits */            856         /* Sometimes flip some bits */
957         if (prandom_u32_below(rng, 4) == 0) {  !! 857         if (prandom_u32() % 4 == 0) {
958                 num_flips = min_t(size_t, 1 << !! 858                 num_flips = min_t(size_t, 1 << (prandom_u32() % 8), size * 8);
959                                   size * 8);   << 
960                 for (i = 0; i < num_flips; i++    859                 for (i = 0; i < num_flips; i++)
961                         flip_random_bit(rng, b !! 860                         flip_random_bit(buf, size);
962         }                                         861         }
963                                                   862 
964         /* Sometimes flip some bytes */           863         /* Sometimes flip some bytes */
965         if (prandom_u32_below(rng, 4) == 0) {  !! 864         if (prandom_u32() % 4 == 0) {
966                 num_flips = min_t(size_t, 1 << !! 865                 num_flips = min_t(size_t, 1 << (prandom_u32() % 8), size);
967                 for (i = 0; i < num_flips; i++    866                 for (i = 0; i < num_flips; i++)
968                         flip_random_byte(rng,  !! 867                         flip_random_byte(buf, size);
969         }                                         868         }
970 }                                                 869 }
971                                                   870 
972 /* Randomly generate 'count' bytes, but someti    871 /* Randomly generate 'count' bytes, but sometimes make them "interesting" */
973 static void generate_random_bytes(struct rnd_s !! 872 static void generate_random_bytes(u8 *buf, size_t count)
974 {                                                 873 {
975         u8 b;                                     874         u8 b;
976         u8 increment;                             875         u8 increment;
977         size_t i;                                 876         size_t i;
978                                                   877 
979         if (count == 0)                           878         if (count == 0)
980                 return;                           879                 return;
981                                                   880 
982         switch (prandom_u32_below(rng, 8)) { / !! 881         switch (prandom_u32() % 8) { /* Choose a generation strategy */
983         case 0:                                   882         case 0:
984         case 1:                                   883         case 1:
985                 /* All the same byte, plus opt    884                 /* All the same byte, plus optional mutations */
986                 switch (prandom_u32_below(rng, !! 885                 switch (prandom_u32() % 4) {
987                 case 0:                           886                 case 0:
988                         b = 0x00;                 887                         b = 0x00;
989                         break;                    888                         break;
990                 case 1:                           889                 case 1:
991                         b = 0xff;                 890                         b = 0xff;
992                         break;                    891                         break;
993                 default:                          892                 default:
994                         b = prandom_u8(rng);   !! 893                         b = (u8)prandom_u32();
995                         break;                    894                         break;
996                 }                                 895                 }
997                 memset(buf, b, count);            896                 memset(buf, b, count);
998                 mutate_buffer(rng, buf, count) !! 897                 mutate_buffer(buf, count);
999                 break;                            898                 break;
1000         case 2:                                  899         case 2:
1001                 /* Ascending or descending by    900                 /* Ascending or descending bytes, plus optional mutations */
1002                 increment = prandom_u8(rng);  !! 901                 increment = (u8)prandom_u32();
1003                 b = prandom_u8(rng);          !! 902                 b = (u8)prandom_u32();
1004                 for (i = 0; i < count; i++, b    903                 for (i = 0; i < count; i++, b += increment)
1005                         buf[i] = b;              904                         buf[i] = b;
1006                 mutate_buffer(rng, buf, count !! 905                 mutate_buffer(buf, count);
1007                 break;                           906                 break;
1008         default:                                 907         default:
1009                 /* Fully random bytes */         908                 /* Fully random bytes */
1010                 prandom_bytes_state(rng, buf, !! 909                 for (i = 0; i < count; i++)
                                                   >> 910                         buf[i] = (u8)prandom_u32();
1011         }                                        911         }
1012 }                                                912 }
1013                                                  913 
1014 static char *generate_random_sgl_divisions(st !! 914 static char *generate_random_sgl_divisions(struct test_sg_division *divs,
1015                                            st << 
1016                                            si    915                                            size_t max_divs, char *p, char *end,
1017                                            bo    916                                            bool gen_flushes, u32 req_flags)
1018 {                                                917 {
1019         struct test_sg_division *div = divs;     918         struct test_sg_division *div = divs;
1020         unsigned int remaining = TEST_SG_TOTA    919         unsigned int remaining = TEST_SG_TOTAL;
1021                                                  920 
1022         do {                                     921         do {
1023                 unsigned int this_len;           922                 unsigned int this_len;
1024                 const char *flushtype_str;       923                 const char *flushtype_str;
1025                                                  924 
1026                 if (div == &divs[max_divs - 1 !! 925                 if (div == &divs[max_divs - 1] || prandom_u32() % 2 == 0)
1027                         this_len = remaining;    926                         this_len = remaining;
1028                 else if (prandom_u32_below(rn << 
1029                         this_len = (remaining << 
1030                 else                             927                 else
1031                         this_len = prandom_u3 !! 928                         this_len = 1 + (prandom_u32() % remaining);
1032                 div->proportion_of_total = th    929                 div->proportion_of_total = this_len;
1033                                                  930 
1034                 if (prandom_u32_below(rng, 4) !! 931                 if (prandom_u32() % 4 == 0)
1035                         div->offset = prandom !! 932                         div->offset = (PAGE_SIZE - 128) + (prandom_u32() % 128);
1036                                               !! 933                 else if (prandom_u32() % 2 == 0)
1037                                               !! 934                         div->offset = prandom_u32() % 32;
1038                 else if (prandom_bool(rng))   << 
1039                         div->offset = prandom << 
1040                 else                             935                 else
1041                         div->offset = prandom !! 936                         div->offset = prandom_u32() % PAGE_SIZE;
1042                 if (prandom_u32_below(rng, 8) !! 937                 if (prandom_u32() % 8 == 0)
1043                         div->offset_relative_    938                         div->offset_relative_to_alignmask = true;
1044                                                  939 
1045                 div->flush_type = FLUSH_TYPE_    940                 div->flush_type = FLUSH_TYPE_NONE;
1046                 if (gen_flushes) {               941                 if (gen_flushes) {
1047                         switch (prandom_u32_b !! 942                         switch (prandom_u32() % 4) {
1048                         case 0:                  943                         case 0:
1049                                 div->flush_ty    944                                 div->flush_type = FLUSH_TYPE_REIMPORT;
1050                                 break;           945                                 break;
1051                         case 1:                  946                         case 1:
1052                                 div->flush_ty    947                                 div->flush_type = FLUSH_TYPE_FLUSH;
1053                                 break;           948                                 break;
1054                         }                        949                         }
1055                 }                                950                 }
1056                                                  951 
1057                 if (div->flush_type != FLUSH_    952                 if (div->flush_type != FLUSH_TYPE_NONE &&
1058                     !(req_flags & CRYPTO_TFM_    953                     !(req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) &&
1059                     prandom_bool(rng))        !! 954                     prandom_u32() % 2 == 0)
1060                         div->nosimd = true;      955                         div->nosimd = true;
1061                                                  956 
1062                 switch (div->flush_type) {       957                 switch (div->flush_type) {
1063                 case FLUSH_TYPE_FLUSH:           958                 case FLUSH_TYPE_FLUSH:
1064                         if (div->nosimd)         959                         if (div->nosimd)
1065                                 flushtype_str    960                                 flushtype_str = "<flush,nosimd>";
1066                         else                     961                         else
1067                                 flushtype_str    962                                 flushtype_str = "<flush>";
1068                         break;                   963                         break;
1069                 case FLUSH_TYPE_REIMPORT:        964                 case FLUSH_TYPE_REIMPORT:
1070                         if (div->nosimd)         965                         if (div->nosimd)
1071                                 flushtype_str    966                                 flushtype_str = "<reimport,nosimd>";
1072                         else                     967                         else
1073                                 flushtype_str    968                                 flushtype_str = "<reimport>";
1074                         break;                   969                         break;
1075                 default:                         970                 default:
1076                         flushtype_str = "";      971                         flushtype_str = "";
1077                         break;                   972                         break;
1078                 }                                973                 }
1079                                                  974 
1080                 BUILD_BUG_ON(TEST_SG_TOTAL !=    975                 BUILD_BUG_ON(TEST_SG_TOTAL != 10000); /* for "%u.%u%%" */
1081                 p += scnprintf(p, end - p, "%    976                 p += scnprintf(p, end - p, "%s%u.%u%%@%s+%u%s", flushtype_str,
1082                                this_len / 100    977                                this_len / 100, this_len % 100,
1083                                div->offset_re    978                                div->offset_relative_to_alignmask ?
1084                                         "alig    979                                         "alignmask" : "",
1085                                div->offset, t    980                                div->offset, this_len == remaining ? "" : ", ");
1086                 remaining -= this_len;           981                 remaining -= this_len;
1087                 div++;                           982                 div++;
1088         } while (remaining);                     983         } while (remaining);
1089                                                  984 
1090         return p;                                985         return p;
1091 }                                                986 }
1092                                                  987 
1093 /* Generate a random testvec_config for fuzz     988 /* Generate a random testvec_config for fuzz testing */
1094 static void generate_random_testvec_config(st !! 989 static void generate_random_testvec_config(struct testvec_config *cfg,
1095                                            st << 
1096                                            ch    990                                            char *name, size_t max_namelen)
1097 {                                                991 {
1098         char *p = name;                          992         char *p = name;
1099         char * const end = name + max_namelen    993         char * const end = name + max_namelen;
1100                                                  994 
1101         memset(cfg, 0, sizeof(*cfg));            995         memset(cfg, 0, sizeof(*cfg));
1102                                                  996 
1103         cfg->name = name;                        997         cfg->name = name;
1104                                                  998 
1105         p += scnprintf(p, end - p, "random:")    999         p += scnprintf(p, end - p, "random:");
1106                                                  1000 
1107         switch (prandom_u32_below(rng, 4)) {  !! 1001         if (prandom_u32() % 2 == 0) {
1108         case 0:                               !! 1002                 cfg->inplace = true;
1109         case 1:                               !! 1003                 p += scnprintf(p, end - p, " inplace");
1110                 cfg->inplace_mode = OUT_OF_PL << 
1111                 break;                        << 
1112         case 2:                               << 
1113                 cfg->inplace_mode = INPLACE_O << 
1114                 p += scnprintf(p, end - p, "  << 
1115                 break;                        << 
1116         default:                              << 
1117                 cfg->inplace_mode = INPLACE_T << 
1118                 p += scnprintf(p, end - p, "  << 
1119                 break;                        << 
1120         }                                        1004         }
1121                                                  1005 
1122         if (prandom_bool(rng)) {              !! 1006         if (prandom_u32() % 2 == 0) {
1123                 cfg->req_flags |= CRYPTO_TFM_    1007                 cfg->req_flags |= CRYPTO_TFM_REQ_MAY_SLEEP;
1124                 p += scnprintf(p, end - p, "     1008                 p += scnprintf(p, end - p, " may_sleep");
1125         }                                        1009         }
1126                                                  1010 
1127         switch (prandom_u32_below(rng, 4)) {  !! 1011         switch (prandom_u32() % 4) {
1128         case 0:                                  1012         case 0:
1129                 cfg->finalization_type = FINA    1013                 cfg->finalization_type = FINALIZATION_TYPE_FINAL;
1130                 p += scnprintf(p, end - p, "     1014                 p += scnprintf(p, end - p, " use_final");
1131                 break;                           1015                 break;
1132         case 1:                                  1016         case 1:
1133                 cfg->finalization_type = FINA    1017                 cfg->finalization_type = FINALIZATION_TYPE_FINUP;
1134                 p += scnprintf(p, end - p, "     1018                 p += scnprintf(p, end - p, " use_finup");
1135                 break;                           1019                 break;
1136         default:                                 1020         default:
1137                 cfg->finalization_type = FINA    1021                 cfg->finalization_type = FINALIZATION_TYPE_DIGEST;
1138                 p += scnprintf(p, end - p, "     1022                 p += scnprintf(p, end - p, " use_digest");
1139                 break;                           1023                 break;
1140         }                                        1024         }
1141                                                  1025 
1142         if (!(cfg->req_flags & CRYPTO_TFM_REQ !! 1026         if (!(cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) &&
1143                 if (prandom_bool(rng)) {      !! 1027             prandom_u32() % 2 == 0) {
1144                         cfg->nosimd = true;   !! 1028                 cfg->nosimd = true;
1145                         p += scnprintf(p, end !! 1029                 p += scnprintf(p, end - p, " nosimd");
1146                 }                             << 
1147                 if (prandom_bool(rng)) {      << 
1148                         cfg->nosimd_setkey =  << 
1149                         p += scnprintf(p, end << 
1150                 }                             << 
1151         }                                        1030         }
1152                                                  1031 
1153         p += scnprintf(p, end - p, " src_divs    1032         p += scnprintf(p, end - p, " src_divs=[");
1154         p = generate_random_sgl_divisions(rng !! 1033         p = generate_random_sgl_divisions(cfg->src_divs,
1155                                           ARR    1034                                           ARRAY_SIZE(cfg->src_divs), p, end,
1156                                           (cf    1035                                           (cfg->finalization_type !=
1157                                            FI    1036                                            FINALIZATION_TYPE_DIGEST),
1158                                           cfg    1037                                           cfg->req_flags);
1159         p += scnprintf(p, end - p, "]");         1038         p += scnprintf(p, end - p, "]");
1160                                                  1039 
1161         if (cfg->inplace_mode == OUT_OF_PLACE !! 1040         if (!cfg->inplace && prandom_u32() % 2 == 0) {
1162                 p += scnprintf(p, end - p, "     1041                 p += scnprintf(p, end - p, " dst_divs=[");
1163                 p = generate_random_sgl_divis !! 1042                 p = generate_random_sgl_divisions(cfg->dst_divs,
1164                                                  1043                                                   ARRAY_SIZE(cfg->dst_divs),
1165                                                  1044                                                   p, end, false,
1166                                                  1045                                                   cfg->req_flags);
1167                 p += scnprintf(p, end - p, "]    1046                 p += scnprintf(p, end - p, "]");
1168         }                                        1047         }
1169                                                  1048 
1170         if (prandom_bool(rng)) {              !! 1049         if (prandom_u32() % 2 == 0) {
1171                 cfg->iv_offset = prandom_u32_ !! 1050                 cfg->iv_offset = 1 + (prandom_u32() % MAX_ALGAPI_ALIGNMASK);
1172                                               << 
1173                 p += scnprintf(p, end - p, "     1051                 p += scnprintf(p, end - p, " iv_offset=%u", cfg->iv_offset);
1174         }                                        1052         }
1175                                                  1053 
1176         if (prandom_bool(rng)) {              !! 1054         if (prandom_u32() % 2 == 0) {
1177                 cfg->key_offset = prandom_u32 !! 1055                 cfg->key_offset = 1 + (prandom_u32() % MAX_ALGAPI_ALIGNMASK);
1178                                               << 
1179                 p += scnprintf(p, end - p, "     1056                 p += scnprintf(p, end - p, " key_offset=%u", cfg->key_offset);
1180         }                                        1057         }
1181                                                  1058 
1182         WARN_ON_ONCE(!valid_testvec_config(cf    1059         WARN_ON_ONCE(!valid_testvec_config(cfg));
1183 }                                                1060 }
1184                                                  1061 
1185 static void crypto_disable_simd_for_test(void    1062 static void crypto_disable_simd_for_test(void)
1186 {                                                1063 {
1187         migrate_disable();                    !! 1064         preempt_disable();
1188         __this_cpu_write(crypto_simd_disabled    1065         __this_cpu_write(crypto_simd_disabled_for_test, true);
1189 }                                                1066 }
1190                                                  1067 
1191 static void crypto_reenable_simd_for_test(voi    1068 static void crypto_reenable_simd_for_test(void)
1192 {                                                1069 {
1193         __this_cpu_write(crypto_simd_disabled    1070         __this_cpu_write(crypto_simd_disabled_for_test, false);
1194         migrate_enable();                     !! 1071         preempt_enable();
1195 }                                                1072 }
1196                                                  1073 
1197 /*                                               1074 /*
1198  * Given an algorithm name, build the name of    1075  * Given an algorithm name, build the name of the generic implementation of that
1199  * algorithm, assuming the usual naming conve    1076  * algorithm, assuming the usual naming convention.  Specifically, this appends
1200  * "-generic" to every part of the name that     1077  * "-generic" to every part of the name that is not a template name.  Examples:
1201  *                                               1078  *
1202  *      aes => aes-generic                       1079  *      aes => aes-generic
1203  *      cbc(aes) => cbc(aes-generic)             1080  *      cbc(aes) => cbc(aes-generic)
1204  *      cts(cbc(aes)) => cts(cbc(aes-generic)    1081  *      cts(cbc(aes)) => cts(cbc(aes-generic))
1205  *      rfc7539(chacha20,poly1305) => rfc7539    1082  *      rfc7539(chacha20,poly1305) => rfc7539(chacha20-generic,poly1305-generic)
1206  *                                               1083  *
1207  * Return: 0 on success, or -ENAMETOOLONG if     1084  * Return: 0 on success, or -ENAMETOOLONG if the generic name would be too long
1208  */                                              1085  */
1209 static int build_generic_driver_name(const ch    1086 static int build_generic_driver_name(const char *algname,
1210                                      char dri    1087                                      char driver_name[CRYPTO_MAX_ALG_NAME])
1211 {                                                1088 {
1212         const char *in = algname;                1089         const char *in = algname;
1213         char *out = driver_name;                 1090         char *out = driver_name;
1214         size_t len = strlen(algname);            1091         size_t len = strlen(algname);
1215                                                  1092 
1216         if (len >= CRYPTO_MAX_ALG_NAME)          1093         if (len >= CRYPTO_MAX_ALG_NAME)
1217                 goto too_long;                   1094                 goto too_long;
1218         do {                                     1095         do {
1219                 const char *in_saved = in;       1096                 const char *in_saved = in;
1220                                                  1097 
1221                 while (*in && *in != '(' && *    1098                 while (*in && *in != '(' && *in != ')' && *in != ',')
1222                         *out++ = *in++;          1099                         *out++ = *in++;
1223                 if (*in != '(' && in > in_sav    1100                 if (*in != '(' && in > in_saved) {
1224                         len += 8;                1101                         len += 8;
1225                         if (len >= CRYPTO_MAX    1102                         if (len >= CRYPTO_MAX_ALG_NAME)
1226                                 goto too_long    1103                                 goto too_long;
1227                         memcpy(out, "-generic    1104                         memcpy(out, "-generic", 8);
1228                         out += 8;                1105                         out += 8;
1229                 }                                1106                 }
1230         } while ((*out++ = *in++) != '\0');      1107         } while ((*out++ = *in++) != '\0');
1231         return 0;                                1108         return 0;
1232                                                  1109 
1233 too_long:                                        1110 too_long:
1234         pr_err("alg: generic driver name for     1111         pr_err("alg: generic driver name for \"%s\" would be too long\n",
1235                algname);                         1112                algname);
1236         return -ENAMETOOLONG;                    1113         return -ENAMETOOLONG;
1237 }                                                1114 }
1238 #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS *    1115 #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
1239 static void crypto_disable_simd_for_test(void    1116 static void crypto_disable_simd_for_test(void)
1240 {                                                1117 {
1241 }                                                1118 }
1242                                                  1119 
1243 static void crypto_reenable_simd_for_test(voi    1120 static void crypto_reenable_simd_for_test(void)
1244 {                                                1121 {
1245 }                                                1122 }
1246 #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS     1123 #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
1247                                                  1124 
1248 static int build_hash_sglist(struct test_sgli    1125 static int build_hash_sglist(struct test_sglist *tsgl,
1249                              const struct has    1126                              const struct hash_testvec *vec,
1250                              const struct tes    1127                              const struct testvec_config *cfg,
1251                              unsigned int ali    1128                              unsigned int alignmask,
1252                              const struct tes    1129                              const struct test_sg_division *divs[XBUFSIZE])
1253 {                                                1130 {
1254         struct kvec kv;                          1131         struct kvec kv;
1255         struct iov_iter input;                   1132         struct iov_iter input;
1256                                                  1133 
1257         kv.iov_base = (void *)vec->plaintext;    1134         kv.iov_base = (void *)vec->plaintext;
1258         kv.iov_len = vec->psize;                 1135         kv.iov_len = vec->psize;
1259         iov_iter_kvec(&input, ITER_SOURCE, &k !! 1136         iov_iter_kvec(&input, WRITE, &kv, 1, vec->psize);
1260         return build_test_sglist(tsgl, cfg->s    1137         return build_test_sglist(tsgl, cfg->src_divs, alignmask, vec->psize,
1261                                  &input, divs    1138                                  &input, divs);
1262 }                                                1139 }
1263                                                  1140 
1264 static int check_hash_result(const char *type    1141 static int check_hash_result(const char *type,
1265                              const u8 *result    1142                              const u8 *result, unsigned int digestsize,
1266                              const struct has    1143                              const struct hash_testvec *vec,
1267                              const char *vec_    1144                              const char *vec_name,
1268                              const char *driv    1145                              const char *driver,
1269                              const struct tes    1146                              const struct testvec_config *cfg)
1270 {                                                1147 {
1271         if (memcmp(result, vec->digest, diges    1148         if (memcmp(result, vec->digest, digestsize) != 0) {
1272                 pr_err("alg: %s: %s test fail    1149                 pr_err("alg: %s: %s test failed (wrong result) on test vector %s, cfg=\"%s\"\n",
1273                        type, driver, vec_name    1150                        type, driver, vec_name, cfg->name);
1274                 return -EINVAL;                  1151                 return -EINVAL;
1275         }                                        1152         }
1276         if (!testmgr_is_poison(&result[digest    1153         if (!testmgr_is_poison(&result[digestsize], TESTMGR_POISON_LEN)) {
1277                 pr_err("alg: %s: %s overran r    1154                 pr_err("alg: %s: %s overran result buffer on test vector %s, cfg=\"%s\"\n",
1278                        type, driver, vec_name    1155                        type, driver, vec_name, cfg->name);
1279                 return -EOVERFLOW;               1156                 return -EOVERFLOW;
1280         }                                        1157         }
1281         return 0;                                1158         return 0;
1282 }                                                1159 }
1283                                                  1160 
1284 static inline int check_shash_op(const char *    1161 static inline int check_shash_op(const char *op, int err,
1285                                  const char *    1162                                  const char *driver, const char *vec_name,
1286                                  const struct    1163                                  const struct testvec_config *cfg)
1287 {                                                1164 {
1288         if (err)                                 1165         if (err)
1289                 pr_err("alg: shash: %s %s() f    1166                 pr_err("alg: shash: %s %s() failed with err %d on test vector %s, cfg=\"%s\"\n",
1290                        driver, op, err, vec_n    1167                        driver, op, err, vec_name, cfg->name);
1291         return err;                              1168         return err;
1292 }                                                1169 }
1293                                                  1170 
1294 /* Test one hash test vector in one configura    1171 /* Test one hash test vector in one configuration, using the shash API */
1295 static int test_shash_vec_cfg(const struct ha    1172 static int test_shash_vec_cfg(const struct hash_testvec *vec,
1296                               const char *vec    1173                               const char *vec_name,
1297                               const struct te    1174                               const struct testvec_config *cfg,
1298                               struct shash_de    1175                               struct shash_desc *desc,
1299                               struct test_sgl    1176                               struct test_sglist *tsgl,
1300                               u8 *hashstate)     1177                               u8 *hashstate)
1301 {                                                1178 {
1302         struct crypto_shash *tfm = desc->tfm;    1179         struct crypto_shash *tfm = desc->tfm;
                                                   >> 1180         const unsigned int alignmask = crypto_shash_alignmask(tfm);
1303         const unsigned int digestsize = crypt    1181         const unsigned int digestsize = crypto_shash_digestsize(tfm);
1304         const unsigned int statesize = crypto    1182         const unsigned int statesize = crypto_shash_statesize(tfm);
1305         const char *driver = crypto_shash_dri    1183         const char *driver = crypto_shash_driver_name(tfm);
1306         const struct test_sg_division *divs[X    1184         const struct test_sg_division *divs[XBUFSIZE];
1307         unsigned int i;                          1185         unsigned int i;
1308         u8 result[HASH_MAX_DIGESTSIZE + TESTM    1186         u8 result[HASH_MAX_DIGESTSIZE + TESTMGR_POISON_LEN];
1309         int err;                                 1187         int err;
1310                                                  1188 
1311         /* Set the key, if specified */          1189         /* Set the key, if specified */
1312         if (vec->ksize) {                        1190         if (vec->ksize) {
1313                 err = do_setkey(crypto_shash_    1191                 err = do_setkey(crypto_shash_setkey, tfm, vec->key, vec->ksize,
1314                                 cfg, 0);      !! 1192                                 cfg, alignmask);
1315                 if (err) {                       1193                 if (err) {
1316                         if (err == vec->setke    1194                         if (err == vec->setkey_error)
1317                                 return 0;        1195                                 return 0;
1318                         pr_err("alg: shash: %    1196                         pr_err("alg: shash: %s setkey failed on test vector %s; expected_error=%d, actual_error=%d, flags=%#x\n",
1319                                driver, vec_na    1197                                driver, vec_name, vec->setkey_error, err,
1320                                crypto_shash_g    1198                                crypto_shash_get_flags(tfm));
1321                         return err;              1199                         return err;
1322                 }                                1200                 }
1323                 if (vec->setkey_error) {         1201                 if (vec->setkey_error) {
1324                         pr_err("alg: shash: %    1202                         pr_err("alg: shash: %s setkey unexpectedly succeeded on test vector %s; expected_error=%d\n",
1325                                driver, vec_na    1203                                driver, vec_name, vec->setkey_error);
1326                         return -EINVAL;          1204                         return -EINVAL;
1327                 }                                1205                 }
1328         }                                        1206         }
1329                                                  1207 
1330         /* Build the scatterlist for the sour    1208         /* Build the scatterlist for the source data */
1331         err = build_hash_sglist(tsgl, vec, cf !! 1209         err = build_hash_sglist(tsgl, vec, cfg, alignmask, divs);
1332         if (err) {                               1210         if (err) {
1333                 pr_err("alg: shash: %s: error    1211                 pr_err("alg: shash: %s: error preparing scatterlist for test vector %s, cfg=\"%s\"\n",
1334                        driver, vec_name, cfg-    1212                        driver, vec_name, cfg->name);
1335                 return err;                      1213                 return err;
1336         }                                        1214         }
1337                                                  1215 
1338         /* Do the actual hashing */              1216         /* Do the actual hashing */
1339                                                  1217 
1340         testmgr_poison(desc->__ctx, crypto_sh    1218         testmgr_poison(desc->__ctx, crypto_shash_descsize(tfm));
1341         testmgr_poison(result, digestsize + T    1219         testmgr_poison(result, digestsize + TESTMGR_POISON_LEN);
1342                                                  1220 
1343         if (cfg->finalization_type == FINALIZ    1221         if (cfg->finalization_type == FINALIZATION_TYPE_DIGEST ||
1344             vec->digest_error) {                 1222             vec->digest_error) {
1345                 /* Just using digest() */        1223                 /* Just using digest() */
1346                 if (tsgl->nents != 1)            1224                 if (tsgl->nents != 1)
1347                         return 0;                1225                         return 0;
1348                 if (cfg->nosimd)                 1226                 if (cfg->nosimd)
1349                         crypto_disable_simd_f    1227                         crypto_disable_simd_for_test();
1350                 err = crypto_shash_digest(des    1228                 err = crypto_shash_digest(desc, sg_virt(&tsgl->sgl[0]),
1351                                           tsg    1229                                           tsgl->sgl[0].length, result);
1352                 if (cfg->nosimd)                 1230                 if (cfg->nosimd)
1353                         crypto_reenable_simd_    1231                         crypto_reenable_simd_for_test();
1354                 if (err) {                       1232                 if (err) {
1355                         if (err == vec->diges    1233                         if (err == vec->digest_error)
1356                                 return 0;        1234                                 return 0;
1357                         pr_err("alg: shash: %    1235                         pr_err("alg: shash: %s digest() failed on test vector %s; expected_error=%d, actual_error=%d, cfg=\"%s\"\n",
1358                                driver, vec_na    1236                                driver, vec_name, vec->digest_error, err,
1359                                cfg->name);       1237                                cfg->name);
1360                         return err;              1238                         return err;
1361                 }                                1239                 }
1362                 if (vec->digest_error) {         1240                 if (vec->digest_error) {
1363                         pr_err("alg: shash: %    1241                         pr_err("alg: shash: %s digest() unexpectedly succeeded on test vector %s; expected_error=%d, cfg=\"%s\"\n",
1364                                driver, vec_na    1242                                driver, vec_name, vec->digest_error, cfg->name);
1365                         return -EINVAL;          1243                         return -EINVAL;
1366                 }                                1244                 }
1367                 goto result_ready;               1245                 goto result_ready;
1368         }                                        1246         }
1369                                                  1247 
1370         /* Using init(), zero or more update(    1248         /* Using init(), zero or more update(), then final() or finup() */
1371                                                  1249 
1372         if (cfg->nosimd)                         1250         if (cfg->nosimd)
1373                 crypto_disable_simd_for_test(    1251                 crypto_disable_simd_for_test();
1374         err = crypto_shash_init(desc);           1252         err = crypto_shash_init(desc);
1375         if (cfg->nosimd)                         1253         if (cfg->nosimd)
1376                 crypto_reenable_simd_for_test    1254                 crypto_reenable_simd_for_test();
1377         err = check_shash_op("init", err, dri    1255         err = check_shash_op("init", err, driver, vec_name, cfg);
1378         if (err)                                 1256         if (err)
1379                 return err;                      1257                 return err;
1380                                                  1258 
1381         for (i = 0; i < tsgl->nents; i++) {      1259         for (i = 0; i < tsgl->nents; i++) {
1382                 if (i + 1 == tsgl->nents &&      1260                 if (i + 1 == tsgl->nents &&
1383                     cfg->finalization_type ==    1261                     cfg->finalization_type == FINALIZATION_TYPE_FINUP) {
1384                         if (divs[i]->nosimd)     1262                         if (divs[i]->nosimd)
1385                                 crypto_disabl    1263                                 crypto_disable_simd_for_test();
1386                         err = crypto_shash_fi    1264                         err = crypto_shash_finup(desc, sg_virt(&tsgl->sgl[i]),
1387                                                  1265                                                  tsgl->sgl[i].length, result);
1388                         if (divs[i]->nosimd)     1266                         if (divs[i]->nosimd)
1389                                 crypto_reenab    1267                                 crypto_reenable_simd_for_test();
1390                         err = check_shash_op(    1268                         err = check_shash_op("finup", err, driver, vec_name,
1391                                                  1269                                              cfg);
1392                         if (err)                 1270                         if (err)
1393                                 return err;      1271                                 return err;
1394                         goto result_ready;       1272                         goto result_ready;
1395                 }                                1273                 }
1396                 if (divs[i]->nosimd)             1274                 if (divs[i]->nosimd)
1397                         crypto_disable_simd_f    1275                         crypto_disable_simd_for_test();
1398                 err = crypto_shash_update(des    1276                 err = crypto_shash_update(desc, sg_virt(&tsgl->sgl[i]),
1399                                           tsg    1277                                           tsgl->sgl[i].length);
1400                 if (divs[i]->nosimd)             1278                 if (divs[i]->nosimd)
1401                         crypto_reenable_simd_    1279                         crypto_reenable_simd_for_test();
1402                 err = check_shash_op("update"    1280                 err = check_shash_op("update", err, driver, vec_name, cfg);
1403                 if (err)                         1281                 if (err)
1404                         return err;              1282                         return err;
1405                 if (divs[i]->flush_type == FL    1283                 if (divs[i]->flush_type == FLUSH_TYPE_REIMPORT) {
1406                         /* Test ->export() an    1284                         /* Test ->export() and ->import() */
1407                         testmgr_poison(hashst    1285                         testmgr_poison(hashstate + statesize,
1408                                        TESTMG    1286                                        TESTMGR_POISON_LEN);
1409                         err = crypto_shash_ex    1287                         err = crypto_shash_export(desc, hashstate);
1410                         err = check_shash_op(    1288                         err = check_shash_op("export", err, driver, vec_name,
1411                                                  1289                                              cfg);
1412                         if (err)                 1290                         if (err)
1413                                 return err;      1291                                 return err;
1414                         if (!testmgr_is_poiso    1292                         if (!testmgr_is_poison(hashstate + statesize,
1415                                                  1293                                                TESTMGR_POISON_LEN)) {
1416                                 pr_err("alg:     1294                                 pr_err("alg: shash: %s export() overran state buffer on test vector %s, cfg=\"%s\"\n",
1417                                        driver    1295                                        driver, vec_name, cfg->name);
1418                                 return -EOVER    1296                                 return -EOVERFLOW;
1419                         }                        1297                         }
1420                         testmgr_poison(desc->    1298                         testmgr_poison(desc->__ctx, crypto_shash_descsize(tfm));
1421                         err = crypto_shash_im    1299                         err = crypto_shash_import(desc, hashstate);
1422                         err = check_shash_op(    1300                         err = check_shash_op("import", err, driver, vec_name,
1423                                                  1301                                              cfg);
1424                         if (err)                 1302                         if (err)
1425                                 return err;      1303                                 return err;
1426                 }                                1304                 }
1427         }                                        1305         }
1428                                                  1306 
1429         if (cfg->nosimd)                         1307         if (cfg->nosimd)
1430                 crypto_disable_simd_for_test(    1308                 crypto_disable_simd_for_test();
1431         err = crypto_shash_final(desc, result    1309         err = crypto_shash_final(desc, result);
1432         if (cfg->nosimd)                         1310         if (cfg->nosimd)
1433                 crypto_reenable_simd_for_test    1311                 crypto_reenable_simd_for_test();
1434         err = check_shash_op("final", err, dr    1312         err = check_shash_op("final", err, driver, vec_name, cfg);
1435         if (err)                                 1313         if (err)
1436                 return err;                      1314                 return err;
1437 result_ready:                                    1315 result_ready:
1438         return check_hash_result("shash", res    1316         return check_hash_result("shash", result, digestsize, vec, vec_name,
1439                                  driver, cfg)    1317                                  driver, cfg);
1440 }                                                1318 }
1441                                                  1319 
1442 static int do_ahash_op(int (*op)(struct ahash    1320 static int do_ahash_op(int (*op)(struct ahash_request *req),
1443                        struct ahash_request *    1321                        struct ahash_request *req,
1444                        struct crypto_wait *wa    1322                        struct crypto_wait *wait, bool nosimd)
1445 {                                                1323 {
1446         int err;                                 1324         int err;
1447                                                  1325 
1448         if (nosimd)                              1326         if (nosimd)
1449                 crypto_disable_simd_for_test(    1327                 crypto_disable_simd_for_test();
1450                                                  1328 
1451         err = op(req);                           1329         err = op(req);
1452                                                  1330 
1453         if (nosimd)                              1331         if (nosimd)
1454                 crypto_reenable_simd_for_test    1332                 crypto_reenable_simd_for_test();
1455                                                  1333 
1456         return crypto_wait_req(err, wait);       1334         return crypto_wait_req(err, wait);
1457 }                                                1335 }
1458                                                  1336 
1459 static int check_nonfinal_ahash_op(const char    1337 static int check_nonfinal_ahash_op(const char *op, int err,
1460                                    u8 *result    1338                                    u8 *result, unsigned int digestsize,
1461                                    const char    1339                                    const char *driver, const char *vec_name,
1462                                    const stru    1340                                    const struct testvec_config *cfg)
1463 {                                                1341 {
1464         if (err) {                               1342         if (err) {
1465                 pr_err("alg: ahash: %s %s() f    1343                 pr_err("alg: ahash: %s %s() failed with err %d on test vector %s, cfg=\"%s\"\n",
1466                        driver, op, err, vec_n    1344                        driver, op, err, vec_name, cfg->name);
1467                 return err;                      1345                 return err;
1468         }                                        1346         }
1469         if (!testmgr_is_poison(result, digest    1347         if (!testmgr_is_poison(result, digestsize)) {
1470                 pr_err("alg: ahash: %s %s() u    1348                 pr_err("alg: ahash: %s %s() used result buffer on test vector %s, cfg=\"%s\"\n",
1471                        driver, op, vec_name,     1349                        driver, op, vec_name, cfg->name);
1472                 return -EINVAL;                  1350                 return -EINVAL;
1473         }                                        1351         }
1474         return 0;                                1352         return 0;
1475 }                                                1353 }
1476                                                  1354 
1477 /* Test one hash test vector in one configura    1355 /* Test one hash test vector in one configuration, using the ahash API */
1478 static int test_ahash_vec_cfg(const struct ha    1356 static int test_ahash_vec_cfg(const struct hash_testvec *vec,
1479                               const char *vec    1357                               const char *vec_name,
1480                               const struct te    1358                               const struct testvec_config *cfg,
1481                               struct ahash_re    1359                               struct ahash_request *req,
1482                               struct test_sgl    1360                               struct test_sglist *tsgl,
1483                               u8 *hashstate)     1361                               u8 *hashstate)
1484 {                                                1362 {
1485         struct crypto_ahash *tfm = crypto_aha    1363         struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
                                                   >> 1364         const unsigned int alignmask = crypto_ahash_alignmask(tfm);
1486         const unsigned int digestsize = crypt    1365         const unsigned int digestsize = crypto_ahash_digestsize(tfm);
1487         const unsigned int statesize = crypto    1366         const unsigned int statesize = crypto_ahash_statesize(tfm);
1488         const char *driver = crypto_ahash_dri    1367         const char *driver = crypto_ahash_driver_name(tfm);
1489         const u32 req_flags = CRYPTO_TFM_REQ_    1368         const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
1490         const struct test_sg_division *divs[X    1369         const struct test_sg_division *divs[XBUFSIZE];
1491         DECLARE_CRYPTO_WAIT(wait);               1370         DECLARE_CRYPTO_WAIT(wait);
1492         unsigned int i;                          1371         unsigned int i;
1493         struct scatterlist *pending_sgl;         1372         struct scatterlist *pending_sgl;
1494         unsigned int pending_len;                1373         unsigned int pending_len;
1495         u8 result[HASH_MAX_DIGESTSIZE + TESTM    1374         u8 result[HASH_MAX_DIGESTSIZE + TESTMGR_POISON_LEN];
1496         int err;                                 1375         int err;
1497                                                  1376 
1498         /* Set the key, if specified */          1377         /* Set the key, if specified */
1499         if (vec->ksize) {                        1378         if (vec->ksize) {
1500                 err = do_setkey(crypto_ahash_    1379                 err = do_setkey(crypto_ahash_setkey, tfm, vec->key, vec->ksize,
1501                                 cfg, 0);      !! 1380                                 cfg, alignmask);
1502                 if (err) {                       1381                 if (err) {
1503                         if (err == vec->setke    1382                         if (err == vec->setkey_error)
1504                                 return 0;        1383                                 return 0;
1505                         pr_err("alg: ahash: %    1384                         pr_err("alg: ahash: %s setkey failed on test vector %s; expected_error=%d, actual_error=%d, flags=%#x\n",
1506                                driver, vec_na    1385                                driver, vec_name, vec->setkey_error, err,
1507                                crypto_ahash_g    1386                                crypto_ahash_get_flags(tfm));
1508                         return err;              1387                         return err;
1509                 }                                1388                 }
1510                 if (vec->setkey_error) {         1389                 if (vec->setkey_error) {
1511                         pr_err("alg: ahash: %    1390                         pr_err("alg: ahash: %s setkey unexpectedly succeeded on test vector %s; expected_error=%d\n",
1512                                driver, vec_na    1391                                driver, vec_name, vec->setkey_error);
1513                         return -EINVAL;          1392                         return -EINVAL;
1514                 }                                1393                 }
1515         }                                        1394         }
1516                                                  1395 
1517         /* Build the scatterlist for the sour    1396         /* Build the scatterlist for the source data */
1518         err = build_hash_sglist(tsgl, vec, cf !! 1397         err = build_hash_sglist(tsgl, vec, cfg, alignmask, divs);
1519         if (err) {                               1398         if (err) {
1520                 pr_err("alg: ahash: %s: error    1399                 pr_err("alg: ahash: %s: error preparing scatterlist for test vector %s, cfg=\"%s\"\n",
1521                        driver, vec_name, cfg-    1400                        driver, vec_name, cfg->name);
1522                 return err;                      1401                 return err;
1523         }                                        1402         }
1524                                                  1403 
1525         /* Do the actual hashing */              1404         /* Do the actual hashing */
1526                                                  1405 
1527         testmgr_poison(req->__ctx, crypto_aha    1406         testmgr_poison(req->__ctx, crypto_ahash_reqsize(tfm));
1528         testmgr_poison(result, digestsize + T    1407         testmgr_poison(result, digestsize + TESTMGR_POISON_LEN);
1529                                                  1408 
1530         if (cfg->finalization_type == FINALIZ    1409         if (cfg->finalization_type == FINALIZATION_TYPE_DIGEST ||
1531             vec->digest_error) {                 1410             vec->digest_error) {
1532                 /* Just using digest() */        1411                 /* Just using digest() */
1533                 ahash_request_set_callback(re    1412                 ahash_request_set_callback(req, req_flags, crypto_req_done,
1534                                            &w    1413                                            &wait);
1535                 ahash_request_set_crypt(req,     1414                 ahash_request_set_crypt(req, tsgl->sgl, result, vec->psize);
1536                 err = do_ahash_op(crypto_ahas    1415                 err = do_ahash_op(crypto_ahash_digest, req, &wait, cfg->nosimd);
1537                 if (err) {                       1416                 if (err) {
1538                         if (err == vec->diges    1417                         if (err == vec->digest_error)
1539                                 return 0;        1418                                 return 0;
1540                         pr_err("alg: ahash: %    1419                         pr_err("alg: ahash: %s digest() failed on test vector %s; expected_error=%d, actual_error=%d, cfg=\"%s\"\n",
1541                                driver, vec_na    1420                                driver, vec_name, vec->digest_error, err,
1542                                cfg->name);       1421                                cfg->name);
1543                         return err;              1422                         return err;
1544                 }                                1423                 }
1545                 if (vec->digest_error) {         1424                 if (vec->digest_error) {
1546                         pr_err("alg: ahash: %    1425                         pr_err("alg: ahash: %s digest() unexpectedly succeeded on test vector %s; expected_error=%d, cfg=\"%s\"\n",
1547                                driver, vec_na    1426                                driver, vec_name, vec->digest_error, cfg->name);
1548                         return -EINVAL;          1427                         return -EINVAL;
1549                 }                                1428                 }
1550                 goto result_ready;               1429                 goto result_ready;
1551         }                                        1430         }
1552                                                  1431 
1553         /* Using init(), zero or more update(    1432         /* Using init(), zero or more update(), then final() or finup() */
1554                                                  1433 
1555         ahash_request_set_callback(req, req_f    1434         ahash_request_set_callback(req, req_flags, crypto_req_done, &wait);
1556         ahash_request_set_crypt(req, NULL, re    1435         ahash_request_set_crypt(req, NULL, result, 0);
1557         err = do_ahash_op(crypto_ahash_init,     1436         err = do_ahash_op(crypto_ahash_init, req, &wait, cfg->nosimd);
1558         err = check_nonfinal_ahash_op("init",    1437         err = check_nonfinal_ahash_op("init", err, result, digestsize,
1559                                       driver,    1438                                       driver, vec_name, cfg);
1560         if (err)                                 1439         if (err)
1561                 return err;                      1440                 return err;
1562                                                  1441 
1563         pending_sgl = NULL;                      1442         pending_sgl = NULL;
1564         pending_len = 0;                         1443         pending_len = 0;
1565         for (i = 0; i < tsgl->nents; i++) {      1444         for (i = 0; i < tsgl->nents; i++) {
1566                 if (divs[i]->flush_type != FL    1445                 if (divs[i]->flush_type != FLUSH_TYPE_NONE &&
1567                     pending_sgl != NULL) {       1446                     pending_sgl != NULL) {
1568                         /* update() with the     1447                         /* update() with the pending data */
1569                         ahash_request_set_cal    1448                         ahash_request_set_callback(req, req_flags,
1570                                                  1449                                                    crypto_req_done, &wait);
1571                         ahash_request_set_cry    1450                         ahash_request_set_crypt(req, pending_sgl, result,
1572                                                  1451                                                 pending_len);
1573                         err = do_ahash_op(cry    1452                         err = do_ahash_op(crypto_ahash_update, req, &wait,
1574                                           div    1453                                           divs[i]->nosimd);
1575                         err = check_nonfinal_    1454                         err = check_nonfinal_ahash_op("update", err,
1576                                                  1455                                                       result, digestsize,
1577                                                  1456                                                       driver, vec_name, cfg);
1578                         if (err)                 1457                         if (err)
1579                                 return err;      1458                                 return err;
1580                         pending_sgl = NULL;      1459                         pending_sgl = NULL;
1581                         pending_len = 0;         1460                         pending_len = 0;
1582                 }                                1461                 }
1583                 if (divs[i]->flush_type == FL    1462                 if (divs[i]->flush_type == FLUSH_TYPE_REIMPORT) {
1584                         /* Test ->export() an    1463                         /* Test ->export() and ->import() */
1585                         testmgr_poison(hashst    1464                         testmgr_poison(hashstate + statesize,
1586                                        TESTMG    1465                                        TESTMGR_POISON_LEN);
1587                         err = crypto_ahash_ex    1466                         err = crypto_ahash_export(req, hashstate);
1588                         err = check_nonfinal_    1467                         err = check_nonfinal_ahash_op("export", err,
1589                                                  1468                                                       result, digestsize,
1590                                                  1469                                                       driver, vec_name, cfg);
1591                         if (err)                 1470                         if (err)
1592                                 return err;      1471                                 return err;
1593                         if (!testmgr_is_poiso    1472                         if (!testmgr_is_poison(hashstate + statesize,
1594                                                  1473                                                TESTMGR_POISON_LEN)) {
1595                                 pr_err("alg:     1474                                 pr_err("alg: ahash: %s export() overran state buffer on test vector %s, cfg=\"%s\"\n",
1596                                        driver    1475                                        driver, vec_name, cfg->name);
1597                                 return -EOVER    1476                                 return -EOVERFLOW;
1598                         }                        1477                         }
1599                                                  1478 
1600                         testmgr_poison(req->_    1479                         testmgr_poison(req->__ctx, crypto_ahash_reqsize(tfm));
1601                         err = crypto_ahash_im    1480                         err = crypto_ahash_import(req, hashstate);
1602                         err = check_nonfinal_    1481                         err = check_nonfinal_ahash_op("import", err,
1603                                                  1482                                                       result, digestsize,
1604                                                  1483                                                       driver, vec_name, cfg);
1605                         if (err)                 1484                         if (err)
1606                                 return err;      1485                                 return err;
1607                 }                                1486                 }
1608                 if (pending_sgl == NULL)         1487                 if (pending_sgl == NULL)
1609                         pending_sgl = &tsgl->    1488                         pending_sgl = &tsgl->sgl[i];
1610                 pending_len += tsgl->sgl[i].l    1489                 pending_len += tsgl->sgl[i].length;
1611         }                                        1490         }
1612                                                  1491 
1613         ahash_request_set_callback(req, req_f    1492         ahash_request_set_callback(req, req_flags, crypto_req_done, &wait);
1614         ahash_request_set_crypt(req, pending_    1493         ahash_request_set_crypt(req, pending_sgl, result, pending_len);
1615         if (cfg->finalization_type == FINALIZ    1494         if (cfg->finalization_type == FINALIZATION_TYPE_FINAL) {
1616                 /* finish with update() and f    1495                 /* finish with update() and final() */
1617                 err = do_ahash_op(crypto_ahas    1496                 err = do_ahash_op(crypto_ahash_update, req, &wait, cfg->nosimd);
1618                 err = check_nonfinal_ahash_op    1497                 err = check_nonfinal_ahash_op("update", err, result, digestsize,
1619                                                  1498                                               driver, vec_name, cfg);
1620                 if (err)                         1499                 if (err)
1621                         return err;              1500                         return err;
1622                 err = do_ahash_op(crypto_ahas    1501                 err = do_ahash_op(crypto_ahash_final, req, &wait, cfg->nosimd);
1623                 if (err) {                       1502                 if (err) {
1624                         pr_err("alg: ahash: %    1503                         pr_err("alg: ahash: %s final() failed with err %d on test vector %s, cfg=\"%s\"\n",
1625                                driver, err, v    1504                                driver, err, vec_name, cfg->name);
1626                         return err;              1505                         return err;
1627                 }                                1506                 }
1628         } else {                                 1507         } else {
1629                 /* finish with finup() */        1508                 /* finish with finup() */
1630                 err = do_ahash_op(crypto_ahas    1509                 err = do_ahash_op(crypto_ahash_finup, req, &wait, cfg->nosimd);
1631                 if (err) {                       1510                 if (err) {
1632                         pr_err("alg: ahash: %    1511                         pr_err("alg: ahash: %s finup() failed with err %d on test vector %s, cfg=\"%s\"\n",
1633                                driver, err, v    1512                                driver, err, vec_name, cfg->name);
1634                         return err;              1513                         return err;
1635                 }                                1514                 }
1636         }                                        1515         }
1637                                                  1516 
1638 result_ready:                                    1517 result_ready:
1639         return check_hash_result("ahash", res    1518         return check_hash_result("ahash", result, digestsize, vec, vec_name,
1640                                  driver, cfg)    1519                                  driver, cfg);
1641 }                                                1520 }
1642                                                  1521 
1643 static int test_hash_vec_cfg(const struct has    1522 static int test_hash_vec_cfg(const struct hash_testvec *vec,
1644                              const char *vec_    1523                              const char *vec_name,
1645                              const struct tes    1524                              const struct testvec_config *cfg,
1646                              struct ahash_req    1525                              struct ahash_request *req,
1647                              struct shash_des    1526                              struct shash_desc *desc,
1648                              struct test_sgli    1527                              struct test_sglist *tsgl,
1649                              u8 *hashstate)      1528                              u8 *hashstate)
1650 {                                                1529 {
1651         int err;                                 1530         int err;
1652                                                  1531 
1653         /*                                       1532         /*
1654          * For algorithms implemented as "sha    1533          * For algorithms implemented as "shash", most bugs will be detected by
1655          * both the shash and ahash tests.  T    1534          * both the shash and ahash tests.  Test the shash API first so that the
1656          * failures involve less indirection,    1535          * failures involve less indirection, so are easier to debug.
1657          */                                      1536          */
1658                                                  1537 
1659         if (desc) {                              1538         if (desc) {
1660                 err = test_shash_vec_cfg(vec,    1539                 err = test_shash_vec_cfg(vec, vec_name, cfg, desc, tsgl,
1661                                          hash    1540                                          hashstate);
1662                 if (err)                         1541                 if (err)
1663                         return err;              1542                         return err;
1664         }                                        1543         }
1665                                                  1544 
1666         return test_ahash_vec_cfg(vec, vec_na    1545         return test_ahash_vec_cfg(vec, vec_name, cfg, req, tsgl, hashstate);
1667 }                                                1546 }
1668                                                  1547 
1669 static int test_hash_vec(const struct hash_te    1548 static int test_hash_vec(const struct hash_testvec *vec, unsigned int vec_num,
1670                          struct ahash_request    1549                          struct ahash_request *req, struct shash_desc *desc,
1671                          struct test_sglist *    1550                          struct test_sglist *tsgl, u8 *hashstate)
1672 {                                                1551 {
1673         char vec_name[16];                       1552         char vec_name[16];
1674         unsigned int i;                          1553         unsigned int i;
1675         int err;                                 1554         int err;
1676                                                  1555 
1677         sprintf(vec_name, "%u", vec_num);        1556         sprintf(vec_name, "%u", vec_num);
1678                                                  1557 
1679         for (i = 0; i < ARRAY_SIZE(default_ha    1558         for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++) {
1680                 err = test_hash_vec_cfg(vec,     1559                 err = test_hash_vec_cfg(vec, vec_name,
1681                                         &defa    1560                                         &default_hash_testvec_configs[i],
1682                                         req,     1561                                         req, desc, tsgl, hashstate);
1683                 if (err)                         1562                 if (err)
1684                         return err;              1563                         return err;
1685         }                                        1564         }
1686                                                  1565 
1687 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS         1566 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1688         if (!noextratests) {                     1567         if (!noextratests) {
1689                 struct rnd_state rng;         << 
1690                 struct testvec_config cfg;       1568                 struct testvec_config cfg;
1691                 char cfgname[TESTVEC_CONFIG_N    1569                 char cfgname[TESTVEC_CONFIG_NAMELEN];
1692                                                  1570 
1693                 init_rnd_state(&rng);         << 
1694                                               << 
1695                 for (i = 0; i < fuzz_iteratio    1571                 for (i = 0; i < fuzz_iterations; i++) {
1696                         generate_random_testv !! 1572                         generate_random_testvec_config(&cfg, cfgname,
1697                                                  1573                                                        sizeof(cfgname));
1698                         err = test_hash_vec_c    1574                         err = test_hash_vec_cfg(vec, vec_name, &cfg,
1699                                                  1575                                                 req, desc, tsgl, hashstate);
1700                         if (err)                 1576                         if (err)
1701                                 return err;      1577                                 return err;
1702                         cond_resched();          1578                         cond_resched();
1703                 }                                1579                 }
1704         }                                        1580         }
1705 #endif                                           1581 #endif
1706         return 0;                                1582         return 0;
1707 }                                                1583 }
1708                                                  1584 
1709 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS         1585 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
1710 /*                                               1586 /*
1711  * Generate a hash test vector from the given    1587  * Generate a hash test vector from the given implementation.
1712  * Assumes the buffers in 'vec' were already     1588  * Assumes the buffers in 'vec' were already allocated.
1713  */                                              1589  */
1714 static void generate_random_hash_testvec(stru !! 1590 static void generate_random_hash_testvec(struct shash_desc *desc,
1715                                          stru << 
1716                                          stru    1591                                          struct hash_testvec *vec,
1717                                          unsi    1592                                          unsigned int maxkeysize,
1718                                          unsi    1593                                          unsigned int maxdatasize,
1719                                          char    1594                                          char *name, size_t max_namelen)
1720 {                                                1595 {
1721         /* Data */                               1596         /* Data */
1722         vec->psize = generate_random_length(r !! 1597         vec->psize = generate_random_length(maxdatasize);
1723         generate_random_bytes(rng, (u8 *)vec- !! 1598         generate_random_bytes((u8 *)vec->plaintext, vec->psize);
1724                                                  1599 
1725         /*                                       1600         /*
1726          * Key: length in range [1, maxkeysiz    1601          * Key: length in range [1, maxkeysize], but usually choose maxkeysize.
1727          * If algorithm is unkeyed, then maxk    1602          * If algorithm is unkeyed, then maxkeysize == 0 and set ksize = 0.
1728          */                                      1603          */
1729         vec->setkey_error = 0;                   1604         vec->setkey_error = 0;
1730         vec->ksize = 0;                          1605         vec->ksize = 0;
1731         if (maxkeysize) {                        1606         if (maxkeysize) {
1732                 vec->ksize = maxkeysize;         1607                 vec->ksize = maxkeysize;
1733                 if (prandom_u32_below(rng, 4) !! 1608                 if (prandom_u32() % 4 == 0)
1734                         vec->ksize = prandom_ !! 1609                         vec->ksize = 1 + (prandom_u32() % maxkeysize);
1735                 generate_random_bytes(rng, (u !! 1610                 generate_random_bytes((u8 *)vec->key, vec->ksize);
1736                                                  1611 
1737                 vec->setkey_error = crypto_sh    1612                 vec->setkey_error = crypto_shash_setkey(desc->tfm, vec->key,
1738                                                  1613                                                         vec->ksize);
1739                 /* If the key couldn't be set    1614                 /* If the key couldn't be set, no need to continue to digest. */
1740                 if (vec->setkey_error)           1615                 if (vec->setkey_error)
1741                         goto done;               1616                         goto done;
1742         }                                        1617         }
1743                                                  1618 
1744         /* Digest */                             1619         /* Digest */
1745         vec->digest_error = crypto_shash_dige    1620         vec->digest_error = crypto_shash_digest(desc, vec->plaintext,
1746                                                  1621                                                 vec->psize, (u8 *)vec->digest);
1747 done:                                            1622 done:
1748         snprintf(name, max_namelen, "\"random    1623         snprintf(name, max_namelen, "\"random: psize=%u ksize=%u\"",
1749                  vec->psize, vec->ksize);        1624                  vec->psize, vec->ksize);
1750 }                                                1625 }
1751                                                  1626 
1752 /*                                               1627 /*
1753  * Test the hash algorithm represented by @re    1628  * Test the hash algorithm represented by @req against the corresponding generic
1754  * implementation, if one is available.          1629  * implementation, if one is available.
1755  */                                              1630  */
1756 static int test_hash_vs_generic_impl(const ch    1631 static int test_hash_vs_generic_impl(const char *generic_driver,
1757                                      unsigned    1632                                      unsigned int maxkeysize,
1758                                      struct a    1633                                      struct ahash_request *req,
1759                                      struct s    1634                                      struct shash_desc *desc,
1760                                      struct t    1635                                      struct test_sglist *tsgl,
1761                                      u8 *hash    1636                                      u8 *hashstate)
1762 {                                                1637 {
1763         struct crypto_ahash *tfm = crypto_aha    1638         struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
1764         const unsigned int digestsize = crypt    1639         const unsigned int digestsize = crypto_ahash_digestsize(tfm);
1765         const unsigned int blocksize = crypto    1640         const unsigned int blocksize = crypto_ahash_blocksize(tfm);
1766         const unsigned int maxdatasize = (2 *    1641         const unsigned int maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN;
1767         const char *algname = crypto_hash_alg    1642         const char *algname = crypto_hash_alg_common(tfm)->base.cra_name;
1768         const char *driver = crypto_ahash_dri    1643         const char *driver = crypto_ahash_driver_name(tfm);
1769         struct rnd_state rng;                 << 
1770         char _generic_driver[CRYPTO_MAX_ALG_N    1644         char _generic_driver[CRYPTO_MAX_ALG_NAME];
1771         struct crypto_shash *generic_tfm = NU    1645         struct crypto_shash *generic_tfm = NULL;
1772         struct shash_desc *generic_desc = NUL    1646         struct shash_desc *generic_desc = NULL;
1773         unsigned int i;                          1647         unsigned int i;
1774         struct hash_testvec vec = { 0 };         1648         struct hash_testvec vec = { 0 };
1775         char vec_name[64];                       1649         char vec_name[64];
1776         struct testvec_config *cfg;              1650         struct testvec_config *cfg;
1777         char cfgname[TESTVEC_CONFIG_NAMELEN];    1651         char cfgname[TESTVEC_CONFIG_NAMELEN];
1778         int err;                                 1652         int err;
1779                                                  1653 
1780         if (noextratests)                        1654         if (noextratests)
1781                 return 0;                        1655                 return 0;
1782                                                  1656 
1783         init_rnd_state(&rng);                 << 
1784                                               << 
1785         if (!generic_driver) { /* Use default    1657         if (!generic_driver) { /* Use default naming convention? */
1786                 err = build_generic_driver_na    1658                 err = build_generic_driver_name(algname, _generic_driver);
1787                 if (err)                         1659                 if (err)
1788                         return err;              1660                         return err;
1789                 generic_driver = _generic_dri    1661                 generic_driver = _generic_driver;
1790         }                                        1662         }
1791                                                  1663 
1792         if (strcmp(generic_driver, driver) ==    1664         if (strcmp(generic_driver, driver) == 0) /* Already the generic impl? */
1793                 return 0;                        1665                 return 0;
1794                                                  1666 
1795         generic_tfm = crypto_alloc_shash(gene    1667         generic_tfm = crypto_alloc_shash(generic_driver, 0, 0);
1796         if (IS_ERR(generic_tfm)) {               1668         if (IS_ERR(generic_tfm)) {
1797                 err = PTR_ERR(generic_tfm);      1669                 err = PTR_ERR(generic_tfm);
1798                 if (err == -ENOENT) {            1670                 if (err == -ENOENT) {
1799                         pr_warn("alg: hash: s    1671                         pr_warn("alg: hash: skipping comparison tests for %s because %s is unavailable\n",
1800                                 driver, gener    1672                                 driver, generic_driver);
1801                         return 0;                1673                         return 0;
1802                 }                                1674                 }
1803                 pr_err("alg: hash: error allo    1675                 pr_err("alg: hash: error allocating %s (generic impl of %s): %d\n",
1804                        generic_driver, algnam    1676                        generic_driver, algname, err);
1805                 return err;                      1677                 return err;
1806         }                                        1678         }
1807                                                  1679 
1808         cfg = kzalloc(sizeof(*cfg), GFP_KERNE    1680         cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
1809         if (!cfg) {                              1681         if (!cfg) {
1810                 err = -ENOMEM;                   1682                 err = -ENOMEM;
1811                 goto out;                        1683                 goto out;
1812         }                                        1684         }
1813                                                  1685 
1814         generic_desc = kzalloc(sizeof(*desc)     1686         generic_desc = kzalloc(sizeof(*desc) +
1815                                crypto_shash_d    1687                                crypto_shash_descsize(generic_tfm), GFP_KERNEL);
1816         if (!generic_desc) {                     1688         if (!generic_desc) {
1817                 err = -ENOMEM;                   1689                 err = -ENOMEM;
1818                 goto out;                        1690                 goto out;
1819         }                                        1691         }
1820         generic_desc->tfm = generic_tfm;         1692         generic_desc->tfm = generic_tfm;
1821                                                  1693 
1822         /* Check the algorithm properties for    1694         /* Check the algorithm properties for consistency. */
1823                                                  1695 
1824         if (digestsize != crypto_shash_digest    1696         if (digestsize != crypto_shash_digestsize(generic_tfm)) {
1825                 pr_err("alg: hash: digestsize    1697                 pr_err("alg: hash: digestsize for %s (%u) doesn't match generic impl (%u)\n",
1826                        driver, digestsize,       1698                        driver, digestsize,
1827                        crypto_shash_digestsiz    1699                        crypto_shash_digestsize(generic_tfm));
1828                 err = -EINVAL;                   1700                 err = -EINVAL;
1829                 goto out;                        1701                 goto out;
1830         }                                        1702         }
1831                                                  1703 
1832         if (blocksize != crypto_shash_blocksi    1704         if (blocksize != crypto_shash_blocksize(generic_tfm)) {
1833                 pr_err("alg: hash: blocksize     1705                 pr_err("alg: hash: blocksize for %s (%u) doesn't match generic impl (%u)\n",
1834                        driver, blocksize, cry    1706                        driver, blocksize, crypto_shash_blocksize(generic_tfm));
1835                 err = -EINVAL;                   1707                 err = -EINVAL;
1836                 goto out;                        1708                 goto out;
1837         }                                        1709         }
1838                                                  1710 
1839         /*                                       1711         /*
1840          * Now generate test vectors using th    1712          * Now generate test vectors using the generic implementation, and test
1841          * the other implementation against t    1713          * the other implementation against them.
1842          */                                      1714          */
1843                                                  1715 
1844         vec.key = kmalloc(maxkeysize, GFP_KER    1716         vec.key = kmalloc(maxkeysize, GFP_KERNEL);
1845         vec.plaintext = kmalloc(maxdatasize,     1717         vec.plaintext = kmalloc(maxdatasize, GFP_KERNEL);
1846         vec.digest = kmalloc(digestsize, GFP_    1718         vec.digest = kmalloc(digestsize, GFP_KERNEL);
1847         if (!vec.key || !vec.plaintext || !ve    1719         if (!vec.key || !vec.plaintext || !vec.digest) {
1848                 err = -ENOMEM;                   1720                 err = -ENOMEM;
1849                 goto out;                        1721                 goto out;
1850         }                                        1722         }
1851                                                  1723 
1852         for (i = 0; i < fuzz_iterations * 8;     1724         for (i = 0; i < fuzz_iterations * 8; i++) {
1853                 generate_random_hash_testvec( !! 1725                 generate_random_hash_testvec(generic_desc, &vec,
1854                                                  1726                                              maxkeysize, maxdatasize,
1855                                                  1727                                              vec_name, sizeof(vec_name));
1856                 generate_random_testvec_confi !! 1728                 generate_random_testvec_config(cfg, cfgname, sizeof(cfgname));
1857                                               << 
1858                                                  1729 
1859                 err = test_hash_vec_cfg(&vec,    1730                 err = test_hash_vec_cfg(&vec, vec_name, cfg,
1860                                         req,     1731                                         req, desc, tsgl, hashstate);
1861                 if (err)                         1732                 if (err)
1862                         goto out;                1733                         goto out;
1863                 cond_resched();                  1734                 cond_resched();
1864         }                                        1735         }
1865         err = 0;                                 1736         err = 0;
1866 out:                                             1737 out:
1867         kfree(cfg);                              1738         kfree(cfg);
1868         kfree(vec.key);                          1739         kfree(vec.key);
1869         kfree(vec.plaintext);                    1740         kfree(vec.plaintext);
1870         kfree(vec.digest);                       1741         kfree(vec.digest);
1871         crypto_free_shash(generic_tfm);          1742         crypto_free_shash(generic_tfm);
1872         kfree_sensitive(generic_desc);           1743         kfree_sensitive(generic_desc);
1873         return err;                              1744         return err;
1874 }                                                1745 }
1875 #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS *    1746 #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
1876 static int test_hash_vs_generic_impl(const ch    1747 static int test_hash_vs_generic_impl(const char *generic_driver,
1877                                      unsigned    1748                                      unsigned int maxkeysize,
1878                                      struct a    1749                                      struct ahash_request *req,
1879                                      struct s    1750                                      struct shash_desc *desc,
1880                                      struct t    1751                                      struct test_sglist *tsgl,
1881                                      u8 *hash    1752                                      u8 *hashstate)
1882 {                                                1753 {
1883         return 0;                                1754         return 0;
1884 }                                                1755 }
1885 #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS     1756 #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
1886                                                  1757 
1887 static int alloc_shash(const char *driver, u3    1758 static int alloc_shash(const char *driver, u32 type, u32 mask,
1888                        struct crypto_shash **    1759                        struct crypto_shash **tfm_ret,
1889                        struct shash_desc **de    1760                        struct shash_desc **desc_ret)
1890 {                                                1761 {
1891         struct crypto_shash *tfm;                1762         struct crypto_shash *tfm;
1892         struct shash_desc *desc;                 1763         struct shash_desc *desc;
1893                                                  1764 
1894         tfm = crypto_alloc_shash(driver, type    1765         tfm = crypto_alloc_shash(driver, type, mask);
1895         if (IS_ERR(tfm)) {                       1766         if (IS_ERR(tfm)) {
1896                 if (PTR_ERR(tfm) == -ENOENT)     1767                 if (PTR_ERR(tfm) == -ENOENT) {
1897                         /*                       1768                         /*
1898                          * This algorithm is     1769                          * This algorithm is only available through the ahash
1899                          * API, not the shash    1770                          * API, not the shash API, so skip the shash tests.
1900                          */                      1771                          */
1901                         return 0;                1772                         return 0;
1902                 }                                1773                 }
1903                 pr_err("alg: hash: failed to     1774                 pr_err("alg: hash: failed to allocate shash transform for %s: %ld\n",
1904                        driver, PTR_ERR(tfm));    1775                        driver, PTR_ERR(tfm));
1905                 return PTR_ERR(tfm);             1776                 return PTR_ERR(tfm);
1906         }                                        1777         }
1907                                                  1778 
1908         desc = kmalloc(sizeof(*desc) + crypto    1779         desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(tfm), GFP_KERNEL);
1909         if (!desc) {                             1780         if (!desc) {
1910                 crypto_free_shash(tfm);          1781                 crypto_free_shash(tfm);
1911                 return -ENOMEM;                  1782                 return -ENOMEM;
1912         }                                        1783         }
1913         desc->tfm = tfm;                         1784         desc->tfm = tfm;
1914                                                  1785 
1915         *tfm_ret = tfm;                          1786         *tfm_ret = tfm;
1916         *desc_ret = desc;                        1787         *desc_ret = desc;
1917         return 0;                                1788         return 0;
1918 }                                                1789 }
1919                                                  1790 
1920 static int __alg_test_hash(const struct hash_    1791 static int __alg_test_hash(const struct hash_testvec *vecs,
1921                            unsigned int num_v    1792                            unsigned int num_vecs, const char *driver,
1922                            u32 type, u32 mask    1793                            u32 type, u32 mask,
1923                            const char *generi    1794                            const char *generic_driver, unsigned int maxkeysize)
1924 {                                                1795 {
1925         struct crypto_ahash *atfm = NULL;        1796         struct crypto_ahash *atfm = NULL;
1926         struct ahash_request *req = NULL;        1797         struct ahash_request *req = NULL;
1927         struct crypto_shash *stfm = NULL;        1798         struct crypto_shash *stfm = NULL;
1928         struct shash_desc *desc = NULL;          1799         struct shash_desc *desc = NULL;
1929         struct test_sglist *tsgl = NULL;         1800         struct test_sglist *tsgl = NULL;
1930         u8 *hashstate = NULL;                    1801         u8 *hashstate = NULL;
1931         unsigned int statesize;                  1802         unsigned int statesize;
1932         unsigned int i;                          1803         unsigned int i;
1933         int err;                                 1804         int err;
1934                                                  1805 
1935         /*                                       1806         /*
1936          * Always test the ahash API.  This w    1807          * Always test the ahash API.  This works regardless of whether the
1937          * algorithm is implemented as ahash     1808          * algorithm is implemented as ahash or shash.
1938          */                                      1809          */
1939                                                  1810 
1940         atfm = crypto_alloc_ahash(driver, typ    1811         atfm = crypto_alloc_ahash(driver, type, mask);
1941         if (IS_ERR(atfm)) {                      1812         if (IS_ERR(atfm)) {
1942                 if (PTR_ERR(atfm) == -ENOENT) << 
1943                         return 0;             << 
1944                 pr_err("alg: hash: failed to     1813                 pr_err("alg: hash: failed to allocate transform for %s: %ld\n",
1945                        driver, PTR_ERR(atfm))    1814                        driver, PTR_ERR(atfm));
1946                 return PTR_ERR(atfm);            1815                 return PTR_ERR(atfm);
1947         }                                        1816         }
1948         driver = crypto_ahash_driver_name(atf    1817         driver = crypto_ahash_driver_name(atfm);
1949                                                  1818 
1950         req = ahash_request_alloc(atfm, GFP_K    1819         req = ahash_request_alloc(atfm, GFP_KERNEL);
1951         if (!req) {                              1820         if (!req) {
1952                 pr_err("alg: hash: failed to     1821                 pr_err("alg: hash: failed to allocate request for %s\n",
1953                        driver);                  1822                        driver);
1954                 err = -ENOMEM;                   1823                 err = -ENOMEM;
1955                 goto out;                        1824                 goto out;
1956         }                                        1825         }
1957                                                  1826 
1958         /*                                       1827         /*
1959          * If available also test the shash A    1828          * If available also test the shash API, to cover corner cases that may
1960          * be missed by testing the ahash API    1829          * be missed by testing the ahash API only.
1961          */                                      1830          */
1962         err = alloc_shash(driver, type, mask,    1831         err = alloc_shash(driver, type, mask, &stfm, &desc);
1963         if (err)                                 1832         if (err)
1964                 goto out;                        1833                 goto out;
1965                                                  1834 
1966         tsgl = kmalloc(sizeof(*tsgl), GFP_KER    1835         tsgl = kmalloc(sizeof(*tsgl), GFP_KERNEL);
1967         if (!tsgl || init_test_sglist(tsgl) !    1836         if (!tsgl || init_test_sglist(tsgl) != 0) {
1968                 pr_err("alg: hash: failed to     1837                 pr_err("alg: hash: failed to allocate test buffers for %s\n",
1969                        driver);                  1838                        driver);
1970                 kfree(tsgl);                     1839                 kfree(tsgl);
1971                 tsgl = NULL;                     1840                 tsgl = NULL;
1972                 err = -ENOMEM;                   1841                 err = -ENOMEM;
1973                 goto out;                        1842                 goto out;
1974         }                                        1843         }
1975                                                  1844 
1976         statesize = crypto_ahash_statesize(at    1845         statesize = crypto_ahash_statesize(atfm);
1977         if (stfm)                                1846         if (stfm)
1978                 statesize = max(statesize, cr    1847                 statesize = max(statesize, crypto_shash_statesize(stfm));
1979         hashstate = kmalloc(statesize + TESTM    1848         hashstate = kmalloc(statesize + TESTMGR_POISON_LEN, GFP_KERNEL);
1980         if (!hashstate) {                        1849         if (!hashstate) {
1981                 pr_err("alg: hash: failed to     1850                 pr_err("alg: hash: failed to allocate hash state buffer for %s\n",
1982                        driver);                  1851                        driver);
1983                 err = -ENOMEM;                   1852                 err = -ENOMEM;
1984                 goto out;                        1853                 goto out;
1985         }                                        1854         }
1986                                                  1855 
1987         for (i = 0; i < num_vecs; i++) {         1856         for (i = 0; i < num_vecs; i++) {
1988                 if (fips_enabled && vecs[i].f << 
1989                         continue;             << 
1990                                               << 
1991                 err = test_hash_vec(&vecs[i],    1857                 err = test_hash_vec(&vecs[i], i, req, desc, tsgl, hashstate);
1992                 if (err)                         1858                 if (err)
1993                         goto out;                1859                         goto out;
1994                 cond_resched();                  1860                 cond_resched();
1995         }                                        1861         }
1996         err = test_hash_vs_generic_impl(gener    1862         err = test_hash_vs_generic_impl(generic_driver, maxkeysize, req,
1997                                         desc,    1863                                         desc, tsgl, hashstate);
1998 out:                                             1864 out:
1999         kfree(hashstate);                        1865         kfree(hashstate);
2000         if (tsgl) {                              1866         if (tsgl) {
2001                 destroy_test_sglist(tsgl);       1867                 destroy_test_sglist(tsgl);
2002                 kfree(tsgl);                     1868                 kfree(tsgl);
2003         }                                        1869         }
2004         kfree(desc);                             1870         kfree(desc);
2005         crypto_free_shash(stfm);                 1871         crypto_free_shash(stfm);
2006         ahash_request_free(req);                 1872         ahash_request_free(req);
2007         crypto_free_ahash(atfm);                 1873         crypto_free_ahash(atfm);
2008         return err;                              1874         return err;
2009 }                                                1875 }
2010                                                  1876 
2011 static int alg_test_hash(const struct alg_tes    1877 static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
2012                          u32 type, u32 mask)     1878                          u32 type, u32 mask)
2013 {                                                1879 {
2014         const struct hash_testvec *template =    1880         const struct hash_testvec *template = desc->suite.hash.vecs;
2015         unsigned int tcount = desc->suite.has    1881         unsigned int tcount = desc->suite.hash.count;
2016         unsigned int nr_unkeyed, nr_keyed;       1882         unsigned int nr_unkeyed, nr_keyed;
2017         unsigned int maxkeysize = 0;             1883         unsigned int maxkeysize = 0;
2018         int err;                                 1884         int err;
2019                                                  1885 
2020         /*                                       1886         /*
2021          * For OPTIONAL_KEY algorithms, we ha    1887          * For OPTIONAL_KEY algorithms, we have to do all the unkeyed tests
2022          * first, before setting a key on the    1888          * first, before setting a key on the tfm.  To make this easier, we
2023          * require that the unkeyed test vect    1889          * require that the unkeyed test vectors (if any) are listed first.
2024          */                                      1890          */
2025                                                  1891 
2026         for (nr_unkeyed = 0; nr_unkeyed < tco    1892         for (nr_unkeyed = 0; nr_unkeyed < tcount; nr_unkeyed++) {
2027                 if (template[nr_unkeyed].ksiz    1893                 if (template[nr_unkeyed].ksize)
2028                         break;                   1894                         break;
2029         }                                        1895         }
2030         for (nr_keyed = 0; nr_unkeyed + nr_ke    1896         for (nr_keyed = 0; nr_unkeyed + nr_keyed < tcount; nr_keyed++) {
2031                 if (!template[nr_unkeyed + nr    1897                 if (!template[nr_unkeyed + nr_keyed].ksize) {
2032                         pr_err("alg: hash: te    1898                         pr_err("alg: hash: test vectors for %s out of order, "
2033                                "unkeyed ones     1899                                "unkeyed ones must come first\n", desc->alg);
2034                         return -EINVAL;          1900                         return -EINVAL;
2035                 }                                1901                 }
2036                 maxkeysize = max_t(unsigned i    1902                 maxkeysize = max_t(unsigned int, maxkeysize,
2037                                    template[n    1903                                    template[nr_unkeyed + nr_keyed].ksize);
2038         }                                        1904         }
2039                                                  1905 
2040         err = 0;                                 1906         err = 0;
2041         if (nr_unkeyed) {                        1907         if (nr_unkeyed) {
2042                 err = __alg_test_hash(templat    1908                 err = __alg_test_hash(template, nr_unkeyed, driver, type, mask,
2043                                       desc->g    1909                                       desc->generic_driver, maxkeysize);
2044                 template += nr_unkeyed;          1910                 template += nr_unkeyed;
2045         }                                        1911         }
2046                                                  1912 
2047         if (!err && nr_keyed)                    1913         if (!err && nr_keyed)
2048                 err = __alg_test_hash(templat    1914                 err = __alg_test_hash(template, nr_keyed, driver, type, mask,
2049                                       desc->g    1915                                       desc->generic_driver, maxkeysize);
2050                                                  1916 
2051         return err;                              1917         return err;
2052 }                                                1918 }
2053                                                  1919 
2054 static int test_aead_vec_cfg(int enc, const s    1920 static int test_aead_vec_cfg(int enc, const struct aead_testvec *vec,
2055                              const char *vec_    1921                              const char *vec_name,
2056                              const struct tes    1922                              const struct testvec_config *cfg,
2057                              struct aead_requ    1923                              struct aead_request *req,
2058                              struct cipher_te    1924                              struct cipher_test_sglists *tsgls)
2059 {                                                1925 {
2060         struct crypto_aead *tfm = crypto_aead    1926         struct crypto_aead *tfm = crypto_aead_reqtfm(req);
2061         const unsigned int alignmask = crypto    1927         const unsigned int alignmask = crypto_aead_alignmask(tfm);
2062         const unsigned int ivsize = crypto_ae    1928         const unsigned int ivsize = crypto_aead_ivsize(tfm);
2063         const unsigned int authsize = vec->cl    1929         const unsigned int authsize = vec->clen - vec->plen;
2064         const char *driver = crypto_aead_driv    1930         const char *driver = crypto_aead_driver_name(tfm);
2065         const u32 req_flags = CRYPTO_TFM_REQ_    1931         const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
2066         const char *op = enc ? "encryption" :    1932         const char *op = enc ? "encryption" : "decryption";
2067         DECLARE_CRYPTO_WAIT(wait);               1933         DECLARE_CRYPTO_WAIT(wait);
2068         u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1)    1934         u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN];
2069         u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_    1935         u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) +
2070                  cfg->iv_offset +                1936                  cfg->iv_offset +
2071                  (cfg->iv_offset_relative_to_    1937                  (cfg->iv_offset_relative_to_alignmask ? alignmask : 0);
2072         struct kvec input[2];                    1938         struct kvec input[2];
2073         int err;                                 1939         int err;
2074                                                  1940 
2075         /* Set the key */                        1941         /* Set the key */
2076         if (vec->wk)                             1942         if (vec->wk)
2077                 crypto_aead_set_flags(tfm, CR    1943                 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
2078         else                                     1944         else
2079                 crypto_aead_clear_flags(tfm,     1945                 crypto_aead_clear_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
2080                                                  1946 
2081         err = do_setkey(crypto_aead_setkey, t    1947         err = do_setkey(crypto_aead_setkey, tfm, vec->key, vec->klen,
2082                         cfg, alignmask);         1948                         cfg, alignmask);
2083         if (err && err != vec->setkey_error)     1949         if (err && err != vec->setkey_error) {
2084                 pr_err("alg: aead: %s setkey     1950                 pr_err("alg: aead: %s setkey failed on test vector %s; expected_error=%d, actual_error=%d, flags=%#x\n",
2085                        driver, vec_name, vec-    1951                        driver, vec_name, vec->setkey_error, err,
2086                        crypto_aead_get_flags(    1952                        crypto_aead_get_flags(tfm));
2087                 return err;                      1953                 return err;
2088         }                                        1954         }
2089         if (!err && vec->setkey_error) {         1955         if (!err && vec->setkey_error) {
2090                 pr_err("alg: aead: %s setkey     1956                 pr_err("alg: aead: %s setkey unexpectedly succeeded on test vector %s; expected_error=%d\n",
2091                        driver, vec_name, vec-    1957                        driver, vec_name, vec->setkey_error);
2092                 return -EINVAL;                  1958                 return -EINVAL;
2093         }                                        1959         }
2094                                                  1960 
2095         /* Set the authentication tag size */    1961         /* Set the authentication tag size */
2096         err = crypto_aead_setauthsize(tfm, au    1962         err = crypto_aead_setauthsize(tfm, authsize);
2097         if (err && err != vec->setauthsize_er    1963         if (err && err != vec->setauthsize_error) {
2098                 pr_err("alg: aead: %s setauth    1964                 pr_err("alg: aead: %s setauthsize failed on test vector %s; expected_error=%d, actual_error=%d\n",
2099                        driver, vec_name, vec-    1965                        driver, vec_name, vec->setauthsize_error, err);
2100                 return err;                      1966                 return err;
2101         }                                        1967         }
2102         if (!err && vec->setauthsize_error) {    1968         if (!err && vec->setauthsize_error) {
2103                 pr_err("alg: aead: %s setauth    1969                 pr_err("alg: aead: %s setauthsize unexpectedly succeeded on test vector %s; expected_error=%d\n",
2104                        driver, vec_name, vec-    1970                        driver, vec_name, vec->setauthsize_error);
2105                 return -EINVAL;                  1971                 return -EINVAL;
2106         }                                        1972         }
2107                                                  1973 
2108         if (vec->setkey_error || vec->setauth    1974         if (vec->setkey_error || vec->setauthsize_error)
2109                 return 0;                        1975                 return 0;
2110                                                  1976 
2111         /* The IV must be copied to a buffer,    1977         /* The IV must be copied to a buffer, as the algorithm may modify it */
2112         if (WARN_ON(ivsize > MAX_IVLEN))         1978         if (WARN_ON(ivsize > MAX_IVLEN))
2113                 return -EINVAL;                  1979                 return -EINVAL;
2114         if (vec->iv)                             1980         if (vec->iv)
2115                 memcpy(iv, vec->iv, ivsize);     1981                 memcpy(iv, vec->iv, ivsize);
2116         else                                     1982         else
2117                 memset(iv, 0, ivsize);           1983                 memset(iv, 0, ivsize);
2118                                                  1984 
2119         /* Build the src/dst scatterlists */     1985         /* Build the src/dst scatterlists */
2120         input[0].iov_base = (void *)vec->asso    1986         input[0].iov_base = (void *)vec->assoc;
2121         input[0].iov_len = vec->alen;            1987         input[0].iov_len = vec->alen;
2122         input[1].iov_base = enc ? (void *)vec    1988         input[1].iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext;
2123         input[1].iov_len = enc ? vec->plen :     1989         input[1].iov_len = enc ? vec->plen : vec->clen;
2124         err = build_cipher_test_sglists(tsgls    1990         err = build_cipher_test_sglists(tsgls, cfg, alignmask,
2125                                         vec->    1991                                         vec->alen + (enc ? vec->plen :
2126                                                  1992                                                      vec->clen),
2127                                         vec->    1993                                         vec->alen + (enc ? vec->clen :
2128                                                  1994                                                      vec->plen),
2129                                         input    1995                                         input, 2);
2130         if (err) {                               1996         if (err) {
2131                 pr_err("alg: aead: %s %s: err    1997                 pr_err("alg: aead: %s %s: error preparing scatterlists for test vector %s, cfg=\"%s\"\n",
2132                        driver, op, vec_name,     1998                        driver, op, vec_name, cfg->name);
2133                 return err;                      1999                 return err;
2134         }                                        2000         }
2135                                                  2001 
2136         /* Do the actual encryption or decryp    2002         /* Do the actual encryption or decryption */
2137         testmgr_poison(req->__ctx, crypto_aea    2003         testmgr_poison(req->__ctx, crypto_aead_reqsize(tfm));
2138         aead_request_set_callback(req, req_fl    2004         aead_request_set_callback(req, req_flags, crypto_req_done, &wait);
2139         aead_request_set_crypt(req, tsgls->sr    2005         aead_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr,
2140                                enc ? vec->ple    2006                                enc ? vec->plen : vec->clen, iv);
2141         aead_request_set_ad(req, vec->alen);     2007         aead_request_set_ad(req, vec->alen);
2142         if (cfg->nosimd)                         2008         if (cfg->nosimd)
2143                 crypto_disable_simd_for_test(    2009                 crypto_disable_simd_for_test();
2144         err = enc ? crypto_aead_encrypt(req)     2010         err = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
2145         if (cfg->nosimd)                         2011         if (cfg->nosimd)
2146                 crypto_reenable_simd_for_test    2012                 crypto_reenable_simd_for_test();
2147         err = crypto_wait_req(err, &wait);       2013         err = crypto_wait_req(err, &wait);
2148                                                  2014 
2149         /* Check that the algorithm didn't ov    2015         /* Check that the algorithm didn't overwrite things it shouldn't have */
2150         if (req->cryptlen != (enc ? vec->plen    2016         if (req->cryptlen != (enc ? vec->plen : vec->clen) ||
2151             req->assoclen != vec->alen ||        2017             req->assoclen != vec->alen ||
2152             req->iv != iv ||                     2018             req->iv != iv ||
2153             req->src != tsgls->src.sgl_ptr ||    2019             req->src != tsgls->src.sgl_ptr ||
2154             req->dst != tsgls->dst.sgl_ptr ||    2020             req->dst != tsgls->dst.sgl_ptr ||
2155             crypto_aead_reqtfm(req) != tfm ||    2021             crypto_aead_reqtfm(req) != tfm ||
2156             req->base.complete != crypto_req_    2022             req->base.complete != crypto_req_done ||
2157             req->base.flags != req_flags ||      2023             req->base.flags != req_flags ||
2158             req->base.data != &wait) {           2024             req->base.data != &wait) {
2159                 pr_err("alg: aead: %s %s corr    2025                 pr_err("alg: aead: %s %s corrupted request struct on test vector %s, cfg=\"%s\"\n",
2160                        driver, op, vec_name,     2026                        driver, op, vec_name, cfg->name);
2161                 if (req->cryptlen != (enc ? v    2027                 if (req->cryptlen != (enc ? vec->plen : vec->clen))
2162                         pr_err("alg: aead: ch    2028                         pr_err("alg: aead: changed 'req->cryptlen'\n");
2163                 if (req->assoclen != vec->ale    2029                 if (req->assoclen != vec->alen)
2164                         pr_err("alg: aead: ch    2030                         pr_err("alg: aead: changed 'req->assoclen'\n");
2165                 if (req->iv != iv)               2031                 if (req->iv != iv)
2166                         pr_err("alg: aead: ch    2032                         pr_err("alg: aead: changed 'req->iv'\n");
2167                 if (req->src != tsgls->src.sg    2033                 if (req->src != tsgls->src.sgl_ptr)
2168                         pr_err("alg: aead: ch    2034                         pr_err("alg: aead: changed 'req->src'\n");
2169                 if (req->dst != tsgls->dst.sg    2035                 if (req->dst != tsgls->dst.sgl_ptr)
2170                         pr_err("alg: aead: ch    2036                         pr_err("alg: aead: changed 'req->dst'\n");
2171                 if (crypto_aead_reqtfm(req) !    2037                 if (crypto_aead_reqtfm(req) != tfm)
2172                         pr_err("alg: aead: ch    2038                         pr_err("alg: aead: changed 'req->base.tfm'\n");
2173                 if (req->base.complete != cry    2039                 if (req->base.complete != crypto_req_done)
2174                         pr_err("alg: aead: ch    2040                         pr_err("alg: aead: changed 'req->base.complete'\n");
2175                 if (req->base.flags != req_fl    2041                 if (req->base.flags != req_flags)
2176                         pr_err("alg: aead: ch    2042                         pr_err("alg: aead: changed 'req->base.flags'\n");
2177                 if (req->base.data != &wait)     2043                 if (req->base.data != &wait)
2178                         pr_err("alg: aead: ch    2044                         pr_err("alg: aead: changed 'req->base.data'\n");
2179                 return -EINVAL;                  2045                 return -EINVAL;
2180         }                                        2046         }
2181         if (is_test_sglist_corrupted(&tsgls->    2047         if (is_test_sglist_corrupted(&tsgls->src)) {
2182                 pr_err("alg: aead: %s %s corr    2048                 pr_err("alg: aead: %s %s corrupted src sgl on test vector %s, cfg=\"%s\"\n",
2183                        driver, op, vec_name,     2049                        driver, op, vec_name, cfg->name);
2184                 return -EINVAL;                  2050                 return -EINVAL;
2185         }                                        2051         }
2186         if (tsgls->dst.sgl_ptr != tsgls->src.    2052         if (tsgls->dst.sgl_ptr != tsgls->src.sgl &&
2187             is_test_sglist_corrupted(&tsgls->    2053             is_test_sglist_corrupted(&tsgls->dst)) {
2188                 pr_err("alg: aead: %s %s corr    2054                 pr_err("alg: aead: %s %s corrupted dst sgl on test vector %s, cfg=\"%s\"\n",
2189                        driver, op, vec_name,     2055                        driver, op, vec_name, cfg->name);
2190                 return -EINVAL;                  2056                 return -EINVAL;
2191         }                                        2057         }
2192                                                  2058 
2193         /* Check for unexpected success or fa    2059         /* Check for unexpected success or failure, or wrong error code */
2194         if ((err == 0 && vec->novrfy) ||         2060         if ((err == 0 && vec->novrfy) ||
2195             (err != vec->crypt_error && !(err    2061             (err != vec->crypt_error && !(err == -EBADMSG && vec->novrfy))) {
2196                 char expected_error[32];         2062                 char expected_error[32];
2197                                                  2063 
2198                 if (vec->novrfy &&               2064                 if (vec->novrfy &&
2199                     vec->crypt_error != 0 &&     2065                     vec->crypt_error != 0 && vec->crypt_error != -EBADMSG)
2200                         sprintf(expected_erro    2066                         sprintf(expected_error, "-EBADMSG or %d",
2201                                 vec->crypt_er    2067                                 vec->crypt_error);
2202                 else if (vec->novrfy)            2068                 else if (vec->novrfy)
2203                         sprintf(expected_erro    2069                         sprintf(expected_error, "-EBADMSG");
2204                 else                             2070                 else
2205                         sprintf(expected_erro    2071                         sprintf(expected_error, "%d", vec->crypt_error);
2206                 if (err) {                       2072                 if (err) {
2207                         pr_err("alg: aead: %s    2073                         pr_err("alg: aead: %s %s failed on test vector %s; expected_error=%s, actual_error=%d, cfg=\"%s\"\n",
2208                                driver, op, ve    2074                                driver, op, vec_name, expected_error, err,
2209                                cfg->name);       2075                                cfg->name);
2210                         return err;              2076                         return err;
2211                 }                                2077                 }
2212                 pr_err("alg: aead: %s %s unex    2078                 pr_err("alg: aead: %s %s unexpectedly succeeded on test vector %s; expected_error=%s, cfg=\"%s\"\n",
2213                        driver, op, vec_name,     2079                        driver, op, vec_name, expected_error, cfg->name);
2214                 return -EINVAL;                  2080                 return -EINVAL;
2215         }                                        2081         }
2216         if (err) /* Expectedly failed. */        2082         if (err) /* Expectedly failed. */
2217                 return 0;                        2083                 return 0;
2218                                                  2084 
2219         /* Check for the correct output (ciph    2085         /* Check for the correct output (ciphertext or plaintext) */
2220         err = verify_correct_output(&tsgls->d    2086         err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext,
2221                                     enc ? vec    2087                                     enc ? vec->clen : vec->plen,
2222                                     vec->alen !! 2088                                     vec->alen, enc || !cfg->inplace);
2223                                     enc || cf << 
2224         if (err == -EOVERFLOW) {                 2089         if (err == -EOVERFLOW) {
2225                 pr_err("alg: aead: %s %s over    2090                 pr_err("alg: aead: %s %s overran dst buffer on test vector %s, cfg=\"%s\"\n",
2226                        driver, op, vec_name,     2091                        driver, op, vec_name, cfg->name);
2227                 return err;                      2092                 return err;
2228         }                                        2093         }
2229         if (err) {                               2094         if (err) {
2230                 pr_err("alg: aead: %s %s test    2095                 pr_err("alg: aead: %s %s test failed (wrong result) on test vector %s, cfg=\"%s\"\n",
2231                        driver, op, vec_name,     2096                        driver, op, vec_name, cfg->name);
2232                 return err;                      2097                 return err;
2233         }                                        2098         }
2234                                                  2099 
2235         return 0;                                2100         return 0;
2236 }                                                2101 }
2237                                                  2102 
2238 static int test_aead_vec(int enc, const struc    2103 static int test_aead_vec(int enc, const struct aead_testvec *vec,
2239                          unsigned int vec_num    2104                          unsigned int vec_num, struct aead_request *req,
2240                          struct cipher_test_s    2105                          struct cipher_test_sglists *tsgls)
2241 {                                                2106 {
2242         char vec_name[16];                       2107         char vec_name[16];
2243         unsigned int i;                          2108         unsigned int i;
2244         int err;                                 2109         int err;
2245                                                  2110 
2246         if (enc && vec->novrfy)                  2111         if (enc && vec->novrfy)
2247                 return 0;                        2112                 return 0;
2248                                                  2113 
2249         sprintf(vec_name, "%u", vec_num);        2114         sprintf(vec_name, "%u", vec_num);
2250                                                  2115 
2251         for (i = 0; i < ARRAY_SIZE(default_ci    2116         for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
2252                 err = test_aead_vec_cfg(enc,     2117                 err = test_aead_vec_cfg(enc, vec, vec_name,
2253                                         &defa    2118                                         &default_cipher_testvec_configs[i],
2254                                         req,     2119                                         req, tsgls);
2255                 if (err)                         2120                 if (err)
2256                         return err;              2121                         return err;
2257         }                                        2122         }
2258                                                  2123 
2259 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS         2124 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
2260         if (!noextratests) {                     2125         if (!noextratests) {
2261                 struct rnd_state rng;         << 
2262                 struct testvec_config cfg;       2126                 struct testvec_config cfg;
2263                 char cfgname[TESTVEC_CONFIG_N    2127                 char cfgname[TESTVEC_CONFIG_NAMELEN];
2264                                                  2128 
2265                 init_rnd_state(&rng);         << 
2266                                               << 
2267                 for (i = 0; i < fuzz_iteratio    2129                 for (i = 0; i < fuzz_iterations; i++) {
2268                         generate_random_testv !! 2130                         generate_random_testvec_config(&cfg, cfgname,
2269                                                  2131                                                        sizeof(cfgname));
2270                         err = test_aead_vec_c    2132                         err = test_aead_vec_cfg(enc, vec, vec_name,
2271                                                  2133                                                 &cfg, req, tsgls);
2272                         if (err)                 2134                         if (err)
2273                                 return err;      2135                                 return err;
2274                         cond_resched();          2136                         cond_resched();
2275                 }                                2137                 }
2276         }                                        2138         }
2277 #endif                                           2139 #endif
2278         return 0;                                2140         return 0;
2279 }                                                2141 }
2280                                                  2142 
2281 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS         2143 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
2282                                                  2144 
2283 struct aead_extra_tests_ctx {                    2145 struct aead_extra_tests_ctx {
2284         struct rnd_state rng;                 << 
2285         struct aead_request *req;                2146         struct aead_request *req;
2286         struct crypto_aead *tfm;                 2147         struct crypto_aead *tfm;
2287         const struct alg_test_desc *test_desc    2148         const struct alg_test_desc *test_desc;
2288         struct cipher_test_sglists *tsgls;       2149         struct cipher_test_sglists *tsgls;
2289         unsigned int maxdatasize;                2150         unsigned int maxdatasize;
2290         unsigned int maxkeysize;                 2151         unsigned int maxkeysize;
2291                                                  2152 
2292         struct aead_testvec vec;                 2153         struct aead_testvec vec;
2293         char vec_name[64];                       2154         char vec_name[64];
2294         char cfgname[TESTVEC_CONFIG_NAMELEN];    2155         char cfgname[TESTVEC_CONFIG_NAMELEN];
2295         struct testvec_config cfg;               2156         struct testvec_config cfg;
2296 };                                               2157 };
2297                                                  2158 
2298 /*                                               2159 /*
2299  * Make at least one random change to a (ciph    2160  * Make at least one random change to a (ciphertext, AAD) pair.  "Ciphertext"
2300  * here means the full ciphertext including t    2161  * here means the full ciphertext including the authentication tag.  The
2301  * authentication tag (and hence also the cip    2162  * authentication tag (and hence also the ciphertext) is assumed to be nonempty.
2302  */                                              2163  */
2303 static void mutate_aead_message(struct rnd_st !! 2164 static void mutate_aead_message(struct aead_testvec *vec, bool aad_iv,
2304                                 struct aead_t << 
2305                                 unsigned int     2165                                 unsigned int ivsize)
2306 {                                                2166 {
2307         const unsigned int aad_tail_size = aa    2167         const unsigned int aad_tail_size = aad_iv ? ivsize : 0;
2308         const unsigned int authsize = vec->cl    2168         const unsigned int authsize = vec->clen - vec->plen;
2309                                                  2169 
2310         if (prandom_bool(rng) && vec->alen >  !! 2170         if (prandom_u32() % 2 == 0 && vec->alen > aad_tail_size) {
2311                  /* Mutate the AAD */            2171                  /* Mutate the AAD */
2312                 flip_random_bit(rng, (u8 *)ve !! 2172                 flip_random_bit((u8 *)vec->assoc, vec->alen - aad_tail_size);
2313                                 vec->alen - a !! 2173                 if (prandom_u32() % 2 == 0)
2314                 if (prandom_bool(rng))        << 
2315                         return;                  2174                         return;
2316         }                                        2175         }
2317         if (prandom_bool(rng)) {              !! 2176         if (prandom_u32() % 2 == 0) {
2318                 /* Mutate auth tag (assuming     2177                 /* Mutate auth tag (assuming it's at the end of ciphertext) */
2319                 flip_random_bit(rng, (u8 *)ve !! 2178                 flip_random_bit((u8 *)vec->ctext + vec->plen, authsize);
2320         } else {                                 2179         } else {
2321                 /* Mutate any part of the cip    2180                 /* Mutate any part of the ciphertext */
2322                 flip_random_bit(rng, (u8 *)ve !! 2181                 flip_random_bit((u8 *)vec->ctext, vec->clen);
2323         }                                        2182         }
2324 }                                                2183 }
2325                                                  2184 
2326 /*                                               2185 /*
2327  * Minimum authentication tag size in bytes a    2186  * Minimum authentication tag size in bytes at which we assume that we can
2328  * reliably generate inauthentic messages, i.    2187  * reliably generate inauthentic messages, i.e. not generate an authentic
2329  * message by chance.                            2188  * message by chance.
2330  */                                              2189  */
2331 #define MIN_COLLISION_FREE_AUTHSIZE 8            2190 #define MIN_COLLISION_FREE_AUTHSIZE 8
2332                                                  2191 
2333 static void generate_aead_message(struct rnd_ !! 2192 static void generate_aead_message(struct aead_request *req,
2334                                   struct aead << 
2335                                   const struc    2193                                   const struct aead_test_suite *suite,
2336                                   struct aead    2194                                   struct aead_testvec *vec,
2337                                   bool prefer    2195                                   bool prefer_inauthentic)
2338 {                                                2196 {
2339         struct crypto_aead *tfm = crypto_aead    2197         struct crypto_aead *tfm = crypto_aead_reqtfm(req);
2340         const unsigned int ivsize = crypto_ae    2198         const unsigned int ivsize = crypto_aead_ivsize(tfm);
2341         const unsigned int authsize = vec->cl    2199         const unsigned int authsize = vec->clen - vec->plen;
2342         const bool inauthentic = (authsize >=    2200         const bool inauthentic = (authsize >= MIN_COLLISION_FREE_AUTHSIZE) &&
2343                                  (prefer_inau !! 2201                                  (prefer_inauthentic || prandom_u32() % 4 == 0);
2344                                   prandom_u32 << 
2345                                                  2202 
2346         /* Generate the AAD. */                  2203         /* Generate the AAD. */
2347         generate_random_bytes(rng, (u8 *)vec- !! 2204         generate_random_bytes((u8 *)vec->assoc, vec->alen);
2348         if (suite->aad_iv && vec->alen >= ivs    2205         if (suite->aad_iv && vec->alen >= ivsize)
2349                 /* Avoid implementation-defin    2206                 /* Avoid implementation-defined behavior. */
2350                 memcpy((u8 *)vec->assoc + vec    2207                 memcpy((u8 *)vec->assoc + vec->alen - ivsize, vec->iv, ivsize);
2351                                                  2208 
2352         if (inauthentic && prandom_bool(rng)) !! 2209         if (inauthentic && prandom_u32() % 2 == 0) {
2353                 /* Generate a random cipherte    2210                 /* Generate a random ciphertext. */
2354                 generate_random_bytes(rng, (u !! 2211                 generate_random_bytes((u8 *)vec->ctext, vec->clen);
2355         } else {                                 2212         } else {
2356                 int i = 0;                       2213                 int i = 0;
2357                 struct scatterlist src[2], ds    2214                 struct scatterlist src[2], dst;
2358                 u8 iv[MAX_IVLEN];                2215                 u8 iv[MAX_IVLEN];
2359                 DECLARE_CRYPTO_WAIT(wait);       2216                 DECLARE_CRYPTO_WAIT(wait);
2360                                                  2217 
2361                 /* Generate a random plaintex    2218                 /* Generate a random plaintext and encrypt it. */
2362                 sg_init_table(src, 2);           2219                 sg_init_table(src, 2);
2363                 if (vec->alen)                   2220                 if (vec->alen)
2364                         sg_set_buf(&src[i++],    2221                         sg_set_buf(&src[i++], vec->assoc, vec->alen);
2365                 if (vec->plen) {                 2222                 if (vec->plen) {
2366                         generate_random_bytes !! 2223                         generate_random_bytes((u8 *)vec->ptext, vec->plen);
2367                         sg_set_buf(&src[i++],    2224                         sg_set_buf(&src[i++], vec->ptext, vec->plen);
2368                 }                                2225                 }
2369                 sg_init_one(&dst, vec->ctext,    2226                 sg_init_one(&dst, vec->ctext, vec->alen + vec->clen);
2370                 memcpy(iv, vec->iv, ivsize);     2227                 memcpy(iv, vec->iv, ivsize);
2371                 aead_request_set_callback(req    2228                 aead_request_set_callback(req, 0, crypto_req_done, &wait);
2372                 aead_request_set_crypt(req, s    2229                 aead_request_set_crypt(req, src, &dst, vec->plen, iv);
2373                 aead_request_set_ad(req, vec-    2230                 aead_request_set_ad(req, vec->alen);
2374                 vec->crypt_error = crypto_wai    2231                 vec->crypt_error = crypto_wait_req(crypto_aead_encrypt(req),
2375                                                  2232                                                    &wait);
2376                 /* If encryption failed, we'r    2233                 /* If encryption failed, we're done. */
2377                 if (vec->crypt_error != 0)       2234                 if (vec->crypt_error != 0)
2378                         return;                  2235                         return;
2379                 memmove((u8 *)vec->ctext, vec    2236                 memmove((u8 *)vec->ctext, vec->ctext + vec->alen, vec->clen);
2380                 if (!inauthentic)                2237                 if (!inauthentic)
2381                         return;                  2238                         return;
2382                 /*                               2239                 /*
2383                  * Mutate the authentic (ciph    2240                  * Mutate the authentic (ciphertext, AAD) pair to get an
2384                  * inauthentic one.              2241                  * inauthentic one.
2385                  */                              2242                  */
2386                 mutate_aead_message(rng, vec, !! 2243                 mutate_aead_message(vec, suite->aad_iv, ivsize);
2387         }                                        2244         }
2388         vec->novrfy = 1;                         2245         vec->novrfy = 1;
2389         if (suite->einval_allowed)               2246         if (suite->einval_allowed)
2390                 vec->crypt_error = -EINVAL;      2247                 vec->crypt_error = -EINVAL;
2391 }                                                2248 }
2392                                                  2249 
2393 /*                                               2250 /*
2394  * Generate an AEAD test vector 'vec' using t    2251  * Generate an AEAD test vector 'vec' using the implementation specified by
2395  * 'req'.  The buffers in 'vec' must already     2252  * 'req'.  The buffers in 'vec' must already be allocated.
2396  *                                               2253  *
2397  * If 'prefer_inauthentic' is true, then this    2254  * If 'prefer_inauthentic' is true, then this function will generate inauthentic
2398  * test vectors (i.e. vectors with 'vec->novr    2255  * test vectors (i.e. vectors with 'vec->novrfy=1') more often.
2399  */                                              2256  */
2400 static void generate_random_aead_testvec(stru !! 2257 static void generate_random_aead_testvec(struct aead_request *req,
2401                                          stru << 
2402                                          stru    2258                                          struct aead_testvec *vec,
2403                                          cons    2259                                          const struct aead_test_suite *suite,
2404                                          unsi    2260                                          unsigned int maxkeysize,
2405                                          unsi    2261                                          unsigned int maxdatasize,
2406                                          char    2262                                          char *name, size_t max_namelen,
2407                                          bool    2263                                          bool prefer_inauthentic)
2408 {                                                2264 {
2409         struct crypto_aead *tfm = crypto_aead    2265         struct crypto_aead *tfm = crypto_aead_reqtfm(req);
2410         const unsigned int ivsize = crypto_ae    2266         const unsigned int ivsize = crypto_aead_ivsize(tfm);
2411         const unsigned int maxauthsize = cryp    2267         const unsigned int maxauthsize = crypto_aead_maxauthsize(tfm);
2412         unsigned int authsize;                   2268         unsigned int authsize;
2413         unsigned int total_len;                  2269         unsigned int total_len;
2414                                                  2270 
2415         /* Key: length in [0, maxkeysize], bu    2271         /* Key: length in [0, maxkeysize], but usually choose maxkeysize */
2416         vec->klen = maxkeysize;                  2272         vec->klen = maxkeysize;
2417         if (prandom_u32_below(rng, 4) == 0)   !! 2273         if (prandom_u32() % 4 == 0)
2418                 vec->klen = prandom_u32_below !! 2274                 vec->klen = prandom_u32() % (maxkeysize + 1);
2419         generate_random_bytes(rng, (u8 *)vec- !! 2275         generate_random_bytes((u8 *)vec->key, vec->klen);
2420         vec->setkey_error = crypto_aead_setke    2276         vec->setkey_error = crypto_aead_setkey(tfm, vec->key, vec->klen);
2421                                                  2277 
2422         /* IV */                                 2278         /* IV */
2423         generate_random_bytes(rng, (u8 *)vec- !! 2279         generate_random_bytes((u8 *)vec->iv, ivsize);
2424                                                  2280 
2425         /* Tag length: in [0, maxauthsize], b    2281         /* Tag length: in [0, maxauthsize], but usually choose maxauthsize */
2426         authsize = maxauthsize;                  2282         authsize = maxauthsize;
2427         if (prandom_u32_below(rng, 4) == 0)   !! 2283         if (prandom_u32() % 4 == 0)
2428                 authsize = prandom_u32_below( !! 2284                 authsize = prandom_u32() % (maxauthsize + 1);
2429         if (prefer_inauthentic && authsize <     2285         if (prefer_inauthentic && authsize < MIN_COLLISION_FREE_AUTHSIZE)
2430                 authsize = MIN_COLLISION_FREE    2286                 authsize = MIN_COLLISION_FREE_AUTHSIZE;
2431         if (WARN_ON(authsize > maxdatasize))     2287         if (WARN_ON(authsize > maxdatasize))
2432                 authsize = maxdatasize;          2288                 authsize = maxdatasize;
2433         maxdatasize -= authsize;                 2289         maxdatasize -= authsize;
2434         vec->setauthsize_error = crypto_aead_    2290         vec->setauthsize_error = crypto_aead_setauthsize(tfm, authsize);
2435                                                  2291 
2436         /* AAD, plaintext, and ciphertext len    2292         /* AAD, plaintext, and ciphertext lengths */
2437         total_len = generate_random_length(rn !! 2293         total_len = generate_random_length(maxdatasize);
2438         if (prandom_u32_below(rng, 4) == 0)   !! 2294         if (prandom_u32() % 4 == 0)
2439                 vec->alen = 0;                   2295                 vec->alen = 0;
2440         else                                     2296         else
2441                 vec->alen = generate_random_l !! 2297                 vec->alen = generate_random_length(total_len);
2442         vec->plen = total_len - vec->alen;       2298         vec->plen = total_len - vec->alen;
2443         vec->clen = vec->plen + authsize;        2299         vec->clen = vec->plen + authsize;
2444                                                  2300 
2445         /*                                       2301         /*
2446          * Generate the AAD, plaintext, and c    2302          * Generate the AAD, plaintext, and ciphertext.  Not applicable if the
2447          * key or the authentication tag size    2303          * key or the authentication tag size couldn't be set.
2448          */                                      2304          */
2449         vec->novrfy = 0;                         2305         vec->novrfy = 0;
2450         vec->crypt_error = 0;                    2306         vec->crypt_error = 0;
2451         if (vec->setkey_error == 0 && vec->se    2307         if (vec->setkey_error == 0 && vec->setauthsize_error == 0)
2452                 generate_aead_message(rng, re !! 2308                 generate_aead_message(req, suite, vec, prefer_inauthentic);
2453         snprintf(name, max_namelen,              2309         snprintf(name, max_namelen,
2454                  "\"random: alen=%u plen=%u a    2310                  "\"random: alen=%u plen=%u authsize=%u klen=%u novrfy=%d\"",
2455                  vec->alen, vec->plen, authsi    2311                  vec->alen, vec->plen, authsize, vec->klen, vec->novrfy);
2456 }                                                2312 }
2457                                                  2313 
2458 static void try_to_generate_inauthentic_testv    2314 static void try_to_generate_inauthentic_testvec(
2459                                         struc    2315                                         struct aead_extra_tests_ctx *ctx)
2460 {                                                2316 {
2461         int i;                                   2317         int i;
2462                                                  2318 
2463         for (i = 0; i < 10; i++) {               2319         for (i = 0; i < 10; i++) {
2464                 generate_random_aead_testvec( !! 2320                 generate_random_aead_testvec(ctx->req, &ctx->vec,
2465                                                  2321                                              &ctx->test_desc->suite.aead,
2466                                                  2322                                              ctx->maxkeysize, ctx->maxdatasize,
2467                                                  2323                                              ctx->vec_name,
2468                                                  2324                                              sizeof(ctx->vec_name), true);
2469                 if (ctx->vec.novrfy)             2325                 if (ctx->vec.novrfy)
2470                         return;                  2326                         return;
2471         }                                        2327         }
2472 }                                                2328 }
2473                                                  2329 
2474 /*                                               2330 /*
2475  * Generate inauthentic test vectors (i.e. ci    2331  * Generate inauthentic test vectors (i.e. ciphertext, AAD pairs that aren't the
2476  * result of an encryption with the key) and     2332  * result of an encryption with the key) and verify that decryption fails.
2477  */                                              2333  */
2478 static int test_aead_inauthentic_inputs(struc    2334 static int test_aead_inauthentic_inputs(struct aead_extra_tests_ctx *ctx)
2479 {                                                2335 {
2480         unsigned int i;                          2336         unsigned int i;
2481         int err;                                 2337         int err;
2482                                                  2338 
2483         for (i = 0; i < fuzz_iterations * 8;     2339         for (i = 0; i < fuzz_iterations * 8; i++) {
2484                 /*                               2340                 /*
2485                  * Since this part of the tes    2341                  * Since this part of the tests isn't comparing the
2486                  * implementation to another,    2342                  * implementation to another, there's no point in testing any
2487                  * test vectors other than in    2343                  * test vectors other than inauthentic ones (vec.novrfy=1) here.
2488                  *                               2344                  *
2489                  * If we're having trouble ge    2345                  * If we're having trouble generating such a test vector, e.g.
2490                  * if the algorithm keeps rej    2346                  * if the algorithm keeps rejecting the generated keys, don't
2491                  * retry forever; just contin    2347                  * retry forever; just continue on.
2492                  */                              2348                  */
2493                 try_to_generate_inauthentic_t    2349                 try_to_generate_inauthentic_testvec(ctx);
2494                 if (ctx->vec.novrfy) {           2350                 if (ctx->vec.novrfy) {
2495                         generate_random_testv !! 2351                         generate_random_testvec_config(&ctx->cfg, ctx->cfgname,
2496                                               << 
2497                                                  2352                                                        sizeof(ctx->cfgname));
2498                         err = test_aead_vec_c    2353                         err = test_aead_vec_cfg(DECRYPT, &ctx->vec,
2499                                                  2354                                                 ctx->vec_name, &ctx->cfg,
2500                                                  2355                                                 ctx->req, ctx->tsgls);
2501                         if (err)                 2356                         if (err)
2502                                 return err;      2357                                 return err;
2503                 }                                2358                 }
2504                 cond_resched();                  2359                 cond_resched();
2505         }                                        2360         }
2506         return 0;                                2361         return 0;
2507 }                                                2362 }
2508                                                  2363 
2509 /*                                               2364 /*
2510  * Test the AEAD algorithm against the corres    2365  * Test the AEAD algorithm against the corresponding generic implementation, if
2511  * one is available.                             2366  * one is available.
2512  */                                              2367  */
2513 static int test_aead_vs_generic_impl(struct a    2368 static int test_aead_vs_generic_impl(struct aead_extra_tests_ctx *ctx)
2514 {                                                2369 {
2515         struct crypto_aead *tfm = ctx->tfm;      2370         struct crypto_aead *tfm = ctx->tfm;
2516         const char *algname = crypto_aead_alg    2371         const char *algname = crypto_aead_alg(tfm)->base.cra_name;
2517         const char *driver = crypto_aead_driv    2372         const char *driver = crypto_aead_driver_name(tfm);
2518         const char *generic_driver = ctx->tes    2373         const char *generic_driver = ctx->test_desc->generic_driver;
2519         char _generic_driver[CRYPTO_MAX_ALG_N    2374         char _generic_driver[CRYPTO_MAX_ALG_NAME];
2520         struct crypto_aead *generic_tfm = NUL    2375         struct crypto_aead *generic_tfm = NULL;
2521         struct aead_request *generic_req = NU    2376         struct aead_request *generic_req = NULL;
2522         unsigned int i;                          2377         unsigned int i;
2523         int err;                                 2378         int err;
2524                                                  2379 
2525         if (!generic_driver) { /* Use default    2380         if (!generic_driver) { /* Use default naming convention? */
2526                 err = build_generic_driver_na    2381                 err = build_generic_driver_name(algname, _generic_driver);
2527                 if (err)                         2382                 if (err)
2528                         return err;              2383                         return err;
2529                 generic_driver = _generic_dri    2384                 generic_driver = _generic_driver;
2530         }                                        2385         }
2531                                                  2386 
2532         if (strcmp(generic_driver, driver) ==    2387         if (strcmp(generic_driver, driver) == 0) /* Already the generic impl? */
2533                 return 0;                        2388                 return 0;
2534                                                  2389 
2535         generic_tfm = crypto_alloc_aead(gener    2390         generic_tfm = crypto_alloc_aead(generic_driver, 0, 0);
2536         if (IS_ERR(generic_tfm)) {               2391         if (IS_ERR(generic_tfm)) {
2537                 err = PTR_ERR(generic_tfm);      2392                 err = PTR_ERR(generic_tfm);
2538                 if (err == -ENOENT) {            2393                 if (err == -ENOENT) {
2539                         pr_warn("alg: aead: s    2394                         pr_warn("alg: aead: skipping comparison tests for %s because %s is unavailable\n",
2540                                 driver, gener    2395                                 driver, generic_driver);
2541                         return 0;                2396                         return 0;
2542                 }                                2397                 }
2543                 pr_err("alg: aead: error allo    2398                 pr_err("alg: aead: error allocating %s (generic impl of %s): %d\n",
2544                        generic_driver, algnam    2399                        generic_driver, algname, err);
2545                 return err;                      2400                 return err;
2546         }                                        2401         }
2547                                                  2402 
2548         generic_req = aead_request_alloc(gene    2403         generic_req = aead_request_alloc(generic_tfm, GFP_KERNEL);
2549         if (!generic_req) {                      2404         if (!generic_req) {
2550                 err = -ENOMEM;                   2405                 err = -ENOMEM;
2551                 goto out;                        2406                 goto out;
2552         }                                        2407         }
2553                                                  2408 
2554         /* Check the algorithm properties for    2409         /* Check the algorithm properties for consistency. */
2555                                                  2410 
2556         if (crypto_aead_maxauthsize(tfm) !=      2411         if (crypto_aead_maxauthsize(tfm) !=
2557             crypto_aead_maxauthsize(generic_t    2412             crypto_aead_maxauthsize(generic_tfm)) {
2558                 pr_err("alg: aead: maxauthsiz    2413                 pr_err("alg: aead: maxauthsize for %s (%u) doesn't match generic impl (%u)\n",
2559                        driver, crypto_aead_ma    2414                        driver, crypto_aead_maxauthsize(tfm),
2560                        crypto_aead_maxauthsiz    2415                        crypto_aead_maxauthsize(generic_tfm));
2561                 err = -EINVAL;                   2416                 err = -EINVAL;
2562                 goto out;                        2417                 goto out;
2563         }                                        2418         }
2564                                                  2419 
2565         if (crypto_aead_ivsize(tfm) != crypto    2420         if (crypto_aead_ivsize(tfm) != crypto_aead_ivsize(generic_tfm)) {
2566                 pr_err("alg: aead: ivsize for    2421                 pr_err("alg: aead: ivsize for %s (%u) doesn't match generic impl (%u)\n",
2567                        driver, crypto_aead_iv    2422                        driver, crypto_aead_ivsize(tfm),
2568                        crypto_aead_ivsize(gen    2423                        crypto_aead_ivsize(generic_tfm));
2569                 err = -EINVAL;                   2424                 err = -EINVAL;
2570                 goto out;                        2425                 goto out;
2571         }                                        2426         }
2572                                                  2427 
2573         if (crypto_aead_blocksize(tfm) != cry    2428         if (crypto_aead_blocksize(tfm) != crypto_aead_blocksize(generic_tfm)) {
2574                 pr_err("alg: aead: blocksize     2429                 pr_err("alg: aead: blocksize for %s (%u) doesn't match generic impl (%u)\n",
2575                        driver, crypto_aead_bl    2430                        driver, crypto_aead_blocksize(tfm),
2576                        crypto_aead_blocksize(    2431                        crypto_aead_blocksize(generic_tfm));
2577                 err = -EINVAL;                   2432                 err = -EINVAL;
2578                 goto out;                        2433                 goto out;
2579         }                                        2434         }
2580                                                  2435 
2581         /*                                       2436         /*
2582          * Now generate test vectors using th    2437          * Now generate test vectors using the generic implementation, and test
2583          * the other implementation against t    2438          * the other implementation against them.
2584          */                                      2439          */
2585         for (i = 0; i < fuzz_iterations * 8;     2440         for (i = 0; i < fuzz_iterations * 8; i++) {
2586                 generate_random_aead_testvec( !! 2441                 generate_random_aead_testvec(generic_req, &ctx->vec,
2587                                                  2442                                              &ctx->test_desc->suite.aead,
2588                                                  2443                                              ctx->maxkeysize, ctx->maxdatasize,
2589                                                  2444                                              ctx->vec_name,
2590                                                  2445                                              sizeof(ctx->vec_name), false);
2591                 generate_random_testvec_confi !! 2446                 generate_random_testvec_config(&ctx->cfg, ctx->cfgname,
2592                                               << 
2593                                                  2447                                                sizeof(ctx->cfgname));
2594                 if (!ctx->vec.novrfy) {          2448                 if (!ctx->vec.novrfy) {
2595                         err = test_aead_vec_c    2449                         err = test_aead_vec_cfg(ENCRYPT, &ctx->vec,
2596                                                  2450                                                 ctx->vec_name, &ctx->cfg,
2597                                                  2451                                                 ctx->req, ctx->tsgls);
2598                         if (err)                 2452                         if (err)
2599                                 goto out;        2453                                 goto out;
2600                 }                                2454                 }
2601                 if (ctx->vec.crypt_error == 0    2455                 if (ctx->vec.crypt_error == 0 || ctx->vec.novrfy) {
2602                         err = test_aead_vec_c    2456                         err = test_aead_vec_cfg(DECRYPT, &ctx->vec,
2603                                                  2457                                                 ctx->vec_name, &ctx->cfg,
2604                                                  2458                                                 ctx->req, ctx->tsgls);
2605                         if (err)                 2459                         if (err)
2606                                 goto out;        2460                                 goto out;
2607                 }                                2461                 }
2608                 cond_resched();                  2462                 cond_resched();
2609         }                                        2463         }
2610         err = 0;                                 2464         err = 0;
2611 out:                                             2465 out:
2612         crypto_free_aead(generic_tfm);           2466         crypto_free_aead(generic_tfm);
2613         aead_request_free(generic_req);          2467         aead_request_free(generic_req);
2614         return err;                              2468         return err;
2615 }                                                2469 }
2616                                                  2470 
2617 static int test_aead_extra(const struct alg_t    2471 static int test_aead_extra(const struct alg_test_desc *test_desc,
2618                            struct aead_reques    2472                            struct aead_request *req,
2619                            struct cipher_test    2473                            struct cipher_test_sglists *tsgls)
2620 {                                                2474 {
2621         struct aead_extra_tests_ctx *ctx;        2475         struct aead_extra_tests_ctx *ctx;
2622         unsigned int i;                          2476         unsigned int i;
2623         int err;                                 2477         int err;
2624                                                  2478 
2625         if (noextratests)                        2479         if (noextratests)
2626                 return 0;                        2480                 return 0;
2627                                                  2481 
2628         ctx = kzalloc(sizeof(*ctx), GFP_KERNE    2482         ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
2629         if (!ctx)                                2483         if (!ctx)
2630                 return -ENOMEM;                  2484                 return -ENOMEM;
2631         init_rnd_state(&ctx->rng);            << 
2632         ctx->req = req;                          2485         ctx->req = req;
2633         ctx->tfm = crypto_aead_reqtfm(req);      2486         ctx->tfm = crypto_aead_reqtfm(req);
2634         ctx->test_desc = test_desc;              2487         ctx->test_desc = test_desc;
2635         ctx->tsgls = tsgls;                      2488         ctx->tsgls = tsgls;
2636         ctx->maxdatasize = (2 * PAGE_SIZE) -     2489         ctx->maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN;
2637         ctx->maxkeysize = 0;                     2490         ctx->maxkeysize = 0;
2638         for (i = 0; i < test_desc->suite.aead    2491         for (i = 0; i < test_desc->suite.aead.count; i++)
2639                 ctx->maxkeysize = max_t(unsig    2492                 ctx->maxkeysize = max_t(unsigned int, ctx->maxkeysize,
2640                                         test_    2493                                         test_desc->suite.aead.vecs[i].klen);
2641                                                  2494 
2642         ctx->vec.key = kmalloc(ctx->maxkeysiz    2495         ctx->vec.key = kmalloc(ctx->maxkeysize, GFP_KERNEL);
2643         ctx->vec.iv = kmalloc(crypto_aead_ivs    2496         ctx->vec.iv = kmalloc(crypto_aead_ivsize(ctx->tfm), GFP_KERNEL);
2644         ctx->vec.assoc = kmalloc(ctx->maxdata    2497         ctx->vec.assoc = kmalloc(ctx->maxdatasize, GFP_KERNEL);
2645         ctx->vec.ptext = kmalloc(ctx->maxdata    2498         ctx->vec.ptext = kmalloc(ctx->maxdatasize, GFP_KERNEL);
2646         ctx->vec.ctext = kmalloc(ctx->maxdata    2499         ctx->vec.ctext = kmalloc(ctx->maxdatasize, GFP_KERNEL);
2647         if (!ctx->vec.key || !ctx->vec.iv ||     2500         if (!ctx->vec.key || !ctx->vec.iv || !ctx->vec.assoc ||
2648             !ctx->vec.ptext || !ctx->vec.ctex    2501             !ctx->vec.ptext || !ctx->vec.ctext) {
2649                 err = -ENOMEM;                   2502                 err = -ENOMEM;
2650                 goto out;                        2503                 goto out;
2651         }                                        2504         }
2652                                                  2505 
2653         err = test_aead_vs_generic_impl(ctx);    2506         err = test_aead_vs_generic_impl(ctx);
2654         if (err)                                 2507         if (err)
2655                 goto out;                        2508                 goto out;
2656                                                  2509 
2657         err = test_aead_inauthentic_inputs(ct    2510         err = test_aead_inauthentic_inputs(ctx);
2658 out:                                             2511 out:
2659         kfree(ctx->vec.key);                     2512         kfree(ctx->vec.key);
2660         kfree(ctx->vec.iv);                      2513         kfree(ctx->vec.iv);
2661         kfree(ctx->vec.assoc);                   2514         kfree(ctx->vec.assoc);
2662         kfree(ctx->vec.ptext);                   2515         kfree(ctx->vec.ptext);
2663         kfree(ctx->vec.ctext);                   2516         kfree(ctx->vec.ctext);
2664         kfree(ctx);                              2517         kfree(ctx);
2665         return err;                              2518         return err;
2666 }                                                2519 }
2667 #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS *    2520 #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
2668 static int test_aead_extra(const struct alg_t    2521 static int test_aead_extra(const struct alg_test_desc *test_desc,
2669                            struct aead_reques    2522                            struct aead_request *req,
2670                            struct cipher_test    2523                            struct cipher_test_sglists *tsgls)
2671 {                                                2524 {
2672         return 0;                                2525         return 0;
2673 }                                                2526 }
2674 #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS     2527 #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
2675                                                  2528 
2676 static int test_aead(int enc, const struct ae    2529 static int test_aead(int enc, const struct aead_test_suite *suite,
2677                      struct aead_request *req    2530                      struct aead_request *req,
2678                      struct cipher_test_sglis    2531                      struct cipher_test_sglists *tsgls)
2679 {                                                2532 {
2680         unsigned int i;                          2533         unsigned int i;
2681         int err;                                 2534         int err;
2682                                                  2535 
2683         for (i = 0; i < suite->count; i++) {     2536         for (i = 0; i < suite->count; i++) {
2684                 err = test_aead_vec(enc, &sui    2537                 err = test_aead_vec(enc, &suite->vecs[i], i, req, tsgls);
2685                 if (err)                         2538                 if (err)
2686                         return err;              2539                         return err;
2687                 cond_resched();                  2540                 cond_resched();
2688         }                                        2541         }
2689         return 0;                                2542         return 0;
2690 }                                                2543 }
2691                                                  2544 
2692 static int alg_test_aead(const struct alg_tes    2545 static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
2693                          u32 type, u32 mask)     2546                          u32 type, u32 mask)
2694 {                                                2547 {
2695         const struct aead_test_suite *suite =    2548         const struct aead_test_suite *suite = &desc->suite.aead;
2696         struct crypto_aead *tfm;                 2549         struct crypto_aead *tfm;
2697         struct aead_request *req = NULL;         2550         struct aead_request *req = NULL;
2698         struct cipher_test_sglists *tsgls = N    2551         struct cipher_test_sglists *tsgls = NULL;
2699         int err;                                 2552         int err;
2700                                                  2553 
2701         if (suite->count <= 0) {                 2554         if (suite->count <= 0) {
2702                 pr_err("alg: aead: empty test    2555                 pr_err("alg: aead: empty test suite for %s\n", driver);
2703                 return -EINVAL;                  2556                 return -EINVAL;
2704         }                                        2557         }
2705                                                  2558 
2706         tfm = crypto_alloc_aead(driver, type,    2559         tfm = crypto_alloc_aead(driver, type, mask);
2707         if (IS_ERR(tfm)) {                       2560         if (IS_ERR(tfm)) {
2708                 if (PTR_ERR(tfm) == -ENOENT)  << 
2709                         return 0;             << 
2710                 pr_err("alg: aead: failed to     2561                 pr_err("alg: aead: failed to allocate transform for %s: %ld\n",
2711                        driver, PTR_ERR(tfm));    2562                        driver, PTR_ERR(tfm));
2712                 return PTR_ERR(tfm);             2563                 return PTR_ERR(tfm);
2713         }                                        2564         }
2714         driver = crypto_aead_driver_name(tfm)    2565         driver = crypto_aead_driver_name(tfm);
2715                                                  2566 
2716         req = aead_request_alloc(tfm, GFP_KER    2567         req = aead_request_alloc(tfm, GFP_KERNEL);
2717         if (!req) {                              2568         if (!req) {
2718                 pr_err("alg: aead: failed to     2569                 pr_err("alg: aead: failed to allocate request for %s\n",
2719                        driver);                  2570                        driver);
2720                 err = -ENOMEM;                   2571                 err = -ENOMEM;
2721                 goto out;                        2572                 goto out;
2722         }                                        2573         }
2723                                                  2574 
2724         tsgls = alloc_cipher_test_sglists();     2575         tsgls = alloc_cipher_test_sglists();
2725         if (!tsgls) {                            2576         if (!tsgls) {
2726                 pr_err("alg: aead: failed to     2577                 pr_err("alg: aead: failed to allocate test buffers for %s\n",
2727                        driver);                  2578                        driver);
2728                 err = -ENOMEM;                   2579                 err = -ENOMEM;
2729                 goto out;                        2580                 goto out;
2730         }                                        2581         }
2731                                                  2582 
2732         err = test_aead(ENCRYPT, suite, req,     2583         err = test_aead(ENCRYPT, suite, req, tsgls);
2733         if (err)                                 2584         if (err)
2734                 goto out;                        2585                 goto out;
2735                                                  2586 
2736         err = test_aead(DECRYPT, suite, req,     2587         err = test_aead(DECRYPT, suite, req, tsgls);
2737         if (err)                                 2588         if (err)
2738                 goto out;                        2589                 goto out;
2739                                                  2590 
2740         err = test_aead_extra(desc, req, tsgl    2591         err = test_aead_extra(desc, req, tsgls);
2741 out:                                             2592 out:
2742         free_cipher_test_sglists(tsgls);         2593         free_cipher_test_sglists(tsgls);
2743         aead_request_free(req);                  2594         aead_request_free(req);
2744         crypto_free_aead(tfm);                   2595         crypto_free_aead(tfm);
2745         return err;                              2596         return err;
2746 }                                                2597 }
2747                                                  2598 
2748 static int test_cipher(struct crypto_cipher *    2599 static int test_cipher(struct crypto_cipher *tfm, int enc,
2749                        const struct cipher_te    2600                        const struct cipher_testvec *template,
2750                        unsigned int tcount)      2601                        unsigned int tcount)
2751 {                                                2602 {
2752         const char *algo = crypto_tfm_alg_dri    2603         const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
2753         unsigned int i, j, k;                    2604         unsigned int i, j, k;
2754         char *q;                                 2605         char *q;
2755         const char *e;                           2606         const char *e;
2756         const char *input, *result;              2607         const char *input, *result;
2757         void *data;                              2608         void *data;
2758         char *xbuf[XBUFSIZE];                    2609         char *xbuf[XBUFSIZE];
2759         int ret = -ENOMEM;                       2610         int ret = -ENOMEM;
2760                                                  2611 
2761         if (testmgr_alloc_buf(xbuf))             2612         if (testmgr_alloc_buf(xbuf))
2762                 goto out_nobuf;                  2613                 goto out_nobuf;
2763                                                  2614 
2764         if (enc == ENCRYPT)                      2615         if (enc == ENCRYPT)
2765                 e = "encryption";                2616                 e = "encryption";
2766         else                                     2617         else
2767                 e = "decryption";                2618                 e = "decryption";
2768                                                  2619 
2769         j = 0;                                   2620         j = 0;
2770         for (i = 0; i < tcount; i++) {           2621         for (i = 0; i < tcount; i++) {
2771                                                  2622 
2772                 if (fips_enabled && template[    2623                 if (fips_enabled && template[i].fips_skip)
2773                         continue;                2624                         continue;
2774                                                  2625 
2775                 input  = enc ? template[i].pt    2626                 input  = enc ? template[i].ptext : template[i].ctext;
2776                 result = enc ? template[i].ct    2627                 result = enc ? template[i].ctext : template[i].ptext;
2777                 j++;                             2628                 j++;
2778                                                  2629 
2779                 ret = -EINVAL;                   2630                 ret = -EINVAL;
2780                 if (WARN_ON(template[i].len >    2631                 if (WARN_ON(template[i].len > PAGE_SIZE))
2781                         goto out;                2632                         goto out;
2782                                                  2633 
2783                 data = xbuf[0];                  2634                 data = xbuf[0];
2784                 memcpy(data, input, template[    2635                 memcpy(data, input, template[i].len);
2785                                                  2636 
2786                 crypto_cipher_clear_flags(tfm    2637                 crypto_cipher_clear_flags(tfm, ~0);
2787                 if (template[i].wk)              2638                 if (template[i].wk)
2788                         crypto_cipher_set_fla    2639                         crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
2789                                                  2640 
2790                 ret = crypto_cipher_setkey(tf    2641                 ret = crypto_cipher_setkey(tfm, template[i].key,
2791                                            te    2642                                            template[i].klen);
2792                 if (ret) {                       2643                 if (ret) {
2793                         if (ret == template[i    2644                         if (ret == template[i].setkey_error)
2794                                 continue;        2645                                 continue;
2795                         pr_err("alg: cipher:     2646                         pr_err("alg: cipher: %s setkey failed on test vector %u; expected_error=%d, actual_error=%d, flags=%#x\n",
2796                                algo, j, templ    2647                                algo, j, template[i].setkey_error, ret,
2797                                crypto_cipher_    2648                                crypto_cipher_get_flags(tfm));
2798                         goto out;                2649                         goto out;
2799                 }                                2650                 }
2800                 if (template[i].setkey_error)    2651                 if (template[i].setkey_error) {
2801                         pr_err("alg: cipher:     2652                         pr_err("alg: cipher: %s setkey unexpectedly succeeded on test vector %u; expected_error=%d\n",
2802                                algo, j, templ    2653                                algo, j, template[i].setkey_error);
2803                         ret = -EINVAL;           2654                         ret = -EINVAL;
2804                         goto out;                2655                         goto out;
2805                 }                                2656                 }
2806                                                  2657 
2807                 for (k = 0; k < template[i].l    2658                 for (k = 0; k < template[i].len;
2808                      k += crypto_cipher_block    2659                      k += crypto_cipher_blocksize(tfm)) {
2809                         if (enc)                 2660                         if (enc)
2810                                 crypto_cipher    2661                                 crypto_cipher_encrypt_one(tfm, data + k,
2811                                                  2662                                                           data + k);
2812                         else                     2663                         else
2813                                 crypto_cipher    2664                                 crypto_cipher_decrypt_one(tfm, data + k,
2814                                                  2665                                                           data + k);
2815                 }                                2666                 }
2816                                                  2667 
2817                 q = data;                        2668                 q = data;
2818                 if (memcmp(q, result, templat    2669                 if (memcmp(q, result, template[i].len)) {
2819                         printk(KERN_ERR "alg:    2670                         printk(KERN_ERR "alg: cipher: Test %d failed "
2820                                "on %s for %s\    2671                                "on %s for %s\n", j, e, algo);
2821                         hexdump(q, template[i    2672                         hexdump(q, template[i].len);
2822                         ret = -EINVAL;           2673                         ret = -EINVAL;
2823                         goto out;                2674                         goto out;
2824                 }                                2675                 }
2825         }                                        2676         }
2826                                                  2677 
2827         ret = 0;                                 2678         ret = 0;
2828                                                  2679 
2829 out:                                             2680 out:
2830         testmgr_free_buf(xbuf);                  2681         testmgr_free_buf(xbuf);
2831 out_nobuf:                                       2682 out_nobuf:
2832         return ret;                              2683         return ret;
2833 }                                                2684 }
2834                                                  2685 
2835 static int test_skcipher_vec_cfg(int enc, con    2686 static int test_skcipher_vec_cfg(int enc, const struct cipher_testvec *vec,
2836                                  const char *    2687                                  const char *vec_name,
2837                                  const struct    2688                                  const struct testvec_config *cfg,
2838                                  struct skcip    2689                                  struct skcipher_request *req,
2839                                  struct ciphe    2690                                  struct cipher_test_sglists *tsgls)
2840 {                                                2691 {
2841         struct crypto_skcipher *tfm = crypto_    2692         struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
2842         const unsigned int alignmask = crypto    2693         const unsigned int alignmask = crypto_skcipher_alignmask(tfm);
2843         const unsigned int ivsize = crypto_sk    2694         const unsigned int ivsize = crypto_skcipher_ivsize(tfm);
2844         const char *driver = crypto_skcipher_    2695         const char *driver = crypto_skcipher_driver_name(tfm);
2845         const u32 req_flags = CRYPTO_TFM_REQ_    2696         const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
2846         const char *op = enc ? "encryption" :    2697         const char *op = enc ? "encryption" : "decryption";
2847         DECLARE_CRYPTO_WAIT(wait);               2698         DECLARE_CRYPTO_WAIT(wait);
2848         u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1)    2699         u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN];
2849         u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_    2700         u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) +
2850                  cfg->iv_offset +                2701                  cfg->iv_offset +
2851                  (cfg->iv_offset_relative_to_    2702                  (cfg->iv_offset_relative_to_alignmask ? alignmask : 0);
2852         struct kvec input;                       2703         struct kvec input;
2853         int err;                                 2704         int err;
2854                                                  2705 
2855         /* Set the key */                        2706         /* Set the key */
2856         if (vec->wk)                             2707         if (vec->wk)
2857                 crypto_skcipher_set_flags(tfm    2708                 crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
2858         else                                     2709         else
2859                 crypto_skcipher_clear_flags(t    2710                 crypto_skcipher_clear_flags(tfm,
2860                                             C    2711                                             CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
2861         err = do_setkey(crypto_skcipher_setke    2712         err = do_setkey(crypto_skcipher_setkey, tfm, vec->key, vec->klen,
2862                         cfg, alignmask);         2713                         cfg, alignmask);
2863         if (err) {                               2714         if (err) {
2864                 if (err == vec->setkey_error)    2715                 if (err == vec->setkey_error)
2865                         return 0;                2716                         return 0;
2866                 pr_err("alg: skcipher: %s set    2717                 pr_err("alg: skcipher: %s setkey failed on test vector %s; expected_error=%d, actual_error=%d, flags=%#x\n",
2867                        driver, vec_name, vec-    2718                        driver, vec_name, vec->setkey_error, err,
2868                        crypto_skcipher_get_fl    2719                        crypto_skcipher_get_flags(tfm));
2869                 return err;                      2720                 return err;
2870         }                                        2721         }
2871         if (vec->setkey_error) {                 2722         if (vec->setkey_error) {
2872                 pr_err("alg: skcipher: %s set    2723                 pr_err("alg: skcipher: %s setkey unexpectedly succeeded on test vector %s; expected_error=%d\n",
2873                        driver, vec_name, vec-    2724                        driver, vec_name, vec->setkey_error);
2874                 return -EINVAL;                  2725                 return -EINVAL;
2875         }                                        2726         }
2876                                                  2727 
2877         /* The IV must be copied to a buffer,    2728         /* The IV must be copied to a buffer, as the algorithm may modify it */
2878         if (ivsize) {                            2729         if (ivsize) {
2879                 if (WARN_ON(ivsize > MAX_IVLE    2730                 if (WARN_ON(ivsize > MAX_IVLEN))
2880                         return -EINVAL;          2731                         return -EINVAL;
2881                 if (vec->generates_iv && !enc    2732                 if (vec->generates_iv && !enc)
2882                         memcpy(iv, vec->iv_ou    2733                         memcpy(iv, vec->iv_out, ivsize);
2883                 else if (vec->iv)                2734                 else if (vec->iv)
2884                         memcpy(iv, vec->iv, i    2735                         memcpy(iv, vec->iv, ivsize);
2885                 else                             2736                 else
2886                         memset(iv, 0, ivsize)    2737                         memset(iv, 0, ivsize);
2887         } else {                                 2738         } else {
2888                 if (vec->generates_iv) {         2739                 if (vec->generates_iv) {
2889                         pr_err("alg: skcipher    2740                         pr_err("alg: skcipher: %s has ivsize=0 but test vector %s generates IV!\n",
2890                                driver, vec_na    2741                                driver, vec_name);
2891                         return -EINVAL;          2742                         return -EINVAL;
2892                 }                                2743                 }
2893                 iv = NULL;                       2744                 iv = NULL;
2894         }                                        2745         }
2895                                                  2746 
2896         /* Build the src/dst scatterlists */     2747         /* Build the src/dst scatterlists */
2897         input.iov_base = enc ? (void *)vec->p    2748         input.iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext;
2898         input.iov_len = vec->len;                2749         input.iov_len = vec->len;
2899         err = build_cipher_test_sglists(tsgls    2750         err = build_cipher_test_sglists(tsgls, cfg, alignmask,
2900                                         vec->    2751                                         vec->len, vec->len, &input, 1);
2901         if (err) {                               2752         if (err) {
2902                 pr_err("alg: skcipher: %s %s:    2753                 pr_err("alg: skcipher: %s %s: error preparing scatterlists for test vector %s, cfg=\"%s\"\n",
2903                        driver, op, vec_name,     2754                        driver, op, vec_name, cfg->name);
2904                 return err;                      2755                 return err;
2905         }                                        2756         }
2906                                                  2757 
2907         /* Do the actual encryption or decryp    2758         /* Do the actual encryption or decryption */
2908         testmgr_poison(req->__ctx, crypto_skc    2759         testmgr_poison(req->__ctx, crypto_skcipher_reqsize(tfm));
2909         skcipher_request_set_callback(req, re    2760         skcipher_request_set_callback(req, req_flags, crypto_req_done, &wait);
2910         skcipher_request_set_crypt(req, tsgls    2761         skcipher_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr,
2911                                    vec->len,     2762                                    vec->len, iv);
2912         if (cfg->nosimd)                         2763         if (cfg->nosimd)
2913                 crypto_disable_simd_for_test(    2764                 crypto_disable_simd_for_test();
2914         err = enc ? crypto_skcipher_encrypt(r    2765         err = enc ? crypto_skcipher_encrypt(req) : crypto_skcipher_decrypt(req);
2915         if (cfg->nosimd)                         2766         if (cfg->nosimd)
2916                 crypto_reenable_simd_for_test    2767                 crypto_reenable_simd_for_test();
2917         err = crypto_wait_req(err, &wait);       2768         err = crypto_wait_req(err, &wait);
2918                                                  2769 
2919         /* Check that the algorithm didn't ov    2770         /* Check that the algorithm didn't overwrite things it shouldn't have */
2920         if (req->cryptlen != vec->len ||         2771         if (req->cryptlen != vec->len ||
2921             req->iv != iv ||                     2772             req->iv != iv ||
2922             req->src != tsgls->src.sgl_ptr ||    2773             req->src != tsgls->src.sgl_ptr ||
2923             req->dst != tsgls->dst.sgl_ptr ||    2774             req->dst != tsgls->dst.sgl_ptr ||
2924             crypto_skcipher_reqtfm(req) != tf    2775             crypto_skcipher_reqtfm(req) != tfm ||
2925             req->base.complete != crypto_req_    2776             req->base.complete != crypto_req_done ||
2926             req->base.flags != req_flags ||      2777             req->base.flags != req_flags ||
2927             req->base.data != &wait) {           2778             req->base.data != &wait) {
2928                 pr_err("alg: skcipher: %s %s     2779                 pr_err("alg: skcipher: %s %s corrupted request struct on test vector %s, cfg=\"%s\"\n",
2929                        driver, op, vec_name,     2780                        driver, op, vec_name, cfg->name);
2930                 if (req->cryptlen != vec->len    2781                 if (req->cryptlen != vec->len)
2931                         pr_err("alg: skcipher    2782                         pr_err("alg: skcipher: changed 'req->cryptlen'\n");
2932                 if (req->iv != iv)               2783                 if (req->iv != iv)
2933                         pr_err("alg: skcipher    2784                         pr_err("alg: skcipher: changed 'req->iv'\n");
2934                 if (req->src != tsgls->src.sg    2785                 if (req->src != tsgls->src.sgl_ptr)
2935                         pr_err("alg: skcipher    2786                         pr_err("alg: skcipher: changed 'req->src'\n");
2936                 if (req->dst != tsgls->dst.sg    2787                 if (req->dst != tsgls->dst.sgl_ptr)
2937                         pr_err("alg: skcipher    2788                         pr_err("alg: skcipher: changed 'req->dst'\n");
2938                 if (crypto_skcipher_reqtfm(re    2789                 if (crypto_skcipher_reqtfm(req) != tfm)
2939                         pr_err("alg: skcipher    2790                         pr_err("alg: skcipher: changed 'req->base.tfm'\n");
2940                 if (req->base.complete != cry    2791                 if (req->base.complete != crypto_req_done)
2941                         pr_err("alg: skcipher    2792                         pr_err("alg: skcipher: changed 'req->base.complete'\n");
2942                 if (req->base.flags != req_fl    2793                 if (req->base.flags != req_flags)
2943                         pr_err("alg: skcipher    2794                         pr_err("alg: skcipher: changed 'req->base.flags'\n");
2944                 if (req->base.data != &wait)     2795                 if (req->base.data != &wait)
2945                         pr_err("alg: skcipher    2796                         pr_err("alg: skcipher: changed 'req->base.data'\n");
2946                 return -EINVAL;                  2797                 return -EINVAL;
2947         }                                        2798         }
2948         if (is_test_sglist_corrupted(&tsgls->    2799         if (is_test_sglist_corrupted(&tsgls->src)) {
2949                 pr_err("alg: skcipher: %s %s     2800                 pr_err("alg: skcipher: %s %s corrupted src sgl on test vector %s, cfg=\"%s\"\n",
2950                        driver, op, vec_name,     2801                        driver, op, vec_name, cfg->name);
2951                 return -EINVAL;                  2802                 return -EINVAL;
2952         }                                        2803         }
2953         if (tsgls->dst.sgl_ptr != tsgls->src.    2804         if (tsgls->dst.sgl_ptr != tsgls->src.sgl &&
2954             is_test_sglist_corrupted(&tsgls->    2805             is_test_sglist_corrupted(&tsgls->dst)) {
2955                 pr_err("alg: skcipher: %s %s     2806                 pr_err("alg: skcipher: %s %s corrupted dst sgl on test vector %s, cfg=\"%s\"\n",
2956                        driver, op, vec_name,     2807                        driver, op, vec_name, cfg->name);
2957                 return -EINVAL;                  2808                 return -EINVAL;
2958         }                                        2809         }
2959                                                  2810 
2960         /* Check for success or failure */       2811         /* Check for success or failure */
2961         if (err) {                               2812         if (err) {
2962                 if (err == vec->crypt_error)     2813                 if (err == vec->crypt_error)
2963                         return 0;                2814                         return 0;
2964                 pr_err("alg: skcipher: %s %s     2815                 pr_err("alg: skcipher: %s %s failed on test vector %s; expected_error=%d, actual_error=%d, cfg=\"%s\"\n",
2965                        driver, op, vec_name,     2816                        driver, op, vec_name, vec->crypt_error, err, cfg->name);
2966                 return err;                      2817                 return err;
2967         }                                        2818         }
2968         if (vec->crypt_error) {                  2819         if (vec->crypt_error) {
2969                 pr_err("alg: skcipher: %s %s     2820                 pr_err("alg: skcipher: %s %s unexpectedly succeeded on test vector %s; expected_error=%d, cfg=\"%s\"\n",
2970                        driver, op, vec_name,     2821                        driver, op, vec_name, vec->crypt_error, cfg->name);
2971                 return -EINVAL;                  2822                 return -EINVAL;
2972         }                                        2823         }
2973                                                  2824 
2974         /* Check for the correct output (ciph    2825         /* Check for the correct output (ciphertext or plaintext) */
2975         err = verify_correct_output(&tsgls->d    2826         err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext,
2976                                     vec->len,    2827                                     vec->len, 0, true);
2977         if (err == -EOVERFLOW) {                 2828         if (err == -EOVERFLOW) {
2978                 pr_err("alg: skcipher: %s %s     2829                 pr_err("alg: skcipher: %s %s overran dst buffer on test vector %s, cfg=\"%s\"\n",
2979                        driver, op, vec_name,     2830                        driver, op, vec_name, cfg->name);
2980                 return err;                      2831                 return err;
2981         }                                        2832         }
2982         if (err) {                               2833         if (err) {
2983                 pr_err("alg: skcipher: %s %s     2834                 pr_err("alg: skcipher: %s %s test failed (wrong result) on test vector %s, cfg=\"%s\"\n",
2984                        driver, op, vec_name,     2835                        driver, op, vec_name, cfg->name);
2985                 return err;                      2836                 return err;
2986         }                                        2837         }
2987                                                  2838 
2988         /* If applicable, check that the algo    2839         /* If applicable, check that the algorithm generated the correct IV */
2989         if (vec->iv_out && memcmp(iv, vec->iv    2840         if (vec->iv_out && memcmp(iv, vec->iv_out, ivsize) != 0) {
2990                 pr_err("alg: skcipher: %s %s     2841                 pr_err("alg: skcipher: %s %s test failed (wrong output IV) on test vector %s, cfg=\"%s\"\n",
2991                        driver, op, vec_name,     2842                        driver, op, vec_name, cfg->name);
2992                 hexdump(iv, ivsize);             2843                 hexdump(iv, ivsize);
2993                 return -EINVAL;                  2844                 return -EINVAL;
2994         }                                        2845         }
2995                                                  2846 
2996         return 0;                                2847         return 0;
2997 }                                                2848 }
2998                                                  2849 
2999 static int test_skcipher_vec(int enc, const s    2850 static int test_skcipher_vec(int enc, const struct cipher_testvec *vec,
3000                              unsigned int vec    2851                              unsigned int vec_num,
3001                              struct skcipher_    2852                              struct skcipher_request *req,
3002                              struct cipher_te    2853                              struct cipher_test_sglists *tsgls)
3003 {                                                2854 {
3004         char vec_name[16];                       2855         char vec_name[16];
3005         unsigned int i;                          2856         unsigned int i;
3006         int err;                                 2857         int err;
3007                                                  2858 
3008         if (fips_enabled && vec->fips_skip)      2859         if (fips_enabled && vec->fips_skip)
3009                 return 0;                        2860                 return 0;
3010                                                  2861 
3011         sprintf(vec_name, "%u", vec_num);        2862         sprintf(vec_name, "%u", vec_num);
3012                                                  2863 
3013         for (i = 0; i < ARRAY_SIZE(default_ci    2864         for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
3014                 err = test_skcipher_vec_cfg(e    2865                 err = test_skcipher_vec_cfg(enc, vec, vec_name,
3015                                             &    2866                                             &default_cipher_testvec_configs[i],
3016                                             r    2867                                             req, tsgls);
3017                 if (err)                         2868                 if (err)
3018                         return err;              2869                         return err;
3019         }                                        2870         }
3020                                                  2871 
3021 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS         2872 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
3022         if (!noextratests) {                     2873         if (!noextratests) {
3023                 struct rnd_state rng;         << 
3024                 struct testvec_config cfg;       2874                 struct testvec_config cfg;
3025                 char cfgname[TESTVEC_CONFIG_N    2875                 char cfgname[TESTVEC_CONFIG_NAMELEN];
3026                                                  2876 
3027                 init_rnd_state(&rng);         << 
3028                                               << 
3029                 for (i = 0; i < fuzz_iteratio    2877                 for (i = 0; i < fuzz_iterations; i++) {
3030                         generate_random_testv !! 2878                         generate_random_testvec_config(&cfg, cfgname,
3031                                                  2879                                                        sizeof(cfgname));
3032                         err = test_skcipher_v    2880                         err = test_skcipher_vec_cfg(enc, vec, vec_name,
3033                                                  2881                                                     &cfg, req, tsgls);
3034                         if (err)                 2882                         if (err)
3035                                 return err;      2883                                 return err;
3036                         cond_resched();          2884                         cond_resched();
3037                 }                                2885                 }
3038         }                                        2886         }
3039 #endif                                           2887 #endif
3040         return 0;                                2888         return 0;
3041 }                                                2889 }
3042                                                  2890 
3043 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS         2891 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
3044 /*                                               2892 /*
3045  * Generate a symmetric cipher test vector fr    2893  * Generate a symmetric cipher test vector from the given implementation.
3046  * Assumes the buffers in 'vec' were already     2894  * Assumes the buffers in 'vec' were already allocated.
3047  */                                              2895  */
3048 static void generate_random_cipher_testvec(st !! 2896 static void generate_random_cipher_testvec(struct skcipher_request *req,
3049                                            st << 
3050                                            st    2897                                            struct cipher_testvec *vec,
3051                                            un    2898                                            unsigned int maxdatasize,
3052                                            ch    2899                                            char *name, size_t max_namelen)
3053 {                                                2900 {
3054         struct crypto_skcipher *tfm = crypto_    2901         struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
3055         const unsigned int maxkeysize = crypt    2902         const unsigned int maxkeysize = crypto_skcipher_max_keysize(tfm);
3056         const unsigned int ivsize = crypto_sk    2903         const unsigned int ivsize = crypto_skcipher_ivsize(tfm);
3057         struct scatterlist src, dst;             2904         struct scatterlist src, dst;
3058         u8 iv[MAX_IVLEN];                        2905         u8 iv[MAX_IVLEN];
3059         DECLARE_CRYPTO_WAIT(wait);               2906         DECLARE_CRYPTO_WAIT(wait);
3060                                                  2907 
3061         /* Key: length in [0, maxkeysize], bu    2908         /* Key: length in [0, maxkeysize], but usually choose maxkeysize */
3062         vec->klen = maxkeysize;                  2909         vec->klen = maxkeysize;
3063         if (prandom_u32_below(rng, 4) == 0)   !! 2910         if (prandom_u32() % 4 == 0)
3064                 vec->klen = prandom_u32_below !! 2911                 vec->klen = prandom_u32() % (maxkeysize + 1);
3065         generate_random_bytes(rng, (u8 *)vec- !! 2912         generate_random_bytes((u8 *)vec->key, vec->klen);
3066         vec->setkey_error = crypto_skcipher_s    2913         vec->setkey_error = crypto_skcipher_setkey(tfm, vec->key, vec->klen);
3067                                                  2914 
3068         /* IV */                                 2915         /* IV */
3069         generate_random_bytes(rng, (u8 *)vec- !! 2916         generate_random_bytes((u8 *)vec->iv, ivsize);
3070                                                  2917 
3071         /* Plaintext */                          2918         /* Plaintext */
3072         vec->len = generate_random_length(rng !! 2919         vec->len = generate_random_length(maxdatasize);
3073         generate_random_bytes(rng, (u8 *)vec- !! 2920         generate_random_bytes((u8 *)vec->ptext, vec->len);
3074                                                  2921 
3075         /* If the key couldn't be set, no nee    2922         /* If the key couldn't be set, no need to continue to encrypt. */
3076         if (vec->setkey_error)                   2923         if (vec->setkey_error)
3077                 goto done;                       2924                 goto done;
3078                                                  2925 
3079         /* Ciphertext */                         2926         /* Ciphertext */
3080         sg_init_one(&src, vec->ptext, vec->le    2927         sg_init_one(&src, vec->ptext, vec->len);
3081         sg_init_one(&dst, vec->ctext, vec->le    2928         sg_init_one(&dst, vec->ctext, vec->len);
3082         memcpy(iv, vec->iv, ivsize);             2929         memcpy(iv, vec->iv, ivsize);
3083         skcipher_request_set_callback(req, 0,    2930         skcipher_request_set_callback(req, 0, crypto_req_done, &wait);
3084         skcipher_request_set_crypt(req, &src,    2931         skcipher_request_set_crypt(req, &src, &dst, vec->len, iv);
3085         vec->crypt_error = crypto_wait_req(cr    2932         vec->crypt_error = crypto_wait_req(crypto_skcipher_encrypt(req), &wait);
3086         if (vec->crypt_error != 0) {             2933         if (vec->crypt_error != 0) {
3087                 /*                               2934                 /*
3088                  * The only acceptable error     2935                  * The only acceptable error here is for an invalid length, so
3089                  * skcipher decryption should    2936                  * skcipher decryption should fail with the same error too.
3090                  * We'll test for this.  But     2937                  * We'll test for this.  But to keep the API usage well-defined,
3091                  * explicitly initialize the     2938                  * explicitly initialize the ciphertext buffer too.
3092                  */                              2939                  */
3093                 memset((u8 *)vec->ctext, 0, v    2940                 memset((u8 *)vec->ctext, 0, vec->len);
3094         }                                        2941         }
3095 done:                                            2942 done:
3096         snprintf(name, max_namelen, "\"random    2943         snprintf(name, max_namelen, "\"random: len=%u klen=%u\"",
3097                  vec->len, vec->klen);           2944                  vec->len, vec->klen);
3098 }                                                2945 }
3099                                                  2946 
3100 /*                                               2947 /*
3101  * Test the skcipher algorithm represented by    2948  * Test the skcipher algorithm represented by @req against the corresponding
3102  * generic implementation, if one is availabl    2949  * generic implementation, if one is available.
3103  */                                              2950  */
3104 static int test_skcipher_vs_generic_impl(cons    2951 static int test_skcipher_vs_generic_impl(const char *generic_driver,
3105                                          stru    2952                                          struct skcipher_request *req,
3106                                          stru    2953                                          struct cipher_test_sglists *tsgls)
3107 {                                                2954 {
3108         struct crypto_skcipher *tfm = crypto_    2955         struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
3109         const unsigned int maxkeysize = crypt    2956         const unsigned int maxkeysize = crypto_skcipher_max_keysize(tfm);
3110         const unsigned int ivsize = crypto_sk    2957         const unsigned int ivsize = crypto_skcipher_ivsize(tfm);
3111         const unsigned int blocksize = crypto    2958         const unsigned int blocksize = crypto_skcipher_blocksize(tfm);
3112         const unsigned int maxdatasize = (2 *    2959         const unsigned int maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN;
3113         const char *algname = crypto_skcipher    2960         const char *algname = crypto_skcipher_alg(tfm)->base.cra_name;
3114         const char *driver = crypto_skcipher_    2961         const char *driver = crypto_skcipher_driver_name(tfm);
3115         struct rnd_state rng;                 << 
3116         char _generic_driver[CRYPTO_MAX_ALG_N    2962         char _generic_driver[CRYPTO_MAX_ALG_NAME];
3117         struct crypto_skcipher *generic_tfm =    2963         struct crypto_skcipher *generic_tfm = NULL;
3118         struct skcipher_request *generic_req     2964         struct skcipher_request *generic_req = NULL;
3119         unsigned int i;                          2965         unsigned int i;
3120         struct cipher_testvec vec = { 0 };       2966         struct cipher_testvec vec = { 0 };
3121         char vec_name[64];                       2967         char vec_name[64];
3122         struct testvec_config *cfg;              2968         struct testvec_config *cfg;
3123         char cfgname[TESTVEC_CONFIG_NAMELEN];    2969         char cfgname[TESTVEC_CONFIG_NAMELEN];
3124         int err;                                 2970         int err;
3125                                                  2971 
3126         if (noextratests)                        2972         if (noextratests)
3127                 return 0;                        2973                 return 0;
3128                                                  2974 
3129         /* Keywrap isn't supported here yet a    2975         /* Keywrap isn't supported here yet as it handles its IV differently. */
3130         if (strncmp(algname, "kw(", 3) == 0)     2976         if (strncmp(algname, "kw(", 3) == 0)
3131                 return 0;                        2977                 return 0;
3132                                                  2978 
3133         init_rnd_state(&rng);                 << 
3134                                               << 
3135         if (!generic_driver) { /* Use default    2979         if (!generic_driver) { /* Use default naming convention? */
3136                 err = build_generic_driver_na    2980                 err = build_generic_driver_name(algname, _generic_driver);
3137                 if (err)                         2981                 if (err)
3138                         return err;              2982                         return err;
3139                 generic_driver = _generic_dri    2983                 generic_driver = _generic_driver;
3140         }                                        2984         }
3141                                                  2985 
3142         if (strcmp(generic_driver, driver) ==    2986         if (strcmp(generic_driver, driver) == 0) /* Already the generic impl? */
3143                 return 0;                        2987                 return 0;
3144                                                  2988 
3145         generic_tfm = crypto_alloc_skcipher(g    2989         generic_tfm = crypto_alloc_skcipher(generic_driver, 0, 0);
3146         if (IS_ERR(generic_tfm)) {               2990         if (IS_ERR(generic_tfm)) {
3147                 err = PTR_ERR(generic_tfm);      2991                 err = PTR_ERR(generic_tfm);
3148                 if (err == -ENOENT) {            2992                 if (err == -ENOENT) {
3149                         pr_warn("alg: skciphe    2993                         pr_warn("alg: skcipher: skipping comparison tests for %s because %s is unavailable\n",
3150                                 driver, gener    2994                                 driver, generic_driver);
3151                         return 0;                2995                         return 0;
3152                 }                                2996                 }
3153                 pr_err("alg: skcipher: error     2997                 pr_err("alg: skcipher: error allocating %s (generic impl of %s): %d\n",
3154                        generic_driver, algnam    2998                        generic_driver, algname, err);
3155                 return err;                      2999                 return err;
3156         }                                        3000         }
3157                                                  3001 
3158         cfg = kzalloc(sizeof(*cfg), GFP_KERNE    3002         cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
3159         if (!cfg) {                              3003         if (!cfg) {
3160                 err = -ENOMEM;                   3004                 err = -ENOMEM;
3161                 goto out;                        3005                 goto out;
3162         }                                        3006         }
3163                                                  3007 
3164         generic_req = skcipher_request_alloc(    3008         generic_req = skcipher_request_alloc(generic_tfm, GFP_KERNEL);
3165         if (!generic_req) {                      3009         if (!generic_req) {
3166                 err = -ENOMEM;                   3010                 err = -ENOMEM;
3167                 goto out;                        3011                 goto out;
3168         }                                        3012         }
3169                                                  3013 
3170         /* Check the algorithm properties for    3014         /* Check the algorithm properties for consistency. */
3171                                                  3015 
3172         if (crypto_skcipher_min_keysize(tfm)     3016         if (crypto_skcipher_min_keysize(tfm) !=
3173             crypto_skcipher_min_keysize(gener    3017             crypto_skcipher_min_keysize(generic_tfm)) {
3174                 pr_err("alg: skcipher: min ke    3018                 pr_err("alg: skcipher: min keysize for %s (%u) doesn't match generic impl (%u)\n",
3175                        driver, crypto_skciphe    3019                        driver, crypto_skcipher_min_keysize(tfm),
3176                        crypto_skcipher_min_ke    3020                        crypto_skcipher_min_keysize(generic_tfm));
3177                 err = -EINVAL;                   3021                 err = -EINVAL;
3178                 goto out;                        3022                 goto out;
3179         }                                        3023         }
3180                                                  3024 
3181         if (maxkeysize != crypto_skcipher_max    3025         if (maxkeysize != crypto_skcipher_max_keysize(generic_tfm)) {
3182                 pr_err("alg: skcipher: max ke    3026                 pr_err("alg: skcipher: max keysize for %s (%u) doesn't match generic impl (%u)\n",
3183                        driver, maxkeysize,       3027                        driver, maxkeysize,
3184                        crypto_skcipher_max_ke    3028                        crypto_skcipher_max_keysize(generic_tfm));
3185                 err = -EINVAL;                   3029                 err = -EINVAL;
3186                 goto out;                        3030                 goto out;
3187         }                                        3031         }
3188                                                  3032 
3189         if (ivsize != crypto_skcipher_ivsize(    3033         if (ivsize != crypto_skcipher_ivsize(generic_tfm)) {
3190                 pr_err("alg: skcipher: ivsize    3034                 pr_err("alg: skcipher: ivsize for %s (%u) doesn't match generic impl (%u)\n",
3191                        driver, ivsize, crypto    3035                        driver, ivsize, crypto_skcipher_ivsize(generic_tfm));
3192                 err = -EINVAL;                   3036                 err = -EINVAL;
3193                 goto out;                        3037                 goto out;
3194         }                                        3038         }
3195                                                  3039 
3196         if (blocksize != crypto_skcipher_bloc    3040         if (blocksize != crypto_skcipher_blocksize(generic_tfm)) {
3197                 pr_err("alg: skcipher: blocks    3041                 pr_err("alg: skcipher: blocksize for %s (%u) doesn't match generic impl (%u)\n",
3198                        driver, blocksize,        3042                        driver, blocksize,
3199                        crypto_skcipher_blocks    3043                        crypto_skcipher_blocksize(generic_tfm));
3200                 err = -EINVAL;                   3044                 err = -EINVAL;
3201                 goto out;                        3045                 goto out;
3202         }                                        3046         }
3203                                                  3047 
3204         /*                                       3048         /*
3205          * Now generate test vectors using th    3049          * Now generate test vectors using the generic implementation, and test
3206          * the other implementation against t    3050          * the other implementation against them.
3207          */                                      3051          */
3208                                                  3052 
3209         vec.key = kmalloc(maxkeysize, GFP_KER    3053         vec.key = kmalloc(maxkeysize, GFP_KERNEL);
3210         vec.iv = kmalloc(ivsize, GFP_KERNEL);    3054         vec.iv = kmalloc(ivsize, GFP_KERNEL);
3211         vec.ptext = kmalloc(maxdatasize, GFP_    3055         vec.ptext = kmalloc(maxdatasize, GFP_KERNEL);
3212         vec.ctext = kmalloc(maxdatasize, GFP_    3056         vec.ctext = kmalloc(maxdatasize, GFP_KERNEL);
3213         if (!vec.key || !vec.iv || !vec.ptext    3057         if (!vec.key || !vec.iv || !vec.ptext || !vec.ctext) {
3214                 err = -ENOMEM;                   3058                 err = -ENOMEM;
3215                 goto out;                        3059                 goto out;
3216         }                                        3060         }
3217                                                  3061 
3218         for (i = 0; i < fuzz_iterations * 8;     3062         for (i = 0; i < fuzz_iterations * 8; i++) {
3219                 generate_random_cipher_testve !! 3063                 generate_random_cipher_testvec(generic_req, &vec, maxdatasize,
3220                                               << 
3221                                                  3064                                                vec_name, sizeof(vec_name));
3222                 generate_random_testvec_confi !! 3065                 generate_random_testvec_config(cfg, cfgname, sizeof(cfgname));
3223                                               << 
3224                                                  3066 
3225                 err = test_skcipher_vec_cfg(E    3067                 err = test_skcipher_vec_cfg(ENCRYPT, &vec, vec_name,
3226                                             c    3068                                             cfg, req, tsgls);
3227                 if (err)                         3069                 if (err)
3228                         goto out;                3070                         goto out;
3229                 err = test_skcipher_vec_cfg(D    3071                 err = test_skcipher_vec_cfg(DECRYPT, &vec, vec_name,
3230                                             c    3072                                             cfg, req, tsgls);
3231                 if (err)                         3073                 if (err)
3232                         goto out;                3074                         goto out;
3233                 cond_resched();                  3075                 cond_resched();
3234         }                                        3076         }
3235         err = 0;                                 3077         err = 0;
3236 out:                                             3078 out:
3237         kfree(cfg);                              3079         kfree(cfg);
3238         kfree(vec.key);                          3080         kfree(vec.key);
3239         kfree(vec.iv);                           3081         kfree(vec.iv);
3240         kfree(vec.ptext);                        3082         kfree(vec.ptext);
3241         kfree(vec.ctext);                        3083         kfree(vec.ctext);
3242         crypto_free_skcipher(generic_tfm);       3084         crypto_free_skcipher(generic_tfm);
3243         skcipher_request_free(generic_req);      3085         skcipher_request_free(generic_req);
3244         return err;                              3086         return err;
3245 }                                                3087 }
3246 #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS *    3088 #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
3247 static int test_skcipher_vs_generic_impl(cons    3089 static int test_skcipher_vs_generic_impl(const char *generic_driver,
3248                                          stru    3090                                          struct skcipher_request *req,
3249                                          stru    3091                                          struct cipher_test_sglists *tsgls)
3250 {                                                3092 {
3251         return 0;                                3093         return 0;
3252 }                                                3094 }
3253 #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS     3095 #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
3254                                                  3096 
3255 static int test_skcipher(int enc, const struc    3097 static int test_skcipher(int enc, const struct cipher_test_suite *suite,
3256                          struct skcipher_requ    3098                          struct skcipher_request *req,
3257                          struct cipher_test_s    3099                          struct cipher_test_sglists *tsgls)
3258 {                                                3100 {
3259         unsigned int i;                          3101         unsigned int i;
3260         int err;                                 3102         int err;
3261                                                  3103 
3262         for (i = 0; i < suite->count; i++) {     3104         for (i = 0; i < suite->count; i++) {
3263                 err = test_skcipher_vec(enc,     3105                 err = test_skcipher_vec(enc, &suite->vecs[i], i, req, tsgls);
3264                 if (err)                         3106                 if (err)
3265                         return err;              3107                         return err;
3266                 cond_resched();                  3108                 cond_resched();
3267         }                                        3109         }
3268         return 0;                                3110         return 0;
3269 }                                                3111 }
3270                                                  3112 
3271 static int alg_test_skcipher(const struct alg    3113 static int alg_test_skcipher(const struct alg_test_desc *desc,
3272                              const char *driv    3114                              const char *driver, u32 type, u32 mask)
3273 {                                                3115 {
3274         const struct cipher_test_suite *suite    3116         const struct cipher_test_suite *suite = &desc->suite.cipher;
3275         struct crypto_skcipher *tfm;             3117         struct crypto_skcipher *tfm;
3276         struct skcipher_request *req = NULL;     3118         struct skcipher_request *req = NULL;
3277         struct cipher_test_sglists *tsgls = N    3119         struct cipher_test_sglists *tsgls = NULL;
3278         int err;                                 3120         int err;
3279                                                  3121 
3280         if (suite->count <= 0) {                 3122         if (suite->count <= 0) {
3281                 pr_err("alg: skcipher: empty     3123                 pr_err("alg: skcipher: empty test suite for %s\n", driver);
3282                 return -EINVAL;                  3124                 return -EINVAL;
3283         }                                        3125         }
3284                                                  3126 
3285         tfm = crypto_alloc_skcipher(driver, t    3127         tfm = crypto_alloc_skcipher(driver, type, mask);
3286         if (IS_ERR(tfm)) {                       3128         if (IS_ERR(tfm)) {
3287                 if (PTR_ERR(tfm) == -ENOENT)  << 
3288                         return 0;             << 
3289                 pr_err("alg: skcipher: failed    3129                 pr_err("alg: skcipher: failed to allocate transform for %s: %ld\n",
3290                        driver, PTR_ERR(tfm));    3130                        driver, PTR_ERR(tfm));
3291                 return PTR_ERR(tfm);             3131                 return PTR_ERR(tfm);
3292         }                                        3132         }
3293         driver = crypto_skcipher_driver_name(    3133         driver = crypto_skcipher_driver_name(tfm);
3294                                                  3134 
3295         req = skcipher_request_alloc(tfm, GFP    3135         req = skcipher_request_alloc(tfm, GFP_KERNEL);
3296         if (!req) {                              3136         if (!req) {
3297                 pr_err("alg: skcipher: failed    3137                 pr_err("alg: skcipher: failed to allocate request for %s\n",
3298                        driver);                  3138                        driver);
3299                 err = -ENOMEM;                   3139                 err = -ENOMEM;
3300                 goto out;                        3140                 goto out;
3301         }                                        3141         }
3302                                                  3142 
3303         tsgls = alloc_cipher_test_sglists();     3143         tsgls = alloc_cipher_test_sglists();
3304         if (!tsgls) {                            3144         if (!tsgls) {
3305                 pr_err("alg: skcipher: failed    3145                 pr_err("alg: skcipher: failed to allocate test buffers for %s\n",
3306                        driver);                  3146                        driver);
3307                 err = -ENOMEM;                   3147                 err = -ENOMEM;
3308                 goto out;                        3148                 goto out;
3309         }                                        3149         }
3310                                                  3150 
3311         err = test_skcipher(ENCRYPT, suite, r    3151         err = test_skcipher(ENCRYPT, suite, req, tsgls);
3312         if (err)                                 3152         if (err)
3313                 goto out;                        3153                 goto out;
3314                                                  3154 
3315         err = test_skcipher(DECRYPT, suite, r    3155         err = test_skcipher(DECRYPT, suite, req, tsgls);
3316         if (err)                                 3156         if (err)
3317                 goto out;                        3157                 goto out;
3318                                                  3158 
3319         err = test_skcipher_vs_generic_impl(d    3159         err = test_skcipher_vs_generic_impl(desc->generic_driver, req, tsgls);
3320 out:                                             3160 out:
3321         free_cipher_test_sglists(tsgls);         3161         free_cipher_test_sglists(tsgls);
3322         skcipher_request_free(req);              3162         skcipher_request_free(req);
3323         crypto_free_skcipher(tfm);               3163         crypto_free_skcipher(tfm);
3324         return err;                              3164         return err;
3325 }                                                3165 }
3326                                                  3166 
3327 static int test_comp(struct crypto_comp *tfm,    3167 static int test_comp(struct crypto_comp *tfm,
3328                      const struct comp_testve    3168                      const struct comp_testvec *ctemplate,
3329                      const struct comp_testve    3169                      const struct comp_testvec *dtemplate,
3330                      int ctcount, int dtcount    3170                      int ctcount, int dtcount)
3331 {                                                3171 {
3332         const char *algo = crypto_tfm_alg_dri    3172         const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
3333         char *output, *decomp_output;            3173         char *output, *decomp_output;
3334         unsigned int i;                          3174         unsigned int i;
3335         int ret;                                 3175         int ret;
3336                                                  3176 
3337         output = kmalloc(COMP_BUF_SIZE, GFP_K    3177         output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
3338         if (!output)                             3178         if (!output)
3339                 return -ENOMEM;                  3179                 return -ENOMEM;
3340                                                  3180 
3341         decomp_output = kmalloc(COMP_BUF_SIZE    3181         decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
3342         if (!decomp_output) {                    3182         if (!decomp_output) {
3343                 kfree(output);                   3183                 kfree(output);
3344                 return -ENOMEM;                  3184                 return -ENOMEM;
3345         }                                        3185         }
3346                                                  3186 
3347         for (i = 0; i < ctcount; i++) {          3187         for (i = 0; i < ctcount; i++) {
3348                 int ilen;                        3188                 int ilen;
3349                 unsigned int dlen = COMP_BUF_    3189                 unsigned int dlen = COMP_BUF_SIZE;
3350                                                  3190 
3351                 memset(output, 0, COMP_BUF_SI    3191                 memset(output, 0, COMP_BUF_SIZE);
3352                 memset(decomp_output, 0, COMP    3192                 memset(decomp_output, 0, COMP_BUF_SIZE);
3353                                                  3193 
3354                 ilen = ctemplate[i].inlen;       3194                 ilen = ctemplate[i].inlen;
3355                 ret = crypto_comp_compress(tf    3195                 ret = crypto_comp_compress(tfm, ctemplate[i].input,
3356                                            il    3196                                            ilen, output, &dlen);
3357                 if (ret) {                       3197                 if (ret) {
3358                         printk(KERN_ERR "alg:    3198                         printk(KERN_ERR "alg: comp: compression failed "
3359                                "on test %d fo    3199                                "on test %d for %s: ret=%d\n", i + 1, algo,
3360                                -ret);            3200                                -ret);
3361                         goto out;                3201                         goto out;
3362                 }                                3202                 }
3363                                                  3203 
3364                 ilen = dlen;                     3204                 ilen = dlen;
3365                 dlen = COMP_BUF_SIZE;            3205                 dlen = COMP_BUF_SIZE;
3366                 ret = crypto_comp_decompress(    3206                 ret = crypto_comp_decompress(tfm, output,
3367                                                  3207                                              ilen, decomp_output, &dlen);
3368                 if (ret) {                       3208                 if (ret) {
3369                         pr_err("alg: comp: co    3209                         pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n",
3370                                i + 1, algo, -    3210                                i + 1, algo, -ret);
3371                         goto out;                3211                         goto out;
3372                 }                                3212                 }
3373                                                  3213 
3374                 if (dlen != ctemplate[i].inle    3214                 if (dlen != ctemplate[i].inlen) {
3375                         printk(KERN_ERR "alg:    3215                         printk(KERN_ERR "alg: comp: Compression test %d "
3376                                "failed for %s    3216                                "failed for %s: output len = %d\n", i + 1, algo,
3377                                dlen);            3217                                dlen);
3378                         ret = -EINVAL;           3218                         ret = -EINVAL;
3379                         goto out;                3219                         goto out;
3380                 }                                3220                 }
3381                                                  3221 
3382                 if (memcmp(decomp_output, cte    3222                 if (memcmp(decomp_output, ctemplate[i].input,
3383                            ctemplate[i].inlen    3223                            ctemplate[i].inlen)) {
3384                         pr_err("alg: comp: co    3224                         pr_err("alg: comp: compression failed: output differs: on test %d for %s\n",
3385                                i + 1, algo);     3225                                i + 1, algo);
3386                         hexdump(decomp_output    3226                         hexdump(decomp_output, dlen);
3387                         ret = -EINVAL;           3227                         ret = -EINVAL;
3388                         goto out;                3228                         goto out;
3389                 }                                3229                 }
3390         }                                        3230         }
3391                                                  3231 
3392         for (i = 0; i < dtcount; i++) {          3232         for (i = 0; i < dtcount; i++) {
3393                 int ilen;                        3233                 int ilen;
3394                 unsigned int dlen = COMP_BUF_    3234                 unsigned int dlen = COMP_BUF_SIZE;
3395                                                  3235 
3396                 memset(decomp_output, 0, COMP    3236                 memset(decomp_output, 0, COMP_BUF_SIZE);
3397                                                  3237 
3398                 ilen = dtemplate[i].inlen;       3238                 ilen = dtemplate[i].inlen;
3399                 ret = crypto_comp_decompress(    3239                 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
3400                                                  3240                                              ilen, decomp_output, &dlen);
3401                 if (ret) {                       3241                 if (ret) {
3402                         printk(KERN_ERR "alg:    3242                         printk(KERN_ERR "alg: comp: decompression failed "
3403                                "on test %d fo    3243                                "on test %d for %s: ret=%d\n", i + 1, algo,
3404                                -ret);            3244                                -ret);
3405                         goto out;                3245                         goto out;
3406                 }                                3246                 }
3407                                                  3247 
3408                 if (dlen != dtemplate[i].outl    3248                 if (dlen != dtemplate[i].outlen) {
3409                         printk(KERN_ERR "alg:    3249                         printk(KERN_ERR "alg: comp: Decompression test %d "
3410                                "failed for %s    3250                                "failed for %s: output len = %d\n", i + 1, algo,
3411                                dlen);            3251                                dlen);
3412                         ret = -EINVAL;           3252                         ret = -EINVAL;
3413                         goto out;                3253                         goto out;
3414                 }                                3254                 }
3415                                                  3255 
3416                 if (memcmp(decomp_output, dte    3256                 if (memcmp(decomp_output, dtemplate[i].output, dlen)) {
3417                         printk(KERN_ERR "alg:    3257                         printk(KERN_ERR "alg: comp: Decompression test %d "
3418                                "failed for %s    3258                                "failed for %s\n", i + 1, algo);
3419                         hexdump(decomp_output    3259                         hexdump(decomp_output, dlen);
3420                         ret = -EINVAL;           3260                         ret = -EINVAL;
3421                         goto out;                3261                         goto out;
3422                 }                                3262                 }
3423         }                                        3263         }
3424                                                  3264 
3425         ret = 0;                                 3265         ret = 0;
3426                                                  3266 
3427 out:                                             3267 out:
3428         kfree(decomp_output);                    3268         kfree(decomp_output);
3429         kfree(output);                           3269         kfree(output);
3430         return ret;                              3270         return ret;
3431 }                                                3271 }
3432                                                  3272 
3433 static int test_acomp(struct crypto_acomp *tf    3273 static int test_acomp(struct crypto_acomp *tfm,
3434                       const struct comp_testv !! 3274                               const struct comp_testvec *ctemplate,
3435                       const struct comp_testv    3275                       const struct comp_testvec *dtemplate,
3436                       int ctcount, int dtcoun    3276                       int ctcount, int dtcount)
3437 {                                                3277 {
3438         const char *algo = crypto_tfm_alg_dri    3278         const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
3439         unsigned int i;                          3279         unsigned int i;
3440         char *output, *decomp_out;               3280         char *output, *decomp_out;
3441         int ret;                                 3281         int ret;
3442         struct scatterlist src, dst;             3282         struct scatterlist src, dst;
3443         struct acomp_req *req;                   3283         struct acomp_req *req;
3444         struct crypto_wait wait;                 3284         struct crypto_wait wait;
3445                                                  3285 
3446         output = kmalloc(COMP_BUF_SIZE, GFP_K    3286         output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
3447         if (!output)                             3287         if (!output)
3448                 return -ENOMEM;                  3288                 return -ENOMEM;
3449                                                  3289 
3450         decomp_out = kmalloc(COMP_BUF_SIZE, G    3290         decomp_out = kmalloc(COMP_BUF_SIZE, GFP_KERNEL);
3451         if (!decomp_out) {                       3291         if (!decomp_out) {
3452                 kfree(output);                   3292                 kfree(output);
3453                 return -ENOMEM;                  3293                 return -ENOMEM;
3454         }                                        3294         }
3455                                                  3295 
3456         for (i = 0; i < ctcount; i++) {          3296         for (i = 0; i < ctcount; i++) {
3457                 unsigned int dlen = COMP_BUF_    3297                 unsigned int dlen = COMP_BUF_SIZE;
3458                 int ilen = ctemplate[i].inlen    3298                 int ilen = ctemplate[i].inlen;
3459                 void *input_vec;                 3299                 void *input_vec;
3460                                                  3300 
3461                 input_vec = kmemdup(ctemplate    3301                 input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL);
3462                 if (!input_vec) {                3302                 if (!input_vec) {
3463                         ret = -ENOMEM;           3303                         ret = -ENOMEM;
3464                         goto out;                3304                         goto out;
3465                 }                                3305                 }
3466                                                  3306 
3467                 memset(output, 0, dlen);         3307                 memset(output, 0, dlen);
3468                 crypto_init_wait(&wait);         3308                 crypto_init_wait(&wait);
3469                 sg_init_one(&src, input_vec,     3309                 sg_init_one(&src, input_vec, ilen);
3470                 sg_init_one(&dst, output, dle    3310                 sg_init_one(&dst, output, dlen);
3471                                                  3311 
3472                 req = acomp_request_alloc(tfm    3312                 req = acomp_request_alloc(tfm);
3473                 if (!req) {                      3313                 if (!req) {
3474                         pr_err("alg: acomp: r    3314                         pr_err("alg: acomp: request alloc failed for %s\n",
3475                                algo);            3315                                algo);
3476                         kfree(input_vec);        3316                         kfree(input_vec);
3477                         ret = -ENOMEM;           3317                         ret = -ENOMEM;
3478                         goto out;                3318                         goto out;
3479                 }                                3319                 }
3480                                                  3320 
3481                 acomp_request_set_params(req,    3321                 acomp_request_set_params(req, &src, &dst, ilen, dlen);
3482                 acomp_request_set_callback(re    3322                 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
3483                                            cr    3323                                            crypto_req_done, &wait);
3484                                                  3324 
3485                 ret = crypto_wait_req(crypto_    3325                 ret = crypto_wait_req(crypto_acomp_compress(req), &wait);
3486                 if (ret) {                       3326                 if (ret) {
3487                         pr_err("alg: acomp: c    3327                         pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
3488                                i + 1, algo, -    3328                                i + 1, algo, -ret);
3489                         kfree(input_vec);        3329                         kfree(input_vec);
3490                         acomp_request_free(re    3330                         acomp_request_free(req);
3491                         goto out;                3331                         goto out;
3492                 }                                3332                 }
3493                                                  3333 
3494                 ilen = req->dlen;                3334                 ilen = req->dlen;
3495                 dlen = COMP_BUF_SIZE;            3335                 dlen = COMP_BUF_SIZE;
3496                 sg_init_one(&src, output, ile    3336                 sg_init_one(&src, output, ilen);
3497                 sg_init_one(&dst, decomp_out,    3337                 sg_init_one(&dst, decomp_out, dlen);
3498                 crypto_init_wait(&wait);         3338                 crypto_init_wait(&wait);
3499                 acomp_request_set_params(req,    3339                 acomp_request_set_params(req, &src, &dst, ilen, dlen);
3500                                                  3340 
3501                 ret = crypto_wait_req(crypto_    3341                 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
3502                 if (ret) {                       3342                 if (ret) {
3503                         pr_err("alg: acomp: c    3343                         pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n",
3504                                i + 1, algo, -    3344                                i + 1, algo, -ret);
3505                         kfree(input_vec);        3345                         kfree(input_vec);
3506                         acomp_request_free(re    3346                         acomp_request_free(req);
3507                         goto out;                3347                         goto out;
3508                 }                                3348                 }
3509                                                  3349 
3510                 if (req->dlen != ctemplate[i]    3350                 if (req->dlen != ctemplate[i].inlen) {
3511                         pr_err("alg: acomp: C    3351                         pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n",
3512                                i + 1, algo, r    3352                                i + 1, algo, req->dlen);
3513                         ret = -EINVAL;           3353                         ret = -EINVAL;
3514                         kfree(input_vec);        3354                         kfree(input_vec);
3515                         acomp_request_free(re    3355                         acomp_request_free(req);
3516                         goto out;                3356                         goto out;
3517                 }                                3357                 }
3518                                                  3358 
3519                 if (memcmp(input_vec, decomp_    3359                 if (memcmp(input_vec, decomp_out, req->dlen)) {
3520                         pr_err("alg: acomp: C    3360                         pr_err("alg: acomp: Compression test %d failed for %s\n",
3521                                i + 1, algo);     3361                                i + 1, algo);
3522                         hexdump(output, req->    3362                         hexdump(output, req->dlen);
3523                         ret = -EINVAL;           3363                         ret = -EINVAL;
3524                         kfree(input_vec);        3364                         kfree(input_vec);
3525                         acomp_request_free(re    3365                         acomp_request_free(req);
3526                         goto out;                3366                         goto out;
3527                 }                                3367                 }
3528                                                  3368 
3529 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS      << 
3530                 crypto_init_wait(&wait);      << 
3531                 sg_init_one(&src, input_vec,  << 
3532                 acomp_request_set_params(req, << 
3533                                               << 
3534                 ret = crypto_wait_req(crypto_ << 
3535                 if (ret) {                    << 
3536                         pr_err("alg: acomp: c << 
3537                                i + 1, algo, - << 
3538                         kfree(input_vec);     << 
3539                         acomp_request_free(re << 
3540                         goto out;             << 
3541                 }                             << 
3542 #endif                                        << 
3543                                               << 
3544                 kfree(input_vec);                3369                 kfree(input_vec);
3545                 acomp_request_free(req);         3370                 acomp_request_free(req);
3546         }                                        3371         }
3547                                                  3372 
3548         for (i = 0; i < dtcount; i++) {          3373         for (i = 0; i < dtcount; i++) {
3549                 unsigned int dlen = COMP_BUF_    3374                 unsigned int dlen = COMP_BUF_SIZE;
3550                 int ilen = dtemplate[i].inlen    3375                 int ilen = dtemplate[i].inlen;
3551                 void *input_vec;                 3376                 void *input_vec;
3552                                                  3377 
3553                 input_vec = kmemdup(dtemplate    3378                 input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL);
3554                 if (!input_vec) {                3379                 if (!input_vec) {
3555                         ret = -ENOMEM;           3380                         ret = -ENOMEM;
3556                         goto out;                3381                         goto out;
3557                 }                                3382                 }
3558                                                  3383 
3559                 memset(output, 0, dlen);         3384                 memset(output, 0, dlen);
3560                 crypto_init_wait(&wait);         3385                 crypto_init_wait(&wait);
3561                 sg_init_one(&src, input_vec,     3386                 sg_init_one(&src, input_vec, ilen);
3562                 sg_init_one(&dst, output, dle    3387                 sg_init_one(&dst, output, dlen);
3563                                                  3388 
3564                 req = acomp_request_alloc(tfm    3389                 req = acomp_request_alloc(tfm);
3565                 if (!req) {                      3390                 if (!req) {
3566                         pr_err("alg: acomp: r    3391                         pr_err("alg: acomp: request alloc failed for %s\n",
3567                                algo);            3392                                algo);
3568                         kfree(input_vec);        3393                         kfree(input_vec);
3569                         ret = -ENOMEM;           3394                         ret = -ENOMEM;
3570                         goto out;                3395                         goto out;
3571                 }                                3396                 }
3572                                                  3397 
3573                 acomp_request_set_params(req,    3398                 acomp_request_set_params(req, &src, &dst, ilen, dlen);
3574                 acomp_request_set_callback(re    3399                 acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
3575                                            cr    3400                                            crypto_req_done, &wait);
3576                                                  3401 
3577                 ret = crypto_wait_req(crypto_    3402                 ret = crypto_wait_req(crypto_acomp_decompress(req), &wait);
3578                 if (ret) {                       3403                 if (ret) {
3579                         pr_err("alg: acomp: d    3404                         pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n",
3580                                i + 1, algo, -    3405                                i + 1, algo, -ret);
3581                         kfree(input_vec);        3406                         kfree(input_vec);
3582                         acomp_request_free(re    3407                         acomp_request_free(req);
3583                         goto out;                3408                         goto out;
3584                 }                                3409                 }
3585                                                  3410 
3586                 if (req->dlen != dtemplate[i]    3411                 if (req->dlen != dtemplate[i].outlen) {
3587                         pr_err("alg: acomp: D    3412                         pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n",
3588                                i + 1, algo, r    3413                                i + 1, algo, req->dlen);
3589                         ret = -EINVAL;           3414                         ret = -EINVAL;
3590                         kfree(input_vec);        3415                         kfree(input_vec);
3591                         acomp_request_free(re    3416                         acomp_request_free(req);
3592                         goto out;                3417                         goto out;
3593                 }                                3418                 }
3594                                                  3419 
3595                 if (memcmp(output, dtemplate[    3420                 if (memcmp(output, dtemplate[i].output, req->dlen)) {
3596                         pr_err("alg: acomp: D    3421                         pr_err("alg: acomp: Decompression test %d failed for %s\n",
3597                                i + 1, algo);     3422                                i + 1, algo);
3598                         hexdump(output, req->    3423                         hexdump(output, req->dlen);
3599                         ret = -EINVAL;           3424                         ret = -EINVAL;
3600                         kfree(input_vec);        3425                         kfree(input_vec);
3601                         acomp_request_free(re    3426                         acomp_request_free(req);
3602                         goto out;                3427                         goto out;
3603                 }                                3428                 }
3604                                                  3429 
3605 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS      << 
3606                 crypto_init_wait(&wait);      << 
3607                 acomp_request_set_params(req, << 
3608                                               << 
3609                 ret = crypto_wait_req(crypto_ << 
3610                 if (ret) {                    << 
3611                         pr_err("alg: acomp: d << 
3612                                i + 1, algo, - << 
3613                         kfree(input_vec);     << 
3614                         acomp_request_free(re << 
3615                         goto out;             << 
3616                 }                             << 
3617 #endif                                        << 
3618                                               << 
3619                 kfree(input_vec);                3430                 kfree(input_vec);
3620                 acomp_request_free(req);         3431                 acomp_request_free(req);
3621         }                                        3432         }
3622                                                  3433 
3623         ret = 0;                                 3434         ret = 0;
3624                                                  3435 
3625 out:                                             3436 out:
3626         kfree(decomp_out);                       3437         kfree(decomp_out);
3627         kfree(output);                           3438         kfree(output);
3628         return ret;                              3439         return ret;
3629 }                                                3440 }
3630                                                  3441 
3631 static int test_cprng(struct crypto_rng *tfm,    3442 static int test_cprng(struct crypto_rng *tfm,
3632                       const struct cprng_test    3443                       const struct cprng_testvec *template,
3633                       unsigned int tcount)       3444                       unsigned int tcount)
3634 {                                                3445 {
3635         const char *algo = crypto_tfm_alg_dri    3446         const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
3636         int err = 0, i, j, seedsize;             3447         int err = 0, i, j, seedsize;
3637         u8 *seed;                                3448         u8 *seed;
3638         char result[32];                         3449         char result[32];
3639                                                  3450 
3640         seedsize = crypto_rng_seedsize(tfm);     3451         seedsize = crypto_rng_seedsize(tfm);
3641                                                  3452 
3642         seed = kmalloc(seedsize, GFP_KERNEL);    3453         seed = kmalloc(seedsize, GFP_KERNEL);
3643         if (!seed) {                             3454         if (!seed) {
3644                 printk(KERN_ERR "alg: cprng:     3455                 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
3645                        "for %s\n", algo);        3456                        "for %s\n", algo);
3646                 return -ENOMEM;                  3457                 return -ENOMEM;
3647         }                                        3458         }
3648                                                  3459 
3649         for (i = 0; i < tcount; i++) {           3460         for (i = 0; i < tcount; i++) {
3650                 memset(result, 0, 32);           3461                 memset(result, 0, 32);
3651                                                  3462 
3652                 memcpy(seed, template[i].v, t    3463                 memcpy(seed, template[i].v, template[i].vlen);
3653                 memcpy(seed + template[i].vle    3464                 memcpy(seed + template[i].vlen, template[i].key,
3654                        template[i].klen);        3465                        template[i].klen);
3655                 memcpy(seed + template[i].vle    3466                 memcpy(seed + template[i].vlen + template[i].klen,
3656                        template[i].dt, templa    3467                        template[i].dt, template[i].dtlen);
3657                                                  3468 
3658                 err = crypto_rng_reset(tfm, s    3469                 err = crypto_rng_reset(tfm, seed, seedsize);
3659                 if (err) {                       3470                 if (err) {
3660                         printk(KERN_ERR "alg:    3471                         printk(KERN_ERR "alg: cprng: Failed to reset rng "
3661                                "for %s\n", al    3472                                "for %s\n", algo);
3662                         goto out;                3473                         goto out;
3663                 }                                3474                 }
3664                                                  3475 
3665                 for (j = 0; j < template[i].l    3476                 for (j = 0; j < template[i].loops; j++) {
3666                         err = crypto_rng_get_    3477                         err = crypto_rng_get_bytes(tfm, result,
3667                                                  3478                                                    template[i].rlen);
3668                         if (err < 0) {           3479                         if (err < 0) {
3669                                 printk(KERN_E    3480                                 printk(KERN_ERR "alg: cprng: Failed to obtain "
3670                                        "the c    3481                                        "the correct amount of random data for "
3671                                        "%s (r    3482                                        "%s (requested %d)\n", algo,
3672                                        templa    3483                                        template[i].rlen);
3673                                 goto out;        3484                                 goto out;
3674                         }                        3485                         }
3675                 }                                3486                 }
3676                                                  3487 
3677                 err = memcmp(result, template    3488                 err = memcmp(result, template[i].result,
3678                              template[i].rlen    3489                              template[i].rlen);
3679                 if (err) {                       3490                 if (err) {
3680                         printk(KERN_ERR "alg:    3491                         printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
3681                                i, algo);         3492                                i, algo);
3682                         hexdump(result, templ    3493                         hexdump(result, template[i].rlen);
3683                         err = -EINVAL;           3494                         err = -EINVAL;
3684                         goto out;                3495                         goto out;
3685                 }                                3496                 }
3686         }                                        3497         }
3687                                                  3498 
3688 out:                                             3499 out:
3689         kfree(seed);                             3500         kfree(seed);
3690         return err;                              3501         return err;
3691 }                                                3502 }
3692                                                  3503 
3693 static int alg_test_cipher(const struct alg_t    3504 static int alg_test_cipher(const struct alg_test_desc *desc,
3694                            const char *driver    3505                            const char *driver, u32 type, u32 mask)
3695 {                                                3506 {
3696         const struct cipher_test_suite *suite    3507         const struct cipher_test_suite *suite = &desc->suite.cipher;
3697         struct crypto_cipher *tfm;               3508         struct crypto_cipher *tfm;
3698         int err;                                 3509         int err;
3699                                                  3510 
3700         tfm = crypto_alloc_cipher(driver, typ    3511         tfm = crypto_alloc_cipher(driver, type, mask);
3701         if (IS_ERR(tfm)) {                       3512         if (IS_ERR(tfm)) {
3702                 if (PTR_ERR(tfm) == -ENOENT)  << 
3703                         return 0;             << 
3704                 printk(KERN_ERR "alg: cipher:    3513                 printk(KERN_ERR "alg: cipher: Failed to load transform for "
3705                        "%s: %ld\n", driver, P    3514                        "%s: %ld\n", driver, PTR_ERR(tfm));
3706                 return PTR_ERR(tfm);             3515                 return PTR_ERR(tfm);
3707         }                                        3516         }
3708                                                  3517 
3709         err = test_cipher(tfm, ENCRYPT, suite    3518         err = test_cipher(tfm, ENCRYPT, suite->vecs, suite->count);
3710         if (!err)                                3519         if (!err)
3711                 err = test_cipher(tfm, DECRYP    3520                 err = test_cipher(tfm, DECRYPT, suite->vecs, suite->count);
3712                                                  3521 
3713         crypto_free_cipher(tfm);                 3522         crypto_free_cipher(tfm);
3714         return err;                              3523         return err;
3715 }                                                3524 }
3716                                                  3525 
3717 static int alg_test_comp(const struct alg_tes    3526 static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
3718                          u32 type, u32 mask)     3527                          u32 type, u32 mask)
3719 {                                                3528 {
3720         struct crypto_comp *comp;                3529         struct crypto_comp *comp;
3721         struct crypto_acomp *acomp;              3530         struct crypto_acomp *acomp;
3722         int err;                                 3531         int err;
3723         u32 algo_type = type & CRYPTO_ALG_TYP    3532         u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK;
3724                                                  3533 
3725         if (algo_type == CRYPTO_ALG_TYPE_ACOM    3534         if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) {
3726                 acomp = crypto_alloc_acomp(dr    3535                 acomp = crypto_alloc_acomp(driver, type, mask);
3727                 if (IS_ERR(acomp)) {             3536                 if (IS_ERR(acomp)) {
3728                         if (PTR_ERR(acomp) == << 
3729                                 return 0;     << 
3730                         pr_err("alg: acomp: F    3537                         pr_err("alg: acomp: Failed to load transform for %s: %ld\n",
3731                                driver, PTR_ER    3538                                driver, PTR_ERR(acomp));
3732                         return PTR_ERR(acomp)    3539                         return PTR_ERR(acomp);
3733                 }                                3540                 }
3734                 err = test_acomp(acomp, desc-    3541                 err = test_acomp(acomp, desc->suite.comp.comp.vecs,
3735                                  desc->suite.    3542                                  desc->suite.comp.decomp.vecs,
3736                                  desc->suite.    3543                                  desc->suite.comp.comp.count,
3737                                  desc->suite.    3544                                  desc->suite.comp.decomp.count);
3738                 crypto_free_acomp(acomp);        3545                 crypto_free_acomp(acomp);
3739         } else {                                 3546         } else {
3740                 comp = crypto_alloc_comp(driv    3547                 comp = crypto_alloc_comp(driver, type, mask);
3741                 if (IS_ERR(comp)) {              3548                 if (IS_ERR(comp)) {
3742                         if (PTR_ERR(comp) ==  << 
3743                                 return 0;     << 
3744                         pr_err("alg: comp: Fa    3549                         pr_err("alg: comp: Failed to load transform for %s: %ld\n",
3745                                driver, PTR_ER    3550                                driver, PTR_ERR(comp));
3746                         return PTR_ERR(comp);    3551                         return PTR_ERR(comp);
3747                 }                                3552                 }
3748                                                  3553 
3749                 err = test_comp(comp, desc->s    3554                 err = test_comp(comp, desc->suite.comp.comp.vecs,
3750                                 desc->suite.c    3555                                 desc->suite.comp.decomp.vecs,
3751                                 desc->suite.c    3556                                 desc->suite.comp.comp.count,
3752                                 desc->suite.c    3557                                 desc->suite.comp.decomp.count);
3753                                                  3558 
3754                 crypto_free_comp(comp);          3559                 crypto_free_comp(comp);
3755         }                                        3560         }
3756         return err;                              3561         return err;
3757 }                                                3562 }
3758                                                  3563 
3759 static int alg_test_crc32c(const struct alg_t    3564 static int alg_test_crc32c(const struct alg_test_desc *desc,
3760                            const char *driver    3565                            const char *driver, u32 type, u32 mask)
3761 {                                                3566 {
3762         struct crypto_shash *tfm;                3567         struct crypto_shash *tfm;
3763         __le32 val;                              3568         __le32 val;
3764         int err;                                 3569         int err;
3765                                                  3570 
3766         err = alg_test_hash(desc, driver, typ    3571         err = alg_test_hash(desc, driver, type, mask);
3767         if (err)                                 3572         if (err)
3768                 return err;                      3573                 return err;
3769                                                  3574 
3770         tfm = crypto_alloc_shash(driver, type    3575         tfm = crypto_alloc_shash(driver, type, mask);
3771         if (IS_ERR(tfm)) {                       3576         if (IS_ERR(tfm)) {
3772                 if (PTR_ERR(tfm) == -ENOENT)     3577                 if (PTR_ERR(tfm) == -ENOENT) {
3773                         /*                       3578                         /*
3774                          * This crc32c implem    3579                          * This crc32c implementation is only available through
3775                          * ahash API, not the    3580                          * ahash API, not the shash API, so the remaining part
3776                          * of the test is not    3581                          * of the test is not applicable to it.
3777                          */                      3582                          */
3778                         return 0;                3583                         return 0;
3779                 }                                3584                 }
3780                 printk(KERN_ERR "alg: crc32c:    3585                 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
3781                        "%ld\n", driver, PTR_E    3586                        "%ld\n", driver, PTR_ERR(tfm));
3782                 return PTR_ERR(tfm);             3587                 return PTR_ERR(tfm);
3783         }                                        3588         }
3784         driver = crypto_shash_driver_name(tfm    3589         driver = crypto_shash_driver_name(tfm);
3785                                                  3590 
3786         do {                                     3591         do {
3787                 SHASH_DESC_ON_STACK(shash, tf    3592                 SHASH_DESC_ON_STACK(shash, tfm);
3788                 u32 *ctx = (u32 *)shash_desc_    3593                 u32 *ctx = (u32 *)shash_desc_ctx(shash);
3789                                                  3594 
3790                 shash->tfm = tfm;                3595                 shash->tfm = tfm;
3791                                                  3596 
3792                 *ctx = 420553207;                3597                 *ctx = 420553207;
3793                 err = crypto_shash_final(shas    3598                 err = crypto_shash_final(shash, (u8 *)&val);
3794                 if (err) {                       3599                 if (err) {
3795                         printk(KERN_ERR "alg:    3600                         printk(KERN_ERR "alg: crc32c: Operation failed for "
3796                                "%s: %d\n", dr    3601                                "%s: %d\n", driver, err);
3797                         break;                   3602                         break;
3798                 }                                3603                 }
3799                                                  3604 
3800                 if (val != cpu_to_le32(~42055    3605                 if (val != cpu_to_le32(~420553207)) {
3801                         pr_err("alg: crc32c:     3606                         pr_err("alg: crc32c: Test failed for %s: %u\n",
3802                                driver, le32_t    3607                                driver, le32_to_cpu(val));
3803                         err = -EINVAL;           3608                         err = -EINVAL;
3804                 }                                3609                 }
3805         } while (0);                             3610         } while (0);
3806                                                  3611 
3807         crypto_free_shash(tfm);                  3612         crypto_free_shash(tfm);
3808                                                  3613 
3809         return err;                              3614         return err;
3810 }                                                3615 }
3811                                                  3616 
3812 static int alg_test_cprng(const struct alg_te    3617 static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
3813                           u32 type, u32 mask)    3618                           u32 type, u32 mask)
3814 {                                                3619 {
3815         struct crypto_rng *rng;                  3620         struct crypto_rng *rng;
3816         int err;                                 3621         int err;
3817                                                  3622 
3818         rng = crypto_alloc_rng(driver, type,     3623         rng = crypto_alloc_rng(driver, type, mask);
3819         if (IS_ERR(rng)) {                       3624         if (IS_ERR(rng)) {
3820                 if (PTR_ERR(rng) == -ENOENT)  << 
3821                         return 0;             << 
3822                 printk(KERN_ERR "alg: cprng:     3625                 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
3823                        "%ld\n", driver, PTR_E    3626                        "%ld\n", driver, PTR_ERR(rng));
3824                 return PTR_ERR(rng);             3627                 return PTR_ERR(rng);
3825         }                                        3628         }
3826                                                  3629 
3827         err = test_cprng(rng, desc->suite.cpr    3630         err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
3828                                                  3631 
3829         crypto_free_rng(rng);                    3632         crypto_free_rng(rng);
3830                                                  3633 
3831         return err;                              3634         return err;
3832 }                                                3635 }
3833                                                  3636 
3834                                                  3637 
3835 static int drbg_cavs_test(const struct drbg_t    3638 static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
3836                           const char *driver,    3639                           const char *driver, u32 type, u32 mask)
3837 {                                                3640 {
3838         int ret = -EAGAIN;                       3641         int ret = -EAGAIN;
3839         struct crypto_rng *drng;                 3642         struct crypto_rng *drng;
3840         struct drbg_test_data test_data;         3643         struct drbg_test_data test_data;
3841         struct drbg_string addtl, pers, teste    3644         struct drbg_string addtl, pers, testentropy;
3842         unsigned char *buf = kzalloc(test->ex    3645         unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
3843                                                  3646 
3844         if (!buf)                                3647         if (!buf)
3845                 return -ENOMEM;                  3648                 return -ENOMEM;
3846                                                  3649 
3847         drng = crypto_alloc_rng(driver, type,    3650         drng = crypto_alloc_rng(driver, type, mask);
3848         if (IS_ERR(drng)) {                      3651         if (IS_ERR(drng)) {
3849                 kfree_sensitive(buf);         << 
3850                 if (PTR_ERR(drng) == -ENOENT) << 
3851                         return 0;             << 
3852                 printk(KERN_ERR "alg: drbg: c    3652                 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
3853                        "%s\n", driver);          3653                        "%s\n", driver);
3854                 return PTR_ERR(drng);         !! 3654                 kfree_sensitive(buf);
                                                   >> 3655                 return -ENOMEM;
3855         }                                        3656         }
3856                                                  3657 
3857         test_data.testentropy = &testentropy;    3658         test_data.testentropy = &testentropy;
3858         drbg_string_fill(&testentropy, test->    3659         drbg_string_fill(&testentropy, test->entropy, test->entropylen);
3859         drbg_string_fill(&pers, test->pers, t    3660         drbg_string_fill(&pers, test->pers, test->perslen);
3860         ret = crypto_drbg_reset_test(drng, &p    3661         ret = crypto_drbg_reset_test(drng, &pers, &test_data);
3861         if (ret) {                               3662         if (ret) {
3862                 printk(KERN_ERR "alg: drbg: F    3663                 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
3863                 goto outbuf;                     3664                 goto outbuf;
3864         }                                        3665         }
3865                                                  3666 
3866         drbg_string_fill(&addtl, test->addtla    3667         drbg_string_fill(&addtl, test->addtla, test->addtllen);
3867         if (pr) {                                3668         if (pr) {
3868                 drbg_string_fill(&testentropy    3669                 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
3869                 ret = crypto_drbg_get_bytes_a    3670                 ret = crypto_drbg_get_bytes_addtl_test(drng,
3870                         buf, test->expectedle    3671                         buf, test->expectedlen, &addtl, &test_data);
3871         } else {                                 3672         } else {
3872                 ret = crypto_drbg_get_bytes_a    3673                 ret = crypto_drbg_get_bytes_addtl(drng,
3873                         buf, test->expectedle    3674                         buf, test->expectedlen, &addtl);
3874         }                                        3675         }
3875         if (ret < 0) {                           3676         if (ret < 0) {
3876                 printk(KERN_ERR "alg: drbg: c    3677                 printk(KERN_ERR "alg: drbg: could not obtain random data for "
3877                        "driver %s\n", driver)    3678                        "driver %s\n", driver);
3878                 goto outbuf;                     3679                 goto outbuf;
3879         }                                        3680         }
3880                                                  3681 
3881         drbg_string_fill(&addtl, test->addtlb    3682         drbg_string_fill(&addtl, test->addtlb, test->addtllen);
3882         if (pr) {                                3683         if (pr) {
3883                 drbg_string_fill(&testentropy    3684                 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
3884                 ret = crypto_drbg_get_bytes_a    3685                 ret = crypto_drbg_get_bytes_addtl_test(drng,
3885                         buf, test->expectedle    3686                         buf, test->expectedlen, &addtl, &test_data);
3886         } else {                                 3687         } else {
3887                 ret = crypto_drbg_get_bytes_a    3688                 ret = crypto_drbg_get_bytes_addtl(drng,
3888                         buf, test->expectedle    3689                         buf, test->expectedlen, &addtl);
3889         }                                        3690         }
3890         if (ret < 0) {                           3691         if (ret < 0) {
3891                 printk(KERN_ERR "alg: drbg: c    3692                 printk(KERN_ERR "alg: drbg: could not obtain random data for "
3892                        "driver %s\n", driver)    3693                        "driver %s\n", driver);
3893                 goto outbuf;                     3694                 goto outbuf;
3894         }                                        3695         }
3895                                                  3696 
3896         ret = memcmp(test->expected, buf, tes    3697         ret = memcmp(test->expected, buf, test->expectedlen);
3897                                                  3698 
3898 outbuf:                                          3699 outbuf:
3899         crypto_free_rng(drng);                   3700         crypto_free_rng(drng);
3900         kfree_sensitive(buf);                    3701         kfree_sensitive(buf);
3901         return ret;                              3702         return ret;
3902 }                                                3703 }
3903                                                  3704 
3904                                                  3705 
3905 static int alg_test_drbg(const struct alg_tes    3706 static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
3906                          u32 type, u32 mask)     3707                          u32 type, u32 mask)
3907 {                                                3708 {
3908         int err = 0;                             3709         int err = 0;
3909         int pr = 0;                              3710         int pr = 0;
3910         int i = 0;                               3711         int i = 0;
3911         const struct drbg_testvec *template =    3712         const struct drbg_testvec *template = desc->suite.drbg.vecs;
3912         unsigned int tcount = desc->suite.drb    3713         unsigned int tcount = desc->suite.drbg.count;
3913                                                  3714 
3914         if (0 == memcmp(driver, "drbg_pr_", 8    3715         if (0 == memcmp(driver, "drbg_pr_", 8))
3915                 pr = 1;                          3716                 pr = 1;
3916                                                  3717 
3917         for (i = 0; i < tcount; i++) {           3718         for (i = 0; i < tcount; i++) {
3918                 err = drbg_cavs_test(&templat    3719                 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
3919                 if (err) {                       3720                 if (err) {
3920                         printk(KERN_ERR "alg:    3721                         printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
3921                                i, driver);       3722                                i, driver);
3922                         err = -EINVAL;           3723                         err = -EINVAL;
3923                         break;                   3724                         break;
3924                 }                                3725                 }
3925         }                                        3726         }
3926         return err;                              3727         return err;
3927                                                  3728 
3928 }                                                3729 }
3929                                                  3730 
3930 static int do_test_kpp(struct crypto_kpp *tfm    3731 static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
3931                        const char *alg)          3732                        const char *alg)
3932 {                                                3733 {
3933         struct kpp_request *req;                 3734         struct kpp_request *req;
3934         void *input_buf = NULL;                  3735         void *input_buf = NULL;
3935         void *output_buf = NULL;                 3736         void *output_buf = NULL;
3936         void *a_public = NULL;                   3737         void *a_public = NULL;
3937         void *a_ss = NULL;                       3738         void *a_ss = NULL;
3938         void *shared_secret = NULL;              3739         void *shared_secret = NULL;
3939         struct crypto_wait wait;                 3740         struct crypto_wait wait;
3940         unsigned int out_len_max;                3741         unsigned int out_len_max;
3941         int err = -ENOMEM;                       3742         int err = -ENOMEM;
3942         struct scatterlist src, dst;             3743         struct scatterlist src, dst;
3943                                                  3744 
3944         req = kpp_request_alloc(tfm, GFP_KERN    3745         req = kpp_request_alloc(tfm, GFP_KERNEL);
3945         if (!req)                                3746         if (!req)
3946                 return err;                      3747                 return err;
3947                                                  3748 
3948         crypto_init_wait(&wait);                 3749         crypto_init_wait(&wait);
3949                                                  3750 
3950         err = crypto_kpp_set_secret(tfm, vec-    3751         err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size);
3951         if (err < 0)                             3752         if (err < 0)
3952                 goto free_req;                   3753                 goto free_req;
3953                                                  3754 
3954         out_len_max = crypto_kpp_maxsize(tfm)    3755         out_len_max = crypto_kpp_maxsize(tfm);
3955         output_buf = kzalloc(out_len_max, GFP    3756         output_buf = kzalloc(out_len_max, GFP_KERNEL);
3956         if (!output_buf) {                       3757         if (!output_buf) {
3957                 err = -ENOMEM;                   3758                 err = -ENOMEM;
3958                 goto free_req;                   3759                 goto free_req;
3959         }                                        3760         }
3960                                                  3761 
3961         /* Use appropriate parameter as base     3762         /* Use appropriate parameter as base */
3962         kpp_request_set_input(req, NULL, 0);     3763         kpp_request_set_input(req, NULL, 0);
3963         sg_init_one(&dst, output_buf, out_len    3764         sg_init_one(&dst, output_buf, out_len_max);
3964         kpp_request_set_output(req, &dst, out    3765         kpp_request_set_output(req, &dst, out_len_max);
3965         kpp_request_set_callback(req, CRYPTO_    3766         kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
3966                                  crypto_req_d    3767                                  crypto_req_done, &wait);
3967                                                  3768 
3968         /* Compute party A's public key */       3769         /* Compute party A's public key */
3969         err = crypto_wait_req(crypto_kpp_gene    3770         err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait);
3970         if (err) {                               3771         if (err) {
3971                 pr_err("alg: %s: Party A: gen    3772                 pr_err("alg: %s: Party A: generate public key test failed. err %d\n",
3972                        alg, err);                3773                        alg, err);
3973                 goto free_output;                3774                 goto free_output;
3974         }                                        3775         }
3975                                                  3776 
3976         if (vec->genkey) {                       3777         if (vec->genkey) {
3977                 /* Save party A's public key     3778                 /* Save party A's public key */
3978                 a_public = kmemdup(sg_virt(re    3779                 a_public = kmemdup(sg_virt(req->dst), out_len_max, GFP_KERNEL);
3979                 if (!a_public) {                 3780                 if (!a_public) {
3980                         err = -ENOMEM;           3781                         err = -ENOMEM;
3981                         goto free_output;        3782                         goto free_output;
3982                 }                                3783                 }
3983         } else {                                 3784         } else {
3984                 /* Verify calculated public k    3785                 /* Verify calculated public key */
3985                 if (memcmp(vec->expected_a_pu    3786                 if (memcmp(vec->expected_a_public, sg_virt(req->dst),
3986                            vec->expected_a_pu    3787                            vec->expected_a_public_size)) {
3987                         pr_err("alg: %s: Part    3788                         pr_err("alg: %s: Party A: generate public key test failed. Invalid output\n",
3988                                alg);             3789                                alg);
3989                         err = -EINVAL;           3790                         err = -EINVAL;
3990                         goto free_output;        3791                         goto free_output;
3991                 }                                3792                 }
3992         }                                        3793         }
3993                                                  3794 
3994         /* Calculate shared secret key by usi    3795         /* Calculate shared secret key by using counter part (b) public key. */
3995         input_buf = kmemdup(vec->b_public, ve    3796         input_buf = kmemdup(vec->b_public, vec->b_public_size, GFP_KERNEL);
3996         if (!input_buf) {                        3797         if (!input_buf) {
3997                 err = -ENOMEM;                   3798                 err = -ENOMEM;
3998                 goto free_output;                3799                 goto free_output;
3999         }                                        3800         }
4000                                                  3801 
4001         sg_init_one(&src, input_buf, vec->b_p    3802         sg_init_one(&src, input_buf, vec->b_public_size);
4002         sg_init_one(&dst, output_buf, out_len    3803         sg_init_one(&dst, output_buf, out_len_max);
4003         kpp_request_set_input(req, &src, vec-    3804         kpp_request_set_input(req, &src, vec->b_public_size);
4004         kpp_request_set_output(req, &dst, out    3805         kpp_request_set_output(req, &dst, out_len_max);
4005         kpp_request_set_callback(req, CRYPTO_    3806         kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4006                                  crypto_req_d    3807                                  crypto_req_done, &wait);
4007         err = crypto_wait_req(crypto_kpp_comp    3808         err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait);
4008         if (err) {                               3809         if (err) {
4009                 pr_err("alg: %s: Party A: com    3810                 pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n",
4010                        alg, err);                3811                        alg, err);
4011                 goto free_all;                   3812                 goto free_all;
4012         }                                        3813         }
4013                                                  3814 
4014         if (vec->genkey) {                       3815         if (vec->genkey) {
4015                 /* Save the shared secret obt    3816                 /* Save the shared secret obtained by party A */
4016                 a_ss = kmemdup(sg_virt(req->d    3817                 a_ss = kmemdup(sg_virt(req->dst), vec->expected_ss_size, GFP_KERNEL);
4017                 if (!a_ss) {                     3818                 if (!a_ss) {
4018                         err = -ENOMEM;           3819                         err = -ENOMEM;
4019                         goto free_all;           3820                         goto free_all;
4020                 }                                3821                 }
4021                                                  3822 
4022                 /*                               3823                 /*
4023                  * Calculate party B's shared    3824                  * Calculate party B's shared secret by using party A's
4024                  * public key.                   3825                  * public key.
4025                  */                              3826                  */
4026                 err = crypto_kpp_set_secret(t    3827                 err = crypto_kpp_set_secret(tfm, vec->b_secret,
4027                                             v    3828                                             vec->b_secret_size);
4028                 if (err < 0)                     3829                 if (err < 0)
4029                         goto free_all;           3830                         goto free_all;
4030                                                  3831 
4031                 sg_init_one(&src, a_public, v    3832                 sg_init_one(&src, a_public, vec->expected_a_public_size);
4032                 sg_init_one(&dst, output_buf,    3833                 sg_init_one(&dst, output_buf, out_len_max);
4033                 kpp_request_set_input(req, &s    3834                 kpp_request_set_input(req, &src, vec->expected_a_public_size);
4034                 kpp_request_set_output(req, &    3835                 kpp_request_set_output(req, &dst, out_len_max);
4035                 kpp_request_set_callback(req,    3836                 kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4036                                          cryp    3837                                          crypto_req_done, &wait);
4037                 err = crypto_wait_req(crypto_    3838                 err = crypto_wait_req(crypto_kpp_compute_shared_secret(req),
4038                                       &wait);    3839                                       &wait);
4039                 if (err) {                       3840                 if (err) {
4040                         pr_err("alg: %s: Part    3841                         pr_err("alg: %s: Party B: compute shared secret failed. err %d\n",
4041                                alg, err);        3842                                alg, err);
4042                         goto free_all;           3843                         goto free_all;
4043                 }                                3844                 }
4044                                                  3845 
4045                 shared_secret = a_ss;            3846                 shared_secret = a_ss;
4046         } else {                                 3847         } else {
4047                 shared_secret = (void *)vec->    3848                 shared_secret = (void *)vec->expected_ss;
4048         }                                        3849         }
4049                                                  3850 
4050         /*                                       3851         /*
4051          * verify shared secret from which th    3852          * verify shared secret from which the user will derive
4052          * secret key by executing whatever h    3853          * secret key by executing whatever hash it has chosen
4053          */                                      3854          */
4054         if (memcmp(shared_secret, sg_virt(req    3855         if (memcmp(shared_secret, sg_virt(req->dst),
4055                    vec->expected_ss_size)) {     3856                    vec->expected_ss_size)) {
4056                 pr_err("alg: %s: compute shar    3857                 pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
4057                        alg);                     3858                        alg);
4058                 err = -EINVAL;                   3859                 err = -EINVAL;
4059         }                                        3860         }
4060                                                  3861 
4061 free_all:                                        3862 free_all:
4062         kfree(a_ss);                             3863         kfree(a_ss);
4063         kfree(input_buf);                        3864         kfree(input_buf);
4064 free_output:                                     3865 free_output:
4065         kfree(a_public);                         3866         kfree(a_public);
4066         kfree(output_buf);                       3867         kfree(output_buf);
4067 free_req:                                        3868 free_req:
4068         kpp_request_free(req);                   3869         kpp_request_free(req);
4069         return err;                              3870         return err;
4070 }                                                3871 }
4071                                                  3872 
4072 static int test_kpp(struct crypto_kpp *tfm, c    3873 static int test_kpp(struct crypto_kpp *tfm, const char *alg,
4073                     const struct kpp_testvec     3874                     const struct kpp_testvec *vecs, unsigned int tcount)
4074 {                                                3875 {
4075         int ret, i;                              3876         int ret, i;
4076                                                  3877 
4077         for (i = 0; i < tcount; i++) {           3878         for (i = 0; i < tcount; i++) {
4078                 ret = do_test_kpp(tfm, vecs++    3879                 ret = do_test_kpp(tfm, vecs++, alg);
4079                 if (ret) {                       3880                 if (ret) {
4080                         pr_err("alg: %s: test    3881                         pr_err("alg: %s: test failed on vector %d, err=%d\n",
4081                                alg, i + 1, re    3882                                alg, i + 1, ret);
4082                         return ret;              3883                         return ret;
4083                 }                                3884                 }
4084         }                                        3885         }
4085         return 0;                                3886         return 0;
4086 }                                                3887 }
4087                                                  3888 
4088 static int alg_test_kpp(const struct alg_test    3889 static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
4089                         u32 type, u32 mask)      3890                         u32 type, u32 mask)
4090 {                                                3891 {
4091         struct crypto_kpp *tfm;                  3892         struct crypto_kpp *tfm;
4092         int err = 0;                             3893         int err = 0;
4093                                                  3894 
4094         tfm = crypto_alloc_kpp(driver, type,     3895         tfm = crypto_alloc_kpp(driver, type, mask);
4095         if (IS_ERR(tfm)) {                       3896         if (IS_ERR(tfm)) {
4096                 if (PTR_ERR(tfm) == -ENOENT)  << 
4097                         return 0;             << 
4098                 pr_err("alg: kpp: Failed to l    3897                 pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
4099                        driver, PTR_ERR(tfm));    3898                        driver, PTR_ERR(tfm));
4100                 return PTR_ERR(tfm);             3899                 return PTR_ERR(tfm);
4101         }                                        3900         }
4102         if (desc->suite.kpp.vecs)                3901         if (desc->suite.kpp.vecs)
4103                 err = test_kpp(tfm, desc->alg    3902                 err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs,
4104                                desc->suite.kp    3903                                desc->suite.kpp.count);
4105                                                  3904 
4106         crypto_free_kpp(tfm);                    3905         crypto_free_kpp(tfm);
4107         return err;                              3906         return err;
4108 }                                                3907 }
4109                                                  3908 
4110 static u8 *test_pack_u32(u8 *dst, u32 val)       3909 static u8 *test_pack_u32(u8 *dst, u32 val)
4111 {                                                3910 {
4112         memcpy(dst, &val, sizeof(val));          3911         memcpy(dst, &val, sizeof(val));
4113         return dst + sizeof(val);                3912         return dst + sizeof(val);
4114 }                                                3913 }
4115                                                  3914 
4116 static int test_akcipher_one(struct crypto_ak    3915 static int test_akcipher_one(struct crypto_akcipher *tfm,
4117                              const struct akc    3916                              const struct akcipher_testvec *vecs)
4118 {                                                3917 {
4119         char *xbuf[XBUFSIZE];                    3918         char *xbuf[XBUFSIZE];
4120         struct akcipher_request *req;            3919         struct akcipher_request *req;
4121         void *outbuf_enc = NULL;                 3920         void *outbuf_enc = NULL;
4122         void *outbuf_dec = NULL;                 3921         void *outbuf_dec = NULL;
4123         struct crypto_wait wait;                 3922         struct crypto_wait wait;
4124         unsigned int out_len_max, out_len = 0    3923         unsigned int out_len_max, out_len = 0;
4125         int err = -ENOMEM;                       3924         int err = -ENOMEM;
4126         struct scatterlist src, dst, src_tab[    3925         struct scatterlist src, dst, src_tab[3];
4127         const char *m, *c;                       3926         const char *m, *c;
4128         unsigned int m_size, c_size;             3927         unsigned int m_size, c_size;
4129         const char *op;                          3928         const char *op;
4130         u8 *key, *ptr;                           3929         u8 *key, *ptr;
4131                                                  3930 
4132         if (testmgr_alloc_buf(xbuf))             3931         if (testmgr_alloc_buf(xbuf))
4133                 return err;                      3932                 return err;
4134                                                  3933 
4135         req = akcipher_request_alloc(tfm, GFP    3934         req = akcipher_request_alloc(tfm, GFP_KERNEL);
4136         if (!req)                                3935         if (!req)
4137                 goto free_xbuf;                  3936                 goto free_xbuf;
4138                                                  3937 
4139         crypto_init_wait(&wait);                 3938         crypto_init_wait(&wait);
4140                                                  3939 
4141         key = kmalloc(vecs->key_len + sizeof(    3940         key = kmalloc(vecs->key_len + sizeof(u32) * 2 + vecs->param_len,
4142                       GFP_KERNEL);               3941                       GFP_KERNEL);
4143         if (!key)                                3942         if (!key)
4144                 goto free_req;                   3943                 goto free_req;
4145         memcpy(key, vecs->key, vecs->key_len)    3944         memcpy(key, vecs->key, vecs->key_len);
4146         ptr = key + vecs->key_len;               3945         ptr = key + vecs->key_len;
4147         ptr = test_pack_u32(ptr, vecs->algo);    3946         ptr = test_pack_u32(ptr, vecs->algo);
4148         ptr = test_pack_u32(ptr, vecs->param_    3947         ptr = test_pack_u32(ptr, vecs->param_len);
4149         memcpy(ptr, vecs->params, vecs->param    3948         memcpy(ptr, vecs->params, vecs->param_len);
4150                                                  3949 
4151         if (vecs->public_key_vec)                3950         if (vecs->public_key_vec)
4152                 err = crypto_akcipher_set_pub    3951                 err = crypto_akcipher_set_pub_key(tfm, key, vecs->key_len);
4153         else                                     3952         else
4154                 err = crypto_akcipher_set_pri    3953                 err = crypto_akcipher_set_priv_key(tfm, key, vecs->key_len);
4155         if (err)                                 3954         if (err)
4156                 goto free_key;                   3955                 goto free_key;
4157                                                  3956 
4158         /*                                       3957         /*
4159          * First run test which do not requir    3958          * First run test which do not require a private key, such as
4160          * encrypt or verify.                    3959          * encrypt or verify.
4161          */                                      3960          */
4162         err = -ENOMEM;                           3961         err = -ENOMEM;
4163         out_len_max = crypto_akcipher_maxsize    3962         out_len_max = crypto_akcipher_maxsize(tfm);
4164         outbuf_enc = kzalloc(out_len_max, GFP    3963         outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
4165         if (!outbuf_enc)                         3964         if (!outbuf_enc)
4166                 goto free_key;                   3965                 goto free_key;
4167                                                  3966 
4168         if (!vecs->siggen_sigver_test) {         3967         if (!vecs->siggen_sigver_test) {
4169                 m = vecs->m;                     3968                 m = vecs->m;
4170                 m_size = vecs->m_size;           3969                 m_size = vecs->m_size;
4171                 c = vecs->c;                     3970                 c = vecs->c;
4172                 c_size = vecs->c_size;           3971                 c_size = vecs->c_size;
4173                 op = "encrypt";                  3972                 op = "encrypt";
4174         } else {                                 3973         } else {
4175                 /* Swap args so we could keep    3974                 /* Swap args so we could keep plaintext (digest)
4176                  * in vecs->m, and cooked sig    3975                  * in vecs->m, and cooked signature in vecs->c.
4177                  */                              3976                  */
4178                 m = vecs->c; /* signature */     3977                 m = vecs->c; /* signature */
4179                 m_size = vecs->c_size;           3978                 m_size = vecs->c_size;
4180                 c = vecs->m; /* digest */        3979                 c = vecs->m; /* digest */
4181                 c_size = vecs->m_size;           3980                 c_size = vecs->m_size;
4182                 op = "verify";                   3981                 op = "verify";
4183         }                                        3982         }
4184                                                  3983 
4185         err = -E2BIG;                            3984         err = -E2BIG;
4186         if (WARN_ON(m_size > PAGE_SIZE))         3985         if (WARN_ON(m_size > PAGE_SIZE))
4187                 goto free_all;                   3986                 goto free_all;
4188         memcpy(xbuf[0], m, m_size);              3987         memcpy(xbuf[0], m, m_size);
4189                                                  3988 
4190         sg_init_table(src_tab, 3);               3989         sg_init_table(src_tab, 3);
4191         sg_set_buf(&src_tab[0], xbuf[0], 8);     3990         sg_set_buf(&src_tab[0], xbuf[0], 8);
4192         sg_set_buf(&src_tab[1], xbuf[0] + 8,     3991         sg_set_buf(&src_tab[1], xbuf[0] + 8, m_size - 8);
4193         if (vecs->siggen_sigver_test) {          3992         if (vecs->siggen_sigver_test) {
4194                 if (WARN_ON(c_size > PAGE_SIZ    3993                 if (WARN_ON(c_size > PAGE_SIZE))
4195                         goto free_all;           3994                         goto free_all;
4196                 memcpy(xbuf[1], c, c_size);      3995                 memcpy(xbuf[1], c, c_size);
4197                 sg_set_buf(&src_tab[2], xbuf[    3996                 sg_set_buf(&src_tab[2], xbuf[1], c_size);
4198                 akcipher_request_set_crypt(re    3997                 akcipher_request_set_crypt(req, src_tab, NULL, m_size, c_size);
4199         } else {                                 3998         } else {
4200                 sg_init_one(&dst, outbuf_enc,    3999                 sg_init_one(&dst, outbuf_enc, out_len_max);
4201                 akcipher_request_set_crypt(re    4000                 akcipher_request_set_crypt(req, src_tab, &dst, m_size,
4202                                            ou    4001                                            out_len_max);
4203         }                                        4002         }
4204         akcipher_request_set_callback(req, CR    4003         akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4205                                       crypto_    4004                                       crypto_req_done, &wait);
4206                                                  4005 
4207         err = crypto_wait_req(vecs->siggen_si    4006         err = crypto_wait_req(vecs->siggen_sigver_test ?
4208                               /* Run asymmetr    4007                               /* Run asymmetric signature verification */
4209                               crypto_akcipher    4008                               crypto_akcipher_verify(req) :
4210                               /* Run asymmetr    4009                               /* Run asymmetric encrypt */
4211                               crypto_akcipher    4010                               crypto_akcipher_encrypt(req), &wait);
4212         if (err) {                               4011         if (err) {
4213                 pr_err("alg: akcipher: %s tes    4012                 pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
4214                 goto free_all;                   4013                 goto free_all;
4215         }                                        4014         }
4216         if (!vecs->siggen_sigver_test && c) {    4015         if (!vecs->siggen_sigver_test && c) {
4217                 if (req->dst_len != c_size) {    4016                 if (req->dst_len != c_size) {
4218                         pr_err("alg: akcipher    4017                         pr_err("alg: akcipher: %s test failed. Invalid output len\n",
4219                                op);              4018                                op);
4220                         err = -EINVAL;           4019                         err = -EINVAL;
4221                         goto free_all;           4020                         goto free_all;
4222                 }                                4021                 }
4223                 /* verify that encrypted mess    4022                 /* verify that encrypted message is equal to expected */
4224                 if (memcmp(c, outbuf_enc, c_s    4023                 if (memcmp(c, outbuf_enc, c_size) != 0) {
4225                         pr_err("alg: akcipher    4024                         pr_err("alg: akcipher: %s test failed. Invalid output\n",
4226                                op);              4025                                op);
4227                         hexdump(outbuf_enc, c    4026                         hexdump(outbuf_enc, c_size);
4228                         err = -EINVAL;           4027                         err = -EINVAL;
4229                         goto free_all;           4028                         goto free_all;
4230                 }                                4029                 }
4231         }                                        4030         }
4232                                                  4031 
4233         /*                                       4032         /*
4234          * Don't invoke (decrypt or sign) tes    4033          * Don't invoke (decrypt or sign) test which require a private key
4235          * for vectors with only a public key    4034          * for vectors with only a public key.
4236          */                                      4035          */
4237         if (vecs->public_key_vec) {              4036         if (vecs->public_key_vec) {
4238                 err = 0;                         4037                 err = 0;
4239                 goto free_all;                   4038                 goto free_all;
4240         }                                        4039         }
4241         outbuf_dec = kzalloc(out_len_max, GFP    4040         outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
4242         if (!outbuf_dec) {                       4041         if (!outbuf_dec) {
4243                 err = -ENOMEM;                   4042                 err = -ENOMEM;
4244                 goto free_all;                   4043                 goto free_all;
4245         }                                        4044         }
4246                                                  4045 
4247         if (!vecs->siggen_sigver_test && !c)     4046         if (!vecs->siggen_sigver_test && !c) {
4248                 c = outbuf_enc;                  4047                 c = outbuf_enc;
4249                 c_size = req->dst_len;           4048                 c_size = req->dst_len;
4250         }                                        4049         }
4251                                                  4050 
4252         err = -E2BIG;                            4051         err = -E2BIG;
4253         op = vecs->siggen_sigver_test ? "sign    4052         op = vecs->siggen_sigver_test ? "sign" : "decrypt";
4254         if (WARN_ON(c_size > PAGE_SIZE))         4053         if (WARN_ON(c_size > PAGE_SIZE))
4255                 goto free_all;                   4054                 goto free_all;
4256         memcpy(xbuf[0], c, c_size);              4055         memcpy(xbuf[0], c, c_size);
4257                                                  4056 
4258         sg_init_one(&src, xbuf[0], c_size);      4057         sg_init_one(&src, xbuf[0], c_size);
4259         sg_init_one(&dst, outbuf_dec, out_len    4058         sg_init_one(&dst, outbuf_dec, out_len_max);
4260         crypto_init_wait(&wait);                 4059         crypto_init_wait(&wait);
4261         akcipher_request_set_crypt(req, &src,    4060         akcipher_request_set_crypt(req, &src, &dst, c_size, out_len_max);
4262                                                  4061 
4263         err = crypto_wait_req(vecs->siggen_si    4062         err = crypto_wait_req(vecs->siggen_sigver_test ?
4264                               /* Run asymmetr    4063                               /* Run asymmetric signature generation */
4265                               crypto_akcipher    4064                               crypto_akcipher_sign(req) :
4266                               /* Run asymmetr    4065                               /* Run asymmetric decrypt */
4267                               crypto_akcipher    4066                               crypto_akcipher_decrypt(req), &wait);
4268         if (err) {                               4067         if (err) {
4269                 pr_err("alg: akcipher: %s tes    4068                 pr_err("alg: akcipher: %s test failed. err %d\n", op, err);
4270                 goto free_all;                   4069                 goto free_all;
4271         }                                        4070         }
4272         out_len = req->dst_len;                  4071         out_len = req->dst_len;
4273         if (out_len < m_size) {                  4072         if (out_len < m_size) {
4274                 pr_err("alg: akcipher: %s tes    4073                 pr_err("alg: akcipher: %s test failed. Invalid output len %u\n",
4275                        op, out_len);             4074                        op, out_len);
4276                 err = -EINVAL;                   4075                 err = -EINVAL;
4277                 goto free_all;                   4076                 goto free_all;
4278         }                                        4077         }
4279         /* verify that decrypted message is e    4078         /* verify that decrypted message is equal to the original msg */
4280         if (memchr_inv(outbuf_dec, 0, out_len    4079         if (memchr_inv(outbuf_dec, 0, out_len - m_size) ||
4281             memcmp(m, outbuf_dec + out_len -     4080             memcmp(m, outbuf_dec + out_len - m_size, m_size)) {
4282                 pr_err("alg: akcipher: %s tes    4081                 pr_err("alg: akcipher: %s test failed. Invalid output\n", op);
4283                 hexdump(outbuf_dec, out_len);    4082                 hexdump(outbuf_dec, out_len);
4284                 err = -EINVAL;                   4083                 err = -EINVAL;
4285         }                                        4084         }
4286 free_all:                                        4085 free_all:
4287         kfree(outbuf_dec);                       4086         kfree(outbuf_dec);
4288         kfree(outbuf_enc);                       4087         kfree(outbuf_enc);
4289 free_key:                                        4088 free_key:
4290         kfree(key);                              4089         kfree(key);
4291 free_req:                                        4090 free_req:
4292         akcipher_request_free(req);              4091         akcipher_request_free(req);
4293 free_xbuf:                                       4092 free_xbuf:
4294         testmgr_free_buf(xbuf);                  4093         testmgr_free_buf(xbuf);
4295         return err;                              4094         return err;
4296 }                                                4095 }
4297                                                  4096 
4298 static int test_akcipher(struct crypto_akciph    4097 static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
4299                          const struct akciphe    4098                          const struct akcipher_testvec *vecs,
4300                          unsigned int tcount)    4099                          unsigned int tcount)
4301 {                                                4100 {
4302         const char *algo =                       4101         const char *algo =
4303                 crypto_tfm_alg_driver_name(cr    4102                 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
4304         int ret, i;                              4103         int ret, i;
4305                                                  4104 
4306         for (i = 0; i < tcount; i++) {           4105         for (i = 0; i < tcount; i++) {
4307                 ret = test_akcipher_one(tfm,     4106                 ret = test_akcipher_one(tfm, vecs++);
4308                 if (!ret)                        4107                 if (!ret)
4309                         continue;                4108                         continue;
4310                                                  4109 
4311                 pr_err("alg: akcipher: test %    4110                 pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
4312                        i + 1, algo, ret);        4111                        i + 1, algo, ret);
4313                 return ret;                      4112                 return ret;
4314         }                                        4113         }
4315         return 0;                                4114         return 0;
4316 }                                                4115 }
4317                                                  4116 
4318 static int alg_test_akcipher(const struct alg    4117 static int alg_test_akcipher(const struct alg_test_desc *desc,
4319                              const char *driv    4118                              const char *driver, u32 type, u32 mask)
4320 {                                                4119 {
4321         struct crypto_akcipher *tfm;             4120         struct crypto_akcipher *tfm;
4322         int err = 0;                             4121         int err = 0;
4323                                                  4122 
4324         tfm = crypto_alloc_akcipher(driver, t    4123         tfm = crypto_alloc_akcipher(driver, type, mask);
4325         if (IS_ERR(tfm)) {                       4124         if (IS_ERR(tfm)) {
4326                 if (PTR_ERR(tfm) == -ENOENT)  << 
4327                         return 0;             << 
4328                 pr_err("alg: akcipher: Failed    4125                 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
4329                        driver, PTR_ERR(tfm));    4126                        driver, PTR_ERR(tfm));
4330                 return PTR_ERR(tfm);             4127                 return PTR_ERR(tfm);
4331         }                                        4128         }
4332         if (desc->suite.akcipher.vecs)           4129         if (desc->suite.akcipher.vecs)
4333                 err = test_akcipher(tfm, desc    4130                 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
4334                                     desc->sui    4131                                     desc->suite.akcipher.count);
4335                                                  4132 
4336         crypto_free_akcipher(tfm);               4133         crypto_free_akcipher(tfm);
4337         return err;                              4134         return err;
4338 }                                                4135 }
4339                                                  4136 
4340 static int alg_test_null(const struct alg_tes    4137 static int alg_test_null(const struct alg_test_desc *desc,
4341                              const char *driv    4138                              const char *driver, u32 type, u32 mask)
4342 {                                                4139 {
4343         return 0;                                4140         return 0;
4344 }                                                4141 }
4345                                                  4142 
4346 #define ____VECS(tv)    .vecs = tv, .count =     4143 #define ____VECS(tv)    .vecs = tv, .count = ARRAY_SIZE(tv)
4347 #define __VECS(tv)      { ____VECS(tv) }         4144 #define __VECS(tv)      { ____VECS(tv) }
4348                                                  4145 
4349 /* Please keep this list sorted by algorithm     4146 /* Please keep this list sorted by algorithm name. */
4350 static const struct alg_test_desc alg_test_de    4147 static const struct alg_test_desc alg_test_descs[] = {
4351         {                                        4148         {
4352                 .alg = "adiantum(xchacha12,ae    4149                 .alg = "adiantum(xchacha12,aes)",
4353                 .generic_driver = "adiantum(x    4150                 .generic_driver = "adiantum(xchacha12-generic,aes-generic,nhpoly1305-generic)",
4354                 .test = alg_test_skcipher,       4151                 .test = alg_test_skcipher,
4355                 .suite = {                       4152                 .suite = {
4356                         .cipher = __VECS(adia    4153                         .cipher = __VECS(adiantum_xchacha12_aes_tv_template)
4357                 },                               4154                 },
4358         }, {                                     4155         }, {
4359                 .alg = "adiantum(xchacha20,ae    4156                 .alg = "adiantum(xchacha20,aes)",
4360                 .generic_driver = "adiantum(x    4157                 .generic_driver = "adiantum(xchacha20-generic,aes-generic,nhpoly1305-generic)",
4361                 .test = alg_test_skcipher,       4158                 .test = alg_test_skcipher,
4362                 .suite = {                       4159                 .suite = {
4363                         .cipher = __VECS(adia    4160                         .cipher = __VECS(adiantum_xchacha20_aes_tv_template)
4364                 },                               4161                 },
4365         }, {                                     4162         }, {
4366                 .alg = "aegis128",               4163                 .alg = "aegis128",
4367                 .test = alg_test_aead,           4164                 .test = alg_test_aead,
4368                 .suite = {                       4165                 .suite = {
4369                         .aead = __VECS(aegis1    4166                         .aead = __VECS(aegis128_tv_template)
4370                 }                                4167                 }
4371         }, {                                     4168         }, {
4372                 .alg = "ansi_cprng",             4169                 .alg = "ansi_cprng",
4373                 .test = alg_test_cprng,          4170                 .test = alg_test_cprng,
4374                 .suite = {                       4171                 .suite = {
4375                         .cprng = __VECS(ansi_    4172                         .cprng = __VECS(ansi_cprng_aes_tv_template)
4376                 }                                4173                 }
4377         }, {                                     4174         }, {
4378                 .alg = "authenc(hmac(md5),ecb    4175                 .alg = "authenc(hmac(md5),ecb(cipher_null))",
4379                 .test = alg_test_aead,           4176                 .test = alg_test_aead,
4380                 .suite = {                       4177                 .suite = {
4381                         .aead = __VECS(hmac_m    4178                         .aead = __VECS(hmac_md5_ecb_cipher_null_tv_template)
4382                 }                                4179                 }
4383         }, {                                     4180         }, {
4384                 .alg = "authenc(hmac(sha1),cb    4181                 .alg = "authenc(hmac(sha1),cbc(aes))",
4385                 .test = alg_test_aead,           4182                 .test = alg_test_aead,
4386                 .fips_allowed = 1,               4183                 .fips_allowed = 1,
4387                 .suite = {                       4184                 .suite = {
4388                         .aead = __VECS(hmac_s    4185                         .aead = __VECS(hmac_sha1_aes_cbc_tv_temp)
4389                 }                                4186                 }
4390         }, {                                     4187         }, {
4391                 .alg = "authenc(hmac(sha1),cb    4188                 .alg = "authenc(hmac(sha1),cbc(des))",
4392                 .test = alg_test_aead,           4189                 .test = alg_test_aead,
4393                 .suite = {                       4190                 .suite = {
4394                         .aead = __VECS(hmac_s    4191                         .aead = __VECS(hmac_sha1_des_cbc_tv_temp)
4395                 }                                4192                 }
4396         }, {                                     4193         }, {
4397                 .alg = "authenc(hmac(sha1),cb    4194                 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
4398                 .test = alg_test_aead,           4195                 .test = alg_test_aead,
                                                   >> 4196                 .fips_allowed = 1,
4399                 .suite = {                       4197                 .suite = {
4400                         .aead = __VECS(hmac_s    4198                         .aead = __VECS(hmac_sha1_des3_ede_cbc_tv_temp)
4401                 }                                4199                 }
4402         }, {                                     4200         }, {
4403                 .alg = "authenc(hmac(sha1),ct    4201                 .alg = "authenc(hmac(sha1),ctr(aes))",
4404                 .test = alg_test_null,           4202                 .test = alg_test_null,
4405                 .fips_allowed = 1,               4203                 .fips_allowed = 1,
4406         }, {                                     4204         }, {
4407                 .alg = "authenc(hmac(sha1),ec    4205                 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
4408                 .test = alg_test_aead,           4206                 .test = alg_test_aead,
4409                 .suite = {                       4207                 .suite = {
4410                         .aead = __VECS(hmac_s    4208                         .aead = __VECS(hmac_sha1_ecb_cipher_null_tv_temp)
4411                 }                                4209                 }
4412         }, {                                     4210         }, {
4413                 .alg = "authenc(hmac(sha1),rf    4211                 .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))",
4414                 .test = alg_test_null,           4212                 .test = alg_test_null,
4415                 .fips_allowed = 1,               4213                 .fips_allowed = 1,
4416         }, {                                     4214         }, {
4417                 .alg = "authenc(hmac(sha224),    4215                 .alg = "authenc(hmac(sha224),cbc(des))",
4418                 .test = alg_test_aead,           4216                 .test = alg_test_aead,
4419                 .suite = {                       4217                 .suite = {
4420                         .aead = __VECS(hmac_s    4218                         .aead = __VECS(hmac_sha224_des_cbc_tv_temp)
4421                 }                                4219                 }
4422         }, {                                     4220         }, {
4423                 .alg = "authenc(hmac(sha224),    4221                 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
4424                 .test = alg_test_aead,           4222                 .test = alg_test_aead,
                                                   >> 4223                 .fips_allowed = 1,
4425                 .suite = {                       4224                 .suite = {
4426                         .aead = __VECS(hmac_s    4225                         .aead = __VECS(hmac_sha224_des3_ede_cbc_tv_temp)
4427                 }                                4226                 }
4428         }, {                                     4227         }, {
4429                 .alg = "authenc(hmac(sha256),    4228                 .alg = "authenc(hmac(sha256),cbc(aes))",
4430                 .test = alg_test_aead,           4229                 .test = alg_test_aead,
4431                 .fips_allowed = 1,               4230                 .fips_allowed = 1,
4432                 .suite = {                       4231                 .suite = {
4433                         .aead = __VECS(hmac_s    4232                         .aead = __VECS(hmac_sha256_aes_cbc_tv_temp)
4434                 }                                4233                 }
4435         }, {                                     4234         }, {
4436                 .alg = "authenc(hmac(sha256),    4235                 .alg = "authenc(hmac(sha256),cbc(des))",
4437                 .test = alg_test_aead,           4236                 .test = alg_test_aead,
4438                 .suite = {                       4237                 .suite = {
4439                         .aead = __VECS(hmac_s    4238                         .aead = __VECS(hmac_sha256_des_cbc_tv_temp)
4440                 }                                4239                 }
4441         }, {                                     4240         }, {
4442                 .alg = "authenc(hmac(sha256),    4241                 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
4443                 .test = alg_test_aead,           4242                 .test = alg_test_aead,
                                                   >> 4243                 .fips_allowed = 1,
4444                 .suite = {                       4244                 .suite = {
4445                         .aead = __VECS(hmac_s    4245                         .aead = __VECS(hmac_sha256_des3_ede_cbc_tv_temp)
4446                 }                                4246                 }
4447         }, {                                     4247         }, {
4448                 .alg = "authenc(hmac(sha256),    4248                 .alg = "authenc(hmac(sha256),ctr(aes))",
4449                 .test = alg_test_null,           4249                 .test = alg_test_null,
4450                 .fips_allowed = 1,               4250                 .fips_allowed = 1,
4451         }, {                                     4251         }, {
4452                 .alg = "authenc(hmac(sha256),    4252                 .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))",
4453                 .test = alg_test_null,           4253                 .test = alg_test_null,
4454                 .fips_allowed = 1,               4254                 .fips_allowed = 1,
4455         }, {                                     4255         }, {
4456                 .alg = "authenc(hmac(sha384),    4256                 .alg = "authenc(hmac(sha384),cbc(des))",
4457                 .test = alg_test_aead,           4257                 .test = alg_test_aead,
4458                 .suite = {                       4258                 .suite = {
4459                         .aead = __VECS(hmac_s    4259                         .aead = __VECS(hmac_sha384_des_cbc_tv_temp)
4460                 }                                4260                 }
4461         }, {                                     4261         }, {
4462                 .alg = "authenc(hmac(sha384),    4262                 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
4463                 .test = alg_test_aead,           4263                 .test = alg_test_aead,
                                                   >> 4264                 .fips_allowed = 1,
4464                 .suite = {                       4265                 .suite = {
4465                         .aead = __VECS(hmac_s    4266                         .aead = __VECS(hmac_sha384_des3_ede_cbc_tv_temp)
4466                 }                                4267                 }
4467         }, {                                     4268         }, {
4468                 .alg = "authenc(hmac(sha384),    4269                 .alg = "authenc(hmac(sha384),ctr(aes))",
4469                 .test = alg_test_null,           4270                 .test = alg_test_null,
4470                 .fips_allowed = 1,               4271                 .fips_allowed = 1,
4471         }, {                                     4272         }, {
4472                 .alg = "authenc(hmac(sha384),    4273                 .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))",
4473                 .test = alg_test_null,           4274                 .test = alg_test_null,
4474                 .fips_allowed = 1,               4275                 .fips_allowed = 1,
4475         }, {                                     4276         }, {
4476                 .alg = "authenc(hmac(sha512),    4277                 .alg = "authenc(hmac(sha512),cbc(aes))",
4477                 .fips_allowed = 1,               4278                 .fips_allowed = 1,
4478                 .test = alg_test_aead,           4279                 .test = alg_test_aead,
4479                 .suite = {                       4280                 .suite = {
4480                         .aead = __VECS(hmac_s    4281                         .aead = __VECS(hmac_sha512_aes_cbc_tv_temp)
4481                 }                                4282                 }
4482         }, {                                     4283         }, {
4483                 .alg = "authenc(hmac(sha512),    4284                 .alg = "authenc(hmac(sha512),cbc(des))",
4484                 .test = alg_test_aead,           4285                 .test = alg_test_aead,
4485                 .suite = {                       4286                 .suite = {
4486                         .aead = __VECS(hmac_s    4287                         .aead = __VECS(hmac_sha512_des_cbc_tv_temp)
4487                 }                                4288                 }
4488         }, {                                     4289         }, {
4489                 .alg = "authenc(hmac(sha512),    4290                 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
4490                 .test = alg_test_aead,           4291                 .test = alg_test_aead,
                                                   >> 4292                 .fips_allowed = 1,
4491                 .suite = {                       4293                 .suite = {
4492                         .aead = __VECS(hmac_s    4294                         .aead = __VECS(hmac_sha512_des3_ede_cbc_tv_temp)
4493                 }                                4295                 }
4494         }, {                                     4296         }, {
4495                 .alg = "authenc(hmac(sha512),    4297                 .alg = "authenc(hmac(sha512),ctr(aes))",
4496                 .test = alg_test_null,           4298                 .test = alg_test_null,
4497                 .fips_allowed = 1,               4299                 .fips_allowed = 1,
4498         }, {                                     4300         }, {
4499                 .alg = "authenc(hmac(sha512),    4301                 .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))",
4500                 .test = alg_test_null,           4302                 .test = alg_test_null,
4501                 .fips_allowed = 1,               4303                 .fips_allowed = 1,
4502         }, {                                     4304         }, {
4503                 .alg = "blake2b-160",            4305                 .alg = "blake2b-160",
4504                 .test = alg_test_hash,           4306                 .test = alg_test_hash,
4505                 .fips_allowed = 0,               4307                 .fips_allowed = 0,
4506                 .suite = {                       4308                 .suite = {
4507                         .hash = __VECS(blake2    4309                         .hash = __VECS(blake2b_160_tv_template)
4508                 }                                4310                 }
4509         }, {                                     4311         }, {
4510                 .alg = "blake2b-256",            4312                 .alg = "blake2b-256",
4511                 .test = alg_test_hash,           4313                 .test = alg_test_hash,
4512                 .fips_allowed = 0,               4314                 .fips_allowed = 0,
4513                 .suite = {                       4315                 .suite = {
4514                         .hash = __VECS(blake2    4316                         .hash = __VECS(blake2b_256_tv_template)
4515                 }                                4317                 }
4516         }, {                                     4318         }, {
4517                 .alg = "blake2b-384",            4319                 .alg = "blake2b-384",
4518                 .test = alg_test_hash,           4320                 .test = alg_test_hash,
4519                 .fips_allowed = 0,               4321                 .fips_allowed = 0,
4520                 .suite = {                       4322                 .suite = {
4521                         .hash = __VECS(blake2    4323                         .hash = __VECS(blake2b_384_tv_template)
4522                 }                                4324                 }
4523         }, {                                     4325         }, {
4524                 .alg = "blake2b-512",            4326                 .alg = "blake2b-512",
4525                 .test = alg_test_hash,           4327                 .test = alg_test_hash,
4526                 .fips_allowed = 0,               4328                 .fips_allowed = 0,
4527                 .suite = {                       4329                 .suite = {
4528                         .hash = __VECS(blake2    4330                         .hash = __VECS(blake2b_512_tv_template)
4529                 }                                4331                 }
4530         }, {                                     4332         }, {
                                                   >> 4333                 .alg = "blake2s-128",
                                                   >> 4334                 .test = alg_test_hash,
                                                   >> 4335                 .suite = {
                                                   >> 4336                         .hash = __VECS(blakes2s_128_tv_template)
                                                   >> 4337                 }
                                                   >> 4338         }, {
                                                   >> 4339                 .alg = "blake2s-160",
                                                   >> 4340                 .test = alg_test_hash,
                                                   >> 4341                 .suite = {
                                                   >> 4342                         .hash = __VECS(blakes2s_160_tv_template)
                                                   >> 4343                 }
                                                   >> 4344         }, {
                                                   >> 4345                 .alg = "blake2s-224",
                                                   >> 4346                 .test = alg_test_hash,
                                                   >> 4347                 .suite = {
                                                   >> 4348                         .hash = __VECS(blakes2s_224_tv_template)
                                                   >> 4349                 }
                                                   >> 4350         }, {
                                                   >> 4351                 .alg = "blake2s-256",
                                                   >> 4352                 .test = alg_test_hash,
                                                   >> 4353                 .suite = {
                                                   >> 4354                         .hash = __VECS(blakes2s_256_tv_template)
                                                   >> 4355                 }
                                                   >> 4356         }, {
4531                 .alg = "cbc(aes)",               4357                 .alg = "cbc(aes)",
4532                 .test = alg_test_skcipher,       4358                 .test = alg_test_skcipher,
4533                 .fips_allowed = 1,               4359                 .fips_allowed = 1,
4534                 .suite = {                       4360                 .suite = {
4535                         .cipher = __VECS(aes_    4361                         .cipher = __VECS(aes_cbc_tv_template)
4536                 },                               4362                 },
4537         }, {                                     4363         }, {
4538                 .alg = "cbc(anubis)",            4364                 .alg = "cbc(anubis)",
4539                 .test = alg_test_skcipher,       4365                 .test = alg_test_skcipher,
4540                 .suite = {                       4366                 .suite = {
4541                         .cipher = __VECS(anub    4367                         .cipher = __VECS(anubis_cbc_tv_template)
4542                 },                               4368                 },
4543         }, {                                     4369         }, {
4544                 .alg = "cbc(aria)",           << 
4545                 .test = alg_test_skcipher,    << 
4546                 .suite = {                    << 
4547                         .cipher = __VECS(aria << 
4548                 },                            << 
4549         }, {                                  << 
4550                 .alg = "cbc(blowfish)",          4370                 .alg = "cbc(blowfish)",
4551                 .test = alg_test_skcipher,       4371                 .test = alg_test_skcipher,
4552                 .suite = {                       4372                 .suite = {
4553                         .cipher = __VECS(bf_c    4373                         .cipher = __VECS(bf_cbc_tv_template)
4554                 },                               4374                 },
4555         }, {                                     4375         }, {
4556                 .alg = "cbc(camellia)",          4376                 .alg = "cbc(camellia)",
4557                 .test = alg_test_skcipher,       4377                 .test = alg_test_skcipher,
4558                 .suite = {                       4378                 .suite = {
4559                         .cipher = __VECS(came    4379                         .cipher = __VECS(camellia_cbc_tv_template)
4560                 },                               4380                 },
4561         }, {                                     4381         }, {
4562                 .alg = "cbc(cast5)",             4382                 .alg = "cbc(cast5)",
4563                 .test = alg_test_skcipher,       4383                 .test = alg_test_skcipher,
4564                 .suite = {                       4384                 .suite = {
4565                         .cipher = __VECS(cast    4385                         .cipher = __VECS(cast5_cbc_tv_template)
4566                 },                               4386                 },
4567         }, {                                     4387         }, {
4568                 .alg = "cbc(cast6)",             4388                 .alg = "cbc(cast6)",
4569                 .test = alg_test_skcipher,       4389                 .test = alg_test_skcipher,
4570                 .suite = {                       4390                 .suite = {
4571                         .cipher = __VECS(cast    4391                         .cipher = __VECS(cast6_cbc_tv_template)
4572                 },                               4392                 },
4573         }, {                                     4393         }, {
4574                 .alg = "cbc(des)",               4394                 .alg = "cbc(des)",
4575                 .test = alg_test_skcipher,       4395                 .test = alg_test_skcipher,
4576                 .suite = {                       4396                 .suite = {
4577                         .cipher = __VECS(des_    4397                         .cipher = __VECS(des_cbc_tv_template)
4578                 },                               4398                 },
4579         }, {                                     4399         }, {
4580                 .alg = "cbc(des3_ede)",          4400                 .alg = "cbc(des3_ede)",
4581                 .test = alg_test_skcipher,       4401                 .test = alg_test_skcipher,
                                                   >> 4402                 .fips_allowed = 1,
4582                 .suite = {                       4403                 .suite = {
4583                         .cipher = __VECS(des3    4404                         .cipher = __VECS(des3_ede_cbc_tv_template)
4584                 },                               4405                 },
4585         }, {                                     4406         }, {
4586                 /* Same as cbc(aes) except th    4407                 /* Same as cbc(aes) except the key is stored in
4587                  * hardware secure memory whi    4408                  * hardware secure memory which we reference by index
4588                  */                              4409                  */
4589                 .alg = "cbc(paes)",              4410                 .alg = "cbc(paes)",
4590                 .test = alg_test_null,           4411                 .test = alg_test_null,
4591                 .fips_allowed = 1,               4412                 .fips_allowed = 1,
4592         }, {                                     4413         }, {
4593                 /* Same as cbc(sm4) except th    4414                 /* Same as cbc(sm4) except the key is stored in
4594                  * hardware secure memory whi    4415                  * hardware secure memory which we reference by index
4595                  */                              4416                  */
4596                 .alg = "cbc(psm4)",              4417                 .alg = "cbc(psm4)",
4597                 .test = alg_test_null,           4418                 .test = alg_test_null,
4598         }, {                                     4419         }, {
4599                 .alg = "cbc(serpent)",           4420                 .alg = "cbc(serpent)",
4600                 .test = alg_test_skcipher,       4421                 .test = alg_test_skcipher,
4601                 .suite = {                       4422                 .suite = {
4602                         .cipher = __VECS(serp    4423                         .cipher = __VECS(serpent_cbc_tv_template)
4603                 },                               4424                 },
4604         }, {                                     4425         }, {
4605                 .alg = "cbc(sm4)",               4426                 .alg = "cbc(sm4)",
4606                 .test = alg_test_skcipher,       4427                 .test = alg_test_skcipher,
4607                 .suite = {                       4428                 .suite = {
4608                         .cipher = __VECS(sm4_    4429                         .cipher = __VECS(sm4_cbc_tv_template)
4609                 }                                4430                 }
4610         }, {                                     4431         }, {
4611                 .alg = "cbc(twofish)",           4432                 .alg = "cbc(twofish)",
4612                 .test = alg_test_skcipher,       4433                 .test = alg_test_skcipher,
4613                 .suite = {                       4434                 .suite = {
4614                         .cipher = __VECS(tf_c    4435                         .cipher = __VECS(tf_cbc_tv_template)
4615                 },                               4436                 },
4616         }, {                                     4437         }, {
4617 #if IS_ENABLED(CONFIG_CRYPTO_PAES_S390)          4438 #if IS_ENABLED(CONFIG_CRYPTO_PAES_S390)
4618                 .alg = "cbc-paes-s390",          4439                 .alg = "cbc-paes-s390",
4619                 .fips_allowed = 1,               4440                 .fips_allowed = 1,
4620                 .test = alg_test_skcipher,       4441                 .test = alg_test_skcipher,
4621                 .suite = {                       4442                 .suite = {
4622                         .cipher = __VECS(aes_    4443                         .cipher = __VECS(aes_cbc_tv_template)
4623                 }                                4444                 }
4624         }, {                                     4445         }, {
4625 #endif                                           4446 #endif
4626                 .alg = "cbcmac(aes)",            4447                 .alg = "cbcmac(aes)",
                                                   >> 4448                 .fips_allowed = 1,
4627                 .test = alg_test_hash,           4449                 .test = alg_test_hash,
4628                 .suite = {                       4450                 .suite = {
4629                         .hash = __VECS(aes_cb    4451                         .hash = __VECS(aes_cbcmac_tv_template)
4630                 }                                4452                 }
4631         }, {                                     4453         }, {
4632                 .alg = "cbcmac(sm4)",         << 
4633                 .test = alg_test_hash,        << 
4634                 .suite = {                    << 
4635                         .hash = __VECS(sm4_cb << 
4636                 }                             << 
4637         }, {                                  << 
4638                 .alg = "ccm(aes)",               4454                 .alg = "ccm(aes)",
4639                 .generic_driver = "ccm_base(c    4455                 .generic_driver = "ccm_base(ctr(aes-generic),cbcmac(aes-generic))",
4640                 .test = alg_test_aead,           4456                 .test = alg_test_aead,
4641                 .fips_allowed = 1,               4457                 .fips_allowed = 1,
4642                 .suite = {                       4458                 .suite = {
4643                         .aead = {                4459                         .aead = {
4644                                 ____VECS(aes_    4460                                 ____VECS(aes_ccm_tv_template),
4645                                 .einval_allow    4461                                 .einval_allowed = 1,
4646                         }                        4462                         }
4647                 }                                4463                 }
4648         }, {                                     4464         }, {
4649                 .alg = "ccm(sm4)",            !! 4465                 .alg = "cfb(aes)",
4650                 .generic_driver = "ccm_base(c !! 4466                 .test = alg_test_skcipher,
4651                 .test = alg_test_aead,        !! 4467                 .fips_allowed = 1,
4652                 .suite = {                       4468                 .suite = {
4653                         .aead = {             !! 4469                         .cipher = __VECS(aes_cfb_tv_template)
4654                                 ____VECS(sm4_ !! 4470                 },
4655                                 .einval_allow !! 4471         }, {
4656                         }                     !! 4472                 .alg = "cfb(sm4)",
                                                   >> 4473                 .test = alg_test_skcipher,
                                                   >> 4474                 .suite = {
                                                   >> 4475                         .cipher = __VECS(sm4_cfb_tv_template)
4657                 }                                4476                 }
4658         }, {                                     4477         }, {
4659                 .alg = "chacha20",               4478                 .alg = "chacha20",
4660                 .test = alg_test_skcipher,       4479                 .test = alg_test_skcipher,
4661                 .suite = {                       4480                 .suite = {
4662                         .cipher = __VECS(chac    4481                         .cipher = __VECS(chacha20_tv_template)
4663                 },                               4482                 },
4664         }, {                                     4483         }, {
4665                 .alg = "cmac(aes)",              4484                 .alg = "cmac(aes)",
4666                 .fips_allowed = 1,               4485                 .fips_allowed = 1,
4667                 .test = alg_test_hash,           4486                 .test = alg_test_hash,
4668                 .suite = {                       4487                 .suite = {
4669                         .hash = __VECS(aes_cm    4488                         .hash = __VECS(aes_cmac128_tv_template)
4670                 }                                4489                 }
4671         }, {                                     4490         }, {
4672                 .alg = "cmac(camellia)",      << 
4673                 .test = alg_test_hash,        << 
4674                 .suite = {                    << 
4675                         .hash = __VECS(camell << 
4676                 }                             << 
4677         }, {                                  << 
4678                 .alg = "cmac(des3_ede)",         4491                 .alg = "cmac(des3_ede)",
                                                   >> 4492                 .fips_allowed = 1,
4679                 .test = alg_test_hash,           4493                 .test = alg_test_hash,
4680                 .suite = {                       4494                 .suite = {
4681                         .hash = __VECS(des3_e    4495                         .hash = __VECS(des3_ede_cmac64_tv_template)
4682                 }                                4496                 }
4683         }, {                                     4497         }, {
4684                 .alg = "cmac(sm4)",           << 
4685                 .test = alg_test_hash,        << 
4686                 .suite = {                    << 
4687                         .hash = __VECS(sm4_cm << 
4688                 }                             << 
4689         }, {                                  << 
4690                 .alg = "compress_null",          4498                 .alg = "compress_null",
4691                 .test = alg_test_null,           4499                 .test = alg_test_null,
4692         }, {                                     4500         }, {
4693                 .alg = "crc32",                  4501                 .alg = "crc32",
4694                 .test = alg_test_hash,           4502                 .test = alg_test_hash,
4695                 .fips_allowed = 1,               4503                 .fips_allowed = 1,
4696                 .suite = {                       4504                 .suite = {
4697                         .hash = __VECS(crc32_    4505                         .hash = __VECS(crc32_tv_template)
4698                 }                                4506                 }
4699         }, {                                     4507         }, {
4700                 .alg = "crc32c",                 4508                 .alg = "crc32c",
4701                 .test = alg_test_crc32c,         4509                 .test = alg_test_crc32c,
4702                 .fips_allowed = 1,               4510                 .fips_allowed = 1,
4703                 .suite = {                       4511                 .suite = {
4704                         .hash = __VECS(crc32c    4512                         .hash = __VECS(crc32c_tv_template)
4705                 }                                4513                 }
4706         }, {                                     4514         }, {
4707                 .alg = "crc64-rocksoft",      << 
4708                 .test = alg_test_hash,        << 
4709                 .fips_allowed = 1,            << 
4710                 .suite = {                    << 
4711                         .hash = __VECS(crc64_ << 
4712                 }                             << 
4713         }, {                                  << 
4714                 .alg = "crct10dif",              4515                 .alg = "crct10dif",
4715                 .test = alg_test_hash,           4516                 .test = alg_test_hash,
4716                 .fips_allowed = 1,               4517                 .fips_allowed = 1,
4717                 .suite = {                       4518                 .suite = {
4718                         .hash = __VECS(crct10    4519                         .hash = __VECS(crct10dif_tv_template)
4719                 }                                4520                 }
4720         }, {                                     4521         }, {
4721                 .alg = "ctr(aes)",               4522                 .alg = "ctr(aes)",
4722                 .test = alg_test_skcipher,       4523                 .test = alg_test_skcipher,
4723                 .fips_allowed = 1,               4524                 .fips_allowed = 1,
4724                 .suite = {                       4525                 .suite = {
4725                         .cipher = __VECS(aes_    4526                         .cipher = __VECS(aes_ctr_tv_template)
4726                 }                                4527                 }
4727         }, {                                     4528         }, {
4728                 .alg = "ctr(aria)",           << 
4729                 .test = alg_test_skcipher,    << 
4730                 .suite = {                    << 
4731                         .cipher = __VECS(aria << 
4732                 }                             << 
4733         }, {                                  << 
4734                 .alg = "ctr(blowfish)",          4529                 .alg = "ctr(blowfish)",
4735                 .test = alg_test_skcipher,       4530                 .test = alg_test_skcipher,
4736                 .suite = {                       4531                 .suite = {
4737                         .cipher = __VECS(bf_c    4532                         .cipher = __VECS(bf_ctr_tv_template)
4738                 }                                4533                 }
4739         }, {                                     4534         }, {
4740                 .alg = "ctr(camellia)",          4535                 .alg = "ctr(camellia)",
4741                 .test = alg_test_skcipher,       4536                 .test = alg_test_skcipher,
4742                 .suite = {                       4537                 .suite = {
4743                         .cipher = __VECS(came    4538                         .cipher = __VECS(camellia_ctr_tv_template)
4744                 }                                4539                 }
4745         }, {                                     4540         }, {
4746                 .alg = "ctr(cast5)",             4541                 .alg = "ctr(cast5)",
4747                 .test = alg_test_skcipher,       4542                 .test = alg_test_skcipher,
4748                 .suite = {                       4543                 .suite = {
4749                         .cipher = __VECS(cast    4544                         .cipher = __VECS(cast5_ctr_tv_template)
4750                 }                                4545                 }
4751         }, {                                     4546         }, {
4752                 .alg = "ctr(cast6)",             4547                 .alg = "ctr(cast6)",
4753                 .test = alg_test_skcipher,       4548                 .test = alg_test_skcipher,
4754                 .suite = {                       4549                 .suite = {
4755                         .cipher = __VECS(cast    4550                         .cipher = __VECS(cast6_ctr_tv_template)
4756                 }                                4551                 }
4757         }, {                                     4552         }, {
4758                 .alg = "ctr(des)",               4553                 .alg = "ctr(des)",
4759                 .test = alg_test_skcipher,       4554                 .test = alg_test_skcipher,
4760                 .suite = {                       4555                 .suite = {
4761                         .cipher = __VECS(des_    4556                         .cipher = __VECS(des_ctr_tv_template)
4762                 }                                4557                 }
4763         }, {                                     4558         }, {
4764                 .alg = "ctr(des3_ede)",          4559                 .alg = "ctr(des3_ede)",
4765                 .test = alg_test_skcipher,       4560                 .test = alg_test_skcipher,
                                                   >> 4561                 .fips_allowed = 1,
4766                 .suite = {                       4562                 .suite = {
4767                         .cipher = __VECS(des3    4563                         .cipher = __VECS(des3_ede_ctr_tv_template)
4768                 }                                4564                 }
4769         }, {                                     4565         }, {
4770                 /* Same as ctr(aes) except th    4566                 /* Same as ctr(aes) except the key is stored in
4771                  * hardware secure memory whi    4567                  * hardware secure memory which we reference by index
4772                  */                              4568                  */
4773                 .alg = "ctr(paes)",              4569                 .alg = "ctr(paes)",
4774                 .test = alg_test_null,           4570                 .test = alg_test_null,
4775                 .fips_allowed = 1,               4571                 .fips_allowed = 1,
4776         }, {                                     4572         }, {
4777                                                  4573 
4778                 /* Same as ctr(sm4) except th    4574                 /* Same as ctr(sm4) except the key is stored in
4779                  * hardware secure memory whi    4575                  * hardware secure memory which we reference by index
4780                  */                              4576                  */
4781                 .alg = "ctr(psm4)",              4577                 .alg = "ctr(psm4)",
4782                 .test = alg_test_null,           4578                 .test = alg_test_null,
4783         }, {                                     4579         }, {
4784                 .alg = "ctr(serpent)",           4580                 .alg = "ctr(serpent)",
4785                 .test = alg_test_skcipher,       4581                 .test = alg_test_skcipher,
4786                 .suite = {                       4582                 .suite = {
4787                         .cipher = __VECS(serp    4583                         .cipher = __VECS(serpent_ctr_tv_template)
4788                 }                                4584                 }
4789         }, {                                     4585         }, {
4790                 .alg = "ctr(sm4)",               4586                 .alg = "ctr(sm4)",
4791                 .test = alg_test_skcipher,       4587                 .test = alg_test_skcipher,
4792                 .suite = {                       4588                 .suite = {
4793                         .cipher = __VECS(sm4_    4589                         .cipher = __VECS(sm4_ctr_tv_template)
4794                 }                                4590                 }
4795         }, {                                     4591         }, {
4796                 .alg = "ctr(twofish)",           4592                 .alg = "ctr(twofish)",
4797                 .test = alg_test_skcipher,       4593                 .test = alg_test_skcipher,
4798                 .suite = {                       4594                 .suite = {
4799                         .cipher = __VECS(tf_c    4595                         .cipher = __VECS(tf_ctr_tv_template)
4800                 }                                4596                 }
4801         }, {                                     4597         }, {
4802 #if IS_ENABLED(CONFIG_CRYPTO_PAES_S390)          4598 #if IS_ENABLED(CONFIG_CRYPTO_PAES_S390)
4803                 .alg = "ctr-paes-s390",          4599                 .alg = "ctr-paes-s390",
4804                 .fips_allowed = 1,               4600                 .fips_allowed = 1,
4805                 .test = alg_test_skcipher,       4601                 .test = alg_test_skcipher,
4806                 .suite = {                       4602                 .suite = {
4807                         .cipher = __VECS(aes_    4603                         .cipher = __VECS(aes_ctr_tv_template)
4808                 }                                4604                 }
4809         }, {                                     4605         }, {
4810 #endif                                           4606 #endif
4811                 .alg = "cts(cbc(aes))",          4607                 .alg = "cts(cbc(aes))",
4812                 .test = alg_test_skcipher,       4608                 .test = alg_test_skcipher,
4813                 .fips_allowed = 1,               4609                 .fips_allowed = 1,
4814                 .suite = {                       4610                 .suite = {
4815                         .cipher = __VECS(cts_    4611                         .cipher = __VECS(cts_mode_tv_template)
4816                 }                                4612                 }
4817         }, {                                     4613         }, {
4818                 /* Same as cts(cbc((aes)) exc    4614                 /* Same as cts(cbc((aes)) except the key is stored in
4819                  * hardware secure memory whi    4615                  * hardware secure memory which we reference by index
4820                  */                              4616                  */
4821                 .alg = "cts(cbc(paes))",         4617                 .alg = "cts(cbc(paes))",
4822                 .test = alg_test_null,           4618                 .test = alg_test_null,
4823                 .fips_allowed = 1,               4619                 .fips_allowed = 1,
4824         }, {                                     4620         }, {
4825                 .alg = "cts(cbc(sm4))",       << 
4826                 .test = alg_test_skcipher,    << 
4827                 .suite = {                    << 
4828                         .cipher = __VECS(sm4_ << 
4829                 }                             << 
4830         }, {                                  << 
4831                 .alg = "curve25519",             4621                 .alg = "curve25519",
4832                 .test = alg_test_kpp,            4622                 .test = alg_test_kpp,
4833                 .suite = {                       4623                 .suite = {
4834                         .kpp = __VECS(curve25    4624                         .kpp = __VECS(curve25519_tv_template)
4835                 }                                4625                 }
4836         }, {                                     4626         }, {
4837                 .alg = "deflate",                4627                 .alg = "deflate",
4838                 .test = alg_test_comp,           4628                 .test = alg_test_comp,
4839                 .fips_allowed = 1,               4629                 .fips_allowed = 1,
4840                 .suite = {                       4630                 .suite = {
4841                         .comp = {                4631                         .comp = {
4842                                 .comp = __VEC    4632                                 .comp = __VECS(deflate_comp_tv_template),
4843                                 .decomp = __V    4633                                 .decomp = __VECS(deflate_decomp_tv_template)
4844                         }                        4634                         }
4845                 }                                4635                 }
4846         }, {                                     4636         }, {
4847                 .alg = "deflate-iaa",         << 
4848                 .test = alg_test_comp,        << 
4849                 .fips_allowed = 1,            << 
4850                 .suite = {                    << 
4851                         .comp = {             << 
4852                                 .comp = __VEC << 
4853                                 .decomp = __V << 
4854                         }                     << 
4855                 }                             << 
4856         }, {                                  << 
4857                 .alg = "dh",                     4637                 .alg = "dh",
4858                 .test = alg_test_kpp,            4638                 .test = alg_test_kpp,
                                                   >> 4639                 .fips_allowed = 1,
4859                 .suite = {                       4640                 .suite = {
4860                         .kpp = __VECS(dh_tv_t    4641                         .kpp = __VECS(dh_tv_template)
4861                 }                                4642                 }
4862         }, {                                     4643         }, {
4863                 .alg = "digest_null",            4644                 .alg = "digest_null",
4864                 .test = alg_test_null,           4645                 .test = alg_test_null,
4865         }, {                                     4646         }, {
4866                 .alg = "drbg_nopr_ctr_aes128"    4647                 .alg = "drbg_nopr_ctr_aes128",
4867                 .test = alg_test_drbg,           4648                 .test = alg_test_drbg,
4868                 .fips_allowed = 1,               4649                 .fips_allowed = 1,
4869                 .suite = {                       4650                 .suite = {
4870                         .drbg = __VECS(drbg_n    4651                         .drbg = __VECS(drbg_nopr_ctr_aes128_tv_template)
4871                 }                                4652                 }
4872         }, {                                     4653         }, {
4873                 .alg = "drbg_nopr_ctr_aes192"    4654                 .alg = "drbg_nopr_ctr_aes192",
4874                 .test = alg_test_drbg,           4655                 .test = alg_test_drbg,
4875                 .fips_allowed = 1,               4656                 .fips_allowed = 1,
4876                 .suite = {                       4657                 .suite = {
4877                         .drbg = __VECS(drbg_n    4658                         .drbg = __VECS(drbg_nopr_ctr_aes192_tv_template)
4878                 }                                4659                 }
4879         }, {                                     4660         }, {
4880                 .alg = "drbg_nopr_ctr_aes256"    4661                 .alg = "drbg_nopr_ctr_aes256",
4881                 .test = alg_test_drbg,           4662                 .test = alg_test_drbg,
4882                 .fips_allowed = 1,               4663                 .fips_allowed = 1,
4883                 .suite = {                       4664                 .suite = {
4884                         .drbg = __VECS(drbg_n    4665                         .drbg = __VECS(drbg_nopr_ctr_aes256_tv_template)
4885                 }                                4666                 }
4886         }, {                                     4667         }, {
                                                   >> 4668                 /*
                                                   >> 4669                  * There is no need to specifically test the DRBG with every
                                                   >> 4670                  * backend cipher -- covered by drbg_nopr_hmac_sha256 test
                                                   >> 4671                  */
                                                   >> 4672                 .alg = "drbg_nopr_hmac_sha1",
                                                   >> 4673                 .fips_allowed = 1,
                                                   >> 4674                 .test = alg_test_null,
                                                   >> 4675         }, {
4887                 .alg = "drbg_nopr_hmac_sha256    4676                 .alg = "drbg_nopr_hmac_sha256",
4888                 .test = alg_test_drbg,           4677                 .test = alg_test_drbg,
4889                 .fips_allowed = 1,               4678                 .fips_allowed = 1,
4890                 .suite = {                       4679                 .suite = {
4891                         .drbg = __VECS(drbg_n    4680                         .drbg = __VECS(drbg_nopr_hmac_sha256_tv_template)
4892                 }                                4681                 }
4893         }, {                                     4682         }, {
4894                 /*                            !! 4683                 /* covered by drbg_nopr_hmac_sha256 test */
4895                  * There is no need to specif << 
4896                  * backend cipher -- covered  << 
4897                  */                           << 
4898                 .alg = "drbg_nopr_hmac_sha384    4684                 .alg = "drbg_nopr_hmac_sha384",
                                                   >> 4685                 .fips_allowed = 1,
4899                 .test = alg_test_null,           4686                 .test = alg_test_null,
4900         }, {                                     4687         }, {
4901                 .alg = "drbg_nopr_hmac_sha512    4688                 .alg = "drbg_nopr_hmac_sha512",
4902                 .test = alg_test_drbg,           4689                 .test = alg_test_drbg,
4903                 .fips_allowed = 1,               4690                 .fips_allowed = 1,
4904                 .suite = {                       4691                 .suite = {
4905                         .drbg = __VECS(drbg_n    4692                         .drbg = __VECS(drbg_nopr_hmac_sha512_tv_template)
4906                 }                                4693                 }
4907         }, {                                     4694         }, {
                                                   >> 4695                 .alg = "drbg_nopr_sha1",
                                                   >> 4696                 .fips_allowed = 1,
                                                   >> 4697                 .test = alg_test_null,
                                                   >> 4698         }, {
4908                 .alg = "drbg_nopr_sha256",       4699                 .alg = "drbg_nopr_sha256",
4909                 .test = alg_test_drbg,           4700                 .test = alg_test_drbg,
4910                 .fips_allowed = 1,               4701                 .fips_allowed = 1,
4911                 .suite = {                       4702                 .suite = {
4912                         .drbg = __VECS(drbg_n    4703                         .drbg = __VECS(drbg_nopr_sha256_tv_template)
4913                 }                                4704                 }
4914         }, {                                     4705         }, {
4915                 /* covered by drbg_nopr_sha25    4706                 /* covered by drbg_nopr_sha256 test */
4916                 .alg = "drbg_nopr_sha384",       4707                 .alg = "drbg_nopr_sha384",
                                                   >> 4708                 .fips_allowed = 1,
4917                 .test = alg_test_null,           4709                 .test = alg_test_null,
4918         }, {                                     4710         }, {
4919                 .alg = "drbg_nopr_sha512",       4711                 .alg = "drbg_nopr_sha512",
4920                 .fips_allowed = 1,               4712                 .fips_allowed = 1,
4921                 .test = alg_test_null,           4713                 .test = alg_test_null,
4922         }, {                                     4714         }, {
4923                 .alg = "drbg_pr_ctr_aes128",     4715                 .alg = "drbg_pr_ctr_aes128",
4924                 .test = alg_test_drbg,           4716                 .test = alg_test_drbg,
4925                 .fips_allowed = 1,               4717                 .fips_allowed = 1,
4926                 .suite = {                       4718                 .suite = {
4927                         .drbg = __VECS(drbg_p    4719                         .drbg = __VECS(drbg_pr_ctr_aes128_tv_template)
4928                 }                                4720                 }
4929         }, {                                     4721         }, {
4930                 /* covered by drbg_pr_ctr_aes    4722                 /* covered by drbg_pr_ctr_aes128 test */
4931                 .alg = "drbg_pr_ctr_aes192",     4723                 .alg = "drbg_pr_ctr_aes192",
4932                 .fips_allowed = 1,               4724                 .fips_allowed = 1,
4933                 .test = alg_test_null,           4725                 .test = alg_test_null,
4934         }, {                                     4726         }, {
4935                 .alg = "drbg_pr_ctr_aes256",     4727                 .alg = "drbg_pr_ctr_aes256",
4936                 .fips_allowed = 1,               4728                 .fips_allowed = 1,
4937                 .test = alg_test_null,           4729                 .test = alg_test_null,
4938         }, {                                     4730         }, {
                                                   >> 4731                 .alg = "drbg_pr_hmac_sha1",
                                                   >> 4732                 .fips_allowed = 1,
                                                   >> 4733                 .test = alg_test_null,
                                                   >> 4734         }, {
4939                 .alg = "drbg_pr_hmac_sha256",    4735                 .alg = "drbg_pr_hmac_sha256",
4940                 .test = alg_test_drbg,           4736                 .test = alg_test_drbg,
4941                 .fips_allowed = 1,               4737                 .fips_allowed = 1,
4942                 .suite = {                       4738                 .suite = {
4943                         .drbg = __VECS(drbg_p    4739                         .drbg = __VECS(drbg_pr_hmac_sha256_tv_template)
4944                 }                                4740                 }
4945         }, {                                     4741         }, {
4946                 /* covered by drbg_pr_hmac_sh    4742                 /* covered by drbg_pr_hmac_sha256 test */
4947                 .alg = "drbg_pr_hmac_sha384",    4743                 .alg = "drbg_pr_hmac_sha384",
                                                   >> 4744                 .fips_allowed = 1,
4948                 .test = alg_test_null,           4745                 .test = alg_test_null,
4949         }, {                                     4746         }, {
4950                 .alg = "drbg_pr_hmac_sha512",    4747                 .alg = "drbg_pr_hmac_sha512",
4951                 .test = alg_test_null,           4748                 .test = alg_test_null,
4952                 .fips_allowed = 1,               4749                 .fips_allowed = 1,
4953         }, {                                     4750         }, {
                                                   >> 4751                 .alg = "drbg_pr_sha1",
                                                   >> 4752                 .fips_allowed = 1,
                                                   >> 4753                 .test = alg_test_null,
                                                   >> 4754         }, {
4954                 .alg = "drbg_pr_sha256",         4755                 .alg = "drbg_pr_sha256",
4955                 .test = alg_test_drbg,           4756                 .test = alg_test_drbg,
4956                 .fips_allowed = 1,               4757                 .fips_allowed = 1,
4957                 .suite = {                       4758                 .suite = {
4958                         .drbg = __VECS(drbg_p    4759                         .drbg = __VECS(drbg_pr_sha256_tv_template)
4959                 }                                4760                 }
4960         }, {                                     4761         }, {
4961                 /* covered by drbg_pr_sha256     4762                 /* covered by drbg_pr_sha256 test */
4962                 .alg = "drbg_pr_sha384",         4763                 .alg = "drbg_pr_sha384",
                                                   >> 4764                 .fips_allowed = 1,
4963                 .test = alg_test_null,           4765                 .test = alg_test_null,
4964         }, {                                     4766         }, {
4965                 .alg = "drbg_pr_sha512",         4767                 .alg = "drbg_pr_sha512",
4966                 .fips_allowed = 1,               4768                 .fips_allowed = 1,
4967                 .test = alg_test_null,           4769                 .test = alg_test_null,
4968         }, {                                     4770         }, {
4969                 .alg = "ecb(aes)",               4771                 .alg = "ecb(aes)",
4970                 .test = alg_test_skcipher,       4772                 .test = alg_test_skcipher,
4971                 .fips_allowed = 1,               4773                 .fips_allowed = 1,
4972                 .suite = {                       4774                 .suite = {
4973                         .cipher = __VECS(aes_    4775                         .cipher = __VECS(aes_tv_template)
4974                 }                                4776                 }
4975         }, {                                     4777         }, {
4976                 .alg = "ecb(anubis)",            4778                 .alg = "ecb(anubis)",
4977                 .test = alg_test_skcipher,       4779                 .test = alg_test_skcipher,
4978                 .suite = {                       4780                 .suite = {
4979                         .cipher = __VECS(anub    4781                         .cipher = __VECS(anubis_tv_template)
4980                 }                                4782                 }
4981         }, {                                     4783         }, {
4982                 .alg = "ecb(arc4)",              4784                 .alg = "ecb(arc4)",
4983                 .generic_driver = "arc4-gener !! 4785                 .generic_driver = "ecb(arc4)-generic",
4984                 .test = alg_test_skcipher,       4786                 .test = alg_test_skcipher,
4985                 .suite = {                       4787                 .suite = {
4986                         .cipher = __VECS(arc4    4788                         .cipher = __VECS(arc4_tv_template)
4987                 }                                4789                 }
4988         }, {                                     4790         }, {
4989                 .alg = "ecb(aria)",           << 
4990                 .test = alg_test_skcipher,    << 
4991                 .suite = {                    << 
4992                         .cipher = __VECS(aria << 
4993                 }                             << 
4994         }, {                                  << 
4995                 .alg = "ecb(blowfish)",          4791                 .alg = "ecb(blowfish)",
4996                 .test = alg_test_skcipher,       4792                 .test = alg_test_skcipher,
4997                 .suite = {                       4793                 .suite = {
4998                         .cipher = __VECS(bf_t    4794                         .cipher = __VECS(bf_tv_template)
4999                 }                                4795                 }
5000         }, {                                     4796         }, {
5001                 .alg = "ecb(camellia)",          4797                 .alg = "ecb(camellia)",
5002                 .test = alg_test_skcipher,       4798                 .test = alg_test_skcipher,
5003                 .suite = {                       4799                 .suite = {
5004                         .cipher = __VECS(came    4800                         .cipher = __VECS(camellia_tv_template)
5005                 }                                4801                 }
5006         }, {                                     4802         }, {
5007                 .alg = "ecb(cast5)",             4803                 .alg = "ecb(cast5)",
5008                 .test = alg_test_skcipher,       4804                 .test = alg_test_skcipher,
5009                 .suite = {                       4805                 .suite = {
5010                         .cipher = __VECS(cast    4806                         .cipher = __VECS(cast5_tv_template)
5011                 }                                4807                 }
5012         }, {                                     4808         }, {
5013                 .alg = "ecb(cast6)",             4809                 .alg = "ecb(cast6)",
5014                 .test = alg_test_skcipher,       4810                 .test = alg_test_skcipher,
5015                 .suite = {                       4811                 .suite = {
5016                         .cipher = __VECS(cast    4812                         .cipher = __VECS(cast6_tv_template)
5017                 }                                4813                 }
5018         }, {                                     4814         }, {
5019                 .alg = "ecb(cipher_null)",       4815                 .alg = "ecb(cipher_null)",
5020                 .test = alg_test_null,           4816                 .test = alg_test_null,
5021                 .fips_allowed = 1,               4817                 .fips_allowed = 1,
5022         }, {                                     4818         }, {
5023                 .alg = "ecb(des)",               4819                 .alg = "ecb(des)",
5024                 .test = alg_test_skcipher,       4820                 .test = alg_test_skcipher,
5025                 .suite = {                       4821                 .suite = {
5026                         .cipher = __VECS(des_    4822                         .cipher = __VECS(des_tv_template)
5027                 }                                4823                 }
5028         }, {                                     4824         }, {
5029                 .alg = "ecb(des3_ede)",          4825                 .alg = "ecb(des3_ede)",
5030                 .test = alg_test_skcipher,       4826                 .test = alg_test_skcipher,
                                                   >> 4827                 .fips_allowed = 1,
5031                 .suite = {                       4828                 .suite = {
5032                         .cipher = __VECS(des3    4829                         .cipher = __VECS(des3_ede_tv_template)
5033                 }                                4830                 }
5034         }, {                                     4831         }, {
5035                 .alg = "ecb(fcrypt)",            4832                 .alg = "ecb(fcrypt)",
5036                 .test = alg_test_skcipher,       4833                 .test = alg_test_skcipher,
5037                 .suite = {                       4834                 .suite = {
5038                         .cipher = {              4835                         .cipher = {
5039                                 .vecs = fcryp    4836                                 .vecs = fcrypt_pcbc_tv_template,
5040                                 .count = 1       4837                                 .count = 1
5041                         }                        4838                         }
5042                 }                                4839                 }
5043         }, {                                     4840         }, {
5044                 .alg = "ecb(khazad)",            4841                 .alg = "ecb(khazad)",
5045                 .test = alg_test_skcipher,       4842                 .test = alg_test_skcipher,
5046                 .suite = {                       4843                 .suite = {
5047                         .cipher = __VECS(khaz    4844                         .cipher = __VECS(khazad_tv_template)
5048                 }                                4845                 }
5049         }, {                                     4846         }, {
5050                 /* Same as ecb(aes) except th    4847                 /* Same as ecb(aes) except the key is stored in
5051                  * hardware secure memory whi    4848                  * hardware secure memory which we reference by index
5052                  */                              4849                  */
5053                 .alg = "ecb(paes)",              4850                 .alg = "ecb(paes)",
5054                 .test = alg_test_null,           4851                 .test = alg_test_null,
5055                 .fips_allowed = 1,               4852                 .fips_allowed = 1,
5056         }, {                                     4853         }, {
5057                 .alg = "ecb(seed)",              4854                 .alg = "ecb(seed)",
5058                 .test = alg_test_skcipher,       4855                 .test = alg_test_skcipher,
5059                 .suite = {                       4856                 .suite = {
5060                         .cipher = __VECS(seed    4857                         .cipher = __VECS(seed_tv_template)
5061                 }                                4858                 }
5062         }, {                                     4859         }, {
5063                 .alg = "ecb(serpent)",           4860                 .alg = "ecb(serpent)",
5064                 .test = alg_test_skcipher,       4861                 .test = alg_test_skcipher,
5065                 .suite = {                       4862                 .suite = {
5066                         .cipher = __VECS(serp    4863                         .cipher = __VECS(serpent_tv_template)
5067                 }                                4864                 }
5068         }, {                                     4865         }, {
5069                 .alg = "ecb(sm4)",               4866                 .alg = "ecb(sm4)",
5070                 .test = alg_test_skcipher,       4867                 .test = alg_test_skcipher,
5071                 .suite = {                       4868                 .suite = {
5072                         .cipher = __VECS(sm4_    4869                         .cipher = __VECS(sm4_tv_template)
5073                 }                                4870                 }
5074         }, {                                     4871         }, {
5075                 .alg = "ecb(tea)",               4872                 .alg = "ecb(tea)",
5076                 .test = alg_test_skcipher,       4873                 .test = alg_test_skcipher,
5077                 .suite = {                       4874                 .suite = {
5078                         .cipher = __VECS(tea_    4875                         .cipher = __VECS(tea_tv_template)
5079                 }                                4876                 }
5080         }, {                                     4877         }, {
5081                 .alg = "ecb(twofish)",           4878                 .alg = "ecb(twofish)",
5082                 .test = alg_test_skcipher,       4879                 .test = alg_test_skcipher,
5083                 .suite = {                       4880                 .suite = {
5084                         .cipher = __VECS(tf_t    4881                         .cipher = __VECS(tf_tv_template)
5085                 }                                4882                 }
5086         }, {                                     4883         }, {
5087                 .alg = "ecb(xeta)",              4884                 .alg = "ecb(xeta)",
5088                 .test = alg_test_skcipher,       4885                 .test = alg_test_skcipher,
5089                 .suite = {                       4886                 .suite = {
5090                         .cipher = __VECS(xeta    4887                         .cipher = __VECS(xeta_tv_template)
5091                 }                                4888                 }
5092         }, {                                     4889         }, {
5093                 .alg = "ecb(xtea)",              4890                 .alg = "ecb(xtea)",
5094                 .test = alg_test_skcipher,       4891                 .test = alg_test_skcipher,
5095                 .suite = {                       4892                 .suite = {
5096                         .cipher = __VECS(xtea    4893                         .cipher = __VECS(xtea_tv_template)
5097                 }                                4894                 }
5098         }, {                                     4895         }, {
5099 #if IS_ENABLED(CONFIG_CRYPTO_PAES_S390)          4896 #if IS_ENABLED(CONFIG_CRYPTO_PAES_S390)
5100                 .alg = "ecb-paes-s390",          4897                 .alg = "ecb-paes-s390",
5101                 .fips_allowed = 1,               4898                 .fips_allowed = 1,
5102                 .test = alg_test_skcipher,       4899                 .test = alg_test_skcipher,
5103                 .suite = {                       4900                 .suite = {
5104                         .cipher = __VECS(aes_    4901                         .cipher = __VECS(aes_tv_template)
5105                 }                                4902                 }
5106         }, {                                     4903         }, {
5107 #endif                                           4904 #endif
5108                 .alg = "ecdh-nist-p192",         4905                 .alg = "ecdh-nist-p192",
5109                 .test = alg_test_kpp,            4906                 .test = alg_test_kpp,
5110                 .suite = {                       4907                 .suite = {
5111                         .kpp = __VECS(ecdh_p1    4908                         .kpp = __VECS(ecdh_p192_tv_template)
5112                 }                                4909                 }
5113         }, {                                     4910         }, {
5114                 .alg = "ecdh-nist-p256",         4911                 .alg = "ecdh-nist-p256",
5115                 .test = alg_test_kpp,            4912                 .test = alg_test_kpp,
5116                 .fips_allowed = 1,               4913                 .fips_allowed = 1,
5117                 .suite = {                       4914                 .suite = {
5118                         .kpp = __VECS(ecdh_p2    4915                         .kpp = __VECS(ecdh_p256_tv_template)
5119                 }                                4916                 }
5120         }, {                                     4917         }, {
5121                 .alg = "ecdh-nist-p384",         4918                 .alg = "ecdh-nist-p384",
5122                 .test = alg_test_kpp,            4919                 .test = alg_test_kpp,
5123                 .fips_allowed = 1,               4920                 .fips_allowed = 1,
5124                 .suite = {                       4921                 .suite = {
5125                         .kpp = __VECS(ecdh_p3    4922                         .kpp = __VECS(ecdh_p384_tv_template)
5126                 }                                4923                 }
5127         }, {                                     4924         }, {
5128                 .alg = "ecdsa-nist-p192",        4925                 .alg = "ecdsa-nist-p192",
5129                 .test = alg_test_akcipher,       4926                 .test = alg_test_akcipher,
5130                 .suite = {                       4927                 .suite = {
5131                         .akcipher = __VECS(ec    4928                         .akcipher = __VECS(ecdsa_nist_p192_tv_template)
5132                 }                                4929                 }
5133         }, {                                     4930         }, {
5134                 .alg = "ecdsa-nist-p256",        4931                 .alg = "ecdsa-nist-p256",
5135                 .test = alg_test_akcipher,       4932                 .test = alg_test_akcipher,
5136                 .fips_allowed = 1,            << 
5137                 .suite = {                       4933                 .suite = {
5138                         .akcipher = __VECS(ec    4934                         .akcipher = __VECS(ecdsa_nist_p256_tv_template)
5139                 }                                4935                 }
5140         }, {                                     4936         }, {
5141                 .alg = "ecdsa-nist-p384",        4937                 .alg = "ecdsa-nist-p384",
5142                 .test = alg_test_akcipher,       4938                 .test = alg_test_akcipher,
5143                 .fips_allowed = 1,            << 
5144                 .suite = {                       4939                 .suite = {
5145                         .akcipher = __VECS(ec    4940                         .akcipher = __VECS(ecdsa_nist_p384_tv_template)
5146                 }                                4941                 }
5147         }, {                                     4942         }, {
5148                 .alg = "ecdsa-nist-p521",     << 
5149                 .test = alg_test_akcipher,    << 
5150                 .fips_allowed = 1,            << 
5151                 .suite = {                    << 
5152                         .akcipher = __VECS(ec << 
5153                 }                             << 
5154         }, {                                  << 
5155                 .alg = "ecrdsa",                 4943                 .alg = "ecrdsa",
5156                 .test = alg_test_akcipher,       4944                 .test = alg_test_akcipher,
5157                 .suite = {                       4945                 .suite = {
5158                         .akcipher = __VECS(ec    4946                         .akcipher = __VECS(ecrdsa_tv_template)
5159                 }                                4947                 }
5160         }, {                                     4948         }, {
5161                 .alg = "essiv(authenc(hmac(sh    4949                 .alg = "essiv(authenc(hmac(sha256),cbc(aes)),sha256)",
5162                 .test = alg_test_aead,           4950                 .test = alg_test_aead,
5163                 .fips_allowed = 1,               4951                 .fips_allowed = 1,
5164                 .suite = {                       4952                 .suite = {
5165                         .aead = __VECS(essiv_    4953                         .aead = __VECS(essiv_hmac_sha256_aes_cbc_tv_temp)
5166                 }                                4954                 }
5167         }, {                                     4955         }, {
5168                 .alg = "essiv(cbc(aes),sha256    4956                 .alg = "essiv(cbc(aes),sha256)",
5169                 .test = alg_test_skcipher,       4957                 .test = alg_test_skcipher,
5170                 .fips_allowed = 1,               4958                 .fips_allowed = 1,
5171                 .suite = {                       4959                 .suite = {
5172                         .cipher = __VECS(essi    4960                         .cipher = __VECS(essiv_aes_cbc_tv_template)
5173                 }                                4961                 }
5174         }, {                                     4962         }, {
5175 #if IS_ENABLED(CONFIG_CRYPTO_DH_RFC7919_GROUP << 
5176                 .alg = "ffdhe2048(dh)",       << 
5177                 .test = alg_test_kpp,         << 
5178                 .fips_allowed = 1,            << 
5179                 .suite = {                    << 
5180                         .kpp = __VECS(ffdhe20 << 
5181                 }                             << 
5182         }, {                                  << 
5183                 .alg = "ffdhe3072(dh)",       << 
5184                 .test = alg_test_kpp,         << 
5185                 .fips_allowed = 1,            << 
5186                 .suite = {                    << 
5187                         .kpp = __VECS(ffdhe30 << 
5188                 }                             << 
5189         }, {                                  << 
5190                 .alg = "ffdhe4096(dh)",       << 
5191                 .test = alg_test_kpp,         << 
5192                 .fips_allowed = 1,            << 
5193                 .suite = {                    << 
5194                         .kpp = __VECS(ffdhe40 << 
5195                 }                             << 
5196         }, {                                  << 
5197                 .alg = "ffdhe6144(dh)",       << 
5198                 .test = alg_test_kpp,         << 
5199                 .fips_allowed = 1,            << 
5200                 .suite = {                    << 
5201                         .kpp = __VECS(ffdhe61 << 
5202                 }                             << 
5203         }, {                                  << 
5204                 .alg = "ffdhe8192(dh)",       << 
5205                 .test = alg_test_kpp,         << 
5206                 .fips_allowed = 1,            << 
5207                 .suite = {                    << 
5208                         .kpp = __VECS(ffdhe81 << 
5209                 }                             << 
5210         }, {                                  << 
5211 #endif /* CONFIG_CRYPTO_DH_RFC7919_GROUPS */  << 
5212                 .alg = "gcm(aes)",               4963                 .alg = "gcm(aes)",
5213                 .generic_driver = "gcm_base(c    4964                 .generic_driver = "gcm_base(ctr(aes-generic),ghash-generic)",
5214                 .test = alg_test_aead,           4965                 .test = alg_test_aead,
5215                 .fips_allowed = 1,               4966                 .fips_allowed = 1,
5216                 .suite = {                       4967                 .suite = {
5217                         .aead = __VECS(aes_gc    4968                         .aead = __VECS(aes_gcm_tv_template)
5218                 }                                4969                 }
5219         }, {                                     4970         }, {
5220                 .alg = "gcm(aria)",           << 
5221                 .generic_driver = "gcm_base(c << 
5222                 .test = alg_test_aead,        << 
5223                 .suite = {                    << 
5224                         .aead = __VECS(aria_g << 
5225                 }                             << 
5226         }, {                                  << 
5227                 .alg = "gcm(sm4)",            << 
5228                 .generic_driver = "gcm_base(c << 
5229                 .test = alg_test_aead,        << 
5230                 .suite = {                    << 
5231                         .aead = __VECS(sm4_gc << 
5232                 }                             << 
5233         }, {                                  << 
5234                 .alg = "ghash",                  4971                 .alg = "ghash",
5235                 .test = alg_test_hash,           4972                 .test = alg_test_hash,
                                                   >> 4973                 .fips_allowed = 1,
5236                 .suite = {                       4974                 .suite = {
5237                         .hash = __VECS(ghash_    4975                         .hash = __VECS(ghash_tv_template)
5238                 }                                4976                 }
5239         }, {                                     4977         }, {
5240                 .alg = "hctr2(aes)",          << 
5241                 .generic_driver =             << 
5242                     "hctr2_base(xctr(aes-gene << 
5243                 .test = alg_test_skcipher,    << 
5244                 .suite = {                    << 
5245                         .cipher = __VECS(aes_ << 
5246                 }                             << 
5247         }, {                                  << 
5248                 .alg = "hmac(md5)",              4978                 .alg = "hmac(md5)",
5249                 .test = alg_test_hash,           4979                 .test = alg_test_hash,
5250                 .suite = {                       4980                 .suite = {
5251                         .hash = __VECS(hmac_m    4981                         .hash = __VECS(hmac_md5_tv_template)
5252                 }                                4982                 }
5253         }, {                                     4983         }, {
5254                 .alg = "hmac(rmd160)",           4984                 .alg = "hmac(rmd160)",
5255                 .test = alg_test_hash,           4985                 .test = alg_test_hash,
5256                 .suite = {                       4986                 .suite = {
5257                         .hash = __VECS(hmac_r    4987                         .hash = __VECS(hmac_rmd160_tv_template)
5258                 }                                4988                 }
5259         }, {                                     4989         }, {
5260                 .alg = "hmac(sha1)",             4990                 .alg = "hmac(sha1)",
5261                 .test = alg_test_hash,           4991                 .test = alg_test_hash,
5262                 .fips_allowed = 1,               4992                 .fips_allowed = 1,
5263                 .suite = {                       4993                 .suite = {
5264                         .hash = __VECS(hmac_s    4994                         .hash = __VECS(hmac_sha1_tv_template)
5265                 }                                4995                 }
5266         }, {                                     4996         }, {
5267                 .alg = "hmac(sha224)",           4997                 .alg = "hmac(sha224)",
5268                 .test = alg_test_hash,           4998                 .test = alg_test_hash,
5269                 .fips_allowed = 1,               4999                 .fips_allowed = 1,
5270                 .suite = {                       5000                 .suite = {
5271                         .hash = __VECS(hmac_s    5001                         .hash = __VECS(hmac_sha224_tv_template)
5272                 }                                5002                 }
5273         }, {                                     5003         }, {
5274                 .alg = "hmac(sha256)",           5004                 .alg = "hmac(sha256)",
5275                 .test = alg_test_hash,           5005                 .test = alg_test_hash,
5276                 .fips_allowed = 1,               5006                 .fips_allowed = 1,
5277                 .suite = {                       5007                 .suite = {
5278                         .hash = __VECS(hmac_s    5008                         .hash = __VECS(hmac_sha256_tv_template)
5279                 }                                5009                 }
5280         }, {                                     5010         }, {
5281                 .alg = "hmac(sha3-224)",         5011                 .alg = "hmac(sha3-224)",
5282                 .test = alg_test_hash,           5012                 .test = alg_test_hash,
5283                 .fips_allowed = 1,               5013                 .fips_allowed = 1,
5284                 .suite = {                       5014                 .suite = {
5285                         .hash = __VECS(hmac_s    5015                         .hash = __VECS(hmac_sha3_224_tv_template)
5286                 }                                5016                 }
5287         }, {                                     5017         }, {
5288                 .alg = "hmac(sha3-256)",         5018                 .alg = "hmac(sha3-256)",
5289                 .test = alg_test_hash,           5019                 .test = alg_test_hash,
5290                 .fips_allowed = 1,               5020                 .fips_allowed = 1,
5291                 .suite = {                       5021                 .suite = {
5292                         .hash = __VECS(hmac_s    5022                         .hash = __VECS(hmac_sha3_256_tv_template)
5293                 }                                5023                 }
5294         }, {                                     5024         }, {
5295                 .alg = "hmac(sha3-384)",         5025                 .alg = "hmac(sha3-384)",
5296                 .test = alg_test_hash,           5026                 .test = alg_test_hash,
5297                 .fips_allowed = 1,               5027                 .fips_allowed = 1,
5298                 .suite = {                       5028                 .suite = {
5299                         .hash = __VECS(hmac_s    5029                         .hash = __VECS(hmac_sha3_384_tv_template)
5300                 }                                5030                 }
5301         }, {                                     5031         }, {
5302                 .alg = "hmac(sha3-512)",         5032                 .alg = "hmac(sha3-512)",
5303                 .test = alg_test_hash,           5033                 .test = alg_test_hash,
5304                 .fips_allowed = 1,               5034                 .fips_allowed = 1,
5305                 .suite = {                       5035                 .suite = {
5306                         .hash = __VECS(hmac_s    5036                         .hash = __VECS(hmac_sha3_512_tv_template)
5307                 }                                5037                 }
5308         }, {                                     5038         }, {
5309                 .alg = "hmac(sha384)",           5039                 .alg = "hmac(sha384)",
5310                 .test = alg_test_hash,           5040                 .test = alg_test_hash,
5311                 .fips_allowed = 1,               5041                 .fips_allowed = 1,
5312                 .suite = {                       5042                 .suite = {
5313                         .hash = __VECS(hmac_s    5043                         .hash = __VECS(hmac_sha384_tv_template)
5314                 }                                5044                 }
5315         }, {                                     5045         }, {
5316                 .alg = "hmac(sha512)",           5046                 .alg = "hmac(sha512)",
5317                 .test = alg_test_hash,           5047                 .test = alg_test_hash,
5318                 .fips_allowed = 1,               5048                 .fips_allowed = 1,
5319                 .suite = {                       5049                 .suite = {
5320                         .hash = __VECS(hmac_s    5050                         .hash = __VECS(hmac_sha512_tv_template)
5321                 }                                5051                 }
5322         }, {                                     5052         }, {
5323                 .alg = "hmac(sm3)",              5053                 .alg = "hmac(sm3)",
5324                 .test = alg_test_hash,           5054                 .test = alg_test_hash,
5325                 .suite = {                       5055                 .suite = {
5326                         .hash = __VECS(hmac_s    5056                         .hash = __VECS(hmac_sm3_tv_template)
5327                 }                                5057                 }
5328         }, {                                     5058         }, {
5329                 .alg = "hmac(streebog256)",      5059                 .alg = "hmac(streebog256)",
5330                 .test = alg_test_hash,           5060                 .test = alg_test_hash,
5331                 .suite = {                       5061                 .suite = {
5332                         .hash = __VECS(hmac_s    5062                         .hash = __VECS(hmac_streebog256_tv_template)
5333                 }                                5063                 }
5334         }, {                                     5064         }, {
5335                 .alg = "hmac(streebog512)",      5065                 .alg = "hmac(streebog512)",
5336                 .test = alg_test_hash,           5066                 .test = alg_test_hash,
5337                 .suite = {                       5067                 .suite = {
5338                         .hash = __VECS(hmac_s    5068                         .hash = __VECS(hmac_streebog512_tv_template)
5339                 }                                5069                 }
5340         }, {                                     5070         }, {
5341                 .alg = "jitterentropy_rng",      5071                 .alg = "jitterentropy_rng",
5342                 .fips_allowed = 1,               5072                 .fips_allowed = 1,
5343                 .test = alg_test_null,           5073                 .test = alg_test_null,
5344         }, {                                     5074         }, {
5345                 .alg = "kw(aes)",                5075                 .alg = "kw(aes)",
5346                 .test = alg_test_skcipher,       5076                 .test = alg_test_skcipher,
5347                 .fips_allowed = 1,               5077                 .fips_allowed = 1,
5348                 .suite = {                       5078                 .suite = {
5349                         .cipher = __VECS(aes_    5079                         .cipher = __VECS(aes_kw_tv_template)
5350                 }                                5080                 }
5351         }, {                                     5081         }, {
5352                 .alg = "lrw(aes)",               5082                 .alg = "lrw(aes)",
5353                 .generic_driver = "lrw(ecb(ae    5083                 .generic_driver = "lrw(ecb(aes-generic))",
5354                 .test = alg_test_skcipher,       5084                 .test = alg_test_skcipher,
5355                 .suite = {                       5085                 .suite = {
5356                         .cipher = __VECS(aes_    5086                         .cipher = __VECS(aes_lrw_tv_template)
5357                 }                                5087                 }
5358         }, {                                     5088         }, {
5359                 .alg = "lrw(camellia)",          5089                 .alg = "lrw(camellia)",
5360                 .generic_driver = "lrw(ecb(ca    5090                 .generic_driver = "lrw(ecb(camellia-generic))",
5361                 .test = alg_test_skcipher,       5091                 .test = alg_test_skcipher,
5362                 .suite = {                       5092                 .suite = {
5363                         .cipher = __VECS(came    5093                         .cipher = __VECS(camellia_lrw_tv_template)
5364                 }                                5094                 }
5365         }, {                                     5095         }, {
5366                 .alg = "lrw(cast6)",             5096                 .alg = "lrw(cast6)",
5367                 .generic_driver = "lrw(ecb(ca    5097                 .generic_driver = "lrw(ecb(cast6-generic))",
5368                 .test = alg_test_skcipher,       5098                 .test = alg_test_skcipher,
5369                 .suite = {                       5099                 .suite = {
5370                         .cipher = __VECS(cast    5100                         .cipher = __VECS(cast6_lrw_tv_template)
5371                 }                                5101                 }
5372         }, {                                     5102         }, {
5373                 .alg = "lrw(serpent)",           5103                 .alg = "lrw(serpent)",
5374                 .generic_driver = "lrw(ecb(se    5104                 .generic_driver = "lrw(ecb(serpent-generic))",
5375                 .test = alg_test_skcipher,       5105                 .test = alg_test_skcipher,
5376                 .suite = {                       5106                 .suite = {
5377                         .cipher = __VECS(serp    5107                         .cipher = __VECS(serpent_lrw_tv_template)
5378                 }                                5108                 }
5379         }, {                                     5109         }, {
5380                 .alg = "lrw(twofish)",           5110                 .alg = "lrw(twofish)",
5381                 .generic_driver = "lrw(ecb(tw    5111                 .generic_driver = "lrw(ecb(twofish-generic))",
5382                 .test = alg_test_skcipher,       5112                 .test = alg_test_skcipher,
5383                 .suite = {                       5113                 .suite = {
5384                         .cipher = __VECS(tf_l    5114                         .cipher = __VECS(tf_lrw_tv_template)
5385                 }                                5115                 }
5386         }, {                                     5116         }, {
5387                 .alg = "lz4",                    5117                 .alg = "lz4",
5388                 .test = alg_test_comp,           5118                 .test = alg_test_comp,
5389                 .fips_allowed = 1,               5119                 .fips_allowed = 1,
5390                 .suite = {                       5120                 .suite = {
5391                         .comp = {                5121                         .comp = {
5392                                 .comp = __VEC    5122                                 .comp = __VECS(lz4_comp_tv_template),
5393                                 .decomp = __V    5123                                 .decomp = __VECS(lz4_decomp_tv_template)
5394                         }                        5124                         }
5395                 }                                5125                 }
5396         }, {                                     5126         }, {
5397                 .alg = "lz4hc",                  5127                 .alg = "lz4hc",
5398                 .test = alg_test_comp,           5128                 .test = alg_test_comp,
5399                 .fips_allowed = 1,               5129                 .fips_allowed = 1,
5400                 .suite = {                       5130                 .suite = {
5401                         .comp = {                5131                         .comp = {
5402                                 .comp = __VEC    5132                                 .comp = __VECS(lz4hc_comp_tv_template),
5403                                 .decomp = __V    5133                                 .decomp = __VECS(lz4hc_decomp_tv_template)
5404                         }                        5134                         }
5405                 }                                5135                 }
5406         }, {                                     5136         }, {
5407                 .alg = "lzo",                    5137                 .alg = "lzo",
5408                 .test = alg_test_comp,           5138                 .test = alg_test_comp,
5409                 .fips_allowed = 1,               5139                 .fips_allowed = 1,
5410                 .suite = {                       5140                 .suite = {
5411                         .comp = {                5141                         .comp = {
5412                                 .comp = __VEC    5142                                 .comp = __VECS(lzo_comp_tv_template),
5413                                 .decomp = __V    5143                                 .decomp = __VECS(lzo_decomp_tv_template)
5414                         }                        5144                         }
5415                 }                                5145                 }
5416         }, {                                     5146         }, {
5417                 .alg = "lzo-rle",                5147                 .alg = "lzo-rle",
5418                 .test = alg_test_comp,           5148                 .test = alg_test_comp,
5419                 .fips_allowed = 1,               5149                 .fips_allowed = 1,
5420                 .suite = {                       5150                 .suite = {
5421                         .comp = {                5151                         .comp = {
5422                                 .comp = __VEC    5152                                 .comp = __VECS(lzorle_comp_tv_template),
5423                                 .decomp = __V    5153                                 .decomp = __VECS(lzorle_decomp_tv_template)
5424                         }                        5154                         }
5425                 }                                5155                 }
5426         }, {                                     5156         }, {
5427                 .alg = "md4",                    5157                 .alg = "md4",
5428                 .test = alg_test_hash,           5158                 .test = alg_test_hash,
5429                 .suite = {                       5159                 .suite = {
5430                         .hash = __VECS(md4_tv    5160                         .hash = __VECS(md4_tv_template)
5431                 }                                5161                 }
5432         }, {                                     5162         }, {
5433                 .alg = "md5",                    5163                 .alg = "md5",
5434                 .test = alg_test_hash,           5164                 .test = alg_test_hash,
5435                 .suite = {                       5165                 .suite = {
5436                         .hash = __VECS(md5_tv    5166                         .hash = __VECS(md5_tv_template)
5437                 }                                5167                 }
5438         }, {                                     5168         }, {
5439                 .alg = "michael_mic",            5169                 .alg = "michael_mic",
5440                 .test = alg_test_hash,           5170                 .test = alg_test_hash,
5441                 .suite = {                       5171                 .suite = {
5442                         .hash = __VECS(michae    5172                         .hash = __VECS(michael_mic_tv_template)
5443                 }                                5173                 }
5444         }, {                                     5174         }, {
5445                 .alg = "nhpoly1305",             5175                 .alg = "nhpoly1305",
5446                 .test = alg_test_hash,           5176                 .test = alg_test_hash,
5447                 .suite = {                       5177                 .suite = {
5448                         .hash = __VECS(nhpoly    5178                         .hash = __VECS(nhpoly1305_tv_template)
5449                 }                                5179                 }
5450         }, {                                     5180         }, {
                                                   >> 5181                 .alg = "ofb(aes)",
                                                   >> 5182                 .test = alg_test_skcipher,
                                                   >> 5183                 .fips_allowed = 1,
                                                   >> 5184                 .suite = {
                                                   >> 5185                         .cipher = __VECS(aes_ofb_tv_template)
                                                   >> 5186                 }
                                                   >> 5187         }, {
                                                   >> 5188                 /* Same as ofb(aes) except the key is stored in
                                                   >> 5189                  * hardware secure memory which we reference by index
                                                   >> 5190                  */
                                                   >> 5191                 .alg = "ofb(paes)",
                                                   >> 5192                 .test = alg_test_null,
                                                   >> 5193                 .fips_allowed = 1,
                                                   >> 5194         }, {
                                                   >> 5195                 .alg = "ofb(sm4)",
                                                   >> 5196                 .test = alg_test_skcipher,
                                                   >> 5197                 .suite = {
                                                   >> 5198                         .cipher = __VECS(sm4_ofb_tv_template)
                                                   >> 5199                 }
                                                   >> 5200         }, {
5451                 .alg = "pcbc(fcrypt)",           5201                 .alg = "pcbc(fcrypt)",
5452                 .test = alg_test_skcipher,       5202                 .test = alg_test_skcipher,
5453                 .suite = {                       5203                 .suite = {
5454                         .cipher = __VECS(fcry    5204                         .cipher = __VECS(fcrypt_pcbc_tv_template)
5455                 }                                5205                 }
5456         }, {                                     5206         }, {
5457                 .alg = "pkcs1pad(rsa,sha224)"    5207                 .alg = "pkcs1pad(rsa,sha224)",
5458                 .test = alg_test_null,           5208                 .test = alg_test_null,
5459                 .fips_allowed = 1,               5209                 .fips_allowed = 1,
5460         }, {                                     5210         }, {
5461                 .alg = "pkcs1pad(rsa,sha256)"    5211                 .alg = "pkcs1pad(rsa,sha256)",
5462                 .test = alg_test_akcipher,       5212                 .test = alg_test_akcipher,
5463                 .fips_allowed = 1,               5213                 .fips_allowed = 1,
5464                 .suite = {                       5214                 .suite = {
5465                         .akcipher = __VECS(pk    5215                         .akcipher = __VECS(pkcs1pad_rsa_tv_template)
5466                 }                                5216                 }
5467         }, {                                     5217         }, {
5468                 .alg = "pkcs1pad(rsa,sha3-256 << 
5469                 .test = alg_test_null,        << 
5470                 .fips_allowed = 1,            << 
5471         }, {                                  << 
5472                 .alg = "pkcs1pad(rsa,sha3-384 << 
5473                 .test = alg_test_null,        << 
5474                 .fips_allowed = 1,            << 
5475         }, {                                  << 
5476                 .alg = "pkcs1pad(rsa,sha3-512 << 
5477                 .test = alg_test_null,        << 
5478                 .fips_allowed = 1,            << 
5479         }, {                                  << 
5480                 .alg = "pkcs1pad(rsa,sha384)"    5218                 .alg = "pkcs1pad(rsa,sha384)",
5481                 .test = alg_test_null,           5219                 .test = alg_test_null,
5482                 .fips_allowed = 1,               5220                 .fips_allowed = 1,
5483         }, {                                     5221         }, {
5484                 .alg = "pkcs1pad(rsa,sha512)"    5222                 .alg = "pkcs1pad(rsa,sha512)",
5485                 .test = alg_test_null,           5223                 .test = alg_test_null,
5486                 .fips_allowed = 1,               5224                 .fips_allowed = 1,
5487         }, {                                     5225         }, {
5488                 .alg = "poly1305",               5226                 .alg = "poly1305",
5489                 .test = alg_test_hash,           5227                 .test = alg_test_hash,
5490                 .suite = {                       5228                 .suite = {
5491                         .hash = __VECS(poly13    5229                         .hash = __VECS(poly1305_tv_template)
5492                 }                                5230                 }
5493         }, {                                     5231         }, {
5494                 .alg = "polyval",             << 
5495                 .test = alg_test_hash,        << 
5496                 .suite = {                    << 
5497                         .hash = __VECS(polyva << 
5498                 }                             << 
5499         }, {                                  << 
5500                 .alg = "rfc3686(ctr(aes))",      5232                 .alg = "rfc3686(ctr(aes))",
5501                 .test = alg_test_skcipher,       5233                 .test = alg_test_skcipher,
5502                 .fips_allowed = 1,               5234                 .fips_allowed = 1,
5503                 .suite = {                       5235                 .suite = {
5504                         .cipher = __VECS(aes_    5236                         .cipher = __VECS(aes_ctr_rfc3686_tv_template)
5505                 }                                5237                 }
5506         }, {                                     5238         }, {
5507                 .alg = "rfc3686(ctr(sm4))",      5239                 .alg = "rfc3686(ctr(sm4))",
5508                 .test = alg_test_skcipher,       5240                 .test = alg_test_skcipher,
5509                 .suite = {                       5241                 .suite = {
5510                         .cipher = __VECS(sm4_    5242                         .cipher = __VECS(sm4_ctr_rfc3686_tv_template)
5511                 }                                5243                 }
5512         }, {                                     5244         }, {
5513                 .alg = "rfc4106(gcm(aes))",      5245                 .alg = "rfc4106(gcm(aes))",
5514                 .generic_driver = "rfc4106(gc    5246                 .generic_driver = "rfc4106(gcm_base(ctr(aes-generic),ghash-generic))",
5515                 .test = alg_test_aead,           5247                 .test = alg_test_aead,
5516                 .fips_allowed = 1,               5248                 .fips_allowed = 1,
5517                 .suite = {                       5249                 .suite = {
5518                         .aead = {                5250                         .aead = {
5519                                 ____VECS(aes_    5251                                 ____VECS(aes_gcm_rfc4106_tv_template),
5520                                 .einval_allow    5252                                 .einval_allowed = 1,
5521                                 .aad_iv = 1,     5253                                 .aad_iv = 1,
5522                         }                        5254                         }
5523                 }                                5255                 }
5524         }, {                                     5256         }, {
5525                 .alg = "rfc4309(ccm(aes))",      5257                 .alg = "rfc4309(ccm(aes))",
5526                 .generic_driver = "rfc4309(cc    5258                 .generic_driver = "rfc4309(ccm_base(ctr(aes-generic),cbcmac(aes-generic)))",
5527                 .test = alg_test_aead,           5259                 .test = alg_test_aead,
5528                 .fips_allowed = 1,               5260                 .fips_allowed = 1,
5529                 .suite = {                       5261                 .suite = {
5530                         .aead = {                5262                         .aead = {
5531                                 ____VECS(aes_    5263                                 ____VECS(aes_ccm_rfc4309_tv_template),
5532                                 .einval_allow    5264                                 .einval_allowed = 1,
5533                                 .aad_iv = 1,     5265                                 .aad_iv = 1,
5534                         }                        5266                         }
5535                 }                                5267                 }
5536         }, {                                     5268         }, {
5537                 .alg = "rfc4543(gcm(aes))",      5269                 .alg = "rfc4543(gcm(aes))",
5538                 .generic_driver = "rfc4543(gc    5270                 .generic_driver = "rfc4543(gcm_base(ctr(aes-generic),ghash-generic))",
5539                 .test = alg_test_aead,           5271                 .test = alg_test_aead,
5540                 .suite = {                       5272                 .suite = {
5541                         .aead = {                5273                         .aead = {
5542                                 ____VECS(aes_    5274                                 ____VECS(aes_gcm_rfc4543_tv_template),
5543                                 .einval_allow    5275                                 .einval_allowed = 1,
5544                                 .aad_iv = 1,     5276                                 .aad_iv = 1,
5545                         }                        5277                         }
5546                 }                                5278                 }
5547         }, {                                     5279         }, {
5548                 .alg = "rfc7539(chacha20,poly    5280                 .alg = "rfc7539(chacha20,poly1305)",
5549                 .test = alg_test_aead,           5281                 .test = alg_test_aead,
5550                 .suite = {                       5282                 .suite = {
5551                         .aead = __VECS(rfc753    5283                         .aead = __VECS(rfc7539_tv_template)
5552                 }                                5284                 }
5553         }, {                                     5285         }, {
5554                 .alg = "rfc7539esp(chacha20,p    5286                 .alg = "rfc7539esp(chacha20,poly1305)",
5555                 .test = alg_test_aead,           5287                 .test = alg_test_aead,
5556                 .suite = {                       5288                 .suite = {
5557                         .aead = {                5289                         .aead = {
5558                                 ____VECS(rfc7    5290                                 ____VECS(rfc7539esp_tv_template),
5559                                 .einval_allow    5291                                 .einval_allowed = 1,
5560                                 .aad_iv = 1,     5292                                 .aad_iv = 1,
5561                         }                        5293                         }
5562                 }                                5294                 }
5563         }, {                                     5295         }, {
5564                 .alg = "rmd160",                 5296                 .alg = "rmd160",
5565                 .test = alg_test_hash,           5297                 .test = alg_test_hash,
5566                 .suite = {                       5298                 .suite = {
5567                         .hash = __VECS(rmd160    5299                         .hash = __VECS(rmd160_tv_template)
5568                 }                                5300                 }
5569         }, {                                     5301         }, {
5570                 .alg = "rsa",                    5302                 .alg = "rsa",
5571                 .test = alg_test_akcipher,       5303                 .test = alg_test_akcipher,
5572                 .fips_allowed = 1,               5304                 .fips_allowed = 1,
5573                 .suite = {                       5305                 .suite = {
5574                         .akcipher = __VECS(rs    5306                         .akcipher = __VECS(rsa_tv_template)
5575                 }                                5307                 }
5576         }, {                                     5308         }, {
5577                 .alg = "sha1",                   5309                 .alg = "sha1",
5578                 .test = alg_test_hash,           5310                 .test = alg_test_hash,
5579                 .fips_allowed = 1,               5311                 .fips_allowed = 1,
5580                 .suite = {                       5312                 .suite = {
5581                         .hash = __VECS(sha1_t    5313                         .hash = __VECS(sha1_tv_template)
5582                 }                                5314                 }
5583         }, {                                     5315         }, {
5584                 .alg = "sha224",                 5316                 .alg = "sha224",
5585                 .test = alg_test_hash,           5317                 .test = alg_test_hash,
5586                 .fips_allowed = 1,               5318                 .fips_allowed = 1,
5587                 .suite = {                       5319                 .suite = {
5588                         .hash = __VECS(sha224    5320                         .hash = __VECS(sha224_tv_template)
5589                 }                                5321                 }
5590         }, {                                     5322         }, {
5591                 .alg = "sha256",                 5323                 .alg = "sha256",
5592                 .test = alg_test_hash,           5324                 .test = alg_test_hash,
5593                 .fips_allowed = 1,               5325                 .fips_allowed = 1,
5594                 .suite = {                       5326                 .suite = {
5595                         .hash = __VECS(sha256    5327                         .hash = __VECS(sha256_tv_template)
5596                 }                                5328                 }
5597         }, {                                     5329         }, {
5598                 .alg = "sha3-224",               5330                 .alg = "sha3-224",
5599                 .test = alg_test_hash,           5331                 .test = alg_test_hash,
5600                 .fips_allowed = 1,               5332                 .fips_allowed = 1,
5601                 .suite = {                       5333                 .suite = {
5602                         .hash = __VECS(sha3_2    5334                         .hash = __VECS(sha3_224_tv_template)
5603                 }                                5335                 }
5604         }, {                                     5336         }, {
5605                 .alg = "sha3-256",               5337                 .alg = "sha3-256",
5606                 .test = alg_test_hash,           5338                 .test = alg_test_hash,
5607                 .fips_allowed = 1,               5339                 .fips_allowed = 1,
5608                 .suite = {                       5340                 .suite = {
5609                         .hash = __VECS(sha3_2    5341                         .hash = __VECS(sha3_256_tv_template)
5610                 }                                5342                 }
5611         }, {                                     5343         }, {
5612                 .alg = "sha3-384",               5344                 .alg = "sha3-384",
5613                 .test = alg_test_hash,           5345                 .test = alg_test_hash,
5614                 .fips_allowed = 1,               5346                 .fips_allowed = 1,
5615                 .suite = {                       5347                 .suite = {
5616                         .hash = __VECS(sha3_3    5348                         .hash = __VECS(sha3_384_tv_template)
5617                 }                                5349                 }
5618         }, {                                     5350         }, {
5619                 .alg = "sha3-512",               5351                 .alg = "sha3-512",
5620                 .test = alg_test_hash,           5352                 .test = alg_test_hash,
5621                 .fips_allowed = 1,               5353                 .fips_allowed = 1,
5622                 .suite = {                       5354                 .suite = {
5623                         .hash = __VECS(sha3_5    5355                         .hash = __VECS(sha3_512_tv_template)
5624                 }                                5356                 }
5625         }, {                                     5357         }, {
5626                 .alg = "sha384",                 5358                 .alg = "sha384",
5627                 .test = alg_test_hash,           5359                 .test = alg_test_hash,
5628                 .fips_allowed = 1,               5360                 .fips_allowed = 1,
5629                 .suite = {                       5361                 .suite = {
5630                         .hash = __VECS(sha384    5362                         .hash = __VECS(sha384_tv_template)
5631                 }                                5363                 }
5632         }, {                                     5364         }, {
5633                 .alg = "sha512",                 5365                 .alg = "sha512",
5634                 .test = alg_test_hash,           5366                 .test = alg_test_hash,
5635                 .fips_allowed = 1,               5367                 .fips_allowed = 1,
5636                 .suite = {                       5368                 .suite = {
5637                         .hash = __VECS(sha512    5369                         .hash = __VECS(sha512_tv_template)
5638                 }                                5370                 }
5639         }, {                                     5371         }, {
                                                   >> 5372                 .alg = "sm2",
                                                   >> 5373                 .test = alg_test_akcipher,
                                                   >> 5374                 .suite = {
                                                   >> 5375                         .akcipher = __VECS(sm2_tv_template)
                                                   >> 5376                 }
                                                   >> 5377         }, {
5640                 .alg = "sm3",                    5378                 .alg = "sm3",
5641                 .test = alg_test_hash,           5379                 .test = alg_test_hash,
5642                 .suite = {                       5380                 .suite = {
5643                         .hash = __VECS(sm3_tv    5381                         .hash = __VECS(sm3_tv_template)
5644                 }                                5382                 }
5645         }, {                                     5383         }, {
5646                 .alg = "streebog256",            5384                 .alg = "streebog256",
5647                 .test = alg_test_hash,           5385                 .test = alg_test_hash,
5648                 .suite = {                       5386                 .suite = {
5649                         .hash = __VECS(streeb    5387                         .hash = __VECS(streebog256_tv_template)
5650                 }                                5388                 }
5651         }, {                                     5389         }, {
5652                 .alg = "streebog512",            5390                 .alg = "streebog512",
5653                 .test = alg_test_hash,           5391                 .test = alg_test_hash,
5654                 .suite = {                       5392                 .suite = {
5655                         .hash = __VECS(streeb    5393                         .hash = __VECS(streebog512_tv_template)
5656                 }                                5394                 }
5657         }, {                                     5395         }, {
5658                 .alg = "vmac64(aes)",            5396                 .alg = "vmac64(aes)",
5659                 .test = alg_test_hash,           5397                 .test = alg_test_hash,
5660                 .suite = {                       5398                 .suite = {
5661                         .hash = __VECS(vmac64    5399                         .hash = __VECS(vmac64_aes_tv_template)
5662                 }                                5400                 }
5663         }, {                                     5401         }, {
5664                 .alg = "wp256",                  5402                 .alg = "wp256",
5665                 .test = alg_test_hash,           5403                 .test = alg_test_hash,
5666                 .suite = {                       5404                 .suite = {
5667                         .hash = __VECS(wp256_    5405                         .hash = __VECS(wp256_tv_template)
5668                 }                                5406                 }
5669         }, {                                     5407         }, {
5670                 .alg = "wp384",                  5408                 .alg = "wp384",
5671                 .test = alg_test_hash,           5409                 .test = alg_test_hash,
5672                 .suite = {                       5410                 .suite = {
5673                         .hash = __VECS(wp384_    5411                         .hash = __VECS(wp384_tv_template)
5674                 }                                5412                 }
5675         }, {                                     5413         }, {
5676                 .alg = "wp512",                  5414                 .alg = "wp512",
5677                 .test = alg_test_hash,           5415                 .test = alg_test_hash,
5678                 .suite = {                       5416                 .suite = {
5679                         .hash = __VECS(wp512_    5417                         .hash = __VECS(wp512_tv_template)
5680                 }                                5418                 }
5681         }, {                                     5419         }, {
5682                 .alg = "xcbc(aes)",              5420                 .alg = "xcbc(aes)",
5683                 .test = alg_test_hash,           5421                 .test = alg_test_hash,
5684                 .suite = {                       5422                 .suite = {
5685                         .hash = __VECS(aes_xc    5423                         .hash = __VECS(aes_xcbc128_tv_template)
5686                 }                                5424                 }
5687         }, {                                     5425         }, {
5688                 .alg = "xcbc(sm4)",           << 
5689                 .test = alg_test_hash,        << 
5690                 .suite = {                    << 
5691                         .hash = __VECS(sm4_xc << 
5692                 }                             << 
5693         }, {                                  << 
5694                 .alg = "xchacha12",              5426                 .alg = "xchacha12",
5695                 .test = alg_test_skcipher,       5427                 .test = alg_test_skcipher,
5696                 .suite = {                       5428                 .suite = {
5697                         .cipher = __VECS(xcha    5429                         .cipher = __VECS(xchacha12_tv_template)
5698                 },                               5430                 },
5699         }, {                                     5431         }, {
5700                 .alg = "xchacha20",              5432                 .alg = "xchacha20",
5701                 .test = alg_test_skcipher,       5433                 .test = alg_test_skcipher,
5702                 .suite = {                       5434                 .suite = {
5703                         .cipher = __VECS(xcha    5435                         .cipher = __VECS(xchacha20_tv_template)
5704                 },                               5436                 },
5705         }, {                                     5437         }, {
5706                 .alg = "xctr(aes)",           << 
5707                 .test = alg_test_skcipher,    << 
5708                 .suite = {                    << 
5709                         .cipher = __VECS(aes_ << 
5710                 }                             << 
5711         }, {                                  << 
5712                 .alg = "xts(aes)",               5438                 .alg = "xts(aes)",
5713                 .generic_driver = "xts(ecb(ae    5439                 .generic_driver = "xts(ecb(aes-generic))",
5714                 .test = alg_test_skcipher,       5440                 .test = alg_test_skcipher,
5715                 .fips_allowed = 1,               5441                 .fips_allowed = 1,
5716                 .suite = {                       5442                 .suite = {
5717                         .cipher = __VECS(aes_    5443                         .cipher = __VECS(aes_xts_tv_template)
5718                 }                                5444                 }
5719         }, {                                     5445         }, {
5720                 .alg = "xts(camellia)",          5446                 .alg = "xts(camellia)",
5721                 .generic_driver = "xts(ecb(ca    5447                 .generic_driver = "xts(ecb(camellia-generic))",
5722                 .test = alg_test_skcipher,       5448                 .test = alg_test_skcipher,
5723                 .suite = {                       5449                 .suite = {
5724                         .cipher = __VECS(came    5450                         .cipher = __VECS(camellia_xts_tv_template)
5725                 }                                5451                 }
5726         }, {                                     5452         }, {
5727                 .alg = "xts(cast6)",             5453                 .alg = "xts(cast6)",
5728                 .generic_driver = "xts(ecb(ca    5454                 .generic_driver = "xts(ecb(cast6-generic))",
5729                 .test = alg_test_skcipher,       5455                 .test = alg_test_skcipher,
5730                 .suite = {                       5456                 .suite = {
5731                         .cipher = __VECS(cast    5457                         .cipher = __VECS(cast6_xts_tv_template)
5732                 }                                5458                 }
5733         }, {                                     5459         }, {
5734                 /* Same as xts(aes) except th    5460                 /* Same as xts(aes) except the key is stored in
5735                  * hardware secure memory whi    5461                  * hardware secure memory which we reference by index
5736                  */                              5462                  */
5737                 .alg = "xts(paes)",              5463                 .alg = "xts(paes)",
5738                 .test = alg_test_null,           5464                 .test = alg_test_null,
5739                 .fips_allowed = 1,               5465                 .fips_allowed = 1,
5740         }, {                                     5466         }, {
5741                 .alg = "xts(serpent)",           5467                 .alg = "xts(serpent)",
5742                 .generic_driver = "xts(ecb(se    5468                 .generic_driver = "xts(ecb(serpent-generic))",
5743                 .test = alg_test_skcipher,       5469                 .test = alg_test_skcipher,
5744                 .suite = {                       5470                 .suite = {
5745                         .cipher = __VECS(serp    5471                         .cipher = __VECS(serpent_xts_tv_template)
5746                 }                                5472                 }
5747         }, {                                     5473         }, {
5748                 .alg = "xts(sm4)",            << 
5749                 .generic_driver = "xts(ecb(sm << 
5750                 .test = alg_test_skcipher,    << 
5751                 .suite = {                    << 
5752                         .cipher = __VECS(sm4_ << 
5753                 }                             << 
5754         }, {                                  << 
5755                 .alg = "xts(twofish)",           5474                 .alg = "xts(twofish)",
5756                 .generic_driver = "xts(ecb(tw    5475                 .generic_driver = "xts(ecb(twofish-generic))",
5757                 .test = alg_test_skcipher,       5476                 .test = alg_test_skcipher,
5758                 .suite = {                       5477                 .suite = {
5759                         .cipher = __VECS(tf_x    5478                         .cipher = __VECS(tf_xts_tv_template)
5760                 }                                5479                 }
5761         }, {                                     5480         }, {
5762 #if IS_ENABLED(CONFIG_CRYPTO_PAES_S390)          5481 #if IS_ENABLED(CONFIG_CRYPTO_PAES_S390)
5763                 .alg = "xts-paes-s390",          5482                 .alg = "xts-paes-s390",
5764                 .fips_allowed = 1,               5483                 .fips_allowed = 1,
5765                 .test = alg_test_skcipher,       5484                 .test = alg_test_skcipher,
5766                 .suite = {                       5485                 .suite = {
5767                         .cipher = __VECS(aes_    5486                         .cipher = __VECS(aes_xts_tv_template)
5768                 }                                5487                 }
5769         }, {                                     5488         }, {
5770 #endif                                           5489 #endif
                                                   >> 5490                 .alg = "xts4096(paes)",
                                                   >> 5491                 .test = alg_test_null,
                                                   >> 5492                 .fips_allowed = 1,
                                                   >> 5493         }, {
                                                   >> 5494                 .alg = "xts512(paes)",
                                                   >> 5495                 .test = alg_test_null,
                                                   >> 5496                 .fips_allowed = 1,
                                                   >> 5497         }, {
5771                 .alg = "xxhash64",               5498                 .alg = "xxhash64",
5772                 .test = alg_test_hash,           5499                 .test = alg_test_hash,
5773                 .fips_allowed = 1,               5500                 .fips_allowed = 1,
5774                 .suite = {                       5501                 .suite = {
5775                         .hash = __VECS(xxhash    5502                         .hash = __VECS(xxhash64_tv_template)
5776                 }                                5503                 }
5777         }, {                                     5504         }, {
                                                   >> 5505                 .alg = "zlib-deflate",
                                                   >> 5506                 .test = alg_test_comp,
                                                   >> 5507                 .fips_allowed = 1,
                                                   >> 5508                 .suite = {
                                                   >> 5509                         .comp = {
                                                   >> 5510                                 .comp = __VECS(zlib_deflate_comp_tv_template),
                                                   >> 5511                                 .decomp = __VECS(zlib_deflate_decomp_tv_template)
                                                   >> 5512                         }
                                                   >> 5513                 }
                                                   >> 5514         }, {
5778                 .alg = "zstd",                   5515                 .alg = "zstd",
5779                 .test = alg_test_comp,           5516                 .test = alg_test_comp,
5780                 .fips_allowed = 1,               5517                 .fips_allowed = 1,
5781                 .suite = {                       5518                 .suite = {
5782                         .comp = {                5519                         .comp = {
5783                                 .comp = __VEC    5520                                 .comp = __VECS(zstd_comp_tv_template),
5784                                 .decomp = __V    5521                                 .decomp = __VECS(zstd_decomp_tv_template)
5785                         }                        5522                         }
5786                 }                                5523                 }
5787         }                                        5524         }
5788 };                                               5525 };
5789                                                  5526 
5790 static void alg_check_test_descs_order(void)     5527 static void alg_check_test_descs_order(void)
5791 {                                                5528 {
5792         int i;                                   5529         int i;
5793                                                  5530 
5794         for (i = 1; i < ARRAY_SIZE(alg_test_d    5531         for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
5795                 int diff = strcmp(alg_test_de    5532                 int diff = strcmp(alg_test_descs[i - 1].alg,
5796                                   alg_test_de    5533                                   alg_test_descs[i].alg);
5797                                                  5534 
5798                 if (WARN_ON(diff > 0)) {         5535                 if (WARN_ON(diff > 0)) {
5799                         pr_warn("testmgr: alg    5536                         pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
5800                                 alg_test_desc    5537                                 alg_test_descs[i - 1].alg,
5801                                 alg_test_desc    5538                                 alg_test_descs[i].alg);
5802                 }                                5539                 }
5803                                                  5540 
5804                 if (WARN_ON(diff == 0)) {        5541                 if (WARN_ON(diff == 0)) {
5805                         pr_warn("testmgr: dup    5542                         pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
5806                                 alg_test_desc    5543                                 alg_test_descs[i].alg);
5807                 }                                5544                 }
5808         }                                        5545         }
5809 }                                                5546 }
5810                                                  5547 
5811 static void alg_check_testvec_configs(void)      5548 static void alg_check_testvec_configs(void)
5812 {                                                5549 {
5813         int i;                                   5550         int i;
5814                                                  5551 
5815         for (i = 0; i < ARRAY_SIZE(default_ci    5552         for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++)
5816                 WARN_ON(!valid_testvec_config    5553                 WARN_ON(!valid_testvec_config(
5817                                 &default_ciph    5554                                 &default_cipher_testvec_configs[i]));
5818                                                  5555 
5819         for (i = 0; i < ARRAY_SIZE(default_ha    5556         for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++)
5820                 WARN_ON(!valid_testvec_config    5557                 WARN_ON(!valid_testvec_config(
5821                                 &default_hash    5558                                 &default_hash_testvec_configs[i]));
5822 }                                                5559 }
5823                                                  5560 
5824 static void testmgr_onetime_init(void)           5561 static void testmgr_onetime_init(void)
5825 {                                                5562 {
5826         alg_check_test_descs_order();            5563         alg_check_test_descs_order();
5827         alg_check_testvec_configs();             5564         alg_check_testvec_configs();
5828                                                  5565 
5829 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS         5566 #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS
5830         pr_warn("alg: extra crypto tests enab    5567         pr_warn("alg: extra crypto tests enabled.  This is intended for developer use only.\n");
5831 #endif                                           5568 #endif
5832 }                                                5569 }
5833                                                  5570 
5834 static int alg_find_test(const char *alg)        5571 static int alg_find_test(const char *alg)
5835 {                                                5572 {
5836         int start = 0;                           5573         int start = 0;
5837         int end = ARRAY_SIZE(alg_test_descs);    5574         int end = ARRAY_SIZE(alg_test_descs);
5838                                                  5575 
5839         while (start < end) {                    5576         while (start < end) {
5840                 int i = (start + end) / 2;       5577                 int i = (start + end) / 2;
5841                 int diff = strcmp(alg_test_de    5578                 int diff = strcmp(alg_test_descs[i].alg, alg);
5842                                                  5579 
5843                 if (diff > 0) {                  5580                 if (diff > 0) {
5844                         end = i;                 5581                         end = i;
5845                         continue;                5582                         continue;
5846                 }                                5583                 }
5847                                                  5584 
5848                 if (diff < 0) {                  5585                 if (diff < 0) {
5849                         start = i + 1;           5586                         start = i + 1;
5850                         continue;                5587                         continue;
5851                 }                                5588                 }
5852                                                  5589 
5853                 return i;                        5590                 return i;
5854         }                                        5591         }
5855                                                  5592 
5856         return -1;                               5593         return -1;
5857 }                                                5594 }
5858                                                  5595 
5859 static int alg_fips_disabled(const char *driv << 
5860 {                                             << 
5861         pr_info("alg: %s (%s) is disabled due << 
5862                                               << 
5863         return -ECANCELED;                    << 
5864 }                                             << 
5865                                               << 
5866 int alg_test(const char *driver, const char *    5596 int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
5867 {                                                5597 {
5868         int i;                                   5598         int i;
5869         int j;                                   5599         int j;
5870         int rc;                                  5600         int rc;
5871                                                  5601 
5872         if (!fips_enabled && notests) {          5602         if (!fips_enabled && notests) {
5873                 printk_once(KERN_INFO "alg: s    5603                 printk_once(KERN_INFO "alg: self-tests disabled\n");
5874                 return 0;                        5604                 return 0;
5875         }                                        5605         }
5876                                                  5606 
5877         DO_ONCE(testmgr_onetime_init);           5607         DO_ONCE(testmgr_onetime_init);
5878                                                  5608 
5879         if ((type & CRYPTO_ALG_TYPE_MASK) ==     5609         if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
5880                 char nalg[CRYPTO_MAX_ALG_NAME    5610                 char nalg[CRYPTO_MAX_ALG_NAME];
5881                                                  5611 
5882                 if (snprintf(nalg, sizeof(nal    5612                 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
5883                     sizeof(nalg))                5613                     sizeof(nalg))
5884                         return -ENAMETOOLONG;    5614                         return -ENAMETOOLONG;
5885                                                  5615 
5886                 i = alg_find_test(nalg);         5616                 i = alg_find_test(nalg);
5887                 if (i < 0)                       5617                 if (i < 0)
5888                         goto notest;             5618                         goto notest;
5889                                                  5619 
5890                 if (fips_enabled && !alg_test    5620                 if (fips_enabled && !alg_test_descs[i].fips_allowed)
5891                         goto non_fips_alg;       5621                         goto non_fips_alg;
5892                                                  5622 
5893                 rc = alg_test_cipher(alg_test    5623                 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
5894                 goto test_done;                  5624                 goto test_done;
5895         }                                        5625         }
5896                                                  5626 
5897         i = alg_find_test(alg);                  5627         i = alg_find_test(alg);
5898         j = alg_find_test(driver);               5628         j = alg_find_test(driver);
5899         if (i < 0 && j < 0)                      5629         if (i < 0 && j < 0)
5900                 goto notest;                     5630                 goto notest;
5901                                                  5631 
5902         if (fips_enabled) {                   !! 5632         if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
5903                 if (j >= 0 && !alg_test_descs !! 5633                              (j >= 0 && !alg_test_descs[j].fips_allowed)))
5904                         return -EINVAL;       !! 5634                 goto non_fips_alg;
5905                                               << 
5906                 if (i >= 0 && !alg_test_descs << 
5907                         goto non_fips_alg;    << 
5908         }                                     << 
5909                                                  5635 
5910         rc = 0;                                  5636         rc = 0;
5911         if (i >= 0)                              5637         if (i >= 0)
5912                 rc |= alg_test_descs[i].test(    5638                 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
5913                                                  5639                                              type, mask);
5914         if (j >= 0 && j != i)                    5640         if (j >= 0 && j != i)
5915                 rc |= alg_test_descs[j].test(    5641                 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
5916                                                  5642                                              type, mask);
5917                                                  5643 
5918 test_done:                                       5644 test_done:
5919         if (rc) {                                5645         if (rc) {
5920                 if (fips_enabled || panic_on_    5646                 if (fips_enabled || panic_on_fail) {
5921                         fips_fail_notify();      5647                         fips_fail_notify();
5922                         panic("alg: self-test    5648                         panic("alg: self-tests for %s (%s) failed in %s mode!\n",
5923                               driver, alg,       5649                               driver, alg,
5924                               fips_enabled ?     5650                               fips_enabled ? "fips" : "panic_on_fail");
5925                 }                                5651                 }
5926                 pr_warn("alg: self-tests for  !! 5652                 WARN(1, "alg: self-tests for %s (%s) failed (rc=%d)",
5927                         alg, driver, rc);     !! 5653                      driver, alg, rc);
5928                 WARN(rc != -ENOENT,           << 
5929                      "alg: self-tests for %s  << 
5930                      alg, driver, rc);        << 
5931         } else {                                 5654         } else {
5932                 if (fips_enabled)                5655                 if (fips_enabled)
5933                         pr_info("alg: self-te    5656                         pr_info("alg: self-tests for %s (%s) passed\n",
5934                                 driver, alg);    5657                                 driver, alg);
5935         }                                        5658         }
5936                                                  5659 
5937         return rc;                               5660         return rc;
5938                                                  5661 
5939 notest:                                          5662 notest:
5940         if ((type & CRYPTO_ALG_TYPE_MASK) ==  << 
5941                 char nalg[CRYPTO_MAX_ALG_NAME << 
5942                                               << 
5943                 if (snprintf(nalg, sizeof(nal << 
5944                     sizeof(nalg))             << 
5945                         goto notest2;         << 
5946                                               << 
5947                 i = alg_find_test(nalg);      << 
5948                 if (i < 0)                    << 
5949                         goto notest2;         << 
5950                                               << 
5951                 if (fips_enabled && !alg_test << 
5952                         goto non_fips_alg;    << 
5953                                               << 
5954                 rc = alg_test_skcipher(alg_te << 
5955                 goto test_done;               << 
5956         }                                     << 
5957                                               << 
5958 notest2:                                      << 
5959         printk(KERN_INFO "alg: No test for %s    5663         printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
5960                                               << 
5961         if (type & CRYPTO_ALG_FIPS_INTERNAL)  << 
5962                 return alg_fips_disabled(driv << 
5963                                               << 
5964         return 0;                                5664         return 0;
5965 non_fips_alg:                                    5665 non_fips_alg:
5966         return alg_fips_disabled(driver, alg) !! 5666         return -EINVAL;
5967 }                                                5667 }
5968                                                  5668 
5969 #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS    5669 #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
5970                                                  5670 
5971 EXPORT_SYMBOL_GPL(alg_test);                     5671 EXPORT_SYMBOL_GPL(alg_test);
5972                                                  5672 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php