blob: 717d6f2d8b0f3acf6990852eab44373a26b404ef [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
Herbert Xu1ce33112015-04-22 15:06:31 +080023#include <crypto/aead.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080024#include <crypto/hash.h>
25#include <linux/err.h>
Herbert Xu1c41b882015-04-22 13:25:58 +080026#include <linux/fips.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080027#include <linux/module.h>
28#include <linux/scatterlist.h>
29#include <linux/slab.h>
30#include <linux/string.h>
Jarod Wilson7647d6c2009-05-04 19:44:50 +080031#include <crypto/rng.h>
Stephan Mueller64d1cdf2014-05-31 17:25:36 +020032#include <crypto/drbg.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080033
34#include "internal.h"
Alexander Shishkin0b767f92010-06-03 20:53:43 +100035
Herbert Xu326a6342010-08-06 09:40:28 +080036#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
Alexander Shishkin0b767f92010-06-03 20:53:43 +100037
38/* a perfect nop */
39int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
40{
41 return 0;
42}
43
44#else
45
Herbert Xuda7f0332008-07-31 17:08:25 +080046#include "testmgr.h"
47
48/*
49 * Need slab memory for testing (size in number of pages).
50 */
51#define XBUFSIZE 8
52
53/*
54 * Indexes into the xbuf to simulate cross-page access.
55 */
56#define IDX1 32
57#define IDX2 32400
58#define IDX3 1
59#define IDX4 8193
60#define IDX5 22222
61#define IDX6 17101
62#define IDX7 27333
63#define IDX8 3000
64
65/*
66* Used by test_cipher()
67*/
68#define ENCRYPT 1
69#define DECRYPT 0
70
71struct tcrypt_result {
72 struct completion completion;
73 int err;
74};
75
76struct aead_test_suite {
77 struct {
78 struct aead_testvec *vecs;
79 unsigned int count;
80 } enc, dec;
81};
82
83struct cipher_test_suite {
84 struct {
85 struct cipher_testvec *vecs;
86 unsigned int count;
87 } enc, dec;
88};
89
90struct comp_test_suite {
91 struct {
92 struct comp_testvec *vecs;
93 unsigned int count;
94 } comp, decomp;
95};
96
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +080097struct pcomp_test_suite {
98 struct {
99 struct pcomp_testvec *vecs;
100 unsigned int count;
101 } comp, decomp;
102};
103
Herbert Xuda7f0332008-07-31 17:08:25 +0800104struct hash_test_suite {
105 struct hash_testvec *vecs;
106 unsigned int count;
107};
108
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800109struct cprng_test_suite {
110 struct cprng_testvec *vecs;
111 unsigned int count;
112};
113
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200114struct drbg_test_suite {
115 struct drbg_testvec *vecs;
116 unsigned int count;
117};
118
Herbert Xuda7f0332008-07-31 17:08:25 +0800119struct alg_test_desc {
120 const char *alg;
121 int (*test)(const struct alg_test_desc *desc, const char *driver,
122 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000123 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800124
125 union {
126 struct aead_test_suite aead;
127 struct cipher_test_suite cipher;
128 struct comp_test_suite comp;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +0800129 struct pcomp_test_suite pcomp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800130 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800131 struct cprng_test_suite cprng;
Stephan Mueller64d1cdf2014-05-31 17:25:36 +0200132 struct drbg_test_suite drbg;
Herbert Xuda7f0332008-07-31 17:08:25 +0800133 } suite;
134};
135
136static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
137
Herbert Xuda7f0332008-07-31 17:08:25 +0800138static void hexdump(unsigned char *buf, unsigned int len)
139{
140 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
141 16, 1,
142 buf, len, false);
143}
144
145static void tcrypt_complete(struct crypto_async_request *req, int err)
146{
147 struct tcrypt_result *res = req->data;
148
149 if (err == -EINPROGRESS)
150 return;
151
152 res->err = err;
153 complete(&res->completion);
154}
155
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800156static int testmgr_alloc_buf(char *buf[XBUFSIZE])
157{
158 int i;
159
160 for (i = 0; i < XBUFSIZE; i++) {
161 buf[i] = (void *)__get_free_page(GFP_KERNEL);
162 if (!buf[i])
163 goto err_free_buf;
164 }
165
166 return 0;
167
168err_free_buf:
169 while (i-- > 0)
170 free_page((unsigned long)buf[i]);
171
172 return -ENOMEM;
173}
174
175static void testmgr_free_buf(char *buf[XBUFSIZE])
176{
177 int i;
178
179 for (i = 0; i < XBUFSIZE; i++)
180 free_page((unsigned long)buf[i]);
181}
182
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300183static int wait_async_op(struct tcrypt_result *tr, int ret)
David S. Millera8f1a052010-05-19 14:12:03 +1000184{
185 if (ret == -EINPROGRESS || ret == -EBUSY) {
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100186 wait_for_completion(&tr->completion);
Wolfram Sang16735d02013-11-14 14:32:02 -0800187 reinit_completion(&tr->completion);
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100188 ret = tr->err;
David S. Millera8f1a052010-05-19 14:12:03 +1000189 }
190 return ret;
191}
192
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300193static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
194 unsigned int tcount, bool use_digest,
195 const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800196{
197 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
198 unsigned int i, j, k, temp;
199 struct scatterlist sg[8];
Horia Geanta29b77e52014-07-23 11:59:38 +0300200 char *result;
201 char *key;
Herbert Xuda7f0332008-07-31 17:08:25 +0800202 struct ahash_request *req;
203 struct tcrypt_result tresult;
Herbert Xuda7f0332008-07-31 17:08:25 +0800204 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800205 char *xbuf[XBUFSIZE];
206 int ret = -ENOMEM;
207
Horia Geanta29b77e52014-07-23 11:59:38 +0300208 result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
209 if (!result)
210 return ret;
211 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
212 if (!key)
213 goto out_nobuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800214 if (testmgr_alloc_buf(xbuf))
215 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800216
217 init_completion(&tresult.completion);
218
219 req = ahash_request_alloc(tfm, GFP_KERNEL);
220 if (!req) {
221 printk(KERN_ERR "alg: hash: Failed to allocate request for "
222 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800223 goto out_noreq;
224 }
225 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
226 tcrypt_complete, &tresult);
227
Herbert Xua0cfae52009-05-29 16:23:12 +1000228 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800229 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000230 if (template[i].np)
231 continue;
232
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300233 ret = -EINVAL;
234 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
235 goto out;
236
Herbert Xua0cfae52009-05-29 16:23:12 +1000237 j++;
Horia Geanta29b77e52014-07-23 11:59:38 +0300238 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800239
240 hash_buff = xbuf[0];
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300241 hash_buff += align_offset;
Herbert Xuda7f0332008-07-31 17:08:25 +0800242
243 memcpy(hash_buff, template[i].plaintext, template[i].psize);
244 sg_init_one(&sg[0], hash_buff, template[i].psize);
245
246 if (template[i].ksize) {
247 crypto_ahash_clear_flags(tfm, ~0);
Horia Geanta29b77e52014-07-23 11:59:38 +0300248 if (template[i].ksize > MAX_KEYLEN) {
249 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
250 j, algo, template[i].ksize, MAX_KEYLEN);
251 ret = -EINVAL;
252 goto out;
253 }
254 memcpy(key, template[i].key, template[i].ksize);
255 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
Herbert Xuda7f0332008-07-31 17:08:25 +0800256 if (ret) {
257 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000258 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800259 -ret);
260 goto out;
261 }
262 }
263
264 ahash_request_set_crypt(req, sg, result, template[i].psize);
David S. Millera8f1a052010-05-19 14:12:03 +1000265 if (use_digest) {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300266 ret = wait_async_op(&tresult, crypto_ahash_digest(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000267 if (ret) {
268 pr_err("alg: hash: digest failed on test %d "
269 "for %s: ret=%d\n", j, algo, -ret);
270 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800271 }
David S. Millera8f1a052010-05-19 14:12:03 +1000272 } else {
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300273 ret = wait_async_op(&tresult, crypto_ahash_init(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000274 if (ret) {
275 pr_err("alt: hash: init failed on test %d "
276 "for %s: ret=%d\n", j, algo, -ret);
277 goto out;
278 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300279 ret = wait_async_op(&tresult, crypto_ahash_update(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000280 if (ret) {
281 pr_err("alt: hash: update failed on test %d "
282 "for %s: ret=%d\n", j, algo, -ret);
283 goto out;
284 }
Cristian Stoicad4c85f92014-08-08 12:30:04 +0300285 ret = wait_async_op(&tresult, crypto_ahash_final(req));
David S. Millera8f1a052010-05-19 14:12:03 +1000286 if (ret) {
287 pr_err("alt: hash: final failed on test %d "
288 "for %s: ret=%d\n", j, algo, -ret);
289 goto out;
290 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800291 }
292
293 if (memcmp(result, template[i].digest,
294 crypto_ahash_digestsize(tfm))) {
295 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000296 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800297 hexdump(result, crypto_ahash_digestsize(tfm));
298 ret = -EINVAL;
299 goto out;
300 }
301 }
302
303 j = 0;
304 for (i = 0; i < tcount; i++) {
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300305 /* alignment tests are only done with continuous buffers */
306 if (align_offset != 0)
307 break;
308
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300309 if (!template[i].np)
310 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800311
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300312 j++;
313 memset(result, 0, MAX_DIGEST_SIZE);
Herbert Xuda7f0332008-07-31 17:08:25 +0800314
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300315 temp = 0;
316 sg_init_table(sg, template[i].np);
317 ret = -EINVAL;
318 for (k = 0; k < template[i].np; k++) {
319 if (WARN_ON(offset_in_page(IDX[k]) +
320 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +0800321 goto out;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300322 sg_set_buf(&sg[k],
323 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
324 offset_in_page(IDX[k]),
325 template[i].plaintext + temp,
326 template[i].tap[k]),
327 template[i].tap[k]);
328 temp += template[i].tap[k];
329 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800330
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300331 if (template[i].ksize) {
332 if (template[i].ksize > MAX_KEYLEN) {
333 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
334 j, algo, template[i].ksize, MAX_KEYLEN);
Herbert Xuda7f0332008-07-31 17:08:25 +0800335 ret = -EINVAL;
336 goto out;
337 }
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300338 crypto_ahash_clear_flags(tfm, ~0);
339 memcpy(key, template[i].key, template[i].ksize);
340 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
341
342 if (ret) {
343 printk(KERN_ERR "alg: hash: setkey "
344 "failed on chunking test %d "
345 "for %s: ret=%d\n", j, algo, -ret);
346 goto out;
347 }
348 }
349
350 ahash_request_set_crypt(req, sg, result, template[i].psize);
351 ret = crypto_ahash_digest(req);
352 switch (ret) {
353 case 0:
354 break;
355 case -EINPROGRESS:
356 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100357 wait_for_completion(&tresult.completion);
358 reinit_completion(&tresult.completion);
359 ret = tresult.err;
360 if (!ret)
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300361 break;
Cristian Stoica5f2b4242014-08-08 14:27:50 +0300362 /* fall through */
363 default:
364 printk(KERN_ERR "alg: hash: digest failed "
365 "on chunking test %d for %s: "
366 "ret=%d\n", j, algo, -ret);
367 goto out;
368 }
369
370 if (memcmp(result, template[i].digest,
371 crypto_ahash_digestsize(tfm))) {
372 printk(KERN_ERR "alg: hash: Chunking test %d "
373 "failed for %s\n", j, algo);
374 hexdump(result, crypto_ahash_digestsize(tfm));
375 ret = -EINVAL;
376 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800377 }
378 }
379
380 ret = 0;
381
382out:
383 ahash_request_free(req);
384out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800385 testmgr_free_buf(xbuf);
386out_nobuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300387 kfree(key);
388 kfree(result);
Herbert Xuda7f0332008-07-31 17:08:25 +0800389 return ret;
390}
391
Jussi Kivilinnada5ffe12013-06-13 17:37:55 +0300392static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
393 unsigned int tcount, bool use_digest)
394{
395 unsigned int alignmask;
396 int ret;
397
398 ret = __test_hash(tfm, template, tcount, use_digest, 0);
399 if (ret)
400 return ret;
401
402 /* test unaligned buffers, check with one byte offset */
403 ret = __test_hash(tfm, template, tcount, use_digest, 1);
404 if (ret)
405 return ret;
406
407 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
408 if (alignmask) {
409 /* Check if alignment mask for tfm is correctly set. */
410 ret = __test_hash(tfm, template, tcount, use_digest,
411 alignmask + 1);
412 if (ret)
413 return ret;
414 }
415
416 return 0;
417}
418
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300419static int __test_aead(struct crypto_aead *tfm, int enc,
420 struct aead_testvec *template, unsigned int tcount,
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300421 const bool diff_dst, const int align_offset)
Herbert Xuda7f0332008-07-31 17:08:25 +0800422{
423 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
424 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800425 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800426 char *q;
427 char *key;
428 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300429 struct scatterlist *sg;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300430 struct scatterlist *sgout;
431 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800432 struct tcrypt_result result;
Cristian Stoica424a5da2015-01-28 11:03:05 +0200433 unsigned int authsize, iv_len;
Herbert Xuda7f0332008-07-31 17:08:25 +0800434 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300435 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800436 void *assoc;
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700437 char *iv;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800438 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300439 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800440 char *axbuf[XBUFSIZE];
441
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700442 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
443 if (!iv)
444 return ret;
Horia Geanta29b77e52014-07-23 11:59:38 +0300445 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
446 if (!key)
447 goto out_noxbuf;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800448 if (testmgr_alloc_buf(xbuf))
449 goto out_noxbuf;
450 if (testmgr_alloc_buf(axbuf))
451 goto out_noaxbuf;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300452 if (diff_dst && testmgr_alloc_buf(xoutbuf))
453 goto out_nooutbuf;
454
455 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800456 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 4 : 2), GFP_KERNEL);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300457 if (!sg)
458 goto out_nosg;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800459 sgout = &sg[16];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300460
461 if (diff_dst)
462 d = "-ddst";
463 else
464 d = "";
465
Herbert Xuda7f0332008-07-31 17:08:25 +0800466 if (enc == ENCRYPT)
467 e = "encryption";
468 else
469 e = "decryption";
470
471 init_completion(&result.completion);
472
473 req = aead_request_alloc(tfm, GFP_KERNEL);
474 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300475 pr_err("alg: aead%s: Failed to allocate request for %s\n",
476 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800477 goto out;
478 }
479
480 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
481 tcrypt_complete, &result);
482
483 for (i = 0, j = 0; i < tcount; i++) {
Cristian Stoica05b1d332014-07-28 13:11:23 +0300484 if (template[i].np)
485 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800486
Cristian Stoica05b1d332014-07-28 13:11:23 +0300487 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800488
Cristian Stoica05b1d332014-07-28 13:11:23 +0300489 /* some templates have no input data but they will
490 * touch input
491 */
492 input = xbuf[0];
493 input += align_offset;
494 assoc = axbuf[0];
495
496 ret = -EINVAL;
497 if (WARN_ON(align_offset + template[i].ilen >
498 PAGE_SIZE || template[i].alen > PAGE_SIZE))
499 goto out;
500
501 memcpy(input, template[i].input, template[i].ilen);
502 memcpy(assoc, template[i].assoc, template[i].alen);
Cristian Stoica424a5da2015-01-28 11:03:05 +0200503 iv_len = crypto_aead_ivsize(tfm);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300504 if (template[i].iv)
Cristian Stoica424a5da2015-01-28 11:03:05 +0200505 memcpy(iv, template[i].iv, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300506 else
Cristian Stoica424a5da2015-01-28 11:03:05 +0200507 memset(iv, 0, iv_len);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300508
509 crypto_aead_clear_flags(tfm, ~0);
510 if (template[i].wk)
511 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
512
513 if (template[i].klen > MAX_KEYLEN) {
514 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
515 d, j, algo, template[i].klen,
516 MAX_KEYLEN);
Herbert Xufd57f222009-05-29 16:05:42 +1000517 ret = -EINVAL;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300518 goto out;
519 }
520 memcpy(key, template[i].key, template[i].klen);
Herbert Xufd57f222009-05-29 16:05:42 +1000521
Cristian Stoica05b1d332014-07-28 13:11:23 +0300522 ret = crypto_aead_setkey(tfm, key, template[i].klen);
523 if (!ret == template[i].fail) {
524 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
525 d, j, algo, crypto_aead_get_flags(tfm));
526 goto out;
527 } else if (ret)
528 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800529
Cristian Stoica05b1d332014-07-28 13:11:23 +0300530 authsize = abs(template[i].rlen - template[i].ilen);
531 ret = crypto_aead_setauthsize(tfm, authsize);
532 if (ret) {
533 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
534 d, authsize, j, algo);
535 goto out;
536 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800537
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800538 k = !!template[i].alen;
539 sg_init_table(sg, k + 1);
540 sg_set_buf(&sg[0], assoc, template[i].alen);
541 sg_set_buf(&sg[k], input,
542 template[i].ilen + (enc ? authsize : 0));
543 output = input;
544
Cristian Stoica05b1d332014-07-28 13:11:23 +0300545 if (diff_dst) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800546 sg_init_table(sgout, k + 1);
547 sg_set_buf(&sgout[0], assoc, template[i].alen);
548
Cristian Stoica05b1d332014-07-28 13:11:23 +0300549 output = xoutbuf[0];
550 output += align_offset;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800551 sg_set_buf(&sgout[k], output,
552 template[i].rlen + (enc ? 0 : authsize));
Cristian Stoica05b1d332014-07-28 13:11:23 +0300553 }
554
Cristian Stoica05b1d332014-07-28 13:11:23 +0300555 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
556 template[i].ilen, iv);
557
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800558 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300559
560 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
561
562 switch (ret) {
563 case 0:
564 if (template[i].novrfy) {
565 /* verification was supposed to fail */
566 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
567 d, e, j, algo);
568 /* so really, we got a bad message */
569 ret = -EBADMSG;
Horia Geanta29b77e52014-07-23 11:59:38 +0300570 goto out;
571 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300572 break;
573 case -EINPROGRESS:
574 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100575 wait_for_completion(&result.completion);
576 reinit_completion(&result.completion);
577 ret = result.err;
578 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +0800579 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300580 case -EBADMSG:
581 if (template[i].novrfy)
582 /* verification failure was expected */
583 continue;
584 /* fall through */
585 default:
586 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
587 d, e, j, algo, -ret);
588 goto out;
589 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800590
Cristian Stoica05b1d332014-07-28 13:11:23 +0300591 q = output;
592 if (memcmp(q, template[i].result, template[i].rlen)) {
593 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
594 d, j, e, algo);
595 hexdump(q, template[i].rlen);
596 ret = -EINVAL;
597 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800598 }
599 }
600
601 for (i = 0, j = 0; i < tcount; i++) {
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300602 /* alignment tests are only done with continuous buffers */
603 if (align_offset != 0)
604 break;
605
Cristian Stoica05b1d332014-07-28 13:11:23 +0300606 if (!template[i].np)
607 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800608
Cristian Stoica05b1d332014-07-28 13:11:23 +0300609 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800610
Cristian Stoica05b1d332014-07-28 13:11:23 +0300611 if (template[i].iv)
612 memcpy(iv, template[i].iv, MAX_IVLEN);
613 else
614 memset(iv, 0, MAX_IVLEN);
615
616 crypto_aead_clear_flags(tfm, ~0);
617 if (template[i].wk)
618 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
619 if (template[i].klen > MAX_KEYLEN) {
620 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
621 d, j, algo, template[i].klen, MAX_KEYLEN);
622 ret = -EINVAL;
623 goto out;
624 }
625 memcpy(key, template[i].key, template[i].klen);
626
627 ret = crypto_aead_setkey(tfm, key, template[i].klen);
628 if (!ret == template[i].fail) {
629 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
630 d, j, algo, crypto_aead_get_flags(tfm));
631 goto out;
632 } else if (ret)
633 continue;
634
635 authsize = abs(template[i].rlen - template[i].ilen);
636
637 ret = -EINVAL;
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800638 sg_init_table(sg, template[i].anp + template[i].np);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300639 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800640 sg_init_table(sgout, template[i].anp + template[i].np);
641
642 ret = -EINVAL;
643 for (k = 0, temp = 0; k < template[i].anp; k++) {
644 if (WARN_ON(offset_in_page(IDX[k]) +
645 template[i].atap[k] > PAGE_SIZE))
646 goto out;
647 sg_set_buf(&sg[k],
648 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
649 offset_in_page(IDX[k]),
650 template[i].assoc + temp,
651 template[i].atap[k]),
652 template[i].atap[k]);
653 if (diff_dst)
654 sg_set_buf(&sgout[k],
655 axbuf[IDX[k] >> PAGE_SHIFT] +
656 offset_in_page(IDX[k]),
657 template[i].atap[k]);
658 temp += template[i].atap[k];
659 }
660
Cristian Stoica05b1d332014-07-28 13:11:23 +0300661 for (k = 0, temp = 0; k < template[i].np; k++) {
662 if (WARN_ON(offset_in_page(IDX[k]) +
663 template[i].tap[k] > PAGE_SIZE))
664 goto out;
665
666 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
667 memcpy(q, template[i].input + temp, template[i].tap[k]);
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800668 sg_set_buf(&sg[template[i].anp + k],
669 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300670
671 if (diff_dst) {
672 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
673 offset_in_page(IDX[k]);
674
675 memset(q, 0, template[i].tap[k]);
676
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800677 sg_set_buf(&sgout[template[i].anp + k],
678 q, template[i].tap[k]);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300679 }
680
681 n = template[i].tap[k];
682 if (k == template[i].np - 1 && enc)
683 n += authsize;
684 if (offset_in_page(q) + n < PAGE_SIZE)
685 q[n] = 0;
686
687 temp += template[i].tap[k];
688 }
689
690 ret = crypto_aead_setauthsize(tfm, authsize);
691 if (ret) {
692 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
693 d, authsize, j, algo);
694 goto out;
695 }
696
697 if (enc) {
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800698 if (WARN_ON(sg[template[i].anp + k - 1].offset +
699 sg[template[i].anp + k - 1].length +
700 authsize > PAGE_SIZE)) {
Horia Geanta29b77e52014-07-23 11:59:38 +0300701 ret = -EINVAL;
702 goto out;
703 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800704
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300705 if (diff_dst)
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800706 sgout[template[i].anp + k - 1].length +=
707 authsize;
708 sg[template[i].anp + k - 1].length += authsize;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300709 }
710
711 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
712 template[i].ilen,
713 iv);
714
Herbert Xu8a525fcd2015-05-27 16:03:43 +0800715 aead_request_set_ad(req, template[i].alen);
Cristian Stoica05b1d332014-07-28 13:11:23 +0300716
717 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
718
719 switch (ret) {
720 case 0:
721 if (template[i].novrfy) {
722 /* verification was supposed to fail */
723 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
724 d, e, j, algo);
725 /* so really, we got a bad message */
726 ret = -EBADMSG;
727 goto out;
728 }
729 break;
730 case -EINPROGRESS:
731 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100732 wait_for_completion(&result.completion);
733 reinit_completion(&result.completion);
734 ret = result.err;
735 if (!ret)
Cristian Stoica05b1d332014-07-28 13:11:23 +0300736 break;
Cristian Stoica05b1d332014-07-28 13:11:23 +0300737 case -EBADMSG:
738 if (template[i].novrfy)
739 /* verification failure was expected */
740 continue;
741 /* fall through */
742 default:
743 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
744 d, e, j, algo, -ret);
745 goto out;
746 }
747
748 ret = -EINVAL;
749 for (k = 0, temp = 0; k < template[i].np; k++) {
750 if (diff_dst)
751 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
752 offset_in_page(IDX[k]);
753 else
Herbert Xuda7f0332008-07-31 17:08:25 +0800754 q = xbuf[IDX[k] >> PAGE_SHIFT] +
755 offset_in_page(IDX[k]);
756
Cristian Stoica05b1d332014-07-28 13:11:23 +0300757 n = template[i].tap[k];
758 if (k == template[i].np - 1)
759 n += enc ? authsize : -authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800760
Cristian Stoica05b1d332014-07-28 13:11:23 +0300761 if (memcmp(q, template[i].result + temp, n)) {
762 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
763 d, j, e, k, algo);
764 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800765 goto out;
766 }
767
Cristian Stoica05b1d332014-07-28 13:11:23 +0300768 q += n;
769 if (k == template[i].np - 1 && !enc) {
770 if (!diff_dst &&
771 memcmp(q, template[i].input +
772 temp + n, authsize))
773 n = authsize;
Horia Geanta8ec25c52013-11-28 15:11:18 +0200774 else
Cristian Stoica05b1d332014-07-28 13:11:23 +0300775 n = 0;
776 } else {
777 for (n = 0; offset_in_page(q + n) && q[n]; n++)
778 ;
Herbert Xuda7f0332008-07-31 17:08:25 +0800779 }
Cristian Stoica05b1d332014-07-28 13:11:23 +0300780 if (n) {
781 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
782 d, j, e, k, algo, n);
783 hexdump(q, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800784 goto out;
785 }
786
Cristian Stoica05b1d332014-07-28 13:11:23 +0300787 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +0800788 }
789 }
790
791 ret = 0;
792
793out:
794 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300795 kfree(sg);
796out_nosg:
797 if (diff_dst)
798 testmgr_free_buf(xoutbuf);
799out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800800 testmgr_free_buf(axbuf);
801out_noaxbuf:
802 testmgr_free_buf(xbuf);
803out_noxbuf:
Horia Geanta29b77e52014-07-23 11:59:38 +0300804 kfree(key);
Tadeusz Struk9bac0192014-05-19 09:51:33 -0700805 kfree(iv);
Herbert Xuda7f0332008-07-31 17:08:25 +0800806 return ret;
807}
808
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300809static int test_aead(struct crypto_aead *tfm, int enc,
810 struct aead_testvec *template, unsigned int tcount)
811{
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300812 unsigned int alignmask;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300813 int ret;
814
815 /* test 'dst == src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300816 ret = __test_aead(tfm, enc, template, tcount, false, 0);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300817 if (ret)
818 return ret;
819
820 /* test 'dst != src' case */
Jussi Kivilinna58dcf542013-06-13 17:37:50 +0300821 ret = __test_aead(tfm, enc, template, tcount, true, 0);
822 if (ret)
823 return ret;
824
825 /* test unaligned buffers, check with one byte offset */
826 ret = __test_aead(tfm, enc, template, tcount, true, 1);
827 if (ret)
828 return ret;
829
830 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
831 if (alignmask) {
832 /* Check if alignment mask for tfm is correctly set. */
833 ret = __test_aead(tfm, enc, template, tcount, true,
834 alignmask + 1);
835 if (ret)
836 return ret;
837 }
838
839 return 0;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300840}
841
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000842static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800843 struct cipher_testvec *template, unsigned int tcount)
844{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000845 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
846 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000847 char *q;
848 const char *e;
849 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800850 char *xbuf[XBUFSIZE];
851 int ret = -ENOMEM;
852
853 if (testmgr_alloc_buf(xbuf))
854 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000855
856 if (enc == ENCRYPT)
857 e = "encryption";
858 else
859 e = "decryption";
860
861 j = 0;
862 for (i = 0; i < tcount; i++) {
863 if (template[i].np)
864 continue;
865
866 j++;
867
Herbert Xufd57f222009-05-29 16:05:42 +1000868 ret = -EINVAL;
869 if (WARN_ON(template[i].ilen > PAGE_SIZE))
870 goto out;
871
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000872 data = xbuf[0];
873 memcpy(data, template[i].input, template[i].ilen);
874
875 crypto_cipher_clear_flags(tfm, ~0);
876 if (template[i].wk)
877 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
878
879 ret = crypto_cipher_setkey(tfm, template[i].key,
880 template[i].klen);
881 if (!ret == template[i].fail) {
882 printk(KERN_ERR "alg: cipher: setkey failed "
883 "on test %d for %s: flags=%x\n", j,
884 algo, crypto_cipher_get_flags(tfm));
885 goto out;
886 } else if (ret)
887 continue;
888
889 for (k = 0; k < template[i].ilen;
890 k += crypto_cipher_blocksize(tfm)) {
891 if (enc)
892 crypto_cipher_encrypt_one(tfm, data + k,
893 data + k);
894 else
895 crypto_cipher_decrypt_one(tfm, data + k,
896 data + k);
897 }
898
899 q = data;
900 if (memcmp(q, template[i].result, template[i].rlen)) {
901 printk(KERN_ERR "alg: cipher: Test %d failed "
902 "on %s for %s\n", j, e, algo);
903 hexdump(q, template[i].rlen);
904 ret = -EINVAL;
905 goto out;
906 }
907 }
908
909 ret = 0;
910
911out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800912 testmgr_free_buf(xbuf);
913out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000914 return ret;
915}
916
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300917static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
918 struct cipher_testvec *template, unsigned int tcount,
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300919 const bool diff_dst, const int align_offset)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000920{
Herbert Xuda7f0332008-07-31 17:08:25 +0800921 const char *algo =
922 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
923 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800924 char *q;
925 struct ablkcipher_request *req;
926 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300927 struct scatterlist sgout[8];
928 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800929 struct tcrypt_result result;
930 void *data;
931 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800932 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300933 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800934 int ret = -ENOMEM;
935
936 if (testmgr_alloc_buf(xbuf))
937 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800938
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300939 if (diff_dst && testmgr_alloc_buf(xoutbuf))
940 goto out_nooutbuf;
941
942 if (diff_dst)
943 d = "-ddst";
944 else
945 d = "";
946
Herbert Xuda7f0332008-07-31 17:08:25 +0800947 if (enc == ENCRYPT)
948 e = "encryption";
949 else
950 e = "decryption";
951
952 init_completion(&result.completion);
953
954 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
955 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300956 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
957 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800958 goto out;
959 }
960
961 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
962 tcrypt_complete, &result);
963
964 j = 0;
965 for (i = 0; i < tcount; i++) {
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +0300966 if (template[i].np && !template[i].also_non_np)
967 continue;
968
Herbert Xuda7f0332008-07-31 17:08:25 +0800969 if (template[i].iv)
970 memcpy(iv, template[i].iv, MAX_IVLEN);
971 else
972 memset(iv, 0, MAX_IVLEN);
973
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300974 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +0300975 ret = -EINVAL;
976 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
977 goto out;
978
979 data = xbuf[0];
980 data += align_offset;
981 memcpy(data, template[i].input, template[i].ilen);
982
983 crypto_ablkcipher_clear_flags(tfm, ~0);
984 if (template[i].wk)
985 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
986
987 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
988 template[i].klen);
989 if (!ret == template[i].fail) {
990 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
991 d, j, algo, crypto_ablkcipher_get_flags(tfm));
992 goto out;
993 } else if (ret)
994 continue;
995
996 sg_init_one(&sg[0], data, template[i].ilen);
997 if (diff_dst) {
998 data = xoutbuf[0];
Jussi Kivilinna3a338f22013-06-13 17:37:45 +0300999 data += align_offset;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001000 sg_init_one(&sgout[0], data, template[i].ilen);
1001 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001002
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001003 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1004 template[i].ilen, iv);
1005 ret = enc ? crypto_ablkcipher_encrypt(req) :
1006 crypto_ablkcipher_decrypt(req);
Herbert Xuda7f0332008-07-31 17:08:25 +08001007
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001008 switch (ret) {
1009 case 0:
1010 break;
1011 case -EINPROGRESS:
1012 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001013 wait_for_completion(&result.completion);
1014 reinit_completion(&result.completion);
1015 ret = result.err;
1016 if (!ret)
Herbert Xuda7f0332008-07-31 17:08:25 +08001017 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001018 /* fall through */
1019 default:
1020 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1021 d, e, j, algo, -ret);
1022 goto out;
1023 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001024
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001025 q = data;
1026 if (memcmp(q, template[i].result, template[i].rlen)) {
1027 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1028 d, j, e, algo);
1029 hexdump(q, template[i].rlen);
1030 ret = -EINVAL;
1031 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001032 }
1033 }
1034
1035 j = 0;
1036 for (i = 0; i < tcount; i++) {
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001037 /* alignment tests are only done with continuous buffers */
1038 if (align_offset != 0)
1039 break;
Herbert Xuda7f0332008-07-31 17:08:25 +08001040
Cristian Stoicabbb9a7d2014-08-08 14:27:52 +03001041 if (!template[i].np)
1042 continue;
1043
Herbert Xuda7f0332008-07-31 17:08:25 +08001044 if (template[i].iv)
1045 memcpy(iv, template[i].iv, MAX_IVLEN);
1046 else
1047 memset(iv, 0, MAX_IVLEN);
1048
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001049 j++;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001050 crypto_ablkcipher_clear_flags(tfm, ~0);
1051 if (template[i].wk)
1052 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1053
1054 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1055 template[i].klen);
1056 if (!ret == template[i].fail) {
1057 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1058 d, j, algo, crypto_ablkcipher_get_flags(tfm));
1059 goto out;
1060 } else if (ret)
1061 continue;
1062
1063 temp = 0;
1064 ret = -EINVAL;
1065 sg_init_table(sg, template[i].np);
1066 if (diff_dst)
1067 sg_init_table(sgout, template[i].np);
1068 for (k = 0; k < template[i].np; k++) {
1069 if (WARN_ON(offset_in_page(IDX[k]) +
1070 template[i].tap[k] > PAGE_SIZE))
Herbert Xuda7f0332008-07-31 17:08:25 +08001071 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001072
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001073 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1074
1075 memcpy(q, template[i].input + temp, template[i].tap[k]);
1076
1077 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1078 q[template[i].tap[k]] = 0;
1079
1080 sg_set_buf(&sg[k], q, template[i].tap[k]);
1081 if (diff_dst) {
1082 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1083 offset_in_page(IDX[k]);
1084
1085 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1086
1087 memset(q, 0, template[i].tap[k]);
1088 if (offset_in_page(q) +
1089 template[i].tap[k] < PAGE_SIZE)
1090 q[template[i].tap[k]] = 0;
1091 }
1092
1093 temp += template[i].tap[k];
1094 }
1095
1096 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1097 template[i].ilen, iv);
1098
1099 ret = enc ? crypto_ablkcipher_encrypt(req) :
1100 crypto_ablkcipher_decrypt(req);
1101
1102 switch (ret) {
1103 case 0:
1104 break;
1105 case -EINPROGRESS:
1106 case -EBUSY:
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001107 wait_for_completion(&result.completion);
1108 reinit_completion(&result.completion);
1109 ret = result.err;
1110 if (!ret)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001111 break;
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001112 /* fall through */
1113 default:
1114 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1115 d, e, j, algo, -ret);
1116 goto out;
1117 }
1118
1119 temp = 0;
1120 ret = -EINVAL;
1121 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001122 if (diff_dst)
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001123 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1124 offset_in_page(IDX[k]);
1125 else
Herbert Xuda7f0332008-07-31 17:08:25 +08001126 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1127 offset_in_page(IDX[k]);
1128
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001129 if (memcmp(q, template[i].result + temp,
1130 template[i].tap[k])) {
1131 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1132 d, j, e, k, algo);
1133 hexdump(q, template[i].tap[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001134 goto out;
1135 }
1136
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001137 q += template[i].tap[k];
1138 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1139 ;
1140 if (n) {
1141 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1142 d, j, e, k, algo, n);
1143 hexdump(q, n);
1144 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +08001145 }
Cristian Stoicaa1aa44a2014-08-08 14:27:51 +03001146 temp += template[i].tap[k];
Herbert Xuda7f0332008-07-31 17:08:25 +08001147 }
1148 }
1149
1150 ret = 0;
1151
1152out:
1153 ablkcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001154 if (diff_dst)
1155 testmgr_free_buf(xoutbuf);
1156out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001157 testmgr_free_buf(xbuf);
1158out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001159 return ret;
1160}
1161
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001162static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1163 struct cipher_testvec *template, unsigned int tcount)
1164{
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001165 unsigned int alignmask;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001166 int ret;
1167
1168 /* test 'dst == src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001169 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001170 if (ret)
1171 return ret;
1172
1173 /* test 'dst != src' case */
Jussi Kivilinna3a338f22013-06-13 17:37:45 +03001174 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1175 if (ret)
1176 return ret;
1177
1178 /* test unaligned buffers, check with one byte offset */
1179 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1180 if (ret)
1181 return ret;
1182
1183 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1184 if (alignmask) {
1185 /* Check if alignment mask for tfm is correctly set. */
1186 ret = __test_skcipher(tfm, enc, template, tcount, true,
1187 alignmask + 1);
1188 if (ret)
1189 return ret;
1190 }
1191
1192 return 0;
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001193}
1194
Herbert Xuda7f0332008-07-31 17:08:25 +08001195static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1196 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1197{
1198 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1199 unsigned int i;
1200 char result[COMP_BUF_SIZE];
1201 int ret;
1202
1203 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001204 int ilen;
1205 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001206
1207 memset(result, 0, sizeof (result));
1208
1209 ilen = ctemplate[i].inlen;
1210 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1211 ilen, result, &dlen);
1212 if (ret) {
1213 printk(KERN_ERR "alg: comp: compression failed "
1214 "on test %d for %s: ret=%d\n", i + 1, algo,
1215 -ret);
1216 goto out;
1217 }
1218
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001219 if (dlen != ctemplate[i].outlen) {
1220 printk(KERN_ERR "alg: comp: Compression test %d "
1221 "failed for %s: output len = %d\n", i + 1, algo,
1222 dlen);
1223 ret = -EINVAL;
1224 goto out;
1225 }
1226
Herbert Xuda7f0332008-07-31 17:08:25 +08001227 if (memcmp(result, ctemplate[i].output, dlen)) {
1228 printk(KERN_ERR "alg: comp: Compression test %d "
1229 "failed for %s\n", i + 1, algo);
1230 hexdump(result, dlen);
1231 ret = -EINVAL;
1232 goto out;
1233 }
1234 }
1235
1236 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001237 int ilen;
1238 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001239
1240 memset(result, 0, sizeof (result));
1241
1242 ilen = dtemplate[i].inlen;
1243 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1244 ilen, result, &dlen);
1245 if (ret) {
1246 printk(KERN_ERR "alg: comp: decompression failed "
1247 "on test %d for %s: ret=%d\n", i + 1, algo,
1248 -ret);
1249 goto out;
1250 }
1251
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001252 if (dlen != dtemplate[i].outlen) {
1253 printk(KERN_ERR "alg: comp: Decompression test %d "
1254 "failed for %s: output len = %d\n", i + 1, algo,
1255 dlen);
1256 ret = -EINVAL;
1257 goto out;
1258 }
1259
Herbert Xuda7f0332008-07-31 17:08:25 +08001260 if (memcmp(result, dtemplate[i].output, dlen)) {
1261 printk(KERN_ERR "alg: comp: Decompression test %d "
1262 "failed for %s\n", i + 1, algo);
1263 hexdump(result, dlen);
1264 ret = -EINVAL;
1265 goto out;
1266 }
1267 }
1268
1269 ret = 0;
1270
1271out:
1272 return ret;
1273}
1274
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001275static int test_pcomp(struct crypto_pcomp *tfm,
1276 struct pcomp_testvec *ctemplate,
1277 struct pcomp_testvec *dtemplate, int ctcount,
1278 int dtcount)
1279{
1280 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1281 unsigned int i;
1282 char result[COMP_BUF_SIZE];
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001283 int res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001284
1285 for (i = 0; i < ctcount; i++) {
1286 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001287 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001288
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001289 res = crypto_compress_setup(tfm, ctemplate[i].params,
1290 ctemplate[i].paramsize);
1291 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001292 pr_err("alg: pcomp: compression setup failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001293 "%d for %s: error=%d\n", i + 1, algo, res);
1294 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001295 }
1296
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001297 res = crypto_compress_init(tfm);
1298 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001299 pr_err("alg: pcomp: compression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001300 "%d for %s: error=%d\n", i + 1, algo, res);
1301 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001302 }
1303
1304 memset(result, 0, sizeof(result));
1305
1306 req.next_in = ctemplate[i].input;
1307 req.avail_in = ctemplate[i].inlen / 2;
1308 req.next_out = result;
1309 req.avail_out = ctemplate[i].outlen / 2;
1310
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001311 res = crypto_compress_update(tfm, &req);
1312 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001313 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001314 "%d for %s: error=%d\n", i + 1, algo, res);
1315 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001316 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001317 if (res > 0)
1318 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001319
1320 /* Add remaining input data */
1321 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1322
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001323 res = crypto_compress_update(tfm, &req);
1324 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001325 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001326 "%d for %s: error=%d\n", i + 1, algo, res);
1327 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001328 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001329 if (res > 0)
1330 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001331
1332 /* Provide remaining output space */
1333 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1334
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001335 res = crypto_compress_final(tfm, &req);
1336 if (res < 0) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001337 pr_err("alg: pcomp: compression final failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001338 "%d for %s: error=%d\n", i + 1, algo, res);
1339 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001340 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001341 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001342
1343 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1344 pr_err("alg: comp: Compression test %d failed for %s: "
1345 "output len = %d (expected %d)\n", i + 1, algo,
1346 COMP_BUF_SIZE - req.avail_out,
1347 ctemplate[i].outlen);
1348 return -EINVAL;
1349 }
1350
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001351 if (produced != ctemplate[i].outlen) {
1352 pr_err("alg: comp: Compression test %d failed for %s: "
1353 "returned len = %u (expected %d)\n", i + 1,
1354 algo, produced, ctemplate[i].outlen);
1355 return -EINVAL;
1356 }
1357
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001358 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1359 pr_err("alg: pcomp: Compression test %d failed for "
1360 "%s\n", i + 1, algo);
1361 hexdump(result, ctemplate[i].outlen);
1362 return -EINVAL;
1363 }
1364 }
1365
1366 for (i = 0; i < dtcount; i++) {
1367 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001368 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001369
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001370 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1371 dtemplate[i].paramsize);
1372 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001373 pr_err("alg: pcomp: decompression setup failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001374 "test %d for %s: error=%d\n", i + 1, algo, res);
1375 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001376 }
1377
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001378 res = crypto_decompress_init(tfm);
1379 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001380 pr_err("alg: pcomp: decompression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001381 "%d for %s: error=%d\n", i + 1, algo, res);
1382 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001383 }
1384
1385 memset(result, 0, sizeof(result));
1386
1387 req.next_in = dtemplate[i].input;
1388 req.avail_in = dtemplate[i].inlen / 2;
1389 req.next_out = result;
1390 req.avail_out = dtemplate[i].outlen / 2;
1391
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001392 res = crypto_decompress_update(tfm, &req);
1393 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001394 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001395 "test %d for %s: error=%d\n", i + 1, algo, res);
1396 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001397 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001398 if (res > 0)
1399 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001400
1401 /* Add remaining input data */
1402 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1403
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001404 res = crypto_decompress_update(tfm, &req);
1405 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001406 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001407 "test %d for %s: error=%d\n", i + 1, algo, res);
1408 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001409 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001410 if (res > 0)
1411 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001412
1413 /* Provide remaining output space */
1414 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1415
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001416 res = crypto_decompress_final(tfm, &req);
1417 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001418 pr_err("alg: pcomp: decompression final failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001419 "test %d for %s: error=%d\n", i + 1, algo, res);
1420 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001421 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001422 if (res > 0)
1423 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001424
1425 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1426 pr_err("alg: comp: Decompression test %d failed for "
1427 "%s: output len = %d (expected %d)\n", i + 1,
1428 algo, COMP_BUF_SIZE - req.avail_out,
1429 dtemplate[i].outlen);
1430 return -EINVAL;
1431 }
1432
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001433 if (produced != dtemplate[i].outlen) {
1434 pr_err("alg: comp: Decompression test %d failed for "
1435 "%s: returned len = %u (expected %d)\n", i + 1,
1436 algo, produced, dtemplate[i].outlen);
1437 return -EINVAL;
1438 }
1439
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001440 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1441 pr_err("alg: pcomp: Decompression test %d failed for "
1442 "%s\n", i + 1, algo);
1443 hexdump(result, dtemplate[i].outlen);
1444 return -EINVAL;
1445 }
1446 }
1447
1448 return 0;
1449}
1450
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001451
1452static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1453 unsigned int tcount)
1454{
1455 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001456 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001457 u8 *seed;
1458 char result[32];
1459
1460 seedsize = crypto_rng_seedsize(tfm);
1461
1462 seed = kmalloc(seedsize, GFP_KERNEL);
1463 if (!seed) {
1464 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1465 "for %s\n", algo);
1466 return -ENOMEM;
1467 }
1468
1469 for (i = 0; i < tcount; i++) {
1470 memset(result, 0, 32);
1471
1472 memcpy(seed, template[i].v, template[i].vlen);
1473 memcpy(seed + template[i].vlen, template[i].key,
1474 template[i].klen);
1475 memcpy(seed + template[i].vlen + template[i].klen,
1476 template[i].dt, template[i].dtlen);
1477
1478 err = crypto_rng_reset(tfm, seed, seedsize);
1479 if (err) {
1480 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1481 "for %s\n", algo);
1482 goto out;
1483 }
1484
1485 for (j = 0; j < template[i].loops; j++) {
1486 err = crypto_rng_get_bytes(tfm, result,
1487 template[i].rlen);
Stephan Mueller19e60e12015-03-10 17:00:36 +01001488 if (err < 0) {
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001489 printk(KERN_ERR "alg: cprng: Failed to obtain "
1490 "the correct amount of random data for "
Stephan Mueller19e60e12015-03-10 17:00:36 +01001491 "%s (requested %d)\n", algo,
1492 template[i].rlen);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001493 goto out;
1494 }
1495 }
1496
1497 err = memcmp(result, template[i].result,
1498 template[i].rlen);
1499 if (err) {
1500 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1501 i, algo);
1502 hexdump(result, template[i].rlen);
1503 err = -EINVAL;
1504 goto out;
1505 }
1506 }
1507
1508out:
1509 kfree(seed);
1510 return err;
1511}
1512
Herbert Xuda7f0332008-07-31 17:08:25 +08001513static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1514 u32 type, u32 mask)
1515{
1516 struct crypto_aead *tfm;
1517 int err = 0;
1518
Stephan Mueller425a8822015-03-30 21:56:31 +02001519 tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001520 if (IS_ERR(tfm)) {
1521 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1522 "%ld\n", driver, PTR_ERR(tfm));
1523 return PTR_ERR(tfm);
1524 }
1525
1526 if (desc->suite.aead.enc.vecs) {
1527 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1528 desc->suite.aead.enc.count);
1529 if (err)
1530 goto out;
1531 }
1532
1533 if (!err && desc->suite.aead.dec.vecs)
1534 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1535 desc->suite.aead.dec.count);
1536
1537out:
1538 crypto_free_aead(tfm);
1539 return err;
1540}
1541
1542static int alg_test_cipher(const struct alg_test_desc *desc,
1543 const char *driver, u32 type, u32 mask)
1544{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001545 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001546 int err = 0;
1547
Stephan Mueller425a8822015-03-30 21:56:31 +02001548 tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001549 if (IS_ERR(tfm)) {
1550 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1551 "%s: %ld\n", driver, PTR_ERR(tfm));
1552 return PTR_ERR(tfm);
1553 }
1554
1555 if (desc->suite.cipher.enc.vecs) {
1556 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1557 desc->suite.cipher.enc.count);
1558 if (err)
1559 goto out;
1560 }
1561
1562 if (desc->suite.cipher.dec.vecs)
1563 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1564 desc->suite.cipher.dec.count);
1565
1566out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001567 crypto_free_cipher(tfm);
1568 return err;
1569}
1570
1571static int alg_test_skcipher(const struct alg_test_desc *desc,
1572 const char *driver, u32 type, u32 mask)
1573{
1574 struct crypto_ablkcipher *tfm;
1575 int err = 0;
1576
Stephan Mueller425a8822015-03-30 21:56:31 +02001577 tfm = crypto_alloc_ablkcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001578 if (IS_ERR(tfm)) {
1579 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1580 "%s: %ld\n", driver, PTR_ERR(tfm));
1581 return PTR_ERR(tfm);
1582 }
1583
1584 if (desc->suite.cipher.enc.vecs) {
1585 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1586 desc->suite.cipher.enc.count);
1587 if (err)
1588 goto out;
1589 }
1590
1591 if (desc->suite.cipher.dec.vecs)
1592 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1593 desc->suite.cipher.dec.count);
1594
1595out:
Herbert Xuda7f0332008-07-31 17:08:25 +08001596 crypto_free_ablkcipher(tfm);
1597 return err;
1598}
1599
1600static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1601 u32 type, u32 mask)
1602{
1603 struct crypto_comp *tfm;
1604 int err;
1605
1606 tfm = crypto_alloc_comp(driver, type, mask);
1607 if (IS_ERR(tfm)) {
1608 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1609 "%ld\n", driver, PTR_ERR(tfm));
1610 return PTR_ERR(tfm);
1611 }
1612
1613 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1614 desc->suite.comp.decomp.vecs,
1615 desc->suite.comp.comp.count,
1616 desc->suite.comp.decomp.count);
1617
1618 crypto_free_comp(tfm);
1619 return err;
1620}
1621
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001622static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1623 u32 type, u32 mask)
1624{
1625 struct crypto_pcomp *tfm;
1626 int err;
1627
1628 tfm = crypto_alloc_pcomp(driver, type, mask);
1629 if (IS_ERR(tfm)) {
1630 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1631 driver, PTR_ERR(tfm));
1632 return PTR_ERR(tfm);
1633 }
1634
1635 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1636 desc->suite.pcomp.decomp.vecs,
1637 desc->suite.pcomp.comp.count,
1638 desc->suite.pcomp.decomp.count);
1639
1640 crypto_free_pcomp(tfm);
1641 return err;
1642}
1643
Herbert Xuda7f0332008-07-31 17:08:25 +08001644static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1645 u32 type, u32 mask)
1646{
1647 struct crypto_ahash *tfm;
1648 int err;
1649
Stephan Mueller425a8822015-03-30 21:56:31 +02001650 tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001651 if (IS_ERR(tfm)) {
1652 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1653 "%ld\n", driver, PTR_ERR(tfm));
1654 return PTR_ERR(tfm);
1655 }
1656
David S. Millera8f1a052010-05-19 14:12:03 +10001657 err = test_hash(tfm, desc->suite.hash.vecs,
1658 desc->suite.hash.count, true);
1659 if (!err)
1660 err = test_hash(tfm, desc->suite.hash.vecs,
1661 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001662
1663 crypto_free_ahash(tfm);
1664 return err;
1665}
1666
Herbert Xu8e3ee852008-11-07 14:58:52 +08001667static int alg_test_crc32c(const struct alg_test_desc *desc,
1668 const char *driver, u32 type, u32 mask)
1669{
1670 struct crypto_shash *tfm;
1671 u32 val;
1672 int err;
1673
1674 err = alg_test_hash(desc, driver, type, mask);
1675 if (err)
1676 goto out;
1677
Stephan Mueller425a8822015-03-30 21:56:31 +02001678 tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001679 if (IS_ERR(tfm)) {
1680 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1681 "%ld\n", driver, PTR_ERR(tfm));
1682 err = PTR_ERR(tfm);
1683 goto out;
1684 }
1685
1686 do {
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001687 SHASH_DESC_ON_STACK(shash, tfm);
1688 u32 *ctx = (u32 *)shash_desc_ctx(shash);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001689
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001690 shash->tfm = tfm;
1691 shash->flags = 0;
Herbert Xu8e3ee852008-11-07 14:58:52 +08001692
Jan-Simon Möller4c5c3022012-07-02 13:48:30 +02001693 *ctx = le32_to_cpu(420553207);
1694 err = crypto_shash_final(shash, (u8 *)&val);
Herbert Xu8e3ee852008-11-07 14:58:52 +08001695 if (err) {
1696 printk(KERN_ERR "alg: crc32c: Operation failed for "
1697 "%s: %d\n", driver, err);
1698 break;
1699 }
1700
1701 if (val != ~420553207) {
1702 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1703 "%d\n", driver, val);
1704 err = -EINVAL;
1705 }
1706 } while (0);
1707
1708 crypto_free_shash(tfm);
1709
1710out:
1711 return err;
1712}
1713
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001714static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1715 u32 type, u32 mask)
1716{
1717 struct crypto_rng *rng;
1718 int err;
1719
Stephan Mueller425a8822015-03-30 21:56:31 +02001720 rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001721 if (IS_ERR(rng)) {
1722 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1723 "%ld\n", driver, PTR_ERR(rng));
1724 return PTR_ERR(rng);
1725 }
1726
1727 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1728
1729 crypto_free_rng(rng);
1730
1731 return err;
1732}
1733
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001734
1735static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1736 const char *driver, u32 type, u32 mask)
1737{
1738 int ret = -EAGAIN;
1739 struct crypto_rng *drng;
1740 struct drbg_test_data test_data;
1741 struct drbg_string addtl, pers, testentropy;
1742 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1743
1744 if (!buf)
1745 return -ENOMEM;
1746
Stephan Mueller425a8822015-03-30 21:56:31 +02001747 drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001748 if (IS_ERR(drng)) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001749 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001750 "%s\n", driver);
1751 kzfree(buf);
1752 return -ENOMEM;
1753 }
1754
1755 test_data.testentropy = &testentropy;
1756 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1757 drbg_string_fill(&pers, test->pers, test->perslen);
1758 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1759 if (ret) {
1760 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1761 goto outbuf;
1762 }
1763
1764 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1765 if (pr) {
1766 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1767 ret = crypto_drbg_get_bytes_addtl_test(drng,
1768 buf, test->expectedlen, &addtl, &test_data);
1769 } else {
1770 ret = crypto_drbg_get_bytes_addtl(drng,
1771 buf, test->expectedlen, &addtl);
1772 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001773 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001774 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001775 "driver %s\n", driver);
1776 goto outbuf;
1777 }
1778
1779 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1780 if (pr) {
1781 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1782 ret = crypto_drbg_get_bytes_addtl_test(drng,
1783 buf, test->expectedlen, &addtl, &test_data);
1784 } else {
1785 ret = crypto_drbg_get_bytes_addtl(drng,
1786 buf, test->expectedlen, &addtl);
1787 }
Stephan Mueller19e60e12015-03-10 17:00:36 +01001788 if (ret < 0) {
Jarod Wilson2fc0d252014-07-29 15:47:56 -04001789 printk(KERN_ERR "alg: drbg: could not obtain random data for "
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02001790 "driver %s\n", driver);
1791 goto outbuf;
1792 }
1793
1794 ret = memcmp(test->expected, buf, test->expectedlen);
1795
1796outbuf:
1797 crypto_free_rng(drng);
1798 kzfree(buf);
1799 return ret;
1800}
1801
1802
1803static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1804 u32 type, u32 mask)
1805{
1806 int err = 0;
1807 int pr = 0;
1808 int i = 0;
1809 struct drbg_testvec *template = desc->suite.drbg.vecs;
1810 unsigned int tcount = desc->suite.drbg.count;
1811
1812 if (0 == memcmp(driver, "drbg_pr_", 8))
1813 pr = 1;
1814
1815 for (i = 0; i < tcount; i++) {
1816 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1817 if (err) {
1818 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1819 i, driver);
1820 err = -EINVAL;
1821 break;
1822 }
1823 }
1824 return err;
1825
1826}
1827
Youquan, Song863b5572009-12-23 19:45:20 +08001828static int alg_test_null(const struct alg_test_desc *desc,
1829 const char *driver, u32 type, u32 mask)
1830{
1831 return 0;
1832}
1833
Herbert Xuda7f0332008-07-31 17:08:25 +08001834/* Please keep this list sorted by algorithm name. */
1835static const struct alg_test_desc alg_test_descs[] = {
1836 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001837 .alg = "__cbc-cast5-avx",
1838 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001839 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001840 .alg = "__cbc-cast6-avx",
1841 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001842 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001843 .alg = "__cbc-serpent-avx",
1844 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001845 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001846 .alg = "__cbc-serpent-avx2",
1847 .test = alg_test_null,
1848 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001849 .alg = "__cbc-serpent-sse2",
1850 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001851 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001852 .alg = "__cbc-twofish-avx",
1853 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001854 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001855 .alg = "__driver-cbc-aes-aesni",
1856 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001857 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001858 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001859 .alg = "__driver-cbc-camellia-aesni",
1860 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001861 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001862 .alg = "__driver-cbc-camellia-aesni-avx2",
1863 .test = alg_test_null,
1864 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001865 .alg = "__driver-cbc-cast5-avx",
1866 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001867 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001868 .alg = "__driver-cbc-cast6-avx",
1869 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001870 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001871 .alg = "__driver-cbc-serpent-avx",
1872 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001873 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001874 .alg = "__driver-cbc-serpent-avx2",
1875 .test = alg_test_null,
1876 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001877 .alg = "__driver-cbc-serpent-sse2",
1878 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001879 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001880 .alg = "__driver-cbc-twofish-avx",
1881 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001882 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001883 .alg = "__driver-ecb-aes-aesni",
1884 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001885 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001886 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001887 .alg = "__driver-ecb-camellia-aesni",
1888 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03001889 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03001890 .alg = "__driver-ecb-camellia-aesni-avx2",
1891 .test = alg_test_null,
1892 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001893 .alg = "__driver-ecb-cast5-avx",
1894 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001895 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001896 .alg = "__driver-ecb-cast6-avx",
1897 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001898 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001899 .alg = "__driver-ecb-serpent-avx",
1900 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001901 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03001902 .alg = "__driver-ecb-serpent-avx2",
1903 .test = alg_test_null,
1904 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001905 .alg = "__driver-ecb-serpent-sse2",
1906 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001907 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001908 .alg = "__driver-ecb-twofish-avx",
1909 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001910 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001911 .alg = "__ghash-pclmulqdqni",
1912 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001913 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001914 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001915 .alg = "ansi_cprng",
1916 .test = alg_test_cprng,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001917 .fips_allowed = 1,
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001918 .suite = {
1919 .cprng = {
1920 .vecs = ansi_cprng_aes_tv_template,
1921 .count = ANSI_CPRNG_AES_TEST_VECTORS
1922 }
1923 }
1924 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001925 .alg = "authenc(hmac(md5),ecb(cipher_null))",
1926 .test = alg_test_aead,
1927 .fips_allowed = 1,
1928 .suite = {
1929 .aead = {
1930 .enc = {
1931 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
1932 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1933 },
1934 .dec = {
1935 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
1936 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1937 }
1938 }
1939 }
1940 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03001941 .alg = "authenc(hmac(sha1),cbc(aes))",
1942 .test = alg_test_aead,
1943 .fips_allowed = 1,
1944 .suite = {
1945 .aead = {
1946 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301947 .vecs =
1948 hmac_sha1_aes_cbc_enc_tv_temp,
1949 .count =
1950 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1951 }
1952 }
1953 }
1954 }, {
1955 .alg = "authenc(hmac(sha1),cbc(des))",
1956 .test = alg_test_aead,
1957 .fips_allowed = 1,
1958 .suite = {
1959 .aead = {
1960 .enc = {
1961 .vecs =
1962 hmac_sha1_des_cbc_enc_tv_temp,
1963 .count =
1964 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1965 }
1966 }
1967 }
1968 }, {
1969 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
1970 .test = alg_test_aead,
1971 .fips_allowed = 1,
1972 .suite = {
1973 .aead = {
1974 .enc = {
1975 .vecs =
1976 hmac_sha1_des3_ede_cbc_enc_tv_temp,
1977 .count =
1978 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03001979 }
1980 }
1981 }
1982 }, {
Horia Geantabca4feb2014-03-14 17:46:51 +02001983 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
1984 .test = alg_test_aead,
1985 .fips_allowed = 1,
1986 .suite = {
1987 .aead = {
1988 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301989 .vecs =
1990 hmac_sha1_ecb_cipher_null_enc_tv_temp,
1991 .count =
1992 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02001993 },
1994 .dec = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05301995 .vecs =
1996 hmac_sha1_ecb_cipher_null_dec_tv_temp,
1997 .count =
1998 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
1999 }
2000 }
2001 }
2002 }, {
2003 .alg = "authenc(hmac(sha224),cbc(des))",
2004 .test = alg_test_aead,
2005 .fips_allowed = 1,
2006 .suite = {
2007 .aead = {
2008 .enc = {
2009 .vecs =
2010 hmac_sha224_des_cbc_enc_tv_temp,
2011 .count =
2012 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2013 }
2014 }
2015 }
2016 }, {
2017 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
2018 .test = alg_test_aead,
2019 .fips_allowed = 1,
2020 .suite = {
2021 .aead = {
2022 .enc = {
2023 .vecs =
2024 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2025 .count =
2026 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantabca4feb2014-03-14 17:46:51 +02002027 }
2028 }
2029 }
2030 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03002031 .alg = "authenc(hmac(sha256),cbc(aes))",
2032 .test = alg_test_aead,
2033 .fips_allowed = 1,
2034 .suite = {
2035 .aead = {
2036 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302037 .vecs =
2038 hmac_sha256_aes_cbc_enc_tv_temp,
2039 .count =
2040 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2041 }
2042 }
2043 }
2044 }, {
2045 .alg = "authenc(hmac(sha256),cbc(des))",
2046 .test = alg_test_aead,
2047 .fips_allowed = 1,
2048 .suite = {
2049 .aead = {
2050 .enc = {
2051 .vecs =
2052 hmac_sha256_des_cbc_enc_tv_temp,
2053 .count =
2054 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2055 }
2056 }
2057 }
2058 }, {
2059 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
2060 .test = alg_test_aead,
2061 .fips_allowed = 1,
2062 .suite = {
2063 .aead = {
2064 .enc = {
2065 .vecs =
2066 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2067 .count =
2068 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2069 }
2070 }
2071 }
2072 }, {
2073 .alg = "authenc(hmac(sha384),cbc(des))",
2074 .test = alg_test_aead,
2075 .fips_allowed = 1,
2076 .suite = {
2077 .aead = {
2078 .enc = {
2079 .vecs =
2080 hmac_sha384_des_cbc_enc_tv_temp,
2081 .count =
2082 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2083 }
2084 }
2085 }
2086 }, {
2087 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
2088 .test = alg_test_aead,
2089 .fips_allowed = 1,
2090 .suite = {
2091 .aead = {
2092 .enc = {
2093 .vecs =
2094 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2095 .count =
2096 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002097 }
2098 }
2099 }
2100 }, {
2101 .alg = "authenc(hmac(sha512),cbc(aes))",
2102 .test = alg_test_aead,
2103 .fips_allowed = 1,
2104 .suite = {
2105 .aead = {
2106 .enc = {
Nitesh Lal5208ed22014-05-21 17:09:08 +05302107 .vecs =
2108 hmac_sha512_aes_cbc_enc_tv_temp,
2109 .count =
2110 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2111 }
2112 }
2113 }
2114 }, {
2115 .alg = "authenc(hmac(sha512),cbc(des))",
2116 .test = alg_test_aead,
2117 .fips_allowed = 1,
2118 .suite = {
2119 .aead = {
2120 .enc = {
2121 .vecs =
2122 hmac_sha512_des_cbc_enc_tv_temp,
2123 .count =
2124 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2125 }
2126 }
2127 }
2128 }, {
2129 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2130 .test = alg_test_aead,
2131 .fips_allowed = 1,
2132 .suite = {
2133 .aead = {
2134 .enc = {
2135 .vecs =
2136 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2137 .count =
2138 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
Horia Geantae46e9a42012-07-03 19:16:54 +03002139 }
2140 }
2141 }
2142 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002143 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002144 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002145 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002146 .suite = {
2147 .cipher = {
2148 .enc = {
2149 .vecs = aes_cbc_enc_tv_template,
2150 .count = AES_CBC_ENC_TEST_VECTORS
2151 },
2152 .dec = {
2153 .vecs = aes_cbc_dec_tv_template,
2154 .count = AES_CBC_DEC_TEST_VECTORS
2155 }
2156 }
2157 }
2158 }, {
2159 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002160 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002161 .suite = {
2162 .cipher = {
2163 .enc = {
2164 .vecs = anubis_cbc_enc_tv_template,
2165 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2166 },
2167 .dec = {
2168 .vecs = anubis_cbc_dec_tv_template,
2169 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2170 }
2171 }
2172 }
2173 }, {
2174 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002175 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002176 .suite = {
2177 .cipher = {
2178 .enc = {
2179 .vecs = bf_cbc_enc_tv_template,
2180 .count = BF_CBC_ENC_TEST_VECTORS
2181 },
2182 .dec = {
2183 .vecs = bf_cbc_dec_tv_template,
2184 .count = BF_CBC_DEC_TEST_VECTORS
2185 }
2186 }
2187 }
2188 }, {
2189 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002190 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002191 .suite = {
2192 .cipher = {
2193 .enc = {
2194 .vecs = camellia_cbc_enc_tv_template,
2195 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2196 },
2197 .dec = {
2198 .vecs = camellia_cbc_dec_tv_template,
2199 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2200 }
2201 }
2202 }
2203 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002204 .alg = "cbc(cast5)",
2205 .test = alg_test_skcipher,
2206 .suite = {
2207 .cipher = {
2208 .enc = {
2209 .vecs = cast5_cbc_enc_tv_template,
2210 .count = CAST5_CBC_ENC_TEST_VECTORS
2211 },
2212 .dec = {
2213 .vecs = cast5_cbc_dec_tv_template,
2214 .count = CAST5_CBC_DEC_TEST_VECTORS
2215 }
2216 }
2217 }
2218 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002219 .alg = "cbc(cast6)",
2220 .test = alg_test_skcipher,
2221 .suite = {
2222 .cipher = {
2223 .enc = {
2224 .vecs = cast6_cbc_enc_tv_template,
2225 .count = CAST6_CBC_ENC_TEST_VECTORS
2226 },
2227 .dec = {
2228 .vecs = cast6_cbc_dec_tv_template,
2229 .count = CAST6_CBC_DEC_TEST_VECTORS
2230 }
2231 }
2232 }
2233 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002234 .alg = "cbc(des)",
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 = des_cbc_enc_tv_template,
2240 .count = DES_CBC_ENC_TEST_VECTORS
2241 },
2242 .dec = {
2243 .vecs = des_cbc_dec_tv_template,
2244 .count = DES_CBC_DEC_TEST_VECTORS
2245 }
2246 }
2247 }
2248 }, {
2249 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002250 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002251 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002252 .suite = {
2253 .cipher = {
2254 .enc = {
2255 .vecs = des3_ede_cbc_enc_tv_template,
2256 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2257 },
2258 .dec = {
2259 .vecs = des3_ede_cbc_dec_tv_template,
2260 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2261 }
2262 }
2263 }
2264 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002265 .alg = "cbc(serpent)",
2266 .test = alg_test_skcipher,
2267 .suite = {
2268 .cipher = {
2269 .enc = {
2270 .vecs = serpent_cbc_enc_tv_template,
2271 .count = SERPENT_CBC_ENC_TEST_VECTORS
2272 },
2273 .dec = {
2274 .vecs = serpent_cbc_dec_tv_template,
2275 .count = SERPENT_CBC_DEC_TEST_VECTORS
2276 }
2277 }
2278 }
2279 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002280 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002281 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002282 .suite = {
2283 .cipher = {
2284 .enc = {
2285 .vecs = tf_cbc_enc_tv_template,
2286 .count = TF_CBC_ENC_TEST_VECTORS
2287 },
2288 .dec = {
2289 .vecs = tf_cbc_dec_tv_template,
2290 .count = TF_CBC_DEC_TEST_VECTORS
2291 }
2292 }
2293 }
2294 }, {
2295 .alg = "ccm(aes)",
2296 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002297 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002298 .suite = {
2299 .aead = {
2300 .enc = {
2301 .vecs = aes_ccm_enc_tv_template,
2302 .count = AES_CCM_ENC_TEST_VECTORS
2303 },
2304 .dec = {
2305 .vecs = aes_ccm_dec_tv_template,
2306 .count = AES_CCM_DEC_TEST_VECTORS
2307 }
2308 }
2309 }
2310 }, {
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03002311 .alg = "cmac(aes)",
2312 .test = alg_test_hash,
2313 .suite = {
2314 .hash = {
2315 .vecs = aes_cmac128_tv_template,
2316 .count = CMAC_AES_TEST_VECTORS
2317 }
2318 }
2319 }, {
2320 .alg = "cmac(des3_ede)",
2321 .test = alg_test_hash,
2322 .suite = {
2323 .hash = {
2324 .vecs = des3_ede_cmac64_tv_template,
2325 .count = CMAC_DES3_EDE_TEST_VECTORS
2326 }
2327 }
2328 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002329 .alg = "compress_null",
2330 .test = alg_test_null,
2331 }, {
Ard Biesheuvelebb34722015-05-04 11:00:17 +02002332 .alg = "crc32",
2333 .test = alg_test_hash,
2334 .suite = {
2335 .hash = {
2336 .vecs = crc32_tv_template,
2337 .count = CRC32_TEST_VECTORS
2338 }
2339 }
2340 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002341 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002342 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002343 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002344 .suite = {
2345 .hash = {
2346 .vecs = crc32c_tv_template,
2347 .count = CRC32C_TEST_VECTORS
2348 }
2349 }
2350 }, {
Herbert Xu684115212013-09-07 12:56:26 +10002351 .alg = "crct10dif",
2352 .test = alg_test_hash,
2353 .fips_allowed = 1,
2354 .suite = {
2355 .hash = {
2356 .vecs = crct10dif_tv_template,
2357 .count = CRCT10DIF_TEST_VECTORS
2358 }
2359 }
2360 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002361 .alg = "cryptd(__driver-cbc-aes-aesni)",
2362 .test = alg_test_null,
2363 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002364 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002365 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2366 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002367 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002368 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2369 .test = alg_test_null,
2370 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002371 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2372 .test = alg_test_null,
2373 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002374 .alg = "cryptd(__driver-ecb-aes-aesni)",
2375 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002376 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002377 }, {
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002378 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2379 .test = alg_test_null,
Jussi Kivilinnad9b1d2e2012-10-26 14:49:01 +03002380 }, {
Jussi Kivilinnaf3f935a2013-04-13 13:47:00 +03002381 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2382 .test = alg_test_null,
2383 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002384 .alg = "cryptd(__driver-ecb-cast5-avx)",
2385 .test = alg_test_null,
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002386 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002387 .alg = "cryptd(__driver-ecb-cast6-avx)",
2388 .test = alg_test_null,
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002389 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002390 .alg = "cryptd(__driver-ecb-serpent-avx)",
2391 .test = alg_test_null,
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002392 }, {
Jussi Kivilinna56d76c92013-04-13 13:46:55 +03002393 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2394 .test = alg_test_null,
2395 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002396 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2397 .test = alg_test_null,
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002398 }, {
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002399 .alg = "cryptd(__driver-ecb-twofish-avx)",
2400 .test = alg_test_null,
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002401 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002402 .alg = "cryptd(__driver-gcm-aes-aesni)",
2403 .test = alg_test_null,
2404 .fips_allowed = 1,
Milan Broz6c792942012-06-29 22:08:09 +02002405 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002406 .alg = "cryptd(__ghash-pclmulqdqni)",
2407 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002408 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002409 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002410 .alg = "ctr(aes)",
2411 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002412 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002413 .suite = {
2414 .cipher = {
2415 .enc = {
2416 .vecs = aes_ctr_enc_tv_template,
2417 .count = AES_CTR_ENC_TEST_VECTORS
2418 },
2419 .dec = {
2420 .vecs = aes_ctr_dec_tv_template,
2421 .count = AES_CTR_DEC_TEST_VECTORS
2422 }
2423 }
2424 }
2425 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002426 .alg = "ctr(blowfish)",
2427 .test = alg_test_skcipher,
2428 .suite = {
2429 .cipher = {
2430 .enc = {
2431 .vecs = bf_ctr_enc_tv_template,
2432 .count = BF_CTR_ENC_TEST_VECTORS
2433 },
2434 .dec = {
2435 .vecs = bf_ctr_dec_tv_template,
2436 .count = BF_CTR_DEC_TEST_VECTORS
2437 }
2438 }
2439 }
2440 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002441 .alg = "ctr(camellia)",
2442 .test = alg_test_skcipher,
2443 .suite = {
2444 .cipher = {
2445 .enc = {
2446 .vecs = camellia_ctr_enc_tv_template,
2447 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2448 },
2449 .dec = {
2450 .vecs = camellia_ctr_dec_tv_template,
2451 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2452 }
2453 }
2454 }
2455 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002456 .alg = "ctr(cast5)",
2457 .test = alg_test_skcipher,
2458 .suite = {
2459 .cipher = {
2460 .enc = {
2461 .vecs = cast5_ctr_enc_tv_template,
2462 .count = CAST5_CTR_ENC_TEST_VECTORS
2463 },
2464 .dec = {
2465 .vecs = cast5_ctr_dec_tv_template,
2466 .count = CAST5_CTR_DEC_TEST_VECTORS
2467 }
2468 }
2469 }
2470 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002471 .alg = "ctr(cast6)",
2472 .test = alg_test_skcipher,
2473 .suite = {
2474 .cipher = {
2475 .enc = {
2476 .vecs = cast6_ctr_enc_tv_template,
2477 .count = CAST6_CTR_ENC_TEST_VECTORS
2478 },
2479 .dec = {
2480 .vecs = cast6_ctr_dec_tv_template,
2481 .count = CAST6_CTR_DEC_TEST_VECTORS
2482 }
2483 }
2484 }
2485 }, {
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03002486 .alg = "ctr(des)",
2487 .test = alg_test_skcipher,
2488 .suite = {
2489 .cipher = {
2490 .enc = {
2491 .vecs = des_ctr_enc_tv_template,
2492 .count = DES_CTR_ENC_TEST_VECTORS
2493 },
2494 .dec = {
2495 .vecs = des_ctr_dec_tv_template,
2496 .count = DES_CTR_DEC_TEST_VECTORS
2497 }
2498 }
2499 }
2500 }, {
Jussi Kivilinnae080b172012-10-20 14:53:12 +03002501 .alg = "ctr(des3_ede)",
2502 .test = alg_test_skcipher,
2503 .suite = {
2504 .cipher = {
2505 .enc = {
2506 .vecs = des3_ede_ctr_enc_tv_template,
2507 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2508 },
2509 .dec = {
2510 .vecs = des3_ede_ctr_dec_tv_template,
2511 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2512 }
2513 }
2514 }
2515 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002516 .alg = "ctr(serpent)",
2517 .test = alg_test_skcipher,
2518 .suite = {
2519 .cipher = {
2520 .enc = {
2521 .vecs = serpent_ctr_enc_tv_template,
2522 .count = SERPENT_CTR_ENC_TEST_VECTORS
2523 },
2524 .dec = {
2525 .vecs = serpent_ctr_dec_tv_template,
2526 .count = SERPENT_CTR_DEC_TEST_VECTORS
2527 }
2528 }
2529 }
2530 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002531 .alg = "ctr(twofish)",
2532 .test = alg_test_skcipher,
2533 .suite = {
2534 .cipher = {
2535 .enc = {
2536 .vecs = tf_ctr_enc_tv_template,
2537 .count = TF_CTR_ENC_TEST_VECTORS
2538 },
2539 .dec = {
2540 .vecs = tf_ctr_dec_tv_template,
2541 .count = TF_CTR_DEC_TEST_VECTORS
2542 }
2543 }
2544 }
2545 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002546 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002547 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002548 .suite = {
2549 .cipher = {
2550 .enc = {
2551 .vecs = cts_mode_enc_tv_template,
2552 .count = CTS_MODE_ENC_TEST_VECTORS
2553 },
2554 .dec = {
2555 .vecs = cts_mode_dec_tv_template,
2556 .count = CTS_MODE_DEC_TEST_VECTORS
2557 }
2558 }
2559 }
2560 }, {
2561 .alg = "deflate",
2562 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08002563 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002564 .suite = {
2565 .comp = {
2566 .comp = {
2567 .vecs = deflate_comp_tv_template,
2568 .count = DEFLATE_COMP_TEST_VECTORS
2569 },
2570 .decomp = {
2571 .vecs = deflate_decomp_tv_template,
2572 .count = DEFLATE_DECOMP_TEST_VECTORS
2573 }
2574 }
2575 }
2576 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002577 .alg = "digest_null",
2578 .test = alg_test_null,
2579 }, {
Stephan Mueller64d1cdf2014-05-31 17:25:36 +02002580 .alg = "drbg_nopr_ctr_aes128",
2581 .test = alg_test_drbg,
2582 .fips_allowed = 1,
2583 .suite = {
2584 .drbg = {
2585 .vecs = drbg_nopr_ctr_aes128_tv_template,
2586 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2587 }
2588 }
2589 }, {
2590 .alg = "drbg_nopr_ctr_aes192",
2591 .test = alg_test_drbg,
2592 .fips_allowed = 1,
2593 .suite = {
2594 .drbg = {
2595 .vecs = drbg_nopr_ctr_aes192_tv_template,
2596 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2597 }
2598 }
2599 }, {
2600 .alg = "drbg_nopr_ctr_aes256",
2601 .test = alg_test_drbg,
2602 .fips_allowed = 1,
2603 .suite = {
2604 .drbg = {
2605 .vecs = drbg_nopr_ctr_aes256_tv_template,
2606 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2607 }
2608 }
2609 }, {
2610 /*
2611 * There is no need to specifically test the DRBG with every
2612 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2613 */
2614 .alg = "drbg_nopr_hmac_sha1",
2615 .fips_allowed = 1,
2616 .test = alg_test_null,
2617 }, {
2618 .alg = "drbg_nopr_hmac_sha256",
2619 .test = alg_test_drbg,
2620 .fips_allowed = 1,
2621 .suite = {
2622 .drbg = {
2623 .vecs = drbg_nopr_hmac_sha256_tv_template,
2624 .count =
2625 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2626 }
2627 }
2628 }, {
2629 /* covered by drbg_nopr_hmac_sha256 test */
2630 .alg = "drbg_nopr_hmac_sha384",
2631 .fips_allowed = 1,
2632 .test = alg_test_null,
2633 }, {
2634 .alg = "drbg_nopr_hmac_sha512",
2635 .test = alg_test_null,
2636 .fips_allowed = 1,
2637 }, {
2638 .alg = "drbg_nopr_sha1",
2639 .fips_allowed = 1,
2640 .test = alg_test_null,
2641 }, {
2642 .alg = "drbg_nopr_sha256",
2643 .test = alg_test_drbg,
2644 .fips_allowed = 1,
2645 .suite = {
2646 .drbg = {
2647 .vecs = drbg_nopr_sha256_tv_template,
2648 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2649 }
2650 }
2651 }, {
2652 /* covered by drbg_nopr_sha256 test */
2653 .alg = "drbg_nopr_sha384",
2654 .fips_allowed = 1,
2655 .test = alg_test_null,
2656 }, {
2657 .alg = "drbg_nopr_sha512",
2658 .fips_allowed = 1,
2659 .test = alg_test_null,
2660 }, {
2661 .alg = "drbg_pr_ctr_aes128",
2662 .test = alg_test_drbg,
2663 .fips_allowed = 1,
2664 .suite = {
2665 .drbg = {
2666 .vecs = drbg_pr_ctr_aes128_tv_template,
2667 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2668 }
2669 }
2670 }, {
2671 /* covered by drbg_pr_ctr_aes128 test */
2672 .alg = "drbg_pr_ctr_aes192",
2673 .fips_allowed = 1,
2674 .test = alg_test_null,
2675 }, {
2676 .alg = "drbg_pr_ctr_aes256",
2677 .fips_allowed = 1,
2678 .test = alg_test_null,
2679 }, {
2680 .alg = "drbg_pr_hmac_sha1",
2681 .fips_allowed = 1,
2682 .test = alg_test_null,
2683 }, {
2684 .alg = "drbg_pr_hmac_sha256",
2685 .test = alg_test_drbg,
2686 .fips_allowed = 1,
2687 .suite = {
2688 .drbg = {
2689 .vecs = drbg_pr_hmac_sha256_tv_template,
2690 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2691 }
2692 }
2693 }, {
2694 /* covered by drbg_pr_hmac_sha256 test */
2695 .alg = "drbg_pr_hmac_sha384",
2696 .fips_allowed = 1,
2697 .test = alg_test_null,
2698 }, {
2699 .alg = "drbg_pr_hmac_sha512",
2700 .test = alg_test_null,
2701 .fips_allowed = 1,
2702 }, {
2703 .alg = "drbg_pr_sha1",
2704 .fips_allowed = 1,
2705 .test = alg_test_null,
2706 }, {
2707 .alg = "drbg_pr_sha256",
2708 .test = alg_test_drbg,
2709 .fips_allowed = 1,
2710 .suite = {
2711 .drbg = {
2712 .vecs = drbg_pr_sha256_tv_template,
2713 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2714 }
2715 }
2716 }, {
2717 /* covered by drbg_pr_sha256 test */
2718 .alg = "drbg_pr_sha384",
2719 .fips_allowed = 1,
2720 .test = alg_test_null,
2721 }, {
2722 .alg = "drbg_pr_sha512",
2723 .fips_allowed = 1,
2724 .test = alg_test_null,
2725 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002726 .alg = "ecb(__aes-aesni)",
2727 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002728 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002729 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002730 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002731 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002732 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002733 .suite = {
2734 .cipher = {
2735 .enc = {
2736 .vecs = aes_enc_tv_template,
2737 .count = AES_ENC_TEST_VECTORS
2738 },
2739 .dec = {
2740 .vecs = aes_dec_tv_template,
2741 .count = AES_DEC_TEST_VECTORS
2742 }
2743 }
2744 }
2745 }, {
2746 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002747 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002748 .suite = {
2749 .cipher = {
2750 .enc = {
2751 .vecs = anubis_enc_tv_template,
2752 .count = ANUBIS_ENC_TEST_VECTORS
2753 },
2754 .dec = {
2755 .vecs = anubis_dec_tv_template,
2756 .count = ANUBIS_DEC_TEST_VECTORS
2757 }
2758 }
2759 }
2760 }, {
2761 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002762 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002763 .suite = {
2764 .cipher = {
2765 .enc = {
2766 .vecs = arc4_enc_tv_template,
2767 .count = ARC4_ENC_TEST_VECTORS
2768 },
2769 .dec = {
2770 .vecs = arc4_dec_tv_template,
2771 .count = ARC4_DEC_TEST_VECTORS
2772 }
2773 }
2774 }
2775 }, {
2776 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002777 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002778 .suite = {
2779 .cipher = {
2780 .enc = {
2781 .vecs = bf_enc_tv_template,
2782 .count = BF_ENC_TEST_VECTORS
2783 },
2784 .dec = {
2785 .vecs = bf_dec_tv_template,
2786 .count = BF_DEC_TEST_VECTORS
2787 }
2788 }
2789 }
2790 }, {
2791 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002792 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002793 .suite = {
2794 .cipher = {
2795 .enc = {
2796 .vecs = camellia_enc_tv_template,
2797 .count = CAMELLIA_ENC_TEST_VECTORS
2798 },
2799 .dec = {
2800 .vecs = camellia_dec_tv_template,
2801 .count = CAMELLIA_DEC_TEST_VECTORS
2802 }
2803 }
2804 }
2805 }, {
2806 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002807 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002808 .suite = {
2809 .cipher = {
2810 .enc = {
2811 .vecs = cast5_enc_tv_template,
2812 .count = CAST5_ENC_TEST_VECTORS
2813 },
2814 .dec = {
2815 .vecs = cast5_dec_tv_template,
2816 .count = CAST5_DEC_TEST_VECTORS
2817 }
2818 }
2819 }
2820 }, {
2821 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002822 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002823 .suite = {
2824 .cipher = {
2825 .enc = {
2826 .vecs = cast6_enc_tv_template,
2827 .count = CAST6_ENC_TEST_VECTORS
2828 },
2829 .dec = {
2830 .vecs = cast6_dec_tv_template,
2831 .count = CAST6_DEC_TEST_VECTORS
2832 }
2833 }
2834 }
2835 }, {
Jussi Kivilinnae4483702013-04-07 16:43:56 +03002836 .alg = "ecb(cipher_null)",
2837 .test = alg_test_null,
2838 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002839 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002840 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002841 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002842 .suite = {
2843 .cipher = {
2844 .enc = {
2845 .vecs = des_enc_tv_template,
2846 .count = DES_ENC_TEST_VECTORS
2847 },
2848 .dec = {
2849 .vecs = des_dec_tv_template,
2850 .count = DES_DEC_TEST_VECTORS
2851 }
2852 }
2853 }
2854 }, {
2855 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002856 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002857 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002858 .suite = {
2859 .cipher = {
2860 .enc = {
2861 .vecs = des3_ede_enc_tv_template,
2862 .count = DES3_EDE_ENC_TEST_VECTORS
2863 },
2864 .dec = {
2865 .vecs = des3_ede_dec_tv_template,
2866 .count = DES3_EDE_DEC_TEST_VECTORS
2867 }
2868 }
2869 }
2870 }, {
Jussi Kivilinna66e5bd02013-01-19 13:31:36 +02002871 .alg = "ecb(fcrypt)",
2872 .test = alg_test_skcipher,
2873 .suite = {
2874 .cipher = {
2875 .enc = {
2876 .vecs = fcrypt_pcbc_enc_tv_template,
2877 .count = 1
2878 },
2879 .dec = {
2880 .vecs = fcrypt_pcbc_dec_tv_template,
2881 .count = 1
2882 }
2883 }
2884 }
2885 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002886 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002887 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002888 .suite = {
2889 .cipher = {
2890 .enc = {
2891 .vecs = khazad_enc_tv_template,
2892 .count = KHAZAD_ENC_TEST_VECTORS
2893 },
2894 .dec = {
2895 .vecs = khazad_dec_tv_template,
2896 .count = KHAZAD_DEC_TEST_VECTORS
2897 }
2898 }
2899 }
2900 }, {
2901 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002902 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002903 .suite = {
2904 .cipher = {
2905 .enc = {
2906 .vecs = seed_enc_tv_template,
2907 .count = SEED_ENC_TEST_VECTORS
2908 },
2909 .dec = {
2910 .vecs = seed_dec_tv_template,
2911 .count = SEED_DEC_TEST_VECTORS
2912 }
2913 }
2914 }
2915 }, {
2916 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002917 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002918 .suite = {
2919 .cipher = {
2920 .enc = {
2921 .vecs = serpent_enc_tv_template,
2922 .count = SERPENT_ENC_TEST_VECTORS
2923 },
2924 .dec = {
2925 .vecs = serpent_dec_tv_template,
2926 .count = SERPENT_DEC_TEST_VECTORS
2927 }
2928 }
2929 }
2930 }, {
2931 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002932 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002933 .suite = {
2934 .cipher = {
2935 .enc = {
2936 .vecs = tea_enc_tv_template,
2937 .count = TEA_ENC_TEST_VECTORS
2938 },
2939 .dec = {
2940 .vecs = tea_dec_tv_template,
2941 .count = TEA_DEC_TEST_VECTORS
2942 }
2943 }
2944 }
2945 }, {
2946 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002947 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002948 .suite = {
2949 .cipher = {
2950 .enc = {
2951 .vecs = tnepres_enc_tv_template,
2952 .count = TNEPRES_ENC_TEST_VECTORS
2953 },
2954 .dec = {
2955 .vecs = tnepres_dec_tv_template,
2956 .count = TNEPRES_DEC_TEST_VECTORS
2957 }
2958 }
2959 }
2960 }, {
2961 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002962 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002963 .suite = {
2964 .cipher = {
2965 .enc = {
2966 .vecs = tf_enc_tv_template,
2967 .count = TF_ENC_TEST_VECTORS
2968 },
2969 .dec = {
2970 .vecs = tf_dec_tv_template,
2971 .count = TF_DEC_TEST_VECTORS
2972 }
2973 }
2974 }
2975 }, {
2976 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002977 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002978 .suite = {
2979 .cipher = {
2980 .enc = {
2981 .vecs = xeta_enc_tv_template,
2982 .count = XETA_ENC_TEST_VECTORS
2983 },
2984 .dec = {
2985 .vecs = xeta_dec_tv_template,
2986 .count = XETA_DEC_TEST_VECTORS
2987 }
2988 }
2989 }
2990 }, {
2991 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002992 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002993 .suite = {
2994 .cipher = {
2995 .enc = {
2996 .vecs = xtea_enc_tv_template,
2997 .count = XTEA_ENC_TEST_VECTORS
2998 },
2999 .dec = {
3000 .vecs = xtea_dec_tv_template,
3001 .count = XTEA_DEC_TEST_VECTORS
3002 }
3003 }
3004 }
3005 }, {
3006 .alg = "gcm(aes)",
3007 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003008 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003009 .suite = {
3010 .aead = {
3011 .enc = {
3012 .vecs = aes_gcm_enc_tv_template,
3013 .count = AES_GCM_ENC_TEST_VECTORS
3014 },
3015 .dec = {
3016 .vecs = aes_gcm_dec_tv_template,
3017 .count = AES_GCM_DEC_TEST_VECTORS
3018 }
3019 }
3020 }
3021 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08003022 .alg = "ghash",
3023 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11003024 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08003025 .suite = {
3026 .hash = {
3027 .vecs = ghash_tv_template,
3028 .count = GHASH_TEST_VECTORS
3029 }
3030 }
3031 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08003032 .alg = "hmac(crc32)",
3033 .test = alg_test_hash,
3034 .suite = {
3035 .hash = {
3036 .vecs = bfin_crc_tv_template,
3037 .count = BFIN_CRC_TEST_VECTORS
3038 }
3039 }
3040 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003041 .alg = "hmac(md5)",
3042 .test = alg_test_hash,
3043 .suite = {
3044 .hash = {
3045 .vecs = hmac_md5_tv_template,
3046 .count = HMAC_MD5_TEST_VECTORS
3047 }
3048 }
3049 }, {
3050 .alg = "hmac(rmd128)",
3051 .test = alg_test_hash,
3052 .suite = {
3053 .hash = {
3054 .vecs = hmac_rmd128_tv_template,
3055 .count = HMAC_RMD128_TEST_VECTORS
3056 }
3057 }
3058 }, {
3059 .alg = "hmac(rmd160)",
3060 .test = alg_test_hash,
3061 .suite = {
3062 .hash = {
3063 .vecs = hmac_rmd160_tv_template,
3064 .count = HMAC_RMD160_TEST_VECTORS
3065 }
3066 }
3067 }, {
3068 .alg = "hmac(sha1)",
3069 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003070 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003071 .suite = {
3072 .hash = {
3073 .vecs = hmac_sha1_tv_template,
3074 .count = HMAC_SHA1_TEST_VECTORS
3075 }
3076 }
3077 }, {
3078 .alg = "hmac(sha224)",
3079 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003080 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003081 .suite = {
3082 .hash = {
3083 .vecs = hmac_sha224_tv_template,
3084 .count = HMAC_SHA224_TEST_VECTORS
3085 }
3086 }
3087 }, {
3088 .alg = "hmac(sha256)",
3089 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003090 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003091 .suite = {
3092 .hash = {
3093 .vecs = hmac_sha256_tv_template,
3094 .count = HMAC_SHA256_TEST_VECTORS
3095 }
3096 }
3097 }, {
3098 .alg = "hmac(sha384)",
3099 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003100 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003101 .suite = {
3102 .hash = {
3103 .vecs = hmac_sha384_tv_template,
3104 .count = HMAC_SHA384_TEST_VECTORS
3105 }
3106 }
3107 }, {
3108 .alg = "hmac(sha512)",
3109 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003110 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003111 .suite = {
3112 .hash = {
3113 .vecs = hmac_sha512_tv_template,
3114 .count = HMAC_SHA512_TEST_VECTORS
3115 }
3116 }
3117 }, {
Stephan Muellerbb5530e2015-05-25 15:10:20 +02003118 .alg = "jitterentropy_rng",
3119 .fips_allowed = 1,
3120 .test = alg_test_null,
3121 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003122 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003123 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003124 .suite = {
3125 .cipher = {
3126 .enc = {
3127 .vecs = aes_lrw_enc_tv_template,
3128 .count = AES_LRW_ENC_TEST_VECTORS
3129 },
3130 .dec = {
3131 .vecs = aes_lrw_dec_tv_template,
3132 .count = AES_LRW_DEC_TEST_VECTORS
3133 }
3134 }
3135 }
3136 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003137 .alg = "lrw(camellia)",
3138 .test = alg_test_skcipher,
3139 .suite = {
3140 .cipher = {
3141 .enc = {
3142 .vecs = camellia_lrw_enc_tv_template,
3143 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3144 },
3145 .dec = {
3146 .vecs = camellia_lrw_dec_tv_template,
3147 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3148 }
3149 }
3150 }
3151 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003152 .alg = "lrw(cast6)",
3153 .test = alg_test_skcipher,
3154 .suite = {
3155 .cipher = {
3156 .enc = {
3157 .vecs = cast6_lrw_enc_tv_template,
3158 .count = CAST6_LRW_ENC_TEST_VECTORS
3159 },
3160 .dec = {
3161 .vecs = cast6_lrw_dec_tv_template,
3162 .count = CAST6_LRW_DEC_TEST_VECTORS
3163 }
3164 }
3165 }
3166 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03003167 .alg = "lrw(serpent)",
3168 .test = alg_test_skcipher,
3169 .suite = {
3170 .cipher = {
3171 .enc = {
3172 .vecs = serpent_lrw_enc_tv_template,
3173 .count = SERPENT_LRW_ENC_TEST_VECTORS
3174 },
3175 .dec = {
3176 .vecs = serpent_lrw_dec_tv_template,
3177 .count = SERPENT_LRW_DEC_TEST_VECTORS
3178 }
3179 }
3180 }
3181 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03003182 .alg = "lrw(twofish)",
3183 .test = alg_test_skcipher,
3184 .suite = {
3185 .cipher = {
3186 .enc = {
3187 .vecs = tf_lrw_enc_tv_template,
3188 .count = TF_LRW_ENC_TEST_VECTORS
3189 },
3190 .dec = {
3191 .vecs = tf_lrw_dec_tv_template,
3192 .count = TF_LRW_DEC_TEST_VECTORS
3193 }
3194 }
3195 }
3196 }, {
KOVACS Krisztian1443cc92014-08-22 10:44:36 +02003197 .alg = "lz4",
3198 .test = alg_test_comp,
3199 .fips_allowed = 1,
3200 .suite = {
3201 .comp = {
3202 .comp = {
3203 .vecs = lz4_comp_tv_template,
3204 .count = LZ4_COMP_TEST_VECTORS
3205 },
3206 .decomp = {
3207 .vecs = lz4_decomp_tv_template,
3208 .count = LZ4_DECOMP_TEST_VECTORS
3209 }
3210 }
3211 }
3212 }, {
3213 .alg = "lz4hc",
3214 .test = alg_test_comp,
3215 .fips_allowed = 1,
3216 .suite = {
3217 .comp = {
3218 .comp = {
3219 .vecs = lz4hc_comp_tv_template,
3220 .count = LZ4HC_COMP_TEST_VECTORS
3221 },
3222 .decomp = {
3223 .vecs = lz4hc_decomp_tv_template,
3224 .count = LZ4HC_DECOMP_TEST_VECTORS
3225 }
3226 }
3227 }
3228 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003229 .alg = "lzo",
3230 .test = alg_test_comp,
Milan Broz08189042012-12-06 17:16:28 +08003231 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003232 .suite = {
3233 .comp = {
3234 .comp = {
3235 .vecs = lzo_comp_tv_template,
3236 .count = LZO_COMP_TEST_VECTORS
3237 },
3238 .decomp = {
3239 .vecs = lzo_decomp_tv_template,
3240 .count = LZO_DECOMP_TEST_VECTORS
3241 }
3242 }
3243 }
3244 }, {
3245 .alg = "md4",
3246 .test = alg_test_hash,
3247 .suite = {
3248 .hash = {
3249 .vecs = md4_tv_template,
3250 .count = MD4_TEST_VECTORS
3251 }
3252 }
3253 }, {
3254 .alg = "md5",
3255 .test = alg_test_hash,
3256 .suite = {
3257 .hash = {
3258 .vecs = md5_tv_template,
3259 .count = MD5_TEST_VECTORS
3260 }
3261 }
3262 }, {
3263 .alg = "michael_mic",
3264 .test = alg_test_hash,
3265 .suite = {
3266 .hash = {
3267 .vecs = michael_mic_tv_template,
3268 .count = MICHAEL_MIC_TEST_VECTORS
3269 }
3270 }
3271 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10003272 .alg = "ofb(aes)",
3273 .test = alg_test_skcipher,
3274 .fips_allowed = 1,
3275 .suite = {
3276 .cipher = {
3277 .enc = {
3278 .vecs = aes_ofb_enc_tv_template,
3279 .count = AES_OFB_ENC_TEST_VECTORS
3280 },
3281 .dec = {
3282 .vecs = aes_ofb_dec_tv_template,
3283 .count = AES_OFB_DEC_TEST_VECTORS
3284 }
3285 }
3286 }
3287 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003288 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003289 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003290 .suite = {
3291 .cipher = {
3292 .enc = {
3293 .vecs = fcrypt_pcbc_enc_tv_template,
3294 .count = FCRYPT_ENC_TEST_VECTORS
3295 },
3296 .dec = {
3297 .vecs = fcrypt_pcbc_dec_tv_template,
3298 .count = FCRYPT_DEC_TEST_VECTORS
3299 }
3300 }
3301 }
3302 }, {
3303 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003304 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003305 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003306 .suite = {
3307 .cipher = {
3308 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003309 .vecs = aes_ctr_rfc3686_enc_tv_template,
3310 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003311 },
3312 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08003313 .vecs = aes_ctr_rfc3686_dec_tv_template,
3314 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08003315 }
3316 }
3317 }
3318 }, {
Adrian Hoban69435b92010-11-04 15:02:04 -04003319 .alg = "rfc4106(gcm(aes))",
3320 .test = alg_test_aead,
Jarod Wilsondb71f29a2015-01-23 12:42:15 -05003321 .fips_allowed = 1,
Adrian Hoban69435b92010-11-04 15:02:04 -04003322 .suite = {
3323 .aead = {
3324 .enc = {
3325 .vecs = aes_gcm_rfc4106_enc_tv_template,
3326 .count = AES_GCM_4106_ENC_TEST_VECTORS
3327 },
3328 .dec = {
3329 .vecs = aes_gcm_rfc4106_dec_tv_template,
3330 .count = AES_GCM_4106_DEC_TEST_VECTORS
3331 }
3332 }
3333 }
3334 }, {
Jarod Wilson5d667322009-05-04 19:23:40 +08003335 .alg = "rfc4309(ccm(aes))",
3336 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003337 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08003338 .suite = {
3339 .aead = {
3340 .enc = {
3341 .vecs = aes_ccm_rfc4309_enc_tv_template,
3342 .count = AES_CCM_4309_ENC_TEST_VECTORS
3343 },
3344 .dec = {
3345 .vecs = aes_ccm_rfc4309_dec_tv_template,
3346 .count = AES_CCM_4309_DEC_TEST_VECTORS
3347 }
3348 }
3349 }
3350 }, {
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03003351 .alg = "rfc4543(gcm(aes))",
3352 .test = alg_test_aead,
3353 .suite = {
3354 .aead = {
3355 .enc = {
3356 .vecs = aes_gcm_rfc4543_enc_tv_template,
3357 .count = AES_GCM_4543_ENC_TEST_VECTORS
3358 },
3359 .dec = {
3360 .vecs = aes_gcm_rfc4543_dec_tv_template,
3361 .count = AES_GCM_4543_DEC_TEST_VECTORS
3362 },
3363 }
3364 }
3365 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003366 .alg = "rmd128",
3367 .test = alg_test_hash,
3368 .suite = {
3369 .hash = {
3370 .vecs = rmd128_tv_template,
3371 .count = RMD128_TEST_VECTORS
3372 }
3373 }
3374 }, {
3375 .alg = "rmd160",
3376 .test = alg_test_hash,
3377 .suite = {
3378 .hash = {
3379 .vecs = rmd160_tv_template,
3380 .count = RMD160_TEST_VECTORS
3381 }
3382 }
3383 }, {
3384 .alg = "rmd256",
3385 .test = alg_test_hash,
3386 .suite = {
3387 .hash = {
3388 .vecs = rmd256_tv_template,
3389 .count = RMD256_TEST_VECTORS
3390 }
3391 }
3392 }, {
3393 .alg = "rmd320",
3394 .test = alg_test_hash,
3395 .suite = {
3396 .hash = {
3397 .vecs = rmd320_tv_template,
3398 .count = RMD320_TEST_VECTORS
3399 }
3400 }
3401 }, {
3402 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003403 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003404 .suite = {
3405 .cipher = {
3406 .enc = {
3407 .vecs = salsa20_stream_enc_tv_template,
3408 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3409 }
3410 }
3411 }
3412 }, {
3413 .alg = "sha1",
3414 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003415 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003416 .suite = {
3417 .hash = {
3418 .vecs = sha1_tv_template,
3419 .count = SHA1_TEST_VECTORS
3420 }
3421 }
3422 }, {
3423 .alg = "sha224",
3424 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003425 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003426 .suite = {
3427 .hash = {
3428 .vecs = sha224_tv_template,
3429 .count = SHA224_TEST_VECTORS
3430 }
3431 }
3432 }, {
3433 .alg = "sha256",
3434 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003435 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003436 .suite = {
3437 .hash = {
3438 .vecs = sha256_tv_template,
3439 .count = SHA256_TEST_VECTORS
3440 }
3441 }
3442 }, {
3443 .alg = "sha384",
3444 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003445 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003446 .suite = {
3447 .hash = {
3448 .vecs = sha384_tv_template,
3449 .count = SHA384_TEST_VECTORS
3450 }
3451 }
3452 }, {
3453 .alg = "sha512",
3454 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003455 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003456 .suite = {
3457 .hash = {
3458 .vecs = sha512_tv_template,
3459 .count = SHA512_TEST_VECTORS
3460 }
3461 }
3462 }, {
3463 .alg = "tgr128",
3464 .test = alg_test_hash,
3465 .suite = {
3466 .hash = {
3467 .vecs = tgr128_tv_template,
3468 .count = TGR128_TEST_VECTORS
3469 }
3470 }
3471 }, {
3472 .alg = "tgr160",
3473 .test = alg_test_hash,
3474 .suite = {
3475 .hash = {
3476 .vecs = tgr160_tv_template,
3477 .count = TGR160_TEST_VECTORS
3478 }
3479 }
3480 }, {
3481 .alg = "tgr192",
3482 .test = alg_test_hash,
3483 .suite = {
3484 .hash = {
3485 .vecs = tgr192_tv_template,
3486 .count = TGR192_TEST_VECTORS
3487 }
3488 }
3489 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003490 .alg = "vmac(aes)",
3491 .test = alg_test_hash,
3492 .suite = {
3493 .hash = {
3494 .vecs = aes_vmac128_tv_template,
3495 .count = VMAC_AES_TEST_VECTORS
3496 }
3497 }
3498 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003499 .alg = "wp256",
3500 .test = alg_test_hash,
3501 .suite = {
3502 .hash = {
3503 .vecs = wp256_tv_template,
3504 .count = WP256_TEST_VECTORS
3505 }
3506 }
3507 }, {
3508 .alg = "wp384",
3509 .test = alg_test_hash,
3510 .suite = {
3511 .hash = {
3512 .vecs = wp384_tv_template,
3513 .count = WP384_TEST_VECTORS
3514 }
3515 }
3516 }, {
3517 .alg = "wp512",
3518 .test = alg_test_hash,
3519 .suite = {
3520 .hash = {
3521 .vecs = wp512_tv_template,
3522 .count = WP512_TEST_VECTORS
3523 }
3524 }
3525 }, {
3526 .alg = "xcbc(aes)",
3527 .test = alg_test_hash,
3528 .suite = {
3529 .hash = {
3530 .vecs = aes_xcbc128_tv_template,
3531 .count = XCBC_AES_TEST_VECTORS
3532 }
3533 }
3534 }, {
3535 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003536 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003537 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003538 .suite = {
3539 .cipher = {
3540 .enc = {
3541 .vecs = aes_xts_enc_tv_template,
3542 .count = AES_XTS_ENC_TEST_VECTORS
3543 },
3544 .dec = {
3545 .vecs = aes_xts_dec_tv_template,
3546 .count = AES_XTS_DEC_TEST_VECTORS
3547 }
3548 }
3549 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003550 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003551 .alg = "xts(camellia)",
3552 .test = alg_test_skcipher,
3553 .suite = {
3554 .cipher = {
3555 .enc = {
3556 .vecs = camellia_xts_enc_tv_template,
3557 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3558 },
3559 .dec = {
3560 .vecs = camellia_xts_dec_tv_template,
3561 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3562 }
3563 }
3564 }
3565 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003566 .alg = "xts(cast6)",
3567 .test = alg_test_skcipher,
3568 .suite = {
3569 .cipher = {
3570 .enc = {
3571 .vecs = cast6_xts_enc_tv_template,
3572 .count = CAST6_XTS_ENC_TEST_VECTORS
3573 },
3574 .dec = {
3575 .vecs = cast6_xts_dec_tv_template,
3576 .count = CAST6_XTS_DEC_TEST_VECTORS
3577 }
3578 }
3579 }
3580 }, {
Jussi Kivilinna18be20b92011-10-18 13:33:17 +03003581 .alg = "xts(serpent)",
3582 .test = alg_test_skcipher,
3583 .suite = {
3584 .cipher = {
3585 .enc = {
3586 .vecs = serpent_xts_enc_tv_template,
3587 .count = SERPENT_XTS_ENC_TEST_VECTORS
3588 },
3589 .dec = {
3590 .vecs = serpent_xts_dec_tv_template,
3591 .count = SERPENT_XTS_DEC_TEST_VECTORS
3592 }
3593 }
3594 }
3595 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003596 .alg = "xts(twofish)",
3597 .test = alg_test_skcipher,
3598 .suite = {
3599 .cipher = {
3600 .enc = {
3601 .vecs = tf_xts_enc_tv_template,
3602 .count = TF_XTS_ENC_TEST_VECTORS
3603 },
3604 .dec = {
3605 .vecs = tf_xts_dec_tv_template,
3606 .count = TF_XTS_DEC_TEST_VECTORS
3607 }
3608 }
3609 }
3610 }, {
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003611 .alg = "zlib",
3612 .test = alg_test_pcomp,
Milan Broz08189042012-12-06 17:16:28 +08003613 .fips_allowed = 1,
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003614 .suite = {
3615 .pcomp = {
3616 .comp = {
3617 .vecs = zlib_comp_tv_template,
3618 .count = ZLIB_COMP_TEST_VECTORS
3619 },
3620 .decomp = {
3621 .vecs = zlib_decomp_tv_template,
3622 .count = ZLIB_DECOMP_TEST_VECTORS
3623 }
3624 }
3625 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003626 }
3627};
3628
Jussi Kivilinna57147582013-06-13 17:37:40 +03003629static bool alg_test_descs_checked;
3630
3631static void alg_test_descs_check_order(void)
3632{
3633 int i;
3634
3635 /* only check once */
3636 if (alg_test_descs_checked)
3637 return;
3638
3639 alg_test_descs_checked = true;
3640
3641 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3642 int diff = strcmp(alg_test_descs[i - 1].alg,
3643 alg_test_descs[i].alg);
3644
3645 if (WARN_ON(diff > 0)) {
3646 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3647 alg_test_descs[i - 1].alg,
3648 alg_test_descs[i].alg);
3649 }
3650
3651 if (WARN_ON(diff == 0)) {
3652 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3653 alg_test_descs[i].alg);
3654 }
3655 }
3656}
3657
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003658static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003659{
3660 int start = 0;
3661 int end = ARRAY_SIZE(alg_test_descs);
3662
3663 while (start < end) {
3664 int i = (start + end) / 2;
3665 int diff = strcmp(alg_test_descs[i].alg, alg);
3666
3667 if (diff > 0) {
3668 end = i;
3669 continue;
3670 }
3671
3672 if (diff < 0) {
3673 start = i + 1;
3674 continue;
3675 }
3676
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003677 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003678 }
3679
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003680 return -1;
3681}
3682
3683int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3684{
3685 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003686 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003687 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003688
Jussi Kivilinna57147582013-06-13 17:37:40 +03003689 alg_test_descs_check_order();
3690
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003691 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3692 char nalg[CRYPTO_MAX_ALG_NAME];
3693
3694 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3695 sizeof(nalg))
3696 return -ENAMETOOLONG;
3697
3698 i = alg_find_test(nalg);
3699 if (i < 0)
3700 goto notest;
3701
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003702 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3703 goto non_fips_alg;
3704
Jarod Wilson941fb322009-05-04 19:49:23 +08003705 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3706 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003707 }
3708
3709 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003710 j = alg_find_test(driver);
3711 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003712 goto notest;
3713
Herbert Xua68f6612009-07-02 16:32:12 +08003714 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3715 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003716 goto non_fips_alg;
3717
Herbert Xua68f6612009-07-02 16:32:12 +08003718 rc = 0;
3719 if (i >= 0)
3720 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3721 type, mask);
Cristian Stoica032c8ca2013-07-18 18:57:07 +03003722 if (j >= 0 && j != i)
Herbert Xua68f6612009-07-02 16:32:12 +08003723 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3724 type, mask);
3725
Jarod Wilson941fb322009-05-04 19:49:23 +08003726test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003727 if (fips_enabled && rc)
3728 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3729
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003730 if (fips_enabled && !rc)
Masanari Iida3e8cffd2014-10-07 00:37:54 +09003731 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003732
Neil Hormand12d6b62008-10-12 20:36:51 +08003733 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003734
3735notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003736 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3737 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003738non_fips_alg:
3739 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003740}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003741
Herbert Xu326a6342010-08-06 09:40:28 +08003742#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003743
Herbert Xuda7f0332008-07-31 17:08:25 +08003744EXPORT_SYMBOL_GPL(alg_test);