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