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