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