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