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