blob: ecddf921a9db401ee30bea1bf24b30f0ee8dd85d [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
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300187static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
188 unsigned int tcount, bool use_digest,
189 const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800190{
191 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
192 unsigned int i, j, k, temp;
193 struct scatterlist sg[8];
194 char result[64];
195 struct ahash_request *req;
196 struct tcrypt_result tresult;
Herbert Xuda7f0332008-07-31 17:08:25 +0800197 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800198 char *xbuf[XBUFSIZE];
199 int ret = -ENOMEM;
200
201 if (testmgr_alloc_buf(xbuf))
202 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800203
204 init_completion(&tresult.completion);
205
206 req = ahash_request_alloc(tfm, GFP_KERNEL);
207 if (!req) {
208 printk(KERN_ERR "alg: hash: Failed to allocate request for "
209 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800210 goto out_noreq;
211 }
212 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
213 tcrypt_complete, &tresult);
214
Herbert Xua0cfae52009-05-29 16:23:12 +1000215 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800216 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000217 if (template[i].np)
218 continue;
219
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300220 ret = -EINVAL;
221 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
222 goto out;
223
Herbert Xua0cfae52009-05-29 16:23:12 +1000224 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800225 memset(result, 0, 64);
226
227 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300228 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800229
230 memcpy(hash_buff, template[i].plaintext, template[i].psize);
231 sg_init_one(&sg[0], hash_buff, template[i].psize);
232
233 if (template[i].ksize) {
234 crypto_ahash_clear_flags(tfm, ~0);
235 ret = crypto_ahash_setkey(tfm, template[i].key,
236 template[i].ksize);
237 if (ret) {
238 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000239 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800240 -ret);
241 goto out;
242 }
243 }
244
245 ahash_request_set_crypt(req, sg, result, template[i].psize);
David S. Millera8f1a052010-05-19 14:12:03 +1000246 if (use_digest) {
247 ret = do_one_async_hash_op(req, &tresult,
248 crypto_ahash_digest(req));
249 if (ret) {
250 pr_err("alg: hash: digest failed on test %d "
251 "for %s: ret=%d\n", j, algo, -ret);
252 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800253 }
David S. Millera8f1a052010-05-19 14:12:03 +1000254 } else {
255 ret = do_one_async_hash_op(req, &tresult,
256 crypto_ahash_init(req));
257 if (ret) {
258 pr_err("alt: hash: init failed on test %d "
259 "for %s: ret=%d\n", j, algo, -ret);
260 goto out;
261 }
262 ret = do_one_async_hash_op(req, &tresult,
263 crypto_ahash_update(req));
264 if (ret) {
265 pr_err("alt: hash: update failed on test %d "
266 "for %s: ret=%d\n", j, algo, -ret);
267 goto out;
268 }
269 ret = do_one_async_hash_op(req, &tresult,
270 crypto_ahash_final(req));
271 if (ret) {
272 pr_err("alt: hash: final failed on test %d "
273 "for %s: ret=%d\n", j, algo, -ret);
274 goto out;
275 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800276 }
277
278 if (memcmp(result, template[i].digest,
279 crypto_ahash_digestsize(tfm))) {
280 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000281 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800282 hexdump(result, crypto_ahash_digestsize(tfm));
283 ret = -EINVAL;
284 goto out;
285 }
286 }
287
288 j = 0;
289 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300290 /* alignment tests are only done with continuous buffers */
291 if (align_offset != 0)
292 break;
293
Herbert Xuda7f0332008-07-31 17:08:25 +0800294 if (template[i].np) {
295 j++;
296 memset(result, 0, 64);
297
298 temp = 0;
299 sg_init_table(sg, template[i].np);
Herbert Xufd57f222009-05-29 16:05:42 +1000300 ret = -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +0800301 for (k = 0; k < template[i].np; k++) {
Herbert Xufd57f222009-05-29 16:05:42 +1000302 if (WARN_ON(offset_in_page(IDX[k]) +
303 template[i].tap[k] > PAGE_SIZE))
304 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800305 sg_set_buf(&sg[k],
306 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
307 offset_in_page(IDX[k]),
308 template[i].plaintext + temp,
309 template[i].tap[k]),
310 template[i].tap[k]);
311 temp += template[i].tap[k];
312 }
313
314 if (template[i].ksize) {
315 crypto_ahash_clear_flags(tfm, ~0);
316 ret = crypto_ahash_setkey(tfm, template[i].key,
317 template[i].ksize);
318
319 if (ret) {
320 printk(KERN_ERR "alg: hash: setkey "
321 "failed on chunking test %d "
322 "for %s: ret=%d\n", j, algo,
323 -ret);
324 goto out;
325 }
326 }
327
328 ahash_request_set_crypt(req, sg, result,
329 template[i].psize);
330 ret = crypto_ahash_digest(req);
331 switch (ret) {
332 case 0:
333 break;
334 case -EINPROGRESS:
335 case -EBUSY:
336 ret = wait_for_completion_interruptible(
337 &tresult.completion);
338 if (!ret && !(ret = tresult.err)) {
339 INIT_COMPLETION(tresult.completion);
340 break;
341 }
342 /* fall through */
343 default:
344 printk(KERN_ERR "alg: hash: digest failed "
345 "on chunking test %d for %s: "
346 "ret=%d\n", j, algo, -ret);
347 goto out;
348 }
349
350 if (memcmp(result, template[i].digest,
351 crypto_ahash_digestsize(tfm))) {
352 printk(KERN_ERR "alg: hash: Chunking test %d "
353 "failed for %s\n", j, algo);
354 hexdump(result, crypto_ahash_digestsize(tfm));
355 ret = -EINVAL;
356 goto out;
357 }
358 }
359 }
360
361 ret = 0;
362
363out:
364 ahash_request_free(req);
365out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800366 testmgr_free_buf(xbuf);
367out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +0800368 return ret;
369}
370
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300371static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
372 unsigned int tcount, bool use_digest)
373{
374 unsigned int alignmask;
375 int ret;
376
377 ret = __test_hash(tfm, template, tcount, use_digest, 0);
378 if (ret)
379 return ret;
380
381 /* test unaligned buffers, check with one byte offset */
382 ret = __test_hash(tfm, template, tcount, use_digest, 1);
383 if (ret)
384 return ret;
385
386 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
387 if (alignmask) {
388 /* Check if alignment mask for tfm is correctly set. */
389 ret = __test_hash(tfm, template, tcount, use_digest,
390 alignmask + 1);
391 if (ret)
392 return ret;
393 }
394
395 return 0;
396}
397
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300398static int __test_aead(struct crypto_aead *tfm, int enc,
399 struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300400 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800401{
402 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
403 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800404 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800405 char *q;
406 char *key;
407 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300408 struct scatterlist *sg;
409 struct scatterlist *asg;
410 struct scatterlist *sgout;
411 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800412 struct tcrypt_result result;
413 unsigned int authsize;
414 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300415 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800416 void *assoc;
417 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800418 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300419 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800420 char *axbuf[XBUFSIZE];
421
422 if (testmgr_alloc_buf(xbuf))
423 goto out_noxbuf;
424 if (testmgr_alloc_buf(axbuf))
425 goto out_noaxbuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800426
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300427 if (diff_dst && testmgr_alloc_buf(xoutbuf))
428 goto out_nooutbuf;
429
430 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
431 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL);
432 if (!sg)
433 goto out_nosg;
434 asg = &sg[8];
435 sgout = &asg[8];
436
437 if (diff_dst)
438 d = "-ddst";
439 else
440 d = "";
441
Herbert Xuda7f0332008-07-31 17:08:25 +0800442 if (enc == ENCRYPT)
443 e = "encryption";
444 else
445 e = "decryption";
446
447 init_completion(&result.completion);
448
449 req = aead_request_alloc(tfm, GFP_KERNEL);
450 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300451 pr_err("alg: aead%s: Failed to allocate request for %s\n",
452 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800453 goto out;
454 }
455
456 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
457 tcrypt_complete, &result);
458
459 for (i = 0, j = 0; i < tcount; i++) {
460 if (!template[i].np) {
461 j++;
462
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300463 /* some templates have no input data but they will
Herbert Xuda7f0332008-07-31 17:08:25 +0800464 * touch input
465 */
466 input = xbuf[0];
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300467 input += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800468 assoc = axbuf[0];
469
Herbert Xufd57f222009-05-29 16:05:42 +1000470 ret = -EINVAL;
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300471 if (WARN_ON(align_offset + template[i].ilen >
472 PAGE_SIZE || template[i].alen > PAGE_SIZE))
Herbert Xufd57f222009-05-29 16:05:42 +1000473 goto out;
474
Herbert Xuda7f0332008-07-31 17:08:25 +0800475 memcpy(input, template[i].input, template[i].ilen);
476 memcpy(assoc, template[i].assoc, template[i].alen);
477 if (template[i].iv)
478 memcpy(iv, template[i].iv, MAX_IVLEN);
479 else
480 memset(iv, 0, MAX_IVLEN);
481
482 crypto_aead_clear_flags(tfm, ~0);
483 if (template[i].wk)
484 crypto_aead_set_flags(
485 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
486
487 key = template[i].key;
488
489 ret = crypto_aead_setkey(tfm, key,
490 template[i].klen);
491 if (!ret == template[i].fail) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300492 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
493 d, j, algo, crypto_aead_get_flags(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +0800494 goto out;
495 } else if (ret)
496 continue;
497
498 authsize = abs(template[i].rlen - template[i].ilen);
499 ret = crypto_aead_setauthsize(tfm, authsize);
500 if (ret) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300501 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
502 d, authsize, j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800503 goto out;
504 }
505
506 sg_init_one(&sg[0], input,
507 template[i].ilen + (enc ? authsize : 0));
508
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300509 if (diff_dst) {
510 output = xoutbuf[0];
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300511 output += align_offset;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300512 sg_init_one(&sgout[0], output,
513 template[i].ilen +
514 (enc ? authsize : 0));
515 } else {
516 output = input;
517 }
518
Herbert Xuda7f0332008-07-31 17:08:25 +0800519 sg_init_one(&asg[0], assoc, template[i].alen);
520
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300521 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Herbert Xuda7f0332008-07-31 17:08:25 +0800522 template[i].ilen, iv);
523
524 aead_request_set_assoc(req, asg, template[i].alen);
525
526 ret = enc ?
527 crypto_aead_encrypt(req) :
528 crypto_aead_decrypt(req);
529
530 switch (ret) {
531 case 0:
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800532 if (template[i].novrfy) {
533 /* verification was supposed to fail */
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300534 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
535 d, e, j, algo);
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800536 /* so really, we got a bad message */
537 ret = -EBADMSG;
538 goto out;
539 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800540 break;
541 case -EINPROGRESS:
542 case -EBUSY:
543 ret = wait_for_completion_interruptible(
544 &result.completion);
545 if (!ret && !(ret = result.err)) {
546 INIT_COMPLETION(result.completion);
547 break;
548 }
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800549 case -EBADMSG:
550 if (template[i].novrfy)
551 /* verification failure was expected */
552 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800553 /* fall through */
554 default:
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300555 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
556 d, e, j, algo, -ret);
Herbert Xuda7f0332008-07-31 17:08:25 +0800557 goto out;
558 }
559
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300560 q = output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800561 if (memcmp(q, template[i].result, template[i].rlen)) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300562 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
563 d, j, e, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800564 hexdump(q, template[i].rlen);
565 ret = -EINVAL;
566 goto out;
567 }
568 }
569 }
570
571 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300572 /* alignment tests are only done with continuous buffers */
573 if (align_offset != 0)
574 break;
575
Herbert Xuda7f0332008-07-31 17:08:25 +0800576 if (template[i].np) {
577 j++;
578
579 if (template[i].iv)
580 memcpy(iv, template[i].iv, MAX_IVLEN);
581 else
582 memset(iv, 0, MAX_IVLEN);
583
584 crypto_aead_clear_flags(tfm, ~0);
585 if (template[i].wk)
586 crypto_aead_set_flags(
587 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
588 key = template[i].key;
589
590 ret = crypto_aead_setkey(tfm, key, template[i].klen);
591 if (!ret == template[i].fail) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300592 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
593 d, j, algo, crypto_aead_get_flags(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +0800594 goto out;
595 } else if (ret)
596 continue;
597
598 authsize = abs(template[i].rlen - template[i].ilen);
599
600 ret = -EINVAL;
601 sg_init_table(sg, template[i].np);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300602 if (diff_dst)
603 sg_init_table(sgout, template[i].np);
Herbert Xuda7f0332008-07-31 17:08:25 +0800604 for (k = 0, temp = 0; k < template[i].np; k++) {
605 if (WARN_ON(offset_in_page(IDX[k]) +
606 template[i].tap[k] > PAGE_SIZE))
607 goto out;
608
609 q = xbuf[IDX[k] >> PAGE_SHIFT] +
610 offset_in_page(IDX[k]);
611
612 memcpy(q, template[i].input + temp,
613 template[i].tap[k]);
614
615 n = template[i].tap[k];
616 if (k == template[i].np - 1 && enc)
617 n += authsize;
618 if (offset_in_page(q) + n < PAGE_SIZE)
619 q[n] = 0;
620
621 sg_set_buf(&sg[k], q, template[i].tap[k]);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300622
623 if (diff_dst) {
624 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
625 offset_in_page(IDX[k]);
626
627 memset(q, 0, template[i].tap[k]);
628 if (offset_in_page(q) + n < PAGE_SIZE)
629 q[n] = 0;
630
631 sg_set_buf(&sgout[k], q,
632 template[i].tap[k]);
633 }
634
Herbert Xuda7f0332008-07-31 17:08:25 +0800635 temp += template[i].tap[k];
636 }
637
638 ret = crypto_aead_setauthsize(tfm, authsize);
639 if (ret) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300640 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
641 d, authsize, j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800642 goto out;
643 }
644
645 if (enc) {
646 if (WARN_ON(sg[k - 1].offset +
647 sg[k - 1].length + authsize >
648 PAGE_SIZE)) {
649 ret = -EINVAL;
650 goto out;
651 }
652
653 sg[k - 1].length += authsize;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300654
655 if (diff_dst)
656 sgout[k - 1].length += authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800657 }
658
659 sg_init_table(asg, template[i].anp);
Herbert Xufd57f222009-05-29 16:05:42 +1000660 ret = -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +0800661 for (k = 0, temp = 0; k < template[i].anp; k++) {
Herbert Xufd57f222009-05-29 16:05:42 +1000662 if (WARN_ON(offset_in_page(IDX[k]) +
663 template[i].atap[k] > PAGE_SIZE))
664 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800665 sg_set_buf(&asg[k],
666 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
667 offset_in_page(IDX[k]),
668 template[i].assoc + temp,
669 template[i].atap[k]),
670 template[i].atap[k]);
671 temp += template[i].atap[k];
672 }
673
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300674 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Herbert Xuda7f0332008-07-31 17:08:25 +0800675 template[i].ilen,
676 iv);
677
678 aead_request_set_assoc(req, asg, template[i].alen);
679
680 ret = enc ?
681 crypto_aead_encrypt(req) :
682 crypto_aead_decrypt(req);
683
684 switch (ret) {
685 case 0:
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800686 if (template[i].novrfy) {
687 /* verification was supposed to fail */
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300688 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
689 d, e, j, algo);
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800690 /* so really, we got a bad message */
691 ret = -EBADMSG;
692 goto out;
693 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800694 break;
695 case -EINPROGRESS:
696 case -EBUSY:
697 ret = wait_for_completion_interruptible(
698 &result.completion);
699 if (!ret && !(ret = result.err)) {
700 INIT_COMPLETION(result.completion);
701 break;
702 }
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800703 case -EBADMSG:
704 if (template[i].novrfy)
705 /* verification failure was expected */
706 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800707 /* fall through */
708 default:
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300709 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
710 d, e, j, algo, -ret);
Herbert Xuda7f0332008-07-31 17:08:25 +0800711 goto out;
712 }
713
714 ret = -EINVAL;
715 for (k = 0, temp = 0; k < template[i].np; k++) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300716 if (diff_dst)
717 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
718 offset_in_page(IDX[k]);
719 else
720 q = xbuf[IDX[k] >> PAGE_SHIFT] +
721 offset_in_page(IDX[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +0800722
723 n = template[i].tap[k];
724 if (k == template[i].np - 1)
725 n += enc ? authsize : -authsize;
726
727 if (memcmp(q, template[i].result + temp, n)) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300728 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
729 d, j, e, k, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800730 hexdump(q, n);
731 goto out;
732 }
733
734 q += n;
735 if (k == template[i].np - 1 && !enc) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300736 if (!diff_dst &&
737 memcmp(q, template[i].input +
Herbert Xuda7f0332008-07-31 17:08:25 +0800738 temp + n, authsize))
739 n = authsize;
740 else
741 n = 0;
742 } else {
743 for (n = 0; offset_in_page(q + n) &&
744 q[n]; n++)
745 ;
746 }
747 if (n) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300748 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
749 d, j, e, k, algo, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800750 hexdump(q, n);
751 goto out;
752 }
753
754 temp += template[i].tap[k];
755 }
756 }
757 }
758
759 ret = 0;
760
761out:
762 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300763 kfree(sg);
764out_nosg:
765 if (diff_dst)
766 testmgr_free_buf(xoutbuf);
767out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800768 testmgr_free_buf(axbuf);
769out_noaxbuf:
770 testmgr_free_buf(xbuf);
771out_noxbuf:
Herbert Xuda7f0332008-07-31 17:08:25 +0800772 return ret;
773}
774
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300775static int test_aead(struct crypto_aead *tfm, int enc,
776 struct aead_testvec *template, unsigned int tcount)
777{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300778 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300779 int ret;
780
781 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300782 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300783 if (ret)
784 return ret;
785
786 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300787 ret = __test_aead(tfm, enc, template, tcount, true, 0);
788 if (ret)
789 return ret;
790
791 /* test unaligned buffers, check with one byte offset */
792 ret = __test_aead(tfm, enc, template, tcount, true, 1);
793 if (ret)
794 return ret;
795
796 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
797 if (alignmask) {
798 /* Check if alignment mask for tfm is correctly set. */
799 ret = __test_aead(tfm, enc, template, tcount, true,
800 alignmask + 1);
801 if (ret)
802 return ret;
803 }
804
805 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300806}
807
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000808static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800809 struct cipher_testvec *template, unsigned int tcount)
810{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000811 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
812 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000813 char *q;
814 const char *e;
815 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800816 char *xbuf[XBUFSIZE];
817 int ret = -ENOMEM;
818
819 if (testmgr_alloc_buf(xbuf))
820 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000821
822 if (enc == ENCRYPT)
823 e = "encryption";
824 else
825 e = "decryption";
826
827 j = 0;
828 for (i = 0; i < tcount; i++) {
829 if (template[i].np)
830 continue;
831
832 j++;
833
Herbert Xufd57f222009-05-29 16:05:42 +1000834 ret = -EINVAL;
835 if (WARN_ON(template[i].ilen > PAGE_SIZE))
836 goto out;
837
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000838 data = xbuf[0];
839 memcpy(data, template[i].input, template[i].ilen);
840
841 crypto_cipher_clear_flags(tfm, ~0);
842 if (template[i].wk)
843 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
844
845 ret = crypto_cipher_setkey(tfm, template[i].key,
846 template[i].klen);
847 if (!ret == template[i].fail) {
848 printk(KERN_ERR "alg: cipher: setkey failed "
849 "on test %d for %s: flags=%x\n", j,
850 algo, crypto_cipher_get_flags(tfm));
851 goto out;
852 } else if (ret)
853 continue;
854
855 for (k = 0; k < template[i].ilen;
856 k += crypto_cipher_blocksize(tfm)) {
857 if (enc)
858 crypto_cipher_encrypt_one(tfm, data + k,
859 data + k);
860 else
861 crypto_cipher_decrypt_one(tfm, data + k,
862 data + k);
863 }
864
865 q = data;
866 if (memcmp(q, template[i].result, template[i].rlen)) {
867 printk(KERN_ERR "alg: cipher: Test %d failed "
868 "on %s for %s\n", j, e, algo);
869 hexdump(q, template[i].rlen);
870 ret = -EINVAL;
871 goto out;
872 }
873 }
874
875 ret = 0;
876
877out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800878 testmgr_free_buf(xbuf);
879out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000880 return ret;
881}
882
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300883static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
884 struct cipher_testvec *template, unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300885 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000886{
Herbert Xuda7f0332008-07-31 17:08:25 +0800887 const char *algo =
888 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
889 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800890 char *q;
891 struct ablkcipher_request *req;
892 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300893 struct scatterlist sgout[8];
894 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800895 struct tcrypt_result result;
896 void *data;
897 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800898 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300899 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800900 int ret = -ENOMEM;
901
902 if (testmgr_alloc_buf(xbuf))
903 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800904
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300905 if (diff_dst && testmgr_alloc_buf(xoutbuf))
906 goto out_nooutbuf;
907
908 if (diff_dst)
909 d = "-ddst";
910 else
911 d = "";
912
Herbert Xuda7f0332008-07-31 17:08:25 +0800913 if (enc == ENCRYPT)
914 e = "encryption";
915 else
916 e = "decryption";
917
918 init_completion(&result.completion);
919
920 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
921 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300922 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
923 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800924 goto out;
925 }
926
927 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
928 tcrypt_complete, &result);
929
930 j = 0;
931 for (i = 0; i < tcount; i++) {
932 if (template[i].iv)
933 memcpy(iv, template[i].iv, MAX_IVLEN);
934 else
935 memset(iv, 0, MAX_IVLEN);
936
Jussi Kivilinnaf44d83d2012-09-19 09:42:49 +0300937 if (!(template[i].np) || (template[i].also_non_np)) {
Herbert Xuda7f0332008-07-31 17:08:25 +0800938 j++;
939
Herbert Xufd57f222009-05-29 16:05:42 +1000940 ret = -EINVAL;
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300941 if (WARN_ON(align_offset + template[i].ilen >
942 PAGE_SIZE))
Herbert Xufd57f222009-05-29 16:05:42 +1000943 goto out;
944
Herbert Xuda7f0332008-07-31 17:08:25 +0800945 data = xbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300946 data += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800947 memcpy(data, template[i].input, template[i].ilen);
948
949 crypto_ablkcipher_clear_flags(tfm, ~0);
950 if (template[i].wk)
951 crypto_ablkcipher_set_flags(
952 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
953
954 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
955 template[i].klen);
956 if (!ret == template[i].fail) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300957 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
958 d, j, algo,
959 crypto_ablkcipher_get_flags(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +0800960 goto out;
961 } else if (ret)
962 continue;
963
964 sg_init_one(&sg[0], data, template[i].ilen);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300965 if (diff_dst) {
966 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300967 data += align_offset;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300968 sg_init_one(&sgout[0], data, template[i].ilen);
969 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800970
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300971 ablkcipher_request_set_crypt(req, sg,
972 (diff_dst) ? sgout : sg,
Herbert Xuda7f0332008-07-31 17:08:25 +0800973 template[i].ilen, iv);
974 ret = enc ?
975 crypto_ablkcipher_encrypt(req) :
976 crypto_ablkcipher_decrypt(req);
977
978 switch (ret) {
979 case 0:
980 break;
981 case -EINPROGRESS:
982 case -EBUSY:
983 ret = wait_for_completion_interruptible(
984 &result.completion);
985 if (!ret && !((ret = result.err))) {
986 INIT_COMPLETION(result.completion);
987 break;
988 }
989 /* fall through */
990 default:
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300991 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
992 d, e, j, algo, -ret);
Herbert Xuda7f0332008-07-31 17:08:25 +0800993 goto out;
994 }
995
996 q = data;
997 if (memcmp(q, template[i].result, template[i].rlen)) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300998 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
999 d, j, e, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +08001000 hexdump(q, template[i].rlen);
1001 ret = -EINVAL;
1002 goto out;
1003 }
1004 }
1005 }
1006
1007 j = 0;
1008 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001009 /* alignment tests are only done with continuous buffers */
1010 if (align_offset != 0)
1011 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001012
1013 if (template[i].iv)
1014 memcpy(iv, template[i].iv, MAX_IVLEN);
1015 else
1016 memset(iv, 0, MAX_IVLEN);
1017
1018 if (template[i].np) {
1019 j++;
1020
1021 crypto_ablkcipher_clear_flags(tfm, ~0);
1022 if (template[i].wk)
1023 crypto_ablkcipher_set_flags(
1024 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1025
1026 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1027 template[i].klen);
1028 if (!ret == template[i].fail) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001029 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1030 d, j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +08001031 crypto_ablkcipher_get_flags(tfm));
1032 goto out;
1033 } else if (ret)
1034 continue;
1035
1036 temp = 0;
1037 ret = -EINVAL;
1038 sg_init_table(sg, template[i].np);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001039 if (diff_dst)
1040 sg_init_table(sgout, template[i].np);
Herbert Xuda7f0332008-07-31 17:08:25 +08001041 for (k = 0; k < template[i].np; k++) {
1042 if (WARN_ON(offset_in_page(IDX[k]) +
1043 template[i].tap[k] > PAGE_SIZE))
1044 goto out;
1045
1046 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1047 offset_in_page(IDX[k]);
1048
1049 memcpy(q, template[i].input + temp,
1050 template[i].tap[k]);
1051
1052 if (offset_in_page(q) + template[i].tap[k] <
1053 PAGE_SIZE)
1054 q[template[i].tap[k]] = 0;
1055
1056 sg_set_buf(&sg[k], q, template[i].tap[k]);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001057 if (diff_dst) {
1058 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1059 offset_in_page(IDX[k]);
1060
1061 sg_set_buf(&sgout[k], q,
1062 template[i].tap[k]);
1063
1064 memset(q, 0, template[i].tap[k]);
1065 if (offset_in_page(q) +
1066 template[i].tap[k] < PAGE_SIZE)
1067 q[template[i].tap[k]] = 0;
1068 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001069
1070 temp += template[i].tap[k];
1071 }
1072
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001073 ablkcipher_request_set_crypt(req, sg,
1074 (diff_dst) ? sgout : sg,
Herbert Xuda7f0332008-07-31 17:08:25 +08001075 template[i].ilen, iv);
1076
1077 ret = enc ?
1078 crypto_ablkcipher_encrypt(req) :
1079 crypto_ablkcipher_decrypt(req);
1080
1081 switch (ret) {
1082 case 0:
1083 break;
1084 case -EINPROGRESS:
1085 case -EBUSY:
1086 ret = wait_for_completion_interruptible(
1087 &result.completion);
1088 if (!ret && !((ret = result.err))) {
1089 INIT_COMPLETION(result.completion);
1090 break;
1091 }
1092 /* fall through */
1093 default:
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001094 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1095 d, e, j, algo, -ret);
Herbert Xuda7f0332008-07-31 17:08:25 +08001096 goto out;
1097 }
1098
1099 temp = 0;
1100 ret = -EINVAL;
1101 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001102 if (diff_dst)
1103 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1104 offset_in_page(IDX[k]);
1105 else
1106 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1107 offset_in_page(IDX[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001108
1109 if (memcmp(q, template[i].result + temp,
1110 template[i].tap[k])) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001111 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1112 d, j, e, k, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +08001113 hexdump(q, template[i].tap[k]);
1114 goto out;
1115 }
1116
1117 q += template[i].tap[k];
1118 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1119 ;
1120 if (n) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001121 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1122 d, j, e, k, algo, n);
Herbert Xuda7f0332008-07-31 17:08:25 +08001123 hexdump(q, n);
1124 goto out;
1125 }
1126 temp += template[i].tap[k];
1127 }
1128 }
1129 }
1130
1131 ret = 0;
1132
1133out:
1134 ablkcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001135 if (diff_dst)
1136 testmgr_free_buf(xoutbuf);
1137out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001138 testmgr_free_buf(xbuf);
1139out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001140 return ret;
1141}
1142
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001143static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1144 struct cipher_testvec *template, unsigned int tcount)
1145{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001146 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001147 int ret;
1148
1149 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001150 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001151 if (ret)
1152 return ret;
1153
1154 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001155 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1156 if (ret)
1157 return ret;
1158
1159 /* test unaligned buffers, check with one byte offset */
1160 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1161 if (ret)
1162 return ret;
1163
1164 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1165 if (alignmask) {
1166 /* Check if alignment mask for tfm is correctly set. */
1167 ret = __test_skcipher(tfm, enc, template, tcount, true,
1168 alignmask + 1);
1169 if (ret)
1170 return ret;
1171 }
1172
1173 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001174}
1175
Herbert Xuda7f0332008-07-31 17:08:25 +08001176static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1177 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1178{
1179 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1180 unsigned int i;
1181 char result[COMP_BUF_SIZE];
1182 int ret;
1183
1184 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001185 int ilen;
1186 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001187
1188 memset(result, 0, sizeof (result));
1189
1190 ilen = ctemplate[i].inlen;
1191 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1192 ilen, result, &dlen);
1193 if (ret) {
1194 printk(KERN_ERR "alg: comp: compression failed "
1195 "on test %d for %s: ret=%d\n", i + 1, algo,
1196 -ret);
1197 goto out;
1198 }
1199
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001200 if (dlen != ctemplate[i].outlen) {
1201 printk(KERN_ERR "alg: comp: Compression test %d "
1202 "failed for %s: output len = %d\n", i + 1, algo,
1203 dlen);
1204 ret = -EINVAL;
1205 goto out;
1206 }
1207
Herbert Xuda7f0332008-07-31 17:08:25 +08001208 if (memcmp(result, ctemplate[i].output, dlen)) {
1209 printk(KERN_ERR "alg: comp: Compression test %d "
1210 "failed for %s\n", i + 1, algo);
1211 hexdump(result, dlen);
1212 ret = -EINVAL;
1213 goto out;
1214 }
1215 }
1216
1217 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001218 int ilen;
1219 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001220
1221 memset(result, 0, sizeof (result));
1222
1223 ilen = dtemplate[i].inlen;
1224 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1225 ilen, result, &dlen);
1226 if (ret) {
1227 printk(KERN_ERR "alg: comp: decompression failed "
1228 "on test %d for %s: ret=%d\n", i + 1, algo,
1229 -ret);
1230 goto out;
1231 }
1232
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001233 if (dlen != dtemplate[i].outlen) {
1234 printk(KERN_ERR "alg: comp: Decompression test %d "
1235 "failed for %s: output len = %d\n", i + 1, algo,
1236 dlen);
1237 ret = -EINVAL;
1238 goto out;
1239 }
1240
Herbert Xuda7f0332008-07-31 17:08:25 +08001241 if (memcmp(result, dtemplate[i].output, dlen)) {
1242 printk(KERN_ERR "alg: comp: Decompression test %d "
1243 "failed for %s\n", i + 1, algo);
1244 hexdump(result, dlen);
1245 ret = -EINVAL;
1246 goto out;
1247 }
1248 }
1249
1250 ret = 0;
1251
1252out:
1253 return ret;
1254}
1255
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001256static int test_pcomp(struct crypto_pcomp *tfm,
1257 struct pcomp_testvec *ctemplate,
1258 struct pcomp_testvec *dtemplate, int ctcount,
1259 int dtcount)
1260{
1261 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1262 unsigned int i;
1263 char result[COMP_BUF_SIZE];
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001264 int res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001265
1266 for (i = 0; i < ctcount; i++) {
1267 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001268 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001269
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001270 res = crypto_compress_setup(tfm, ctemplate[i].params,
1271 ctemplate[i].paramsize);
1272 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001273 pr_err("alg: pcomp: compression setup failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001274 "%d for %s: error=%d\n", i + 1, algo, res);
1275 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001276 }
1277
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001278 res = crypto_compress_init(tfm);
1279 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001280 pr_err("alg: pcomp: compression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001281 "%d for %s: error=%d\n", i + 1, algo, res);
1282 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001283 }
1284
1285 memset(result, 0, sizeof(result));
1286
1287 req.next_in = ctemplate[i].input;
1288 req.avail_in = ctemplate[i].inlen / 2;
1289 req.next_out = result;
1290 req.avail_out = ctemplate[i].outlen / 2;
1291
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001292 res = crypto_compress_update(tfm, &req);
1293 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001294 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001295 "%d for %s: error=%d\n", i + 1, algo, res);
1296 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001297 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001298 if (res > 0)
1299 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001300
1301 /* Add remaining input data */
1302 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1303
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001304 res = crypto_compress_update(tfm, &req);
1305 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001306 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001307 "%d for %s: error=%d\n", i + 1, algo, res);
1308 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001309 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001310 if (res > 0)
1311 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001312
1313 /* Provide remaining output space */
1314 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1315
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001316 res = crypto_compress_final(tfm, &req);
1317 if (res < 0) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001318 pr_err("alg: pcomp: compression final failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001319 "%d for %s: error=%d\n", i + 1, algo, res);
1320 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001321 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001322 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001323
1324 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1325 pr_err("alg: comp: Compression test %d failed for %s: "
1326 "output len = %d (expected %d)\n", i + 1, algo,
1327 COMP_BUF_SIZE - req.avail_out,
1328 ctemplate[i].outlen);
1329 return -EINVAL;
1330 }
1331
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001332 if (produced != ctemplate[i].outlen) {
1333 pr_err("alg: comp: Compression test %d failed for %s: "
1334 "returned len = %u (expected %d)\n", i + 1,
1335 algo, produced, ctemplate[i].outlen);
1336 return -EINVAL;
1337 }
1338
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001339 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1340 pr_err("alg: pcomp: Compression test %d failed for "
1341 "%s\n", i + 1, algo);
1342 hexdump(result, ctemplate[i].outlen);
1343 return -EINVAL;
1344 }
1345 }
1346
1347 for (i = 0; i < dtcount; i++) {
1348 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001349 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001350
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001351 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1352 dtemplate[i].paramsize);
1353 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001354 pr_err("alg: pcomp: decompression setup failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001355 "test %d for %s: error=%d\n", i + 1, algo, res);
1356 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001357 }
1358
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001359 res = crypto_decompress_init(tfm);
1360 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001361 pr_err("alg: pcomp: decompression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001362 "%d for %s: error=%d\n", i + 1, algo, res);
1363 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001364 }
1365
1366 memset(result, 0, sizeof(result));
1367
1368 req.next_in = dtemplate[i].input;
1369 req.avail_in = dtemplate[i].inlen / 2;
1370 req.next_out = result;
1371 req.avail_out = dtemplate[i].outlen / 2;
1372
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001373 res = crypto_decompress_update(tfm, &req);
1374 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001375 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001376 "test %d for %s: error=%d\n", i + 1, algo, res);
1377 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001378 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001379 if (res > 0)
1380 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001381
1382 /* Add remaining input data */
1383 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1384
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001385 res = crypto_decompress_update(tfm, &req);
1386 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001387 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001388 "test %d for %s: error=%d\n", i + 1, algo, res);
1389 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001390 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001391 if (res > 0)
1392 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001393
1394 /* Provide remaining output space */
1395 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1396
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001397 res = crypto_decompress_final(tfm, &req);
1398 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001399 pr_err("alg: pcomp: decompression final failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001400 "test %d for %s: error=%d\n", i + 1, algo, res);
1401 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001402 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001403 if (res > 0)
1404 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001405
1406 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1407 pr_err("alg: comp: Decompression test %d failed for "
1408 "%s: output len = %d (expected %d)\n", i + 1,
1409 algo, COMP_BUF_SIZE - req.avail_out,
1410 dtemplate[i].outlen);
1411 return -EINVAL;
1412 }
1413
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001414 if (produced != dtemplate[i].outlen) {
1415 pr_err("alg: comp: Decompression test %d failed for "
1416 "%s: returned len = %u (expected %d)\n", i + 1,
1417 algo, produced, dtemplate[i].outlen);
1418 return -EINVAL;
1419 }
1420
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001421 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1422 pr_err("alg: pcomp: Decompression test %d failed for "
1423 "%s\n", i + 1, algo);
1424 hexdump(result, dtemplate[i].outlen);
1425 return -EINVAL;
1426 }
1427 }
1428
1429 return 0;
1430}
1431
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001432
1433static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1434 unsigned int tcount)
1435{
1436 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001437 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001438 u8 *seed;
1439 char result[32];
1440
1441 seedsize = crypto_rng_seedsize(tfm);
1442
1443 seed = kmalloc(seedsize, GFP_KERNEL);
1444 if (!seed) {
1445 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1446 "for %s\n", algo);
1447 return -ENOMEM;
1448 }
1449
1450 for (i = 0; i < tcount; i++) {
1451 memset(result, 0, 32);
1452
1453 memcpy(seed, template[i].v, template[i].vlen);
1454 memcpy(seed + template[i].vlen, template[i].key,
1455 template[i].klen);
1456 memcpy(seed + template[i].vlen + template[i].klen,
1457 template[i].dt, template[i].dtlen);
1458
1459 err = crypto_rng_reset(tfm, seed, seedsize);
1460 if (err) {
1461 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1462 "for %s\n", algo);
1463 goto out;
1464 }
1465
1466 for (j = 0; j < template[i].loops; j++) {
1467 err = crypto_rng_get_bytes(tfm, result,
1468 template[i].rlen);
1469 if (err != template[i].rlen) {
1470 printk(KERN_ERR "alg: cprng: Failed to obtain "
1471 "the correct amount of random data for "
1472 "%s (requested %d, got %d)\n", algo,
1473 template[i].rlen, err);
1474 goto out;
1475 }
1476 }
1477
1478 err = memcmp(result, template[i].result,
1479 template[i].rlen);
1480 if (err) {
1481 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1482 i, algo);
1483 hexdump(result, template[i].rlen);
1484 err = -EINVAL;
1485 goto out;
1486 }
1487 }
1488
1489out:
1490 kfree(seed);
1491 return err;
1492}
1493
Herbert Xuda7f0332008-07-31 17:08:25 +08001494static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1495 u32 type, u32 mask)
1496{
1497 struct crypto_aead *tfm;
1498 int err = 0;
1499
1500 tfm = crypto_alloc_aead(driver, type, mask);
1501 if (IS_ERR(tfm)) {
1502 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1503 "%ld\n", driver, PTR_ERR(tfm));
1504 return PTR_ERR(tfm);
1505 }
1506
1507 if (desc->suite.aead.enc.vecs) {
1508 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1509 desc->suite.aead.enc.count);
1510 if (err)
1511 goto out;
1512 }
1513
1514 if (!err && desc->suite.aead.dec.vecs)
1515 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1516 desc->suite.aead.dec.count);
1517
1518out:
1519 crypto_free_aead(tfm);
1520 return err;
1521}
1522
1523static int alg_test_cipher(const struct alg_test_desc *desc,
1524 const char *driver, u32 type, u32 mask)
1525{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001526 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001527 int err = 0;
1528
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001529 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001530 if (IS_ERR(tfm)) {
1531 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1532 "%s: %ld\n", driver, PTR_ERR(tfm));
1533 return PTR_ERR(tfm);
1534 }
1535
1536 if (desc->suite.cipher.enc.vecs) {
1537 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1538 desc->suite.cipher.enc.count);
1539 if (err)
1540 goto out;
1541 }
1542
1543 if (desc->suite.cipher.dec.vecs)
1544 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1545 desc->suite.cipher.dec.count);
1546
1547out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001548 crypto_free_cipher(tfm);
1549 return err;
1550}
1551
1552static int alg_test_skcipher(const struct alg_test_desc *desc,
1553 const char *driver, u32 type, u32 mask)
1554{
1555 struct crypto_ablkcipher *tfm;
1556 int err = 0;
1557
1558 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1559 if (IS_ERR(tfm)) {
1560 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1561 "%s: %ld\n", driver, PTR_ERR(tfm));
1562 return PTR_ERR(tfm);
1563 }
1564
1565 if (desc->suite.cipher.enc.vecs) {
1566 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1567 desc->suite.cipher.enc.count);
1568 if (err)
1569 goto out;
1570 }
1571
1572 if (desc->suite.cipher.dec.vecs)
1573 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1574 desc->suite.cipher.dec.count);
1575
1576out:
Herbert Xuda7f0332008-07-31 17:08:25 +08001577 crypto_free_ablkcipher(tfm);
1578 return err;
1579}
1580
1581static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1582 u32 type, u32 mask)
1583{
1584 struct crypto_comp *tfm;
1585 int err;
1586
1587 tfm = crypto_alloc_comp(driver, type, mask);
1588 if (IS_ERR(tfm)) {
1589 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1590 "%ld\n", driver, PTR_ERR(tfm));
1591 return PTR_ERR(tfm);
1592 }
1593
1594 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1595 desc->suite.comp.decomp.vecs,
1596 desc->suite.comp.comp.count,
1597 desc->suite.comp.decomp.count);
1598
1599 crypto_free_comp(tfm);
1600 return err;
1601}
1602
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001603static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1604 u32 type, u32 mask)
1605{
1606 struct crypto_pcomp *tfm;
1607 int err;
1608
1609 tfm = crypto_alloc_pcomp(driver, type, mask);
1610 if (IS_ERR(tfm)) {
1611 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1612 driver, PTR_ERR(tfm));
1613 return PTR_ERR(tfm);
1614 }
1615
1616 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1617 desc->suite.pcomp.decomp.vecs,
1618 desc->suite.pcomp.comp.count,
1619 desc->suite.pcomp.decomp.count);
1620
1621 crypto_free_pcomp(tfm);
1622 return err;
1623}
1624
Herbert Xuda7f0332008-07-31 17:08:25 +08001625static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1626 u32 type, u32 mask)
1627{
1628 struct crypto_ahash *tfm;
1629 int err;
1630
1631 tfm = crypto_alloc_ahash(driver, type, mask);
1632 if (IS_ERR(tfm)) {
1633 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1634 "%ld\n", driver, PTR_ERR(tfm));
1635 return PTR_ERR(tfm);
1636 }
1637
David S. Millera8f1a052010-05-19 14:12:03 +10001638 err = test_hash(tfm, desc->suite.hash.vecs,
1639 desc->suite.hash.count, true);
1640 if (!err)
1641 err = test_hash(tfm, desc->suite.hash.vecs,
1642 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001643
1644 crypto_free_ahash(tfm);
1645 return err;
1646}
1647
Herbert Xu8e3ee852008-11-07 14:58:52 +08001648static int alg_test_crc32c(const struct alg_test_desc *desc,
1649 const char *driver, u32 type, u32 mask)
1650{
1651 struct crypto_shash *tfm;
1652 u32 val;
1653 int err;
1654
1655 err = alg_test_hash(desc, driver, type, mask);
1656 if (err)
1657 goto out;
1658
1659 tfm = crypto_alloc_shash(driver, type, mask);
1660 if (IS_ERR(tfm)) {
1661 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1662 "%ld\n", driver, PTR_ERR(tfm));
1663 err = PTR_ERR(tfm);
1664 goto out;
1665 }
1666
1667 do {
1668 struct {
1669 struct shash_desc shash;
1670 char ctx[crypto_shash_descsize(tfm)];
1671 } sdesc;
1672
1673 sdesc.shash.tfm = tfm;
1674 sdesc.shash.flags = 0;
1675
1676 *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1677 err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1678 if (err) {
1679 printk(KERN_ERR "alg: crc32c: Operation failed for "
1680 "%s: %d\n", driver, err);
1681 break;
1682 }
1683
1684 if (val != ~420553207) {
1685 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1686 "%d\n", driver, val);
1687 err = -EINVAL;
1688 }
1689 } while (0);
1690
1691 crypto_free_shash(tfm);
1692
1693out:
1694 return err;
1695}
1696
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001697static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1698 u32 type, u32 mask)
1699{
1700 struct crypto_rng *rng;
1701 int err;
1702
1703 rng = crypto_alloc_rng(driver, type, mask);
1704 if (IS_ERR(rng)) {
1705 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1706 "%ld\n", driver, PTR_ERR(rng));
1707 return PTR_ERR(rng);
1708 }
1709
1710 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1711
1712 crypto_free_rng(rng);
1713
1714 return err;
1715}
1716
Youquan, Song863b5572009-12-23 19:45:20 +08001717static int alg_test_null(const struct alg_test_desc *desc,
1718 const char *driver, u32 type, u32 mask)
1719{
1720 return 0;
1721}
1722
Herbert Xuda7f0332008-07-31 17:08:25 +08001723/* Please keep this list sorted by algorithm name. */
1724static const struct alg_test_desc alg_test_descs[] = {
1725 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001726 .alg = "__cbc-cast5-avx",
1727 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001728 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001729 .alg = "__cbc-cast6-avx",
1730 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001731 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001732 .alg = "__cbc-serpent-avx",
1733 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001734 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001735 .alg = "__cbc-serpent-avx2",
1736 .test = alg_test_null,
1737 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001738 .alg = "__cbc-serpent-sse2",
1739 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001740 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001741 .alg = "__cbc-twofish-avx",
1742 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001743 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001744 .alg = "__driver-cbc-aes-aesni",
1745 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001746 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001747 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001748 .alg = "__driver-cbc-camellia-aesni",
1749 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001750 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001751 .alg = "__driver-cbc-camellia-aesni-avx2",
1752 .test = alg_test_null,
1753 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001754 .alg = "__driver-cbc-cast5-avx",
1755 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001756 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001757 .alg = "__driver-cbc-cast6-avx",
1758 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001759 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001760 .alg = "__driver-cbc-serpent-avx",
1761 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001762 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001763 .alg = "__driver-cbc-serpent-avx2",
1764 .test = alg_test_null,
1765 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001766 .alg = "__driver-cbc-serpent-sse2",
1767 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001768 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001769 .alg = "__driver-cbc-twofish-avx",
1770 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001771 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001772 .alg = "__driver-ecb-aes-aesni",
1773 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001774 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001775 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001776 .alg = "__driver-ecb-camellia-aesni",
1777 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001778 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001779 .alg = "__driver-ecb-camellia-aesni-avx2",
1780 .test = alg_test_null,
1781 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001782 .alg = "__driver-ecb-cast5-avx",
1783 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001784 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001785 .alg = "__driver-ecb-cast6-avx",
1786 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001787 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001788 .alg = "__driver-ecb-serpent-avx",
1789 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001790 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001791 .alg = "__driver-ecb-serpent-avx2",
1792 .test = alg_test_null,
1793 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001794 .alg = "__driver-ecb-serpent-sse2",
1795 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001796 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001797 .alg = "__driver-ecb-twofish-avx",
1798 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001799 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001800 .alg = "__ghash-pclmulqdqni",
1801 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001802 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001803 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001804 .alg = "ansi_cprng",
1805 .test = alg_test_cprng,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001806 .fips_allowed = 1,
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001807 .suite = {
1808 .cprng = {
1809 .vecs = ansi_cprng_aes_tv_template,
1810 .count = ANSI_CPRNG_AES_TEST_VECTORS
1811 }
1812 }
1813 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03001814 .alg = "authenc(hmac(sha1),cbc(aes))",
1815 .test = alg_test_aead,
1816 .fips_allowed = 1,
1817 .suite = {
1818 .aead = {
1819 .enc = {
1820 .vecs = hmac_sha1_aes_cbc_enc_tv_template,
1821 .count = HMAC_SHA1_AES_CBC_ENC_TEST_VECTORS
1822 }
1823 }
1824 }
1825 }, {
1826 .alg = "authenc(hmac(sha256),cbc(aes))",
1827 .test = alg_test_aead,
1828 .fips_allowed = 1,
1829 .suite = {
1830 .aead = {
1831 .enc = {
1832 .vecs = hmac_sha256_aes_cbc_enc_tv_template,
1833 .count = HMAC_SHA256_AES_CBC_ENC_TEST_VECTORS
1834 }
1835 }
1836 }
1837 }, {
1838 .alg = "authenc(hmac(sha512),cbc(aes))",
1839 .test = alg_test_aead,
1840 .fips_allowed = 1,
1841 .suite = {
1842 .aead = {
1843 .enc = {
1844 .vecs = hmac_sha512_aes_cbc_enc_tv_template,
1845 .count = HMAC_SHA512_AES_CBC_ENC_TEST_VECTORS
1846 }
1847 }
1848 }
1849 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08001850 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001851 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001852 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08001853 .suite = {
1854 .cipher = {
1855 .enc = {
1856 .vecs = aes_cbc_enc_tv_template,
1857 .count = AES_CBC_ENC_TEST_VECTORS
1858 },
1859 .dec = {
1860 .vecs = aes_cbc_dec_tv_template,
1861 .count = AES_CBC_DEC_TEST_VECTORS
1862 }
1863 }
1864 }
1865 }, {
1866 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001867 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08001868 .suite = {
1869 .cipher = {
1870 .enc = {
1871 .vecs = anubis_cbc_enc_tv_template,
1872 .count = ANUBIS_CBC_ENC_TEST_VECTORS
1873 },
1874 .dec = {
1875 .vecs = anubis_cbc_dec_tv_template,
1876 .count = ANUBIS_CBC_DEC_TEST_VECTORS
1877 }
1878 }
1879 }
1880 }, {
1881 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001882 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08001883 .suite = {
1884 .cipher = {
1885 .enc = {
1886 .vecs = bf_cbc_enc_tv_template,
1887 .count = BF_CBC_ENC_TEST_VECTORS
1888 },
1889 .dec = {
1890 .vecs = bf_cbc_dec_tv_template,
1891 .count = BF_CBC_DEC_TEST_VECTORS
1892 }
1893 }
1894 }
1895 }, {
1896 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001897 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08001898 .suite = {
1899 .cipher = {
1900 .enc = {
1901 .vecs = camellia_cbc_enc_tv_template,
1902 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
1903 },
1904 .dec = {
1905 .vecs = camellia_cbc_dec_tv_template,
1906 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
1907 }
1908 }
1909 }
1910 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001911 .alg = "cbc(cast5)",
1912 .test = alg_test_skcipher,
1913 .suite = {
1914 .cipher = {
1915 .enc = {
1916 .vecs = cast5_cbc_enc_tv_template,
1917 .count = CAST5_CBC_ENC_TEST_VECTORS
1918 },
1919 .dec = {
1920 .vecs = cast5_cbc_dec_tv_template,
1921 .count = CAST5_CBC_DEC_TEST_VECTORS
1922 }
1923 }
1924 }
1925 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001926 .alg = "cbc(cast6)",
1927 .test = alg_test_skcipher,
1928 .suite = {
1929 .cipher = {
1930 .enc = {
1931 .vecs = cast6_cbc_enc_tv_template,
1932 .count = CAST6_CBC_ENC_TEST_VECTORS
1933 },
1934 .dec = {
1935 .vecs = cast6_cbc_dec_tv_template,
1936 .count = CAST6_CBC_DEC_TEST_VECTORS
1937 }
1938 }
1939 }
1940 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08001941 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001942 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08001943 .suite = {
1944 .cipher = {
1945 .enc = {
1946 .vecs = des_cbc_enc_tv_template,
1947 .count = DES_CBC_ENC_TEST_VECTORS
1948 },
1949 .dec = {
1950 .vecs = des_cbc_dec_tv_template,
1951 .count = DES_CBC_DEC_TEST_VECTORS
1952 }
1953 }
1954 }
1955 }, {
1956 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001957 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001958 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08001959 .suite = {
1960 .cipher = {
1961 .enc = {
1962 .vecs = des3_ede_cbc_enc_tv_template,
1963 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
1964 },
1965 .dec = {
1966 .vecs = des3_ede_cbc_dec_tv_template,
1967 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
1968 }
1969 }
1970 }
1971 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03001972 .alg = "cbc(serpent)",
1973 .test = alg_test_skcipher,
1974 .suite = {
1975 .cipher = {
1976 .enc = {
1977 .vecs = serpent_cbc_enc_tv_template,
1978 .count = SERPENT_CBC_ENC_TEST_VECTORS
1979 },
1980 .dec = {
1981 .vecs = serpent_cbc_dec_tv_template,
1982 .count = SERPENT_CBC_DEC_TEST_VECTORS
1983 }
1984 }
1985 }
1986 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08001987 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001988 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08001989 .suite = {
1990 .cipher = {
1991 .enc = {
1992 .vecs = tf_cbc_enc_tv_template,
1993 .count = TF_CBC_ENC_TEST_VECTORS
1994 },
1995 .dec = {
1996 .vecs = tf_cbc_dec_tv_template,
1997 .count = TF_CBC_DEC_TEST_VECTORS
1998 }
1999 }
2000 }
2001 }, {
2002 .alg = "ccm(aes)",
2003 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002004 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002005 .suite = {
2006 .aead = {
2007 .enc = {
2008 .vecs = aes_ccm_enc_tv_template,
2009 .count = AES_CCM_ENC_TEST_VECTORS
2010 },
2011 .dec = {
2012 .vecs = aes_ccm_dec_tv_template,
2013 .count = AES_CCM_DEC_TEST_VECTORS
2014 }
2015 }
2016 }
2017 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002018 .alg = "cmac(aes)",
2019 .test = alg_test_hash,
2020 .suite = {
2021 .hash = {
2022 .vecs = aes_cmac128_tv_template,
2023 .count = CMAC_AES_TEST_VECTORS
2024 }
2025 }
2026 }, {
2027 .alg = "cmac(des3_ede)",
2028 .test = alg_test_hash,
2029 .suite = {
2030 .hash = {
2031 .vecs = des3_ede_cmac64_tv_template,
2032 .count = CMAC_DES3_EDE_TEST_VECTORS
2033 }
2034 }
2035 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002036 .alg = "compress_null",
2037 .test = alg_test_null,
2038 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002039 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002040 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002041 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002042 .suite = {
2043 .hash = {
2044 .vecs = crc32c_tv_template,
2045 .count = CRC32C_TEST_VECTORS
2046 }
2047 }
2048 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002049 .alg = "cryptd(__driver-cbc-aes-aesni)",
2050 .test = alg_test_null,
2051 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002052 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002053 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2054 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002055 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002056 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2057 .test = alg_test_null,
2058 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002059 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2060 .test = alg_test_null,
2061 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002062 .alg = "cryptd(__driver-ecb-aes-aesni)",
2063 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002064 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002065 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002066 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2067 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002068 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002069 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2070 .test = alg_test_null,
2071 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002072 .alg = "cryptd(__driver-ecb-cast5-avx)",
2073 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002074 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002075 .alg = "cryptd(__driver-ecb-cast6-avx)",
2076 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002077 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002078 .alg = "cryptd(__driver-ecb-serpent-avx)",
2079 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002080 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002081 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2082 .test = alg_test_null,
2083 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002084 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2085 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002086 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002087 .alg = "cryptd(__driver-ecb-twofish-avx)",
2088 .test = alg_test_null,
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002089 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002090 .alg = "cryptd(__driver-gcm-aes-aesni)",
2091 .test = alg_test_null,
2092 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002093 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002094 .alg = "cryptd(__ghash-pclmulqdqni)",
2095 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002096 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002097 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002098 .alg = "ctr(aes)",
2099 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002100 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002101 .suite = {
2102 .cipher = {
2103 .enc = {
2104 .vecs = aes_ctr_enc_tv_template,
2105 .count = AES_CTR_ENC_TEST_VECTORS
2106 },
2107 .dec = {
2108 .vecs = aes_ctr_dec_tv_template,
2109 .count = AES_CTR_DEC_TEST_VECTORS
2110 }
2111 }
2112 }
2113 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002114 .alg = "ctr(blowfish)",
2115 .test = alg_test_skcipher,
2116 .suite = {
2117 .cipher = {
2118 .enc = {
2119 .vecs = bf_ctr_enc_tv_template,
2120 .count = BF_CTR_ENC_TEST_VECTORS
2121 },
2122 .dec = {
2123 .vecs = bf_ctr_dec_tv_template,
2124 .count = BF_CTR_DEC_TEST_VECTORS
2125 }
2126 }
2127 }
2128 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002129 .alg = "ctr(camellia)",
2130 .test = alg_test_skcipher,
2131 .suite = {
2132 .cipher = {
2133 .enc = {
2134 .vecs = camellia_ctr_enc_tv_template,
2135 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2136 },
2137 .dec = {
2138 .vecs = camellia_ctr_dec_tv_template,
2139 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2140 }
2141 }
2142 }
2143 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002144 .alg = "ctr(cast5)",
2145 .test = alg_test_skcipher,
2146 .suite = {
2147 .cipher = {
2148 .enc = {
2149 .vecs = cast5_ctr_enc_tv_template,
2150 .count = CAST5_CTR_ENC_TEST_VECTORS
2151 },
2152 .dec = {
2153 .vecs = cast5_ctr_dec_tv_template,
2154 .count = CAST5_CTR_DEC_TEST_VECTORS
2155 }
2156 }
2157 }
2158 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002159 .alg = "ctr(cast6)",
2160 .test = alg_test_skcipher,
2161 .suite = {
2162 .cipher = {
2163 .enc = {
2164 .vecs = cast6_ctr_enc_tv_template,
2165 .count = CAST6_CTR_ENC_TEST_VECTORS
2166 },
2167 .dec = {
2168 .vecs = cast6_ctr_dec_tv_template,
2169 .count = CAST6_CTR_DEC_TEST_VECTORS
2170 }
2171 }
2172 }
2173 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002174 .alg = "ctr(des)",
2175 .test = alg_test_skcipher,
2176 .suite = {
2177 .cipher = {
2178 .enc = {
2179 .vecs = des_ctr_enc_tv_template,
2180 .count = DES_CTR_ENC_TEST_VECTORS
2181 },
2182 .dec = {
2183 .vecs = des_ctr_dec_tv_template,
2184 .count = DES_CTR_DEC_TEST_VECTORS
2185 }
2186 }
2187 }
2188 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002189 .alg = "ctr(des3_ede)",
2190 .test = alg_test_skcipher,
2191 .suite = {
2192 .cipher = {
2193 .enc = {
2194 .vecs = des3_ede_ctr_enc_tv_template,
2195 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2196 },
2197 .dec = {
2198 .vecs = des3_ede_ctr_dec_tv_template,
2199 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2200 }
2201 }
2202 }
2203 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002204 .alg = "ctr(serpent)",
2205 .test = alg_test_skcipher,
2206 .suite = {
2207 .cipher = {
2208 .enc = {
2209 .vecs = serpent_ctr_enc_tv_template,
2210 .count = SERPENT_CTR_ENC_TEST_VECTORS
2211 },
2212 .dec = {
2213 .vecs = serpent_ctr_dec_tv_template,
2214 .count = SERPENT_CTR_DEC_TEST_VECTORS
2215 }
2216 }
2217 }
2218 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002219 .alg = "ctr(twofish)",
2220 .test = alg_test_skcipher,
2221 .suite = {
2222 .cipher = {
2223 .enc = {
2224 .vecs = tf_ctr_enc_tv_template,
2225 .count = TF_CTR_ENC_TEST_VECTORS
2226 },
2227 .dec = {
2228 .vecs = tf_ctr_dec_tv_template,
2229 .count = TF_CTR_DEC_TEST_VECTORS
2230 }
2231 }
2232 }
2233 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002234 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002235 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002236 .suite = {
2237 .cipher = {
2238 .enc = {
2239 .vecs = cts_mode_enc_tv_template,
2240 .count = CTS_MODE_ENC_TEST_VECTORS
2241 },
2242 .dec = {
2243 .vecs = cts_mode_dec_tv_template,
2244 .count = CTS_MODE_DEC_TEST_VECTORS
2245 }
2246 }
2247 }
2248 }, {
2249 .alg = "deflate",
2250 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002251 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002252 .suite = {
2253 .comp = {
2254 .comp = {
2255 .vecs = deflate_comp_tv_template,
2256 .count = DEFLATE_COMP_TEST_VECTORS
2257 },
2258 .decomp = {
2259 .vecs = deflate_decomp_tv_template,
2260 .count = DEFLATE_DECOMP_TEST_VECTORS
2261 }
2262 }
2263 }
2264 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002265 .alg = "digest_null",
2266 .test = alg_test_null,
2267 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002268 .alg = "ecb(__aes-aesni)",
2269 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002270 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002271 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002272 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002273 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002274 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002275 .suite = {
2276 .cipher = {
2277 .enc = {
2278 .vecs = aes_enc_tv_template,
2279 .count = AES_ENC_TEST_VECTORS
2280 },
2281 .dec = {
2282 .vecs = aes_dec_tv_template,
2283 .count = AES_DEC_TEST_VECTORS
2284 }
2285 }
2286 }
2287 }, {
2288 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002289 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002290 .suite = {
2291 .cipher = {
2292 .enc = {
2293 .vecs = anubis_enc_tv_template,
2294 .count = ANUBIS_ENC_TEST_VECTORS
2295 },
2296 .dec = {
2297 .vecs = anubis_dec_tv_template,
2298 .count = ANUBIS_DEC_TEST_VECTORS
2299 }
2300 }
2301 }
2302 }, {
2303 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002304 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002305 .suite = {
2306 .cipher = {
2307 .enc = {
2308 .vecs = arc4_enc_tv_template,
2309 .count = ARC4_ENC_TEST_VECTORS
2310 },
2311 .dec = {
2312 .vecs = arc4_dec_tv_template,
2313 .count = ARC4_DEC_TEST_VECTORS
2314 }
2315 }
2316 }
2317 }, {
2318 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002319 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002320 .suite = {
2321 .cipher = {
2322 .enc = {
2323 .vecs = bf_enc_tv_template,
2324 .count = BF_ENC_TEST_VECTORS
2325 },
2326 .dec = {
2327 .vecs = bf_dec_tv_template,
2328 .count = BF_DEC_TEST_VECTORS
2329 }
2330 }
2331 }
2332 }, {
2333 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002334 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002335 .suite = {
2336 .cipher = {
2337 .enc = {
2338 .vecs = camellia_enc_tv_template,
2339 .count = CAMELLIA_ENC_TEST_VECTORS
2340 },
2341 .dec = {
2342 .vecs = camellia_dec_tv_template,
2343 .count = CAMELLIA_DEC_TEST_VECTORS
2344 }
2345 }
2346 }
2347 }, {
2348 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002349 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002350 .suite = {
2351 .cipher = {
2352 .enc = {
2353 .vecs = cast5_enc_tv_template,
2354 .count = CAST5_ENC_TEST_VECTORS
2355 },
2356 .dec = {
2357 .vecs = cast5_dec_tv_template,
2358 .count = CAST5_DEC_TEST_VECTORS
2359 }
2360 }
2361 }
2362 }, {
2363 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002364 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002365 .suite = {
2366 .cipher = {
2367 .enc = {
2368 .vecs = cast6_enc_tv_template,
2369 .count = CAST6_ENC_TEST_VECTORS
2370 },
2371 .dec = {
2372 .vecs = cast6_dec_tv_template,
2373 .count = CAST6_DEC_TEST_VECTORS
2374 }
2375 }
2376 }
2377 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002378 .alg = "ecb(cipher_null)",
2379 .test = alg_test_null,
2380 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002381 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002382 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002383 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002384 .suite = {
2385 .cipher = {
2386 .enc = {
2387 .vecs = des_enc_tv_template,
2388 .count = DES_ENC_TEST_VECTORS
2389 },
2390 .dec = {
2391 .vecs = des_dec_tv_template,
2392 .count = DES_DEC_TEST_VECTORS
2393 }
2394 }
2395 }
2396 }, {
2397 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002398 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002399 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002400 .suite = {
2401 .cipher = {
2402 .enc = {
2403 .vecs = des3_ede_enc_tv_template,
2404 .count = DES3_EDE_ENC_TEST_VECTORS
2405 },
2406 .dec = {
2407 .vecs = des3_ede_dec_tv_template,
2408 .count = DES3_EDE_DEC_TEST_VECTORS
2409 }
2410 }
2411 }
2412 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002413 .alg = "ecb(fcrypt)",
2414 .test = alg_test_skcipher,
2415 .suite = {
2416 .cipher = {
2417 .enc = {
2418 .vecs = fcrypt_pcbc_enc_tv_template,
2419 .count = 1
2420 },
2421 .dec = {
2422 .vecs = fcrypt_pcbc_dec_tv_template,
2423 .count = 1
2424 }
2425 }
2426 }
2427 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002428 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002429 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002430 .suite = {
2431 .cipher = {
2432 .enc = {
2433 .vecs = khazad_enc_tv_template,
2434 .count = KHAZAD_ENC_TEST_VECTORS
2435 },
2436 .dec = {
2437 .vecs = khazad_dec_tv_template,
2438 .count = KHAZAD_DEC_TEST_VECTORS
2439 }
2440 }
2441 }
2442 }, {
2443 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002444 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002445 .suite = {
2446 .cipher = {
2447 .enc = {
2448 .vecs = seed_enc_tv_template,
2449 .count = SEED_ENC_TEST_VECTORS
2450 },
2451 .dec = {
2452 .vecs = seed_dec_tv_template,
2453 .count = SEED_DEC_TEST_VECTORS
2454 }
2455 }
2456 }
2457 }, {
2458 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002459 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002460 .suite = {
2461 .cipher = {
2462 .enc = {
2463 .vecs = serpent_enc_tv_template,
2464 .count = SERPENT_ENC_TEST_VECTORS
2465 },
2466 .dec = {
2467 .vecs = serpent_dec_tv_template,
2468 .count = SERPENT_DEC_TEST_VECTORS
2469 }
2470 }
2471 }
2472 }, {
2473 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002474 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002475 .suite = {
2476 .cipher = {
2477 .enc = {
2478 .vecs = tea_enc_tv_template,
2479 .count = TEA_ENC_TEST_VECTORS
2480 },
2481 .dec = {
2482 .vecs = tea_dec_tv_template,
2483 .count = TEA_DEC_TEST_VECTORS
2484 }
2485 }
2486 }
2487 }, {
2488 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002489 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002490 .suite = {
2491 .cipher = {
2492 .enc = {
2493 .vecs = tnepres_enc_tv_template,
2494 .count = TNEPRES_ENC_TEST_VECTORS
2495 },
2496 .dec = {
2497 .vecs = tnepres_dec_tv_template,
2498 .count = TNEPRES_DEC_TEST_VECTORS
2499 }
2500 }
2501 }
2502 }, {
2503 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002504 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002505 .suite = {
2506 .cipher = {
2507 .enc = {
2508 .vecs = tf_enc_tv_template,
2509 .count = TF_ENC_TEST_VECTORS
2510 },
2511 .dec = {
2512 .vecs = tf_dec_tv_template,
2513 .count = TF_DEC_TEST_VECTORS
2514 }
2515 }
2516 }
2517 }, {
2518 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002519 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002520 .suite = {
2521 .cipher = {
2522 .enc = {
2523 .vecs = xeta_enc_tv_template,
2524 .count = XETA_ENC_TEST_VECTORS
2525 },
2526 .dec = {
2527 .vecs = xeta_dec_tv_template,
2528 .count = XETA_DEC_TEST_VECTORS
2529 }
2530 }
2531 }
2532 }, {
2533 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002534 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002535 .suite = {
2536 .cipher = {
2537 .enc = {
2538 .vecs = xtea_enc_tv_template,
2539 .count = XTEA_ENC_TEST_VECTORS
2540 },
2541 .dec = {
2542 .vecs = xtea_dec_tv_template,
2543 .count = XTEA_DEC_TEST_VECTORS
2544 }
2545 }
2546 }
2547 }, {
2548 .alg = "gcm(aes)",
2549 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002550 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002551 .suite = {
2552 .aead = {
2553 .enc = {
2554 .vecs = aes_gcm_enc_tv_template,
2555 .count = AES_GCM_ENC_TEST_VECTORS
2556 },
2557 .dec = {
2558 .vecs = aes_gcm_dec_tv_template,
2559 .count = AES_GCM_DEC_TEST_VECTORS
2560 }
2561 }
2562 }
2563 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08002564 .alg = "ghash",
2565 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11002566 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08002567 .suite = {
2568 .hash = {
2569 .vecs = ghash_tv_template,
2570 .count = GHASH_TEST_VECTORS
2571 }
2572 }
2573 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08002574 .alg = "hmac(crc32)",
2575 .test = alg_test_hash,
2576 .suite = {
2577 .hash = {
2578 .vecs = bfin_crc_tv_template,
2579 .count = BFIN_CRC_TEST_VECTORS
2580 }
2581 }
2582 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002583 .alg = "hmac(md5)",
2584 .test = alg_test_hash,
2585 .suite = {
2586 .hash = {
2587 .vecs = hmac_md5_tv_template,
2588 .count = HMAC_MD5_TEST_VECTORS
2589 }
2590 }
2591 }, {
2592 .alg = "hmac(rmd128)",
2593 .test = alg_test_hash,
2594 .suite = {
2595 .hash = {
2596 .vecs = hmac_rmd128_tv_template,
2597 .count = HMAC_RMD128_TEST_VECTORS
2598 }
2599 }
2600 }, {
2601 .alg = "hmac(rmd160)",
2602 .test = alg_test_hash,
2603 .suite = {
2604 .hash = {
2605 .vecs = hmac_rmd160_tv_template,
2606 .count = HMAC_RMD160_TEST_VECTORS
2607 }
2608 }
2609 }, {
2610 .alg = "hmac(sha1)",
2611 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002612 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002613 .suite = {
2614 .hash = {
2615 .vecs = hmac_sha1_tv_template,
2616 .count = HMAC_SHA1_TEST_VECTORS
2617 }
2618 }
2619 }, {
2620 .alg = "hmac(sha224)",
2621 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002622 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002623 .suite = {
2624 .hash = {
2625 .vecs = hmac_sha224_tv_template,
2626 .count = HMAC_SHA224_TEST_VECTORS
2627 }
2628 }
2629 }, {
2630 .alg = "hmac(sha256)",
2631 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002632 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002633 .suite = {
2634 .hash = {
2635 .vecs = hmac_sha256_tv_template,
2636 .count = HMAC_SHA256_TEST_VECTORS
2637 }
2638 }
2639 }, {
2640 .alg = "hmac(sha384)",
2641 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002642 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002643 .suite = {
2644 .hash = {
2645 .vecs = hmac_sha384_tv_template,
2646 .count = HMAC_SHA384_TEST_VECTORS
2647 }
2648 }
2649 }, {
2650 .alg = "hmac(sha512)",
2651 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002652 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002653 .suite = {
2654 .hash = {
2655 .vecs = hmac_sha512_tv_template,
2656 .count = HMAC_SHA512_TEST_VECTORS
2657 }
2658 }
2659 }, {
2660 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002661 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002662 .suite = {
2663 .cipher = {
2664 .enc = {
2665 .vecs = aes_lrw_enc_tv_template,
2666 .count = AES_LRW_ENC_TEST_VECTORS
2667 },
2668 .dec = {
2669 .vecs = aes_lrw_dec_tv_template,
2670 .count = AES_LRW_DEC_TEST_VECTORS
2671 }
2672 }
2673 }
2674 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002675 .alg = "lrw(camellia)",
2676 .test = alg_test_skcipher,
2677 .suite = {
2678 .cipher = {
2679 .enc = {
2680 .vecs = camellia_lrw_enc_tv_template,
2681 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
2682 },
2683 .dec = {
2684 .vecs = camellia_lrw_dec_tv_template,
2685 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
2686 }
2687 }
2688 }
2689 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002690 .alg = "lrw(cast6)",
2691 .test = alg_test_skcipher,
2692 .suite = {
2693 .cipher = {
2694 .enc = {
2695 .vecs = cast6_lrw_enc_tv_template,
2696 .count = CAST6_LRW_ENC_TEST_VECTORS
2697 },
2698 .dec = {
2699 .vecs = cast6_lrw_dec_tv_template,
2700 .count = CAST6_LRW_DEC_TEST_VECTORS
2701 }
2702 }
2703 }
2704 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03002705 .alg = "lrw(serpent)",
2706 .test = alg_test_skcipher,
2707 .suite = {
2708 .cipher = {
2709 .enc = {
2710 .vecs = serpent_lrw_enc_tv_template,
2711 .count = SERPENT_LRW_ENC_TEST_VECTORS
2712 },
2713 .dec = {
2714 .vecs = serpent_lrw_dec_tv_template,
2715 .count = SERPENT_LRW_DEC_TEST_VECTORS
2716 }
2717 }
2718 }
2719 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03002720 .alg = "lrw(twofish)",
2721 .test = alg_test_skcipher,
2722 .suite = {
2723 .cipher = {
2724 .enc = {
2725 .vecs = tf_lrw_enc_tv_template,
2726 .count = TF_LRW_ENC_TEST_VECTORS
2727 },
2728 .dec = {
2729 .vecs = tf_lrw_dec_tv_template,
2730 .count = TF_LRW_DEC_TEST_VECTORS
2731 }
2732 }
2733 }
2734 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002735 .alg = "lzo",
2736 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002737 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002738 .suite = {
2739 .comp = {
2740 .comp = {
2741 .vecs = lzo_comp_tv_template,
2742 .count = LZO_COMP_TEST_VECTORS
2743 },
2744 .decomp = {
2745 .vecs = lzo_decomp_tv_template,
2746 .count = LZO_DECOMP_TEST_VECTORS
2747 }
2748 }
2749 }
2750 }, {
2751 .alg = "md4",
2752 .test = alg_test_hash,
2753 .suite = {
2754 .hash = {
2755 .vecs = md4_tv_template,
2756 .count = MD4_TEST_VECTORS
2757 }
2758 }
2759 }, {
2760 .alg = "md5",
2761 .test = alg_test_hash,
2762 .suite = {
2763 .hash = {
2764 .vecs = md5_tv_template,
2765 .count = MD5_TEST_VECTORS
2766 }
2767 }
2768 }, {
2769 .alg = "michael_mic",
2770 .test = alg_test_hash,
2771 .suite = {
2772 .hash = {
2773 .vecs = michael_mic_tv_template,
2774 .count = MICHAEL_MIC_TEST_VECTORS
2775 }
2776 }
2777 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10002778 .alg = "ofb(aes)",
2779 .test = alg_test_skcipher,
2780 .fips_allowed = 1,
2781 .suite = {
2782 .cipher = {
2783 .enc = {
2784 .vecs = aes_ofb_enc_tv_template,
2785 .count = AES_OFB_ENC_TEST_VECTORS
2786 },
2787 .dec = {
2788 .vecs = aes_ofb_dec_tv_template,
2789 .count = AES_OFB_DEC_TEST_VECTORS
2790 }
2791 }
2792 }
2793 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002794 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002795 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002796 .suite = {
2797 .cipher = {
2798 .enc = {
2799 .vecs = fcrypt_pcbc_enc_tv_template,
2800 .count = FCRYPT_ENC_TEST_VECTORS
2801 },
2802 .dec = {
2803 .vecs = fcrypt_pcbc_dec_tv_template,
2804 .count = FCRYPT_DEC_TEST_VECTORS
2805 }
2806 }
2807 }
2808 }, {
2809 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002810 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002811 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002812 .suite = {
2813 .cipher = {
2814 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002815 .vecs = aes_ctr_rfc3686_enc_tv_template,
2816 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08002817 },
2818 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002819 .vecs = aes_ctr_rfc3686_dec_tv_template,
2820 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08002821 }
2822 }
2823 }
2824 }, {
Adrian Hoban69435b92010-11-04 15:02:04 -04002825 .alg = "rfc4106(gcm(aes))",
2826 .test = alg_test_aead,
2827 .suite = {
2828 .aead = {
2829 .enc = {
2830 .vecs = aes_gcm_rfc4106_enc_tv_template,
2831 .count = AES_GCM_4106_ENC_TEST_VECTORS
2832 },
2833 .dec = {
2834 .vecs = aes_gcm_rfc4106_dec_tv_template,
2835 .count = AES_GCM_4106_DEC_TEST_VECTORS
2836 }
2837 }
2838 }
2839 }, {
Jarod Wilson5d667322009-05-04 19:23:40 +08002840 .alg = "rfc4309(ccm(aes))",
2841 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002842 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08002843 .suite = {
2844 .aead = {
2845 .enc = {
2846 .vecs = aes_ccm_rfc4309_enc_tv_template,
2847 .count = AES_CCM_4309_ENC_TEST_VECTORS
2848 },
2849 .dec = {
2850 .vecs = aes_ccm_rfc4309_dec_tv_template,
2851 .count = AES_CCM_4309_DEC_TEST_VECTORS
2852 }
2853 }
2854 }
2855 }, {
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03002856 .alg = "rfc4543(gcm(aes))",
2857 .test = alg_test_aead,
2858 .suite = {
2859 .aead = {
2860 .enc = {
2861 .vecs = aes_gcm_rfc4543_enc_tv_template,
2862 .count = AES_GCM_4543_ENC_TEST_VECTORS
2863 },
2864 .dec = {
2865 .vecs = aes_gcm_rfc4543_dec_tv_template,
2866 .count = AES_GCM_4543_DEC_TEST_VECTORS
2867 },
2868 }
2869 }
2870 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002871 .alg = "rmd128",
2872 .test = alg_test_hash,
2873 .suite = {
2874 .hash = {
2875 .vecs = rmd128_tv_template,
2876 .count = RMD128_TEST_VECTORS
2877 }
2878 }
2879 }, {
2880 .alg = "rmd160",
2881 .test = alg_test_hash,
2882 .suite = {
2883 .hash = {
2884 .vecs = rmd160_tv_template,
2885 .count = RMD160_TEST_VECTORS
2886 }
2887 }
2888 }, {
2889 .alg = "rmd256",
2890 .test = alg_test_hash,
2891 .suite = {
2892 .hash = {
2893 .vecs = rmd256_tv_template,
2894 .count = RMD256_TEST_VECTORS
2895 }
2896 }
2897 }, {
2898 .alg = "rmd320",
2899 .test = alg_test_hash,
2900 .suite = {
2901 .hash = {
2902 .vecs = rmd320_tv_template,
2903 .count = RMD320_TEST_VECTORS
2904 }
2905 }
2906 }, {
2907 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002908 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002909 .suite = {
2910 .cipher = {
2911 .enc = {
2912 .vecs = salsa20_stream_enc_tv_template,
2913 .count = SALSA20_STREAM_ENC_TEST_VECTORS
2914 }
2915 }
2916 }
2917 }, {
2918 .alg = "sha1",
2919 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002920 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002921 .suite = {
2922 .hash = {
2923 .vecs = sha1_tv_template,
2924 .count = SHA1_TEST_VECTORS
2925 }
2926 }
2927 }, {
2928 .alg = "sha224",
2929 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002930 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002931 .suite = {
2932 .hash = {
2933 .vecs = sha224_tv_template,
2934 .count = SHA224_TEST_VECTORS
2935 }
2936 }
2937 }, {
2938 .alg = "sha256",
2939 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002940 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002941 .suite = {
2942 .hash = {
2943 .vecs = sha256_tv_template,
2944 .count = SHA256_TEST_VECTORS
2945 }
2946 }
2947 }, {
2948 .alg = "sha384",
2949 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002950 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002951 .suite = {
2952 .hash = {
2953 .vecs = sha384_tv_template,
2954 .count = SHA384_TEST_VECTORS
2955 }
2956 }
2957 }, {
2958 .alg = "sha512",
2959 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002960 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002961 .suite = {
2962 .hash = {
2963 .vecs = sha512_tv_template,
2964 .count = SHA512_TEST_VECTORS
2965 }
2966 }
2967 }, {
2968 .alg = "tgr128",
2969 .test = alg_test_hash,
2970 .suite = {
2971 .hash = {
2972 .vecs = tgr128_tv_template,
2973 .count = TGR128_TEST_VECTORS
2974 }
2975 }
2976 }, {
2977 .alg = "tgr160",
2978 .test = alg_test_hash,
2979 .suite = {
2980 .hash = {
2981 .vecs = tgr160_tv_template,
2982 .count = TGR160_TEST_VECTORS
2983 }
2984 }
2985 }, {
2986 .alg = "tgr192",
2987 .test = alg_test_hash,
2988 .suite = {
2989 .hash = {
2990 .vecs = tgr192_tv_template,
2991 .count = TGR192_TEST_VECTORS
2992 }
2993 }
2994 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10002995 .alg = "vmac(aes)",
2996 .test = alg_test_hash,
2997 .suite = {
2998 .hash = {
2999 .vecs = aes_vmac128_tv_template,
3000 .count = VMAC_AES_TEST_VECTORS
3001 }
3002 }
3003 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003004 .alg = "wp256",
3005 .test = alg_test_hash,
3006 .suite = {
3007 .hash = {
3008 .vecs = wp256_tv_template,
3009 .count = WP256_TEST_VECTORS
3010 }
3011 }
3012 }, {
3013 .alg = "wp384",
3014 .test = alg_test_hash,
3015 .suite = {
3016 .hash = {
3017 .vecs = wp384_tv_template,
3018 .count = WP384_TEST_VECTORS
3019 }
3020 }
3021 }, {
3022 .alg = "wp512",
3023 .test = alg_test_hash,
3024 .suite = {
3025 .hash = {
3026 .vecs = wp512_tv_template,
3027 .count = WP512_TEST_VECTORS
3028 }
3029 }
3030 }, {
3031 .alg = "xcbc(aes)",
3032 .test = alg_test_hash,
3033 .suite = {
3034 .hash = {
3035 .vecs = aes_xcbc128_tv_template,
3036 .count = XCBC_AES_TEST_VECTORS
3037 }
3038 }
3039 }, {
3040 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003041 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003042 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003043 .suite = {
3044 .cipher = {
3045 .enc = {
3046 .vecs = aes_xts_enc_tv_template,
3047 .count = AES_XTS_ENC_TEST_VECTORS
3048 },
3049 .dec = {
3050 .vecs = aes_xts_dec_tv_template,
3051 .count = AES_XTS_DEC_TEST_VECTORS
3052 }
3053 }
3054 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003055 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003056 .alg = "xts(camellia)",
3057 .test = alg_test_skcipher,
3058 .suite = {
3059 .cipher = {
3060 .enc = {
3061 .vecs = camellia_xts_enc_tv_template,
3062 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3063 },
3064 .dec = {
3065 .vecs = camellia_xts_dec_tv_template,
3066 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3067 }
3068 }
3069 }
3070 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003071 .alg = "xts(cast6)",
3072 .test = alg_test_skcipher,
3073 .suite = {
3074 .cipher = {
3075 .enc = {
3076 .vecs = cast6_xts_enc_tv_template,
3077 .count = CAST6_XTS_ENC_TEST_VECTORS
3078 },
3079 .dec = {
3080 .vecs = cast6_xts_dec_tv_template,
3081 .count = CAST6_XTS_DEC_TEST_VECTORS
3082 }
3083 }
3084 }
3085 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003086 .alg = "xts(serpent)",
3087 .test = alg_test_skcipher,
3088 .suite = {
3089 .cipher = {
3090 .enc = {
3091 .vecs = serpent_xts_enc_tv_template,
3092 .count = SERPENT_XTS_ENC_TEST_VECTORS
3093 },
3094 .dec = {
3095 .vecs = serpent_xts_dec_tv_template,
3096 .count = SERPENT_XTS_DEC_TEST_VECTORS
3097 }
3098 }
3099 }
3100 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003101 .alg = "xts(twofish)",
3102 .test = alg_test_skcipher,
3103 .suite = {
3104 .cipher = {
3105 .enc = {
3106 .vecs = tf_xts_enc_tv_template,
3107 .count = TF_XTS_ENC_TEST_VECTORS
3108 },
3109 .dec = {
3110 .vecs = tf_xts_dec_tv_template,
3111 .count = TF_XTS_DEC_TEST_VECTORS
3112 }
3113 }
3114 }
3115 }, {
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003116 .alg = "zlib",
3117 .test = alg_test_pcomp,
Milan Broz08189042012-12-06 17:16:28 +08003118 .fips_allowed = 1,
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003119 .suite = {
3120 .pcomp = {
3121 .comp = {
3122 .vecs = zlib_comp_tv_template,
3123 .count = ZLIB_COMP_TEST_VECTORS
3124 },
3125 .decomp = {
3126 .vecs = zlib_decomp_tv_template,
3127 .count = ZLIB_DECOMP_TEST_VECTORS
3128 }
3129 }
3130 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003131 }
3132};
3133
Jussi Kivilinna57147582013-06-13 17:37:40 +03003134static bool alg_test_descs_checked;
3135
3136static void alg_test_descs_check_order(void)
3137{
3138 int i;
3139
3140 /* only check once */
3141 if (alg_test_descs_checked)
3142 return;
3143
3144 alg_test_descs_checked = true;
3145
3146 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3147 int diff = strcmp(alg_test_descs[i - 1].alg,
3148 alg_test_descs[i].alg);
3149
3150 if (WARN_ON(diff > 0)) {
3151 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3152 alg_test_descs[i - 1].alg,
3153 alg_test_descs[i].alg);
3154 }
3155
3156 if (WARN_ON(diff == 0)) {
3157 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3158 alg_test_descs[i].alg);
3159 }
3160 }
3161}
3162
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003163static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003164{
3165 int start = 0;
3166 int end = ARRAY_SIZE(alg_test_descs);
3167
3168 while (start < end) {
3169 int i = (start + end) / 2;
3170 int diff = strcmp(alg_test_descs[i].alg, alg);
3171
3172 if (diff > 0) {
3173 end = i;
3174 continue;
3175 }
3176
3177 if (diff < 0) {
3178 start = i + 1;
3179 continue;
3180 }
3181
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003182 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003183 }
3184
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003185 return -1;
3186}
3187
3188int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3189{
3190 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003191 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003192 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003193
Jussi Kivilinna57147582013-06-13 17:37:40 +03003194 alg_test_descs_check_order();
3195
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003196 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3197 char nalg[CRYPTO_MAX_ALG_NAME];
3198
3199 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3200 sizeof(nalg))
3201 return -ENAMETOOLONG;
3202
3203 i = alg_find_test(nalg);
3204 if (i < 0)
3205 goto notest;
3206
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003207 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3208 goto non_fips_alg;
3209
Jarod Wilson941fb322009-05-04 19:49:23 +08003210 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3211 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003212 }
3213
3214 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003215 j = alg_find_test(driver);
3216 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003217 goto notest;
3218
Herbert Xua68f6612009-07-02 16:32:12 +08003219 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3220 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003221 goto non_fips_alg;
3222
Herbert Xua68f6612009-07-02 16:32:12 +08003223 rc = 0;
3224 if (i >= 0)
3225 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3226 type, mask);
3227 if (j >= 0)
3228 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3229 type, mask);
3230
Jarod Wilson941fb322009-05-04 19:49:23 +08003231test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003232 if (fips_enabled && rc)
3233 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3234
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003235 if (fips_enabled && !rc)
3236 printk(KERN_INFO "alg: self-tests for %s (%s) passed\n",
3237 driver, alg);
3238
Neil Hormand12d6b62008-10-12 20:36:51 +08003239 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003240
3241notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003242 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3243 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003244non_fips_alg:
3245 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003246}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003247
Herbert Xu326a6342010-08-06 09:40:28 +08003248#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003249
Herbert Xuda7f0332008-07-31 17:08:25 +08003250EXPORT_SYMBOL_GPL(alg_test);