Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Algorithm testing framework and tests. |
| 3 | * |
| 4 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> |
| 5 | * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org> |
| 6 | * Copyright (c) 2007 Nokia Siemens Networks |
| 7 | * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au> |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 8 | * Copyright (c) 2019 Google LLC |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 9 | * |
Adrian Hoban | 69435b9 | 2010-11-04 15:02:04 -0400 | [diff] [blame] | 10 | * Updated RFC4106 AES-GCM testing. |
| 11 | * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com) |
| 12 | * Adrian Hoban <adrian.hoban@intel.com> |
| 13 | * Gabriele Paoloni <gabriele.paoloni@intel.com> |
| 14 | * Tadeusz Struk (tadeusz.struk@intel.com) |
| 15 | * Copyright (c) 2010, Intel Corporation. |
| 16 | * |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 17 | * This program is free software; you can redistribute it and/or modify it |
| 18 | * under the terms of the GNU General Public License as published by the Free |
| 19 | * Software Foundation; either version 2 of the License, or (at your option) |
| 20 | * any later version. |
| 21 | * |
| 22 | */ |
| 23 | |
Herbert Xu | 1ce3311 | 2015-04-22 15:06:31 +0800 | [diff] [blame] | 24 | #include <crypto/aead.h> |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 25 | #include <crypto/hash.h> |
Herbert Xu | 12773d9 | 2015-08-20 15:21:46 +0800 | [diff] [blame] | 26 | #include <crypto/skcipher.h> |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 27 | #include <linux/err.h> |
Herbert Xu | 1c41b88 | 2015-04-22 13:25:58 +0800 | [diff] [blame] | 28 | #include <linux/fips.h> |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 29 | #include <linux/module.h> |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 30 | #include <linux/once.h> |
Eric Biggers | 25f9ddd | 2019-01-31 23:51:45 -0800 | [diff] [blame] | 31 | #include <linux/random.h> |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 32 | #include <linux/scatterlist.h> |
| 33 | #include <linux/slab.h> |
| 34 | #include <linux/string.h> |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 35 | #include <crypto/rng.h> |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 36 | #include <crypto/drbg.h> |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 37 | #include <crypto/akcipher.h> |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 38 | #include <crypto/kpp.h> |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 39 | #include <crypto/acompress.h> |
Eric Biggers | b55e1a3 | 2019-03-12 22:12:47 -0700 | [diff] [blame] | 40 | #include <crypto/internal/simd.h> |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 41 | |
| 42 | #include "internal.h" |
Alexander Shishkin | 0b767f9 | 2010-06-03 20:53:43 +1000 | [diff] [blame] | 43 | |
Richard W.M. Jones | 9e5c9fe | 2016-05-03 10:00:17 +0100 | [diff] [blame] | 44 | static bool notests; |
| 45 | module_param(notests, bool, 0644); |
| 46 | MODULE_PARM_DESC(notests, "disable crypto self-tests"); |
| 47 | |
Eric Biggers | eda69b0 | 2019-03-31 13:09:14 -0700 | [diff] [blame] | 48 | static bool panic_on_fail; |
| 49 | module_param(panic_on_fail, bool, 0444); |
| 50 | |
Eric Biggers | 5b2706a | 2019-01-31 23:51:44 -0800 | [diff] [blame] | 51 | #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS |
| 52 | static bool noextratests; |
| 53 | module_param(noextratests, bool, 0644); |
| 54 | MODULE_PARM_DESC(noextratests, "disable expensive crypto self-tests"); |
| 55 | |
| 56 | static unsigned int fuzz_iterations = 100; |
| 57 | module_param(fuzz_iterations, uint, 0644); |
| 58 | MODULE_PARM_DESC(fuzz_iterations, "number of fuzz test iterations"); |
Eric Biggers | b55e1a3 | 2019-03-12 22:12:47 -0700 | [diff] [blame] | 59 | |
| 60 | DEFINE_PER_CPU(bool, crypto_simd_disabled_for_test); |
| 61 | EXPORT_PER_CPU_SYMBOL_GPL(crypto_simd_disabled_for_test); |
Eric Biggers | 5b2706a | 2019-01-31 23:51:44 -0800 | [diff] [blame] | 62 | #endif |
| 63 | |
Herbert Xu | 326a634 | 2010-08-06 09:40:28 +0800 | [diff] [blame] | 64 | #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS |
Alexander Shishkin | 0b767f9 | 2010-06-03 20:53:43 +1000 | [diff] [blame] | 65 | |
| 66 | /* a perfect nop */ |
| 67 | int alg_test(const char *driver, const char *alg, u32 type, u32 mask) |
| 68 | { |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | #else |
| 73 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 74 | #include "testmgr.h" |
| 75 | |
| 76 | /* |
| 77 | * Need slab memory for testing (size in number of pages). |
| 78 | */ |
| 79 | #define XBUFSIZE 8 |
| 80 | |
| 81 | /* |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 82 | * Used by test_cipher() |
| 83 | */ |
| 84 | #define ENCRYPT 1 |
| 85 | #define DECRYPT 0 |
| 86 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 87 | struct aead_test_suite { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 88 | const struct aead_testvec *vecs; |
| 89 | unsigned int count; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | struct cipher_test_suite { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 93 | const struct cipher_testvec *vecs; |
| 94 | unsigned int count; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | struct comp_test_suite { |
| 98 | struct { |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 99 | const struct comp_testvec *vecs; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 100 | unsigned int count; |
| 101 | } comp, decomp; |
| 102 | }; |
| 103 | |
| 104 | struct hash_test_suite { |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 105 | const struct hash_testvec *vecs; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 106 | unsigned int count; |
| 107 | }; |
| 108 | |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 109 | struct cprng_test_suite { |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 110 | const struct cprng_testvec *vecs; |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 111 | unsigned int count; |
| 112 | }; |
| 113 | |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 114 | struct drbg_test_suite { |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 115 | const struct drbg_testvec *vecs; |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 116 | unsigned int count; |
| 117 | }; |
| 118 | |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 119 | struct akcipher_test_suite { |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 120 | const struct akcipher_testvec *vecs; |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 121 | unsigned int count; |
| 122 | }; |
| 123 | |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 124 | struct kpp_test_suite { |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 125 | const struct kpp_testvec *vecs; |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 126 | unsigned int count; |
| 127 | }; |
| 128 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 129 | struct alg_test_desc { |
| 130 | const char *alg; |
Eric Biggers | f2bb770a | 2019-04-11 21:57:38 -0700 | [diff] [blame] | 131 | const char *generic_driver; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 132 | int (*test)(const struct alg_test_desc *desc, const char *driver, |
| 133 | u32 type, u32 mask); |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 134 | int fips_allowed; /* set if alg is allowed in fips mode */ |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 135 | |
| 136 | union { |
| 137 | struct aead_test_suite aead; |
| 138 | struct cipher_test_suite cipher; |
| 139 | struct comp_test_suite comp; |
| 140 | struct hash_test_suite hash; |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 141 | struct cprng_test_suite cprng; |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 142 | struct drbg_test_suite drbg; |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 143 | struct akcipher_test_suite akcipher; |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 144 | struct kpp_test_suite kpp; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 145 | } suite; |
| 146 | }; |
| 147 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 148 | static void hexdump(unsigned char *buf, unsigned int len) |
| 149 | { |
| 150 | print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET, |
| 151 | 16, 1, |
| 152 | buf, len, false); |
| 153 | } |
| 154 | |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 155 | static int __testmgr_alloc_buf(char *buf[XBUFSIZE], int order) |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 156 | { |
| 157 | int i; |
| 158 | |
| 159 | for (i = 0; i < XBUFSIZE; i++) { |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 160 | buf[i] = (char *)__get_free_pages(GFP_KERNEL, order); |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 161 | if (!buf[i]) |
| 162 | goto err_free_buf; |
| 163 | } |
| 164 | |
| 165 | return 0; |
| 166 | |
| 167 | err_free_buf: |
| 168 | while (i-- > 0) |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 169 | free_pages((unsigned long)buf[i], order); |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 170 | |
| 171 | return -ENOMEM; |
| 172 | } |
| 173 | |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 174 | static int testmgr_alloc_buf(char *buf[XBUFSIZE]) |
| 175 | { |
| 176 | return __testmgr_alloc_buf(buf, 0); |
| 177 | } |
| 178 | |
| 179 | static void __testmgr_free_buf(char *buf[XBUFSIZE], int order) |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 180 | { |
| 181 | int i; |
| 182 | |
| 183 | for (i = 0; i < XBUFSIZE; i++) |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 184 | free_pages((unsigned long)buf[i], order); |
| 185 | } |
| 186 | |
| 187 | static void testmgr_free_buf(char *buf[XBUFSIZE]) |
| 188 | { |
| 189 | __testmgr_free_buf(buf, 0); |
| 190 | } |
| 191 | |
| 192 | #define TESTMGR_POISON_BYTE 0xfe |
| 193 | #define TESTMGR_POISON_LEN 16 |
| 194 | |
| 195 | static inline void testmgr_poison(void *addr, size_t len) |
| 196 | { |
| 197 | memset(addr, TESTMGR_POISON_BYTE, len); |
| 198 | } |
| 199 | |
| 200 | /* Is the memory region still fully poisoned? */ |
| 201 | static inline bool testmgr_is_poison(const void *addr, size_t len) |
| 202 | { |
| 203 | return memchr_inv(addr, TESTMGR_POISON_BYTE, len) == NULL; |
| 204 | } |
| 205 | |
| 206 | /* flush type for hash algorithms */ |
| 207 | enum flush_type { |
| 208 | /* merge with update of previous buffer(s) */ |
| 209 | FLUSH_TYPE_NONE = 0, |
| 210 | |
| 211 | /* update with previous buffer(s) before doing this one */ |
| 212 | FLUSH_TYPE_FLUSH, |
| 213 | |
| 214 | /* likewise, but also export and re-import the intermediate state */ |
| 215 | FLUSH_TYPE_REIMPORT, |
| 216 | }; |
| 217 | |
| 218 | /* finalization function for hash algorithms */ |
| 219 | enum finalization_type { |
| 220 | FINALIZATION_TYPE_FINAL, /* use final() */ |
| 221 | FINALIZATION_TYPE_FINUP, /* use finup() */ |
| 222 | FINALIZATION_TYPE_DIGEST, /* use digest() */ |
| 223 | }; |
| 224 | |
| 225 | #define TEST_SG_TOTAL 10000 |
| 226 | |
| 227 | /** |
| 228 | * struct test_sg_division - description of a scatterlist entry |
| 229 | * |
| 230 | * This struct describes one entry of a scatterlist being constructed to check a |
| 231 | * crypto test vector. |
| 232 | * |
| 233 | * @proportion_of_total: length of this chunk relative to the total length, |
| 234 | * given as a proportion out of TEST_SG_TOTAL so that it |
| 235 | * scales to fit any test vector |
| 236 | * @offset: byte offset into a 2-page buffer at which this chunk will start |
| 237 | * @offset_relative_to_alignmask: if true, add the algorithm's alignmask to the |
| 238 | * @offset |
| 239 | * @flush_type: for hashes, whether an update() should be done now vs. |
| 240 | * continuing to accumulate data |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 241 | * @nosimd: if doing the pending update(), do it with SIMD disabled? |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 242 | */ |
| 243 | struct test_sg_division { |
| 244 | unsigned int proportion_of_total; |
| 245 | unsigned int offset; |
| 246 | bool offset_relative_to_alignmask; |
| 247 | enum flush_type flush_type; |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 248 | bool nosimd; |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | /** |
| 252 | * struct testvec_config - configuration for testing a crypto test vector |
| 253 | * |
| 254 | * This struct describes the data layout and other parameters with which each |
| 255 | * crypto test vector can be tested. |
| 256 | * |
| 257 | * @name: name of this config, logged for debugging purposes if a test fails |
| 258 | * @inplace: operate on the data in-place, if applicable for the algorithm type? |
| 259 | * @req_flags: extra request_flags, e.g. CRYPTO_TFM_REQ_MAY_SLEEP |
| 260 | * @src_divs: description of how to arrange the source scatterlist |
| 261 | * @dst_divs: description of how to arrange the dst scatterlist, if applicable |
| 262 | * for the algorithm type. Defaults to @src_divs if unset. |
| 263 | * @iv_offset: misalignment of the IV in the range [0..MAX_ALGAPI_ALIGNMASK+1], |
| 264 | * where 0 is aligned to a 2*(MAX_ALGAPI_ALIGNMASK+1) byte boundary |
| 265 | * @iv_offset_relative_to_alignmask: if true, add the algorithm's alignmask to |
| 266 | * the @iv_offset |
| 267 | * @finalization_type: what finalization function to use for hashes |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 268 | * @nosimd: execute with SIMD disabled? Requires !CRYPTO_TFM_REQ_MAY_SLEEP. |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 269 | */ |
| 270 | struct testvec_config { |
| 271 | const char *name; |
| 272 | bool inplace; |
| 273 | u32 req_flags; |
| 274 | struct test_sg_division src_divs[XBUFSIZE]; |
| 275 | struct test_sg_division dst_divs[XBUFSIZE]; |
| 276 | unsigned int iv_offset; |
| 277 | bool iv_offset_relative_to_alignmask; |
| 278 | enum finalization_type finalization_type; |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 279 | bool nosimd; |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 280 | }; |
| 281 | |
| 282 | #define TESTVEC_CONFIG_NAMELEN 192 |
| 283 | |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 284 | /* |
| 285 | * The following are the lists of testvec_configs to test for each algorithm |
| 286 | * type when the basic crypto self-tests are enabled, i.e. when |
| 287 | * CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is unset. They aim to provide good test |
| 288 | * coverage, while keeping the test time much shorter than the full fuzz tests |
| 289 | * so that the basic tests can be enabled in a wider range of circumstances. |
| 290 | */ |
| 291 | |
| 292 | /* Configs for skciphers and aeads */ |
| 293 | static const struct testvec_config default_cipher_testvec_configs[] = { |
| 294 | { |
| 295 | .name = "in-place", |
| 296 | .inplace = true, |
| 297 | .src_divs = { { .proportion_of_total = 10000 } }, |
| 298 | }, { |
| 299 | .name = "out-of-place", |
| 300 | .src_divs = { { .proportion_of_total = 10000 } }, |
| 301 | }, { |
| 302 | .name = "unaligned buffer, offset=1", |
| 303 | .src_divs = { { .proportion_of_total = 10000, .offset = 1 } }, |
| 304 | .iv_offset = 1, |
| 305 | }, { |
| 306 | .name = "buffer aligned only to alignmask", |
| 307 | .src_divs = { |
| 308 | { |
| 309 | .proportion_of_total = 10000, |
| 310 | .offset = 1, |
| 311 | .offset_relative_to_alignmask = true, |
| 312 | }, |
| 313 | }, |
| 314 | .iv_offset = 1, |
| 315 | .iv_offset_relative_to_alignmask = true, |
| 316 | }, { |
| 317 | .name = "two even aligned splits", |
| 318 | .src_divs = { |
| 319 | { .proportion_of_total = 5000 }, |
| 320 | { .proportion_of_total = 5000 }, |
| 321 | }, |
| 322 | }, { |
| 323 | .name = "uneven misaligned splits, may sleep", |
| 324 | .req_flags = CRYPTO_TFM_REQ_MAY_SLEEP, |
| 325 | .src_divs = { |
| 326 | { .proportion_of_total = 1900, .offset = 33 }, |
| 327 | { .proportion_of_total = 3300, .offset = 7 }, |
| 328 | { .proportion_of_total = 4800, .offset = 18 }, |
| 329 | }, |
| 330 | .iv_offset = 3, |
| 331 | }, { |
| 332 | .name = "misaligned splits crossing pages, inplace", |
| 333 | .inplace = true, |
| 334 | .src_divs = { |
| 335 | { |
| 336 | .proportion_of_total = 7500, |
| 337 | .offset = PAGE_SIZE - 32 |
| 338 | }, { |
| 339 | .proportion_of_total = 2500, |
| 340 | .offset = PAGE_SIZE - 7 |
| 341 | }, |
| 342 | }, |
| 343 | } |
| 344 | }; |
| 345 | |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 346 | static const struct testvec_config default_hash_testvec_configs[] = { |
| 347 | { |
| 348 | .name = "init+update+final aligned buffer", |
| 349 | .src_divs = { { .proportion_of_total = 10000 } }, |
| 350 | .finalization_type = FINALIZATION_TYPE_FINAL, |
| 351 | }, { |
| 352 | .name = "init+finup aligned buffer", |
| 353 | .src_divs = { { .proportion_of_total = 10000 } }, |
| 354 | .finalization_type = FINALIZATION_TYPE_FINUP, |
| 355 | }, { |
| 356 | .name = "digest aligned buffer", |
| 357 | .src_divs = { { .proportion_of_total = 10000 } }, |
| 358 | .finalization_type = FINALIZATION_TYPE_DIGEST, |
| 359 | }, { |
| 360 | .name = "init+update+final misaligned buffer", |
| 361 | .src_divs = { { .proportion_of_total = 10000, .offset = 1 } }, |
| 362 | .finalization_type = FINALIZATION_TYPE_FINAL, |
| 363 | }, { |
| 364 | .name = "digest buffer aligned only to alignmask", |
| 365 | .src_divs = { |
| 366 | { |
| 367 | .proportion_of_total = 10000, |
| 368 | .offset = 1, |
| 369 | .offset_relative_to_alignmask = true, |
| 370 | }, |
| 371 | }, |
| 372 | .finalization_type = FINALIZATION_TYPE_DIGEST, |
| 373 | }, { |
| 374 | .name = "init+update+update+final two even splits", |
| 375 | .src_divs = { |
| 376 | { .proportion_of_total = 5000 }, |
| 377 | { |
| 378 | .proportion_of_total = 5000, |
| 379 | .flush_type = FLUSH_TYPE_FLUSH, |
| 380 | }, |
| 381 | }, |
| 382 | .finalization_type = FINALIZATION_TYPE_FINAL, |
| 383 | }, { |
| 384 | .name = "digest uneven misaligned splits, may sleep", |
| 385 | .req_flags = CRYPTO_TFM_REQ_MAY_SLEEP, |
| 386 | .src_divs = { |
| 387 | { .proportion_of_total = 1900, .offset = 33 }, |
| 388 | { .proportion_of_total = 3300, .offset = 7 }, |
| 389 | { .proportion_of_total = 4800, .offset = 18 }, |
| 390 | }, |
| 391 | .finalization_type = FINALIZATION_TYPE_DIGEST, |
| 392 | }, { |
| 393 | .name = "digest misaligned splits crossing pages", |
| 394 | .src_divs = { |
| 395 | { |
| 396 | .proportion_of_total = 7500, |
| 397 | .offset = PAGE_SIZE - 32, |
| 398 | }, { |
| 399 | .proportion_of_total = 2500, |
| 400 | .offset = PAGE_SIZE - 7, |
| 401 | }, |
| 402 | }, |
| 403 | .finalization_type = FINALIZATION_TYPE_DIGEST, |
| 404 | }, { |
| 405 | .name = "import/export", |
| 406 | .src_divs = { |
| 407 | { |
| 408 | .proportion_of_total = 6500, |
| 409 | .flush_type = FLUSH_TYPE_REIMPORT, |
| 410 | }, { |
| 411 | .proportion_of_total = 3500, |
| 412 | .flush_type = FLUSH_TYPE_REIMPORT, |
| 413 | }, |
| 414 | }, |
| 415 | .finalization_type = FINALIZATION_TYPE_FINAL, |
| 416 | } |
| 417 | }; |
| 418 | |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 419 | static unsigned int count_test_sg_divisions(const struct test_sg_division *divs) |
| 420 | { |
| 421 | unsigned int remaining = TEST_SG_TOTAL; |
| 422 | unsigned int ndivs = 0; |
| 423 | |
| 424 | do { |
| 425 | remaining -= divs[ndivs++].proportion_of_total; |
| 426 | } while (remaining); |
| 427 | |
| 428 | return ndivs; |
| 429 | } |
| 430 | |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 431 | #define SGDIVS_HAVE_FLUSHES BIT(0) |
| 432 | #define SGDIVS_HAVE_NOSIMD BIT(1) |
| 433 | |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 434 | static bool valid_sg_divisions(const struct test_sg_division *divs, |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 435 | unsigned int count, int *flags_ret) |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 436 | { |
| 437 | unsigned int total = 0; |
| 438 | unsigned int i; |
| 439 | |
| 440 | for (i = 0; i < count && total != TEST_SG_TOTAL; i++) { |
| 441 | if (divs[i].proportion_of_total <= 0 || |
| 442 | divs[i].proportion_of_total > TEST_SG_TOTAL - total) |
| 443 | return false; |
| 444 | total += divs[i].proportion_of_total; |
| 445 | if (divs[i].flush_type != FLUSH_TYPE_NONE) |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 446 | *flags_ret |= SGDIVS_HAVE_FLUSHES; |
| 447 | if (divs[i].nosimd) |
| 448 | *flags_ret |= SGDIVS_HAVE_NOSIMD; |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 449 | } |
| 450 | return total == TEST_SG_TOTAL && |
| 451 | memchr_inv(&divs[i], 0, (count - i) * sizeof(divs[0])) == NULL; |
| 452 | } |
| 453 | |
| 454 | /* |
| 455 | * Check whether the given testvec_config is valid. This isn't strictly needed |
| 456 | * since every testvec_config should be valid, but check anyway so that people |
| 457 | * don't unknowingly add broken configs that don't do what they wanted. |
| 458 | */ |
| 459 | static bool valid_testvec_config(const struct testvec_config *cfg) |
| 460 | { |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 461 | int flags = 0; |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 462 | |
| 463 | if (cfg->name == NULL) |
| 464 | return false; |
| 465 | |
| 466 | if (!valid_sg_divisions(cfg->src_divs, ARRAY_SIZE(cfg->src_divs), |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 467 | &flags)) |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 468 | return false; |
| 469 | |
| 470 | if (cfg->dst_divs[0].proportion_of_total) { |
| 471 | if (!valid_sg_divisions(cfg->dst_divs, |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 472 | ARRAY_SIZE(cfg->dst_divs), &flags)) |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 473 | return false; |
| 474 | } else { |
| 475 | if (memchr_inv(cfg->dst_divs, 0, sizeof(cfg->dst_divs))) |
| 476 | return false; |
| 477 | /* defaults to dst_divs=src_divs */ |
| 478 | } |
| 479 | |
| 480 | if (cfg->iv_offset + |
| 481 | (cfg->iv_offset_relative_to_alignmask ? MAX_ALGAPI_ALIGNMASK : 0) > |
| 482 | MAX_ALGAPI_ALIGNMASK + 1) |
| 483 | return false; |
| 484 | |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 485 | if ((flags & (SGDIVS_HAVE_FLUSHES | SGDIVS_HAVE_NOSIMD)) && |
| 486 | cfg->finalization_type == FINALIZATION_TYPE_DIGEST) |
| 487 | return false; |
| 488 | |
| 489 | if ((cfg->nosimd || (flags & SGDIVS_HAVE_NOSIMD)) && |
| 490 | (cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP)) |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 491 | return false; |
| 492 | |
| 493 | return true; |
| 494 | } |
| 495 | |
| 496 | struct test_sglist { |
| 497 | char *bufs[XBUFSIZE]; |
| 498 | struct scatterlist sgl[XBUFSIZE]; |
| 499 | struct scatterlist sgl_saved[XBUFSIZE]; |
| 500 | struct scatterlist *sgl_ptr; |
| 501 | unsigned int nents; |
| 502 | }; |
| 503 | |
| 504 | static int init_test_sglist(struct test_sglist *tsgl) |
| 505 | { |
| 506 | return __testmgr_alloc_buf(tsgl->bufs, 1 /* two pages per buffer */); |
| 507 | } |
| 508 | |
| 509 | static void destroy_test_sglist(struct test_sglist *tsgl) |
| 510 | { |
| 511 | return __testmgr_free_buf(tsgl->bufs, 1 /* two pages per buffer */); |
| 512 | } |
| 513 | |
| 514 | /** |
| 515 | * build_test_sglist() - build a scatterlist for a crypto test |
| 516 | * |
| 517 | * @tsgl: the scatterlist to build. @tsgl->bufs[] contains an array of 2-page |
| 518 | * buffers which the scatterlist @tsgl->sgl[] will be made to point into. |
| 519 | * @divs: the layout specification on which the scatterlist will be based |
| 520 | * @alignmask: the algorithm's alignmask |
| 521 | * @total_len: the total length of the scatterlist to build in bytes |
| 522 | * @data: if non-NULL, the buffers will be filled with this data until it ends. |
| 523 | * Otherwise the buffers will be poisoned. In both cases, some bytes |
| 524 | * past the end of each buffer will be poisoned to help detect overruns. |
| 525 | * @out_divs: if non-NULL, the test_sg_division to which each scatterlist entry |
| 526 | * corresponds will be returned here. This will match @divs except |
| 527 | * that divisions resolving to a length of 0 are omitted as they are |
| 528 | * not included in the scatterlist. |
| 529 | * |
| 530 | * Return: 0 or a -errno value |
| 531 | */ |
| 532 | static int build_test_sglist(struct test_sglist *tsgl, |
| 533 | const struct test_sg_division *divs, |
| 534 | const unsigned int alignmask, |
| 535 | const unsigned int total_len, |
| 536 | struct iov_iter *data, |
| 537 | const struct test_sg_division *out_divs[XBUFSIZE]) |
| 538 | { |
| 539 | struct { |
| 540 | const struct test_sg_division *div; |
| 541 | size_t length; |
| 542 | } partitions[XBUFSIZE]; |
| 543 | const unsigned int ndivs = count_test_sg_divisions(divs); |
| 544 | unsigned int len_remaining = total_len; |
| 545 | unsigned int i; |
| 546 | |
| 547 | BUILD_BUG_ON(ARRAY_SIZE(partitions) != ARRAY_SIZE(tsgl->sgl)); |
| 548 | if (WARN_ON(ndivs > ARRAY_SIZE(partitions))) |
| 549 | return -EINVAL; |
| 550 | |
| 551 | /* Calculate the (div, length) pairs */ |
| 552 | tsgl->nents = 0; |
| 553 | for (i = 0; i < ndivs; i++) { |
| 554 | unsigned int len_this_sg = |
| 555 | min(len_remaining, |
| 556 | (total_len * divs[i].proportion_of_total + |
| 557 | TEST_SG_TOTAL / 2) / TEST_SG_TOTAL); |
| 558 | |
| 559 | if (len_this_sg != 0) { |
| 560 | partitions[tsgl->nents].div = &divs[i]; |
| 561 | partitions[tsgl->nents].length = len_this_sg; |
| 562 | tsgl->nents++; |
| 563 | len_remaining -= len_this_sg; |
| 564 | } |
| 565 | } |
| 566 | if (tsgl->nents == 0) { |
| 567 | partitions[tsgl->nents].div = &divs[0]; |
| 568 | partitions[tsgl->nents].length = 0; |
| 569 | tsgl->nents++; |
| 570 | } |
| 571 | partitions[tsgl->nents - 1].length += len_remaining; |
| 572 | |
| 573 | /* Set up the sgl entries and fill the data or poison */ |
| 574 | sg_init_table(tsgl->sgl, tsgl->nents); |
| 575 | for (i = 0; i < tsgl->nents; i++) { |
| 576 | unsigned int offset = partitions[i].div->offset; |
| 577 | void *addr; |
| 578 | |
| 579 | if (partitions[i].div->offset_relative_to_alignmask) |
| 580 | offset += alignmask; |
| 581 | |
| 582 | while (offset + partitions[i].length + TESTMGR_POISON_LEN > |
| 583 | 2 * PAGE_SIZE) { |
| 584 | if (WARN_ON(offset <= 0)) |
| 585 | return -EINVAL; |
| 586 | offset /= 2; |
| 587 | } |
| 588 | |
| 589 | addr = &tsgl->bufs[i][offset]; |
| 590 | sg_set_buf(&tsgl->sgl[i], addr, partitions[i].length); |
| 591 | |
| 592 | if (out_divs) |
| 593 | out_divs[i] = partitions[i].div; |
| 594 | |
| 595 | if (data) { |
| 596 | size_t copy_len, copied; |
| 597 | |
| 598 | copy_len = min(partitions[i].length, data->count); |
| 599 | copied = copy_from_iter(addr, copy_len, data); |
| 600 | if (WARN_ON(copied != copy_len)) |
| 601 | return -EINVAL; |
| 602 | testmgr_poison(addr + copy_len, partitions[i].length + |
| 603 | TESTMGR_POISON_LEN - copy_len); |
| 604 | } else { |
| 605 | testmgr_poison(addr, partitions[i].length + |
| 606 | TESTMGR_POISON_LEN); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | sg_mark_end(&tsgl->sgl[tsgl->nents - 1]); |
| 611 | tsgl->sgl_ptr = tsgl->sgl; |
| 612 | memcpy(tsgl->sgl_saved, tsgl->sgl, tsgl->nents * sizeof(tsgl->sgl[0])); |
| 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | /* |
| 617 | * Verify that a scatterlist crypto operation produced the correct output. |
| 618 | * |
| 619 | * @tsgl: scatterlist containing the actual output |
| 620 | * @expected_output: buffer containing the expected output |
| 621 | * @len_to_check: length of @expected_output in bytes |
| 622 | * @unchecked_prefix_len: number of ignored bytes in @tsgl prior to real result |
| 623 | * @check_poison: verify that the poison bytes after each chunk are intact? |
| 624 | * |
| 625 | * Return: 0 if correct, -EINVAL if incorrect, -EOVERFLOW if buffer overrun. |
| 626 | */ |
| 627 | static int verify_correct_output(const struct test_sglist *tsgl, |
| 628 | const char *expected_output, |
| 629 | unsigned int len_to_check, |
| 630 | unsigned int unchecked_prefix_len, |
| 631 | bool check_poison) |
| 632 | { |
| 633 | unsigned int i; |
| 634 | |
| 635 | for (i = 0; i < tsgl->nents; i++) { |
| 636 | struct scatterlist *sg = &tsgl->sgl_ptr[i]; |
| 637 | unsigned int len = sg->length; |
| 638 | unsigned int offset = sg->offset; |
| 639 | const char *actual_output; |
| 640 | |
| 641 | if (unchecked_prefix_len) { |
| 642 | if (unchecked_prefix_len >= len) { |
| 643 | unchecked_prefix_len -= len; |
| 644 | continue; |
| 645 | } |
| 646 | offset += unchecked_prefix_len; |
| 647 | len -= unchecked_prefix_len; |
| 648 | unchecked_prefix_len = 0; |
| 649 | } |
| 650 | len = min(len, len_to_check); |
| 651 | actual_output = page_address(sg_page(sg)) + offset; |
| 652 | if (memcmp(expected_output, actual_output, len) != 0) |
| 653 | return -EINVAL; |
| 654 | if (check_poison && |
| 655 | !testmgr_is_poison(actual_output + len, TESTMGR_POISON_LEN)) |
| 656 | return -EOVERFLOW; |
| 657 | len_to_check -= len; |
| 658 | expected_output += len; |
| 659 | } |
| 660 | if (WARN_ON(len_to_check != 0)) |
| 661 | return -EINVAL; |
| 662 | return 0; |
| 663 | } |
| 664 | |
| 665 | static bool is_test_sglist_corrupted(const struct test_sglist *tsgl) |
| 666 | { |
| 667 | unsigned int i; |
| 668 | |
| 669 | for (i = 0; i < tsgl->nents; i++) { |
| 670 | if (tsgl->sgl[i].page_link != tsgl->sgl_saved[i].page_link) |
| 671 | return true; |
| 672 | if (tsgl->sgl[i].offset != tsgl->sgl_saved[i].offset) |
| 673 | return true; |
| 674 | if (tsgl->sgl[i].length != tsgl->sgl_saved[i].length) |
| 675 | return true; |
| 676 | } |
| 677 | return false; |
| 678 | } |
| 679 | |
| 680 | struct cipher_test_sglists { |
| 681 | struct test_sglist src; |
| 682 | struct test_sglist dst; |
| 683 | }; |
| 684 | |
| 685 | static struct cipher_test_sglists *alloc_cipher_test_sglists(void) |
| 686 | { |
| 687 | struct cipher_test_sglists *tsgls; |
| 688 | |
| 689 | tsgls = kmalloc(sizeof(*tsgls), GFP_KERNEL); |
| 690 | if (!tsgls) |
| 691 | return NULL; |
| 692 | |
| 693 | if (init_test_sglist(&tsgls->src) != 0) |
| 694 | goto fail_kfree; |
| 695 | if (init_test_sglist(&tsgls->dst) != 0) |
| 696 | goto fail_destroy_src; |
| 697 | |
| 698 | return tsgls; |
| 699 | |
| 700 | fail_destroy_src: |
| 701 | destroy_test_sglist(&tsgls->src); |
| 702 | fail_kfree: |
| 703 | kfree(tsgls); |
| 704 | return NULL; |
| 705 | } |
| 706 | |
| 707 | static void free_cipher_test_sglists(struct cipher_test_sglists *tsgls) |
| 708 | { |
| 709 | if (tsgls) { |
| 710 | destroy_test_sglist(&tsgls->src); |
| 711 | destroy_test_sglist(&tsgls->dst); |
| 712 | kfree(tsgls); |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | /* Build the src and dst scatterlists for an skcipher or AEAD test */ |
| 717 | static int build_cipher_test_sglists(struct cipher_test_sglists *tsgls, |
| 718 | const struct testvec_config *cfg, |
| 719 | unsigned int alignmask, |
| 720 | unsigned int src_total_len, |
| 721 | unsigned int dst_total_len, |
| 722 | const struct kvec *inputs, |
| 723 | unsigned int nr_inputs) |
| 724 | { |
| 725 | struct iov_iter input; |
| 726 | int err; |
| 727 | |
| 728 | iov_iter_kvec(&input, WRITE, inputs, nr_inputs, src_total_len); |
| 729 | err = build_test_sglist(&tsgls->src, cfg->src_divs, alignmask, |
| 730 | cfg->inplace ? |
| 731 | max(dst_total_len, src_total_len) : |
| 732 | src_total_len, |
| 733 | &input, NULL); |
| 734 | if (err) |
| 735 | return err; |
| 736 | |
| 737 | if (cfg->inplace) { |
| 738 | tsgls->dst.sgl_ptr = tsgls->src.sgl; |
| 739 | tsgls->dst.nents = tsgls->src.nents; |
| 740 | return 0; |
| 741 | } |
| 742 | return build_test_sglist(&tsgls->dst, |
| 743 | cfg->dst_divs[0].proportion_of_total ? |
| 744 | cfg->dst_divs : cfg->src_divs, |
| 745 | alignmask, dst_total_len, NULL, NULL); |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 746 | } |
| 747 | |
Eric Biggers | 25f9ddd | 2019-01-31 23:51:45 -0800 | [diff] [blame] | 748 | #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS |
Eric Biggers | f2bb770a | 2019-04-11 21:57:38 -0700 | [diff] [blame] | 749 | |
| 750 | /* Generate a random length in range [0, max_len], but prefer smaller values */ |
| 751 | static unsigned int generate_random_length(unsigned int max_len) |
| 752 | { |
| 753 | unsigned int len = prandom_u32() % (max_len + 1); |
| 754 | |
| 755 | switch (prandom_u32() % 4) { |
| 756 | case 0: |
| 757 | return len % 64; |
| 758 | case 1: |
| 759 | return len % 256; |
| 760 | case 2: |
| 761 | return len % 1024; |
| 762 | default: |
| 763 | return len; |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | /* Sometimes make some random changes to the given data buffer */ |
| 768 | static void mutate_buffer(u8 *buf, size_t count) |
| 769 | { |
| 770 | size_t num_flips; |
| 771 | size_t i; |
| 772 | size_t pos; |
| 773 | |
| 774 | /* Sometimes flip some bits */ |
| 775 | if (prandom_u32() % 4 == 0) { |
| 776 | num_flips = min_t(size_t, 1 << (prandom_u32() % 8), count * 8); |
| 777 | for (i = 0; i < num_flips; i++) { |
| 778 | pos = prandom_u32() % (count * 8); |
| 779 | buf[pos / 8] ^= 1 << (pos % 8); |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | /* Sometimes flip some bytes */ |
| 784 | if (prandom_u32() % 4 == 0) { |
| 785 | num_flips = min_t(size_t, 1 << (prandom_u32() % 8), count); |
| 786 | for (i = 0; i < num_flips; i++) |
| 787 | buf[prandom_u32() % count] ^= 0xff; |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | /* Randomly generate 'count' bytes, but sometimes make them "interesting" */ |
| 792 | static void generate_random_bytes(u8 *buf, size_t count) |
| 793 | { |
| 794 | u8 b; |
| 795 | u8 increment; |
| 796 | size_t i; |
| 797 | |
| 798 | if (count == 0) |
| 799 | return; |
| 800 | |
| 801 | switch (prandom_u32() % 8) { /* Choose a generation strategy */ |
| 802 | case 0: |
| 803 | case 1: |
| 804 | /* All the same byte, plus optional mutations */ |
| 805 | switch (prandom_u32() % 4) { |
| 806 | case 0: |
| 807 | b = 0x00; |
| 808 | break; |
| 809 | case 1: |
| 810 | b = 0xff; |
| 811 | break; |
| 812 | default: |
| 813 | b = (u8)prandom_u32(); |
| 814 | break; |
| 815 | } |
| 816 | memset(buf, b, count); |
| 817 | mutate_buffer(buf, count); |
| 818 | break; |
| 819 | case 2: |
| 820 | /* Ascending or descending bytes, plus optional mutations */ |
| 821 | increment = (u8)prandom_u32(); |
| 822 | b = (u8)prandom_u32(); |
| 823 | for (i = 0; i < count; i++, b += increment) |
| 824 | buf[i] = b; |
| 825 | mutate_buffer(buf, count); |
| 826 | break; |
| 827 | default: |
| 828 | /* Fully random bytes */ |
| 829 | for (i = 0; i < count; i++) |
| 830 | buf[i] = (u8)prandom_u32(); |
| 831 | } |
| 832 | } |
| 833 | |
Eric Biggers | 25f9ddd | 2019-01-31 23:51:45 -0800 | [diff] [blame] | 834 | static char *generate_random_sgl_divisions(struct test_sg_division *divs, |
| 835 | size_t max_divs, char *p, char *end, |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 836 | bool gen_flushes, u32 req_flags) |
Eric Biggers | 25f9ddd | 2019-01-31 23:51:45 -0800 | [diff] [blame] | 837 | { |
| 838 | struct test_sg_division *div = divs; |
| 839 | unsigned int remaining = TEST_SG_TOTAL; |
| 840 | |
| 841 | do { |
| 842 | unsigned int this_len; |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 843 | const char *flushtype_str; |
Eric Biggers | 25f9ddd | 2019-01-31 23:51:45 -0800 | [diff] [blame] | 844 | |
| 845 | if (div == &divs[max_divs - 1] || prandom_u32() % 2 == 0) |
| 846 | this_len = remaining; |
| 847 | else |
| 848 | this_len = 1 + (prandom_u32() % remaining); |
| 849 | div->proportion_of_total = this_len; |
| 850 | |
| 851 | if (prandom_u32() % 4 == 0) |
| 852 | div->offset = (PAGE_SIZE - 128) + (prandom_u32() % 128); |
| 853 | else if (prandom_u32() % 2 == 0) |
| 854 | div->offset = prandom_u32() % 32; |
| 855 | else |
| 856 | div->offset = prandom_u32() % PAGE_SIZE; |
| 857 | if (prandom_u32() % 8 == 0) |
| 858 | div->offset_relative_to_alignmask = true; |
| 859 | |
| 860 | div->flush_type = FLUSH_TYPE_NONE; |
| 861 | if (gen_flushes) { |
| 862 | switch (prandom_u32() % 4) { |
| 863 | case 0: |
| 864 | div->flush_type = FLUSH_TYPE_REIMPORT; |
| 865 | break; |
| 866 | case 1: |
| 867 | div->flush_type = FLUSH_TYPE_FLUSH; |
| 868 | break; |
| 869 | } |
| 870 | } |
| 871 | |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 872 | if (div->flush_type != FLUSH_TYPE_NONE && |
| 873 | !(req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) && |
| 874 | prandom_u32() % 2 == 0) |
| 875 | div->nosimd = true; |
| 876 | |
| 877 | switch (div->flush_type) { |
| 878 | case FLUSH_TYPE_FLUSH: |
| 879 | if (div->nosimd) |
| 880 | flushtype_str = "<flush,nosimd>"; |
| 881 | else |
| 882 | flushtype_str = "<flush>"; |
| 883 | break; |
| 884 | case FLUSH_TYPE_REIMPORT: |
| 885 | if (div->nosimd) |
| 886 | flushtype_str = "<reimport,nosimd>"; |
| 887 | else |
| 888 | flushtype_str = "<reimport>"; |
| 889 | break; |
| 890 | default: |
| 891 | flushtype_str = ""; |
| 892 | break; |
| 893 | } |
| 894 | |
Eric Biggers | 25f9ddd | 2019-01-31 23:51:45 -0800 | [diff] [blame] | 895 | BUILD_BUG_ON(TEST_SG_TOTAL != 10000); /* for "%u.%u%%" */ |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 896 | p += scnprintf(p, end - p, "%s%u.%u%%@%s+%u%s", flushtype_str, |
Eric Biggers | 25f9ddd | 2019-01-31 23:51:45 -0800 | [diff] [blame] | 897 | this_len / 100, this_len % 100, |
| 898 | div->offset_relative_to_alignmask ? |
| 899 | "alignmask" : "", |
| 900 | div->offset, this_len == remaining ? "" : ", "); |
| 901 | remaining -= this_len; |
| 902 | div++; |
| 903 | } while (remaining); |
| 904 | |
| 905 | return p; |
| 906 | } |
| 907 | |
| 908 | /* Generate a random testvec_config for fuzz testing */ |
| 909 | static void generate_random_testvec_config(struct testvec_config *cfg, |
| 910 | char *name, size_t max_namelen) |
| 911 | { |
| 912 | char *p = name; |
| 913 | char * const end = name + max_namelen; |
| 914 | |
| 915 | memset(cfg, 0, sizeof(*cfg)); |
| 916 | |
| 917 | cfg->name = name; |
| 918 | |
| 919 | p += scnprintf(p, end - p, "random:"); |
| 920 | |
| 921 | if (prandom_u32() % 2 == 0) { |
| 922 | cfg->inplace = true; |
| 923 | p += scnprintf(p, end - p, " inplace"); |
| 924 | } |
| 925 | |
| 926 | if (prandom_u32() % 2 == 0) { |
| 927 | cfg->req_flags |= CRYPTO_TFM_REQ_MAY_SLEEP; |
| 928 | p += scnprintf(p, end - p, " may_sleep"); |
| 929 | } |
| 930 | |
| 931 | switch (prandom_u32() % 4) { |
| 932 | case 0: |
| 933 | cfg->finalization_type = FINALIZATION_TYPE_FINAL; |
| 934 | p += scnprintf(p, end - p, " use_final"); |
| 935 | break; |
| 936 | case 1: |
| 937 | cfg->finalization_type = FINALIZATION_TYPE_FINUP; |
| 938 | p += scnprintf(p, end - p, " use_finup"); |
| 939 | break; |
| 940 | default: |
| 941 | cfg->finalization_type = FINALIZATION_TYPE_DIGEST; |
| 942 | p += scnprintf(p, end - p, " use_digest"); |
| 943 | break; |
| 944 | } |
| 945 | |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 946 | if (!(cfg->req_flags & CRYPTO_TFM_REQ_MAY_SLEEP) && |
| 947 | prandom_u32() % 2 == 0) { |
| 948 | cfg->nosimd = true; |
| 949 | p += scnprintf(p, end - p, " nosimd"); |
| 950 | } |
| 951 | |
Eric Biggers | 25f9ddd | 2019-01-31 23:51:45 -0800 | [diff] [blame] | 952 | p += scnprintf(p, end - p, " src_divs=["); |
| 953 | p = generate_random_sgl_divisions(cfg->src_divs, |
| 954 | ARRAY_SIZE(cfg->src_divs), p, end, |
| 955 | (cfg->finalization_type != |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 956 | FINALIZATION_TYPE_DIGEST), |
| 957 | cfg->req_flags); |
Eric Biggers | 25f9ddd | 2019-01-31 23:51:45 -0800 | [diff] [blame] | 958 | p += scnprintf(p, end - p, "]"); |
| 959 | |
| 960 | if (!cfg->inplace && prandom_u32() % 2 == 0) { |
| 961 | p += scnprintf(p, end - p, " dst_divs=["); |
| 962 | p = generate_random_sgl_divisions(cfg->dst_divs, |
| 963 | ARRAY_SIZE(cfg->dst_divs), |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 964 | p, end, false, |
| 965 | cfg->req_flags); |
Eric Biggers | 25f9ddd | 2019-01-31 23:51:45 -0800 | [diff] [blame] | 966 | p += scnprintf(p, end - p, "]"); |
| 967 | } |
| 968 | |
| 969 | if (prandom_u32() % 2 == 0) { |
| 970 | cfg->iv_offset = 1 + (prandom_u32() % MAX_ALGAPI_ALIGNMASK); |
| 971 | p += scnprintf(p, end - p, " iv_offset=%u", cfg->iv_offset); |
| 972 | } |
| 973 | |
| 974 | WARN_ON_ONCE(!valid_testvec_config(cfg)); |
| 975 | } |
Eric Biggers | b55e1a3 | 2019-03-12 22:12:47 -0700 | [diff] [blame] | 976 | |
| 977 | static void crypto_disable_simd_for_test(void) |
| 978 | { |
| 979 | preempt_disable(); |
| 980 | __this_cpu_write(crypto_simd_disabled_for_test, true); |
| 981 | } |
| 982 | |
| 983 | static void crypto_reenable_simd_for_test(void) |
| 984 | { |
| 985 | __this_cpu_write(crypto_simd_disabled_for_test, false); |
| 986 | preempt_enable(); |
| 987 | } |
Eric Biggers | f2bb770a | 2019-04-11 21:57:38 -0700 | [diff] [blame] | 988 | |
| 989 | /* |
| 990 | * Given an algorithm name, build the name of the generic implementation of that |
| 991 | * algorithm, assuming the usual naming convention. Specifically, this appends |
| 992 | * "-generic" to every part of the name that is not a template name. Examples: |
| 993 | * |
| 994 | * aes => aes-generic |
| 995 | * cbc(aes) => cbc(aes-generic) |
| 996 | * cts(cbc(aes)) => cts(cbc(aes-generic)) |
| 997 | * rfc7539(chacha20,poly1305) => rfc7539(chacha20-generic,poly1305-generic) |
| 998 | * |
| 999 | * Return: 0 on success, or -ENAMETOOLONG if the generic name would be too long |
| 1000 | */ |
| 1001 | static int build_generic_driver_name(const char *algname, |
| 1002 | char driver_name[CRYPTO_MAX_ALG_NAME]) |
| 1003 | { |
| 1004 | const char *in = algname; |
| 1005 | char *out = driver_name; |
| 1006 | size_t len = strlen(algname); |
| 1007 | |
| 1008 | if (len >= CRYPTO_MAX_ALG_NAME) |
| 1009 | goto too_long; |
| 1010 | do { |
| 1011 | const char *in_saved = in; |
| 1012 | |
| 1013 | while (*in && *in != '(' && *in != ')' && *in != ',') |
| 1014 | *out++ = *in++; |
| 1015 | if (*in != '(' && in > in_saved) { |
| 1016 | len += 8; |
| 1017 | if (len >= CRYPTO_MAX_ALG_NAME) |
| 1018 | goto too_long; |
| 1019 | memcpy(out, "-generic", 8); |
| 1020 | out += 8; |
| 1021 | } |
| 1022 | } while ((*out++ = *in++) != '\0'); |
| 1023 | return 0; |
| 1024 | |
| 1025 | too_long: |
| 1026 | pr_err("alg: generic driver name for \"%s\" would be too long\n", |
| 1027 | algname); |
| 1028 | return -ENAMETOOLONG; |
| 1029 | } |
Eric Biggers | b55e1a3 | 2019-03-12 22:12:47 -0700 | [diff] [blame] | 1030 | #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */ |
| 1031 | static void crypto_disable_simd_for_test(void) |
| 1032 | { |
| 1033 | } |
| 1034 | |
| 1035 | static void crypto_reenable_simd_for_test(void) |
| 1036 | { |
| 1037 | } |
| 1038 | #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */ |
Eric Biggers | 25f9ddd | 2019-01-31 23:51:45 -0800 | [diff] [blame] | 1039 | |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 1040 | static int do_ahash_op(int (*op)(struct ahash_request *req), |
| 1041 | struct ahash_request *req, |
| 1042 | struct crypto_wait *wait, bool nosimd) |
| 1043 | { |
| 1044 | int err; |
| 1045 | |
| 1046 | if (nosimd) |
| 1047 | crypto_disable_simd_for_test(); |
| 1048 | |
| 1049 | err = op(req); |
| 1050 | |
| 1051 | if (nosimd) |
| 1052 | crypto_reenable_simd_for_test(); |
| 1053 | |
| 1054 | return crypto_wait_req(err, wait); |
| 1055 | } |
| 1056 | |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1057 | static int check_nonfinal_hash_op(const char *op, int err, |
| 1058 | u8 *result, unsigned int digestsize, |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1059 | const char *driver, const char *vec_name, |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1060 | const struct testvec_config *cfg) |
Kamil Konieczny | 466d7b9 | 2018-01-16 15:26:13 +0100 | [diff] [blame] | 1061 | { |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1062 | if (err) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1063 | pr_err("alg: hash: %s %s() failed with err %d on test vector %s, cfg=\"%s\"\n", |
| 1064 | driver, op, err, vec_name, cfg->name); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1065 | return err; |
| 1066 | } |
| 1067 | if (!testmgr_is_poison(result, digestsize)) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1068 | pr_err("alg: hash: %s %s() used result buffer on test vector %s, cfg=\"%s\"\n", |
| 1069 | driver, op, vec_name, cfg->name); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1070 | return -EINVAL; |
| 1071 | } |
| 1072 | return 0; |
| 1073 | } |
Kamil Konieczny | 466d7b9 | 2018-01-16 15:26:13 +0100 | [diff] [blame] | 1074 | |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1075 | static int test_hash_vec_cfg(const char *driver, |
| 1076 | const struct hash_testvec *vec, |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1077 | const char *vec_name, |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1078 | const struct testvec_config *cfg, |
| 1079 | struct ahash_request *req, |
| 1080 | struct test_sglist *tsgl, |
| 1081 | u8 *hashstate) |
| 1082 | { |
| 1083 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); |
| 1084 | const unsigned int alignmask = crypto_ahash_alignmask(tfm); |
| 1085 | const unsigned int digestsize = crypto_ahash_digestsize(tfm); |
| 1086 | const unsigned int statesize = crypto_ahash_statesize(tfm); |
| 1087 | const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags; |
| 1088 | const struct test_sg_division *divs[XBUFSIZE]; |
| 1089 | DECLARE_CRYPTO_WAIT(wait); |
| 1090 | struct kvec _input; |
| 1091 | struct iov_iter input; |
| 1092 | unsigned int i; |
| 1093 | struct scatterlist *pending_sgl; |
| 1094 | unsigned int pending_len; |
| 1095 | u8 result[HASH_MAX_DIGESTSIZE + TESTMGR_POISON_LEN]; |
| 1096 | int err; |
| 1097 | |
| 1098 | /* Set the key, if specified */ |
| 1099 | if (vec->ksize) { |
| 1100 | err = crypto_ahash_setkey(tfm, vec->key, vec->ksize); |
| 1101 | if (err) { |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1102 | if (err == vec->setkey_error) |
| 1103 | return 0; |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1104 | pr_err("alg: hash: %s setkey failed on test vector %s; expected_error=%d, actual_error=%d, flags=%#x\n", |
| 1105 | driver, vec_name, vec->setkey_error, err, |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1106 | crypto_ahash_get_flags(tfm)); |
| 1107 | return err; |
| 1108 | } |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1109 | if (vec->setkey_error) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1110 | pr_err("alg: hash: %s setkey unexpectedly succeeded on test vector %s; expected_error=%d\n", |
| 1111 | driver, vec_name, vec->setkey_error); |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1112 | return -EINVAL; |
| 1113 | } |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | /* Build the scatterlist for the source data */ |
| 1117 | _input.iov_base = (void *)vec->plaintext; |
| 1118 | _input.iov_len = vec->psize; |
| 1119 | iov_iter_kvec(&input, WRITE, &_input, 1, vec->psize); |
| 1120 | err = build_test_sglist(tsgl, cfg->src_divs, alignmask, vec->psize, |
| 1121 | &input, divs); |
| 1122 | if (err) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1123 | pr_err("alg: hash: %s: error preparing scatterlist for test vector %s, cfg=\"%s\"\n", |
| 1124 | driver, vec_name, cfg->name); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1125 | return err; |
| 1126 | } |
| 1127 | |
| 1128 | /* Do the actual hashing */ |
| 1129 | |
| 1130 | testmgr_poison(req->__ctx, crypto_ahash_reqsize(tfm)); |
| 1131 | testmgr_poison(result, digestsize + TESTMGR_POISON_LEN); |
| 1132 | |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1133 | if (cfg->finalization_type == FINALIZATION_TYPE_DIGEST || |
| 1134 | vec->digest_error) { |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1135 | /* Just using digest() */ |
| 1136 | ahash_request_set_callback(req, req_flags, crypto_req_done, |
| 1137 | &wait); |
| 1138 | ahash_request_set_crypt(req, tsgl->sgl, result, vec->psize); |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 1139 | err = do_ahash_op(crypto_ahash_digest, req, &wait, cfg->nosimd); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1140 | if (err) { |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1141 | if (err == vec->digest_error) |
| 1142 | return 0; |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1143 | pr_err("alg: hash: %s digest() failed on test vector %s; expected_error=%d, actual_error=%d, cfg=\"%s\"\n", |
| 1144 | driver, vec_name, vec->digest_error, err, |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1145 | cfg->name); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1146 | return err; |
| 1147 | } |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1148 | if (vec->digest_error) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1149 | pr_err("alg: hash: %s digest() unexpectedly succeeded on test vector %s; expected_error=%d, cfg=\"%s\"\n", |
| 1150 | driver, vec_name, vec->digest_error, cfg->name); |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1151 | return -EINVAL; |
| 1152 | } |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1153 | goto result_ready; |
| 1154 | } |
| 1155 | |
| 1156 | /* Using init(), zero or more update(), then final() or finup() */ |
| 1157 | |
| 1158 | ahash_request_set_callback(req, req_flags, crypto_req_done, &wait); |
| 1159 | ahash_request_set_crypt(req, NULL, result, 0); |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 1160 | err = do_ahash_op(crypto_ahash_init, req, &wait, cfg->nosimd); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1161 | err = check_nonfinal_hash_op("init", err, result, digestsize, |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1162 | driver, vec_name, cfg); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1163 | if (err) |
| 1164 | return err; |
| 1165 | |
| 1166 | pending_sgl = NULL; |
| 1167 | pending_len = 0; |
| 1168 | for (i = 0; i < tsgl->nents; i++) { |
| 1169 | if (divs[i]->flush_type != FLUSH_TYPE_NONE && |
| 1170 | pending_sgl != NULL) { |
| 1171 | /* update() with the pending data */ |
| 1172 | ahash_request_set_callback(req, req_flags, |
| 1173 | crypto_req_done, &wait); |
| 1174 | ahash_request_set_crypt(req, pending_sgl, result, |
| 1175 | pending_len); |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 1176 | err = do_ahash_op(crypto_ahash_update, req, &wait, |
| 1177 | divs[i]->nosimd); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1178 | err = check_nonfinal_hash_op("update", err, |
| 1179 | result, digestsize, |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1180 | driver, vec_name, cfg); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1181 | if (err) |
| 1182 | return err; |
| 1183 | pending_sgl = NULL; |
| 1184 | pending_len = 0; |
| 1185 | } |
| 1186 | if (divs[i]->flush_type == FLUSH_TYPE_REIMPORT) { |
| 1187 | /* Test ->export() and ->import() */ |
| 1188 | testmgr_poison(hashstate + statesize, |
| 1189 | TESTMGR_POISON_LEN); |
| 1190 | err = crypto_ahash_export(req, hashstate); |
| 1191 | err = check_nonfinal_hash_op("export", err, |
| 1192 | result, digestsize, |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1193 | driver, vec_name, cfg); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1194 | if (err) |
| 1195 | return err; |
| 1196 | if (!testmgr_is_poison(hashstate + statesize, |
| 1197 | TESTMGR_POISON_LEN)) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1198 | pr_err("alg: hash: %s export() overran state buffer on test vector %s, cfg=\"%s\"\n", |
| 1199 | driver, vec_name, cfg->name); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1200 | return -EOVERFLOW; |
| 1201 | } |
| 1202 | |
| 1203 | testmgr_poison(req->__ctx, crypto_ahash_reqsize(tfm)); |
| 1204 | err = crypto_ahash_import(req, hashstate); |
| 1205 | err = check_nonfinal_hash_op("import", err, |
| 1206 | result, digestsize, |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1207 | driver, vec_name, cfg); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1208 | if (err) |
| 1209 | return err; |
| 1210 | } |
| 1211 | if (pending_sgl == NULL) |
| 1212 | pending_sgl = &tsgl->sgl[i]; |
| 1213 | pending_len += tsgl->sgl[i].length; |
| 1214 | } |
| 1215 | |
| 1216 | ahash_request_set_callback(req, req_flags, crypto_req_done, &wait); |
| 1217 | ahash_request_set_crypt(req, pending_sgl, result, pending_len); |
| 1218 | if (cfg->finalization_type == FINALIZATION_TYPE_FINAL) { |
| 1219 | /* finish with update() and final() */ |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 1220 | err = do_ahash_op(crypto_ahash_update, req, &wait, cfg->nosimd); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1221 | err = check_nonfinal_hash_op("update", err, result, digestsize, |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1222 | driver, vec_name, cfg); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1223 | if (err) |
| 1224 | return err; |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 1225 | err = do_ahash_op(crypto_ahash_final, req, &wait, cfg->nosimd); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1226 | if (err) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1227 | pr_err("alg: hash: %s final() failed with err %d on test vector %s, cfg=\"%s\"\n", |
| 1228 | driver, err, vec_name, cfg->name); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1229 | return err; |
| 1230 | } |
| 1231 | } else { |
| 1232 | /* finish with finup() */ |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 1233 | err = do_ahash_op(crypto_ahash_finup, req, &wait, cfg->nosimd); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1234 | if (err) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1235 | pr_err("alg: hash: %s finup() failed with err %d on test vector %s, cfg=\"%s\"\n", |
| 1236 | driver, err, vec_name, cfg->name); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1237 | return err; |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | result_ready: |
| 1242 | /* Check that the algorithm produced the correct digest */ |
| 1243 | if (memcmp(result, vec->digest, digestsize) != 0) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1244 | pr_err("alg: hash: %s test failed (wrong result) on test vector %s, cfg=\"%s\"\n", |
| 1245 | driver, vec_name, cfg->name); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1246 | return -EINVAL; |
| 1247 | } |
| 1248 | if (!testmgr_is_poison(&result[digestsize], TESTMGR_POISON_LEN)) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1249 | pr_err("alg: hash: %s overran result buffer on test vector %s, cfg=\"%s\"\n", |
| 1250 | driver, vec_name, cfg->name); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1251 | return -EOVERFLOW; |
| 1252 | } |
| 1253 | |
| 1254 | return 0; |
| 1255 | } |
| 1256 | |
| 1257 | static int test_hash_vec(const char *driver, const struct hash_testvec *vec, |
| 1258 | unsigned int vec_num, struct ahash_request *req, |
| 1259 | struct test_sglist *tsgl, u8 *hashstate) |
| 1260 | { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1261 | char vec_name[16]; |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1262 | unsigned int i; |
| 1263 | int err; |
| 1264 | |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1265 | sprintf(vec_name, "%u", vec_num); |
| 1266 | |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1267 | for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1268 | err = test_hash_vec_cfg(driver, vec, vec_name, |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1269 | &default_hash_testvec_configs[i], |
| 1270 | req, tsgl, hashstate); |
| 1271 | if (err) |
| 1272 | return err; |
| 1273 | } |
| 1274 | |
| 1275 | #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS |
| 1276 | if (!noextratests) { |
| 1277 | struct testvec_config cfg; |
| 1278 | char cfgname[TESTVEC_CONFIG_NAMELEN]; |
| 1279 | |
| 1280 | for (i = 0; i < fuzz_iterations; i++) { |
| 1281 | generate_random_testvec_config(&cfg, cfgname, |
| 1282 | sizeof(cfgname)); |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1283 | err = test_hash_vec_cfg(driver, vec, vec_name, &cfg, |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1284 | req, tsgl, hashstate); |
| 1285 | if (err) |
| 1286 | return err; |
| 1287 | } |
| 1288 | } |
| 1289 | #endif |
| 1290 | return 0; |
| 1291 | } |
| 1292 | |
Eric Biggers | 9a8a6b3 | 2019-04-11 21:57:39 -0700 | [diff] [blame] | 1293 | #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS |
| 1294 | /* |
| 1295 | * Generate a hash test vector from the given implementation. |
| 1296 | * Assumes the buffers in 'vec' were already allocated. |
| 1297 | */ |
| 1298 | static void generate_random_hash_testvec(struct crypto_shash *tfm, |
| 1299 | struct hash_testvec *vec, |
| 1300 | unsigned int maxkeysize, |
| 1301 | unsigned int maxdatasize, |
| 1302 | char *name, size_t max_namelen) |
| 1303 | { |
| 1304 | SHASH_DESC_ON_STACK(desc, tfm); |
| 1305 | |
| 1306 | /* Data */ |
| 1307 | vec->psize = generate_random_length(maxdatasize); |
| 1308 | generate_random_bytes((u8 *)vec->plaintext, vec->psize); |
| 1309 | |
| 1310 | /* |
| 1311 | * Key: length in range [1, maxkeysize], but usually choose maxkeysize. |
| 1312 | * If algorithm is unkeyed, then maxkeysize == 0 and set ksize = 0. |
| 1313 | */ |
| 1314 | vec->setkey_error = 0; |
| 1315 | vec->ksize = 0; |
| 1316 | if (maxkeysize) { |
| 1317 | vec->ksize = maxkeysize; |
| 1318 | if (prandom_u32() % 4 == 0) |
| 1319 | vec->ksize = 1 + (prandom_u32() % maxkeysize); |
| 1320 | generate_random_bytes((u8 *)vec->key, vec->ksize); |
| 1321 | |
| 1322 | vec->setkey_error = crypto_shash_setkey(tfm, vec->key, |
| 1323 | vec->ksize); |
| 1324 | /* If the key couldn't be set, no need to continue to digest. */ |
| 1325 | if (vec->setkey_error) |
| 1326 | goto done; |
| 1327 | } |
| 1328 | |
| 1329 | /* Digest */ |
| 1330 | desc->tfm = tfm; |
| 1331 | desc->flags = 0; |
| 1332 | vec->digest_error = crypto_shash_digest(desc, vec->plaintext, |
| 1333 | vec->psize, (u8 *)vec->digest); |
| 1334 | done: |
| 1335 | snprintf(name, max_namelen, "\"random: psize=%u ksize=%u\"", |
| 1336 | vec->psize, vec->ksize); |
| 1337 | } |
| 1338 | |
| 1339 | /* |
| 1340 | * Test the hash algorithm represented by @req against the corresponding generic |
| 1341 | * implementation, if one is available. |
| 1342 | */ |
| 1343 | static int test_hash_vs_generic_impl(const char *driver, |
| 1344 | const char *generic_driver, |
| 1345 | unsigned int maxkeysize, |
| 1346 | struct ahash_request *req, |
| 1347 | struct test_sglist *tsgl, |
| 1348 | u8 *hashstate) |
| 1349 | { |
| 1350 | struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); |
| 1351 | const unsigned int digestsize = crypto_ahash_digestsize(tfm); |
| 1352 | const unsigned int blocksize = crypto_ahash_blocksize(tfm); |
| 1353 | const unsigned int maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN; |
| 1354 | const char *algname = crypto_hash_alg_common(tfm)->base.cra_name; |
| 1355 | char _generic_driver[CRYPTO_MAX_ALG_NAME]; |
| 1356 | struct crypto_shash *generic_tfm = NULL; |
| 1357 | unsigned int i; |
| 1358 | struct hash_testvec vec = { 0 }; |
| 1359 | char vec_name[64]; |
| 1360 | struct testvec_config cfg; |
| 1361 | char cfgname[TESTVEC_CONFIG_NAMELEN]; |
| 1362 | int err; |
| 1363 | |
| 1364 | if (noextratests) |
| 1365 | return 0; |
| 1366 | |
| 1367 | if (!generic_driver) { /* Use default naming convention? */ |
| 1368 | err = build_generic_driver_name(algname, _generic_driver); |
| 1369 | if (err) |
| 1370 | return err; |
| 1371 | generic_driver = _generic_driver; |
| 1372 | } |
| 1373 | |
| 1374 | if (strcmp(generic_driver, driver) == 0) /* Already the generic impl? */ |
| 1375 | return 0; |
| 1376 | |
| 1377 | generic_tfm = crypto_alloc_shash(generic_driver, 0, 0); |
| 1378 | if (IS_ERR(generic_tfm)) { |
| 1379 | err = PTR_ERR(generic_tfm); |
| 1380 | if (err == -ENOENT) { |
| 1381 | pr_warn("alg: hash: skipping comparison tests for %s because %s is unavailable\n", |
| 1382 | driver, generic_driver); |
| 1383 | return 0; |
| 1384 | } |
| 1385 | pr_err("alg: hash: error allocating %s (generic impl of %s): %d\n", |
| 1386 | generic_driver, algname, err); |
| 1387 | return err; |
| 1388 | } |
| 1389 | |
| 1390 | /* Check the algorithm properties for consistency. */ |
| 1391 | |
| 1392 | if (digestsize != crypto_shash_digestsize(generic_tfm)) { |
| 1393 | pr_err("alg: hash: digestsize for %s (%u) doesn't match generic impl (%u)\n", |
| 1394 | driver, digestsize, |
| 1395 | crypto_shash_digestsize(generic_tfm)); |
| 1396 | err = -EINVAL; |
| 1397 | goto out; |
| 1398 | } |
| 1399 | |
| 1400 | if (blocksize != crypto_shash_blocksize(generic_tfm)) { |
| 1401 | pr_err("alg: hash: blocksize for %s (%u) doesn't match generic impl (%u)\n", |
| 1402 | driver, blocksize, crypto_shash_blocksize(generic_tfm)); |
| 1403 | err = -EINVAL; |
| 1404 | goto out; |
| 1405 | } |
| 1406 | |
| 1407 | /* |
| 1408 | * Now generate test vectors using the generic implementation, and test |
| 1409 | * the other implementation against them. |
| 1410 | */ |
| 1411 | |
| 1412 | vec.key = kmalloc(maxkeysize, GFP_KERNEL); |
| 1413 | vec.plaintext = kmalloc(maxdatasize, GFP_KERNEL); |
| 1414 | vec.digest = kmalloc(digestsize, GFP_KERNEL); |
| 1415 | if (!vec.key || !vec.plaintext || !vec.digest) { |
| 1416 | err = -ENOMEM; |
| 1417 | goto out; |
| 1418 | } |
| 1419 | |
| 1420 | for (i = 0; i < fuzz_iterations * 8; i++) { |
| 1421 | generate_random_hash_testvec(generic_tfm, &vec, |
| 1422 | maxkeysize, maxdatasize, |
| 1423 | vec_name, sizeof(vec_name)); |
| 1424 | generate_random_testvec_config(&cfg, cfgname, sizeof(cfgname)); |
| 1425 | |
| 1426 | err = test_hash_vec_cfg(driver, &vec, vec_name, &cfg, |
| 1427 | req, tsgl, hashstate); |
| 1428 | if (err) |
| 1429 | goto out; |
| 1430 | cond_resched(); |
| 1431 | } |
| 1432 | err = 0; |
| 1433 | out: |
| 1434 | kfree(vec.key); |
| 1435 | kfree(vec.plaintext); |
| 1436 | kfree(vec.digest); |
| 1437 | crypto_free_shash(generic_tfm); |
| 1438 | return err; |
| 1439 | } |
| 1440 | #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */ |
| 1441 | static int test_hash_vs_generic_impl(const char *driver, |
| 1442 | const char *generic_driver, |
| 1443 | unsigned int maxkeysize, |
| 1444 | struct ahash_request *req, |
| 1445 | struct test_sglist *tsgl, |
| 1446 | u8 *hashstate) |
| 1447 | { |
| 1448 | return 0; |
| 1449 | } |
| 1450 | #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */ |
| 1451 | |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1452 | static int __alg_test_hash(const struct hash_testvec *vecs, |
| 1453 | unsigned int num_vecs, const char *driver, |
Eric Biggers | 9a8a6b3 | 2019-04-11 21:57:39 -0700 | [diff] [blame] | 1454 | u32 type, u32 mask, |
| 1455 | const char *generic_driver, unsigned int maxkeysize) |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1456 | { |
| 1457 | struct crypto_ahash *tfm; |
| 1458 | struct ahash_request *req = NULL; |
| 1459 | struct test_sglist *tsgl = NULL; |
| 1460 | u8 *hashstate = NULL; |
| 1461 | unsigned int i; |
| 1462 | int err; |
| 1463 | |
| 1464 | tfm = crypto_alloc_ahash(driver, type, mask); |
| 1465 | if (IS_ERR(tfm)) { |
| 1466 | pr_err("alg: hash: failed to allocate transform for %s: %ld\n", |
| 1467 | driver, PTR_ERR(tfm)); |
| 1468 | return PTR_ERR(tfm); |
| 1469 | } |
| 1470 | |
| 1471 | req = ahash_request_alloc(tfm, GFP_KERNEL); |
| 1472 | if (!req) { |
| 1473 | pr_err("alg: hash: failed to allocate request for %s\n", |
| 1474 | driver); |
| 1475 | err = -ENOMEM; |
| 1476 | goto out; |
| 1477 | } |
| 1478 | |
| 1479 | tsgl = kmalloc(sizeof(*tsgl), GFP_KERNEL); |
| 1480 | if (!tsgl || init_test_sglist(tsgl) != 0) { |
| 1481 | pr_err("alg: hash: failed to allocate test buffers for %s\n", |
| 1482 | driver); |
| 1483 | kfree(tsgl); |
| 1484 | tsgl = NULL; |
| 1485 | err = -ENOMEM; |
| 1486 | goto out; |
| 1487 | } |
| 1488 | |
| 1489 | hashstate = kmalloc(crypto_ahash_statesize(tfm) + TESTMGR_POISON_LEN, |
| 1490 | GFP_KERNEL); |
| 1491 | if (!hashstate) { |
| 1492 | pr_err("alg: hash: failed to allocate hash state buffer for %s\n", |
| 1493 | driver); |
| 1494 | err = -ENOMEM; |
| 1495 | goto out; |
| 1496 | } |
| 1497 | |
| 1498 | for (i = 0; i < num_vecs; i++) { |
| 1499 | err = test_hash_vec(driver, &vecs[i], i, req, tsgl, hashstate); |
| 1500 | if (err) |
| 1501 | goto out; |
| 1502 | } |
Eric Biggers | 9a8a6b3 | 2019-04-11 21:57:39 -0700 | [diff] [blame] | 1503 | err = test_hash_vs_generic_impl(driver, generic_driver, maxkeysize, req, |
| 1504 | tsgl, hashstate); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1505 | out: |
| 1506 | kfree(hashstate); |
| 1507 | if (tsgl) { |
| 1508 | destroy_test_sglist(tsgl); |
| 1509 | kfree(tsgl); |
| 1510 | } |
| 1511 | ahash_request_free(req); |
| 1512 | crypto_free_ahash(tfm); |
| 1513 | return err; |
| 1514 | } |
| 1515 | |
| 1516 | static int alg_test_hash(const struct alg_test_desc *desc, const char *driver, |
| 1517 | u32 type, u32 mask) |
| 1518 | { |
| 1519 | const struct hash_testvec *template = desc->suite.hash.vecs; |
| 1520 | unsigned int tcount = desc->suite.hash.count; |
| 1521 | unsigned int nr_unkeyed, nr_keyed; |
Eric Biggers | 9a8a6b3 | 2019-04-11 21:57:39 -0700 | [diff] [blame] | 1522 | unsigned int maxkeysize = 0; |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1523 | int err; |
| 1524 | |
| 1525 | /* |
| 1526 | * For OPTIONAL_KEY algorithms, we have to do all the unkeyed tests |
| 1527 | * first, before setting a key on the tfm. To make this easier, we |
| 1528 | * require that the unkeyed test vectors (if any) are listed first. |
| 1529 | */ |
| 1530 | |
| 1531 | for (nr_unkeyed = 0; nr_unkeyed < tcount; nr_unkeyed++) { |
| 1532 | if (template[nr_unkeyed].ksize) |
| 1533 | break; |
| 1534 | } |
| 1535 | for (nr_keyed = 0; nr_unkeyed + nr_keyed < tcount; nr_keyed++) { |
| 1536 | if (!template[nr_unkeyed + nr_keyed].ksize) { |
| 1537 | pr_err("alg: hash: test vectors for %s out of order, " |
| 1538 | "unkeyed ones must come first\n", desc->alg); |
Kamil Konieczny | 466d7b9 | 2018-01-16 15:26:13 +0100 | [diff] [blame] | 1539 | return -EINVAL; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1540 | } |
Eric Biggers | 9a8a6b3 | 2019-04-11 21:57:39 -0700 | [diff] [blame] | 1541 | maxkeysize = max_t(unsigned int, maxkeysize, |
| 1542 | template[nr_unkeyed + nr_keyed].ksize); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1543 | } |
| 1544 | |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1545 | err = 0; |
| 1546 | if (nr_unkeyed) { |
Eric Biggers | 9a8a6b3 | 2019-04-11 21:57:39 -0700 | [diff] [blame] | 1547 | err = __alg_test_hash(template, nr_unkeyed, driver, type, mask, |
| 1548 | desc->generic_driver, maxkeysize); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1549 | template += nr_unkeyed; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1550 | } |
| 1551 | |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1552 | if (!err && nr_keyed) |
Eric Biggers | 9a8a6b3 | 2019-04-11 21:57:39 -0700 | [diff] [blame] | 1553 | err = __alg_test_hash(template, nr_keyed, driver, type, mask, |
| 1554 | desc->generic_driver, maxkeysize); |
Wang, Rui Y | 018ba95 | 2016-02-03 18:26:57 +0800 | [diff] [blame] | 1555 | |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 1556 | return err; |
Jussi Kivilinna | da5ffe1 | 2013-06-13 17:37:55 +0300 | [diff] [blame] | 1557 | } |
| 1558 | |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1559 | static int test_aead_vec_cfg(const char *driver, int enc, |
| 1560 | const struct aead_testvec *vec, |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1561 | const char *vec_name, |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1562 | const struct testvec_config *cfg, |
| 1563 | struct aead_request *req, |
| 1564 | struct cipher_test_sglists *tsgls) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1565 | { |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1566 | struct crypto_aead *tfm = crypto_aead_reqtfm(req); |
| 1567 | const unsigned int alignmask = crypto_aead_alignmask(tfm); |
| 1568 | const unsigned int ivsize = crypto_aead_ivsize(tfm); |
| 1569 | const unsigned int authsize = vec->clen - vec->plen; |
| 1570 | const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags; |
| 1571 | const char *op = enc ? "encryption" : "decryption"; |
| 1572 | DECLARE_CRYPTO_WAIT(wait); |
| 1573 | u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN]; |
| 1574 | u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) + |
| 1575 | cfg->iv_offset + |
| 1576 | (cfg->iv_offset_relative_to_alignmask ? alignmask : 0); |
| 1577 | struct kvec input[2]; |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1578 | int expected_error; |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1579 | int err; |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 1580 | |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1581 | /* Set the key */ |
| 1582 | if (vec->wk) |
| 1583 | crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS); |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 1584 | else |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1585 | crypto_aead_clear_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS); |
| 1586 | err = crypto_aead_setkey(tfm, vec->key, vec->klen); |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1587 | if (err && err != vec->setkey_error) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1588 | pr_err("alg: aead: %s setkey failed on test vector %s; expected_error=%d, actual_error=%d, flags=%#x\n", |
| 1589 | driver, vec_name, vec->setkey_error, err, |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1590 | crypto_aead_get_flags(tfm)); |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1591 | return err; |
| 1592 | } |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1593 | if (!err && vec->setkey_error) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1594 | pr_err("alg: aead: %s setkey unexpectedly succeeded on test vector %s; expected_error=%d\n", |
| 1595 | driver, vec_name, vec->setkey_error); |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1596 | return -EINVAL; |
| 1597 | } |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 1598 | |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1599 | /* Set the authentication tag size */ |
| 1600 | err = crypto_aead_setauthsize(tfm, authsize); |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1601 | if (err && err != vec->setauthsize_error) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1602 | pr_err("alg: aead: %s setauthsize failed on test vector %s; expected_error=%d, actual_error=%d\n", |
| 1603 | driver, vec_name, vec->setauthsize_error, err); |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1604 | return err; |
| 1605 | } |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1606 | if (!err && vec->setauthsize_error) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1607 | pr_err("alg: aead: %s setauthsize unexpectedly succeeded on test vector %s; expected_error=%d\n", |
| 1608 | driver, vec_name, vec->setauthsize_error); |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1609 | return -EINVAL; |
| 1610 | } |
| 1611 | |
| 1612 | if (vec->setkey_error || vec->setauthsize_error) |
| 1613 | return 0; |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1614 | |
| 1615 | /* The IV must be copied to a buffer, as the algorithm may modify it */ |
| 1616 | if (WARN_ON(ivsize > MAX_IVLEN)) |
| 1617 | return -EINVAL; |
| 1618 | if (vec->iv) |
| 1619 | memcpy(iv, vec->iv, ivsize); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1620 | else |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1621 | memset(iv, 0, ivsize); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1622 | |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1623 | /* Build the src/dst scatterlists */ |
| 1624 | input[0].iov_base = (void *)vec->assoc; |
| 1625 | input[0].iov_len = vec->alen; |
| 1626 | input[1].iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext; |
| 1627 | input[1].iov_len = enc ? vec->plen : vec->clen; |
| 1628 | err = build_cipher_test_sglists(tsgls, cfg, alignmask, |
| 1629 | vec->alen + (enc ? vec->plen : |
| 1630 | vec->clen), |
| 1631 | vec->alen + (enc ? vec->clen : |
| 1632 | vec->plen), |
| 1633 | input, 2); |
| 1634 | if (err) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1635 | pr_err("alg: aead: %s %s: error preparing scatterlists for test vector %s, cfg=\"%s\"\n", |
| 1636 | driver, op, vec_name, cfg->name); |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1637 | return err; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1638 | } |
| 1639 | |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1640 | /* Do the actual encryption or decryption */ |
| 1641 | testmgr_poison(req->__ctx, crypto_aead_reqsize(tfm)); |
| 1642 | aead_request_set_callback(req, req_flags, crypto_req_done, &wait); |
| 1643 | aead_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr, |
| 1644 | enc ? vec->plen : vec->clen, iv); |
| 1645 | aead_request_set_ad(req, vec->alen); |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 1646 | if (cfg->nosimd) |
| 1647 | crypto_disable_simd_for_test(); |
| 1648 | err = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req); |
| 1649 | if (cfg->nosimd) |
| 1650 | crypto_reenable_simd_for_test(); |
| 1651 | err = crypto_wait_req(err, &wait); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1652 | |
Eric Biggers | a6e5ef9 | 2019-01-31 23:51:50 -0800 | [diff] [blame] | 1653 | /* Check that the algorithm didn't overwrite things it shouldn't have */ |
| 1654 | if (req->cryptlen != (enc ? vec->plen : vec->clen) || |
| 1655 | req->assoclen != vec->alen || |
| 1656 | req->iv != iv || |
| 1657 | req->src != tsgls->src.sgl_ptr || |
| 1658 | req->dst != tsgls->dst.sgl_ptr || |
| 1659 | crypto_aead_reqtfm(req) != tfm || |
| 1660 | req->base.complete != crypto_req_done || |
| 1661 | req->base.flags != req_flags || |
| 1662 | req->base.data != &wait) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1663 | pr_err("alg: aead: %s %s corrupted request struct on test vector %s, cfg=\"%s\"\n", |
| 1664 | driver, op, vec_name, cfg->name); |
Eric Biggers | a6e5ef9 | 2019-01-31 23:51:50 -0800 | [diff] [blame] | 1665 | if (req->cryptlen != (enc ? vec->plen : vec->clen)) |
| 1666 | pr_err("alg: aead: changed 'req->cryptlen'\n"); |
| 1667 | if (req->assoclen != vec->alen) |
| 1668 | pr_err("alg: aead: changed 'req->assoclen'\n"); |
| 1669 | if (req->iv != iv) |
| 1670 | pr_err("alg: aead: changed 'req->iv'\n"); |
| 1671 | if (req->src != tsgls->src.sgl_ptr) |
| 1672 | pr_err("alg: aead: changed 'req->src'\n"); |
| 1673 | if (req->dst != tsgls->dst.sgl_ptr) |
| 1674 | pr_err("alg: aead: changed 'req->dst'\n"); |
| 1675 | if (crypto_aead_reqtfm(req) != tfm) |
| 1676 | pr_err("alg: aead: changed 'req->base.tfm'\n"); |
| 1677 | if (req->base.complete != crypto_req_done) |
| 1678 | pr_err("alg: aead: changed 'req->base.complete'\n"); |
| 1679 | if (req->base.flags != req_flags) |
| 1680 | pr_err("alg: aead: changed 'req->base.flags'\n"); |
| 1681 | if (req->base.data != &wait) |
| 1682 | pr_err("alg: aead: changed 'req->base.data'\n"); |
| 1683 | return -EINVAL; |
| 1684 | } |
| 1685 | if (is_test_sglist_corrupted(&tsgls->src)) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1686 | pr_err("alg: aead: %s %s corrupted src sgl on test vector %s, cfg=\"%s\"\n", |
| 1687 | driver, op, vec_name, cfg->name); |
Eric Biggers | a6e5ef9 | 2019-01-31 23:51:50 -0800 | [diff] [blame] | 1688 | return -EINVAL; |
| 1689 | } |
| 1690 | if (tsgls->dst.sgl_ptr != tsgls->src.sgl && |
| 1691 | is_test_sglist_corrupted(&tsgls->dst)) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1692 | pr_err("alg: aead: %s %s corrupted dst sgl on test vector %s, cfg=\"%s\"\n", |
| 1693 | driver, op, vec_name, cfg->name); |
Eric Biggers | a6e5ef9 | 2019-01-31 23:51:50 -0800 | [diff] [blame] | 1694 | return -EINVAL; |
| 1695 | } |
| 1696 | |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1697 | /* Check for success or failure */ |
| 1698 | expected_error = vec->novrfy ? -EBADMSG : vec->crypt_error; |
| 1699 | if (err) { |
| 1700 | if (err == expected_error) |
| 1701 | return 0; |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1702 | pr_err("alg: aead: %s %s failed on test vector %s; expected_error=%d, actual_error=%d, cfg=\"%s\"\n", |
| 1703 | driver, op, vec_name, expected_error, err, cfg->name); |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1704 | return err; |
| 1705 | } |
| 1706 | if (expected_error) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1707 | pr_err("alg: aead: %s %s unexpectedly succeeded on test vector %s; expected_error=%d, cfg=\"%s\"\n", |
| 1708 | driver, op, vec_name, expected_error, cfg->name); |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 1709 | return -EINVAL; |
| 1710 | } |
| 1711 | |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1712 | /* Check for the correct output (ciphertext or plaintext) */ |
| 1713 | err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext, |
| 1714 | enc ? vec->clen : vec->plen, |
| 1715 | vec->alen, enc || !cfg->inplace); |
| 1716 | if (err == -EOVERFLOW) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1717 | pr_err("alg: aead: %s %s overran dst buffer on test vector %s, cfg=\"%s\"\n", |
| 1718 | driver, op, vec_name, cfg->name); |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1719 | return err; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1720 | } |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1721 | if (err) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1722 | pr_err("alg: aead: %s %s test failed (wrong result) on test vector %s, cfg=\"%s\"\n", |
| 1723 | driver, op, vec_name, cfg->name); |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1724 | return err; |
Jussi Kivilinna | 58dcf54 | 2013-06-13 17:37:50 +0300 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | return 0; |
Jussi Kivilinna | d8a32ac | 2012-09-21 10:26:52 +0300 | [diff] [blame] | 1728 | } |
| 1729 | |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1730 | static int test_aead_vec(const char *driver, int enc, |
| 1731 | const struct aead_testvec *vec, unsigned int vec_num, |
| 1732 | struct aead_request *req, |
| 1733 | struct cipher_test_sglists *tsgls) |
| 1734 | { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1735 | char vec_name[16]; |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1736 | unsigned int i; |
| 1737 | int err; |
| 1738 | |
| 1739 | if (enc && vec->novrfy) |
| 1740 | return 0; |
| 1741 | |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1742 | sprintf(vec_name, "%u", vec_num); |
| 1743 | |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1744 | for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1745 | err = test_aead_vec_cfg(driver, enc, vec, vec_name, |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1746 | &default_cipher_testvec_configs[i], |
| 1747 | req, tsgls); |
| 1748 | if (err) |
| 1749 | return err; |
| 1750 | } |
| 1751 | |
| 1752 | #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS |
| 1753 | if (!noextratests) { |
| 1754 | struct testvec_config cfg; |
| 1755 | char cfgname[TESTVEC_CONFIG_NAMELEN]; |
| 1756 | |
| 1757 | for (i = 0; i < fuzz_iterations; i++) { |
| 1758 | generate_random_testvec_config(&cfg, cfgname, |
| 1759 | sizeof(cfgname)); |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 1760 | err = test_aead_vec_cfg(driver, enc, vec, vec_name, |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1761 | &cfg, req, tsgls); |
| 1762 | if (err) |
| 1763 | return err; |
| 1764 | } |
| 1765 | } |
| 1766 | #endif |
| 1767 | return 0; |
| 1768 | } |
| 1769 | |
Eric Biggers | 40153b1 | 2019-04-11 21:57:41 -0700 | [diff] [blame^] | 1770 | #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS |
| 1771 | /* |
| 1772 | * Generate an AEAD test vector from the given implementation. |
| 1773 | * Assumes the buffers in 'vec' were already allocated. |
| 1774 | */ |
| 1775 | static void generate_random_aead_testvec(struct aead_request *req, |
| 1776 | struct aead_testvec *vec, |
| 1777 | unsigned int maxkeysize, |
| 1778 | unsigned int maxdatasize, |
| 1779 | char *name, size_t max_namelen) |
| 1780 | { |
| 1781 | struct crypto_aead *tfm = crypto_aead_reqtfm(req); |
| 1782 | const unsigned int ivsize = crypto_aead_ivsize(tfm); |
| 1783 | unsigned int maxauthsize = crypto_aead_alg(tfm)->maxauthsize; |
| 1784 | unsigned int authsize; |
| 1785 | unsigned int total_len; |
| 1786 | int i; |
| 1787 | struct scatterlist src[2], dst; |
| 1788 | u8 iv[MAX_IVLEN]; |
| 1789 | DECLARE_CRYPTO_WAIT(wait); |
| 1790 | |
| 1791 | /* Key: length in [0, maxkeysize], but usually choose maxkeysize */ |
| 1792 | vec->klen = maxkeysize; |
| 1793 | if (prandom_u32() % 4 == 0) |
| 1794 | vec->klen = prandom_u32() % (maxkeysize + 1); |
| 1795 | generate_random_bytes((u8 *)vec->key, vec->klen); |
| 1796 | vec->setkey_error = crypto_aead_setkey(tfm, vec->key, vec->klen); |
| 1797 | |
| 1798 | /* IV */ |
| 1799 | generate_random_bytes((u8 *)vec->iv, ivsize); |
| 1800 | |
| 1801 | /* Tag length: in [0, maxauthsize], but usually choose maxauthsize */ |
| 1802 | authsize = maxauthsize; |
| 1803 | if (prandom_u32() % 4 == 0) |
| 1804 | authsize = prandom_u32() % (maxauthsize + 1); |
| 1805 | if (WARN_ON(authsize > maxdatasize)) |
| 1806 | authsize = maxdatasize; |
| 1807 | maxdatasize -= authsize; |
| 1808 | vec->setauthsize_error = crypto_aead_setauthsize(tfm, authsize); |
| 1809 | |
| 1810 | /* Plaintext and associated data */ |
| 1811 | total_len = generate_random_length(maxdatasize); |
| 1812 | if (prandom_u32() % 4 == 0) |
| 1813 | vec->alen = 0; |
| 1814 | else |
| 1815 | vec->alen = generate_random_length(total_len); |
| 1816 | vec->plen = total_len - vec->alen; |
| 1817 | generate_random_bytes((u8 *)vec->assoc, vec->alen); |
| 1818 | generate_random_bytes((u8 *)vec->ptext, vec->plen); |
| 1819 | |
| 1820 | vec->clen = vec->plen + authsize; |
| 1821 | |
| 1822 | /* |
| 1823 | * If the key or authentication tag size couldn't be set, no need to |
| 1824 | * continue to encrypt. |
| 1825 | */ |
| 1826 | if (vec->setkey_error || vec->setauthsize_error) |
| 1827 | goto done; |
| 1828 | |
| 1829 | /* Ciphertext */ |
| 1830 | sg_init_table(src, 2); |
| 1831 | i = 0; |
| 1832 | if (vec->alen) |
| 1833 | sg_set_buf(&src[i++], vec->assoc, vec->alen); |
| 1834 | if (vec->plen) |
| 1835 | sg_set_buf(&src[i++], vec->ptext, vec->plen); |
| 1836 | sg_init_one(&dst, vec->ctext, vec->alen + vec->clen); |
| 1837 | memcpy(iv, vec->iv, ivsize); |
| 1838 | aead_request_set_callback(req, 0, crypto_req_done, &wait); |
| 1839 | aead_request_set_crypt(req, src, &dst, vec->plen, iv); |
| 1840 | aead_request_set_ad(req, vec->alen); |
| 1841 | vec->crypt_error = crypto_wait_req(crypto_aead_encrypt(req), &wait); |
| 1842 | if (vec->crypt_error == 0) |
| 1843 | memmove((u8 *)vec->ctext, vec->ctext + vec->alen, vec->clen); |
| 1844 | done: |
| 1845 | snprintf(name, max_namelen, |
| 1846 | "\"random: alen=%u plen=%u authsize=%u klen=%u\"", |
| 1847 | vec->alen, vec->plen, authsize, vec->klen); |
| 1848 | } |
| 1849 | |
| 1850 | /* |
| 1851 | * Test the AEAD algorithm represented by @req against the corresponding generic |
| 1852 | * implementation, if one is available. |
| 1853 | */ |
| 1854 | static int test_aead_vs_generic_impl(const char *driver, |
| 1855 | const struct alg_test_desc *test_desc, |
| 1856 | struct aead_request *req, |
| 1857 | struct cipher_test_sglists *tsgls) |
| 1858 | { |
| 1859 | struct crypto_aead *tfm = crypto_aead_reqtfm(req); |
| 1860 | const unsigned int ivsize = crypto_aead_ivsize(tfm); |
| 1861 | const unsigned int maxauthsize = crypto_aead_alg(tfm)->maxauthsize; |
| 1862 | const unsigned int blocksize = crypto_aead_blocksize(tfm); |
| 1863 | const unsigned int maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN; |
| 1864 | const char *algname = crypto_aead_alg(tfm)->base.cra_name; |
| 1865 | const char *generic_driver = test_desc->generic_driver; |
| 1866 | char _generic_driver[CRYPTO_MAX_ALG_NAME]; |
| 1867 | struct crypto_aead *generic_tfm = NULL; |
| 1868 | struct aead_request *generic_req = NULL; |
| 1869 | unsigned int maxkeysize; |
| 1870 | unsigned int i; |
| 1871 | struct aead_testvec vec = { 0 }; |
| 1872 | char vec_name[64]; |
| 1873 | struct testvec_config cfg; |
| 1874 | char cfgname[TESTVEC_CONFIG_NAMELEN]; |
| 1875 | int err; |
| 1876 | |
| 1877 | if (noextratests) |
| 1878 | return 0; |
| 1879 | |
| 1880 | if (!generic_driver) { /* Use default naming convention? */ |
| 1881 | err = build_generic_driver_name(algname, _generic_driver); |
| 1882 | if (err) |
| 1883 | return err; |
| 1884 | generic_driver = _generic_driver; |
| 1885 | } |
| 1886 | |
| 1887 | if (strcmp(generic_driver, driver) == 0) /* Already the generic impl? */ |
| 1888 | return 0; |
| 1889 | |
| 1890 | generic_tfm = crypto_alloc_aead(generic_driver, 0, 0); |
| 1891 | if (IS_ERR(generic_tfm)) { |
| 1892 | err = PTR_ERR(generic_tfm); |
| 1893 | if (err == -ENOENT) { |
| 1894 | pr_warn("alg: aead: skipping comparison tests for %s because %s is unavailable\n", |
| 1895 | driver, generic_driver); |
| 1896 | return 0; |
| 1897 | } |
| 1898 | pr_err("alg: aead: error allocating %s (generic impl of %s): %d\n", |
| 1899 | generic_driver, algname, err); |
| 1900 | return err; |
| 1901 | } |
| 1902 | |
| 1903 | generic_req = aead_request_alloc(generic_tfm, GFP_KERNEL); |
| 1904 | if (!generic_req) { |
| 1905 | err = -ENOMEM; |
| 1906 | goto out; |
| 1907 | } |
| 1908 | |
| 1909 | /* Check the algorithm properties for consistency. */ |
| 1910 | |
| 1911 | if (maxauthsize != crypto_aead_alg(generic_tfm)->maxauthsize) { |
| 1912 | pr_err("alg: aead: maxauthsize for %s (%u) doesn't match generic impl (%u)\n", |
| 1913 | driver, maxauthsize, |
| 1914 | crypto_aead_alg(generic_tfm)->maxauthsize); |
| 1915 | err = -EINVAL; |
| 1916 | goto out; |
| 1917 | } |
| 1918 | |
| 1919 | if (ivsize != crypto_aead_ivsize(generic_tfm)) { |
| 1920 | pr_err("alg: aead: ivsize for %s (%u) doesn't match generic impl (%u)\n", |
| 1921 | driver, ivsize, crypto_aead_ivsize(generic_tfm)); |
| 1922 | err = -EINVAL; |
| 1923 | goto out; |
| 1924 | } |
| 1925 | |
| 1926 | if (blocksize != crypto_aead_blocksize(generic_tfm)) { |
| 1927 | pr_err("alg: aead: blocksize for %s (%u) doesn't match generic impl (%u)\n", |
| 1928 | driver, blocksize, crypto_aead_blocksize(generic_tfm)); |
| 1929 | err = -EINVAL; |
| 1930 | goto out; |
| 1931 | } |
| 1932 | |
| 1933 | /* |
| 1934 | * Now generate test vectors using the generic implementation, and test |
| 1935 | * the other implementation against them. |
| 1936 | */ |
| 1937 | |
| 1938 | maxkeysize = 0; |
| 1939 | for (i = 0; i < test_desc->suite.aead.count; i++) |
| 1940 | maxkeysize = max_t(unsigned int, maxkeysize, |
| 1941 | test_desc->suite.aead.vecs[i].klen); |
| 1942 | |
| 1943 | vec.key = kmalloc(maxkeysize, GFP_KERNEL); |
| 1944 | vec.iv = kmalloc(ivsize, GFP_KERNEL); |
| 1945 | vec.assoc = kmalloc(maxdatasize, GFP_KERNEL); |
| 1946 | vec.ptext = kmalloc(maxdatasize, GFP_KERNEL); |
| 1947 | vec.ctext = kmalloc(maxdatasize, GFP_KERNEL); |
| 1948 | if (!vec.key || !vec.iv || !vec.assoc || !vec.ptext || !vec.ctext) { |
| 1949 | err = -ENOMEM; |
| 1950 | goto out; |
| 1951 | } |
| 1952 | |
| 1953 | for (i = 0; i < fuzz_iterations * 8; i++) { |
| 1954 | generate_random_aead_testvec(generic_req, &vec, |
| 1955 | maxkeysize, maxdatasize, |
| 1956 | vec_name, sizeof(vec_name)); |
| 1957 | generate_random_testvec_config(&cfg, cfgname, sizeof(cfgname)); |
| 1958 | |
| 1959 | err = test_aead_vec_cfg(driver, ENCRYPT, &vec, vec_name, &cfg, |
| 1960 | req, tsgls); |
| 1961 | if (err) |
| 1962 | goto out; |
| 1963 | err = test_aead_vec_cfg(driver, DECRYPT, &vec, vec_name, &cfg, |
| 1964 | req, tsgls); |
| 1965 | if (err) |
| 1966 | goto out; |
| 1967 | cond_resched(); |
| 1968 | } |
| 1969 | err = 0; |
| 1970 | out: |
| 1971 | kfree(vec.key); |
| 1972 | kfree(vec.iv); |
| 1973 | kfree(vec.assoc); |
| 1974 | kfree(vec.ptext); |
| 1975 | kfree(vec.ctext); |
| 1976 | crypto_free_aead(generic_tfm); |
| 1977 | aead_request_free(generic_req); |
| 1978 | return err; |
| 1979 | } |
| 1980 | #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */ |
| 1981 | static int test_aead_vs_generic_impl(const char *driver, |
| 1982 | const struct alg_test_desc *test_desc, |
| 1983 | struct aead_request *req, |
| 1984 | struct cipher_test_sglists *tsgls) |
| 1985 | { |
| 1986 | return 0; |
| 1987 | } |
| 1988 | #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */ |
| 1989 | |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 1990 | static int test_aead(const char *driver, int enc, |
| 1991 | const struct aead_test_suite *suite, |
| 1992 | struct aead_request *req, |
| 1993 | struct cipher_test_sglists *tsgls) |
| 1994 | { |
| 1995 | unsigned int i; |
| 1996 | int err; |
| 1997 | |
| 1998 | for (i = 0; i < suite->count; i++) { |
| 1999 | err = test_aead_vec(driver, enc, &suite->vecs[i], i, req, |
| 2000 | tsgls); |
| 2001 | if (err) |
| 2002 | return err; |
| 2003 | } |
| 2004 | return 0; |
| 2005 | } |
| 2006 | |
| 2007 | static int alg_test_aead(const struct alg_test_desc *desc, const char *driver, |
| 2008 | u32 type, u32 mask) |
| 2009 | { |
| 2010 | const struct aead_test_suite *suite = &desc->suite.aead; |
| 2011 | struct crypto_aead *tfm; |
| 2012 | struct aead_request *req = NULL; |
| 2013 | struct cipher_test_sglists *tsgls = NULL; |
| 2014 | int err; |
| 2015 | |
| 2016 | if (suite->count <= 0) { |
| 2017 | pr_err("alg: aead: empty test suite for %s\n", driver); |
| 2018 | return -EINVAL; |
| 2019 | } |
| 2020 | |
| 2021 | tfm = crypto_alloc_aead(driver, type, mask); |
| 2022 | if (IS_ERR(tfm)) { |
| 2023 | pr_err("alg: aead: failed to allocate transform for %s: %ld\n", |
| 2024 | driver, PTR_ERR(tfm)); |
| 2025 | return PTR_ERR(tfm); |
| 2026 | } |
| 2027 | |
| 2028 | req = aead_request_alloc(tfm, GFP_KERNEL); |
| 2029 | if (!req) { |
| 2030 | pr_err("alg: aead: failed to allocate request for %s\n", |
| 2031 | driver); |
| 2032 | err = -ENOMEM; |
| 2033 | goto out; |
| 2034 | } |
| 2035 | |
| 2036 | tsgls = alloc_cipher_test_sglists(); |
| 2037 | if (!tsgls) { |
| 2038 | pr_err("alg: aead: failed to allocate test buffers for %s\n", |
| 2039 | driver); |
| 2040 | err = -ENOMEM; |
| 2041 | goto out; |
| 2042 | } |
| 2043 | |
| 2044 | err = test_aead(driver, ENCRYPT, suite, req, tsgls); |
| 2045 | if (err) |
| 2046 | goto out; |
| 2047 | |
| 2048 | err = test_aead(driver, DECRYPT, suite, req, tsgls); |
Eric Biggers | 40153b1 | 2019-04-11 21:57:41 -0700 | [diff] [blame^] | 2049 | if (err) |
| 2050 | goto out; |
| 2051 | |
| 2052 | err = test_aead_vs_generic_impl(driver, desc, req, tsgls); |
Eric Biggers | ed96804 | 2019-01-31 23:51:47 -0800 | [diff] [blame] | 2053 | out: |
| 2054 | free_cipher_test_sglists(tsgls); |
| 2055 | aead_request_free(req); |
| 2056 | crypto_free_aead(tfm); |
| 2057 | return err; |
| 2058 | } |
| 2059 | |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2060 | static int test_cipher(struct crypto_cipher *tfm, int enc, |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 2061 | const struct cipher_testvec *template, |
| 2062 | unsigned int tcount) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2063 | { |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2064 | const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm)); |
| 2065 | unsigned int i, j, k; |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2066 | char *q; |
| 2067 | const char *e; |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 2068 | const char *input, *result; |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2069 | void *data; |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 2070 | char *xbuf[XBUFSIZE]; |
| 2071 | int ret = -ENOMEM; |
| 2072 | |
| 2073 | if (testmgr_alloc_buf(xbuf)) |
| 2074 | goto out_nobuf; |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2075 | |
| 2076 | if (enc == ENCRYPT) |
| 2077 | e = "encryption"; |
| 2078 | else |
| 2079 | e = "decryption"; |
| 2080 | |
| 2081 | j = 0; |
| 2082 | for (i = 0; i < tcount; i++) { |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2083 | |
Stephan Mueller | 10faa8c | 2016-08-25 15:15:01 +0200 | [diff] [blame] | 2084 | if (fips_enabled && template[i].fips_skip) |
| 2085 | continue; |
| 2086 | |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 2087 | input = enc ? template[i].ptext : template[i].ctext; |
| 2088 | result = enc ? template[i].ctext : template[i].ptext; |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2089 | j++; |
| 2090 | |
Herbert Xu | fd57f22 | 2009-05-29 16:05:42 +1000 | [diff] [blame] | 2091 | ret = -EINVAL; |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 2092 | if (WARN_ON(template[i].len > PAGE_SIZE)) |
Herbert Xu | fd57f22 | 2009-05-29 16:05:42 +1000 | [diff] [blame] | 2093 | goto out; |
| 2094 | |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2095 | data = xbuf[0]; |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 2096 | memcpy(data, input, template[i].len); |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2097 | |
| 2098 | crypto_cipher_clear_flags(tfm, ~0); |
| 2099 | if (template[i].wk) |
Eric Biggers | 231baec | 2019-01-18 22:48:00 -0800 | [diff] [blame] | 2100 | crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS); |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2101 | |
| 2102 | ret = crypto_cipher_setkey(tfm, template[i].key, |
| 2103 | template[i].klen); |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 2104 | if (ret) { |
| 2105 | if (ret == template[i].setkey_error) |
| 2106 | continue; |
| 2107 | pr_err("alg: cipher: %s setkey failed on test vector %u; expected_error=%d, actual_error=%d, flags=%#x\n", |
| 2108 | algo, j, template[i].setkey_error, ret, |
| 2109 | crypto_cipher_get_flags(tfm)); |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2110 | goto out; |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 2111 | } |
| 2112 | if (template[i].setkey_error) { |
| 2113 | pr_err("alg: cipher: %s setkey unexpectedly succeeded on test vector %u; expected_error=%d\n", |
| 2114 | algo, j, template[i].setkey_error); |
| 2115 | ret = -EINVAL; |
| 2116 | goto out; |
| 2117 | } |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2118 | |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 2119 | for (k = 0; k < template[i].len; |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2120 | k += crypto_cipher_blocksize(tfm)) { |
| 2121 | if (enc) |
| 2122 | crypto_cipher_encrypt_one(tfm, data + k, |
| 2123 | data + k); |
| 2124 | else |
| 2125 | crypto_cipher_decrypt_one(tfm, data + k, |
| 2126 | data + k); |
| 2127 | } |
| 2128 | |
| 2129 | q = data; |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 2130 | if (memcmp(q, result, template[i].len)) { |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2131 | printk(KERN_ERR "alg: cipher: Test %d failed " |
| 2132 | "on %s for %s\n", j, e, algo); |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 2133 | hexdump(q, template[i].len); |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2134 | ret = -EINVAL; |
| 2135 | goto out; |
| 2136 | } |
| 2137 | } |
| 2138 | |
| 2139 | ret = 0; |
| 2140 | |
| 2141 | out: |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 2142 | testmgr_free_buf(xbuf); |
| 2143 | out_nobuf: |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2144 | return ret; |
| 2145 | } |
| 2146 | |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2147 | static int test_skcipher_vec_cfg(const char *driver, int enc, |
| 2148 | const struct cipher_testvec *vec, |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2149 | const char *vec_name, |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2150 | const struct testvec_config *cfg, |
| 2151 | struct skcipher_request *req, |
| 2152 | struct cipher_test_sglists *tsgls) |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2153 | { |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2154 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
| 2155 | const unsigned int alignmask = crypto_skcipher_alignmask(tfm); |
| 2156 | const unsigned int ivsize = crypto_skcipher_ivsize(tfm); |
| 2157 | const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags; |
| 2158 | const char *op = enc ? "encryption" : "decryption"; |
| 2159 | DECLARE_CRYPTO_WAIT(wait); |
| 2160 | u8 _iv[3 * (MAX_ALGAPI_ALIGNMASK + 1) + MAX_IVLEN]; |
| 2161 | u8 *iv = PTR_ALIGN(&_iv[0], 2 * (MAX_ALGAPI_ALIGNMASK + 1)) + |
| 2162 | cfg->iv_offset + |
| 2163 | (cfg->iv_offset_relative_to_alignmask ? alignmask : 0); |
| 2164 | struct kvec input; |
| 2165 | int err; |
Herbert Xu | f8b0d4d | 2009-05-06 14:15:47 +0800 | [diff] [blame] | 2166 | |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2167 | /* Set the key */ |
| 2168 | if (vec->wk) |
| 2169 | crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS); |
Jussi Kivilinna | 08d6af8 | 2012-09-21 10:26:47 +0300 | [diff] [blame] | 2170 | else |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2171 | crypto_skcipher_clear_flags(tfm, |
| 2172 | CRYPTO_TFM_REQ_FORBID_WEAK_KEYS); |
| 2173 | err = crypto_skcipher_setkey(tfm, vec->key, vec->klen); |
| 2174 | if (err) { |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 2175 | if (err == vec->setkey_error) |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2176 | return 0; |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2177 | pr_err("alg: skcipher: %s setkey failed on test vector %s; expected_error=%d, actual_error=%d, flags=%#x\n", |
| 2178 | driver, vec_name, vec->setkey_error, err, |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 2179 | crypto_skcipher_get_flags(tfm)); |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2180 | return err; |
| 2181 | } |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 2182 | if (vec->setkey_error) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2183 | pr_err("alg: skcipher: %s setkey unexpectedly succeeded on test vector %s; expected_error=%d\n", |
| 2184 | driver, vec_name, vec->setkey_error); |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2185 | return -EINVAL; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2186 | } |
| 2187 | |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2188 | /* The IV must be copied to a buffer, as the algorithm may modify it */ |
| 2189 | if (ivsize) { |
| 2190 | if (WARN_ON(ivsize > MAX_IVLEN)) |
| 2191 | return -EINVAL; |
Eric Biggers | 8efd972 | 2019-02-14 00:03:51 -0800 | [diff] [blame] | 2192 | if (vec->generates_iv && !enc) |
| 2193 | memcpy(iv, vec->iv_out, ivsize); |
| 2194 | else if (vec->iv) |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2195 | memcpy(iv, vec->iv, ivsize); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2196 | else |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2197 | memset(iv, 0, ivsize); |
| 2198 | } else { |
| 2199 | if (vec->generates_iv) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2200 | pr_err("alg: skcipher: %s has ivsize=0 but test vector %s generates IV!\n", |
| 2201 | driver, vec_name); |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2202 | return -EINVAL; |
Cristian Stoica | a1aa44a | 2014-08-08 14:27:51 +0300 | [diff] [blame] | 2203 | } |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2204 | iv = NULL; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2205 | } |
| 2206 | |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2207 | /* Build the src/dst scatterlists */ |
| 2208 | input.iov_base = enc ? (void *)vec->ptext : (void *)vec->ctext; |
| 2209 | input.iov_len = vec->len; |
| 2210 | err = build_cipher_test_sglists(tsgls, cfg, alignmask, |
| 2211 | vec->len, vec->len, &input, 1); |
| 2212 | if (err) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2213 | pr_err("alg: skcipher: %s %s: error preparing scatterlists for test vector %s, cfg=\"%s\"\n", |
| 2214 | driver, op, vec_name, cfg->name); |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2215 | return err; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2216 | } |
| 2217 | |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2218 | /* Do the actual encryption or decryption */ |
| 2219 | testmgr_poison(req->__ctx, crypto_skcipher_reqsize(tfm)); |
| 2220 | skcipher_request_set_callback(req, req_flags, crypto_req_done, &wait); |
| 2221 | skcipher_request_set_crypt(req, tsgls->src.sgl_ptr, tsgls->dst.sgl_ptr, |
| 2222 | vec->len, iv); |
Eric Biggers | 6570737 | 2019-03-12 22:12:52 -0700 | [diff] [blame] | 2223 | if (cfg->nosimd) |
| 2224 | crypto_disable_simd_for_test(); |
| 2225 | err = enc ? crypto_skcipher_encrypt(req) : crypto_skcipher_decrypt(req); |
| 2226 | if (cfg->nosimd) |
| 2227 | crypto_reenable_simd_for_test(); |
| 2228 | err = crypto_wait_req(err, &wait); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2229 | |
Eric Biggers | fa353c9 | 2019-01-31 23:51:49 -0800 | [diff] [blame] | 2230 | /* Check that the algorithm didn't overwrite things it shouldn't have */ |
| 2231 | if (req->cryptlen != vec->len || |
| 2232 | req->iv != iv || |
| 2233 | req->src != tsgls->src.sgl_ptr || |
| 2234 | req->dst != tsgls->dst.sgl_ptr || |
| 2235 | crypto_skcipher_reqtfm(req) != tfm || |
| 2236 | req->base.complete != crypto_req_done || |
| 2237 | req->base.flags != req_flags || |
| 2238 | req->base.data != &wait) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2239 | pr_err("alg: skcipher: %s %s corrupted request struct on test vector %s, cfg=\"%s\"\n", |
| 2240 | driver, op, vec_name, cfg->name); |
Eric Biggers | fa353c9 | 2019-01-31 23:51:49 -0800 | [diff] [blame] | 2241 | if (req->cryptlen != vec->len) |
| 2242 | pr_err("alg: skcipher: changed 'req->cryptlen'\n"); |
| 2243 | if (req->iv != iv) |
| 2244 | pr_err("alg: skcipher: changed 'req->iv'\n"); |
| 2245 | if (req->src != tsgls->src.sgl_ptr) |
| 2246 | pr_err("alg: skcipher: changed 'req->src'\n"); |
| 2247 | if (req->dst != tsgls->dst.sgl_ptr) |
| 2248 | pr_err("alg: skcipher: changed 'req->dst'\n"); |
| 2249 | if (crypto_skcipher_reqtfm(req) != tfm) |
| 2250 | pr_err("alg: skcipher: changed 'req->base.tfm'\n"); |
| 2251 | if (req->base.complete != crypto_req_done) |
| 2252 | pr_err("alg: skcipher: changed 'req->base.complete'\n"); |
| 2253 | if (req->base.flags != req_flags) |
| 2254 | pr_err("alg: skcipher: changed 'req->base.flags'\n"); |
| 2255 | if (req->base.data != &wait) |
| 2256 | pr_err("alg: skcipher: changed 'req->base.data'\n"); |
| 2257 | return -EINVAL; |
| 2258 | } |
| 2259 | if (is_test_sglist_corrupted(&tsgls->src)) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2260 | pr_err("alg: skcipher: %s %s corrupted src sgl on test vector %s, cfg=\"%s\"\n", |
| 2261 | driver, op, vec_name, cfg->name); |
Eric Biggers | fa353c9 | 2019-01-31 23:51:49 -0800 | [diff] [blame] | 2262 | return -EINVAL; |
| 2263 | } |
| 2264 | if (tsgls->dst.sgl_ptr != tsgls->src.sgl && |
| 2265 | is_test_sglist_corrupted(&tsgls->dst)) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2266 | pr_err("alg: skcipher: %s %s corrupted dst sgl on test vector %s, cfg=\"%s\"\n", |
| 2267 | driver, op, vec_name, cfg->name); |
Eric Biggers | fa353c9 | 2019-01-31 23:51:49 -0800 | [diff] [blame] | 2268 | return -EINVAL; |
| 2269 | } |
| 2270 | |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 2271 | /* Check for success or failure */ |
| 2272 | if (err) { |
| 2273 | if (err == vec->crypt_error) |
| 2274 | return 0; |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2275 | pr_err("alg: skcipher: %s %s failed on test vector %s; expected_error=%d, actual_error=%d, cfg=\"%s\"\n", |
| 2276 | driver, op, vec_name, vec->crypt_error, err, cfg->name); |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 2277 | return err; |
| 2278 | } |
| 2279 | if (vec->crypt_error) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2280 | pr_err("alg: skcipher: %s %s unexpectedly succeeded on test vector %s; expected_error=%d, cfg=\"%s\"\n", |
| 2281 | driver, op, vec_name, vec->crypt_error, cfg->name); |
Eric Biggers | 5283a8e | 2019-04-11 21:57:36 -0700 | [diff] [blame] | 2282 | return -EINVAL; |
| 2283 | } |
| 2284 | |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2285 | /* Check for the correct output (ciphertext or plaintext) */ |
| 2286 | err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext, |
| 2287 | vec->len, 0, true); |
| 2288 | if (err == -EOVERFLOW) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2289 | pr_err("alg: skcipher: %s %s overran dst buffer on test vector %s, cfg=\"%s\"\n", |
| 2290 | driver, op, vec_name, cfg->name); |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2291 | return err; |
| 2292 | } |
| 2293 | if (err) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2294 | pr_err("alg: skcipher: %s %s test failed (wrong result) on test vector %s, cfg=\"%s\"\n", |
| 2295 | driver, op, vec_name, cfg->name); |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2296 | return err; |
| 2297 | } |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2298 | |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2299 | /* If applicable, check that the algorithm generated the correct IV */ |
Eric Biggers | 8efd972 | 2019-02-14 00:03:51 -0800 | [diff] [blame] | 2300 | if (vec->iv_out && memcmp(iv, vec->iv_out, ivsize) != 0) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2301 | pr_err("alg: skcipher: %s %s test failed (wrong output IV) on test vector %s, cfg=\"%s\"\n", |
| 2302 | driver, op, vec_name, cfg->name); |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2303 | hexdump(iv, ivsize); |
| 2304 | return -EINVAL; |
Jussi Kivilinna | 3a338f2 | 2013-06-13 17:37:45 +0300 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | return 0; |
Jussi Kivilinna | 08d6af8 | 2012-09-21 10:26:47 +0300 | [diff] [blame] | 2308 | } |
| 2309 | |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2310 | static int test_skcipher_vec(const char *driver, int enc, |
| 2311 | const struct cipher_testvec *vec, |
| 2312 | unsigned int vec_num, |
| 2313 | struct skcipher_request *req, |
| 2314 | struct cipher_test_sglists *tsgls) |
| 2315 | { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2316 | char vec_name[16]; |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2317 | unsigned int i; |
| 2318 | int err; |
| 2319 | |
| 2320 | if (fips_enabled && vec->fips_skip) |
| 2321 | return 0; |
| 2322 | |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2323 | sprintf(vec_name, "%u", vec_num); |
| 2324 | |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2325 | for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) { |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2326 | err = test_skcipher_vec_cfg(driver, enc, vec, vec_name, |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2327 | &default_cipher_testvec_configs[i], |
| 2328 | req, tsgls); |
| 2329 | if (err) |
| 2330 | return err; |
| 2331 | } |
| 2332 | |
| 2333 | #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS |
| 2334 | if (!noextratests) { |
| 2335 | struct testvec_config cfg; |
| 2336 | char cfgname[TESTVEC_CONFIG_NAMELEN]; |
| 2337 | |
| 2338 | for (i = 0; i < fuzz_iterations; i++) { |
| 2339 | generate_random_testvec_config(&cfg, cfgname, |
| 2340 | sizeof(cfgname)); |
Eric Biggers | 951d133 | 2019-04-11 21:57:37 -0700 | [diff] [blame] | 2341 | err = test_skcipher_vec_cfg(driver, enc, vec, vec_name, |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2342 | &cfg, req, tsgls); |
| 2343 | if (err) |
| 2344 | return err; |
| 2345 | } |
| 2346 | } |
| 2347 | #endif |
| 2348 | return 0; |
| 2349 | } |
| 2350 | |
Eric Biggers | d435e10 | 2019-04-11 21:57:40 -0700 | [diff] [blame] | 2351 | #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS |
| 2352 | /* |
| 2353 | * Generate a symmetric cipher test vector from the given implementation. |
| 2354 | * Assumes the buffers in 'vec' were already allocated. |
| 2355 | */ |
| 2356 | static void generate_random_cipher_testvec(struct skcipher_request *req, |
| 2357 | struct cipher_testvec *vec, |
| 2358 | unsigned int maxdatasize, |
| 2359 | char *name, size_t max_namelen) |
| 2360 | { |
| 2361 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
| 2362 | const unsigned int maxkeysize = tfm->keysize; |
| 2363 | const unsigned int ivsize = crypto_skcipher_ivsize(tfm); |
| 2364 | struct scatterlist src, dst; |
| 2365 | u8 iv[MAX_IVLEN]; |
| 2366 | DECLARE_CRYPTO_WAIT(wait); |
| 2367 | |
| 2368 | /* Key: length in [0, maxkeysize], but usually choose maxkeysize */ |
| 2369 | vec->klen = maxkeysize; |
| 2370 | if (prandom_u32() % 4 == 0) |
| 2371 | vec->klen = prandom_u32() % (maxkeysize + 1); |
| 2372 | generate_random_bytes((u8 *)vec->key, vec->klen); |
| 2373 | vec->setkey_error = crypto_skcipher_setkey(tfm, vec->key, vec->klen); |
| 2374 | |
| 2375 | /* IV */ |
| 2376 | generate_random_bytes((u8 *)vec->iv, ivsize); |
| 2377 | |
| 2378 | /* Plaintext */ |
| 2379 | vec->len = generate_random_length(maxdatasize); |
| 2380 | generate_random_bytes((u8 *)vec->ptext, vec->len); |
| 2381 | |
| 2382 | /* If the key couldn't be set, no need to continue to encrypt. */ |
| 2383 | if (vec->setkey_error) |
| 2384 | goto done; |
| 2385 | |
| 2386 | /* Ciphertext */ |
| 2387 | sg_init_one(&src, vec->ptext, vec->len); |
| 2388 | sg_init_one(&dst, vec->ctext, vec->len); |
| 2389 | memcpy(iv, vec->iv, ivsize); |
| 2390 | skcipher_request_set_callback(req, 0, crypto_req_done, &wait); |
| 2391 | skcipher_request_set_crypt(req, &src, &dst, vec->len, iv); |
| 2392 | vec->crypt_error = crypto_wait_req(crypto_skcipher_encrypt(req), &wait); |
| 2393 | done: |
| 2394 | snprintf(name, max_namelen, "\"random: len=%u klen=%u\"", |
| 2395 | vec->len, vec->klen); |
| 2396 | } |
| 2397 | |
| 2398 | /* |
| 2399 | * Test the skcipher algorithm represented by @req against the corresponding |
| 2400 | * generic implementation, if one is available. |
| 2401 | */ |
| 2402 | static int test_skcipher_vs_generic_impl(const char *driver, |
| 2403 | const char *generic_driver, |
| 2404 | struct skcipher_request *req, |
| 2405 | struct cipher_test_sglists *tsgls) |
| 2406 | { |
| 2407 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
| 2408 | const unsigned int ivsize = crypto_skcipher_ivsize(tfm); |
| 2409 | const unsigned int blocksize = crypto_skcipher_blocksize(tfm); |
| 2410 | const unsigned int maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN; |
| 2411 | const char *algname = crypto_skcipher_alg(tfm)->base.cra_name; |
| 2412 | char _generic_driver[CRYPTO_MAX_ALG_NAME]; |
| 2413 | struct crypto_skcipher *generic_tfm = NULL; |
| 2414 | struct skcipher_request *generic_req = NULL; |
| 2415 | unsigned int i; |
| 2416 | struct cipher_testvec vec = { 0 }; |
| 2417 | char vec_name[64]; |
| 2418 | struct testvec_config cfg; |
| 2419 | char cfgname[TESTVEC_CONFIG_NAMELEN]; |
| 2420 | int err; |
| 2421 | |
| 2422 | if (noextratests) |
| 2423 | return 0; |
| 2424 | |
| 2425 | /* Keywrap isn't supported here yet as it handles its IV differently. */ |
| 2426 | if (strncmp(algname, "kw(", 3) == 0) |
| 2427 | return 0; |
| 2428 | |
| 2429 | if (!generic_driver) { /* Use default naming convention? */ |
| 2430 | err = build_generic_driver_name(algname, _generic_driver); |
| 2431 | if (err) |
| 2432 | return err; |
| 2433 | generic_driver = _generic_driver; |
| 2434 | } |
| 2435 | |
| 2436 | if (strcmp(generic_driver, driver) == 0) /* Already the generic impl? */ |
| 2437 | return 0; |
| 2438 | |
| 2439 | generic_tfm = crypto_alloc_skcipher(generic_driver, 0, 0); |
| 2440 | if (IS_ERR(generic_tfm)) { |
| 2441 | err = PTR_ERR(generic_tfm); |
| 2442 | if (err == -ENOENT) { |
| 2443 | pr_warn("alg: skcipher: skipping comparison tests for %s because %s is unavailable\n", |
| 2444 | driver, generic_driver); |
| 2445 | return 0; |
| 2446 | } |
| 2447 | pr_err("alg: skcipher: error allocating %s (generic impl of %s): %d\n", |
| 2448 | generic_driver, algname, err); |
| 2449 | return err; |
| 2450 | } |
| 2451 | |
| 2452 | generic_req = skcipher_request_alloc(generic_tfm, GFP_KERNEL); |
| 2453 | if (!generic_req) { |
| 2454 | err = -ENOMEM; |
| 2455 | goto out; |
| 2456 | } |
| 2457 | |
| 2458 | /* Check the algorithm properties for consistency. */ |
| 2459 | |
| 2460 | if (tfm->keysize != generic_tfm->keysize) { |
| 2461 | pr_err("alg: skcipher: max keysize for %s (%u) doesn't match generic impl (%u)\n", |
| 2462 | driver, tfm->keysize, generic_tfm->keysize); |
| 2463 | err = -EINVAL; |
| 2464 | goto out; |
| 2465 | } |
| 2466 | |
| 2467 | if (ivsize != crypto_skcipher_ivsize(generic_tfm)) { |
| 2468 | pr_err("alg: skcipher: ivsize for %s (%u) doesn't match generic impl (%u)\n", |
| 2469 | driver, ivsize, crypto_skcipher_ivsize(generic_tfm)); |
| 2470 | err = -EINVAL; |
| 2471 | goto out; |
| 2472 | } |
| 2473 | |
| 2474 | if (blocksize != crypto_skcipher_blocksize(generic_tfm)) { |
| 2475 | pr_err("alg: skcipher: blocksize for %s (%u) doesn't match generic impl (%u)\n", |
| 2476 | driver, blocksize, |
| 2477 | crypto_skcipher_blocksize(generic_tfm)); |
| 2478 | err = -EINVAL; |
| 2479 | goto out; |
| 2480 | } |
| 2481 | |
| 2482 | /* |
| 2483 | * Now generate test vectors using the generic implementation, and test |
| 2484 | * the other implementation against them. |
| 2485 | */ |
| 2486 | |
| 2487 | vec.key = kmalloc(tfm->keysize, GFP_KERNEL); |
| 2488 | vec.iv = kmalloc(ivsize, GFP_KERNEL); |
| 2489 | vec.ptext = kmalloc(maxdatasize, GFP_KERNEL); |
| 2490 | vec.ctext = kmalloc(maxdatasize, GFP_KERNEL); |
| 2491 | if (!vec.key || !vec.iv || !vec.ptext || !vec.ctext) { |
| 2492 | err = -ENOMEM; |
| 2493 | goto out; |
| 2494 | } |
| 2495 | |
| 2496 | for (i = 0; i < fuzz_iterations * 8; i++) { |
| 2497 | generate_random_cipher_testvec(generic_req, &vec, maxdatasize, |
| 2498 | vec_name, sizeof(vec_name)); |
| 2499 | generate_random_testvec_config(&cfg, cfgname, sizeof(cfgname)); |
| 2500 | |
| 2501 | err = test_skcipher_vec_cfg(driver, ENCRYPT, &vec, vec_name, |
| 2502 | &cfg, req, tsgls); |
| 2503 | if (err) |
| 2504 | goto out; |
| 2505 | err = test_skcipher_vec_cfg(driver, DECRYPT, &vec, vec_name, |
| 2506 | &cfg, req, tsgls); |
| 2507 | if (err) |
| 2508 | goto out; |
| 2509 | cond_resched(); |
| 2510 | } |
| 2511 | err = 0; |
| 2512 | out: |
| 2513 | kfree(vec.key); |
| 2514 | kfree(vec.iv); |
| 2515 | kfree(vec.ptext); |
| 2516 | kfree(vec.ctext); |
| 2517 | crypto_free_skcipher(generic_tfm); |
| 2518 | skcipher_request_free(generic_req); |
| 2519 | return err; |
| 2520 | } |
| 2521 | #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */ |
| 2522 | static int test_skcipher_vs_generic_impl(const char *driver, |
| 2523 | const char *generic_driver, |
| 2524 | struct skcipher_request *req, |
| 2525 | struct cipher_test_sglists *tsgls) |
| 2526 | { |
| 2527 | return 0; |
| 2528 | } |
| 2529 | #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */ |
| 2530 | |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2531 | static int test_skcipher(const char *driver, int enc, |
| 2532 | const struct cipher_test_suite *suite, |
| 2533 | struct skcipher_request *req, |
| 2534 | struct cipher_test_sglists *tsgls) |
| 2535 | { |
| 2536 | unsigned int i; |
| 2537 | int err; |
| 2538 | |
| 2539 | for (i = 0; i < suite->count; i++) { |
| 2540 | err = test_skcipher_vec(driver, enc, &suite->vecs[i], i, req, |
| 2541 | tsgls); |
| 2542 | if (err) |
| 2543 | return err; |
| 2544 | } |
| 2545 | return 0; |
| 2546 | } |
| 2547 | |
| 2548 | static int alg_test_skcipher(const struct alg_test_desc *desc, |
| 2549 | const char *driver, u32 type, u32 mask) |
| 2550 | { |
| 2551 | const struct cipher_test_suite *suite = &desc->suite.cipher; |
| 2552 | struct crypto_skcipher *tfm; |
| 2553 | struct skcipher_request *req = NULL; |
| 2554 | struct cipher_test_sglists *tsgls = NULL; |
| 2555 | int err; |
| 2556 | |
| 2557 | if (suite->count <= 0) { |
| 2558 | pr_err("alg: skcipher: empty test suite for %s\n", driver); |
| 2559 | return -EINVAL; |
| 2560 | } |
| 2561 | |
| 2562 | tfm = crypto_alloc_skcipher(driver, type, mask); |
| 2563 | if (IS_ERR(tfm)) { |
| 2564 | pr_err("alg: skcipher: failed to allocate transform for %s: %ld\n", |
| 2565 | driver, PTR_ERR(tfm)); |
| 2566 | return PTR_ERR(tfm); |
| 2567 | } |
| 2568 | |
| 2569 | req = skcipher_request_alloc(tfm, GFP_KERNEL); |
| 2570 | if (!req) { |
| 2571 | pr_err("alg: skcipher: failed to allocate request for %s\n", |
| 2572 | driver); |
| 2573 | err = -ENOMEM; |
| 2574 | goto out; |
| 2575 | } |
| 2576 | |
| 2577 | tsgls = alloc_cipher_test_sglists(); |
| 2578 | if (!tsgls) { |
| 2579 | pr_err("alg: skcipher: failed to allocate test buffers for %s\n", |
| 2580 | driver); |
| 2581 | err = -ENOMEM; |
| 2582 | goto out; |
| 2583 | } |
| 2584 | |
| 2585 | err = test_skcipher(driver, ENCRYPT, suite, req, tsgls); |
| 2586 | if (err) |
| 2587 | goto out; |
| 2588 | |
| 2589 | err = test_skcipher(driver, DECRYPT, suite, req, tsgls); |
Eric Biggers | d435e10 | 2019-04-11 21:57:40 -0700 | [diff] [blame] | 2590 | if (err) |
| 2591 | goto out; |
| 2592 | |
| 2593 | err = test_skcipher_vs_generic_impl(driver, desc->generic_driver, req, |
| 2594 | tsgls); |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 2595 | out: |
| 2596 | free_cipher_test_sglists(tsgls); |
| 2597 | skcipher_request_free(req); |
| 2598 | crypto_free_skcipher(tfm); |
| 2599 | return err; |
| 2600 | } |
| 2601 | |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 2602 | static int test_comp(struct crypto_comp *tfm, |
| 2603 | const struct comp_testvec *ctemplate, |
| 2604 | const struct comp_testvec *dtemplate, |
| 2605 | int ctcount, int dtcount) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2606 | { |
| 2607 | const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm)); |
Mahipal Challa | 3360738 | 2018-04-11 20:28:32 +0200 | [diff] [blame] | 2608 | char *output, *decomp_output; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2609 | unsigned int i; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2610 | int ret; |
| 2611 | |
Mahipal Challa | 3360738 | 2018-04-11 20:28:32 +0200 | [diff] [blame] | 2612 | output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL); |
| 2613 | if (!output) |
| 2614 | return -ENOMEM; |
| 2615 | |
| 2616 | decomp_output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL); |
| 2617 | if (!decomp_output) { |
| 2618 | kfree(output); |
| 2619 | return -ENOMEM; |
| 2620 | } |
| 2621 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2622 | for (i = 0; i < ctcount; i++) { |
Geert Uytterhoeven | c79cf91 | 2009-03-29 15:44:19 +0800 | [diff] [blame] | 2623 | int ilen; |
| 2624 | unsigned int dlen = COMP_BUF_SIZE; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2625 | |
Michael Schupikov | 22a8118 | 2018-10-07 13:58:10 +0200 | [diff] [blame] | 2626 | memset(output, 0, COMP_BUF_SIZE); |
| 2627 | memset(decomp_output, 0, COMP_BUF_SIZE); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2628 | |
| 2629 | ilen = ctemplate[i].inlen; |
| 2630 | ret = crypto_comp_compress(tfm, ctemplate[i].input, |
Mahipal Challa | 3360738 | 2018-04-11 20:28:32 +0200 | [diff] [blame] | 2631 | ilen, output, &dlen); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2632 | if (ret) { |
| 2633 | printk(KERN_ERR "alg: comp: compression failed " |
| 2634 | "on test %d for %s: ret=%d\n", i + 1, algo, |
| 2635 | -ret); |
| 2636 | goto out; |
| 2637 | } |
| 2638 | |
Mahipal Challa | 3360738 | 2018-04-11 20:28:32 +0200 | [diff] [blame] | 2639 | ilen = dlen; |
| 2640 | dlen = COMP_BUF_SIZE; |
| 2641 | ret = crypto_comp_decompress(tfm, output, |
| 2642 | ilen, decomp_output, &dlen); |
| 2643 | if (ret) { |
| 2644 | pr_err("alg: comp: compression failed: decompress: on test %d for %s failed: ret=%d\n", |
| 2645 | i + 1, algo, -ret); |
| 2646 | goto out; |
| 2647 | } |
| 2648 | |
| 2649 | if (dlen != ctemplate[i].inlen) { |
Geert Uytterhoeven | b812eb0 | 2008-11-28 20:51:28 +0800 | [diff] [blame] | 2650 | printk(KERN_ERR "alg: comp: Compression test %d " |
| 2651 | "failed for %s: output len = %d\n", i + 1, algo, |
| 2652 | dlen); |
| 2653 | ret = -EINVAL; |
| 2654 | goto out; |
| 2655 | } |
| 2656 | |
Mahipal Challa | 3360738 | 2018-04-11 20:28:32 +0200 | [diff] [blame] | 2657 | if (memcmp(decomp_output, ctemplate[i].input, |
| 2658 | ctemplate[i].inlen)) { |
| 2659 | pr_err("alg: comp: compression failed: output differs: on test %d for %s\n", |
| 2660 | i + 1, algo); |
| 2661 | hexdump(decomp_output, dlen); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2662 | ret = -EINVAL; |
| 2663 | goto out; |
| 2664 | } |
| 2665 | } |
| 2666 | |
| 2667 | for (i = 0; i < dtcount; i++) { |
Geert Uytterhoeven | c79cf91 | 2009-03-29 15:44:19 +0800 | [diff] [blame] | 2668 | int ilen; |
| 2669 | unsigned int dlen = COMP_BUF_SIZE; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2670 | |
Michael Schupikov | 22a8118 | 2018-10-07 13:58:10 +0200 | [diff] [blame] | 2671 | memset(decomp_output, 0, COMP_BUF_SIZE); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2672 | |
| 2673 | ilen = dtemplate[i].inlen; |
| 2674 | ret = crypto_comp_decompress(tfm, dtemplate[i].input, |
Mahipal Challa | 3360738 | 2018-04-11 20:28:32 +0200 | [diff] [blame] | 2675 | ilen, decomp_output, &dlen); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2676 | if (ret) { |
| 2677 | printk(KERN_ERR "alg: comp: decompression failed " |
| 2678 | "on test %d for %s: ret=%d\n", i + 1, algo, |
| 2679 | -ret); |
| 2680 | goto out; |
| 2681 | } |
| 2682 | |
Geert Uytterhoeven | b812eb0 | 2008-11-28 20:51:28 +0800 | [diff] [blame] | 2683 | if (dlen != dtemplate[i].outlen) { |
| 2684 | printk(KERN_ERR "alg: comp: Decompression test %d " |
| 2685 | "failed for %s: output len = %d\n", i + 1, algo, |
| 2686 | dlen); |
| 2687 | ret = -EINVAL; |
| 2688 | goto out; |
| 2689 | } |
| 2690 | |
Mahipal Challa | 3360738 | 2018-04-11 20:28:32 +0200 | [diff] [blame] | 2691 | if (memcmp(decomp_output, dtemplate[i].output, dlen)) { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2692 | printk(KERN_ERR "alg: comp: Decompression test %d " |
| 2693 | "failed for %s\n", i + 1, algo); |
Mahipal Challa | 3360738 | 2018-04-11 20:28:32 +0200 | [diff] [blame] | 2694 | hexdump(decomp_output, dlen); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2695 | ret = -EINVAL; |
| 2696 | goto out; |
| 2697 | } |
| 2698 | } |
| 2699 | |
| 2700 | ret = 0; |
| 2701 | |
| 2702 | out: |
Mahipal Challa | 3360738 | 2018-04-11 20:28:32 +0200 | [diff] [blame] | 2703 | kfree(decomp_output); |
| 2704 | kfree(output); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2705 | return ret; |
| 2706 | } |
| 2707 | |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 2708 | static int test_acomp(struct crypto_acomp *tfm, |
Mahipal Challa | 3360738 | 2018-04-11 20:28:32 +0200 | [diff] [blame] | 2709 | const struct comp_testvec *ctemplate, |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 2710 | const struct comp_testvec *dtemplate, |
| 2711 | int ctcount, int dtcount) |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2712 | { |
| 2713 | const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm)); |
| 2714 | unsigned int i; |
Giovanni Cabiddu | a9943a0 | 2017-04-19 14:27:18 +0100 | [diff] [blame] | 2715 | char *output, *decomp_out; |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2716 | int ret; |
| 2717 | struct scatterlist src, dst; |
| 2718 | struct acomp_req *req; |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 2719 | struct crypto_wait wait; |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2720 | |
Eric Biggers | eb09559 | 2016-11-23 10:24:35 -0800 | [diff] [blame] | 2721 | output = kmalloc(COMP_BUF_SIZE, GFP_KERNEL); |
| 2722 | if (!output) |
| 2723 | return -ENOMEM; |
| 2724 | |
Giovanni Cabiddu | a9943a0 | 2017-04-19 14:27:18 +0100 | [diff] [blame] | 2725 | decomp_out = kmalloc(COMP_BUF_SIZE, GFP_KERNEL); |
| 2726 | if (!decomp_out) { |
| 2727 | kfree(output); |
| 2728 | return -ENOMEM; |
| 2729 | } |
| 2730 | |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2731 | for (i = 0; i < ctcount; i++) { |
| 2732 | unsigned int dlen = COMP_BUF_SIZE; |
| 2733 | int ilen = ctemplate[i].inlen; |
Laura Abbott | 02608e0 | 2016-12-21 12:32:54 -0800 | [diff] [blame] | 2734 | void *input_vec; |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2735 | |
Eric Biggers | d211022 | 2016-12-30 14:12:00 -0600 | [diff] [blame] | 2736 | input_vec = kmemdup(ctemplate[i].input, ilen, GFP_KERNEL); |
Laura Abbott | 02608e0 | 2016-12-21 12:32:54 -0800 | [diff] [blame] | 2737 | if (!input_vec) { |
| 2738 | ret = -ENOMEM; |
| 2739 | goto out; |
| 2740 | } |
| 2741 | |
Eric Biggers | eb09559 | 2016-11-23 10:24:35 -0800 | [diff] [blame] | 2742 | memset(output, 0, dlen); |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 2743 | crypto_init_wait(&wait); |
Laura Abbott | 02608e0 | 2016-12-21 12:32:54 -0800 | [diff] [blame] | 2744 | sg_init_one(&src, input_vec, ilen); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2745 | sg_init_one(&dst, output, dlen); |
| 2746 | |
| 2747 | req = acomp_request_alloc(tfm); |
| 2748 | if (!req) { |
| 2749 | pr_err("alg: acomp: request alloc failed for %s\n", |
| 2750 | algo); |
Laura Abbott | 02608e0 | 2016-12-21 12:32:54 -0800 | [diff] [blame] | 2751 | kfree(input_vec); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2752 | ret = -ENOMEM; |
| 2753 | goto out; |
| 2754 | } |
| 2755 | |
| 2756 | acomp_request_set_params(req, &src, &dst, ilen, dlen); |
| 2757 | acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 2758 | crypto_req_done, &wait); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2759 | |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 2760 | ret = crypto_wait_req(crypto_acomp_compress(req), &wait); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2761 | if (ret) { |
| 2762 | pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n", |
| 2763 | i + 1, algo, -ret); |
Laura Abbott | 02608e0 | 2016-12-21 12:32:54 -0800 | [diff] [blame] | 2764 | kfree(input_vec); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2765 | acomp_request_free(req); |
| 2766 | goto out; |
| 2767 | } |
| 2768 | |
Giovanni Cabiddu | a9943a0 | 2017-04-19 14:27:18 +0100 | [diff] [blame] | 2769 | ilen = req->dlen; |
| 2770 | dlen = COMP_BUF_SIZE; |
| 2771 | sg_init_one(&src, output, ilen); |
| 2772 | sg_init_one(&dst, decomp_out, dlen); |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 2773 | crypto_init_wait(&wait); |
Giovanni Cabiddu | a9943a0 | 2017-04-19 14:27:18 +0100 | [diff] [blame] | 2774 | acomp_request_set_params(req, &src, &dst, ilen, dlen); |
| 2775 | |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 2776 | ret = crypto_wait_req(crypto_acomp_decompress(req), &wait); |
Giovanni Cabiddu | a9943a0 | 2017-04-19 14:27:18 +0100 | [diff] [blame] | 2777 | if (ret) { |
| 2778 | pr_err("alg: acomp: compression failed on test %d for %s: ret=%d\n", |
| 2779 | i + 1, algo, -ret); |
| 2780 | kfree(input_vec); |
| 2781 | acomp_request_free(req); |
| 2782 | goto out; |
| 2783 | } |
| 2784 | |
| 2785 | if (req->dlen != ctemplate[i].inlen) { |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2786 | pr_err("alg: acomp: Compression test %d failed for %s: output len = %d\n", |
| 2787 | i + 1, algo, req->dlen); |
| 2788 | ret = -EINVAL; |
Laura Abbott | 02608e0 | 2016-12-21 12:32:54 -0800 | [diff] [blame] | 2789 | kfree(input_vec); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2790 | acomp_request_free(req); |
| 2791 | goto out; |
| 2792 | } |
| 2793 | |
Giovanni Cabiddu | a9943a0 | 2017-04-19 14:27:18 +0100 | [diff] [blame] | 2794 | if (memcmp(input_vec, decomp_out, req->dlen)) { |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2795 | pr_err("alg: acomp: Compression test %d failed for %s\n", |
| 2796 | i + 1, algo); |
| 2797 | hexdump(output, req->dlen); |
| 2798 | ret = -EINVAL; |
Laura Abbott | 02608e0 | 2016-12-21 12:32:54 -0800 | [diff] [blame] | 2799 | kfree(input_vec); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2800 | acomp_request_free(req); |
| 2801 | goto out; |
| 2802 | } |
| 2803 | |
Laura Abbott | 02608e0 | 2016-12-21 12:32:54 -0800 | [diff] [blame] | 2804 | kfree(input_vec); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2805 | acomp_request_free(req); |
| 2806 | } |
| 2807 | |
| 2808 | for (i = 0; i < dtcount; i++) { |
| 2809 | unsigned int dlen = COMP_BUF_SIZE; |
| 2810 | int ilen = dtemplate[i].inlen; |
Laura Abbott | 02608e0 | 2016-12-21 12:32:54 -0800 | [diff] [blame] | 2811 | void *input_vec; |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2812 | |
Eric Biggers | d211022 | 2016-12-30 14:12:00 -0600 | [diff] [blame] | 2813 | input_vec = kmemdup(dtemplate[i].input, ilen, GFP_KERNEL); |
Laura Abbott | 02608e0 | 2016-12-21 12:32:54 -0800 | [diff] [blame] | 2814 | if (!input_vec) { |
| 2815 | ret = -ENOMEM; |
| 2816 | goto out; |
| 2817 | } |
| 2818 | |
Eric Biggers | eb09559 | 2016-11-23 10:24:35 -0800 | [diff] [blame] | 2819 | memset(output, 0, dlen); |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 2820 | crypto_init_wait(&wait); |
Laura Abbott | 02608e0 | 2016-12-21 12:32:54 -0800 | [diff] [blame] | 2821 | sg_init_one(&src, input_vec, ilen); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2822 | sg_init_one(&dst, output, dlen); |
| 2823 | |
| 2824 | req = acomp_request_alloc(tfm); |
| 2825 | if (!req) { |
| 2826 | pr_err("alg: acomp: request alloc failed for %s\n", |
| 2827 | algo); |
Laura Abbott | 02608e0 | 2016-12-21 12:32:54 -0800 | [diff] [blame] | 2828 | kfree(input_vec); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2829 | ret = -ENOMEM; |
| 2830 | goto out; |
| 2831 | } |
| 2832 | |
| 2833 | acomp_request_set_params(req, &src, &dst, ilen, dlen); |
| 2834 | acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 2835 | crypto_req_done, &wait); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2836 | |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 2837 | ret = crypto_wait_req(crypto_acomp_decompress(req), &wait); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2838 | if (ret) { |
| 2839 | pr_err("alg: acomp: decompression failed on test %d for %s: ret=%d\n", |
| 2840 | i + 1, algo, -ret); |
Laura Abbott | 02608e0 | 2016-12-21 12:32:54 -0800 | [diff] [blame] | 2841 | kfree(input_vec); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2842 | acomp_request_free(req); |
| 2843 | goto out; |
| 2844 | } |
| 2845 | |
| 2846 | if (req->dlen != dtemplate[i].outlen) { |
| 2847 | pr_err("alg: acomp: Decompression test %d failed for %s: output len = %d\n", |
| 2848 | i + 1, algo, req->dlen); |
| 2849 | ret = -EINVAL; |
Laura Abbott | 02608e0 | 2016-12-21 12:32:54 -0800 | [diff] [blame] | 2850 | kfree(input_vec); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2851 | acomp_request_free(req); |
| 2852 | goto out; |
| 2853 | } |
| 2854 | |
| 2855 | if (memcmp(output, dtemplate[i].output, req->dlen)) { |
| 2856 | pr_err("alg: acomp: Decompression test %d failed for %s\n", |
| 2857 | i + 1, algo); |
| 2858 | hexdump(output, req->dlen); |
| 2859 | ret = -EINVAL; |
Laura Abbott | 02608e0 | 2016-12-21 12:32:54 -0800 | [diff] [blame] | 2860 | kfree(input_vec); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2861 | acomp_request_free(req); |
| 2862 | goto out; |
| 2863 | } |
| 2864 | |
Laura Abbott | 02608e0 | 2016-12-21 12:32:54 -0800 | [diff] [blame] | 2865 | kfree(input_vec); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2866 | acomp_request_free(req); |
| 2867 | } |
| 2868 | |
| 2869 | ret = 0; |
| 2870 | |
| 2871 | out: |
Giovanni Cabiddu | a9943a0 | 2017-04-19 14:27:18 +0100 | [diff] [blame] | 2872 | kfree(decomp_out); |
Eric Biggers | eb09559 | 2016-11-23 10:24:35 -0800 | [diff] [blame] | 2873 | kfree(output); |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2874 | return ret; |
| 2875 | } |
| 2876 | |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 2877 | static int test_cprng(struct crypto_rng *tfm, |
| 2878 | const struct cprng_testvec *template, |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 2879 | unsigned int tcount) |
| 2880 | { |
| 2881 | const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm)); |
Felipe Contreras | fa4ef8a | 2009-10-27 19:04:42 +0800 | [diff] [blame] | 2882 | int err = 0, i, j, seedsize; |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 2883 | u8 *seed; |
| 2884 | char result[32]; |
| 2885 | |
| 2886 | seedsize = crypto_rng_seedsize(tfm); |
| 2887 | |
| 2888 | seed = kmalloc(seedsize, GFP_KERNEL); |
| 2889 | if (!seed) { |
| 2890 | printk(KERN_ERR "alg: cprng: Failed to allocate seed space " |
| 2891 | "for %s\n", algo); |
| 2892 | return -ENOMEM; |
| 2893 | } |
| 2894 | |
| 2895 | for (i = 0; i < tcount; i++) { |
| 2896 | memset(result, 0, 32); |
| 2897 | |
| 2898 | memcpy(seed, template[i].v, template[i].vlen); |
| 2899 | memcpy(seed + template[i].vlen, template[i].key, |
| 2900 | template[i].klen); |
| 2901 | memcpy(seed + template[i].vlen + template[i].klen, |
| 2902 | template[i].dt, template[i].dtlen); |
| 2903 | |
| 2904 | err = crypto_rng_reset(tfm, seed, seedsize); |
| 2905 | if (err) { |
| 2906 | printk(KERN_ERR "alg: cprng: Failed to reset rng " |
| 2907 | "for %s\n", algo); |
| 2908 | goto out; |
| 2909 | } |
| 2910 | |
| 2911 | for (j = 0; j < template[i].loops; j++) { |
| 2912 | err = crypto_rng_get_bytes(tfm, result, |
| 2913 | template[i].rlen); |
Stephan Mueller | 19e60e1 | 2015-03-10 17:00:36 +0100 | [diff] [blame] | 2914 | if (err < 0) { |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 2915 | printk(KERN_ERR "alg: cprng: Failed to obtain " |
| 2916 | "the correct amount of random data for " |
Stephan Mueller | 19e60e1 | 2015-03-10 17:00:36 +0100 | [diff] [blame] | 2917 | "%s (requested %d)\n", algo, |
| 2918 | template[i].rlen); |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 2919 | goto out; |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | err = memcmp(result, template[i].result, |
| 2924 | template[i].rlen); |
| 2925 | if (err) { |
| 2926 | printk(KERN_ERR "alg: cprng: Test %d failed for %s\n", |
| 2927 | i, algo); |
| 2928 | hexdump(result, template[i].rlen); |
| 2929 | err = -EINVAL; |
| 2930 | goto out; |
| 2931 | } |
| 2932 | } |
| 2933 | |
| 2934 | out: |
| 2935 | kfree(seed); |
| 2936 | return err; |
| 2937 | } |
| 2938 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2939 | static int alg_test_cipher(const struct alg_test_desc *desc, |
| 2940 | const char *driver, u32 type, u32 mask) |
| 2941 | { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 2942 | const struct cipher_test_suite *suite = &desc->suite.cipher; |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2943 | struct crypto_cipher *tfm; |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 2944 | int err; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2945 | |
Herbert Xu | eed93e0 | 2016-11-22 20:08:31 +0800 | [diff] [blame] | 2946 | tfm = crypto_alloc_cipher(driver, type, mask); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2947 | if (IS_ERR(tfm)) { |
| 2948 | printk(KERN_ERR "alg: cipher: Failed to load transform for " |
| 2949 | "%s: %ld\n", driver, PTR_ERR(tfm)); |
| 2950 | return PTR_ERR(tfm); |
| 2951 | } |
| 2952 | |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 2953 | err = test_cipher(tfm, ENCRYPT, suite->vecs, suite->count); |
| 2954 | if (!err) |
| 2955 | err = test_cipher(tfm, DECRYPT, suite->vecs, suite->count); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2956 | |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 2957 | crypto_free_cipher(tfm); |
| 2958 | return err; |
| 2959 | } |
| 2960 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2961 | static int alg_test_comp(const struct alg_test_desc *desc, const char *driver, |
| 2962 | u32 type, u32 mask) |
| 2963 | { |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2964 | struct crypto_comp *comp; |
| 2965 | struct crypto_acomp *acomp; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2966 | int err; |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2967 | u32 algo_type = type & CRYPTO_ALG_TYPE_ACOMPRESS_MASK; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2968 | |
Giovanni Cabiddu | d7db7a8 | 2016-10-21 13:19:54 +0100 | [diff] [blame] | 2969 | if (algo_type == CRYPTO_ALG_TYPE_ACOMPRESS) { |
| 2970 | acomp = crypto_alloc_acomp(driver, type, mask); |
| 2971 | if (IS_ERR(acomp)) { |
| 2972 | pr_err("alg: acomp: Failed to load transform for %s: %ld\n", |
| 2973 | driver, PTR_ERR(acomp)); |
| 2974 | return PTR_ERR(acomp); |
| 2975 | } |
| 2976 | err = test_acomp(acomp, desc->suite.comp.comp.vecs, |
| 2977 | desc->suite.comp.decomp.vecs, |
| 2978 | desc->suite.comp.comp.count, |
| 2979 | desc->suite.comp.decomp.count); |
| 2980 | crypto_free_acomp(acomp); |
| 2981 | } else { |
| 2982 | comp = crypto_alloc_comp(driver, type, mask); |
| 2983 | if (IS_ERR(comp)) { |
| 2984 | pr_err("alg: comp: Failed to load transform for %s: %ld\n", |
| 2985 | driver, PTR_ERR(comp)); |
| 2986 | return PTR_ERR(comp); |
| 2987 | } |
| 2988 | |
| 2989 | err = test_comp(comp, desc->suite.comp.comp.vecs, |
| 2990 | desc->suite.comp.decomp.vecs, |
| 2991 | desc->suite.comp.comp.count, |
| 2992 | desc->suite.comp.decomp.count); |
| 2993 | |
| 2994 | crypto_free_comp(comp); |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2995 | } |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2996 | return err; |
| 2997 | } |
| 2998 | |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 2999 | static int alg_test_crc32c(const struct alg_test_desc *desc, |
| 3000 | const char *driver, u32 type, u32 mask) |
| 3001 | { |
| 3002 | struct crypto_shash *tfm; |
Eric Biggers | cb9dde8 | 2019-01-10 12:17:55 -0800 | [diff] [blame] | 3003 | __le32 val; |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 3004 | int err; |
| 3005 | |
| 3006 | err = alg_test_hash(desc, driver, type, mask); |
| 3007 | if (err) |
Eric Biggers | eb5e673 | 2019-01-23 20:57:35 -0800 | [diff] [blame] | 3008 | return err; |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 3009 | |
Herbert Xu | eed93e0 | 2016-11-22 20:08:31 +0800 | [diff] [blame] | 3010 | tfm = crypto_alloc_shash(driver, type, mask); |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 3011 | if (IS_ERR(tfm)) { |
Eric Biggers | eb5e673 | 2019-01-23 20:57:35 -0800 | [diff] [blame] | 3012 | if (PTR_ERR(tfm) == -ENOENT) { |
| 3013 | /* |
| 3014 | * This crc32c implementation is only available through |
| 3015 | * ahash API, not the shash API, so the remaining part |
| 3016 | * of the test is not applicable to it. |
| 3017 | */ |
| 3018 | return 0; |
| 3019 | } |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 3020 | printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: " |
| 3021 | "%ld\n", driver, PTR_ERR(tfm)); |
Eric Biggers | eb5e673 | 2019-01-23 20:57:35 -0800 | [diff] [blame] | 3022 | return PTR_ERR(tfm); |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 3023 | } |
| 3024 | |
| 3025 | do { |
Jan-Simon Möller | 4c5c302 | 2012-07-02 13:48:30 +0200 | [diff] [blame] | 3026 | SHASH_DESC_ON_STACK(shash, tfm); |
| 3027 | u32 *ctx = (u32 *)shash_desc_ctx(shash); |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 3028 | |
Jan-Simon Möller | 4c5c302 | 2012-07-02 13:48:30 +0200 | [diff] [blame] | 3029 | shash->tfm = tfm; |
| 3030 | shash->flags = 0; |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 3031 | |
Eric Biggers | cb9dde8 | 2019-01-10 12:17:55 -0800 | [diff] [blame] | 3032 | *ctx = 420553207; |
Jan-Simon Möller | 4c5c302 | 2012-07-02 13:48:30 +0200 | [diff] [blame] | 3033 | err = crypto_shash_final(shash, (u8 *)&val); |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 3034 | if (err) { |
| 3035 | printk(KERN_ERR "alg: crc32c: Operation failed for " |
| 3036 | "%s: %d\n", driver, err); |
| 3037 | break; |
| 3038 | } |
| 3039 | |
Eric Biggers | cb9dde8 | 2019-01-10 12:17:55 -0800 | [diff] [blame] | 3040 | if (val != cpu_to_le32(~420553207)) { |
| 3041 | pr_err("alg: crc32c: Test failed for %s: %u\n", |
| 3042 | driver, le32_to_cpu(val)); |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 3043 | err = -EINVAL; |
| 3044 | } |
| 3045 | } while (0); |
| 3046 | |
| 3047 | crypto_free_shash(tfm); |
| 3048 | |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 3049 | return err; |
| 3050 | } |
| 3051 | |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 3052 | static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver, |
| 3053 | u32 type, u32 mask) |
| 3054 | { |
| 3055 | struct crypto_rng *rng; |
| 3056 | int err; |
| 3057 | |
Herbert Xu | eed93e0 | 2016-11-22 20:08:31 +0800 | [diff] [blame] | 3058 | rng = crypto_alloc_rng(driver, type, mask); |
Jarod Wilson | 7647d6c | 2009-05-04 19:44:50 +0800 | [diff] [blame] | 3059 | if (IS_ERR(rng)) { |
| 3060 | printk(KERN_ERR "alg: cprng: Failed to load transform for %s: " |
| 3061 | "%ld\n", driver, PTR_ERR(rng)); |
| 3062 | return PTR_ERR(rng); |
| 3063 | } |
| 3064 | |
| 3065 | err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count); |
| 3066 | |
| 3067 | crypto_free_rng(rng); |
| 3068 | |
| 3069 | return err; |
| 3070 | } |
| 3071 | |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 3072 | |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 3073 | static int drbg_cavs_test(const struct drbg_testvec *test, int pr, |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 3074 | const char *driver, u32 type, u32 mask) |
| 3075 | { |
| 3076 | int ret = -EAGAIN; |
| 3077 | struct crypto_rng *drng; |
| 3078 | struct drbg_test_data test_data; |
| 3079 | struct drbg_string addtl, pers, testentropy; |
| 3080 | unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL); |
| 3081 | |
| 3082 | if (!buf) |
| 3083 | return -ENOMEM; |
| 3084 | |
Herbert Xu | eed93e0 | 2016-11-22 20:08:31 +0800 | [diff] [blame] | 3085 | drng = crypto_alloc_rng(driver, type, mask); |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 3086 | if (IS_ERR(drng)) { |
Jarod Wilson | 2fc0d25 | 2014-07-29 15:47:56 -0400 | [diff] [blame] | 3087 | printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for " |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 3088 | "%s\n", driver); |
| 3089 | kzfree(buf); |
| 3090 | return -ENOMEM; |
| 3091 | } |
| 3092 | |
| 3093 | test_data.testentropy = &testentropy; |
| 3094 | drbg_string_fill(&testentropy, test->entropy, test->entropylen); |
| 3095 | drbg_string_fill(&pers, test->pers, test->perslen); |
| 3096 | ret = crypto_drbg_reset_test(drng, &pers, &test_data); |
| 3097 | if (ret) { |
| 3098 | printk(KERN_ERR "alg: drbg: Failed to reset rng\n"); |
| 3099 | goto outbuf; |
| 3100 | } |
| 3101 | |
| 3102 | drbg_string_fill(&addtl, test->addtla, test->addtllen); |
| 3103 | if (pr) { |
| 3104 | drbg_string_fill(&testentropy, test->entpra, test->entprlen); |
| 3105 | ret = crypto_drbg_get_bytes_addtl_test(drng, |
| 3106 | buf, test->expectedlen, &addtl, &test_data); |
| 3107 | } else { |
| 3108 | ret = crypto_drbg_get_bytes_addtl(drng, |
| 3109 | buf, test->expectedlen, &addtl); |
| 3110 | } |
Stephan Mueller | 19e60e1 | 2015-03-10 17:00:36 +0100 | [diff] [blame] | 3111 | if (ret < 0) { |
Jarod Wilson | 2fc0d25 | 2014-07-29 15:47:56 -0400 | [diff] [blame] | 3112 | printk(KERN_ERR "alg: drbg: could not obtain random data for " |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 3113 | "driver %s\n", driver); |
| 3114 | goto outbuf; |
| 3115 | } |
| 3116 | |
| 3117 | drbg_string_fill(&addtl, test->addtlb, test->addtllen); |
| 3118 | if (pr) { |
| 3119 | drbg_string_fill(&testentropy, test->entprb, test->entprlen); |
| 3120 | ret = crypto_drbg_get_bytes_addtl_test(drng, |
| 3121 | buf, test->expectedlen, &addtl, &test_data); |
| 3122 | } else { |
| 3123 | ret = crypto_drbg_get_bytes_addtl(drng, |
| 3124 | buf, test->expectedlen, &addtl); |
| 3125 | } |
Stephan Mueller | 19e60e1 | 2015-03-10 17:00:36 +0100 | [diff] [blame] | 3126 | if (ret < 0) { |
Jarod Wilson | 2fc0d25 | 2014-07-29 15:47:56 -0400 | [diff] [blame] | 3127 | printk(KERN_ERR "alg: drbg: could not obtain random data for " |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 3128 | "driver %s\n", driver); |
| 3129 | goto outbuf; |
| 3130 | } |
| 3131 | |
| 3132 | ret = memcmp(test->expected, buf, test->expectedlen); |
| 3133 | |
| 3134 | outbuf: |
| 3135 | crypto_free_rng(drng); |
| 3136 | kzfree(buf); |
| 3137 | return ret; |
| 3138 | } |
| 3139 | |
| 3140 | |
| 3141 | static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver, |
| 3142 | u32 type, u32 mask) |
| 3143 | { |
| 3144 | int err = 0; |
| 3145 | int pr = 0; |
| 3146 | int i = 0; |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 3147 | const struct drbg_testvec *template = desc->suite.drbg.vecs; |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 3148 | unsigned int tcount = desc->suite.drbg.count; |
| 3149 | |
| 3150 | if (0 == memcmp(driver, "drbg_pr_", 8)) |
| 3151 | pr = 1; |
| 3152 | |
| 3153 | for (i = 0; i < tcount; i++) { |
| 3154 | err = drbg_cavs_test(&template[i], pr, driver, type, mask); |
| 3155 | if (err) { |
| 3156 | printk(KERN_ERR "alg: drbg: Test %d failed for %s\n", |
| 3157 | i, driver); |
| 3158 | err = -EINVAL; |
| 3159 | break; |
| 3160 | } |
| 3161 | } |
| 3162 | return err; |
| 3163 | |
| 3164 | } |
| 3165 | |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 3166 | static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec, |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3167 | const char *alg) |
| 3168 | { |
| 3169 | struct kpp_request *req; |
| 3170 | void *input_buf = NULL; |
| 3171 | void *output_buf = NULL; |
Tudor-Dan Ambarus | 47d3fd3 | 2017-05-30 17:52:49 +0300 | [diff] [blame] | 3172 | void *a_public = NULL; |
| 3173 | void *a_ss = NULL; |
| 3174 | void *shared_secret = NULL; |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 3175 | struct crypto_wait wait; |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3176 | unsigned int out_len_max; |
| 3177 | int err = -ENOMEM; |
| 3178 | struct scatterlist src, dst; |
| 3179 | |
| 3180 | req = kpp_request_alloc(tfm, GFP_KERNEL); |
| 3181 | if (!req) |
| 3182 | return err; |
| 3183 | |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 3184 | crypto_init_wait(&wait); |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3185 | |
| 3186 | err = crypto_kpp_set_secret(tfm, vec->secret, vec->secret_size); |
| 3187 | if (err < 0) |
| 3188 | goto free_req; |
| 3189 | |
| 3190 | out_len_max = crypto_kpp_maxsize(tfm); |
| 3191 | output_buf = kzalloc(out_len_max, GFP_KERNEL); |
| 3192 | if (!output_buf) { |
| 3193 | err = -ENOMEM; |
| 3194 | goto free_req; |
| 3195 | } |
| 3196 | |
| 3197 | /* Use appropriate parameter as base */ |
| 3198 | kpp_request_set_input(req, NULL, 0); |
| 3199 | sg_init_one(&dst, output_buf, out_len_max); |
| 3200 | kpp_request_set_output(req, &dst, out_len_max); |
| 3201 | kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 3202 | crypto_req_done, &wait); |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3203 | |
Tudor-Dan Ambarus | 47d3fd3 | 2017-05-30 17:52:49 +0300 | [diff] [blame] | 3204 | /* Compute party A's public key */ |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 3205 | err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait); |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3206 | if (err) { |
Tudor-Dan Ambarus | 47d3fd3 | 2017-05-30 17:52:49 +0300 | [diff] [blame] | 3207 | pr_err("alg: %s: Party A: generate public key test failed. err %d\n", |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3208 | alg, err); |
| 3209 | goto free_output; |
| 3210 | } |
Tudor-Dan Ambarus | 47d3fd3 | 2017-05-30 17:52:49 +0300 | [diff] [blame] | 3211 | |
| 3212 | if (vec->genkey) { |
| 3213 | /* Save party A's public key */ |
Christopher Diaz Riveros | e3d90e52 | 2019-01-28 19:01:18 -0500 | [diff] [blame] | 3214 | a_public = kmemdup(sg_virt(req->dst), out_len_max, GFP_KERNEL); |
Tudor-Dan Ambarus | 47d3fd3 | 2017-05-30 17:52:49 +0300 | [diff] [blame] | 3215 | if (!a_public) { |
| 3216 | err = -ENOMEM; |
| 3217 | goto free_output; |
| 3218 | } |
Tudor-Dan Ambarus | 47d3fd3 | 2017-05-30 17:52:49 +0300 | [diff] [blame] | 3219 | } else { |
| 3220 | /* Verify calculated public key */ |
| 3221 | if (memcmp(vec->expected_a_public, sg_virt(req->dst), |
| 3222 | vec->expected_a_public_size)) { |
| 3223 | pr_err("alg: %s: Party A: generate public key test failed. Invalid output\n", |
| 3224 | alg); |
| 3225 | err = -EINVAL; |
| 3226 | goto free_output; |
| 3227 | } |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3228 | } |
| 3229 | |
| 3230 | /* Calculate shared secret key by using counter part (b) public key. */ |
Christopher Diaz Riveros | e3d90e52 | 2019-01-28 19:01:18 -0500 | [diff] [blame] | 3231 | input_buf = kmemdup(vec->b_public, vec->b_public_size, GFP_KERNEL); |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3232 | if (!input_buf) { |
| 3233 | err = -ENOMEM; |
| 3234 | goto free_output; |
| 3235 | } |
| 3236 | |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3237 | sg_init_one(&src, input_buf, vec->b_public_size); |
| 3238 | sg_init_one(&dst, output_buf, out_len_max); |
| 3239 | kpp_request_set_input(req, &src, vec->b_public_size); |
| 3240 | kpp_request_set_output(req, &dst, out_len_max); |
| 3241 | kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 3242 | crypto_req_done, &wait); |
| 3243 | err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait); |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3244 | if (err) { |
Tudor-Dan Ambarus | 47d3fd3 | 2017-05-30 17:52:49 +0300 | [diff] [blame] | 3245 | pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n", |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3246 | alg, err); |
| 3247 | goto free_all; |
| 3248 | } |
Tudor-Dan Ambarus | 47d3fd3 | 2017-05-30 17:52:49 +0300 | [diff] [blame] | 3249 | |
| 3250 | if (vec->genkey) { |
| 3251 | /* Save the shared secret obtained by party A */ |
Christopher Diaz Riveros | e3d90e52 | 2019-01-28 19:01:18 -0500 | [diff] [blame] | 3252 | a_ss = kmemdup(sg_virt(req->dst), vec->expected_ss_size, GFP_KERNEL); |
Tudor-Dan Ambarus | 47d3fd3 | 2017-05-30 17:52:49 +0300 | [diff] [blame] | 3253 | if (!a_ss) { |
| 3254 | err = -ENOMEM; |
| 3255 | goto free_all; |
| 3256 | } |
Tudor-Dan Ambarus | 47d3fd3 | 2017-05-30 17:52:49 +0300 | [diff] [blame] | 3257 | |
| 3258 | /* |
| 3259 | * Calculate party B's shared secret by using party A's |
| 3260 | * public key. |
| 3261 | */ |
| 3262 | err = crypto_kpp_set_secret(tfm, vec->b_secret, |
| 3263 | vec->b_secret_size); |
| 3264 | if (err < 0) |
| 3265 | goto free_all; |
| 3266 | |
| 3267 | sg_init_one(&src, a_public, vec->expected_a_public_size); |
| 3268 | sg_init_one(&dst, output_buf, out_len_max); |
| 3269 | kpp_request_set_input(req, &src, vec->expected_a_public_size); |
| 3270 | kpp_request_set_output(req, &dst, out_len_max); |
| 3271 | kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 3272 | crypto_req_done, &wait); |
| 3273 | err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), |
| 3274 | &wait); |
Tudor-Dan Ambarus | 47d3fd3 | 2017-05-30 17:52:49 +0300 | [diff] [blame] | 3275 | if (err) { |
| 3276 | pr_err("alg: %s: Party B: compute shared secret failed. err %d\n", |
| 3277 | alg, err); |
| 3278 | goto free_all; |
| 3279 | } |
| 3280 | |
| 3281 | shared_secret = a_ss; |
| 3282 | } else { |
| 3283 | shared_secret = (void *)vec->expected_ss; |
| 3284 | } |
| 3285 | |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3286 | /* |
| 3287 | * verify shared secret from which the user will derive |
| 3288 | * secret key by executing whatever hash it has chosen |
| 3289 | */ |
Tudor-Dan Ambarus | 47d3fd3 | 2017-05-30 17:52:49 +0300 | [diff] [blame] | 3290 | if (memcmp(shared_secret, sg_virt(req->dst), |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3291 | vec->expected_ss_size)) { |
| 3292 | pr_err("alg: %s: compute shared secret test failed. Invalid output\n", |
| 3293 | alg); |
| 3294 | err = -EINVAL; |
| 3295 | } |
| 3296 | |
| 3297 | free_all: |
Tudor-Dan Ambarus | 47d3fd3 | 2017-05-30 17:52:49 +0300 | [diff] [blame] | 3298 | kfree(a_ss); |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3299 | kfree(input_buf); |
| 3300 | free_output: |
Tudor-Dan Ambarus | 47d3fd3 | 2017-05-30 17:52:49 +0300 | [diff] [blame] | 3301 | kfree(a_public); |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3302 | kfree(output_buf); |
| 3303 | free_req: |
| 3304 | kpp_request_free(req); |
| 3305 | return err; |
| 3306 | } |
| 3307 | |
| 3308 | static int test_kpp(struct crypto_kpp *tfm, const char *alg, |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 3309 | const struct kpp_testvec *vecs, unsigned int tcount) |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3310 | { |
| 3311 | int ret, i; |
| 3312 | |
| 3313 | for (i = 0; i < tcount; i++) { |
| 3314 | ret = do_test_kpp(tfm, vecs++, alg); |
| 3315 | if (ret) { |
| 3316 | pr_err("alg: %s: test failed on vector %d, err=%d\n", |
| 3317 | alg, i + 1, ret); |
| 3318 | return ret; |
| 3319 | } |
| 3320 | } |
| 3321 | return 0; |
| 3322 | } |
| 3323 | |
| 3324 | static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver, |
| 3325 | u32 type, u32 mask) |
| 3326 | { |
| 3327 | struct crypto_kpp *tfm; |
| 3328 | int err = 0; |
| 3329 | |
Herbert Xu | eed93e0 | 2016-11-22 20:08:31 +0800 | [diff] [blame] | 3330 | tfm = crypto_alloc_kpp(driver, type, mask); |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3331 | if (IS_ERR(tfm)) { |
| 3332 | pr_err("alg: kpp: Failed to load tfm for %s: %ld\n", |
| 3333 | driver, PTR_ERR(tfm)); |
| 3334 | return PTR_ERR(tfm); |
| 3335 | } |
| 3336 | if (desc->suite.kpp.vecs) |
| 3337 | err = test_kpp(tfm, desc->alg, desc->suite.kpp.vecs, |
| 3338 | desc->suite.kpp.count); |
| 3339 | |
| 3340 | crypto_free_kpp(tfm); |
| 3341 | return err; |
| 3342 | } |
| 3343 | |
Vitaly Chikunov | f1774cb | 2019-04-11 18:51:17 +0300 | [diff] [blame] | 3344 | static u8 *test_pack_u32(u8 *dst, u32 val) |
| 3345 | { |
| 3346 | memcpy(dst, &val, sizeof(val)); |
| 3347 | return dst + sizeof(val); |
| 3348 | } |
| 3349 | |
Herbert Xu | 50d2b643 | 2016-06-29 19:32:20 +0800 | [diff] [blame] | 3350 | static int test_akcipher_one(struct crypto_akcipher *tfm, |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 3351 | const struct akcipher_testvec *vecs) |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3352 | { |
Herbert Xu | df27b26 | 2016-05-05 16:42:49 +0800 | [diff] [blame] | 3353 | char *xbuf[XBUFSIZE]; |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3354 | struct akcipher_request *req; |
| 3355 | void *outbuf_enc = NULL; |
| 3356 | void *outbuf_dec = NULL; |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 3357 | struct crypto_wait wait; |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3358 | unsigned int out_len_max, out_len = 0; |
| 3359 | int err = -ENOMEM; |
Vitaly Chikunov | c7381b0 | 2019-04-11 18:51:15 +0300 | [diff] [blame] | 3360 | struct scatterlist src, dst, src_tab[3]; |
Vitaly Chikunov | 0507de9 | 2019-01-07 20:54:27 +0300 | [diff] [blame] | 3361 | const char *m, *c; |
| 3362 | unsigned int m_size, c_size; |
| 3363 | const char *op; |
Vitaly Chikunov | f1774cb | 2019-04-11 18:51:17 +0300 | [diff] [blame] | 3364 | u8 *key, *ptr; |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3365 | |
Herbert Xu | df27b26 | 2016-05-05 16:42:49 +0800 | [diff] [blame] | 3366 | if (testmgr_alloc_buf(xbuf)) |
| 3367 | return err; |
| 3368 | |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3369 | req = akcipher_request_alloc(tfm, GFP_KERNEL); |
| 3370 | if (!req) |
Herbert Xu | df27b26 | 2016-05-05 16:42:49 +0800 | [diff] [blame] | 3371 | goto free_xbuf; |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3372 | |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 3373 | crypto_init_wait(&wait); |
Tadeusz Struk | 22287b0 | 2015-10-08 09:26:55 -0700 | [diff] [blame] | 3374 | |
Vitaly Chikunov | f1774cb | 2019-04-11 18:51:17 +0300 | [diff] [blame] | 3375 | key = kmalloc(vecs->key_len + sizeof(u32) * 2 + vecs->param_len, |
| 3376 | GFP_KERNEL); |
| 3377 | if (!key) |
| 3378 | goto free_xbuf; |
| 3379 | memcpy(key, vecs->key, vecs->key_len); |
| 3380 | ptr = key + vecs->key_len; |
| 3381 | ptr = test_pack_u32(ptr, vecs->algo); |
| 3382 | ptr = test_pack_u32(ptr, vecs->param_len); |
| 3383 | memcpy(ptr, vecs->params, vecs->param_len); |
| 3384 | |
Tadeusz Struk | 22287b0 | 2015-10-08 09:26:55 -0700 | [diff] [blame] | 3385 | if (vecs->public_key_vec) |
Vitaly Chikunov | f1774cb | 2019-04-11 18:51:17 +0300 | [diff] [blame] | 3386 | err = crypto_akcipher_set_pub_key(tfm, key, vecs->key_len); |
Tadeusz Struk | 22287b0 | 2015-10-08 09:26:55 -0700 | [diff] [blame] | 3387 | else |
Vitaly Chikunov | f1774cb | 2019-04-11 18:51:17 +0300 | [diff] [blame] | 3388 | err = crypto_akcipher_set_priv_key(tfm, key, vecs->key_len); |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3389 | if (err) |
| 3390 | goto free_req; |
| 3391 | |
Vitaly Chikunov | 0507de9 | 2019-01-07 20:54:27 +0300 | [diff] [blame] | 3392 | /* |
| 3393 | * First run test which do not require a private key, such as |
| 3394 | * encrypt or verify. |
| 3395 | */ |
Vitaly Chikunov | c7381b0 | 2019-04-11 18:51:15 +0300 | [diff] [blame] | 3396 | err = -ENOMEM; |
| 3397 | out_len_max = crypto_akcipher_maxsize(tfm); |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3398 | outbuf_enc = kzalloc(out_len_max, GFP_KERNEL); |
| 3399 | if (!outbuf_enc) |
| 3400 | goto free_req; |
| 3401 | |
Vitaly Chikunov | 0507de9 | 2019-01-07 20:54:27 +0300 | [diff] [blame] | 3402 | if (!vecs->siggen_sigver_test) { |
| 3403 | m = vecs->m; |
| 3404 | m_size = vecs->m_size; |
| 3405 | c = vecs->c; |
| 3406 | c_size = vecs->c_size; |
| 3407 | op = "encrypt"; |
| 3408 | } else { |
| 3409 | /* Swap args so we could keep plaintext (digest) |
| 3410 | * in vecs->m, and cooked signature in vecs->c. |
| 3411 | */ |
| 3412 | m = vecs->c; /* signature */ |
| 3413 | m_size = vecs->c_size; |
| 3414 | c = vecs->m; /* digest */ |
| 3415 | c_size = vecs->m_size; |
| 3416 | op = "verify"; |
| 3417 | } |
Herbert Xu | df27b26 | 2016-05-05 16:42:49 +0800 | [diff] [blame] | 3418 | |
Vitaly Chikunov | 0507de9 | 2019-01-07 20:54:27 +0300 | [diff] [blame] | 3419 | if (WARN_ON(m_size > PAGE_SIZE)) |
| 3420 | goto free_all; |
| 3421 | memcpy(xbuf[0], m, m_size); |
Herbert Xu | df27b26 | 2016-05-05 16:42:49 +0800 | [diff] [blame] | 3422 | |
Vitaly Chikunov | c7381b0 | 2019-04-11 18:51:15 +0300 | [diff] [blame] | 3423 | sg_init_table(src_tab, 3); |
Herbert Xu | df27b26 | 2016-05-05 16:42:49 +0800 | [diff] [blame] | 3424 | sg_set_buf(&src_tab[0], xbuf[0], 8); |
Vitaly Chikunov | 0507de9 | 2019-01-07 20:54:27 +0300 | [diff] [blame] | 3425 | sg_set_buf(&src_tab[1], xbuf[0] + 8, m_size - 8); |
Vitaly Chikunov | c7381b0 | 2019-04-11 18:51:15 +0300 | [diff] [blame] | 3426 | if (vecs->siggen_sigver_test) { |
| 3427 | if (WARN_ON(c_size > PAGE_SIZE)) |
| 3428 | goto free_all; |
| 3429 | memcpy(xbuf[1], c, c_size); |
| 3430 | sg_set_buf(&src_tab[2], xbuf[1], c_size); |
| 3431 | akcipher_request_set_crypt(req, src_tab, NULL, m_size, c_size); |
| 3432 | } else { |
| 3433 | sg_init_one(&dst, outbuf_enc, out_len_max); |
| 3434 | akcipher_request_set_crypt(req, src_tab, &dst, m_size, |
| 3435 | out_len_max); |
| 3436 | } |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3437 | akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 3438 | crypto_req_done, &wait); |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3439 | |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 3440 | err = crypto_wait_req(vecs->siggen_sigver_test ? |
Vitaly Chikunov | 0507de9 | 2019-01-07 20:54:27 +0300 | [diff] [blame] | 3441 | /* Run asymmetric signature verification */ |
| 3442 | crypto_akcipher_verify(req) : |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 3443 | /* Run asymmetric encrypt */ |
| 3444 | crypto_akcipher_encrypt(req), &wait); |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3445 | if (err) { |
Vitaly Chikunov | 0507de9 | 2019-01-07 20:54:27 +0300 | [diff] [blame] | 3446 | pr_err("alg: akcipher: %s test failed. err %d\n", op, err); |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3447 | goto free_all; |
| 3448 | } |
Vitaly Chikunov | c7381b0 | 2019-04-11 18:51:15 +0300 | [diff] [blame] | 3449 | if (!vecs->siggen_sigver_test) { |
| 3450 | if (req->dst_len != c_size) { |
| 3451 | pr_err("alg: akcipher: %s test failed. Invalid output len\n", |
| 3452 | op); |
| 3453 | err = -EINVAL; |
| 3454 | goto free_all; |
| 3455 | } |
| 3456 | /* verify that encrypted message is equal to expected */ |
| 3457 | if (memcmp(c, outbuf_enc, c_size) != 0) { |
| 3458 | pr_err("alg: akcipher: %s test failed. Invalid output\n", |
| 3459 | op); |
| 3460 | hexdump(outbuf_enc, c_size); |
| 3461 | err = -EINVAL; |
| 3462 | goto free_all; |
| 3463 | } |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3464 | } |
Vitaly Chikunov | 0507de9 | 2019-01-07 20:54:27 +0300 | [diff] [blame] | 3465 | |
| 3466 | /* |
| 3467 | * Don't invoke (decrypt or sign) test which require a private key |
| 3468 | * for vectors with only a public key. |
| 3469 | */ |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3470 | if (vecs->public_key_vec) { |
| 3471 | err = 0; |
| 3472 | goto free_all; |
| 3473 | } |
| 3474 | outbuf_dec = kzalloc(out_len_max, GFP_KERNEL); |
| 3475 | if (!outbuf_dec) { |
| 3476 | err = -ENOMEM; |
| 3477 | goto free_all; |
| 3478 | } |
Herbert Xu | df27b26 | 2016-05-05 16:42:49 +0800 | [diff] [blame] | 3479 | |
Vitaly Chikunov | 0507de9 | 2019-01-07 20:54:27 +0300 | [diff] [blame] | 3480 | op = vecs->siggen_sigver_test ? "sign" : "decrypt"; |
| 3481 | if (WARN_ON(c_size > PAGE_SIZE)) |
Herbert Xu | df27b26 | 2016-05-05 16:42:49 +0800 | [diff] [blame] | 3482 | goto free_all; |
Vitaly Chikunov | 0507de9 | 2019-01-07 20:54:27 +0300 | [diff] [blame] | 3483 | memcpy(xbuf[0], c, c_size); |
Herbert Xu | df27b26 | 2016-05-05 16:42:49 +0800 | [diff] [blame] | 3484 | |
Vitaly Chikunov | 0507de9 | 2019-01-07 20:54:27 +0300 | [diff] [blame] | 3485 | sg_init_one(&src, xbuf[0], c_size); |
Tadeusz Struk | 22287b0 | 2015-10-08 09:26:55 -0700 | [diff] [blame] | 3486 | sg_init_one(&dst, outbuf_dec, out_len_max); |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 3487 | crypto_init_wait(&wait); |
Vitaly Chikunov | 0507de9 | 2019-01-07 20:54:27 +0300 | [diff] [blame] | 3488 | akcipher_request_set_crypt(req, &src, &dst, c_size, out_len_max); |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3489 | |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 3490 | err = crypto_wait_req(vecs->siggen_sigver_test ? |
Vitaly Chikunov | 0507de9 | 2019-01-07 20:54:27 +0300 | [diff] [blame] | 3491 | /* Run asymmetric signature generation */ |
| 3492 | crypto_akcipher_sign(req) : |
Gilad Ben-Yossef | 7f39713 | 2017-10-18 08:00:43 +0100 | [diff] [blame] | 3493 | /* Run asymmetric decrypt */ |
| 3494 | crypto_akcipher_decrypt(req), &wait); |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3495 | if (err) { |
Vitaly Chikunov | 0507de9 | 2019-01-07 20:54:27 +0300 | [diff] [blame] | 3496 | pr_err("alg: akcipher: %s test failed. err %d\n", op, err); |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3497 | goto free_all; |
| 3498 | } |
| 3499 | out_len = req->dst_len; |
Vitaly Chikunov | 0507de9 | 2019-01-07 20:54:27 +0300 | [diff] [blame] | 3500 | if (out_len < m_size) { |
| 3501 | pr_err("alg: akcipher: %s test failed. Invalid output len %u\n", |
| 3502 | op, out_len); |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3503 | err = -EINVAL; |
| 3504 | goto free_all; |
| 3505 | } |
| 3506 | /* verify that decrypted message is equal to the original msg */ |
Vitaly Chikunov | 0507de9 | 2019-01-07 20:54:27 +0300 | [diff] [blame] | 3507 | if (memchr_inv(outbuf_dec, 0, out_len - m_size) || |
| 3508 | memcmp(m, outbuf_dec + out_len - m_size, m_size)) { |
| 3509 | pr_err("alg: akcipher: %s test failed. Invalid output\n", op); |
Herbert Xu | 50d2b643 | 2016-06-29 19:32:20 +0800 | [diff] [blame] | 3510 | hexdump(outbuf_dec, out_len); |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3511 | err = -EINVAL; |
| 3512 | } |
| 3513 | free_all: |
| 3514 | kfree(outbuf_dec); |
| 3515 | kfree(outbuf_enc); |
| 3516 | free_req: |
| 3517 | akcipher_request_free(req); |
Vitaly Chikunov | f1774cb | 2019-04-11 18:51:17 +0300 | [diff] [blame] | 3518 | kfree(key); |
Herbert Xu | df27b26 | 2016-05-05 16:42:49 +0800 | [diff] [blame] | 3519 | free_xbuf: |
| 3520 | testmgr_free_buf(xbuf); |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3521 | return err; |
| 3522 | } |
| 3523 | |
Herbert Xu | 50d2b643 | 2016-06-29 19:32:20 +0800 | [diff] [blame] | 3524 | static int test_akcipher(struct crypto_akcipher *tfm, const char *alg, |
Eric Biggers | b13b1e0 | 2017-02-24 15:46:59 -0800 | [diff] [blame] | 3525 | const struct akcipher_testvec *vecs, |
| 3526 | unsigned int tcount) |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3527 | { |
Herbert Xu | 15226e4 | 2016-07-18 18:20:10 +0800 | [diff] [blame] | 3528 | const char *algo = |
| 3529 | crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm)); |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3530 | int ret, i; |
| 3531 | |
| 3532 | for (i = 0; i < tcount; i++) { |
Herbert Xu | 50d2b643 | 2016-06-29 19:32:20 +0800 | [diff] [blame] | 3533 | ret = test_akcipher_one(tfm, vecs++); |
| 3534 | if (!ret) |
| 3535 | continue; |
| 3536 | |
Herbert Xu | 15226e4 | 2016-07-18 18:20:10 +0800 | [diff] [blame] | 3537 | pr_err("alg: akcipher: test %d failed for %s, err=%d\n", |
| 3538 | i + 1, algo, ret); |
Herbert Xu | 50d2b643 | 2016-06-29 19:32:20 +0800 | [diff] [blame] | 3539 | return ret; |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3540 | } |
| 3541 | return 0; |
| 3542 | } |
| 3543 | |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3544 | static int alg_test_akcipher(const struct alg_test_desc *desc, |
| 3545 | const char *driver, u32 type, u32 mask) |
| 3546 | { |
| 3547 | struct crypto_akcipher *tfm; |
| 3548 | int err = 0; |
| 3549 | |
Herbert Xu | eed93e0 | 2016-11-22 20:08:31 +0800 | [diff] [blame] | 3550 | tfm = crypto_alloc_akcipher(driver, type, mask); |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 3551 | if (IS_ERR(tfm)) { |
| 3552 | pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n", |
| 3553 | driver, PTR_ERR(tfm)); |
| 3554 | return PTR_ERR(tfm); |
| 3555 | } |
| 3556 | if (desc->suite.akcipher.vecs) |
| 3557 | err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs, |
| 3558 | desc->suite.akcipher.count); |
| 3559 | |
| 3560 | crypto_free_akcipher(tfm); |
| 3561 | return err; |
| 3562 | } |
| 3563 | |
Youquan, Song | 863b557 | 2009-12-23 19:45:20 +0800 | [diff] [blame] | 3564 | static int alg_test_null(const struct alg_test_desc *desc, |
| 3565 | const char *driver, u32 type, u32 mask) |
| 3566 | { |
| 3567 | return 0; |
| 3568 | } |
| 3569 | |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 3570 | #define __VECS(tv) { .vecs = tv, .count = ARRAY_SIZE(tv) } |
| 3571 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3572 | /* Please keep this list sorted by algorithm name. */ |
| 3573 | static const struct alg_test_desc alg_test_descs[] = { |
| 3574 | { |
Eric Biggers | 059c2a4 | 2018-11-16 17:26:31 -0800 | [diff] [blame] | 3575 | .alg = "adiantum(xchacha12,aes)", |
Eric Biggers | d435e10 | 2019-04-11 21:57:40 -0700 | [diff] [blame] | 3576 | .generic_driver = "adiantum(xchacha12-generic,aes-generic,nhpoly1305-generic)", |
Eric Biggers | 059c2a4 | 2018-11-16 17:26:31 -0800 | [diff] [blame] | 3577 | .test = alg_test_skcipher, |
| 3578 | .suite = { |
| 3579 | .cipher = __VECS(adiantum_xchacha12_aes_tv_template) |
| 3580 | }, |
| 3581 | }, { |
| 3582 | .alg = "adiantum(xchacha20,aes)", |
Eric Biggers | d435e10 | 2019-04-11 21:57:40 -0700 | [diff] [blame] | 3583 | .generic_driver = "adiantum(xchacha20-generic,aes-generic,nhpoly1305-generic)", |
Eric Biggers | 059c2a4 | 2018-11-16 17:26:31 -0800 | [diff] [blame] | 3584 | .test = alg_test_skcipher, |
| 3585 | .suite = { |
| 3586 | .cipher = __VECS(adiantum_xchacha20_aes_tv_template) |
| 3587 | }, |
| 3588 | }, { |
Ondrej Mosnacek | b87dc20 | 2018-05-11 14:12:50 +0200 | [diff] [blame] | 3589 | .alg = "aegis128", |
| 3590 | .test = alg_test_aead, |
| 3591 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3592 | .aead = __VECS(aegis128_tv_template) |
Ondrej Mosnacek | b87dc20 | 2018-05-11 14:12:50 +0200 | [diff] [blame] | 3593 | } |
| 3594 | }, { |
| 3595 | .alg = "aegis128l", |
| 3596 | .test = alg_test_aead, |
| 3597 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3598 | .aead = __VECS(aegis128l_tv_template) |
Ondrej Mosnacek | b87dc20 | 2018-05-11 14:12:50 +0200 | [diff] [blame] | 3599 | } |
| 3600 | }, { |
| 3601 | .alg = "aegis256", |
| 3602 | .test = alg_test_aead, |
| 3603 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3604 | .aead = __VECS(aegis256_tv_template) |
Ondrej Mosnacek | b87dc20 | 2018-05-11 14:12:50 +0200 | [diff] [blame] | 3605 | } |
| 3606 | }, { |
Jarod Wilson | e08ca2d | 2009-05-04 19:46:29 +0800 | [diff] [blame] | 3607 | .alg = "ansi_cprng", |
| 3608 | .test = alg_test_cprng, |
| 3609 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 3610 | .cprng = __VECS(ansi_cprng_aes_tv_template) |
Jarod Wilson | e08ca2d | 2009-05-04 19:46:29 +0800 | [diff] [blame] | 3611 | } |
| 3612 | }, { |
Horia Geanta | bca4feb | 2014-03-14 17:46:51 +0200 | [diff] [blame] | 3613 | .alg = "authenc(hmac(md5),ecb(cipher_null))", |
| 3614 | .test = alg_test_aead, |
Horia Geanta | bca4feb | 2014-03-14 17:46:51 +0200 | [diff] [blame] | 3615 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3616 | .aead = __VECS(hmac_md5_ecb_cipher_null_tv_template) |
Horia Geanta | bca4feb | 2014-03-14 17:46:51 +0200 | [diff] [blame] | 3617 | } |
| 3618 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 3619 | .alg = "authenc(hmac(sha1),cbc(aes))", |
Horia Geanta | e46e9a4 | 2012-07-03 19:16:54 +0300 | [diff] [blame] | 3620 | .test = alg_test_aead, |
Herbert Xu | bcf741c | 2017-06-28 19:09:07 +0800 | [diff] [blame] | 3621 | .fips_allowed = 1, |
Horia Geanta | e46e9a4 | 2012-07-03 19:16:54 +0300 | [diff] [blame] | 3622 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3623 | .aead = __VECS(hmac_sha1_aes_cbc_tv_temp) |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3624 | } |
| 3625 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 3626 | .alg = "authenc(hmac(sha1),cbc(des))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3627 | .test = alg_test_aead, |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3628 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3629 | .aead = __VECS(hmac_sha1_des_cbc_tv_temp) |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3630 | } |
| 3631 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 3632 | .alg = "authenc(hmac(sha1),cbc(des3_ede))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3633 | .test = alg_test_aead, |
Marcus Meissner | ed1afac | 2016-02-05 14:23:33 +0100 | [diff] [blame] | 3634 | .fips_allowed = 1, |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3635 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3636 | .aead = __VECS(hmac_sha1_des3_ede_cbc_tv_temp) |
Horia Geanta | e46e9a4 | 2012-07-03 19:16:54 +0300 | [diff] [blame] | 3637 | } |
| 3638 | }, { |
Marcus Meissner | fb16abc | 2016-02-06 11:53:07 +0100 | [diff] [blame] | 3639 | .alg = "authenc(hmac(sha1),ctr(aes))", |
| 3640 | .test = alg_test_null, |
| 3641 | .fips_allowed = 1, |
| 3642 | }, { |
Horia Geanta | bca4feb | 2014-03-14 17:46:51 +0200 | [diff] [blame] | 3643 | .alg = "authenc(hmac(sha1),ecb(cipher_null))", |
| 3644 | .test = alg_test_aead, |
Horia Geanta | bca4feb | 2014-03-14 17:46:51 +0200 | [diff] [blame] | 3645 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3646 | .aead = __VECS(hmac_sha1_ecb_cipher_null_tv_temp) |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3647 | } |
| 3648 | }, { |
Marcus Meissner | 8888690 | 2016-02-19 13:34:28 +0100 | [diff] [blame] | 3649 | .alg = "authenc(hmac(sha1),rfc3686(ctr(aes)))", |
| 3650 | .test = alg_test_null, |
| 3651 | .fips_allowed = 1, |
| 3652 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 3653 | .alg = "authenc(hmac(sha224),cbc(des))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3654 | .test = alg_test_aead, |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3655 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3656 | .aead = __VECS(hmac_sha224_des_cbc_tv_temp) |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3657 | } |
| 3658 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 3659 | .alg = "authenc(hmac(sha224),cbc(des3_ede))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3660 | .test = alg_test_aead, |
Marcus Meissner | ed1afac | 2016-02-05 14:23:33 +0100 | [diff] [blame] | 3661 | .fips_allowed = 1, |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3662 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3663 | .aead = __VECS(hmac_sha224_des3_ede_cbc_tv_temp) |
Horia Geanta | bca4feb | 2014-03-14 17:46:51 +0200 | [diff] [blame] | 3664 | } |
| 3665 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 3666 | .alg = "authenc(hmac(sha256),cbc(aes))", |
Horia Geanta | e46e9a4 | 2012-07-03 19:16:54 +0300 | [diff] [blame] | 3667 | .test = alg_test_aead, |
Marcus Meissner | ed1afac | 2016-02-05 14:23:33 +0100 | [diff] [blame] | 3668 | .fips_allowed = 1, |
Horia Geanta | e46e9a4 | 2012-07-03 19:16:54 +0300 | [diff] [blame] | 3669 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3670 | .aead = __VECS(hmac_sha256_aes_cbc_tv_temp) |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3671 | } |
| 3672 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 3673 | .alg = "authenc(hmac(sha256),cbc(des))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3674 | .test = alg_test_aead, |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3675 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3676 | .aead = __VECS(hmac_sha256_des_cbc_tv_temp) |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3677 | } |
| 3678 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 3679 | .alg = "authenc(hmac(sha256),cbc(des3_ede))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3680 | .test = alg_test_aead, |
Marcus Meissner | ed1afac | 2016-02-05 14:23:33 +0100 | [diff] [blame] | 3681 | .fips_allowed = 1, |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3682 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3683 | .aead = __VECS(hmac_sha256_des3_ede_cbc_tv_temp) |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3684 | } |
| 3685 | }, { |
Marcus Meissner | fb16abc | 2016-02-06 11:53:07 +0100 | [diff] [blame] | 3686 | .alg = "authenc(hmac(sha256),ctr(aes))", |
| 3687 | .test = alg_test_null, |
| 3688 | .fips_allowed = 1, |
| 3689 | }, { |
Marcus Meissner | 8888690 | 2016-02-19 13:34:28 +0100 | [diff] [blame] | 3690 | .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))", |
| 3691 | .test = alg_test_null, |
| 3692 | .fips_allowed = 1, |
| 3693 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 3694 | .alg = "authenc(hmac(sha384),cbc(des))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3695 | .test = alg_test_aead, |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3696 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3697 | .aead = __VECS(hmac_sha384_des_cbc_tv_temp) |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3698 | } |
| 3699 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 3700 | .alg = "authenc(hmac(sha384),cbc(des3_ede))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3701 | .test = alg_test_aead, |
Marcus Meissner | ed1afac | 2016-02-05 14:23:33 +0100 | [diff] [blame] | 3702 | .fips_allowed = 1, |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3703 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3704 | .aead = __VECS(hmac_sha384_des3_ede_cbc_tv_temp) |
Horia Geanta | e46e9a4 | 2012-07-03 19:16:54 +0300 | [diff] [blame] | 3705 | } |
| 3706 | }, { |
Marcus Meissner | fb16abc | 2016-02-06 11:53:07 +0100 | [diff] [blame] | 3707 | .alg = "authenc(hmac(sha384),ctr(aes))", |
| 3708 | .test = alg_test_null, |
| 3709 | .fips_allowed = 1, |
| 3710 | }, { |
Marcus Meissner | 8888690 | 2016-02-19 13:34:28 +0100 | [diff] [blame] | 3711 | .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))", |
| 3712 | .test = alg_test_null, |
| 3713 | .fips_allowed = 1, |
| 3714 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 3715 | .alg = "authenc(hmac(sha512),cbc(aes))", |
Marcus Meissner | ed1afac | 2016-02-05 14:23:33 +0100 | [diff] [blame] | 3716 | .fips_allowed = 1, |
Horia Geanta | e46e9a4 | 2012-07-03 19:16:54 +0300 | [diff] [blame] | 3717 | .test = alg_test_aead, |
Horia Geanta | e46e9a4 | 2012-07-03 19:16:54 +0300 | [diff] [blame] | 3718 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3719 | .aead = __VECS(hmac_sha512_aes_cbc_tv_temp) |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3720 | } |
| 3721 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 3722 | .alg = "authenc(hmac(sha512),cbc(des))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3723 | .test = alg_test_aead, |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3724 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3725 | .aead = __VECS(hmac_sha512_des_cbc_tv_temp) |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3726 | } |
| 3727 | }, { |
Herbert Xu | a4198fd | 2015-07-30 17:53:23 +0800 | [diff] [blame] | 3728 | .alg = "authenc(hmac(sha512),cbc(des3_ede))", |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3729 | .test = alg_test_aead, |
Marcus Meissner | ed1afac | 2016-02-05 14:23:33 +0100 | [diff] [blame] | 3730 | .fips_allowed = 1, |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 3731 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3732 | .aead = __VECS(hmac_sha512_des3_ede_cbc_tv_temp) |
Horia Geanta | e46e9a4 | 2012-07-03 19:16:54 +0300 | [diff] [blame] | 3733 | } |
| 3734 | }, { |
Marcus Meissner | fb16abc | 2016-02-06 11:53:07 +0100 | [diff] [blame] | 3735 | .alg = "authenc(hmac(sha512),ctr(aes))", |
| 3736 | .test = alg_test_null, |
| 3737 | .fips_allowed = 1, |
| 3738 | }, { |
Marcus Meissner | 8888690 | 2016-02-19 13:34:28 +0100 | [diff] [blame] | 3739 | .alg = "authenc(hmac(sha512),rfc3686(ctr(aes)))", |
| 3740 | .test = alg_test_null, |
| 3741 | .fips_allowed = 1, |
| 3742 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3743 | .alg = "cbc(aes)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3744 | .test = alg_test_skcipher, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3745 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3746 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3747 | .cipher = __VECS(aes_cbc_tv_template) |
| 3748 | }, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3749 | }, { |
| 3750 | .alg = "cbc(anubis)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3751 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3752 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3753 | .cipher = __VECS(anubis_cbc_tv_template) |
| 3754 | }, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3755 | }, { |
| 3756 | .alg = "cbc(blowfish)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3757 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3758 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3759 | .cipher = __VECS(bf_cbc_tv_template) |
| 3760 | }, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3761 | }, { |
| 3762 | .alg = "cbc(camellia)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3763 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3764 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3765 | .cipher = __VECS(camellia_cbc_tv_template) |
| 3766 | }, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3767 | }, { |
Johannes Goetzfried | a2c5826 | 2012-07-11 19:37:21 +0200 | [diff] [blame] | 3768 | .alg = "cbc(cast5)", |
| 3769 | .test = alg_test_skcipher, |
| 3770 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3771 | .cipher = __VECS(cast5_cbc_tv_template) |
| 3772 | }, |
Johannes Goetzfried | a2c5826 | 2012-07-11 19:37:21 +0200 | [diff] [blame] | 3773 | }, { |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 3774 | .alg = "cbc(cast6)", |
| 3775 | .test = alg_test_skcipher, |
| 3776 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3777 | .cipher = __VECS(cast6_cbc_tv_template) |
| 3778 | }, |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 3779 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3780 | .alg = "cbc(des)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3781 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3782 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3783 | .cipher = __VECS(des_cbc_tv_template) |
| 3784 | }, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3785 | }, { |
| 3786 | .alg = "cbc(des3_ede)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3787 | .test = alg_test_skcipher, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3788 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3789 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3790 | .cipher = __VECS(des3_ede_cbc_tv_template) |
| 3791 | }, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3792 | }, { |
Gilad Ben-Yossef | a794d8d | 2018-04-23 08:25:14 +0100 | [diff] [blame] | 3793 | /* Same as cbc(aes) except the key is stored in |
| 3794 | * hardware secure memory which we reference by index |
| 3795 | */ |
| 3796 | .alg = "cbc(paes)", |
| 3797 | .test = alg_test_null, |
| 3798 | .fips_allowed = 1, |
| 3799 | }, { |
Jussi Kivilinna | 9d25917 | 2011-10-18 00:02:53 +0300 | [diff] [blame] | 3800 | .alg = "cbc(serpent)", |
| 3801 | .test = alg_test_skcipher, |
| 3802 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3803 | .cipher = __VECS(serpent_cbc_tv_template) |
| 3804 | }, |
Jussi Kivilinna | 9d25917 | 2011-10-18 00:02:53 +0300 | [diff] [blame] | 3805 | }, { |
Gilad Ben-Yossef | 95ba597 | 2018-09-20 14:18:38 +0100 | [diff] [blame] | 3806 | .alg = "cbc(sm4)", |
| 3807 | .test = alg_test_skcipher, |
| 3808 | .suite = { |
| 3809 | .cipher = __VECS(sm4_cbc_tv_template) |
| 3810 | } |
| 3811 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3812 | .alg = "cbc(twofish)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3813 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3814 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3815 | .cipher = __VECS(tf_cbc_tv_template) |
| 3816 | }, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3817 | }, { |
Ard Biesheuvel | 092acf0 | 2017-02-03 14:49:35 +0000 | [diff] [blame] | 3818 | .alg = "cbcmac(aes)", |
| 3819 | .fips_allowed = 1, |
| 3820 | .test = alg_test_hash, |
| 3821 | .suite = { |
| 3822 | .hash = __VECS(aes_cbcmac_tv_template) |
| 3823 | } |
| 3824 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3825 | .alg = "ccm(aes)", |
Eric Biggers | 40153b1 | 2019-04-11 21:57:41 -0700 | [diff] [blame^] | 3826 | .generic_driver = "ccm_base(ctr(aes-generic),cbcmac(aes-generic))", |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3827 | .test = alg_test_aead, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3828 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3829 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 3830 | .aead = __VECS(aes_ccm_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3831 | } |
| 3832 | }, { |
Dmitry Eremin-Solenikov | 7da6667 | 2018-10-20 02:01:53 +0300 | [diff] [blame] | 3833 | .alg = "cfb(aes)", |
| 3834 | .test = alg_test_skcipher, |
| 3835 | .fips_allowed = 1, |
| 3836 | .suite = { |
| 3837 | .cipher = __VECS(aes_cfb_tv_template) |
| 3838 | }, |
| 3839 | }, { |
Martin Willi | 3590ebf | 2015-06-01 13:43:57 +0200 | [diff] [blame] | 3840 | .alg = "chacha20", |
| 3841 | .test = alg_test_skcipher, |
| 3842 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3843 | .cipher = __VECS(chacha20_tv_template) |
| 3844 | }, |
Martin Willi | 3590ebf | 2015-06-01 13:43:57 +0200 | [diff] [blame] | 3845 | }, { |
Jussi Kivilinna | 93b5e86 | 2013-04-08 10:48:44 +0300 | [diff] [blame] | 3846 | .alg = "cmac(aes)", |
Stephan Mueller | 8f18375 | 2015-08-19 08:42:07 +0200 | [diff] [blame] | 3847 | .fips_allowed = 1, |
Jussi Kivilinna | 93b5e86 | 2013-04-08 10:48:44 +0300 | [diff] [blame] | 3848 | .test = alg_test_hash, |
| 3849 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 3850 | .hash = __VECS(aes_cmac128_tv_template) |
Jussi Kivilinna | 93b5e86 | 2013-04-08 10:48:44 +0300 | [diff] [blame] | 3851 | } |
| 3852 | }, { |
| 3853 | .alg = "cmac(des3_ede)", |
Stephan Mueller | 8f18375 | 2015-08-19 08:42:07 +0200 | [diff] [blame] | 3854 | .fips_allowed = 1, |
Jussi Kivilinna | 93b5e86 | 2013-04-08 10:48:44 +0300 | [diff] [blame] | 3855 | .test = alg_test_hash, |
| 3856 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 3857 | .hash = __VECS(des3_ede_cmac64_tv_template) |
Jussi Kivilinna | 93b5e86 | 2013-04-08 10:48:44 +0300 | [diff] [blame] | 3858 | } |
| 3859 | }, { |
Jussi Kivilinna | e448370 | 2013-04-07 16:43:56 +0300 | [diff] [blame] | 3860 | .alg = "compress_null", |
| 3861 | .test = alg_test_null, |
| 3862 | }, { |
Ard Biesheuvel | ebb3472 | 2015-05-04 11:00:17 +0200 | [diff] [blame] | 3863 | .alg = "crc32", |
| 3864 | .test = alg_test_hash, |
Milan Broz | a8a3441 | 2019-01-25 10:31:47 +0100 | [diff] [blame] | 3865 | .fips_allowed = 1, |
Ard Biesheuvel | ebb3472 | 2015-05-04 11:00:17 +0200 | [diff] [blame] | 3866 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 3867 | .hash = __VECS(crc32_tv_template) |
Ard Biesheuvel | ebb3472 | 2015-05-04 11:00:17 +0200 | [diff] [blame] | 3868 | } |
| 3869 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3870 | .alg = "crc32c", |
Herbert Xu | 8e3ee85 | 2008-11-07 14:58:52 +0800 | [diff] [blame] | 3871 | .test = alg_test_crc32c, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3872 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3873 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 3874 | .hash = __VECS(crc32c_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3875 | } |
| 3876 | }, { |
Herbert Xu | 68411521 | 2013-09-07 12:56:26 +1000 | [diff] [blame] | 3877 | .alg = "crct10dif", |
| 3878 | .test = alg_test_hash, |
| 3879 | .fips_allowed = 1, |
| 3880 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 3881 | .hash = __VECS(crct10dif_tv_template) |
Herbert Xu | 68411521 | 2013-09-07 12:56:26 +1000 | [diff] [blame] | 3882 | } |
| 3883 | }, { |
Jarod Wilson | f7cb80f | 2009-05-06 17:29:17 +0800 | [diff] [blame] | 3884 | .alg = "ctr(aes)", |
| 3885 | .test = alg_test_skcipher, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 3886 | .fips_allowed = 1, |
Jarod Wilson | f7cb80f | 2009-05-06 17:29:17 +0800 | [diff] [blame] | 3887 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3888 | .cipher = __VECS(aes_ctr_tv_template) |
Jarod Wilson | f7cb80f | 2009-05-06 17:29:17 +0800 | [diff] [blame] | 3889 | } |
| 3890 | }, { |
Jussi Kivilinna | 85b63e3 | 2011-10-10 23:03:03 +0300 | [diff] [blame] | 3891 | .alg = "ctr(blowfish)", |
| 3892 | .test = alg_test_skcipher, |
| 3893 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3894 | .cipher = __VECS(bf_ctr_tv_template) |
Jussi Kivilinna | 85b63e3 | 2011-10-10 23:03:03 +0300 | [diff] [blame] | 3895 | } |
| 3896 | }, { |
Jussi Kivilinna | 0840605 | 2012-03-05 20:26:21 +0200 | [diff] [blame] | 3897 | .alg = "ctr(camellia)", |
| 3898 | .test = alg_test_skcipher, |
| 3899 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3900 | .cipher = __VECS(camellia_ctr_tv_template) |
Jussi Kivilinna | 0840605 | 2012-03-05 20:26:21 +0200 | [diff] [blame] | 3901 | } |
| 3902 | }, { |
Johannes Goetzfried | a2c5826 | 2012-07-11 19:37:21 +0200 | [diff] [blame] | 3903 | .alg = "ctr(cast5)", |
| 3904 | .test = alg_test_skcipher, |
| 3905 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3906 | .cipher = __VECS(cast5_ctr_tv_template) |
Johannes Goetzfried | a2c5826 | 2012-07-11 19:37:21 +0200 | [diff] [blame] | 3907 | } |
| 3908 | }, { |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 3909 | .alg = "ctr(cast6)", |
| 3910 | .test = alg_test_skcipher, |
| 3911 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3912 | .cipher = __VECS(cast6_ctr_tv_template) |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 3913 | } |
| 3914 | }, { |
Jussi Kivilinna | 8163fc3 | 2012-10-20 14:53:07 +0300 | [diff] [blame] | 3915 | .alg = "ctr(des)", |
| 3916 | .test = alg_test_skcipher, |
| 3917 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3918 | .cipher = __VECS(des_ctr_tv_template) |
Jussi Kivilinna | 8163fc3 | 2012-10-20 14:53:07 +0300 | [diff] [blame] | 3919 | } |
| 3920 | }, { |
Jussi Kivilinna | e080b17 | 2012-10-20 14:53:12 +0300 | [diff] [blame] | 3921 | .alg = "ctr(des3_ede)", |
| 3922 | .test = alg_test_skcipher, |
Marcelo Cerri | 0d8da10 | 2017-03-20 17:28:05 -0300 | [diff] [blame] | 3923 | .fips_allowed = 1, |
Jussi Kivilinna | e080b17 | 2012-10-20 14:53:12 +0300 | [diff] [blame] | 3924 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3925 | .cipher = __VECS(des3_ede_ctr_tv_template) |
Jussi Kivilinna | e080b17 | 2012-10-20 14:53:12 +0300 | [diff] [blame] | 3926 | } |
| 3927 | }, { |
Gilad Ben-Yossef | a794d8d | 2018-04-23 08:25:14 +0100 | [diff] [blame] | 3928 | /* Same as ctr(aes) except the key is stored in |
| 3929 | * hardware secure memory which we reference by index |
| 3930 | */ |
| 3931 | .alg = "ctr(paes)", |
| 3932 | .test = alg_test_null, |
| 3933 | .fips_allowed = 1, |
| 3934 | }, { |
Jussi Kivilinna | 9d25917 | 2011-10-18 00:02:53 +0300 | [diff] [blame] | 3935 | .alg = "ctr(serpent)", |
| 3936 | .test = alg_test_skcipher, |
| 3937 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3938 | .cipher = __VECS(serpent_ctr_tv_template) |
Jussi Kivilinna | 9d25917 | 2011-10-18 00:02:53 +0300 | [diff] [blame] | 3939 | } |
| 3940 | }, { |
Gilad Ben-Yossef | 95ba597 | 2018-09-20 14:18:38 +0100 | [diff] [blame] | 3941 | .alg = "ctr(sm4)", |
| 3942 | .test = alg_test_skcipher, |
| 3943 | .suite = { |
| 3944 | .cipher = __VECS(sm4_ctr_tv_template) |
| 3945 | } |
| 3946 | }, { |
Jussi Kivilinna | 573da62 | 2011-10-10 23:03:12 +0300 | [diff] [blame] | 3947 | .alg = "ctr(twofish)", |
| 3948 | .test = alg_test_skcipher, |
| 3949 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3950 | .cipher = __VECS(tf_ctr_tv_template) |
Jussi Kivilinna | 573da62 | 2011-10-10 23:03:12 +0300 | [diff] [blame] | 3951 | } |
| 3952 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3953 | .alg = "cts(cbc(aes))", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 3954 | .test = alg_test_skcipher, |
Gilad Ben-Yossef | 196ad60 | 2018-11-04 10:05:24 +0000 | [diff] [blame] | 3955 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3956 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 3957 | .cipher = __VECS(cts_mode_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3958 | } |
| 3959 | }, { |
| 3960 | .alg = "deflate", |
| 3961 | .test = alg_test_comp, |
Milan Broz | 0818904 | 2012-12-06 17:16:28 +0800 | [diff] [blame] | 3962 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3963 | .suite = { |
| 3964 | .comp = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 3965 | .comp = __VECS(deflate_comp_tv_template), |
| 3966 | .decomp = __VECS(deflate_decomp_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 3967 | } |
| 3968 | } |
| 3969 | }, { |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3970 | .alg = "dh", |
| 3971 | .test = alg_test_kpp, |
| 3972 | .fips_allowed = 1, |
| 3973 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 3974 | .kpp = __VECS(dh_tv_template) |
Salvatore Benedetto | 802c7f1 | 2016-06-22 17:49:14 +0100 | [diff] [blame] | 3975 | } |
| 3976 | }, { |
Jussi Kivilinna | e448370 | 2013-04-07 16:43:56 +0300 | [diff] [blame] | 3977 | .alg = "digest_null", |
| 3978 | .test = alg_test_null, |
| 3979 | }, { |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 3980 | .alg = "drbg_nopr_ctr_aes128", |
| 3981 | .test = alg_test_drbg, |
| 3982 | .fips_allowed = 1, |
| 3983 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 3984 | .drbg = __VECS(drbg_nopr_ctr_aes128_tv_template) |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 3985 | } |
| 3986 | }, { |
| 3987 | .alg = "drbg_nopr_ctr_aes192", |
| 3988 | .test = alg_test_drbg, |
| 3989 | .fips_allowed = 1, |
| 3990 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 3991 | .drbg = __VECS(drbg_nopr_ctr_aes192_tv_template) |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 3992 | } |
| 3993 | }, { |
| 3994 | .alg = "drbg_nopr_ctr_aes256", |
| 3995 | .test = alg_test_drbg, |
| 3996 | .fips_allowed = 1, |
| 3997 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 3998 | .drbg = __VECS(drbg_nopr_ctr_aes256_tv_template) |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 3999 | } |
| 4000 | }, { |
| 4001 | /* |
| 4002 | * There is no need to specifically test the DRBG with every |
| 4003 | * backend cipher -- covered by drbg_nopr_hmac_sha256 test |
| 4004 | */ |
| 4005 | .alg = "drbg_nopr_hmac_sha1", |
| 4006 | .fips_allowed = 1, |
| 4007 | .test = alg_test_null, |
| 4008 | }, { |
| 4009 | .alg = "drbg_nopr_hmac_sha256", |
| 4010 | .test = alg_test_drbg, |
| 4011 | .fips_allowed = 1, |
| 4012 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4013 | .drbg = __VECS(drbg_nopr_hmac_sha256_tv_template) |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 4014 | } |
| 4015 | }, { |
| 4016 | /* covered by drbg_nopr_hmac_sha256 test */ |
| 4017 | .alg = "drbg_nopr_hmac_sha384", |
| 4018 | .fips_allowed = 1, |
| 4019 | .test = alg_test_null, |
| 4020 | }, { |
| 4021 | .alg = "drbg_nopr_hmac_sha512", |
| 4022 | .test = alg_test_null, |
| 4023 | .fips_allowed = 1, |
| 4024 | }, { |
| 4025 | .alg = "drbg_nopr_sha1", |
| 4026 | .fips_allowed = 1, |
| 4027 | .test = alg_test_null, |
| 4028 | }, { |
| 4029 | .alg = "drbg_nopr_sha256", |
| 4030 | .test = alg_test_drbg, |
| 4031 | .fips_allowed = 1, |
| 4032 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4033 | .drbg = __VECS(drbg_nopr_sha256_tv_template) |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 4034 | } |
| 4035 | }, { |
| 4036 | /* covered by drbg_nopr_sha256 test */ |
| 4037 | .alg = "drbg_nopr_sha384", |
| 4038 | .fips_allowed = 1, |
| 4039 | .test = alg_test_null, |
| 4040 | }, { |
| 4041 | .alg = "drbg_nopr_sha512", |
| 4042 | .fips_allowed = 1, |
| 4043 | .test = alg_test_null, |
| 4044 | }, { |
| 4045 | .alg = "drbg_pr_ctr_aes128", |
| 4046 | .test = alg_test_drbg, |
| 4047 | .fips_allowed = 1, |
| 4048 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4049 | .drbg = __VECS(drbg_pr_ctr_aes128_tv_template) |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 4050 | } |
| 4051 | }, { |
| 4052 | /* covered by drbg_pr_ctr_aes128 test */ |
| 4053 | .alg = "drbg_pr_ctr_aes192", |
| 4054 | .fips_allowed = 1, |
| 4055 | .test = alg_test_null, |
| 4056 | }, { |
| 4057 | .alg = "drbg_pr_ctr_aes256", |
| 4058 | .fips_allowed = 1, |
| 4059 | .test = alg_test_null, |
| 4060 | }, { |
| 4061 | .alg = "drbg_pr_hmac_sha1", |
| 4062 | .fips_allowed = 1, |
| 4063 | .test = alg_test_null, |
| 4064 | }, { |
| 4065 | .alg = "drbg_pr_hmac_sha256", |
| 4066 | .test = alg_test_drbg, |
| 4067 | .fips_allowed = 1, |
| 4068 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4069 | .drbg = __VECS(drbg_pr_hmac_sha256_tv_template) |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 4070 | } |
| 4071 | }, { |
| 4072 | /* covered by drbg_pr_hmac_sha256 test */ |
| 4073 | .alg = "drbg_pr_hmac_sha384", |
| 4074 | .fips_allowed = 1, |
| 4075 | .test = alg_test_null, |
| 4076 | }, { |
| 4077 | .alg = "drbg_pr_hmac_sha512", |
| 4078 | .test = alg_test_null, |
| 4079 | .fips_allowed = 1, |
| 4080 | }, { |
| 4081 | .alg = "drbg_pr_sha1", |
| 4082 | .fips_allowed = 1, |
| 4083 | .test = alg_test_null, |
| 4084 | }, { |
| 4085 | .alg = "drbg_pr_sha256", |
| 4086 | .test = alg_test_drbg, |
| 4087 | .fips_allowed = 1, |
| 4088 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4089 | .drbg = __VECS(drbg_pr_sha256_tv_template) |
Stephan Mueller | 64d1cdf | 2014-05-31 17:25:36 +0200 | [diff] [blame] | 4090 | } |
| 4091 | }, { |
| 4092 | /* covered by drbg_pr_sha256 test */ |
| 4093 | .alg = "drbg_pr_sha384", |
| 4094 | .fips_allowed = 1, |
| 4095 | .test = alg_test_null, |
| 4096 | }, { |
| 4097 | .alg = "drbg_pr_sha512", |
| 4098 | .fips_allowed = 1, |
| 4099 | .test = alg_test_null, |
| 4100 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4101 | .alg = "ecb(aes)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4102 | .test = alg_test_skcipher, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 4103 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4104 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4105 | .cipher = __VECS(aes_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4106 | } |
| 4107 | }, { |
| 4108 | .alg = "ecb(anubis)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4109 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4110 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4111 | .cipher = __VECS(anubis_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4112 | } |
| 4113 | }, { |
| 4114 | .alg = "ecb(arc4)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4115 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4116 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4117 | .cipher = __VECS(arc4_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4118 | } |
| 4119 | }, { |
| 4120 | .alg = "ecb(blowfish)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4121 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4122 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4123 | .cipher = __VECS(bf_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4124 | } |
| 4125 | }, { |
| 4126 | .alg = "ecb(camellia)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4127 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4128 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4129 | .cipher = __VECS(camellia_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4130 | } |
| 4131 | }, { |
| 4132 | .alg = "ecb(cast5)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4133 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4134 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4135 | .cipher = __VECS(cast5_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4136 | } |
| 4137 | }, { |
| 4138 | .alg = "ecb(cast6)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4139 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4140 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4141 | .cipher = __VECS(cast6_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4142 | } |
| 4143 | }, { |
Jussi Kivilinna | e448370 | 2013-04-07 16:43:56 +0300 | [diff] [blame] | 4144 | .alg = "ecb(cipher_null)", |
| 4145 | .test = alg_test_null, |
Milan Broz | 6175ca2 | 2017-04-21 13:03:06 +0200 | [diff] [blame] | 4146 | .fips_allowed = 1, |
Jussi Kivilinna | e448370 | 2013-04-07 16:43:56 +0300 | [diff] [blame] | 4147 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4148 | .alg = "ecb(des)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4149 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4150 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4151 | .cipher = __VECS(des_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4152 | } |
| 4153 | }, { |
| 4154 | .alg = "ecb(des3_ede)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4155 | .test = alg_test_skcipher, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 4156 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4157 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4158 | .cipher = __VECS(des3_ede_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4159 | } |
| 4160 | }, { |
Jussi Kivilinna | 66e5bd0 | 2013-01-19 13:31:36 +0200 | [diff] [blame] | 4161 | .alg = "ecb(fcrypt)", |
| 4162 | .test = alg_test_skcipher, |
| 4163 | .suite = { |
| 4164 | .cipher = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4165 | .vecs = fcrypt_pcbc_tv_template, |
| 4166 | .count = 1 |
Jussi Kivilinna | 66e5bd0 | 2013-01-19 13:31:36 +0200 | [diff] [blame] | 4167 | } |
| 4168 | } |
| 4169 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4170 | .alg = "ecb(khazad)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4171 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4172 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4173 | .cipher = __VECS(khazad_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4174 | } |
| 4175 | }, { |
Gilad Ben-Yossef | 15f47ce | 2018-05-11 09:04:06 +0100 | [diff] [blame] | 4176 | /* Same as ecb(aes) except the key is stored in |
| 4177 | * hardware secure memory which we reference by index |
| 4178 | */ |
| 4179 | .alg = "ecb(paes)", |
| 4180 | .test = alg_test_null, |
| 4181 | .fips_allowed = 1, |
| 4182 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4183 | .alg = "ecb(seed)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4184 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4185 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4186 | .cipher = __VECS(seed_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4187 | } |
| 4188 | }, { |
| 4189 | .alg = "ecb(serpent)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4190 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4191 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4192 | .cipher = __VECS(serpent_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4193 | } |
| 4194 | }, { |
Gilad Ben-Yossef | cd83a8a | 2018-03-06 09:44:43 +0000 | [diff] [blame] | 4195 | .alg = "ecb(sm4)", |
| 4196 | .test = alg_test_skcipher, |
| 4197 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4198 | .cipher = __VECS(sm4_tv_template) |
Gilad Ben-Yossef | cd83a8a | 2018-03-06 09:44:43 +0000 | [diff] [blame] | 4199 | } |
| 4200 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4201 | .alg = "ecb(tea)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4202 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4203 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4204 | .cipher = __VECS(tea_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4205 | } |
| 4206 | }, { |
| 4207 | .alg = "ecb(tnepres)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4208 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4209 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4210 | .cipher = __VECS(tnepres_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4211 | } |
| 4212 | }, { |
| 4213 | .alg = "ecb(twofish)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4214 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4215 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4216 | .cipher = __VECS(tf_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4217 | } |
| 4218 | }, { |
| 4219 | .alg = "ecb(xeta)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4220 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4221 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4222 | .cipher = __VECS(xeta_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4223 | } |
| 4224 | }, { |
| 4225 | .alg = "ecb(xtea)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4226 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4227 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4228 | .cipher = __VECS(xtea_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4229 | } |
| 4230 | }, { |
Salvatore Benedetto | 3c4b239 | 2016-06-22 17:49:15 +0100 | [diff] [blame] | 4231 | .alg = "ecdh", |
| 4232 | .test = alg_test_kpp, |
| 4233 | .fips_allowed = 1, |
| 4234 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4235 | .kpp = __VECS(ecdh_tv_template) |
Salvatore Benedetto | 3c4b239 | 2016-06-22 17:49:15 +0100 | [diff] [blame] | 4236 | } |
| 4237 | }, { |
Vitaly Chikunov | 32fbdbd | 2019-04-11 18:51:21 +0300 | [diff] [blame] | 4238 | .alg = "ecrdsa", |
| 4239 | .test = alg_test_akcipher, |
| 4240 | .suite = { |
| 4241 | .akcipher = __VECS(ecrdsa_tv_template) |
| 4242 | } |
| 4243 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4244 | .alg = "gcm(aes)", |
Eric Biggers | 40153b1 | 2019-04-11 21:57:41 -0700 | [diff] [blame^] | 4245 | .generic_driver = "gcm_base(ctr(aes-generic),ghash-generic)", |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4246 | .test = alg_test_aead, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 4247 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4248 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 4249 | .aead = __VECS(aes_gcm_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4250 | } |
| 4251 | }, { |
Youquan, Song | 507069c | 2009-11-23 20:23:04 +0800 | [diff] [blame] | 4252 | .alg = "ghash", |
| 4253 | .test = alg_test_hash, |
Jarod Wilson | 18c0ebd | 2011-01-29 15:14:35 +1100 | [diff] [blame] | 4254 | .fips_allowed = 1, |
Youquan, Song | 507069c | 2009-11-23 20:23:04 +0800 | [diff] [blame] | 4255 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4256 | .hash = __VECS(ghash_tv_template) |
Youquan, Song | 507069c | 2009-11-23 20:23:04 +0800 | [diff] [blame] | 4257 | } |
| 4258 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4259 | .alg = "hmac(md5)", |
| 4260 | .test = alg_test_hash, |
| 4261 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4262 | .hash = __VECS(hmac_md5_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4263 | } |
| 4264 | }, { |
| 4265 | .alg = "hmac(rmd128)", |
| 4266 | .test = alg_test_hash, |
| 4267 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4268 | .hash = __VECS(hmac_rmd128_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4269 | } |
| 4270 | }, { |
| 4271 | .alg = "hmac(rmd160)", |
| 4272 | .test = alg_test_hash, |
| 4273 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4274 | .hash = __VECS(hmac_rmd160_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4275 | } |
| 4276 | }, { |
| 4277 | .alg = "hmac(sha1)", |
| 4278 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 4279 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4280 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4281 | .hash = __VECS(hmac_sha1_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4282 | } |
| 4283 | }, { |
| 4284 | .alg = "hmac(sha224)", |
| 4285 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 4286 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4287 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4288 | .hash = __VECS(hmac_sha224_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4289 | } |
| 4290 | }, { |
| 4291 | .alg = "hmac(sha256)", |
| 4292 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 4293 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4294 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4295 | .hash = __VECS(hmac_sha256_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4296 | } |
| 4297 | }, { |
raveendra padasalagi | 98eca72 | 2016-07-01 11:16:54 +0530 | [diff] [blame] | 4298 | .alg = "hmac(sha3-224)", |
| 4299 | .test = alg_test_hash, |
| 4300 | .fips_allowed = 1, |
| 4301 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4302 | .hash = __VECS(hmac_sha3_224_tv_template) |
raveendra padasalagi | 98eca72 | 2016-07-01 11:16:54 +0530 | [diff] [blame] | 4303 | } |
| 4304 | }, { |
| 4305 | .alg = "hmac(sha3-256)", |
| 4306 | .test = alg_test_hash, |
| 4307 | .fips_allowed = 1, |
| 4308 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4309 | .hash = __VECS(hmac_sha3_256_tv_template) |
raveendra padasalagi | 98eca72 | 2016-07-01 11:16:54 +0530 | [diff] [blame] | 4310 | } |
| 4311 | }, { |
| 4312 | .alg = "hmac(sha3-384)", |
| 4313 | .test = alg_test_hash, |
| 4314 | .fips_allowed = 1, |
| 4315 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4316 | .hash = __VECS(hmac_sha3_384_tv_template) |
raveendra padasalagi | 98eca72 | 2016-07-01 11:16:54 +0530 | [diff] [blame] | 4317 | } |
| 4318 | }, { |
| 4319 | .alg = "hmac(sha3-512)", |
| 4320 | .test = alg_test_hash, |
| 4321 | .fips_allowed = 1, |
| 4322 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4323 | .hash = __VECS(hmac_sha3_512_tv_template) |
raveendra padasalagi | 98eca72 | 2016-07-01 11:16:54 +0530 | [diff] [blame] | 4324 | } |
| 4325 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4326 | .alg = "hmac(sha384)", |
| 4327 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 4328 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4329 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4330 | .hash = __VECS(hmac_sha384_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4331 | } |
| 4332 | }, { |
| 4333 | .alg = "hmac(sha512)", |
| 4334 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 4335 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4336 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4337 | .hash = __VECS(hmac_sha512_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4338 | } |
| 4339 | }, { |
Vitaly Chikunov | 25a0b9d | 2018-11-07 00:00:03 +0300 | [diff] [blame] | 4340 | .alg = "hmac(streebog256)", |
| 4341 | .test = alg_test_hash, |
| 4342 | .suite = { |
| 4343 | .hash = __VECS(hmac_streebog256_tv_template) |
| 4344 | } |
| 4345 | }, { |
| 4346 | .alg = "hmac(streebog512)", |
| 4347 | .test = alg_test_hash, |
| 4348 | .suite = { |
| 4349 | .hash = __VECS(hmac_streebog512_tv_template) |
| 4350 | } |
| 4351 | }, { |
Stephan Mueller | bb5530e | 2015-05-25 15:10:20 +0200 | [diff] [blame] | 4352 | .alg = "jitterentropy_rng", |
| 4353 | .fips_allowed = 1, |
| 4354 | .test = alg_test_null, |
| 4355 | }, { |
Stephan Mueller | 3535198 | 2015-09-21 20:59:56 +0200 | [diff] [blame] | 4356 | .alg = "kw(aes)", |
| 4357 | .test = alg_test_skcipher, |
| 4358 | .fips_allowed = 1, |
| 4359 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4360 | .cipher = __VECS(aes_kw_tv_template) |
Stephan Mueller | 3535198 | 2015-09-21 20:59:56 +0200 | [diff] [blame] | 4361 | } |
| 4362 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4363 | .alg = "lrw(aes)", |
Eric Biggers | d435e10 | 2019-04-11 21:57:40 -0700 | [diff] [blame] | 4364 | .generic_driver = "lrw(ecb(aes-generic))", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4365 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4366 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4367 | .cipher = __VECS(aes_lrw_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4368 | } |
| 4369 | }, { |
Jussi Kivilinna | 0840605 | 2012-03-05 20:26:21 +0200 | [diff] [blame] | 4370 | .alg = "lrw(camellia)", |
Eric Biggers | d435e10 | 2019-04-11 21:57:40 -0700 | [diff] [blame] | 4371 | .generic_driver = "lrw(ecb(camellia-generic))", |
Jussi Kivilinna | 0840605 | 2012-03-05 20:26:21 +0200 | [diff] [blame] | 4372 | .test = alg_test_skcipher, |
| 4373 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4374 | .cipher = __VECS(camellia_lrw_tv_template) |
Jussi Kivilinna | 0840605 | 2012-03-05 20:26:21 +0200 | [diff] [blame] | 4375 | } |
| 4376 | }, { |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 4377 | .alg = "lrw(cast6)", |
Eric Biggers | d435e10 | 2019-04-11 21:57:40 -0700 | [diff] [blame] | 4378 | .generic_driver = "lrw(ecb(cast6-generic))", |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 4379 | .test = alg_test_skcipher, |
| 4380 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4381 | .cipher = __VECS(cast6_lrw_tv_template) |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 4382 | } |
| 4383 | }, { |
Jussi Kivilinna | d7bfc0f | 2011-10-18 13:32:34 +0300 | [diff] [blame] | 4384 | .alg = "lrw(serpent)", |
Eric Biggers | d435e10 | 2019-04-11 21:57:40 -0700 | [diff] [blame] | 4385 | .generic_driver = "lrw(ecb(serpent-generic))", |
Jussi Kivilinna | d7bfc0f | 2011-10-18 13:32:34 +0300 | [diff] [blame] | 4386 | .test = alg_test_skcipher, |
| 4387 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4388 | .cipher = __VECS(serpent_lrw_tv_template) |
Jussi Kivilinna | d7bfc0f | 2011-10-18 13:32:34 +0300 | [diff] [blame] | 4389 | } |
| 4390 | }, { |
Jussi Kivilinna | 0b2a155 | 2011-10-18 13:32:50 +0300 | [diff] [blame] | 4391 | .alg = "lrw(twofish)", |
Eric Biggers | d435e10 | 2019-04-11 21:57:40 -0700 | [diff] [blame] | 4392 | .generic_driver = "lrw(ecb(twofish-generic))", |
Jussi Kivilinna | 0b2a155 | 2011-10-18 13:32:50 +0300 | [diff] [blame] | 4393 | .test = alg_test_skcipher, |
| 4394 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4395 | .cipher = __VECS(tf_lrw_tv_template) |
Jussi Kivilinna | 0b2a155 | 2011-10-18 13:32:50 +0300 | [diff] [blame] | 4396 | } |
| 4397 | }, { |
KOVACS Krisztian | 1443cc9 | 2014-08-22 10:44:36 +0200 | [diff] [blame] | 4398 | .alg = "lz4", |
| 4399 | .test = alg_test_comp, |
| 4400 | .fips_allowed = 1, |
| 4401 | .suite = { |
| 4402 | .comp = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4403 | .comp = __VECS(lz4_comp_tv_template), |
| 4404 | .decomp = __VECS(lz4_decomp_tv_template) |
KOVACS Krisztian | 1443cc9 | 2014-08-22 10:44:36 +0200 | [diff] [blame] | 4405 | } |
| 4406 | } |
| 4407 | }, { |
| 4408 | .alg = "lz4hc", |
| 4409 | .test = alg_test_comp, |
| 4410 | .fips_allowed = 1, |
| 4411 | .suite = { |
| 4412 | .comp = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4413 | .comp = __VECS(lz4hc_comp_tv_template), |
| 4414 | .decomp = __VECS(lz4hc_decomp_tv_template) |
KOVACS Krisztian | 1443cc9 | 2014-08-22 10:44:36 +0200 | [diff] [blame] | 4415 | } |
| 4416 | } |
| 4417 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4418 | .alg = "lzo", |
| 4419 | .test = alg_test_comp, |
Milan Broz | 0818904 | 2012-12-06 17:16:28 +0800 | [diff] [blame] | 4420 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4421 | .suite = { |
| 4422 | .comp = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4423 | .comp = __VECS(lzo_comp_tv_template), |
| 4424 | .decomp = __VECS(lzo_decomp_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4425 | } |
| 4426 | } |
| 4427 | }, { |
| 4428 | .alg = "md4", |
| 4429 | .test = alg_test_hash, |
| 4430 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4431 | .hash = __VECS(md4_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4432 | } |
| 4433 | }, { |
| 4434 | .alg = "md5", |
| 4435 | .test = alg_test_hash, |
| 4436 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4437 | .hash = __VECS(md5_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4438 | } |
| 4439 | }, { |
| 4440 | .alg = "michael_mic", |
| 4441 | .test = alg_test_hash, |
| 4442 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4443 | .hash = __VECS(michael_mic_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4444 | } |
| 4445 | }, { |
Ondrej Mosnacek | 4feb4c5 | 2018-05-11 14:19:10 +0200 | [diff] [blame] | 4446 | .alg = "morus1280", |
| 4447 | .test = alg_test_aead, |
| 4448 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 4449 | .aead = __VECS(morus1280_tv_template) |
Ondrej Mosnacek | 4feb4c5 | 2018-05-11 14:19:10 +0200 | [diff] [blame] | 4450 | } |
| 4451 | }, { |
| 4452 | .alg = "morus640", |
| 4453 | .test = alg_test_aead, |
| 4454 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 4455 | .aead = __VECS(morus640_tv_template) |
Ondrej Mosnacek | 4feb4c5 | 2018-05-11 14:19:10 +0200 | [diff] [blame] | 4456 | } |
| 4457 | }, { |
Eric Biggers | 26609a2 | 2018-11-16 17:26:29 -0800 | [diff] [blame] | 4458 | .alg = "nhpoly1305", |
| 4459 | .test = alg_test_hash, |
| 4460 | .suite = { |
| 4461 | .hash = __VECS(nhpoly1305_tv_template) |
| 4462 | } |
| 4463 | }, { |
Puneet Saxena | ba0e14a | 2011-05-04 15:04:10 +1000 | [diff] [blame] | 4464 | .alg = "ofb(aes)", |
| 4465 | .test = alg_test_skcipher, |
| 4466 | .fips_allowed = 1, |
| 4467 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4468 | .cipher = __VECS(aes_ofb_tv_template) |
Puneet Saxena | ba0e14a | 2011-05-04 15:04:10 +1000 | [diff] [blame] | 4469 | } |
| 4470 | }, { |
Gilad Ben-Yossef | a794d8d | 2018-04-23 08:25:14 +0100 | [diff] [blame] | 4471 | /* Same as ofb(aes) except the key is stored in |
| 4472 | * hardware secure memory which we reference by index |
| 4473 | */ |
| 4474 | .alg = "ofb(paes)", |
| 4475 | .test = alg_test_null, |
| 4476 | .fips_allowed = 1, |
| 4477 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4478 | .alg = "pcbc(fcrypt)", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4479 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4480 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4481 | .cipher = __VECS(fcrypt_pcbc_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4482 | } |
| 4483 | }, { |
Stephan Mueller | 1207107 | 2017-06-12 23:27:51 +0200 | [diff] [blame] | 4484 | .alg = "pkcs1pad(rsa,sha224)", |
| 4485 | .test = alg_test_null, |
| 4486 | .fips_allowed = 1, |
| 4487 | }, { |
| 4488 | .alg = "pkcs1pad(rsa,sha256)", |
| 4489 | .test = alg_test_akcipher, |
| 4490 | .fips_allowed = 1, |
| 4491 | .suite = { |
| 4492 | .akcipher = __VECS(pkcs1pad_rsa_tv_template) |
| 4493 | } |
| 4494 | }, { |
| 4495 | .alg = "pkcs1pad(rsa,sha384)", |
| 4496 | .test = alg_test_null, |
| 4497 | .fips_allowed = 1, |
| 4498 | }, { |
| 4499 | .alg = "pkcs1pad(rsa,sha512)", |
| 4500 | .test = alg_test_null, |
| 4501 | .fips_allowed = 1, |
| 4502 | }, { |
Martin Willi | eee9dc6 | 2015-06-01 13:43:59 +0200 | [diff] [blame] | 4503 | .alg = "poly1305", |
| 4504 | .test = alg_test_hash, |
| 4505 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4506 | .hash = __VECS(poly1305_tv_template) |
Martin Willi | eee9dc6 | 2015-06-01 13:43:59 +0200 | [diff] [blame] | 4507 | } |
| 4508 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4509 | .alg = "rfc3686(ctr(aes))", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4510 | .test = alg_test_skcipher, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 4511 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4512 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4513 | .cipher = __VECS(aes_ctr_rfc3686_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4514 | } |
| 4515 | }, { |
Herbert Xu | 3f31a74 | 2015-07-09 07:17:34 +0800 | [diff] [blame] | 4516 | .alg = "rfc4106(gcm(aes))", |
Eric Biggers | 40153b1 | 2019-04-11 21:57:41 -0700 | [diff] [blame^] | 4517 | .generic_driver = "rfc4106(gcm_base(ctr(aes-generic),ghash-generic))", |
Adrian Hoban | 69435b9 | 2010-11-04 15:02:04 -0400 | [diff] [blame] | 4518 | .test = alg_test_aead, |
Jarod Wilson | db71f29a | 2015-01-23 12:42:15 -0500 | [diff] [blame] | 4519 | .fips_allowed = 1, |
Adrian Hoban | 69435b9 | 2010-11-04 15:02:04 -0400 | [diff] [blame] | 4520 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 4521 | .aead = __VECS(aes_gcm_rfc4106_tv_template) |
Adrian Hoban | 69435b9 | 2010-11-04 15:02:04 -0400 | [diff] [blame] | 4522 | } |
| 4523 | }, { |
Herbert Xu | 544c436 | 2015-07-14 16:53:22 +0800 | [diff] [blame] | 4524 | .alg = "rfc4309(ccm(aes))", |
Eric Biggers | 40153b1 | 2019-04-11 21:57:41 -0700 | [diff] [blame^] | 4525 | .generic_driver = "rfc4309(ccm_base(ctr(aes-generic),cbcmac(aes-generic)))", |
Jarod Wilson | 5d66732 | 2009-05-04 19:23:40 +0800 | [diff] [blame] | 4526 | .test = alg_test_aead, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 4527 | .fips_allowed = 1, |
Jarod Wilson | 5d66732 | 2009-05-04 19:23:40 +0800 | [diff] [blame] | 4528 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 4529 | .aead = __VECS(aes_ccm_rfc4309_tv_template) |
Jarod Wilson | 5d66732 | 2009-05-04 19:23:40 +0800 | [diff] [blame] | 4530 | } |
| 4531 | }, { |
Herbert Xu | bb68745 | 2015-06-16 13:54:24 +0800 | [diff] [blame] | 4532 | .alg = "rfc4543(gcm(aes))", |
Eric Biggers | 40153b1 | 2019-04-11 21:57:41 -0700 | [diff] [blame^] | 4533 | .generic_driver = "rfc4543(gcm_base(ctr(aes-generic),ghash-generic))", |
Jussi Kivilinna | e9b7441 | 2013-04-07 16:43:51 +0300 | [diff] [blame] | 4534 | .test = alg_test_aead, |
| 4535 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 4536 | .aead = __VECS(aes_gcm_rfc4543_tv_template) |
Jussi Kivilinna | e9b7441 | 2013-04-07 16:43:51 +0300 | [diff] [blame] | 4537 | } |
| 4538 | }, { |
Martin Willi | af2b76b | 2015-06-01 13:44:01 +0200 | [diff] [blame] | 4539 | .alg = "rfc7539(chacha20,poly1305)", |
| 4540 | .test = alg_test_aead, |
| 4541 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 4542 | .aead = __VECS(rfc7539_tv_template) |
Martin Willi | af2b76b | 2015-06-01 13:44:01 +0200 | [diff] [blame] | 4543 | } |
| 4544 | }, { |
Martin Willi | 5900758 | 2015-06-01 13:44:03 +0200 | [diff] [blame] | 4545 | .alg = "rfc7539esp(chacha20,poly1305)", |
| 4546 | .test = alg_test_aead, |
| 4547 | .suite = { |
Eric Biggers | a0d608ee | 2019-01-13 15:32:28 -0800 | [diff] [blame] | 4548 | .aead = __VECS(rfc7539esp_tv_template) |
Martin Willi | 5900758 | 2015-06-01 13:44:03 +0200 | [diff] [blame] | 4549 | } |
| 4550 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4551 | .alg = "rmd128", |
| 4552 | .test = alg_test_hash, |
| 4553 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4554 | .hash = __VECS(rmd128_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4555 | } |
| 4556 | }, { |
| 4557 | .alg = "rmd160", |
| 4558 | .test = alg_test_hash, |
| 4559 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4560 | .hash = __VECS(rmd160_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4561 | } |
| 4562 | }, { |
| 4563 | .alg = "rmd256", |
| 4564 | .test = alg_test_hash, |
| 4565 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4566 | .hash = __VECS(rmd256_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4567 | } |
| 4568 | }, { |
| 4569 | .alg = "rmd320", |
| 4570 | .test = alg_test_hash, |
| 4571 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4572 | .hash = __VECS(rmd320_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4573 | } |
| 4574 | }, { |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 4575 | .alg = "rsa", |
| 4576 | .test = alg_test_akcipher, |
| 4577 | .fips_allowed = 1, |
| 4578 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4579 | .akcipher = __VECS(rsa_tv_template) |
Tadeusz Struk | 946cc46 | 2015-06-16 10:31:06 -0700 | [diff] [blame] | 4580 | } |
| 4581 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4582 | .alg = "salsa20", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4583 | .test = alg_test_skcipher, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4584 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4585 | .cipher = __VECS(salsa20_stream_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4586 | } |
| 4587 | }, { |
| 4588 | .alg = "sha1", |
| 4589 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 4590 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4591 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4592 | .hash = __VECS(sha1_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4593 | } |
| 4594 | }, { |
| 4595 | .alg = "sha224", |
| 4596 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 4597 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4598 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4599 | .hash = __VECS(sha224_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4600 | } |
| 4601 | }, { |
| 4602 | .alg = "sha256", |
| 4603 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 4604 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4605 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4606 | .hash = __VECS(sha256_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4607 | } |
| 4608 | }, { |
raveendra padasalagi | 79cc6ab | 2016-06-17 10:30:36 +0530 | [diff] [blame] | 4609 | .alg = "sha3-224", |
| 4610 | .test = alg_test_hash, |
| 4611 | .fips_allowed = 1, |
| 4612 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4613 | .hash = __VECS(sha3_224_tv_template) |
raveendra padasalagi | 79cc6ab | 2016-06-17 10:30:36 +0530 | [diff] [blame] | 4614 | } |
| 4615 | }, { |
| 4616 | .alg = "sha3-256", |
| 4617 | .test = alg_test_hash, |
| 4618 | .fips_allowed = 1, |
| 4619 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4620 | .hash = __VECS(sha3_256_tv_template) |
raveendra padasalagi | 79cc6ab | 2016-06-17 10:30:36 +0530 | [diff] [blame] | 4621 | } |
| 4622 | }, { |
| 4623 | .alg = "sha3-384", |
| 4624 | .test = alg_test_hash, |
| 4625 | .fips_allowed = 1, |
| 4626 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4627 | .hash = __VECS(sha3_384_tv_template) |
raveendra padasalagi | 79cc6ab | 2016-06-17 10:30:36 +0530 | [diff] [blame] | 4628 | } |
| 4629 | }, { |
| 4630 | .alg = "sha3-512", |
| 4631 | .test = alg_test_hash, |
| 4632 | .fips_allowed = 1, |
| 4633 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4634 | .hash = __VECS(sha3_512_tv_template) |
raveendra padasalagi | 79cc6ab | 2016-06-17 10:30:36 +0530 | [diff] [blame] | 4635 | } |
| 4636 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4637 | .alg = "sha384", |
| 4638 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 4639 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4640 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4641 | .hash = __VECS(sha384_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4642 | } |
| 4643 | }, { |
| 4644 | .alg = "sha512", |
| 4645 | .test = alg_test_hash, |
Jarod Wilson | a1915d5 | 2009-05-15 15:16:03 +1000 | [diff] [blame] | 4646 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4647 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4648 | .hash = __VECS(sha512_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4649 | } |
| 4650 | }, { |
Gilad Ben-Yossef | b7e2753 | 2017-08-21 13:51:29 +0300 | [diff] [blame] | 4651 | .alg = "sm3", |
| 4652 | .test = alg_test_hash, |
| 4653 | .suite = { |
| 4654 | .hash = __VECS(sm3_tv_template) |
| 4655 | } |
| 4656 | }, { |
Vitaly Chikunov | 25a0b9d | 2018-11-07 00:00:03 +0300 | [diff] [blame] | 4657 | .alg = "streebog256", |
| 4658 | .test = alg_test_hash, |
| 4659 | .suite = { |
| 4660 | .hash = __VECS(streebog256_tv_template) |
| 4661 | } |
| 4662 | }, { |
| 4663 | .alg = "streebog512", |
| 4664 | .test = alg_test_hash, |
| 4665 | .suite = { |
| 4666 | .hash = __VECS(streebog512_tv_template) |
| 4667 | } |
| 4668 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4669 | .alg = "tgr128", |
| 4670 | .test = alg_test_hash, |
| 4671 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4672 | .hash = __VECS(tgr128_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4673 | } |
| 4674 | }, { |
| 4675 | .alg = "tgr160", |
| 4676 | .test = alg_test_hash, |
| 4677 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4678 | .hash = __VECS(tgr160_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4679 | } |
| 4680 | }, { |
| 4681 | .alg = "tgr192", |
| 4682 | .test = alg_test_hash, |
| 4683 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4684 | .hash = __VECS(tgr192_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4685 | } |
| 4686 | }, { |
Eric Biggers | ed331ad | 2018-06-18 10:22:39 -0700 | [diff] [blame] | 4687 | .alg = "vmac64(aes)", |
| 4688 | .test = alg_test_hash, |
| 4689 | .suite = { |
| 4690 | .hash = __VECS(vmac64_aes_tv_template) |
| 4691 | } |
| 4692 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4693 | .alg = "wp256", |
| 4694 | .test = alg_test_hash, |
| 4695 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4696 | .hash = __VECS(wp256_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4697 | } |
| 4698 | }, { |
| 4699 | .alg = "wp384", |
| 4700 | .test = alg_test_hash, |
| 4701 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4702 | .hash = __VECS(wp384_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4703 | } |
| 4704 | }, { |
| 4705 | .alg = "wp512", |
| 4706 | .test = alg_test_hash, |
| 4707 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4708 | .hash = __VECS(wp512_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4709 | } |
| 4710 | }, { |
| 4711 | .alg = "xcbc(aes)", |
| 4712 | .test = alg_test_hash, |
| 4713 | .suite = { |
Ard Biesheuvel | 21c8e72 | 2017-01-12 13:40:39 +0000 | [diff] [blame] | 4714 | .hash = __VECS(aes_xcbc128_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4715 | } |
| 4716 | }, { |
Eric Biggers | aa76240 | 2018-11-16 17:26:22 -0800 | [diff] [blame] | 4717 | .alg = "xchacha12", |
| 4718 | .test = alg_test_skcipher, |
| 4719 | .suite = { |
| 4720 | .cipher = __VECS(xchacha12_tv_template) |
| 4721 | }, |
| 4722 | }, { |
Eric Biggers | de61d7a | 2018-11-16 17:26:20 -0800 | [diff] [blame] | 4723 | .alg = "xchacha20", |
| 4724 | .test = alg_test_skcipher, |
| 4725 | .suite = { |
| 4726 | .cipher = __VECS(xchacha20_tv_template) |
| 4727 | }, |
| 4728 | }, { |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4729 | .alg = "xts(aes)", |
Eric Biggers | d435e10 | 2019-04-11 21:57:40 -0700 | [diff] [blame] | 4730 | .generic_driver = "xts(ecb(aes-generic))", |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4731 | .test = alg_test_skcipher, |
Jarod Wilson | 2918aa8 | 2011-01-29 15:14:01 +1100 | [diff] [blame] | 4732 | .fips_allowed = 1, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4733 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4734 | .cipher = __VECS(aes_xts_tv_template) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4735 | } |
Geert Uytterhoeven | 0c01aed | 2009-03-04 15:42:15 +0800 | [diff] [blame] | 4736 | }, { |
Jussi Kivilinna | 0840605 | 2012-03-05 20:26:21 +0200 | [diff] [blame] | 4737 | .alg = "xts(camellia)", |
Eric Biggers | d435e10 | 2019-04-11 21:57:40 -0700 | [diff] [blame] | 4738 | .generic_driver = "xts(ecb(camellia-generic))", |
Jussi Kivilinna | 0840605 | 2012-03-05 20:26:21 +0200 | [diff] [blame] | 4739 | .test = alg_test_skcipher, |
| 4740 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4741 | .cipher = __VECS(camellia_xts_tv_template) |
Jussi Kivilinna | 0840605 | 2012-03-05 20:26:21 +0200 | [diff] [blame] | 4742 | } |
| 4743 | }, { |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 4744 | .alg = "xts(cast6)", |
Eric Biggers | d435e10 | 2019-04-11 21:57:40 -0700 | [diff] [blame] | 4745 | .generic_driver = "xts(ecb(cast6-generic))", |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 4746 | .test = alg_test_skcipher, |
| 4747 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4748 | .cipher = __VECS(cast6_xts_tv_template) |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 4749 | } |
| 4750 | }, { |
Gilad Ben-Yossef | 15f47ce | 2018-05-11 09:04:06 +0100 | [diff] [blame] | 4751 | /* Same as xts(aes) except the key is stored in |
| 4752 | * hardware secure memory which we reference by index |
| 4753 | */ |
| 4754 | .alg = "xts(paes)", |
| 4755 | .test = alg_test_null, |
| 4756 | .fips_allowed = 1, |
| 4757 | }, { |
Jussi Kivilinna | 18be20b9 | 2011-10-18 13:33:17 +0300 | [diff] [blame] | 4758 | .alg = "xts(serpent)", |
Eric Biggers | d435e10 | 2019-04-11 21:57:40 -0700 | [diff] [blame] | 4759 | .generic_driver = "xts(ecb(serpent-generic))", |
Jussi Kivilinna | 18be20b9 | 2011-10-18 13:33:17 +0300 | [diff] [blame] | 4760 | .test = alg_test_skcipher, |
| 4761 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4762 | .cipher = __VECS(serpent_xts_tv_template) |
Jussi Kivilinna | 18be20b9 | 2011-10-18 13:33:17 +0300 | [diff] [blame] | 4763 | } |
| 4764 | }, { |
Jussi Kivilinna | aed265b | 2011-10-18 13:33:33 +0300 | [diff] [blame] | 4765 | .alg = "xts(twofish)", |
Eric Biggers | d435e10 | 2019-04-11 21:57:40 -0700 | [diff] [blame] | 4766 | .generic_driver = "xts(ecb(twofish-generic))", |
Jussi Kivilinna | aed265b | 2011-10-18 13:33:33 +0300 | [diff] [blame] | 4767 | .test = alg_test_skcipher, |
| 4768 | .suite = { |
Eric Biggers | 92a4c9f | 2018-05-20 22:50:29 -0700 | [diff] [blame] | 4769 | .cipher = __VECS(tf_xts_tv_template) |
Jussi Kivilinna | aed265b | 2011-10-18 13:33:33 +0300 | [diff] [blame] | 4770 | } |
Giovanni Cabiddu | a368f43 | 2017-04-21 21:54:30 +0100 | [diff] [blame] | 4771 | }, { |
Gilad Ben-Yossef | 15f47ce | 2018-05-11 09:04:06 +0100 | [diff] [blame] | 4772 | .alg = "xts4096(paes)", |
| 4773 | .test = alg_test_null, |
| 4774 | .fips_allowed = 1, |
| 4775 | }, { |
| 4776 | .alg = "xts512(paes)", |
| 4777 | .test = alg_test_null, |
| 4778 | .fips_allowed = 1, |
| 4779 | }, { |
Giovanni Cabiddu | a368f43 | 2017-04-21 21:54:30 +0100 | [diff] [blame] | 4780 | .alg = "zlib-deflate", |
| 4781 | .test = alg_test_comp, |
| 4782 | .fips_allowed = 1, |
| 4783 | .suite = { |
| 4784 | .comp = { |
| 4785 | .comp = __VECS(zlib_deflate_comp_tv_template), |
| 4786 | .decomp = __VECS(zlib_deflate_decomp_tv_template) |
| 4787 | } |
| 4788 | } |
Nick Terrell | d28fc3d | 2018-03-30 12:14:53 -0700 | [diff] [blame] | 4789 | }, { |
| 4790 | .alg = "zstd", |
| 4791 | .test = alg_test_comp, |
| 4792 | .fips_allowed = 1, |
| 4793 | .suite = { |
| 4794 | .comp = { |
| 4795 | .comp = __VECS(zstd_comp_tv_template), |
| 4796 | .decomp = __VECS(zstd_decomp_tv_template) |
| 4797 | } |
| 4798 | } |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4799 | } |
| 4800 | }; |
| 4801 | |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 4802 | static void alg_check_test_descs_order(void) |
Jussi Kivilinna | 5714758 | 2013-06-13 17:37:40 +0300 | [diff] [blame] | 4803 | { |
| 4804 | int i; |
| 4805 | |
Jussi Kivilinna | 5714758 | 2013-06-13 17:37:40 +0300 | [diff] [blame] | 4806 | for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) { |
| 4807 | int diff = strcmp(alg_test_descs[i - 1].alg, |
| 4808 | alg_test_descs[i].alg); |
| 4809 | |
| 4810 | if (WARN_ON(diff > 0)) { |
| 4811 | pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n", |
| 4812 | alg_test_descs[i - 1].alg, |
| 4813 | alg_test_descs[i].alg); |
| 4814 | } |
| 4815 | |
| 4816 | if (WARN_ON(diff == 0)) { |
| 4817 | pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n", |
| 4818 | alg_test_descs[i].alg); |
| 4819 | } |
| 4820 | } |
| 4821 | } |
| 4822 | |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 4823 | static void alg_check_testvec_configs(void) |
| 4824 | { |
Eric Biggers | 4e7babba | 2019-01-31 23:51:46 -0800 | [diff] [blame] | 4825 | int i; |
| 4826 | |
| 4827 | for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) |
| 4828 | WARN_ON(!valid_testvec_config( |
| 4829 | &default_cipher_testvec_configs[i])); |
Eric Biggers | 4cc2dcf | 2019-01-31 23:51:48 -0800 | [diff] [blame] | 4830 | |
| 4831 | for (i = 0; i < ARRAY_SIZE(default_hash_testvec_configs); i++) |
| 4832 | WARN_ON(!valid_testvec_config( |
| 4833 | &default_hash_testvec_configs[i])); |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | static void testmgr_onetime_init(void) |
| 4837 | { |
| 4838 | alg_check_test_descs_order(); |
| 4839 | alg_check_testvec_configs(); |
Eric Biggers | 5b2706a | 2019-01-31 23:51:44 -0800 | [diff] [blame] | 4840 | |
| 4841 | #ifdef CONFIG_CRYPTO_MANAGER_EXTRA_TESTS |
| 4842 | pr_warn("alg: extra crypto tests enabled. This is intended for developer use only.\n"); |
| 4843 | #endif |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 4844 | } |
| 4845 | |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4846 | static int alg_find_test(const char *alg) |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4847 | { |
| 4848 | int start = 0; |
| 4849 | int end = ARRAY_SIZE(alg_test_descs); |
| 4850 | |
| 4851 | while (start < end) { |
| 4852 | int i = (start + end) / 2; |
| 4853 | int diff = strcmp(alg_test_descs[i].alg, alg); |
| 4854 | |
| 4855 | if (diff > 0) { |
| 4856 | end = i; |
| 4857 | continue; |
| 4858 | } |
| 4859 | |
| 4860 | if (diff < 0) { |
| 4861 | start = i + 1; |
| 4862 | continue; |
| 4863 | } |
| 4864 | |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4865 | return i; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4866 | } |
| 4867 | |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4868 | return -1; |
| 4869 | } |
| 4870 | |
| 4871 | int alg_test(const char *driver, const char *alg, u32 type, u32 mask) |
| 4872 | { |
| 4873 | int i; |
Herbert Xu | a68f661 | 2009-07-02 16:32:12 +0800 | [diff] [blame] | 4874 | int j; |
Neil Horman | d12d6b6 | 2008-10-12 20:36:51 +0800 | [diff] [blame] | 4875 | int rc; |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4876 | |
Richard W.M. Jones | 9e5c9fe | 2016-05-03 10:00:17 +0100 | [diff] [blame] | 4877 | if (!fips_enabled && notests) { |
| 4878 | printk_once(KERN_INFO "alg: self-tests disabled\n"); |
| 4879 | return 0; |
| 4880 | } |
| 4881 | |
Eric Biggers | 3f47a03 | 2019-01-31 23:51:43 -0800 | [diff] [blame] | 4882 | DO_ONCE(testmgr_onetime_init); |
Jussi Kivilinna | 5714758 | 2013-06-13 17:37:40 +0300 | [diff] [blame] | 4883 | |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4884 | if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) { |
| 4885 | char nalg[CRYPTO_MAX_ALG_NAME]; |
| 4886 | |
| 4887 | if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >= |
| 4888 | sizeof(nalg)) |
| 4889 | return -ENAMETOOLONG; |
| 4890 | |
| 4891 | i = alg_find_test(nalg); |
| 4892 | if (i < 0) |
| 4893 | goto notest; |
| 4894 | |
Jarod Wilson | a3bef3a | 2009-05-15 15:17:05 +1000 | [diff] [blame] | 4895 | if (fips_enabled && !alg_test_descs[i].fips_allowed) |
| 4896 | goto non_fips_alg; |
| 4897 | |
Jarod Wilson | 941fb32 | 2009-05-04 19:49:23 +0800 | [diff] [blame] | 4898 | rc = alg_test_cipher(alg_test_descs + i, driver, type, mask); |
| 4899 | goto test_done; |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4900 | } |
| 4901 | |
| 4902 | i = alg_find_test(alg); |
Herbert Xu | a68f661 | 2009-07-02 16:32:12 +0800 | [diff] [blame] | 4903 | j = alg_find_test(driver); |
| 4904 | if (i < 0 && j < 0) |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4905 | goto notest; |
| 4906 | |
Herbert Xu | a68f661 | 2009-07-02 16:32:12 +0800 | [diff] [blame] | 4907 | if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) || |
| 4908 | (j >= 0 && !alg_test_descs[j].fips_allowed))) |
Jarod Wilson | a3bef3a | 2009-05-15 15:17:05 +1000 | [diff] [blame] | 4909 | goto non_fips_alg; |
| 4910 | |
Herbert Xu | a68f661 | 2009-07-02 16:32:12 +0800 | [diff] [blame] | 4911 | rc = 0; |
| 4912 | if (i >= 0) |
| 4913 | rc |= alg_test_descs[i].test(alg_test_descs + i, driver, |
| 4914 | type, mask); |
Cristian Stoica | 032c8ca | 2013-07-18 18:57:07 +0300 | [diff] [blame] | 4915 | if (j >= 0 && j != i) |
Herbert Xu | a68f661 | 2009-07-02 16:32:12 +0800 | [diff] [blame] | 4916 | rc |= alg_test_descs[j].test(alg_test_descs + j, driver, |
| 4917 | type, mask); |
| 4918 | |
Jarod Wilson | 941fb32 | 2009-05-04 19:49:23 +0800 | [diff] [blame] | 4919 | test_done: |
Eric Biggers | eda69b0 | 2019-03-31 13:09:14 -0700 | [diff] [blame] | 4920 | if (rc && (fips_enabled || panic_on_fail)) |
| 4921 | panic("alg: self-tests for %s (%s) failed in %s mode!\n", |
| 4922 | driver, alg, fips_enabled ? "fips" : "panic_on_fail"); |
Neil Horman | d12d6b6 | 2008-10-12 20:36:51 +0800 | [diff] [blame] | 4923 | |
Jarod Wilson | 29ecd4a | 2009-05-04 19:51:17 +0800 | [diff] [blame] | 4924 | if (fips_enabled && !rc) |
Masanari Iida | 3e8cffd | 2014-10-07 00:37:54 +0900 | [diff] [blame] | 4925 | pr_info("alg: self-tests for %s (%s) passed\n", driver, alg); |
Jarod Wilson | 29ecd4a | 2009-05-04 19:51:17 +0800 | [diff] [blame] | 4926 | |
Neil Horman | d12d6b6 | 2008-10-12 20:36:51 +0800 | [diff] [blame] | 4927 | return rc; |
Herbert Xu | 1aa4ecd | 2008-08-17 17:01:56 +1000 | [diff] [blame] | 4928 | |
| 4929 | notest: |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4930 | printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver); |
| 4931 | return 0; |
Jarod Wilson | a3bef3a | 2009-05-15 15:17:05 +1000 | [diff] [blame] | 4932 | non_fips_alg: |
| 4933 | return -EINVAL; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4934 | } |
Alexander Shishkin | 0b767f9 | 2010-06-03 20:53:43 +1000 | [diff] [blame] | 4935 | |
Herbert Xu | 326a634 | 2010-08-06 09:40:28 +0800 | [diff] [blame] | 4936 | #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */ |
Alexander Shishkin | 0b767f9 | 2010-06-03 20:53:43 +1000 | [diff] [blame] | 4937 | |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 4938 | EXPORT_SYMBOL_GPL(alg_test); |