blob: f205386167765af583d3710d79015d8d65a1802f [file] [log] [blame]
Herbert Xuda7f0332008-07-31 17:08:25 +08001/*
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>
8 *
Adrian Hoban69435b92010-11-04 15:02:04 -04009 * Updated RFC4106 AES-GCM testing.
10 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
11 * Adrian Hoban <adrian.hoban@intel.com>
12 * Gabriele Paoloni <gabriele.paoloni@intel.com>
13 * Tadeusz Struk (tadeusz.struk@intel.com)
14 * Copyright (c) 2010, Intel Corporation.
15 *
Herbert Xuda7f0332008-07-31 17:08:25 +080016 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the Free
18 * Software Foundation; either version 2 of the License, or (at your option)
19 * any later version.
20 *
21 */
22
23#include <crypto/hash.h>
24#include <linux/err.h>
25#include <linux/module.h>
26#include <linux/scatterlist.h>
27#include <linux/slab.h>
28#include <linux/string.h>
Jarod Wilson7647d6c2009-05-04 19:44:50 +080029#include <crypto/rng.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080030
31#include "internal.h"
Alexander Shishkin0b767f92010-06-03 20:53:43 +100032
Herbert Xu326a6342010-08-06 09:40:28 +080033#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
Alexander Shishkin0b767f92010-06-03 20:53:43 +100034
35/* a perfect nop */
36int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
37{
38 return 0;
39}
40
41#else
42
Herbert Xuda7f0332008-07-31 17:08:25 +080043#include "testmgr.h"
44
45/*
46 * Need slab memory for testing (size in number of pages).
47 */
48#define XBUFSIZE 8
49
50/*
51 * Indexes into the xbuf to simulate cross-page access.
52 */
53#define IDX1 32
54#define IDX2 32400
55#define IDX3 1
56#define IDX4 8193
57#define IDX5 22222
58#define IDX6 17101
59#define IDX7 27333
60#define IDX8 3000
61
62/*
63* Used by test_cipher()
64*/
65#define ENCRYPT 1
66#define DECRYPT 0
67
68struct tcrypt_result {
69 struct completion completion;
70 int err;
71};
72
73struct aead_test_suite {
74 struct {
75 struct aead_testvec *vecs;
76 unsigned int count;
77 } enc, dec;
78};
79
80struct cipher_test_suite {
81 struct {
82 struct cipher_testvec *vecs;
83 unsigned int count;
84 } enc, dec;
85};
86
87struct comp_test_suite {
88 struct {
89 struct comp_testvec *vecs;
90 unsigned int count;
91 } comp, decomp;
92};
93
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +080094struct pcomp_test_suite {
95 struct {
96 struct pcomp_testvec *vecs;
97 unsigned int count;
98 } comp, decomp;
99};
100
Herbert Xuda7f0332008-07-31 17:08:25 +0800101struct hash_test_suite {
102 struct hash_testvec *vecs;
103 unsigned int count;
104};
105
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800106struct cprng_test_suite {
107 struct cprng_testvec *vecs;
108 unsigned int count;
109};
110
Herbert Xuda7f0332008-07-31 17:08:25 +0800111struct alg_test_desc {
112 const char *alg;
113 int (*test)(const struct alg_test_desc *desc, const char *driver,
114 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000115 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800116
117 union {
118 struct aead_test_suite aead;
119 struct cipher_test_suite cipher;
120 struct comp_test_suite comp;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +0800121 struct pcomp_test_suite pcomp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800122 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800123 struct cprng_test_suite cprng;
Herbert Xuda7f0332008-07-31 17:08:25 +0800124 } suite;
125};
126
127static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
128
Herbert Xuda7f0332008-07-31 17:08:25 +0800129static void hexdump(unsigned char *buf, unsigned int len)
130{
131 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
132 16, 1,
133 buf, len, false);
134}
135
136static void tcrypt_complete(struct crypto_async_request *req, int err)
137{
138 struct tcrypt_result *res = req->data;
139
140 if (err == -EINPROGRESS)
141 return;
142
143 res->err = err;
144 complete(&res->completion);
145}
146
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800147static int testmgr_alloc_buf(char *buf[XBUFSIZE])
148{
149 int i;
150
151 for (i = 0; i < XBUFSIZE; i++) {
152 buf[i] = (void *)__get_free_page(GFP_KERNEL);
153 if (!buf[i])
154 goto err_free_buf;
155 }
156
157 return 0;
158
159err_free_buf:
160 while (i-- > 0)
161 free_page((unsigned long)buf[i]);
162
163 return -ENOMEM;
164}
165
166static void testmgr_free_buf(char *buf[XBUFSIZE])
167{
168 int i;
169
170 for (i = 0; i < XBUFSIZE; i++)
171 free_page((unsigned long)buf[i]);
172}
173
David S. Millera8f1a052010-05-19 14:12:03 +1000174static int do_one_async_hash_op(struct ahash_request *req,
175 struct tcrypt_result *tr,
176 int ret)
177{
178 if (ret == -EINPROGRESS || ret == -EBUSY) {
179 ret = wait_for_completion_interruptible(&tr->completion);
180 if (!ret)
181 ret = tr->err;
182 INIT_COMPLETION(tr->completion);
183 }
184 return ret;
185}
186
Herbert Xuda7f0332008-07-31 17:08:25 +0800187static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
David S. Millera8f1a052010-05-19 14:12:03 +1000188 unsigned int tcount, bool use_digest)
Herbert Xuda7f0332008-07-31 17:08:25 +0800189{
190 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
191 unsigned int i, j, k, temp;
192 struct scatterlist sg[8];
193 char result[64];
194 struct ahash_request *req;
195 struct tcrypt_result tresult;
Herbert Xuda7f0332008-07-31 17:08:25 +0800196 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800197 char *xbuf[XBUFSIZE];
198 int ret = -ENOMEM;
199
200 if (testmgr_alloc_buf(xbuf))
201 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800202
203 init_completion(&tresult.completion);
204
205 req = ahash_request_alloc(tfm, GFP_KERNEL);
206 if (!req) {
207 printk(KERN_ERR "alg: hash: Failed to allocate request for "
208 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800209 goto out_noreq;
210 }
211 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
212 tcrypt_complete, &tresult);
213
Herbert Xua0cfae52009-05-29 16:23:12 +1000214 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800215 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000216 if (template[i].np)
217 continue;
218
219 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800220 memset(result, 0, 64);
221
222 hash_buff = xbuf[0];
223
224 memcpy(hash_buff, template[i].plaintext, template[i].psize);
225 sg_init_one(&sg[0], hash_buff, template[i].psize);
226
227 if (template[i].ksize) {
228 crypto_ahash_clear_flags(tfm, ~0);
229 ret = crypto_ahash_setkey(tfm, template[i].key,
230 template[i].ksize);
231 if (ret) {
232 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000233 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800234 -ret);
235 goto out;
236 }
237 }
238
239 ahash_request_set_crypt(req, sg, result, template[i].psize);
David S. Millera8f1a052010-05-19 14:12:03 +1000240 if (use_digest) {
241 ret = do_one_async_hash_op(req, &tresult,
242 crypto_ahash_digest(req));
243 if (ret) {
244 pr_err("alg: hash: digest failed on test %d "
245 "for %s: ret=%d\n", j, algo, -ret);
246 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800247 }
David S. Millera8f1a052010-05-19 14:12:03 +1000248 } else {
249 ret = do_one_async_hash_op(req, &tresult,
250 crypto_ahash_init(req));
251 if (ret) {
252 pr_err("alt: hash: init failed on test %d "
253 "for %s: ret=%d\n", j, algo, -ret);
254 goto out;
255 }
256 ret = do_one_async_hash_op(req, &tresult,
257 crypto_ahash_update(req));
258 if (ret) {
259 pr_err("alt: hash: update failed on test %d "
260 "for %s: ret=%d\n", j, algo, -ret);
261 goto out;
262 }
263 ret = do_one_async_hash_op(req, &tresult,
264 crypto_ahash_final(req));
265 if (ret) {
266 pr_err("alt: hash: final failed on test %d "
267 "for %s: ret=%d\n", j, algo, -ret);
268 goto out;
269 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800270 }
271
272 if (memcmp(result, template[i].digest,
273 crypto_ahash_digestsize(tfm))) {
274 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000275 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800276 hexdump(result, crypto_ahash_digestsize(tfm));
277 ret = -EINVAL;
278 goto out;
279 }
280 }
281
282 j = 0;
283 for (i = 0; i < tcount; i++) {
284 if (template[i].np) {
285 j++;
286 memset(result, 0, 64);
287
288 temp = 0;
289 sg_init_table(sg, template[i].np);
Herbert Xufd57f222009-05-29 16:05:42 +1000290 ret = -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +0800291 for (k = 0; k < template[i].np; k++) {
Herbert Xufd57f222009-05-29 16:05:42 +1000292 if (WARN_ON(offset_in_page(IDX[k]) +
293 template[i].tap[k] > PAGE_SIZE))
294 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800295 sg_set_buf(&sg[k],
296 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
297 offset_in_page(IDX[k]),
298 template[i].plaintext + temp,
299 template[i].tap[k]),
300 template[i].tap[k]);
301 temp += template[i].tap[k];
302 }
303
304 if (template[i].ksize) {
305 crypto_ahash_clear_flags(tfm, ~0);
306 ret = crypto_ahash_setkey(tfm, template[i].key,
307 template[i].ksize);
308
309 if (ret) {
310 printk(KERN_ERR "alg: hash: setkey "
311 "failed on chunking test %d "
312 "for %s: ret=%d\n", j, algo,
313 -ret);
314 goto out;
315 }
316 }
317
318 ahash_request_set_crypt(req, sg, result,
319 template[i].psize);
320 ret = crypto_ahash_digest(req);
321 switch (ret) {
322 case 0:
323 break;
324 case -EINPROGRESS:
325 case -EBUSY:
326 ret = wait_for_completion_interruptible(
327 &tresult.completion);
328 if (!ret && !(ret = tresult.err)) {
329 INIT_COMPLETION(tresult.completion);
330 break;
331 }
332 /* fall through */
333 default:
334 printk(KERN_ERR "alg: hash: digest failed "
335 "on chunking test %d for %s: "
336 "ret=%d\n", j, algo, -ret);
337 goto out;
338 }
339
340 if (memcmp(result, template[i].digest,
341 crypto_ahash_digestsize(tfm))) {
342 printk(KERN_ERR "alg: hash: Chunking test %d "
343 "failed for %s\n", j, algo);
344 hexdump(result, crypto_ahash_digestsize(tfm));
345 ret = -EINVAL;
346 goto out;
347 }
348 }
349 }
350
351 ret = 0;
352
353out:
354 ahash_request_free(req);
355out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800356 testmgr_free_buf(xbuf);
357out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +0800358 return ret;
359}
360
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300361static int __test_aead(struct crypto_aead *tfm, int enc,
362 struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300363 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800364{
365 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
366 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800367 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800368 char *q;
369 char *key;
370 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300371 struct scatterlist *sg;
372 struct scatterlist *asg;
373 struct scatterlist *sgout;
374 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800375 struct tcrypt_result result;
376 unsigned int authsize;
377 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300378 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800379 void *assoc;
380 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800381 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300382 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800383 char *axbuf[XBUFSIZE];
384
385 if (testmgr_alloc_buf(xbuf))
386 goto out_noxbuf;
387 if (testmgr_alloc_buf(axbuf))
388 goto out_noaxbuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800389
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300390 if (diff_dst && testmgr_alloc_buf(xoutbuf))
391 goto out_nooutbuf;
392
393 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
394 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL);
395 if (!sg)
396 goto out_nosg;
397 asg = &sg[8];
398 sgout = &asg[8];
399
400 if (diff_dst)
401 d = "-ddst";
402 else
403 d = "";
404
Herbert Xuda7f0332008-07-31 17:08:25 +0800405 if (enc == ENCRYPT)
406 e = "encryption";
407 else
408 e = "decryption";
409
410 init_completion(&result.completion);
411
412 req = aead_request_alloc(tfm, GFP_KERNEL);
413 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300414 pr_err("alg: aead%s: Failed to allocate request for %s\n",
415 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800416 goto out;
417 }
418
419 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
420 tcrypt_complete, &result);
421
422 for (i = 0, j = 0; i < tcount; i++) {
423 if (!template[i].np) {
424 j++;
425
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300426 /* some templates have no input data but they will
Herbert Xuda7f0332008-07-31 17:08:25 +0800427 * touch input
428 */
429 input = xbuf[0];
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300430 input += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800431 assoc = axbuf[0];
432
Herbert Xufd57f222009-05-29 16:05:42 +1000433 ret = -EINVAL;
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300434 if (WARN_ON(align_offset + template[i].ilen >
435 PAGE_SIZE || template[i].alen > PAGE_SIZE))
Herbert Xufd57f222009-05-29 16:05:42 +1000436 goto out;
437
Herbert Xuda7f0332008-07-31 17:08:25 +0800438 memcpy(input, template[i].input, template[i].ilen);
439 memcpy(assoc, template[i].assoc, template[i].alen);
440 if (template[i].iv)
441 memcpy(iv, template[i].iv, MAX_IVLEN);
442 else
443 memset(iv, 0, MAX_IVLEN);
444
445 crypto_aead_clear_flags(tfm, ~0);
446 if (template[i].wk)
447 crypto_aead_set_flags(
448 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
449
450 key = template[i].key;
451
452 ret = crypto_aead_setkey(tfm, key,
453 template[i].klen);
454 if (!ret == template[i].fail) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300455 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
456 d, j, algo, crypto_aead_get_flags(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +0800457 goto out;
458 } else if (ret)
459 continue;
460
461 authsize = abs(template[i].rlen - template[i].ilen);
462 ret = crypto_aead_setauthsize(tfm, authsize);
463 if (ret) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300464 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
465 d, authsize, j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800466 goto out;
467 }
468
469 sg_init_one(&sg[0], input,
470 template[i].ilen + (enc ? authsize : 0));
471
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300472 if (diff_dst) {
473 output = xoutbuf[0];
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300474 output += align_offset;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300475 sg_init_one(&sgout[0], output,
476 template[i].ilen +
477 (enc ? authsize : 0));
478 } else {
479 output = input;
480 }
481
Herbert Xuda7f0332008-07-31 17:08:25 +0800482 sg_init_one(&asg[0], assoc, template[i].alen);
483
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300484 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Herbert Xuda7f0332008-07-31 17:08:25 +0800485 template[i].ilen, iv);
486
487 aead_request_set_assoc(req, asg, template[i].alen);
488
489 ret = enc ?
490 crypto_aead_encrypt(req) :
491 crypto_aead_decrypt(req);
492
493 switch (ret) {
494 case 0:
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800495 if (template[i].novrfy) {
496 /* verification was supposed to fail */
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300497 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
498 d, e, j, algo);
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800499 /* so really, we got a bad message */
500 ret = -EBADMSG;
501 goto out;
502 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800503 break;
504 case -EINPROGRESS:
505 case -EBUSY:
506 ret = wait_for_completion_interruptible(
507 &result.completion);
508 if (!ret && !(ret = result.err)) {
509 INIT_COMPLETION(result.completion);
510 break;
511 }
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800512 case -EBADMSG:
513 if (template[i].novrfy)
514 /* verification failure was expected */
515 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800516 /* fall through */
517 default:
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300518 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
519 d, e, j, algo, -ret);
Herbert Xuda7f0332008-07-31 17:08:25 +0800520 goto out;
521 }
522
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300523 q = output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800524 if (memcmp(q, template[i].result, template[i].rlen)) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300525 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
526 d, j, e, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800527 hexdump(q, template[i].rlen);
528 ret = -EINVAL;
529 goto out;
530 }
531 }
532 }
533
534 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300535 /* alignment tests are only done with continuous buffers */
536 if (align_offset != 0)
537 break;
538
Herbert Xuda7f0332008-07-31 17:08:25 +0800539 if (template[i].np) {
540 j++;
541
542 if (template[i].iv)
543 memcpy(iv, template[i].iv, MAX_IVLEN);
544 else
545 memset(iv, 0, MAX_IVLEN);
546
547 crypto_aead_clear_flags(tfm, ~0);
548 if (template[i].wk)
549 crypto_aead_set_flags(
550 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
551 key = template[i].key;
552
553 ret = crypto_aead_setkey(tfm, key, template[i].klen);
554 if (!ret == template[i].fail) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300555 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
556 d, j, algo, crypto_aead_get_flags(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +0800557 goto out;
558 } else if (ret)
559 continue;
560
561 authsize = abs(template[i].rlen - template[i].ilen);
562
563 ret = -EINVAL;
564 sg_init_table(sg, template[i].np);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300565 if (diff_dst)
566 sg_init_table(sgout, template[i].np);
Herbert Xuda7f0332008-07-31 17:08:25 +0800567 for (k = 0, temp = 0; k < template[i].np; k++) {
568 if (WARN_ON(offset_in_page(IDX[k]) +
569 template[i].tap[k] > PAGE_SIZE))
570 goto out;
571
572 q = xbuf[IDX[k] >> PAGE_SHIFT] +
573 offset_in_page(IDX[k]);
574
575 memcpy(q, template[i].input + temp,
576 template[i].tap[k]);
577
578 n = template[i].tap[k];
579 if (k == template[i].np - 1 && enc)
580 n += authsize;
581 if (offset_in_page(q) + n < PAGE_SIZE)
582 q[n] = 0;
583
584 sg_set_buf(&sg[k], q, template[i].tap[k]);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300585
586 if (diff_dst) {
587 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
588 offset_in_page(IDX[k]);
589
590 memset(q, 0, template[i].tap[k]);
591 if (offset_in_page(q) + n < PAGE_SIZE)
592 q[n] = 0;
593
594 sg_set_buf(&sgout[k], q,
595 template[i].tap[k]);
596 }
597
Herbert Xuda7f0332008-07-31 17:08:25 +0800598 temp += template[i].tap[k];
599 }
600
601 ret = crypto_aead_setauthsize(tfm, authsize);
602 if (ret) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300603 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
604 d, authsize, j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800605 goto out;
606 }
607
608 if (enc) {
609 if (WARN_ON(sg[k - 1].offset +
610 sg[k - 1].length + authsize >
611 PAGE_SIZE)) {
612 ret = -EINVAL;
613 goto out;
614 }
615
616 sg[k - 1].length += authsize;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300617
618 if (diff_dst)
619 sgout[k - 1].length += authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800620 }
621
622 sg_init_table(asg, template[i].anp);
Herbert Xufd57f222009-05-29 16:05:42 +1000623 ret = -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +0800624 for (k = 0, temp = 0; k < template[i].anp; k++) {
Herbert Xufd57f222009-05-29 16:05:42 +1000625 if (WARN_ON(offset_in_page(IDX[k]) +
626 template[i].atap[k] > PAGE_SIZE))
627 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800628 sg_set_buf(&asg[k],
629 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
630 offset_in_page(IDX[k]),
631 template[i].assoc + temp,
632 template[i].atap[k]),
633 template[i].atap[k]);
634 temp += template[i].atap[k];
635 }
636
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300637 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Herbert Xuda7f0332008-07-31 17:08:25 +0800638 template[i].ilen,
639 iv);
640
641 aead_request_set_assoc(req, asg, template[i].alen);
642
643 ret = enc ?
644 crypto_aead_encrypt(req) :
645 crypto_aead_decrypt(req);
646
647 switch (ret) {
648 case 0:
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800649 if (template[i].novrfy) {
650 /* verification was supposed to fail */
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300651 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
652 d, e, j, algo);
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800653 /* so really, we got a bad message */
654 ret = -EBADMSG;
655 goto out;
656 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800657 break;
658 case -EINPROGRESS:
659 case -EBUSY:
660 ret = wait_for_completion_interruptible(
661 &result.completion);
662 if (!ret && !(ret = result.err)) {
663 INIT_COMPLETION(result.completion);
664 break;
665 }
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800666 case -EBADMSG:
667 if (template[i].novrfy)
668 /* verification failure was expected */
669 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800670 /* fall through */
671 default:
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300672 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
673 d, e, j, algo, -ret);
Herbert Xuda7f0332008-07-31 17:08:25 +0800674 goto out;
675 }
676
677 ret = -EINVAL;
678 for (k = 0, temp = 0; k < template[i].np; k++) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300679 if (diff_dst)
680 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
681 offset_in_page(IDX[k]);
682 else
683 q = xbuf[IDX[k] >> PAGE_SHIFT] +
684 offset_in_page(IDX[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +0800685
686 n = template[i].tap[k];
687 if (k == template[i].np - 1)
688 n += enc ? authsize : -authsize;
689
690 if (memcmp(q, template[i].result + temp, n)) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300691 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
692 d, j, e, k, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800693 hexdump(q, n);
694 goto out;
695 }
696
697 q += n;
698 if (k == template[i].np - 1 && !enc) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300699 if (!diff_dst &&
700 memcmp(q, template[i].input +
Herbert Xuda7f0332008-07-31 17:08:25 +0800701 temp + n, authsize))
702 n = authsize;
703 else
704 n = 0;
705 } else {
706 for (n = 0; offset_in_page(q + n) &&
707 q[n]; n++)
708 ;
709 }
710 if (n) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300711 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
712 d, j, e, k, algo, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800713 hexdump(q, n);
714 goto out;
715 }
716
717 temp += template[i].tap[k];
718 }
719 }
720 }
721
722 ret = 0;
723
724out:
725 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300726 kfree(sg);
727out_nosg:
728 if (diff_dst)
729 testmgr_free_buf(xoutbuf);
730out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800731 testmgr_free_buf(axbuf);
732out_noaxbuf:
733 testmgr_free_buf(xbuf);
734out_noxbuf:
Herbert Xuda7f0332008-07-31 17:08:25 +0800735 return ret;
736}
737
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300738static int test_aead(struct crypto_aead *tfm, int enc,
739 struct aead_testvec *template, unsigned int tcount)
740{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300741 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300742 int ret;
743
744 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300745 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300746 if (ret)
747 return ret;
748
749 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300750 ret = __test_aead(tfm, enc, template, tcount, true, 0);
751 if (ret)
752 return ret;
753
754 /* test unaligned buffers, check with one byte offset */
755 ret = __test_aead(tfm, enc, template, tcount, true, 1);
756 if (ret)
757 return ret;
758
759 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
760 if (alignmask) {
761 /* Check if alignment mask for tfm is correctly set. */
762 ret = __test_aead(tfm, enc, template, tcount, true,
763 alignmask + 1);
764 if (ret)
765 return ret;
766 }
767
768 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300769}
770
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000771static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800772 struct cipher_testvec *template, unsigned int tcount)
773{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000774 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
775 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000776 char *q;
777 const char *e;
778 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800779 char *xbuf[XBUFSIZE];
780 int ret = -ENOMEM;
781
782 if (testmgr_alloc_buf(xbuf))
783 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000784
785 if (enc == ENCRYPT)
786 e = "encryption";
787 else
788 e = "decryption";
789
790 j = 0;
791 for (i = 0; i < tcount; i++) {
792 if (template[i].np)
793 continue;
794
795 j++;
796
Herbert Xufd57f222009-05-29 16:05:42 +1000797 ret = -EINVAL;
798 if (WARN_ON(template[i].ilen > PAGE_SIZE))
799 goto out;
800
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000801 data = xbuf[0];
802 memcpy(data, template[i].input, template[i].ilen);
803
804 crypto_cipher_clear_flags(tfm, ~0);
805 if (template[i].wk)
806 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
807
808 ret = crypto_cipher_setkey(tfm, template[i].key,
809 template[i].klen);
810 if (!ret == template[i].fail) {
811 printk(KERN_ERR "alg: cipher: setkey failed "
812 "on test %d for %s: flags=%x\n", j,
813 algo, crypto_cipher_get_flags(tfm));
814 goto out;
815 } else if (ret)
816 continue;
817
818 for (k = 0; k < template[i].ilen;
819 k += crypto_cipher_blocksize(tfm)) {
820 if (enc)
821 crypto_cipher_encrypt_one(tfm, data + k,
822 data + k);
823 else
824 crypto_cipher_decrypt_one(tfm, data + k,
825 data + k);
826 }
827
828 q = data;
829 if (memcmp(q, template[i].result, template[i].rlen)) {
830 printk(KERN_ERR "alg: cipher: Test %d failed "
831 "on %s for %s\n", j, e, algo);
832 hexdump(q, template[i].rlen);
833 ret = -EINVAL;
834 goto out;
835 }
836 }
837
838 ret = 0;
839
840out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800841 testmgr_free_buf(xbuf);
842out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000843 return ret;
844}
845
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300846static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
847 struct cipher_testvec *template, unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300848 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000849{
Herbert Xuda7f0332008-07-31 17:08:25 +0800850 const char *algo =
851 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
852 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800853 char *q;
854 struct ablkcipher_request *req;
855 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300856 struct scatterlist sgout[8];
857 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800858 struct tcrypt_result result;
859 void *data;
860 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800861 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300862 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800863 int ret = -ENOMEM;
864
865 if (testmgr_alloc_buf(xbuf))
866 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800867
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300868 if (diff_dst && testmgr_alloc_buf(xoutbuf))
869 goto out_nooutbuf;
870
871 if (diff_dst)
872 d = "-ddst";
873 else
874 d = "";
875
Herbert Xuda7f0332008-07-31 17:08:25 +0800876 if (enc == ENCRYPT)
877 e = "encryption";
878 else
879 e = "decryption";
880
881 init_completion(&result.completion);
882
883 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
884 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300885 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
886 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800887 goto out;
888 }
889
890 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
891 tcrypt_complete, &result);
892
893 j = 0;
894 for (i = 0; i < tcount; i++) {
895 if (template[i].iv)
896 memcpy(iv, template[i].iv, MAX_IVLEN);
897 else
898 memset(iv, 0, MAX_IVLEN);
899
Jussi Kivilinnaf44d83d2012-09-19 09:42:49 +0300900 if (!(template[i].np) || (template[i].also_non_np)) {
Herbert Xuda7f0332008-07-31 17:08:25 +0800901 j++;
902
Herbert Xufd57f222009-05-29 16:05:42 +1000903 ret = -EINVAL;
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300904 if (WARN_ON(align_offset + template[i].ilen >
905 PAGE_SIZE))
Herbert Xufd57f222009-05-29 16:05:42 +1000906 goto out;
907
Herbert Xuda7f0332008-07-31 17:08:25 +0800908 data = xbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300909 data += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800910 memcpy(data, template[i].input, template[i].ilen);
911
912 crypto_ablkcipher_clear_flags(tfm, ~0);
913 if (template[i].wk)
914 crypto_ablkcipher_set_flags(
915 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
916
917 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
918 template[i].klen);
919 if (!ret == template[i].fail) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300920 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
921 d, j, algo,
922 crypto_ablkcipher_get_flags(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +0800923 goto out;
924 } else if (ret)
925 continue;
926
927 sg_init_one(&sg[0], data, template[i].ilen);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300928 if (diff_dst) {
929 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300930 data += align_offset;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300931 sg_init_one(&sgout[0], data, template[i].ilen);
932 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800933
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300934 ablkcipher_request_set_crypt(req, sg,
935 (diff_dst) ? sgout : sg,
Herbert Xuda7f0332008-07-31 17:08:25 +0800936 template[i].ilen, iv);
937 ret = enc ?
938 crypto_ablkcipher_encrypt(req) :
939 crypto_ablkcipher_decrypt(req);
940
941 switch (ret) {
942 case 0:
943 break;
944 case -EINPROGRESS:
945 case -EBUSY:
946 ret = wait_for_completion_interruptible(
947 &result.completion);
948 if (!ret && !((ret = result.err))) {
949 INIT_COMPLETION(result.completion);
950 break;
951 }
952 /* fall through */
953 default:
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300954 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
955 d, e, j, algo, -ret);
Herbert Xuda7f0332008-07-31 17:08:25 +0800956 goto out;
957 }
958
959 q = data;
960 if (memcmp(q, template[i].result, template[i].rlen)) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300961 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
962 d, j, e, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800963 hexdump(q, template[i].rlen);
964 ret = -EINVAL;
965 goto out;
966 }
967 }
968 }
969
970 j = 0;
971 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300972 /* alignment tests are only done with continuous buffers */
973 if (align_offset != 0)
974 break;
Herbert Xuda7f0332008-07-31 17:08:25 +0800975
976 if (template[i].iv)
977 memcpy(iv, template[i].iv, MAX_IVLEN);
978 else
979 memset(iv, 0, MAX_IVLEN);
980
981 if (template[i].np) {
982 j++;
983
984 crypto_ablkcipher_clear_flags(tfm, ~0);
985 if (template[i].wk)
986 crypto_ablkcipher_set_flags(
987 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
988
989 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
990 template[i].klen);
991 if (!ret == template[i].fail) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300992 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
993 d, j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800994 crypto_ablkcipher_get_flags(tfm));
995 goto out;
996 } else if (ret)
997 continue;
998
999 temp = 0;
1000 ret = -EINVAL;
1001 sg_init_table(sg, template[i].np);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001002 if (diff_dst)
1003 sg_init_table(sgout, template[i].np);
Herbert Xuda7f0332008-07-31 17:08:25 +08001004 for (k = 0; k < template[i].np; k++) {
1005 if (WARN_ON(offset_in_page(IDX[k]) +
1006 template[i].tap[k] > PAGE_SIZE))
1007 goto out;
1008
1009 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1010 offset_in_page(IDX[k]);
1011
1012 memcpy(q, template[i].input + temp,
1013 template[i].tap[k]);
1014
1015 if (offset_in_page(q) + template[i].tap[k] <
1016 PAGE_SIZE)
1017 q[template[i].tap[k]] = 0;
1018
1019 sg_set_buf(&sg[k], q, template[i].tap[k]);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001020 if (diff_dst) {
1021 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1022 offset_in_page(IDX[k]);
1023
1024 sg_set_buf(&sgout[k], q,
1025 template[i].tap[k]);
1026
1027 memset(q, 0, template[i].tap[k]);
1028 if (offset_in_page(q) +
1029 template[i].tap[k] < PAGE_SIZE)
1030 q[template[i].tap[k]] = 0;
1031 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001032
1033 temp += template[i].tap[k];
1034 }
1035
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001036 ablkcipher_request_set_crypt(req, sg,
1037 (diff_dst) ? sgout : sg,
Herbert Xuda7f0332008-07-31 17:08:25 +08001038 template[i].ilen, iv);
1039
1040 ret = enc ?
1041 crypto_ablkcipher_encrypt(req) :
1042 crypto_ablkcipher_decrypt(req);
1043
1044 switch (ret) {
1045 case 0:
1046 break;
1047 case -EINPROGRESS:
1048 case -EBUSY:
1049 ret = wait_for_completion_interruptible(
1050 &result.completion);
1051 if (!ret && !((ret = result.err))) {
1052 INIT_COMPLETION(result.completion);
1053 break;
1054 }
1055 /* fall through */
1056 default:
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001057 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1058 d, e, j, algo, -ret);
Herbert Xuda7f0332008-07-31 17:08:25 +08001059 goto out;
1060 }
1061
1062 temp = 0;
1063 ret = -EINVAL;
1064 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001065 if (diff_dst)
1066 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1067 offset_in_page(IDX[k]);
1068 else
1069 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1070 offset_in_page(IDX[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001071
1072 if (memcmp(q, template[i].result + temp,
1073 template[i].tap[k])) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001074 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1075 d, j, e, k, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +08001076 hexdump(q, template[i].tap[k]);
1077 goto out;
1078 }
1079
1080 q += template[i].tap[k];
1081 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1082 ;
1083 if (n) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001084 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1085 d, j, e, k, algo, n);
Herbert Xuda7f0332008-07-31 17:08:25 +08001086 hexdump(q, n);
1087 goto out;
1088 }
1089 temp += template[i].tap[k];
1090 }
1091 }
1092 }
1093
1094 ret = 0;
1095
1096out:
1097 ablkcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001098 if (diff_dst)
1099 testmgr_free_buf(xoutbuf);
1100out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001101 testmgr_free_buf(xbuf);
1102out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001103 return ret;
1104}
1105
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001106static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1107 struct cipher_testvec *template, unsigned int tcount)
1108{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001109 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001110 int ret;
1111
1112 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001113 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001114 if (ret)
1115 return ret;
1116
1117 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001118 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1119 if (ret)
1120 return ret;
1121
1122 /* test unaligned buffers, check with one byte offset */
1123 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1124 if (ret)
1125 return ret;
1126
1127 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1128 if (alignmask) {
1129 /* Check if alignment mask for tfm is correctly set. */
1130 ret = __test_skcipher(tfm, enc, template, tcount, true,
1131 alignmask + 1);
1132 if (ret)
1133 return ret;
1134 }
1135
1136 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001137}
1138
Herbert Xuda7f0332008-07-31 17:08:25 +08001139static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1140 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1141{
1142 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1143 unsigned int i;
1144 char result[COMP_BUF_SIZE];
1145 int ret;
1146
1147 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001148 int ilen;
1149 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001150
1151 memset(result, 0, sizeof (result));
1152
1153 ilen = ctemplate[i].inlen;
1154 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1155 ilen, result, &dlen);
1156 if (ret) {
1157 printk(KERN_ERR "alg: comp: compression failed "
1158 "on test %d for %s: ret=%d\n", i + 1, algo,
1159 -ret);
1160 goto out;
1161 }
1162
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001163 if (dlen != ctemplate[i].outlen) {
1164 printk(KERN_ERR "alg: comp: Compression test %d "
1165 "failed for %s: output len = %d\n", i + 1, algo,
1166 dlen);
1167 ret = -EINVAL;
1168 goto out;
1169 }
1170
Herbert Xuda7f0332008-07-31 17:08:25 +08001171 if (memcmp(result, ctemplate[i].output, dlen)) {
1172 printk(KERN_ERR "alg: comp: Compression test %d "
1173 "failed for %s\n", i + 1, algo);
1174 hexdump(result, dlen);
1175 ret = -EINVAL;
1176 goto out;
1177 }
1178 }
1179
1180 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001181 int ilen;
1182 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001183
1184 memset(result, 0, sizeof (result));
1185
1186 ilen = dtemplate[i].inlen;
1187 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1188 ilen, result, &dlen);
1189 if (ret) {
1190 printk(KERN_ERR "alg: comp: decompression failed "
1191 "on test %d for %s: ret=%d\n", i + 1, algo,
1192 -ret);
1193 goto out;
1194 }
1195
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001196 if (dlen != dtemplate[i].outlen) {
1197 printk(KERN_ERR "alg: comp: Decompression test %d "
1198 "failed for %s: output len = %d\n", i + 1, algo,
1199 dlen);
1200 ret = -EINVAL;
1201 goto out;
1202 }
1203
Herbert Xuda7f0332008-07-31 17:08:25 +08001204 if (memcmp(result, dtemplate[i].output, dlen)) {
1205 printk(KERN_ERR "alg: comp: Decompression test %d "
1206 "failed for %s\n", i + 1, algo);
1207 hexdump(result, dlen);
1208 ret = -EINVAL;
1209 goto out;
1210 }
1211 }
1212
1213 ret = 0;
1214
1215out:
1216 return ret;
1217}
1218
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001219static int test_pcomp(struct crypto_pcomp *tfm,
1220 struct pcomp_testvec *ctemplate,
1221 struct pcomp_testvec *dtemplate, int ctcount,
1222 int dtcount)
1223{
1224 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1225 unsigned int i;
1226 char result[COMP_BUF_SIZE];
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001227 int res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001228
1229 for (i = 0; i < ctcount; i++) {
1230 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001231 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001232
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001233 res = crypto_compress_setup(tfm, ctemplate[i].params,
1234 ctemplate[i].paramsize);
1235 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001236 pr_err("alg: pcomp: compression setup failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001237 "%d for %s: error=%d\n", i + 1, algo, res);
1238 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001239 }
1240
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001241 res = crypto_compress_init(tfm);
1242 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001243 pr_err("alg: pcomp: compression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001244 "%d for %s: error=%d\n", i + 1, algo, res);
1245 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001246 }
1247
1248 memset(result, 0, sizeof(result));
1249
1250 req.next_in = ctemplate[i].input;
1251 req.avail_in = ctemplate[i].inlen / 2;
1252 req.next_out = result;
1253 req.avail_out = ctemplate[i].outlen / 2;
1254
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001255 res = crypto_compress_update(tfm, &req);
1256 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001257 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001258 "%d for %s: error=%d\n", i + 1, algo, res);
1259 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001260 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001261 if (res > 0)
1262 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001263
1264 /* Add remaining input data */
1265 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1266
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001267 res = crypto_compress_update(tfm, &req);
1268 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001269 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001270 "%d for %s: error=%d\n", i + 1, algo, res);
1271 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001272 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001273 if (res > 0)
1274 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001275
1276 /* Provide remaining output space */
1277 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1278
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001279 res = crypto_compress_final(tfm, &req);
1280 if (res < 0) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001281 pr_err("alg: pcomp: compression final failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001282 "%d for %s: error=%d\n", i + 1, algo, res);
1283 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001284 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001285 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001286
1287 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1288 pr_err("alg: comp: Compression test %d failed for %s: "
1289 "output len = %d (expected %d)\n", i + 1, algo,
1290 COMP_BUF_SIZE - req.avail_out,
1291 ctemplate[i].outlen);
1292 return -EINVAL;
1293 }
1294
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001295 if (produced != ctemplate[i].outlen) {
1296 pr_err("alg: comp: Compression test %d failed for %s: "
1297 "returned len = %u (expected %d)\n", i + 1,
1298 algo, produced, ctemplate[i].outlen);
1299 return -EINVAL;
1300 }
1301
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001302 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1303 pr_err("alg: pcomp: Compression test %d failed for "
1304 "%s\n", i + 1, algo);
1305 hexdump(result, ctemplate[i].outlen);
1306 return -EINVAL;
1307 }
1308 }
1309
1310 for (i = 0; i < dtcount; i++) {
1311 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001312 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001313
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001314 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1315 dtemplate[i].paramsize);
1316 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001317 pr_err("alg: pcomp: decompression setup failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001318 "test %d for %s: error=%d\n", i + 1, algo, res);
1319 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001320 }
1321
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001322 res = crypto_decompress_init(tfm);
1323 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001324 pr_err("alg: pcomp: decompression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001325 "%d for %s: error=%d\n", i + 1, algo, res);
1326 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001327 }
1328
1329 memset(result, 0, sizeof(result));
1330
1331 req.next_in = dtemplate[i].input;
1332 req.avail_in = dtemplate[i].inlen / 2;
1333 req.next_out = result;
1334 req.avail_out = dtemplate[i].outlen / 2;
1335
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001336 res = crypto_decompress_update(tfm, &req);
1337 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001338 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001339 "test %d for %s: error=%d\n", i + 1, algo, res);
1340 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001341 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001342 if (res > 0)
1343 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001344
1345 /* Add remaining input data */
1346 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1347
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001348 res = crypto_decompress_update(tfm, &req);
1349 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001350 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001351 "test %d for %s: error=%d\n", i + 1, algo, res);
1352 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001353 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001354 if (res > 0)
1355 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001356
1357 /* Provide remaining output space */
1358 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1359
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001360 res = crypto_decompress_final(tfm, &req);
1361 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001362 pr_err("alg: pcomp: decompression final failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001363 "test %d for %s: error=%d\n", i + 1, algo, res);
1364 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001365 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001366 if (res > 0)
1367 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001368
1369 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1370 pr_err("alg: comp: Decompression test %d failed for "
1371 "%s: output len = %d (expected %d)\n", i + 1,
1372 algo, COMP_BUF_SIZE - req.avail_out,
1373 dtemplate[i].outlen);
1374 return -EINVAL;
1375 }
1376
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001377 if (produced != dtemplate[i].outlen) {
1378 pr_err("alg: comp: Decompression test %d failed for "
1379 "%s: returned len = %u (expected %d)\n", i + 1,
1380 algo, produced, dtemplate[i].outlen);
1381 return -EINVAL;
1382 }
1383
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001384 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1385 pr_err("alg: pcomp: Decompression test %d failed for "
1386 "%s\n", i + 1, algo);
1387 hexdump(result, dtemplate[i].outlen);
1388 return -EINVAL;
1389 }
1390 }
1391
1392 return 0;
1393}
1394
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001395
1396static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1397 unsigned int tcount)
1398{
1399 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001400 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001401 u8 *seed;
1402 char result[32];
1403
1404 seedsize = crypto_rng_seedsize(tfm);
1405
1406 seed = kmalloc(seedsize, GFP_KERNEL);
1407 if (!seed) {
1408 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1409 "for %s\n", algo);
1410 return -ENOMEM;
1411 }
1412
1413 for (i = 0; i < tcount; i++) {
1414 memset(result, 0, 32);
1415
1416 memcpy(seed, template[i].v, template[i].vlen);
1417 memcpy(seed + template[i].vlen, template[i].key,
1418 template[i].klen);
1419 memcpy(seed + template[i].vlen + template[i].klen,
1420 template[i].dt, template[i].dtlen);
1421
1422 err = crypto_rng_reset(tfm, seed, seedsize);
1423 if (err) {
1424 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1425 "for %s\n", algo);
1426 goto out;
1427 }
1428
1429 for (j = 0; j < template[i].loops; j++) {
1430 err = crypto_rng_get_bytes(tfm, result,
1431 template[i].rlen);
1432 if (err != template[i].rlen) {
1433 printk(KERN_ERR "alg: cprng: Failed to obtain "
1434 "the correct amount of random data for "
1435 "%s (requested %d, got %d)\n", algo,
1436 template[i].rlen, err);
1437 goto out;
1438 }
1439 }
1440
1441 err = memcmp(result, template[i].result,
1442 template[i].rlen);
1443 if (err) {
1444 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1445 i, algo);
1446 hexdump(result, template[i].rlen);
1447 err = -EINVAL;
1448 goto out;
1449 }
1450 }
1451
1452out:
1453 kfree(seed);
1454 return err;
1455}
1456
Herbert Xuda7f0332008-07-31 17:08:25 +08001457static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1458 u32 type, u32 mask)
1459{
1460 struct crypto_aead *tfm;
1461 int err = 0;
1462
1463 tfm = crypto_alloc_aead(driver, type, mask);
1464 if (IS_ERR(tfm)) {
1465 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1466 "%ld\n", driver, PTR_ERR(tfm));
1467 return PTR_ERR(tfm);
1468 }
1469
1470 if (desc->suite.aead.enc.vecs) {
1471 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1472 desc->suite.aead.enc.count);
1473 if (err)
1474 goto out;
1475 }
1476
1477 if (!err && desc->suite.aead.dec.vecs)
1478 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1479 desc->suite.aead.dec.count);
1480
1481out:
1482 crypto_free_aead(tfm);
1483 return err;
1484}
1485
1486static int alg_test_cipher(const struct alg_test_desc *desc,
1487 const char *driver, u32 type, u32 mask)
1488{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001489 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001490 int err = 0;
1491
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001492 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001493 if (IS_ERR(tfm)) {
1494 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1495 "%s: %ld\n", driver, PTR_ERR(tfm));
1496 return PTR_ERR(tfm);
1497 }
1498
1499 if (desc->suite.cipher.enc.vecs) {
1500 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1501 desc->suite.cipher.enc.count);
1502 if (err)
1503 goto out;
1504 }
1505
1506 if (desc->suite.cipher.dec.vecs)
1507 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1508 desc->suite.cipher.dec.count);
1509
1510out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001511 crypto_free_cipher(tfm);
1512 return err;
1513}
1514
1515static int alg_test_skcipher(const struct alg_test_desc *desc,
1516 const char *driver, u32 type, u32 mask)
1517{
1518 struct crypto_ablkcipher *tfm;
1519 int err = 0;
1520
1521 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1522 if (IS_ERR(tfm)) {
1523 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1524 "%s: %ld\n", driver, PTR_ERR(tfm));
1525 return PTR_ERR(tfm);
1526 }
1527
1528 if (desc->suite.cipher.enc.vecs) {
1529 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1530 desc->suite.cipher.enc.count);
1531 if (err)
1532 goto out;
1533 }
1534
1535 if (desc->suite.cipher.dec.vecs)
1536 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1537 desc->suite.cipher.dec.count);
1538
1539out:
Herbert Xuda7f0332008-07-31 17:08:25 +08001540 crypto_free_ablkcipher(tfm);
1541 return err;
1542}
1543
1544static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1545 u32 type, u32 mask)
1546{
1547 struct crypto_comp *tfm;
1548 int err;
1549
1550 tfm = crypto_alloc_comp(driver, type, mask);
1551 if (IS_ERR(tfm)) {
1552 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1553 "%ld\n", driver, PTR_ERR(tfm));
1554 return PTR_ERR(tfm);
1555 }
1556
1557 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1558 desc->suite.comp.decomp.vecs,
1559 desc->suite.comp.comp.count,
1560 desc->suite.comp.decomp.count);
1561
1562 crypto_free_comp(tfm);
1563 return err;
1564}
1565
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001566static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1567 u32 type, u32 mask)
1568{
1569 struct crypto_pcomp *tfm;
1570 int err;
1571
1572 tfm = crypto_alloc_pcomp(driver, type, mask);
1573 if (IS_ERR(tfm)) {
1574 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1575 driver, PTR_ERR(tfm));
1576 return PTR_ERR(tfm);
1577 }
1578
1579 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1580 desc->suite.pcomp.decomp.vecs,
1581 desc->suite.pcomp.comp.count,
1582 desc->suite.pcomp.decomp.count);
1583
1584 crypto_free_pcomp(tfm);
1585 return err;
1586}
1587
Herbert Xuda7f0332008-07-31 17:08:25 +08001588static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1589 u32 type, u32 mask)
1590{
1591 struct crypto_ahash *tfm;
1592 int err;
1593
1594 tfm = crypto_alloc_ahash(driver, type, mask);
1595 if (IS_ERR(tfm)) {
1596 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1597 "%ld\n", driver, PTR_ERR(tfm));
1598 return PTR_ERR(tfm);
1599 }
1600
David S. Millera8f1a052010-05-19 14:12:03 +10001601 err = test_hash(tfm, desc->suite.hash.vecs,
1602 desc->suite.hash.count, true);
1603 if (!err)
1604 err = test_hash(tfm, desc->suite.hash.vecs,
1605 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001606
1607 crypto_free_ahash(tfm);
1608 return err;
1609}
1610
Herbert Xu8e3ee852008-11-07 14:58:52 +08001611static int alg_test_crc32c(const struct alg_test_desc *desc,
1612 const char *driver, u32 type, u32 mask)
1613{
1614 struct crypto_shash *tfm;
1615 u32 val;
1616 int err;
1617
1618 err = alg_test_hash(desc, driver, type, mask);
1619 if (err)
1620 goto out;
1621
1622 tfm = crypto_alloc_shash(driver, type, mask);
1623 if (IS_ERR(tfm)) {
1624 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1625 "%ld\n", driver, PTR_ERR(tfm));
1626 err = PTR_ERR(tfm);
1627 goto out;
1628 }
1629
1630 do {
1631 struct {
1632 struct shash_desc shash;
1633 char ctx[crypto_shash_descsize(tfm)];
1634 } sdesc;
1635
1636 sdesc.shash.tfm = tfm;
1637 sdesc.shash.flags = 0;
1638
1639 *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1640 err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1641 if (err) {
1642 printk(KERN_ERR "alg: crc32c: Operation failed for "
1643 "%s: %d\n", driver, err);
1644 break;
1645 }
1646
1647 if (val != ~420553207) {
1648 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1649 "%d\n", driver, val);
1650 err = -EINVAL;
1651 }
1652 } while (0);
1653
1654 crypto_free_shash(tfm);
1655
1656out:
1657 return err;
1658}
1659
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001660static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1661 u32 type, u32 mask)
1662{
1663 struct crypto_rng *rng;
1664 int err;
1665
1666 rng = crypto_alloc_rng(driver, type, mask);
1667 if (IS_ERR(rng)) {
1668 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1669 "%ld\n", driver, PTR_ERR(rng));
1670 return PTR_ERR(rng);
1671 }
1672
1673 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1674
1675 crypto_free_rng(rng);
1676
1677 return err;
1678}
1679
Youquan, Song863b5572009-12-23 19:45:20 +08001680static int alg_test_null(const struct alg_test_desc *desc,
1681 const char *driver, u32 type, u32 mask)
1682{
1683 return 0;
1684}
1685
Herbert Xuda7f0332008-07-31 17:08:25 +08001686/* Please keep this list sorted by algorithm name. */
1687static const struct alg_test_desc alg_test_descs[] = {
1688 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001689 .alg = "__cbc-cast5-avx",
1690 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001691 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001692 .alg = "__cbc-cast6-avx",
1693 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001694 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001695 .alg = "__cbc-serpent-avx",
1696 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001697 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001698 .alg = "__cbc-serpent-avx2",
1699 .test = alg_test_null,
1700 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001701 .alg = "__cbc-serpent-sse2",
1702 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001703 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001704 .alg = "__cbc-twofish-avx",
1705 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001706 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001707 .alg = "__driver-cbc-aes-aesni",
1708 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001709 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001710 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001711 .alg = "__driver-cbc-camellia-aesni",
1712 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001713 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001714 .alg = "__driver-cbc-camellia-aesni-avx2",
1715 .test = alg_test_null,
1716 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001717 .alg = "__driver-cbc-cast5-avx",
1718 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001719 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001720 .alg = "__driver-cbc-cast6-avx",
1721 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001722 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001723 .alg = "__driver-cbc-serpent-avx",
1724 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001725 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001726 .alg = "__driver-cbc-serpent-avx2",
1727 .test = alg_test_null,
1728 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001729 .alg = "__driver-cbc-serpent-sse2",
1730 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001731 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001732 .alg = "__driver-cbc-twofish-avx",
1733 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001734 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001735 .alg = "__driver-ecb-aes-aesni",
1736 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001737 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001738 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001739 .alg = "__driver-ecb-camellia-aesni",
1740 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001741 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001742 .alg = "__driver-ecb-camellia-aesni-avx2",
1743 .test = alg_test_null,
1744 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001745 .alg = "__driver-ecb-cast5-avx",
1746 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001747 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001748 .alg = "__driver-ecb-cast6-avx",
1749 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001750 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001751 .alg = "__driver-ecb-serpent-avx",
1752 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001753 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001754 .alg = "__driver-ecb-serpent-avx2",
1755 .test = alg_test_null,
1756 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001757 .alg = "__driver-ecb-serpent-sse2",
1758 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001759 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001760 .alg = "__driver-ecb-twofish-avx",
1761 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001762 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001763 .alg = "__ghash-pclmulqdqni",
1764 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001765 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001766 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001767 .alg = "ansi_cprng",
1768 .test = alg_test_cprng,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001769 .fips_allowed = 1,
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001770 .suite = {
1771 .cprng = {
1772 .vecs = ansi_cprng_aes_tv_template,
1773 .count = ANSI_CPRNG_AES_TEST_VECTORS
1774 }
1775 }
1776 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03001777 .alg = "authenc(hmac(sha1),cbc(aes))",
1778 .test = alg_test_aead,
1779 .fips_allowed = 1,
1780 .suite = {
1781 .aead = {
1782 .enc = {
1783 .vecs = hmac_sha1_aes_cbc_enc_tv_template,
1784 .count = HMAC_SHA1_AES_CBC_ENC_TEST_VECTORS
1785 }
1786 }
1787 }
1788 }, {
1789 .alg = "authenc(hmac(sha256),cbc(aes))",
1790 .test = alg_test_aead,
1791 .fips_allowed = 1,
1792 .suite = {
1793 .aead = {
1794 .enc = {
1795 .vecs = hmac_sha256_aes_cbc_enc_tv_template,
1796 .count = HMAC_SHA256_AES_CBC_ENC_TEST_VECTORS
1797 }
1798 }
1799 }
1800 }, {
1801 .alg = "authenc(hmac(sha512),cbc(aes))",
1802 .test = alg_test_aead,
1803 .fips_allowed = 1,
1804 .suite = {
1805 .aead = {
1806 .enc = {
1807 .vecs = hmac_sha512_aes_cbc_enc_tv_template,
1808 .count = HMAC_SHA512_AES_CBC_ENC_TEST_VECTORS
1809 }
1810 }
1811 }
1812 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08001813 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001814 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001815 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08001816 .suite = {
1817 .cipher = {
1818 .enc = {
1819 .vecs = aes_cbc_enc_tv_template,
1820 .count = AES_CBC_ENC_TEST_VECTORS
1821 },
1822 .dec = {
1823 .vecs = aes_cbc_dec_tv_template,
1824 .count = AES_CBC_DEC_TEST_VECTORS
1825 }
1826 }
1827 }
1828 }, {
1829 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001830 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08001831 .suite = {
1832 .cipher = {
1833 .enc = {
1834 .vecs = anubis_cbc_enc_tv_template,
1835 .count = ANUBIS_CBC_ENC_TEST_VECTORS
1836 },
1837 .dec = {
1838 .vecs = anubis_cbc_dec_tv_template,
1839 .count = ANUBIS_CBC_DEC_TEST_VECTORS
1840 }
1841 }
1842 }
1843 }, {
1844 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001845 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08001846 .suite = {
1847 .cipher = {
1848 .enc = {
1849 .vecs = bf_cbc_enc_tv_template,
1850 .count = BF_CBC_ENC_TEST_VECTORS
1851 },
1852 .dec = {
1853 .vecs = bf_cbc_dec_tv_template,
1854 .count = BF_CBC_DEC_TEST_VECTORS
1855 }
1856 }
1857 }
1858 }, {
1859 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001860 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08001861 .suite = {
1862 .cipher = {
1863 .enc = {
1864 .vecs = camellia_cbc_enc_tv_template,
1865 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
1866 },
1867 .dec = {
1868 .vecs = camellia_cbc_dec_tv_template,
1869 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
1870 }
1871 }
1872 }
1873 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001874 .alg = "cbc(cast5)",
1875 .test = alg_test_skcipher,
1876 .suite = {
1877 .cipher = {
1878 .enc = {
1879 .vecs = cast5_cbc_enc_tv_template,
1880 .count = CAST5_CBC_ENC_TEST_VECTORS
1881 },
1882 .dec = {
1883 .vecs = cast5_cbc_dec_tv_template,
1884 .count = CAST5_CBC_DEC_TEST_VECTORS
1885 }
1886 }
1887 }
1888 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001889 .alg = "cbc(cast6)",
1890 .test = alg_test_skcipher,
1891 .suite = {
1892 .cipher = {
1893 .enc = {
1894 .vecs = cast6_cbc_enc_tv_template,
1895 .count = CAST6_CBC_ENC_TEST_VECTORS
1896 },
1897 .dec = {
1898 .vecs = cast6_cbc_dec_tv_template,
1899 .count = CAST6_CBC_DEC_TEST_VECTORS
1900 }
1901 }
1902 }
1903 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08001904 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001905 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08001906 .suite = {
1907 .cipher = {
1908 .enc = {
1909 .vecs = des_cbc_enc_tv_template,
1910 .count = DES_CBC_ENC_TEST_VECTORS
1911 },
1912 .dec = {
1913 .vecs = des_cbc_dec_tv_template,
1914 .count = DES_CBC_DEC_TEST_VECTORS
1915 }
1916 }
1917 }
1918 }, {
1919 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001920 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001921 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08001922 .suite = {
1923 .cipher = {
1924 .enc = {
1925 .vecs = des3_ede_cbc_enc_tv_template,
1926 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
1927 },
1928 .dec = {
1929 .vecs = des3_ede_cbc_dec_tv_template,
1930 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
1931 }
1932 }
1933 }
1934 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03001935 .alg = "cbc(serpent)",
1936 .test = alg_test_skcipher,
1937 .suite = {
1938 .cipher = {
1939 .enc = {
1940 .vecs = serpent_cbc_enc_tv_template,
1941 .count = SERPENT_CBC_ENC_TEST_VECTORS
1942 },
1943 .dec = {
1944 .vecs = serpent_cbc_dec_tv_template,
1945 .count = SERPENT_CBC_DEC_TEST_VECTORS
1946 }
1947 }
1948 }
1949 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08001950 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001951 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08001952 .suite = {
1953 .cipher = {
1954 .enc = {
1955 .vecs = tf_cbc_enc_tv_template,
1956 .count = TF_CBC_ENC_TEST_VECTORS
1957 },
1958 .dec = {
1959 .vecs = tf_cbc_dec_tv_template,
1960 .count = TF_CBC_DEC_TEST_VECTORS
1961 }
1962 }
1963 }
1964 }, {
1965 .alg = "ccm(aes)",
1966 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001967 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08001968 .suite = {
1969 .aead = {
1970 .enc = {
1971 .vecs = aes_ccm_enc_tv_template,
1972 .count = AES_CCM_ENC_TEST_VECTORS
1973 },
1974 .dec = {
1975 .vecs = aes_ccm_dec_tv_template,
1976 .count = AES_CCM_DEC_TEST_VECTORS
1977 }
1978 }
1979 }
1980 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001981 .alg = "cmac(aes)",
1982 .test = alg_test_hash,
1983 .suite = {
1984 .hash = {
1985 .vecs = aes_cmac128_tv_template,
1986 .count = CMAC_AES_TEST_VECTORS
1987 }
1988 }
1989 }, {
1990 .alg = "cmac(des3_ede)",
1991 .test = alg_test_hash,
1992 .suite = {
1993 .hash = {
1994 .vecs = des3_ede_cmac64_tv_template,
1995 .count = CMAC_DES3_EDE_TEST_VECTORS
1996 }
1997 }
1998 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03001999 .alg = "compress_null",
2000 .test = alg_test_null,
2001 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002002 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002003 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002004 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002005 .suite = {
2006 .hash = {
2007 .vecs = crc32c_tv_template,
2008 .count = CRC32C_TEST_VECTORS
2009 }
2010 }
2011 }, {
Tim Chen39761212013-05-01 12:52:51 -07002012 .alg = "crct10dif",
2013 .test = alg_test_hash,
2014 .fips_allowed = 1,
2015 .suite = {
2016 .hash = {
2017 .vecs = crct10dif_tv_template,
2018 .count = CRCT10DIF_TEST_VECTORS
2019 }
2020 }
2021 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002022 .alg = "cryptd(__driver-cbc-aes-aesni)",
2023 .test = alg_test_null,
2024 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002025 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002026 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2027 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002028 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002029 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2030 .test = alg_test_null,
2031 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002032 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2033 .test = alg_test_null,
2034 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002035 .alg = "cryptd(__driver-ecb-aes-aesni)",
2036 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002037 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002038 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002039 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2040 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002041 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002042 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2043 .test = alg_test_null,
2044 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002045 .alg = "cryptd(__driver-ecb-cast5-avx)",
2046 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002047 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002048 .alg = "cryptd(__driver-ecb-cast6-avx)",
2049 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002050 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002051 .alg = "cryptd(__driver-ecb-serpent-avx)",
2052 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002053 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002054 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2055 .test = alg_test_null,
2056 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002057 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2058 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002059 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002060 .alg = "cryptd(__driver-ecb-twofish-avx)",
2061 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002062 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002063 .alg = "cryptd(__driver-gcm-aes-aesni)",
2064 .test = alg_test_null,
2065 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002066 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002067 .alg = "cryptd(__ghash-pclmulqdqni)",
2068 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002069 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002070 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002071 .alg = "ctr(aes)",
2072 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002073 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002074 .suite = {
2075 .cipher = {
2076 .enc = {
2077 .vecs = aes_ctr_enc_tv_template,
2078 .count = AES_CTR_ENC_TEST_VECTORS
2079 },
2080 .dec = {
2081 .vecs = aes_ctr_dec_tv_template,
2082 .count = AES_CTR_DEC_TEST_VECTORS
2083 }
2084 }
2085 }
2086 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002087 .alg = "ctr(blowfish)",
2088 .test = alg_test_skcipher,
2089 .suite = {
2090 .cipher = {
2091 .enc = {
2092 .vecs = bf_ctr_enc_tv_template,
2093 .count = BF_CTR_ENC_TEST_VECTORS
2094 },
2095 .dec = {
2096 .vecs = bf_ctr_dec_tv_template,
2097 .count = BF_CTR_DEC_TEST_VECTORS
2098 }
2099 }
2100 }
2101 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002102 .alg = "ctr(camellia)",
2103 .test = alg_test_skcipher,
2104 .suite = {
2105 .cipher = {
2106 .enc = {
2107 .vecs = camellia_ctr_enc_tv_template,
2108 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2109 },
2110 .dec = {
2111 .vecs = camellia_ctr_dec_tv_template,
2112 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2113 }
2114 }
2115 }
2116 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002117 .alg = "ctr(cast5)",
2118 .test = alg_test_skcipher,
2119 .suite = {
2120 .cipher = {
2121 .enc = {
2122 .vecs = cast5_ctr_enc_tv_template,
2123 .count = CAST5_CTR_ENC_TEST_VECTORS
2124 },
2125 .dec = {
2126 .vecs = cast5_ctr_dec_tv_template,
2127 .count = CAST5_CTR_DEC_TEST_VECTORS
2128 }
2129 }
2130 }
2131 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002132 .alg = "ctr(cast6)",
2133 .test = alg_test_skcipher,
2134 .suite = {
2135 .cipher = {
2136 .enc = {
2137 .vecs = cast6_ctr_enc_tv_template,
2138 .count = CAST6_CTR_ENC_TEST_VECTORS
2139 },
2140 .dec = {
2141 .vecs = cast6_ctr_dec_tv_template,
2142 .count = CAST6_CTR_DEC_TEST_VECTORS
2143 }
2144 }
2145 }
2146 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002147 .alg = "ctr(des)",
2148 .test = alg_test_skcipher,
2149 .suite = {
2150 .cipher = {
2151 .enc = {
2152 .vecs = des_ctr_enc_tv_template,
2153 .count = DES_CTR_ENC_TEST_VECTORS
2154 },
2155 .dec = {
2156 .vecs = des_ctr_dec_tv_template,
2157 .count = DES_CTR_DEC_TEST_VECTORS
2158 }
2159 }
2160 }
2161 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002162 .alg = "ctr(des3_ede)",
2163 .test = alg_test_skcipher,
2164 .suite = {
2165 .cipher = {
2166 .enc = {
2167 .vecs = des3_ede_ctr_enc_tv_template,
2168 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2169 },
2170 .dec = {
2171 .vecs = des3_ede_ctr_dec_tv_template,
2172 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2173 }
2174 }
2175 }
2176 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002177 .alg = "ctr(serpent)",
2178 .test = alg_test_skcipher,
2179 .suite = {
2180 .cipher = {
2181 .enc = {
2182 .vecs = serpent_ctr_enc_tv_template,
2183 .count = SERPENT_CTR_ENC_TEST_VECTORS
2184 },
2185 .dec = {
2186 .vecs = serpent_ctr_dec_tv_template,
2187 .count = SERPENT_CTR_DEC_TEST_VECTORS
2188 }
2189 }
2190 }
2191 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002192 .alg = "ctr(twofish)",
2193 .test = alg_test_skcipher,
2194 .suite = {
2195 .cipher = {
2196 .enc = {
2197 .vecs = tf_ctr_enc_tv_template,
2198 .count = TF_CTR_ENC_TEST_VECTORS
2199 },
2200 .dec = {
2201 .vecs = tf_ctr_dec_tv_template,
2202 .count = TF_CTR_DEC_TEST_VECTORS
2203 }
2204 }
2205 }
2206 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002207 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002208 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002209 .suite = {
2210 .cipher = {
2211 .enc = {
2212 .vecs = cts_mode_enc_tv_template,
2213 .count = CTS_MODE_ENC_TEST_VECTORS
2214 },
2215 .dec = {
2216 .vecs = cts_mode_dec_tv_template,
2217 .count = CTS_MODE_DEC_TEST_VECTORS
2218 }
2219 }
2220 }
2221 }, {
2222 .alg = "deflate",
2223 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002224 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002225 .suite = {
2226 .comp = {
2227 .comp = {
2228 .vecs = deflate_comp_tv_template,
2229 .count = DEFLATE_COMP_TEST_VECTORS
2230 },
2231 .decomp = {
2232 .vecs = deflate_decomp_tv_template,
2233 .count = DEFLATE_DECOMP_TEST_VECTORS
2234 }
2235 }
2236 }
2237 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002238 .alg = "digest_null",
2239 .test = alg_test_null,
2240 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002241 .alg = "ecb(__aes-aesni)",
2242 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002243 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002244 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002245 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002246 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002247 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002248 .suite = {
2249 .cipher = {
2250 .enc = {
2251 .vecs = aes_enc_tv_template,
2252 .count = AES_ENC_TEST_VECTORS
2253 },
2254 .dec = {
2255 .vecs = aes_dec_tv_template,
2256 .count = AES_DEC_TEST_VECTORS
2257 }
2258 }
2259 }
2260 }, {
2261 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002262 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002263 .suite = {
2264 .cipher = {
2265 .enc = {
2266 .vecs = anubis_enc_tv_template,
2267 .count = ANUBIS_ENC_TEST_VECTORS
2268 },
2269 .dec = {
2270 .vecs = anubis_dec_tv_template,
2271 .count = ANUBIS_DEC_TEST_VECTORS
2272 }
2273 }
2274 }
2275 }, {
2276 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002277 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002278 .suite = {
2279 .cipher = {
2280 .enc = {
2281 .vecs = arc4_enc_tv_template,
2282 .count = ARC4_ENC_TEST_VECTORS
2283 },
2284 .dec = {
2285 .vecs = arc4_dec_tv_template,
2286 .count = ARC4_DEC_TEST_VECTORS
2287 }
2288 }
2289 }
2290 }, {
2291 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002292 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002293 .suite = {
2294 .cipher = {
2295 .enc = {
2296 .vecs = bf_enc_tv_template,
2297 .count = BF_ENC_TEST_VECTORS
2298 },
2299 .dec = {
2300 .vecs = bf_dec_tv_template,
2301 .count = BF_DEC_TEST_VECTORS
2302 }
2303 }
2304 }
2305 }, {
2306 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002307 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002308 .suite = {
2309 .cipher = {
2310 .enc = {
2311 .vecs = camellia_enc_tv_template,
2312 .count = CAMELLIA_ENC_TEST_VECTORS
2313 },
2314 .dec = {
2315 .vecs = camellia_dec_tv_template,
2316 .count = CAMELLIA_DEC_TEST_VECTORS
2317 }
2318 }
2319 }
2320 }, {
2321 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002322 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002323 .suite = {
2324 .cipher = {
2325 .enc = {
2326 .vecs = cast5_enc_tv_template,
2327 .count = CAST5_ENC_TEST_VECTORS
2328 },
2329 .dec = {
2330 .vecs = cast5_dec_tv_template,
2331 .count = CAST5_DEC_TEST_VECTORS
2332 }
2333 }
2334 }
2335 }, {
2336 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002337 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002338 .suite = {
2339 .cipher = {
2340 .enc = {
2341 .vecs = cast6_enc_tv_template,
2342 .count = CAST6_ENC_TEST_VECTORS
2343 },
2344 .dec = {
2345 .vecs = cast6_dec_tv_template,
2346 .count = CAST6_DEC_TEST_VECTORS
2347 }
2348 }
2349 }
2350 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002351 .alg = "ecb(cipher_null)",
2352 .test = alg_test_null,
2353 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002354 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002355 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002356 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002357 .suite = {
2358 .cipher = {
2359 .enc = {
2360 .vecs = des_enc_tv_template,
2361 .count = DES_ENC_TEST_VECTORS
2362 },
2363 .dec = {
2364 .vecs = des_dec_tv_template,
2365 .count = DES_DEC_TEST_VECTORS
2366 }
2367 }
2368 }
2369 }, {
2370 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002371 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002372 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002373 .suite = {
2374 .cipher = {
2375 .enc = {
2376 .vecs = des3_ede_enc_tv_template,
2377 .count = DES3_EDE_ENC_TEST_VECTORS
2378 },
2379 .dec = {
2380 .vecs = des3_ede_dec_tv_template,
2381 .count = DES3_EDE_DEC_TEST_VECTORS
2382 }
2383 }
2384 }
2385 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002386 .alg = "ecb(fcrypt)",
2387 .test = alg_test_skcipher,
2388 .suite = {
2389 .cipher = {
2390 .enc = {
2391 .vecs = fcrypt_pcbc_enc_tv_template,
2392 .count = 1
2393 },
2394 .dec = {
2395 .vecs = fcrypt_pcbc_dec_tv_template,
2396 .count = 1
2397 }
2398 }
2399 }
2400 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002401 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002402 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002403 .suite = {
2404 .cipher = {
2405 .enc = {
2406 .vecs = khazad_enc_tv_template,
2407 .count = KHAZAD_ENC_TEST_VECTORS
2408 },
2409 .dec = {
2410 .vecs = khazad_dec_tv_template,
2411 .count = KHAZAD_DEC_TEST_VECTORS
2412 }
2413 }
2414 }
2415 }, {
2416 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002417 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002418 .suite = {
2419 .cipher = {
2420 .enc = {
2421 .vecs = seed_enc_tv_template,
2422 .count = SEED_ENC_TEST_VECTORS
2423 },
2424 .dec = {
2425 .vecs = seed_dec_tv_template,
2426 .count = SEED_DEC_TEST_VECTORS
2427 }
2428 }
2429 }
2430 }, {
2431 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002432 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002433 .suite = {
2434 .cipher = {
2435 .enc = {
2436 .vecs = serpent_enc_tv_template,
2437 .count = SERPENT_ENC_TEST_VECTORS
2438 },
2439 .dec = {
2440 .vecs = serpent_dec_tv_template,
2441 .count = SERPENT_DEC_TEST_VECTORS
2442 }
2443 }
2444 }
2445 }, {
2446 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002447 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002448 .suite = {
2449 .cipher = {
2450 .enc = {
2451 .vecs = tea_enc_tv_template,
2452 .count = TEA_ENC_TEST_VECTORS
2453 },
2454 .dec = {
2455 .vecs = tea_dec_tv_template,
2456 .count = TEA_DEC_TEST_VECTORS
2457 }
2458 }
2459 }
2460 }, {
2461 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002462 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002463 .suite = {
2464 .cipher = {
2465 .enc = {
2466 .vecs = tnepres_enc_tv_template,
2467 .count = TNEPRES_ENC_TEST_VECTORS
2468 },
2469 .dec = {
2470 .vecs = tnepres_dec_tv_template,
2471 .count = TNEPRES_DEC_TEST_VECTORS
2472 }
2473 }
2474 }
2475 }, {
2476 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002477 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002478 .suite = {
2479 .cipher = {
2480 .enc = {
2481 .vecs = tf_enc_tv_template,
2482 .count = TF_ENC_TEST_VECTORS
2483 },
2484 .dec = {
2485 .vecs = tf_dec_tv_template,
2486 .count = TF_DEC_TEST_VECTORS
2487 }
2488 }
2489 }
2490 }, {
2491 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002492 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002493 .suite = {
2494 .cipher = {
2495 .enc = {
2496 .vecs = xeta_enc_tv_template,
2497 .count = XETA_ENC_TEST_VECTORS
2498 },
2499 .dec = {
2500 .vecs = xeta_dec_tv_template,
2501 .count = XETA_DEC_TEST_VECTORS
2502 }
2503 }
2504 }
2505 }, {
2506 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002507 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002508 .suite = {
2509 .cipher = {
2510 .enc = {
2511 .vecs = xtea_enc_tv_template,
2512 .count = XTEA_ENC_TEST_VECTORS
2513 },
2514 .dec = {
2515 .vecs = xtea_dec_tv_template,
2516 .count = XTEA_DEC_TEST_VECTORS
2517 }
2518 }
2519 }
2520 }, {
2521 .alg = "gcm(aes)",
2522 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002523 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002524 .suite = {
2525 .aead = {
2526 .enc = {
2527 .vecs = aes_gcm_enc_tv_template,
2528 .count = AES_GCM_ENC_TEST_VECTORS
2529 },
2530 .dec = {
2531 .vecs = aes_gcm_dec_tv_template,
2532 .count = AES_GCM_DEC_TEST_VECTORS
2533 }
2534 }
2535 }
2536 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08002537 .alg = "ghash",
2538 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11002539 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08002540 .suite = {
2541 .hash = {
2542 .vecs = ghash_tv_template,
2543 .count = GHASH_TEST_VECTORS
2544 }
2545 }
2546 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08002547 .alg = "hmac(crc32)",
2548 .test = alg_test_hash,
2549 .suite = {
2550 .hash = {
2551 .vecs = bfin_crc_tv_template,
2552 .count = BFIN_CRC_TEST_VECTORS
2553 }
2554 }
2555 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002556 .alg = "hmac(md5)",
2557 .test = alg_test_hash,
2558 .suite = {
2559 .hash = {
2560 .vecs = hmac_md5_tv_template,
2561 .count = HMAC_MD5_TEST_VECTORS
2562 }
2563 }
2564 }, {
2565 .alg = "hmac(rmd128)",
2566 .test = alg_test_hash,
2567 .suite = {
2568 .hash = {
2569 .vecs = hmac_rmd128_tv_template,
2570 .count = HMAC_RMD128_TEST_VECTORS
2571 }
2572 }
2573 }, {
2574 .alg = "hmac(rmd160)",
2575 .test = alg_test_hash,
2576 .suite = {
2577 .hash = {
2578 .vecs = hmac_rmd160_tv_template,
2579 .count = HMAC_RMD160_TEST_VECTORS
2580 }
2581 }
2582 }, {
2583 .alg = "hmac(sha1)",
2584 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002585 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002586 .suite = {
2587 .hash = {
2588 .vecs = hmac_sha1_tv_template,
2589 .count = HMAC_SHA1_TEST_VECTORS
2590 }
2591 }
2592 }, {
2593 .alg = "hmac(sha224)",
2594 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002595 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002596 .suite = {
2597 .hash = {
2598 .vecs = hmac_sha224_tv_template,
2599 .count = HMAC_SHA224_TEST_VECTORS
2600 }
2601 }
2602 }, {
2603 .alg = "hmac(sha256)",
2604 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002605 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002606 .suite = {
2607 .hash = {
2608 .vecs = hmac_sha256_tv_template,
2609 .count = HMAC_SHA256_TEST_VECTORS
2610 }
2611 }
2612 }, {
2613 .alg = "hmac(sha384)",
2614 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002615 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002616 .suite = {
2617 .hash = {
2618 .vecs = hmac_sha384_tv_template,
2619 .count = HMAC_SHA384_TEST_VECTORS
2620 }
2621 }
2622 }, {
2623 .alg = "hmac(sha512)",
2624 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002625 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002626 .suite = {
2627 .hash = {
2628 .vecs = hmac_sha512_tv_template,
2629 .count = HMAC_SHA512_TEST_VECTORS
2630 }
2631 }
2632 }, {
2633 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002634 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002635 .suite = {
2636 .cipher = {
2637 .enc = {
2638 .vecs = aes_lrw_enc_tv_template,
2639 .count = AES_LRW_ENC_TEST_VECTORS
2640 },
2641 .dec = {
2642 .vecs = aes_lrw_dec_tv_template,
2643 .count = AES_LRW_DEC_TEST_VECTORS
2644 }
2645 }
2646 }
2647 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002648 .alg = "lrw(camellia)",
2649 .test = alg_test_skcipher,
2650 .suite = {
2651 .cipher = {
2652 .enc = {
2653 .vecs = camellia_lrw_enc_tv_template,
2654 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
2655 },
2656 .dec = {
2657 .vecs = camellia_lrw_dec_tv_template,
2658 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
2659 }
2660 }
2661 }
2662 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002663 .alg = "lrw(cast6)",
2664 .test = alg_test_skcipher,
2665 .suite = {
2666 .cipher = {
2667 .enc = {
2668 .vecs = cast6_lrw_enc_tv_template,
2669 .count = CAST6_LRW_ENC_TEST_VECTORS
2670 },
2671 .dec = {
2672 .vecs = cast6_lrw_dec_tv_template,
2673 .count = CAST6_LRW_DEC_TEST_VECTORS
2674 }
2675 }
2676 }
2677 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03002678 .alg = "lrw(serpent)",
2679 .test = alg_test_skcipher,
2680 .suite = {
2681 .cipher = {
2682 .enc = {
2683 .vecs = serpent_lrw_enc_tv_template,
2684 .count = SERPENT_LRW_ENC_TEST_VECTORS
2685 },
2686 .dec = {
2687 .vecs = serpent_lrw_dec_tv_template,
2688 .count = SERPENT_LRW_DEC_TEST_VECTORS
2689 }
2690 }
2691 }
2692 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03002693 .alg = "lrw(twofish)",
2694 .test = alg_test_skcipher,
2695 .suite = {
2696 .cipher = {
2697 .enc = {
2698 .vecs = tf_lrw_enc_tv_template,
2699 .count = TF_LRW_ENC_TEST_VECTORS
2700 },
2701 .dec = {
2702 .vecs = tf_lrw_dec_tv_template,
2703 .count = TF_LRW_DEC_TEST_VECTORS
2704 }
2705 }
2706 }
2707 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002708 .alg = "lzo",
2709 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002710 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002711 .suite = {
2712 .comp = {
2713 .comp = {
2714 .vecs = lzo_comp_tv_template,
2715 .count = LZO_COMP_TEST_VECTORS
2716 },
2717 .decomp = {
2718 .vecs = lzo_decomp_tv_template,
2719 .count = LZO_DECOMP_TEST_VECTORS
2720 }
2721 }
2722 }
2723 }, {
2724 .alg = "md4",
2725 .test = alg_test_hash,
2726 .suite = {
2727 .hash = {
2728 .vecs = md4_tv_template,
2729 .count = MD4_TEST_VECTORS
2730 }
2731 }
2732 }, {
2733 .alg = "md5",
2734 .test = alg_test_hash,
2735 .suite = {
2736 .hash = {
2737 .vecs = md5_tv_template,
2738 .count = MD5_TEST_VECTORS
2739 }
2740 }
2741 }, {
2742 .alg = "michael_mic",
2743 .test = alg_test_hash,
2744 .suite = {
2745 .hash = {
2746 .vecs = michael_mic_tv_template,
2747 .count = MICHAEL_MIC_TEST_VECTORS
2748 }
2749 }
2750 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10002751 .alg = "ofb(aes)",
2752 .test = alg_test_skcipher,
2753 .fips_allowed = 1,
2754 .suite = {
2755 .cipher = {
2756 .enc = {
2757 .vecs = aes_ofb_enc_tv_template,
2758 .count = AES_OFB_ENC_TEST_VECTORS
2759 },
2760 .dec = {
2761 .vecs = aes_ofb_dec_tv_template,
2762 .count = AES_OFB_DEC_TEST_VECTORS
2763 }
2764 }
2765 }
2766 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002767 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002768 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002769 .suite = {
2770 .cipher = {
2771 .enc = {
2772 .vecs = fcrypt_pcbc_enc_tv_template,
2773 .count = FCRYPT_ENC_TEST_VECTORS
2774 },
2775 .dec = {
2776 .vecs = fcrypt_pcbc_dec_tv_template,
2777 .count = FCRYPT_DEC_TEST_VECTORS
2778 }
2779 }
2780 }
2781 }, {
2782 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002783 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002784 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002785 .suite = {
2786 .cipher = {
2787 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002788 .vecs = aes_ctr_rfc3686_enc_tv_template,
2789 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08002790 },
2791 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002792 .vecs = aes_ctr_rfc3686_dec_tv_template,
2793 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08002794 }
2795 }
2796 }
2797 }, {
Adrian Hoban69435b92010-11-04 15:02:04 -04002798 .alg = "rfc4106(gcm(aes))",
2799 .test = alg_test_aead,
2800 .suite = {
2801 .aead = {
2802 .enc = {
2803 .vecs = aes_gcm_rfc4106_enc_tv_template,
2804 .count = AES_GCM_4106_ENC_TEST_VECTORS
2805 },
2806 .dec = {
2807 .vecs = aes_gcm_rfc4106_dec_tv_template,
2808 .count = AES_GCM_4106_DEC_TEST_VECTORS
2809 }
2810 }
2811 }
2812 }, {
Jarod Wilson5d667322009-05-04 19:23:40 +08002813 .alg = "rfc4309(ccm(aes))",
2814 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002815 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08002816 .suite = {
2817 .aead = {
2818 .enc = {
2819 .vecs = aes_ccm_rfc4309_enc_tv_template,
2820 .count = AES_CCM_4309_ENC_TEST_VECTORS
2821 },
2822 .dec = {
2823 .vecs = aes_ccm_rfc4309_dec_tv_template,
2824 .count = AES_CCM_4309_DEC_TEST_VECTORS
2825 }
2826 }
2827 }
2828 }, {
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03002829 .alg = "rfc4543(gcm(aes))",
2830 .test = alg_test_aead,
2831 .suite = {
2832 .aead = {
2833 .enc = {
2834 .vecs = aes_gcm_rfc4543_enc_tv_template,
2835 .count = AES_GCM_4543_ENC_TEST_VECTORS
2836 },
2837 .dec = {
2838 .vecs = aes_gcm_rfc4543_dec_tv_template,
2839 .count = AES_GCM_4543_DEC_TEST_VECTORS
2840 },
2841 }
2842 }
2843 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002844 .alg = "rmd128",
2845 .test = alg_test_hash,
2846 .suite = {
2847 .hash = {
2848 .vecs = rmd128_tv_template,
2849 .count = RMD128_TEST_VECTORS
2850 }
2851 }
2852 }, {
2853 .alg = "rmd160",
2854 .test = alg_test_hash,
2855 .suite = {
2856 .hash = {
2857 .vecs = rmd160_tv_template,
2858 .count = RMD160_TEST_VECTORS
2859 }
2860 }
2861 }, {
2862 .alg = "rmd256",
2863 .test = alg_test_hash,
2864 .suite = {
2865 .hash = {
2866 .vecs = rmd256_tv_template,
2867 .count = RMD256_TEST_VECTORS
2868 }
2869 }
2870 }, {
2871 .alg = "rmd320",
2872 .test = alg_test_hash,
2873 .suite = {
2874 .hash = {
2875 .vecs = rmd320_tv_template,
2876 .count = RMD320_TEST_VECTORS
2877 }
2878 }
2879 }, {
2880 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002881 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002882 .suite = {
2883 .cipher = {
2884 .enc = {
2885 .vecs = salsa20_stream_enc_tv_template,
2886 .count = SALSA20_STREAM_ENC_TEST_VECTORS
2887 }
2888 }
2889 }
2890 }, {
2891 .alg = "sha1",
2892 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002893 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002894 .suite = {
2895 .hash = {
2896 .vecs = sha1_tv_template,
2897 .count = SHA1_TEST_VECTORS
2898 }
2899 }
2900 }, {
2901 .alg = "sha224",
2902 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002903 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002904 .suite = {
2905 .hash = {
2906 .vecs = sha224_tv_template,
2907 .count = SHA224_TEST_VECTORS
2908 }
2909 }
2910 }, {
2911 .alg = "sha256",
2912 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002913 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002914 .suite = {
2915 .hash = {
2916 .vecs = sha256_tv_template,
2917 .count = SHA256_TEST_VECTORS
2918 }
2919 }
2920 }, {
2921 .alg = "sha384",
2922 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002923 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002924 .suite = {
2925 .hash = {
2926 .vecs = sha384_tv_template,
2927 .count = SHA384_TEST_VECTORS
2928 }
2929 }
2930 }, {
2931 .alg = "sha512",
2932 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002933 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002934 .suite = {
2935 .hash = {
2936 .vecs = sha512_tv_template,
2937 .count = SHA512_TEST_VECTORS
2938 }
2939 }
2940 }, {
2941 .alg = "tgr128",
2942 .test = alg_test_hash,
2943 .suite = {
2944 .hash = {
2945 .vecs = tgr128_tv_template,
2946 .count = TGR128_TEST_VECTORS
2947 }
2948 }
2949 }, {
2950 .alg = "tgr160",
2951 .test = alg_test_hash,
2952 .suite = {
2953 .hash = {
2954 .vecs = tgr160_tv_template,
2955 .count = TGR160_TEST_VECTORS
2956 }
2957 }
2958 }, {
2959 .alg = "tgr192",
2960 .test = alg_test_hash,
2961 .suite = {
2962 .hash = {
2963 .vecs = tgr192_tv_template,
2964 .count = TGR192_TEST_VECTORS
2965 }
2966 }
2967 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10002968 .alg = "vmac(aes)",
2969 .test = alg_test_hash,
2970 .suite = {
2971 .hash = {
2972 .vecs = aes_vmac128_tv_template,
2973 .count = VMAC_AES_TEST_VECTORS
2974 }
2975 }
2976 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002977 .alg = "wp256",
2978 .test = alg_test_hash,
2979 .suite = {
2980 .hash = {
2981 .vecs = wp256_tv_template,
2982 .count = WP256_TEST_VECTORS
2983 }
2984 }
2985 }, {
2986 .alg = "wp384",
2987 .test = alg_test_hash,
2988 .suite = {
2989 .hash = {
2990 .vecs = wp384_tv_template,
2991 .count = WP384_TEST_VECTORS
2992 }
2993 }
2994 }, {
2995 .alg = "wp512",
2996 .test = alg_test_hash,
2997 .suite = {
2998 .hash = {
2999 .vecs = wp512_tv_template,
3000 .count = WP512_TEST_VECTORS
3001 }
3002 }
3003 }, {
3004 .alg = "xcbc(aes)",
3005 .test = alg_test_hash,
3006 .suite = {
3007 .hash = {
3008 .vecs = aes_xcbc128_tv_template,
3009 .count = XCBC_AES_TEST_VECTORS
3010 }
3011 }
3012 }, {
3013 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003014 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003015 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003016 .suite = {
3017 .cipher = {
3018 .enc = {
3019 .vecs = aes_xts_enc_tv_template,
3020 .count = AES_XTS_ENC_TEST_VECTORS
3021 },
3022 .dec = {
3023 .vecs = aes_xts_dec_tv_template,
3024 .count = AES_XTS_DEC_TEST_VECTORS
3025 }
3026 }
3027 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003028 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003029 .alg = "xts(camellia)",
3030 .test = alg_test_skcipher,
3031 .suite = {
3032 .cipher = {
3033 .enc = {
3034 .vecs = camellia_xts_enc_tv_template,
3035 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3036 },
3037 .dec = {
3038 .vecs = camellia_xts_dec_tv_template,
3039 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3040 }
3041 }
3042 }
3043 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003044 .alg = "xts(cast6)",
3045 .test = alg_test_skcipher,
3046 .suite = {
3047 .cipher = {
3048 .enc = {
3049 .vecs = cast6_xts_enc_tv_template,
3050 .count = CAST6_XTS_ENC_TEST_VECTORS
3051 },
3052 .dec = {
3053 .vecs = cast6_xts_dec_tv_template,
3054 .count = CAST6_XTS_DEC_TEST_VECTORS
3055 }
3056 }
3057 }
3058 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003059 .alg = "xts(serpent)",
3060 .test = alg_test_skcipher,
3061 .suite = {
3062 .cipher = {
3063 .enc = {
3064 .vecs = serpent_xts_enc_tv_template,
3065 .count = SERPENT_XTS_ENC_TEST_VECTORS
3066 },
3067 .dec = {
3068 .vecs = serpent_xts_dec_tv_template,
3069 .count = SERPENT_XTS_DEC_TEST_VECTORS
3070 }
3071 }
3072 }
3073 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003074 .alg = "xts(twofish)",
3075 .test = alg_test_skcipher,
3076 .suite = {
3077 .cipher = {
3078 .enc = {
3079 .vecs = tf_xts_enc_tv_template,
3080 .count = TF_XTS_ENC_TEST_VECTORS
3081 },
3082 .dec = {
3083 .vecs = tf_xts_dec_tv_template,
3084 .count = TF_XTS_DEC_TEST_VECTORS
3085 }
3086 }
3087 }
3088 }, {
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003089 .alg = "zlib",
3090 .test = alg_test_pcomp,
Milan Broz08189042012-12-06 17:16:28 +08003091 .fips_allowed = 1,
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003092 .suite = {
3093 .pcomp = {
3094 .comp = {
3095 .vecs = zlib_comp_tv_template,
3096 .count = ZLIB_COMP_TEST_VECTORS
3097 },
3098 .decomp = {
3099 .vecs = zlib_decomp_tv_template,
3100 .count = ZLIB_DECOMP_TEST_VECTORS
3101 }
3102 }
3103 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003104 }
3105};
3106
Jussi Kivilinna57147582013-06-13 17:37:40 +03003107static bool alg_test_descs_checked;
3108
3109static void alg_test_descs_check_order(void)
3110{
3111 int i;
3112
3113 /* only check once */
3114 if (alg_test_descs_checked)
3115 return;
3116
3117 alg_test_descs_checked = true;
3118
3119 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3120 int diff = strcmp(alg_test_descs[i - 1].alg,
3121 alg_test_descs[i].alg);
3122
3123 if (WARN_ON(diff > 0)) {
3124 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3125 alg_test_descs[i - 1].alg,
3126 alg_test_descs[i].alg);
3127 }
3128
3129 if (WARN_ON(diff == 0)) {
3130 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3131 alg_test_descs[i].alg);
3132 }
3133 }
3134}
3135
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003136static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003137{
3138 int start = 0;
3139 int end = ARRAY_SIZE(alg_test_descs);
3140
3141 while (start < end) {
3142 int i = (start + end) / 2;
3143 int diff = strcmp(alg_test_descs[i].alg, alg);
3144
3145 if (diff > 0) {
3146 end = i;
3147 continue;
3148 }
3149
3150 if (diff < 0) {
3151 start = i + 1;
3152 continue;
3153 }
3154
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003155 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003156 }
3157
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003158 return -1;
3159}
3160
3161int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3162{
3163 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003164 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003165 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003166
Jussi Kivilinna57147582013-06-13 17:37:40 +03003167 alg_test_descs_check_order();
3168
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003169 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3170 char nalg[CRYPTO_MAX_ALG_NAME];
3171
3172 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3173 sizeof(nalg))
3174 return -ENAMETOOLONG;
3175
3176 i = alg_find_test(nalg);
3177 if (i < 0)
3178 goto notest;
3179
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003180 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3181 goto non_fips_alg;
3182
Jarod Wilson941fb322009-05-04 19:49:23 +08003183 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3184 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003185 }
3186
3187 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003188 j = alg_find_test(driver);
3189 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003190 goto notest;
3191
Herbert Xua68f6612009-07-02 16:32:12 +08003192 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3193 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003194 goto non_fips_alg;
3195
Herbert Xua68f6612009-07-02 16:32:12 +08003196 rc = 0;
3197 if (i >= 0)
3198 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3199 type, mask);
3200 if (j >= 0)
3201 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3202 type, mask);
3203
Jarod Wilson941fb322009-05-04 19:49:23 +08003204test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003205 if (fips_enabled && rc)
3206 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3207
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003208 if (fips_enabled && !rc)
3209 printk(KERN_INFO "alg: self-tests for %s (%s) passed\n",
3210 driver, alg);
3211
Neil Hormand12d6b62008-10-12 20:36:51 +08003212 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003213
3214notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003215 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3216 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003217non_fips_alg:
3218 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003219}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003220
Herbert Xu326a6342010-08-06 09:40:28 +08003221#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003222
Herbert Xuda7f0332008-07-31 17:08:25 +08003223EXPORT_SYMBOL_GPL(alg_test);