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