]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - crypto/tcrypt.c
[CRYPTO] rmd: Use pointer form of endian swapping operations
[mirror_ubuntu-jammy-kernel.git] / crypto / tcrypt.c
CommitLineData
ef2736fc 1/*
1da177e4
LT
2 * Quick & dirty crypto testing module.
3 *
4 * This will only exist until we have a better testing mechanism
5 * (e.g. a char device).
6 *
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
e3a4ea4f 9 * Copyright (c) 2007 Nokia Siemens Networks
1da177e4
LT
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
ef2736fc 13 * Software Foundation; either version 2 of the License, or (at your option)
1da177e4
LT
14 * any later version.
15 *
1da177e4
LT
16 */
17
cba83564 18#include <linux/err.h>
1da177e4
LT
19#include <linux/init.h>
20#include <linux/module.h>
21#include <linux/mm.h>
22#include <linux/slab.h>
378f058c 23#include <linux/scatterlist.h>
1da177e4
LT
24#include <linux/string.h>
25#include <linux/crypto.h>
26#include <linux/highmem.h>
27#include <linux/moduleparam.h>
ebfd9bcf 28#include <linux/jiffies.h>
6a17944c
HX
29#include <linux/timex.h>
30#include <linux/interrupt.h>
1da177e4
LT
31#include "tcrypt.h"
32
33/*
34 * Need to kmalloc() memory for testing kmap().
35 */
ebfd9bcf 36#define TVMEMSIZE 16384
1da177e4
LT
37#define XBUFSIZE 32768
38
39/*
40 * Indexes into the xbuf to simulate cross-page access.
41 */
a558f1d4 42#define IDX1 32
1da177e4
LT
43#define IDX2 32400
44#define IDX3 1
45#define IDX4 8193
46#define IDX5 22222
47#define IDX6 17101
48#define IDX7 27333
49#define IDX8 3000
50
51/*
52* Used by test_cipher()
53*/
54#define ENCRYPT 1
55#define DECRYPT 0
1da177e4 56
6158efc0
HX
57struct tcrypt_result {
58 struct completion completion;
59 int err;
60};
61
1da177e4
LT
62static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
63
ebfd9bcf
HW
64/*
65 * Used by test_cipher_speed()
66 */
6a17944c 67static unsigned int sec;
ebfd9bcf 68
1da177e4
LT
69static int mode;
70static char *xbuf;
e3a4ea4f 71static char *axbuf;
1da177e4
LT
72static char *tvmem;
73
74static char *check[] = {
cd12fb90
JL
75 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
76 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
77 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
90831639 78 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
2998db37
AKR
79 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
80 "lzo", "cts", NULL
1da177e4
LT
81};
82
ef2736fc 83static void hexdump(unsigned char *buf, unsigned int len)
1da177e4 84{
a10e1194
DC
85 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
86 16, 1,
87 buf, len, false);
1da177e4
LT
88}
89
6158efc0
HX
90static void tcrypt_complete(struct crypto_async_request *req, int err)
91{
92 struct tcrypt_result *res = req->data;
93
94 if (err == -EINPROGRESS)
95 return;
96
97 res->err = err;
98 complete(&res->completion);
99}
100
ef2736fc
HX
101static void test_hash(char *algo, struct hash_testvec *template,
102 unsigned int tcount)
1da177e4 103{
ef2736fc
HX
104 unsigned int i, j, k, temp;
105 struct scatterlist sg[8];
106 char result[64];
cde0e2c8
LH
107 struct crypto_ahash *tfm;
108 struct ahash_request *req;
109 struct tcrypt_result tresult;
e9d41164 110 int ret;
562954d5 111 void *hash_buff;
ef2736fc
HX
112
113 printk("\ntesting %s\n", algo);
114
cde0e2c8
LH
115 init_completion(&tresult.completion);
116
117 tfm = crypto_alloc_ahash(algo, 0, 0);
e9d41164
HX
118 if (IS_ERR(tfm)) {
119 printk("failed to load transform for %s: %ld\n", algo,
120 PTR_ERR(tfm));
1da177e4
LT
121 return;
122 }
123
cde0e2c8
LH
124 req = ahash_request_alloc(tfm, GFP_KERNEL);
125 if (!req) {
126 printk(KERN_ERR "failed to allocate request for %s\n", algo);
127 goto out_noreq;
128 }
129 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
130 tcrypt_complete, &tresult);
e9d41164 131
1da177e4 132 for (i = 0; i < tcount; i++) {
ef2736fc
HX
133 printk("test %u:\n", i + 1);
134 memset(result, 0, 64);
1da177e4 135
562954d5
SS
136 hash_buff = kzalloc(template[i].psize, GFP_KERNEL);
137 if (!hash_buff)
138 continue;
1da177e4 139
562954d5
SS
140 memcpy(hash_buff, template[i].plaintext, template[i].psize);
141 sg_init_one(&sg[0], hash_buff, template[i].psize);
142
143 if (template[i].ksize) {
cde0e2c8
LH
144 crypto_ahash_clear_flags(tfm, ~0);
145 ret = crypto_ahash_setkey(tfm, template[i].key,
146 template[i].ksize);
e9d41164
HX
147 if (ret) {
148 printk("setkey() failed ret=%d\n", ret);
562954d5 149 kfree(hash_buff);
e9d41164
HX
150 goto out;
151 }
152 }
153
cde0e2c8
LH
154 ahash_request_set_crypt(req, sg, result, template[i].psize);
155 ret = crypto_ahash_digest(req);
156 switch (ret) {
157 case 0:
158 break;
159 case -EINPROGRESS:
160 case -EBUSY:
161 ret = wait_for_completion_interruptible(
162 &tresult.completion);
163 if (!ret && !(ret = tresult.err)) {
164 INIT_COMPLETION(tresult.completion);
165 break;
166 }
167 /* fall through */
168 default:
e9d41164 169 printk("digest () failed ret=%d\n", ret);
562954d5 170 kfree(hash_buff);
e9d41164
HX
171 goto out;
172 }
1da177e4 173
cde0e2c8 174 hexdump(result, crypto_ahash_digestsize(tfm));
1da177e4 175 printk("%s\n",
562954d5 176 memcmp(result, template[i].digest,
cde0e2c8 177 crypto_ahash_digestsize(tfm)) ?
ef2736fc 178 "fail" : "pass");
562954d5 179 kfree(hash_buff);
1da177e4
LT
180 }
181
ef2736fc 182 printk("testing %s across pages\n", algo);
1da177e4
LT
183
184 /* setup the dummy buffer first */
ef2736fc 185 memset(xbuf, 0, XBUFSIZE);
1da177e4
LT
186
187 j = 0;
188 for (i = 0; i < tcount; i++) {
562954d5 189 if (template[i].np) {
1da177e4 190 j++;
ef2736fc
HX
191 printk("test %u:\n", j);
192 memset(result, 0, 64);
1da177e4
LT
193
194 temp = 0;
562954d5
SS
195 sg_init_table(sg, template[i].np);
196 for (k = 0; k < template[i].np; k++) {
ef2736fc 197 memcpy(&xbuf[IDX[k]],
562954d5
SS
198 template[i].plaintext + temp,
199 template[i].tap[k]);
200 temp += template[i].tap[k];
378f058c 201 sg_set_buf(&sg[k], &xbuf[IDX[k]],
562954d5 202 template[i].tap[k]);
1da177e4
LT
203 }
204
562954d5 205 if (template[i].ksize) {
cde0e2c8
LH
206 crypto_ahash_clear_flags(tfm, ~0);
207 ret = crypto_ahash_setkey(tfm, template[i].key,
208 template[i].ksize);
ef2736fc 209
e9d41164
HX
210 if (ret) {
211 printk("setkey() failed ret=%d\n", ret);
212 goto out;
213 }
1da177e4
LT
214 }
215
cde0e2c8
LH
216 ahash_request_set_crypt(req, sg, result,
217 template[i].psize);
218 ret = crypto_ahash_digest(req);
219 switch (ret) {
220 case 0:
221 break;
222 case -EINPROGRESS:
223 case -EBUSY:
224 ret = wait_for_completion_interruptible(
225 &tresult.completion);
226 if (!ret && !(ret = tresult.err)) {
227 INIT_COMPLETION(tresult.completion);
228 break;
229 }
230 /* fall through */
231 default:
e9d41164
HX
232 printk("digest () failed ret=%d\n", ret);
233 goto out;
234 }
ef2736fc 235
cde0e2c8 236 hexdump(result, crypto_ahash_digestsize(tfm));
1da177e4 237 printk("%s\n",
562954d5 238 memcmp(result, template[i].digest,
cde0e2c8 239 crypto_ahash_digestsize(tfm)) ?
ef2736fc 240 "fail" : "pass");
1da177e4
LT
241 }
242 }
e9d41164 243
1da177e4 244out:
cde0e2c8
LH
245 ahash_request_free(req);
246out_noreq:
247 crypto_free_ahash(tfm);
1da177e4
LT
248}
249
e3a4ea4f
MH
250static void test_aead(char *algo, int enc, struct aead_testvec *template,
251 unsigned int tcount)
252{
a558f1d4 253 unsigned int ret, i, j, k, n, temp;
e3a4ea4f
MH
254 char *q;
255 struct crypto_aead *tfm;
256 char *key;
e3a4ea4f
MH
257 struct aead_request *req;
258 struct scatterlist sg[8];
259 struct scatterlist asg[8];
260 const char *e;
261 struct tcrypt_result result;
6160b289 262 unsigned int authsize;
562954d5
SS
263 void *input;
264 void *assoc;
265 char iv[MAX_IVLEN];
e3a4ea4f
MH
266
267 if (enc == ENCRYPT)
268 e = "encryption";
269 else
270 e = "decryption";
271
272 printk(KERN_INFO "\ntesting %s %s\n", algo, e);
273
e3a4ea4f
MH
274 init_completion(&result.completion);
275
276 tfm = crypto_alloc_aead(algo, 0, 0);
277
278 if (IS_ERR(tfm)) {
279 printk(KERN_INFO "failed to load transform for %s: %ld\n",
280 algo, PTR_ERR(tfm));
281 return;
282 }
283
284 req = aead_request_alloc(tfm, GFP_KERNEL);
285 if (!req) {
286 printk(KERN_INFO "failed to allocate request for %s\n", algo);
287 goto out;
288 }
289
290 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
291 tcrypt_complete, &result);
292
293 for (i = 0, j = 0; i < tcount; i++) {
562954d5 294 if (!template[i].np) {
e3a4ea4f 295 printk(KERN_INFO "test %u (%d bit key):\n",
562954d5
SS
296 ++j, template[i].klen * 8);
297
298 /* some tepmplates have no input data but they will
299 * touch input
300 */
301 input = kzalloc(template[i].ilen + template[i].rlen, GFP_KERNEL);
302 if (!input)
303 continue;
304
305 assoc = kzalloc(template[i].alen, GFP_KERNEL);
306 if (!assoc) {
307 kfree(input);
308 continue;
309 }
310
311 memcpy(input, template[i].input, template[i].ilen);
312 memcpy(assoc, template[i].assoc, template[i].alen);
313 if (template[i].iv)
314 memcpy(iv, template[i].iv, MAX_IVLEN);
315 else
316 memset(iv, 0, MAX_IVLEN);
e3a4ea4f
MH
317
318 crypto_aead_clear_flags(tfm, ~0);
562954d5 319 if (template[i].wk)
e3a4ea4f
MH
320 crypto_aead_set_flags(
321 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
562954d5
SS
322
323 if (template[i].key)
324 key = template[i].key;
325 else
326 key = kzalloc(template[i].klen, GFP_KERNEL);
e3a4ea4f
MH
327
328 ret = crypto_aead_setkey(tfm, key,
562954d5 329 template[i].klen);
e3a4ea4f
MH
330 if (ret) {
331 printk(KERN_INFO "setkey() failed flags=%x\n",
332 crypto_aead_get_flags(tfm));
333
562954d5
SS
334 if (!template[i].fail)
335 goto next_one;
e3a4ea4f
MH
336 }
337
562954d5 338 authsize = abs(template[i].rlen - template[i].ilen);
93cc74e0
JL
339 ret = crypto_aead_setauthsize(tfm, authsize);
340 if (ret) {
341 printk(KERN_INFO
342 "failed to set authsize = %u\n",
343 authsize);
562954d5 344 goto next_one;
93cc74e0
JL
345 }
346
562954d5
SS
347 sg_init_one(&sg[0], input,
348 template[i].ilen + (enc ? authsize : 0));
e3a4ea4f 349
562954d5 350 sg_init_one(&asg[0], assoc, template[i].alen);
e3a4ea4f
MH
351
352 aead_request_set_crypt(req, sg, sg,
562954d5 353 template[i].ilen, iv);
e3a4ea4f 354
562954d5 355 aead_request_set_assoc(req, asg, template[i].alen);
e3a4ea4f 356
6160b289
HX
357 ret = enc ?
358 crypto_aead_encrypt(req) :
359 crypto_aead_decrypt(req);
e3a4ea4f
MH
360
361 switch (ret) {
362 case 0:
363 break;
364 case -EINPROGRESS:
365 case -EBUSY:
366 ret = wait_for_completion_interruptible(
367 &result.completion);
368 if (!ret && !(ret = result.err)) {
369 INIT_COMPLETION(result.completion);
370 break;
371 }
372 /* fall through */
373 default:
374 printk(KERN_INFO "%s () failed err=%d\n",
375 e, -ret);
562954d5 376 goto next_one;
e3a4ea4f
MH
377 }
378
379 q = kmap(sg_page(&sg[0])) + sg[0].offset;
562954d5 380 hexdump(q, template[i].rlen);
e3a4ea4f
MH
381
382 printk(KERN_INFO "enc/dec: %s\n",
562954d5
SS
383 memcmp(q, template[i].result,
384 template[i].rlen) ? "fail" : "pass");
385 kunmap(sg_page(&sg[0]));
386next_one:
387 if (!template[i].key)
388 kfree(key);
389 kfree(assoc);
390 kfree(input);
e3a4ea4f
MH
391 }
392 }
393
394 printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e);
2a999a3a 395 memset(axbuf, 0, XBUFSIZE);
e3a4ea4f
MH
396
397 for (i = 0, j = 0; i < tcount; i++) {
562954d5 398 if (template[i].np) {
e3a4ea4f 399 printk(KERN_INFO "test %u (%d bit key):\n",
562954d5
SS
400 ++j, template[i].klen * 8);
401
402 if (template[i].iv)
403 memcpy(iv, template[i].iv, MAX_IVLEN);
404 else
405 memset(iv, 0, MAX_IVLEN);
e3a4ea4f
MH
406
407 crypto_aead_clear_flags(tfm, ~0);
562954d5 408 if (template[i].wk)
e3a4ea4f
MH
409 crypto_aead_set_flags(
410 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
562954d5 411 key = template[i].key;
e3a4ea4f 412
562954d5 413 ret = crypto_aead_setkey(tfm, key, template[i].klen);
e3a4ea4f
MH
414 if (ret) {
415 printk(KERN_INFO "setkey() failed flags=%x\n",
416 crypto_aead_get_flags(tfm));
417
562954d5 418 if (!template[i].fail)
e3a4ea4f
MH
419 goto out;
420 }
421
a558f1d4 422 memset(xbuf, 0, XBUFSIZE);
562954d5
SS
423 sg_init_table(sg, template[i].np);
424 for (k = 0, temp = 0; k < template[i].np; k++) {
e3a4ea4f 425 memcpy(&xbuf[IDX[k]],
562954d5
SS
426 template[i].input + temp,
427 template[i].tap[k]);
428 temp += template[i].tap[k];
e3a4ea4f 429 sg_set_buf(&sg[k], &xbuf[IDX[k]],
562954d5 430 template[i].tap[k]);
e3a4ea4f
MH
431 }
432
562954d5 433 authsize = abs(template[i].rlen - template[i].ilen);
93cc74e0
JL
434 ret = crypto_aead_setauthsize(tfm, authsize);
435 if (ret) {
436 printk(KERN_INFO
437 "failed to set authsize = %u\n",
438 authsize);
439 goto out;
440 }
441
6160b289
HX
442 if (enc)
443 sg[k - 1].length += authsize;
444
562954d5
SS
445 sg_init_table(asg, template[i].anp);
446 for (k = 0, temp = 0; k < template[i].anp; k++) {
e3a4ea4f 447 memcpy(&axbuf[IDX[k]],
562954d5
SS
448 template[i].assoc + temp,
449 template[i].atap[k]);
450 temp += template[i].atap[k];
e3a4ea4f 451 sg_set_buf(&asg[k], &axbuf[IDX[k]],
562954d5 452 template[i].atap[k]);
e3a4ea4f
MH
453 }
454
455 aead_request_set_crypt(req, sg, sg,
562954d5
SS
456 template[i].ilen,
457 iv);
e3a4ea4f 458
562954d5 459 aead_request_set_assoc(req, asg, template[i].alen);
e3a4ea4f 460
6160b289
HX
461 ret = enc ?
462 crypto_aead_encrypt(req) :
463 crypto_aead_decrypt(req);
e3a4ea4f
MH
464
465 switch (ret) {
466 case 0:
467 break;
468 case -EINPROGRESS:
469 case -EBUSY:
470 ret = wait_for_completion_interruptible(
471 &result.completion);
472 if (!ret && !(ret = result.err)) {
473 INIT_COMPLETION(result.completion);
474 break;
475 }
476 /* fall through */
477 default:
478 printk(KERN_INFO "%s () failed err=%d\n",
479 e, -ret);
480 goto out;
481 }
482
562954d5 483 for (k = 0, temp = 0; k < template[i].np; k++) {
e3a4ea4f
MH
484 printk(KERN_INFO "page %u\n", k);
485 q = kmap(sg_page(&sg[k])) + sg[k].offset;
562954d5 486 hexdump(q, template[i].tap[k]);
e3a4ea4f 487 printk(KERN_INFO "%s\n",
562954d5
SS
488 memcmp(q, template[i].result + temp,
489 template[i].tap[k] -
490 (k < template[i].np - 1 || enc ?
6160b289 491 0 : authsize)) ?
e3a4ea4f
MH
492 "fail" : "pass");
493
a558f1d4
PM
494 for (n = 0; q[template[i].tap[k] + n]; n++)
495 ;
496 if (n) {
497 printk("Result buffer corruption %u "
498 "bytes:\n", n);
499 hexdump(&q[template[i].tap[k]], n);
500 }
501
562954d5
SS
502 temp += template[i].tap[k];
503 kunmap(sg_page(&sg[k]));
e3a4ea4f 504 }
e3a4ea4f
MH
505 }
506 }
507
508out:
509 crypto_free_aead(tfm);
510 aead_request_free(req);
511}
512
cba83564 513static void test_cipher(char *algo, int enc,
ef2736fc 514 struct cipher_testvec *template, unsigned int tcount)
1da177e4 515{
a558f1d4 516 unsigned int ret, i, j, k, n, temp;
378f058c 517 char *q;
6158efc0 518 struct crypto_ablkcipher *tfm;
6158efc0 519 struct ablkcipher_request *req;
1da177e4 520 struct scatterlist sg[8];
cba83564 521 const char *e;
6158efc0 522 struct tcrypt_result result;
562954d5
SS
523 void *data;
524 char iv[MAX_IVLEN];
1da177e4
LT
525
526 if (enc == ENCRYPT)
3cc3816f 527 e = "encryption";
1da177e4 528 else
3cc3816f 529 e = "decryption";
1da177e4 530
cba83564 531 printk("\ntesting %s %s\n", algo, e);
1da177e4 532
6158efc0 533 init_completion(&result.completion);
6158efc0 534 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
1da177e4 535
cba83564
HX
536 if (IS_ERR(tfm)) {
537 printk("failed to load transform for %s: %ld\n", algo,
538 PTR_ERR(tfm));
1da177e4
LT
539 return;
540 }
6158efc0
HX
541
542 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
543 if (!req) {
544 printk("failed to allocate request for %s\n", algo);
545 goto out;
546 }
547
548 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
549 tcrypt_complete, &result);
ef2736fc 550
1da177e4
LT
551 j = 0;
552 for (i = 0; i < tcount; i++) {
562954d5
SS
553
554 data = kzalloc(template[i].ilen, GFP_KERNEL);
555 if (!data)
556 continue;
557
558 memcpy(data, template[i].input, template[i].ilen);
559 if (template[i].iv)
560 memcpy(iv, template[i].iv, MAX_IVLEN);
561 else
562 memset(iv, 0, MAX_IVLEN);
563
564 if (!(template[i].np)) {
ef2736fc 565 j++;
1da177e4 566 printk("test %u (%d bit key):\n",
562954d5 567 j, template[i].klen * 8);
1da177e4 568
6158efc0 569 crypto_ablkcipher_clear_flags(tfm, ~0);
562954d5 570 if (template[i].wk)
6158efc0 571 crypto_ablkcipher_set_flags(
cba83564 572 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
ef2736fc 573
562954d5
SS
574 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
575 template[i].klen);
1da177e4 576 if (ret) {
cba83564 577 printk("setkey() failed flags=%x\n",
6158efc0 578 crypto_ablkcipher_get_flags(tfm));
ef2736fc 579
562954d5
SS
580 if (!template[i].fail) {
581 kfree(data);
1da177e4 582 goto out;
562954d5 583 }
ef2736fc 584 }
1da177e4 585
562954d5 586 sg_init_one(&sg[0], data, template[i].ilen);
ef2736fc 587
6158efc0 588 ablkcipher_request_set_crypt(req, sg, sg,
562954d5 589 template[i].ilen, iv);
cba83564 590 ret = enc ?
6158efc0
HX
591 crypto_ablkcipher_encrypt(req) :
592 crypto_ablkcipher_decrypt(req);
ef2736fc 593
6158efc0
HX
594 switch (ret) {
595 case 0:
596 break;
597 case -EINPROGRESS:
598 case -EBUSY:
599 ret = wait_for_completion_interruptible(
600 &result.completion);
601 if (!ret && !((ret = result.err))) {
602 INIT_COMPLETION(result.completion);
603 break;
604 }
605 /* fall through */
606 default:
607 printk("%s () failed err=%d\n", e, -ret);
562954d5 608 kfree(data);
1da177e4 609 goto out;
ef2736fc
HX
610 }
611
78c2f0b8 612 q = kmap(sg_page(&sg[0])) + sg[0].offset;
562954d5 613 hexdump(q, template[i].rlen);
ef2736fc
HX
614
615 printk("%s\n",
562954d5
SS
616 memcmp(q, template[i].result,
617 template[i].rlen) ? "fail" : "pass");
618 kunmap(sg_page(&sg[0]));
1da177e4 619 }
562954d5 620 kfree(data);
1da177e4 621 }
ef2736fc 622
cba83564 623 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
ef2736fc 624
1da177e4
LT
625 j = 0;
626 for (i = 0; i < tcount; i++) {
562954d5 627
562954d5
SS
628 if (template[i].iv)
629 memcpy(iv, template[i].iv, MAX_IVLEN);
630 else
631 memset(iv, 0, MAX_IVLEN);
632
633 if (template[i].np) {
ef2736fc 634 j++;
1da177e4 635 printk("test %u (%d bit key):\n",
562954d5 636 j, template[i].klen * 8);
1da177e4 637
a558f1d4 638 memset(xbuf, 0, XBUFSIZE);
6158efc0 639 crypto_ablkcipher_clear_flags(tfm, ~0);
562954d5 640 if (template[i].wk)
6158efc0 641 crypto_ablkcipher_set_flags(
cba83564 642 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
ef2736fc 643
562954d5
SS
644 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
645 template[i].klen);
1da177e4 646 if (ret) {
cba83564 647 printk("setkey() failed flags=%x\n",
562954d5 648 crypto_ablkcipher_get_flags(tfm));
ef2736fc 649
dbb018cd 650 if (!template[i].fail)
1da177e4
LT
651 goto out;
652 }
653
654 temp = 0;
562954d5
SS
655 sg_init_table(sg, template[i].np);
656 for (k = 0; k < template[i].np; k++) {
ef2736fc 657 memcpy(&xbuf[IDX[k]],
562954d5
SS
658 template[i].input + temp,
659 template[i].tap[k]);
660 temp += template[i].tap[k];
378f058c 661 sg_set_buf(&sg[k], &xbuf[IDX[k]],
562954d5 662 template[i].tap[k]);
1da177e4 663 }
ef2736fc 664
6158efc0 665 ablkcipher_request_set_crypt(req, sg, sg,
562954d5 666 template[i].ilen, iv);
ef2736fc 667
cba83564 668 ret = enc ?
6158efc0
HX
669 crypto_ablkcipher_encrypt(req) :
670 crypto_ablkcipher_decrypt(req);
ef2736fc 671
6158efc0
HX
672 switch (ret) {
673 case 0:
674 break;
675 case -EINPROGRESS:
676 case -EBUSY:
677 ret = wait_for_completion_interruptible(
678 &result.completion);
679 if (!ret && !((ret = result.err))) {
680 INIT_COMPLETION(result.completion);
681 break;
682 }
683 /* fall through */
684 default:
685 printk("%s () failed err=%d\n", e, -ret);
1da177e4
LT
686 goto out;
687 }
688
689 temp = 0;
562954d5 690 for (k = 0; k < template[i].np; k++) {
1da177e4 691 printk("page %u\n", k);
78c2f0b8 692 q = kmap(sg_page(&sg[k])) + sg[k].offset;
562954d5 693 hexdump(q, template[i].tap[k]);
ef2736fc 694 printk("%s\n",
562954d5
SS
695 memcmp(q, template[i].result + temp,
696 template[i].tap[k]) ? "fail" :
1da177e4 697 "pass");
a558f1d4
PM
698
699 for (n = 0; q[template[i].tap[k] + n]; n++)
700 ;
701 if (n) {
702 printk("Result buffer corruption %u "
703 "bytes:\n", n);
704 hexdump(&q[template[i].tap[k]], n);
705 }
562954d5
SS
706 temp += template[i].tap[k];
707 kunmap(sg_page(&sg[k]));
1da177e4
LT
708 }
709 }
710 }
1da177e4 711out:
6158efc0
HX
712 crypto_free_ablkcipher(tfm);
713 ablkcipher_request_free(req);
1da177e4
LT
714}
715
cba83564 716static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
6a17944c
HX
717 int blen, int sec)
718{
6df5b9f4 719 struct scatterlist sg[1];
6a17944c
HX
720 unsigned long start, end;
721 int bcount;
722 int ret;
723
b7335885 724 sg_init_one(sg, p, blen);
6a17944c
HX
725
726 for (start = jiffies, end = start + sec * HZ, bcount = 0;
727 time_before(jiffies, end); bcount++) {
728 if (enc)
cba83564 729 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
6a17944c 730 else
cba83564 731 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
6a17944c
HX
732
733 if (ret)
734 return ret;
735 }
736
737 printk("%d operations in %d seconds (%ld bytes)\n",
738 bcount, sec, (long)bcount * blen);
739 return 0;
740}
741
cba83564 742static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
6a17944c
HX
743 int blen)
744{
6df5b9f4 745 struct scatterlist sg[1];
6a17944c
HX
746 unsigned long cycles = 0;
747 int ret = 0;
748 int i;
749
b7335885 750 sg_init_one(sg, p, blen);
6a17944c
HX
751
752 local_bh_disable();
753 local_irq_disable();
754
755 /* Warm-up run. */
756 for (i = 0; i < 4; i++) {
757 if (enc)
cba83564 758 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
6a17944c 759 else
cba83564 760 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
6a17944c
HX
761
762 if (ret)
763 goto out;
764 }
765
766 /* The real thing. */
767 for (i = 0; i < 8; i++) {
768 cycles_t start, end;
769
770 start = get_cycles();
771 if (enc)
cba83564 772 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
6a17944c 773 else
cba83564 774 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
6a17944c
HX
775 end = get_cycles();
776
777 if (ret)
778 goto out;
779
780 cycles += end - start;
781 }
782
783out:
784 local_irq_enable();
785 local_bh_enable();
786
787 if (ret == 0)
788 printk("1 operation in %lu cycles (%d bytes)\n",
789 (cycles + 4) / 8, blen);
790
791 return ret;
792}
793
d5dc3927
SS
794static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
795
cba83564 796static void test_cipher_speed(char *algo, int enc, unsigned int sec,
dce907c0 797 struct cipher_testvec *template,
d5dc3927 798 unsigned int tcount, u8 *keysize)
ebfd9bcf 799{
dce907c0 800 unsigned int ret, i, j, iv_len;
ebfd9bcf 801 unsigned char *key, *p, iv[128];
cba83564
HX
802 struct crypto_blkcipher *tfm;
803 struct blkcipher_desc desc;
804 const char *e;
d5dc3927 805 u32 *b_size;
ebfd9bcf
HW
806
807 if (enc == ENCRYPT)
808 e = "encryption";
809 else
810 e = "decryption";
ebfd9bcf 811
cba83564 812 printk("\ntesting speed of %s %s\n", algo, e);
ebfd9bcf 813
cba83564 814 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
ebfd9bcf 815
cba83564
HX
816 if (IS_ERR(tfm)) {
817 printk("failed to load transform for %s: %ld\n", algo,
818 PTR_ERR(tfm));
ebfd9bcf
HW
819 return;
820 }
cba83564
HX
821 desc.tfm = tfm;
822 desc.flags = 0;
ebfd9bcf 823
d5dc3927
SS
824 i = 0;
825 do {
ebfd9bcf 826
d5dc3927
SS
827 b_size = block_sizes;
828 do {
ebfd9bcf 829
d5dc3927
SS
830 if ((*keysize + *b_size) > TVMEMSIZE) {
831 printk("template (%u) too big for tvmem (%u)\n",
832 *keysize + *b_size, TVMEMSIZE);
833 goto out;
834 }
ebfd9bcf 835
d5dc3927
SS
836 printk("test %u (%d bit key, %d byte blocks): ", i,
837 *keysize * 8, *b_size);
838
839 memset(tvmem, 0xff, *keysize + *b_size);
840
841 /* set key, plain text and IV */
842 key = (unsigned char *)tvmem;
843 for (j = 0; j < tcount; j++) {
844 if (template[j].klen == *keysize) {
845 key = template[j].key;
846 break;
847 }
dce907c0 848 }
d5dc3927 849 p = (unsigned char *)tvmem + *keysize;
ebfd9bcf 850
d5dc3927
SS
851 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
852 if (ret) {
853 printk("setkey() failed flags=%x\n",
854 crypto_blkcipher_get_flags(tfm));
855 goto out;
856 }
ebfd9bcf 857
d5dc3927
SS
858 iv_len = crypto_blkcipher_ivsize(tfm);
859 if (iv_len) {
860 memset(&iv, 0xff, iv_len);
861 crypto_blkcipher_set_iv(tfm, iv, iv_len);
862 }
ebfd9bcf 863
d5dc3927
SS
864 if (sec)
865 ret = test_cipher_jiffies(&desc, enc, p, *b_size, sec);
866 else
867 ret = test_cipher_cycles(&desc, enc, p, *b_size);
ebfd9bcf 868
d5dc3927
SS
869 if (ret) {
870 printk("%s() failed flags=%x\n", e, desc.flags);
871 break;
872 }
873 b_size++;
874 i++;
875 } while (*b_size);
876 keysize++;
877 } while (*keysize);
ebfd9bcf
HW
878
879out:
cba83564 880 crypto_free_blkcipher(tfm);
ebfd9bcf
HW
881}
882
e9d41164
HX
883static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
884 char *out, int sec)
885{
886 struct scatterlist sg[1];
887 unsigned long start, end;
888 int bcount;
889 int ret;
890
a5a613a4
HX
891 sg_init_table(sg, 1);
892
e9d41164
HX
893 for (start = jiffies, end = start + sec * HZ, bcount = 0;
894 time_before(jiffies, end); bcount++) {
a5a613a4 895 sg_set_buf(sg, p, blen);
e9d41164
HX
896 ret = crypto_hash_digest(desc, sg, blen, out);
897 if (ret)
898 return ret;
899 }
900
901 printk("%6u opers/sec, %9lu bytes/sec\n",
902 bcount / sec, ((long)bcount * blen) / sec);
903
904 return 0;
905}
906
907static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
908 int plen, char *out, int sec)
e8057928
ML
909{
910 struct scatterlist sg[1];
911 unsigned long start, end;
912 int bcount, pcount;
e9d41164
HX
913 int ret;
914
915 if (plen == blen)
916 return test_hash_jiffies_digest(desc, p, blen, out, sec);
e8057928 917
a5a613a4
HX
918 sg_init_table(sg, 1);
919
e8057928
ML
920 for (start = jiffies, end = start + sec * HZ, bcount = 0;
921 time_before(jiffies, end); bcount++) {
e9d41164
HX
922 ret = crypto_hash_init(desc);
923 if (ret)
924 return ret;
e8057928 925 for (pcount = 0; pcount < blen; pcount += plen) {
a5a613a4 926 sg_set_buf(sg, p + pcount, plen);
e9d41164
HX
927 ret = crypto_hash_update(desc, sg, plen);
928 if (ret)
929 return ret;
e8057928
ML
930 }
931 /* we assume there is enough space in 'out' for the result */
e9d41164
HX
932 ret = crypto_hash_final(desc, out);
933 if (ret)
934 return ret;
e8057928
ML
935 }
936
937 printk("%6u opers/sec, %9lu bytes/sec\n",
938 bcount / sec, ((long)bcount * blen) / sec);
939
e9d41164
HX
940 return 0;
941}
942
943static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
944 char *out)
945{
946 struct scatterlist sg[1];
947 unsigned long cycles = 0;
948 int i;
949 int ret;
950
a5a613a4
HX
951 sg_init_table(sg, 1);
952
e9d41164
HX
953 local_bh_disable();
954 local_irq_disable();
955
956 /* Warm-up run. */
957 for (i = 0; i < 4; i++) {
a5a613a4 958 sg_set_buf(sg, p, blen);
e9d41164
HX
959 ret = crypto_hash_digest(desc, sg, blen, out);
960 if (ret)
961 goto out;
962 }
963
964 /* The real thing. */
965 for (i = 0; i < 8; i++) {
966 cycles_t start, end;
967
968 start = get_cycles();
969
a5a613a4 970 sg_set_buf(sg, p, blen);
e9d41164
HX
971 ret = crypto_hash_digest(desc, sg, blen, out);
972 if (ret)
973 goto out;
974
975 end = get_cycles();
976
977 cycles += end - start;
978 }
979
980out:
981 local_irq_enable();
982 local_bh_enable();
983
984 if (ret)
985 return ret;
986
987 printk("%6lu cycles/operation, %4lu cycles/byte\n",
988 cycles / 8, cycles / (8 * blen));
989
990 return 0;
e8057928
ML
991}
992
e9d41164
HX
993static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
994 int plen, char *out)
e8057928
ML
995{
996 struct scatterlist sg[1];
997 unsigned long cycles = 0;
998 int i, pcount;
e9d41164
HX
999 int ret;
1000
1001 if (plen == blen)
1002 return test_hash_cycles_digest(desc, p, blen, out);
e8057928 1003
a5a613a4
HX
1004 sg_init_table(sg, 1);
1005
e8057928
ML
1006 local_bh_disable();
1007 local_irq_disable();
1008
1009 /* Warm-up run. */
1010 for (i = 0; i < 4; i++) {
e9d41164
HX
1011 ret = crypto_hash_init(desc);
1012 if (ret)
1013 goto out;
e8057928 1014 for (pcount = 0; pcount < blen; pcount += plen) {
a5a613a4 1015 sg_set_buf(sg, p + pcount, plen);
e9d41164
HX
1016 ret = crypto_hash_update(desc, sg, plen);
1017 if (ret)
1018 goto out;
e8057928 1019 }
29059d12 1020 ret = crypto_hash_final(desc, out);
e9d41164
HX
1021 if (ret)
1022 goto out;
e8057928
ML
1023 }
1024
1025 /* The real thing. */
1026 for (i = 0; i < 8; i++) {
1027 cycles_t start, end;
1028
e8057928
ML
1029 start = get_cycles();
1030
e9d41164
HX
1031 ret = crypto_hash_init(desc);
1032 if (ret)
1033 goto out;
e8057928 1034 for (pcount = 0; pcount < blen; pcount += plen) {
a5a613a4 1035 sg_set_buf(sg, p + pcount, plen);
e9d41164
HX
1036 ret = crypto_hash_update(desc, sg, plen);
1037 if (ret)
1038 goto out;
e8057928 1039 }
e9d41164
HX
1040 ret = crypto_hash_final(desc, out);
1041 if (ret)
1042 goto out;
e8057928
ML
1043
1044 end = get_cycles();
1045
1046 cycles += end - start;
1047 }
1048
e9d41164 1049out:
e8057928
ML
1050 local_irq_enable();
1051 local_bh_enable();
1052
e9d41164
HX
1053 if (ret)
1054 return ret;
1055
e8057928
ML
1056 printk("%6lu cycles/operation, %4lu cycles/byte\n",
1057 cycles / 8, cycles / (8 * blen));
1058
e9d41164 1059 return 0;
e8057928
ML
1060}
1061
e9d41164
HX
1062static void test_hash_speed(char *algo, unsigned int sec,
1063 struct hash_speed *speed)
e8057928 1064{
e9d41164
HX
1065 struct crypto_hash *tfm;
1066 struct hash_desc desc;
e8057928
ML
1067 char output[1024];
1068 int i;
e9d41164 1069 int ret;
e8057928
ML
1070
1071 printk("\ntesting speed of %s\n", algo);
1072
e9d41164 1073 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
e8057928 1074
e9d41164
HX
1075 if (IS_ERR(tfm)) {
1076 printk("failed to load transform for %s: %ld\n", algo,
1077 PTR_ERR(tfm));
e8057928
ML
1078 return;
1079 }
1080
e9d41164
HX
1081 desc.tfm = tfm;
1082 desc.flags = 0;
1083
1084 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
e8057928 1085 printk("digestsize(%u) > outputbuffer(%zu)\n",
e9d41164 1086 crypto_hash_digestsize(tfm), sizeof(output));
e8057928
ML
1087 goto out;
1088 }
1089
1090 for (i = 0; speed[i].blen != 0; i++) {
1091 if (speed[i].blen > TVMEMSIZE) {
1092 printk("template (%u) too big for tvmem (%u)\n",
1093 speed[i].blen, TVMEMSIZE);
1094 goto out;
1095 }
1096
1097 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1098 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1099
1100 memset(tvmem, 0xff, speed[i].blen);
1101
1102 if (sec)
e9d41164
HX
1103 ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
1104 speed[i].plen, output, sec);
e8057928 1105 else
e9d41164
HX
1106 ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
1107 speed[i].plen, output);
1108
1109 if (ret) {
1110 printk("hashing failed ret=%d\n", ret);
1111 break;
1112 }
e8057928
ML
1113 }
1114
1115out:
e9d41164 1116 crypto_free_hash(tfm);
e8057928
ML
1117}
1118
91755a92
ZS
1119static void test_comp(char *algo, struct comp_testvec *ctemplate,
1120 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1da177e4
LT
1121{
1122 unsigned int i;
1123 char result[COMP_BUF_SIZE];
e4d5b79c 1124 struct crypto_comp *tfm;
1da177e4
LT
1125 unsigned int tsize;
1126
91755a92 1127 printk("\ntesting %s compression\n", algo);
1da177e4 1128
91755a92 1129 tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC);
7bc301e9 1130 if (IS_ERR(tfm)) {
91755a92 1131 printk("failed to load transform for %s\n", algo);
1da177e4
LT
1132 return;
1133 }
1134
91755a92 1135 for (i = 0; i < ctcount; i++) {
1da177e4 1136 int ilen, ret, dlen = COMP_BUF_SIZE;
ef2736fc 1137
1da177e4
LT
1138 printk("test %u:\n", i + 1);
1139 memset(result, 0, sizeof (result));
1140
562954d5
SS
1141 ilen = ctemplate[i].inlen;
1142 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1da177e4
LT
1143 ilen, result, &dlen);
1144 if (ret) {
1145 printk("fail: ret=%d\n", ret);
1146 continue;
1147 }
1148 hexdump(result, dlen);
1149 printk("%s (ratio %d:%d)\n",
562954d5 1150 memcmp(result, ctemplate[i].output, dlen) ? "fail" : "pass",
1da177e4
LT
1151 ilen, dlen);
1152 }
1153
91755a92 1154 printk("\ntesting %s decompression\n", algo);
1da177e4 1155
91755a92
ZS
1156 tsize = sizeof(struct comp_testvec);
1157 tsize *= dtcount;
1da177e4
LT
1158 if (tsize > TVMEMSIZE) {
1159 printk("template (%u) too big for tvmem (%u)\n", tsize,
1160 TVMEMSIZE);
1161 goto out;
1162 }
1163
91755a92 1164 for (i = 0; i < dtcount; i++) {
1da177e4 1165 int ilen, ret, dlen = COMP_BUF_SIZE;
ef2736fc 1166
1da177e4
LT
1167 printk("test %u:\n", i + 1);
1168 memset(result, 0, sizeof (result));
1169
562954d5
SS
1170 ilen = dtemplate[i].inlen;
1171 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1da177e4
LT
1172 ilen, result, &dlen);
1173 if (ret) {
1174 printk("fail: ret=%d\n", ret);
1175 continue;
1176 }
1177 hexdump(result, dlen);
1178 printk("%s (ratio %d:%d)\n",
562954d5 1179 memcmp(result, dtemplate[i].output, dlen) ? "fail" : "pass",
1da177e4
LT
1180 ilen, dlen);
1181 }
1182out:
e4d5b79c 1183 crypto_free_comp(tfm);
1da177e4
LT
1184}
1185
ef2736fc 1186static void test_available(void)
1da177e4
LT
1187{
1188 char **name = check;
ef2736fc 1189
1da177e4
LT
1190 while (*name) {
1191 printk("alg %s ", *name);
6158efc0 1192 printk(crypto_has_alg(*name, 0, 0) ?
e4d5b79c 1193 "found\n" : "not found\n");
1da177e4 1194 name++;
ef2736fc 1195 }
1da177e4
LT
1196}
1197
ef2736fc 1198static void do_test(void)
1da177e4
LT
1199{
1200 switch (mode) {
1201
1202 case 0:
1203 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
ef2736fc 1204
1da177e4 1205 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
ef2736fc 1206
1da177e4 1207 //DES
cba83564
HX
1208 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1209 DES_ENC_TEST_VECTORS);
1210 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1211 DES_DEC_TEST_VECTORS);
1212 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1213 DES_CBC_ENC_TEST_VECTORS);
1214 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1215 DES_CBC_DEC_TEST_VECTORS);
ef2736fc 1216
1da177e4 1217 //DES3_EDE
cba83564
HX
1218 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1219 DES3_EDE_ENC_TEST_VECTORS);
1220 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1221 DES3_EDE_DEC_TEST_VECTORS);
ef2736fc 1222
1da177e4 1223 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
ef2736fc 1224
cd12fb90
JL
1225 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1226
1da177e4 1227 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
ef2736fc 1228
1da177e4 1229 //BLOWFISH
cba83564
HX
1230 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1231 BF_ENC_TEST_VECTORS);
1232 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1233 BF_DEC_TEST_VECTORS);
1234 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1235 BF_CBC_ENC_TEST_VECTORS);
1236 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1237 BF_CBC_DEC_TEST_VECTORS);
ef2736fc 1238
1da177e4 1239 //TWOFISH
cba83564
HX
1240 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1241 TF_ENC_TEST_VECTORS);
1242 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1243 TF_DEC_TEST_VECTORS);
1244 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1245 TF_CBC_ENC_TEST_VECTORS);
1246 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1247 TF_CBC_DEC_TEST_VECTORS);
ef2736fc 1248
1da177e4 1249 //SERPENT
cba83564
HX
1250 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1251 SERPENT_ENC_TEST_VECTORS);
1252 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1253 SERPENT_DEC_TEST_VECTORS);
ef2736fc 1254
1da177e4 1255 //TNEPRES
cba83564
HX
1256 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1257 TNEPRES_ENC_TEST_VECTORS);
1258 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1259 TNEPRES_DEC_TEST_VECTORS);
1da177e4
LT
1260
1261 //AES
cba83564
HX
1262 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1263 AES_ENC_TEST_VECTORS);
1264 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1265 AES_DEC_TEST_VECTORS);
1266 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1267 AES_CBC_ENC_TEST_VECTORS);
1268 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1269 AES_CBC_DEC_TEST_VECTORS);
f3d1044c
RS
1270 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1271 AES_LRW_ENC_TEST_VECTORS);
1272 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1273 AES_LRW_DEC_TEST_VECTORS);
f19f5111
RS
1274 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1275 AES_XTS_ENC_TEST_VECTORS);
1276 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1277 AES_XTS_DEC_TEST_VECTORS);
5311f248 1278 test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
23e353c8 1279 AES_CTR_ENC_TEST_VECTORS);
5311f248 1280 test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
23e353c8 1281 AES_CTR_DEC_TEST_VECTORS);
28db8e3e
MH
1282 test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
1283 AES_GCM_ENC_TEST_VECTORS);
1284 test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
1285 AES_GCM_DEC_TEST_VECTORS);
93cc74e0
JL
1286 test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
1287 AES_CCM_ENC_TEST_VECTORS);
1288 test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
1289 AES_CCM_DEC_TEST_VECTORS);
1da177e4
LT
1290
1291 //CAST5
cba83564
HX
1292 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1293 CAST5_ENC_TEST_VECTORS);
1294 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1295 CAST5_DEC_TEST_VECTORS);
ef2736fc 1296
1da177e4 1297 //CAST6
cba83564
HX
1298 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1299 CAST6_ENC_TEST_VECTORS);
1300 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1301 CAST6_DEC_TEST_VECTORS);
1da177e4
LT
1302
1303 //ARC4
cba83564
HX
1304 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1305 ARC4_ENC_TEST_VECTORS);
1306 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1307 ARC4_DEC_TEST_VECTORS);
1da177e4
LT
1308
1309 //TEA
cba83564
HX
1310 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1311 TEA_ENC_TEST_VECTORS);
1312 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1313 TEA_DEC_TEST_VECTORS);
1da177e4
LT
1314
1315
1316 //XTEA
cba83564
HX
1317 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1318 XTEA_ENC_TEST_VECTORS);
1319 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1320 XTEA_DEC_TEST_VECTORS);
1da177e4
LT
1321
1322 //KHAZAD
cba83564
HX
1323 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1324 KHAZAD_ENC_TEST_VECTORS);
1325 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1326 KHAZAD_DEC_TEST_VECTORS);
1da177e4
LT
1327
1328 //ANUBIS
cba83564
HX
1329 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1330 ANUBIS_ENC_TEST_VECTORS);
1331 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1332 ANUBIS_DEC_TEST_VECTORS);
1333 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1334 ANUBIS_CBC_ENC_TEST_VECTORS);
1335 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1336 ANUBIS_CBC_ENC_TEST_VECTORS);
1da177e4 1337
fb4f10ed 1338 //XETA
cba83564
HX
1339 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1340 XETA_ENC_TEST_VECTORS);
1341 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1342 XETA_DEC_TEST_VECTORS);
fb4f10ed 1343
90831639
DH
1344 //FCrypt
1345 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1346 FCRYPT_ENC_TEST_VECTORS);
1347 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1348 FCRYPT_DEC_TEST_VECTORS);
1349
02ab5a70
NT
1350 //CAMELLIA
1351 test_cipher("ecb(camellia)", ENCRYPT,
1352 camellia_enc_tv_template,
1353 CAMELLIA_ENC_TEST_VECTORS);
1354 test_cipher("ecb(camellia)", DECRYPT,
1355 camellia_dec_tv_template,
1356 CAMELLIA_DEC_TEST_VECTORS);
1357 test_cipher("cbc(camellia)", ENCRYPT,
1358 camellia_cbc_enc_tv_template,
1359 CAMELLIA_CBC_ENC_TEST_VECTORS);
1360 test_cipher("cbc(camellia)", DECRYPT,
1361 camellia_cbc_dec_tv_template,
1362 CAMELLIA_CBC_DEC_TEST_VECTORS);
1363
e2ee95b8
HSC
1364 //SEED
1365 test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template,
1366 SEED_ENC_TEST_VECTORS);
1367 test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
1368 SEED_DEC_TEST_VECTORS);
1369
76cb9521
KC
1370 //CTS
1371 test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
1372 CTS_MODE_ENC_TEST_VECTORS);
1373 test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
1374 CTS_MODE_DEC_TEST_VECTORS);
1375
1da177e4
LT
1376 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1377 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1378 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1379 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1380 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1381 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1382 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1383 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
91755a92
ZS
1384 test_comp("deflate", deflate_comp_tv_template,
1385 deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
1386 DEFLATE_DECOMP_TEST_VECTORS);
0b77abb3
ZS
1387 test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
1388 LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
c907ee76 1389 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
e9d41164
HX
1390 test_hash("hmac(md5)", hmac_md5_tv_template,
1391 HMAC_MD5_TEST_VECTORS);
1392 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1393 HMAC_SHA1_TEST_VECTORS);
cd12fb90
JL
1394 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1395 HMAC_SHA224_TEST_VECTORS);
e9d41164
HX
1396 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1397 HMAC_SHA256_TEST_VECTORS);
a28091ae
AD
1398 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1399 HMAC_SHA384_TEST_VECTORS);
1400 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1401 HMAC_SHA512_TEST_VECTORS);
1da177e4 1402
5b2becf5
KM
1403 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1404 XCBC_AES_TEST_VECTORS);
1405
1da177e4
LT
1406 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1407 break;
1408
1409 case 1:
1410 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1411 break;
1412
1413 case 2:
1414 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1415 break;
1416
1417 case 3:
cba83564
HX
1418 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1419 DES_ENC_TEST_VECTORS);
1420 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1421 DES_DEC_TEST_VECTORS);
1422 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1423 DES_CBC_ENC_TEST_VECTORS);
1424 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1425 DES_CBC_DEC_TEST_VECTORS);
1da177e4
LT
1426 break;
1427
1428 case 4:
cba83564
HX
1429 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1430 DES3_EDE_ENC_TEST_VECTORS);
1431 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1432 DES3_EDE_DEC_TEST_VECTORS);
1da177e4
LT
1433 break;
1434
1435 case 5:
1436 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1437 break;
ef2736fc 1438
1da177e4
LT
1439 case 6:
1440 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1441 break;
ef2736fc 1442
1da177e4 1443 case 7:
cba83564
HX
1444 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1445 BF_ENC_TEST_VECTORS);
1446 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1447 BF_DEC_TEST_VECTORS);
1448 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1449 BF_CBC_ENC_TEST_VECTORS);
1450 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1451 BF_CBC_DEC_TEST_VECTORS);
1da177e4
LT
1452 break;
1453
1454 case 8:
cba83564
HX
1455 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1456 TF_ENC_TEST_VECTORS);
1457 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1458 TF_DEC_TEST_VECTORS);
1459 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1460 TF_CBC_ENC_TEST_VECTORS);
1461 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1462 TF_CBC_DEC_TEST_VECTORS);
1da177e4 1463 break;
ef2736fc 1464
1da177e4 1465 case 9:
cba83564
HX
1466 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1467 SERPENT_ENC_TEST_VECTORS);
1468 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1469 SERPENT_DEC_TEST_VECTORS);
1da177e4
LT
1470 break;
1471
1472 case 10:
cba83564
HX
1473 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1474 AES_ENC_TEST_VECTORS);
1475 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1476 AES_DEC_TEST_VECTORS);
1477 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1478 AES_CBC_ENC_TEST_VECTORS);
1479 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1480 AES_CBC_DEC_TEST_VECTORS);
f3d1044c
RS
1481 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1482 AES_LRW_ENC_TEST_VECTORS);
1483 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1484 AES_LRW_DEC_TEST_VECTORS);
f19f5111
RS
1485 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1486 AES_XTS_ENC_TEST_VECTORS);
1487 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1488 AES_XTS_DEC_TEST_VECTORS);
5311f248 1489 test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
23e353c8 1490 AES_CTR_ENC_TEST_VECTORS);
5311f248 1491 test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
23e353c8 1492 AES_CTR_DEC_TEST_VECTORS);
1da177e4
LT
1493 break;
1494
1495 case 11:
1496 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1497 break;
ef2736fc 1498
1da177e4
LT
1499 case 12:
1500 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1501 break;
1502
1503 case 13:
91755a92
ZS
1504 test_comp("deflate", deflate_comp_tv_template,
1505 deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
1506 DEFLATE_DECOMP_TEST_VECTORS);
1da177e4
LT
1507 break;
1508
1509 case 14:
cba83564
HX
1510 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1511 CAST5_ENC_TEST_VECTORS);
1512 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1513 CAST5_DEC_TEST_VECTORS);
1da177e4
LT
1514 break;
1515
1516 case 15:
cba83564
HX
1517 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1518 CAST6_ENC_TEST_VECTORS);
1519 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1520 CAST6_DEC_TEST_VECTORS);
1da177e4
LT
1521 break;
1522
1523 case 16:
cba83564
HX
1524 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1525 ARC4_ENC_TEST_VECTORS);
1526 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1527 ARC4_DEC_TEST_VECTORS);
1da177e4
LT
1528 break;
1529
1530 case 17:
1531 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1532 break;
1533
1534 case 18:
c907ee76 1535 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1da177e4
LT
1536 break;
1537
1538 case 19:
cba83564
HX
1539 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1540 TEA_ENC_TEST_VECTORS);
1541 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1542 TEA_DEC_TEST_VECTORS);
1da177e4
LT
1543 break;
1544
1545 case 20:
cba83564
HX
1546 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1547 XTEA_ENC_TEST_VECTORS);
1548 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1549 XTEA_DEC_TEST_VECTORS);
1da177e4
LT
1550 break;
1551
1552 case 21:
cba83564
HX
1553 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1554 KHAZAD_ENC_TEST_VECTORS);
1555 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1556 KHAZAD_DEC_TEST_VECTORS);
1da177e4
LT
1557 break;
1558
1559 case 22:
1560 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1561 break;
1562
1563 case 23:
1564 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1565 break;
1566
1567 case 24:
1568 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1569 break;
1570
1571 case 25:
cba83564
HX
1572 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1573 TNEPRES_ENC_TEST_VECTORS);
1574 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1575 TNEPRES_DEC_TEST_VECTORS);
1da177e4
LT
1576 break;
1577
1578 case 26:
cba83564
HX
1579 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1580 ANUBIS_ENC_TEST_VECTORS);
1581 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1582 ANUBIS_DEC_TEST_VECTORS);
1583 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1584 ANUBIS_CBC_ENC_TEST_VECTORS);
1585 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1586 ANUBIS_CBC_ENC_TEST_VECTORS);
1da177e4
LT
1587 break;
1588
1589 case 27:
1590 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1591 break;
1592
1593 case 28:
1594
1595 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1596 break;
1597
1598 case 29:
1599 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1600 break;
2998db37 1601
fb4f10ed 1602 case 30:
cba83564
HX
1603 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1604 XETA_ENC_TEST_VECTORS);
1605 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1606 XETA_DEC_TEST_VECTORS);
fb4f10ed 1607 break;
1da177e4 1608
90831639
DH
1609 case 31:
1610 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1611 FCRYPT_ENC_TEST_VECTORS);
1612 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1613 FCRYPT_DEC_TEST_VECTORS);
1614 break;
1615
02ab5a70
NT
1616 case 32:
1617 test_cipher("ecb(camellia)", ENCRYPT,
1618 camellia_enc_tv_template,
1619 CAMELLIA_ENC_TEST_VECTORS);
1620 test_cipher("ecb(camellia)", DECRYPT,
1621 camellia_dec_tv_template,
1622 CAMELLIA_DEC_TEST_VECTORS);
1623 test_cipher("cbc(camellia)", ENCRYPT,
1624 camellia_cbc_enc_tv_template,
1625 CAMELLIA_CBC_ENC_TEST_VECTORS);
1626 test_cipher("cbc(camellia)", DECRYPT,
1627 camellia_cbc_dec_tv_template,
1628 CAMELLIA_CBC_DEC_TEST_VECTORS);
1629 break;
cd12fb90
JL
1630 case 33:
1631 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1632 break;
02ab5a70 1633
2407d608
TSH
1634 case 34:
1635 test_cipher("salsa20", ENCRYPT,
1636 salsa20_stream_enc_tv_template,
1637 SALSA20_STREAM_ENC_TEST_VECTORS);
1638 break;
1639
8df213d9
HX
1640 case 35:
1641 test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
1642 AES_GCM_ENC_TEST_VECTORS);
1643 test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
1644 AES_GCM_DEC_TEST_VECTORS);
1645 break;
1646
0b77abb3
ZS
1647 case 36:
1648 test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
1649 LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
1650 break;
1651
93cc74e0
JL
1652 case 37:
1653 test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
1654 AES_CCM_ENC_TEST_VECTORS);
1655 test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
1656 AES_CCM_DEC_TEST_VECTORS);
1657 break;
1658
76cb9521
KC
1659 case 38:
1660 test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
1661 CTS_MODE_ENC_TEST_VECTORS);
1662 test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
1663 CTS_MODE_DEC_TEST_VECTORS);
1664 break;
1665
fd4adf1a
AKR
1666 case 39:
1667 test_hash("rmd128", rmd128_tv_template, RMD128_TEST_VECTORS);
1668 break;
1669
1670 case 40:
1671 test_hash("rmd160", rmd160_tv_template, RMD160_TEST_VECTORS);
1672 break;
1673
2998db37
AKR
1674 case 41:
1675 test_hash("rmd256", rmd256_tv_template, RMD256_TEST_VECTORS);
1676 break;
1677
1678 case 42:
1679 test_hash("rmd320", rmd320_tv_template, RMD320_TEST_VECTORS);
1680 break;
1681
1da177e4 1682 case 100:
e9d41164
HX
1683 test_hash("hmac(md5)", hmac_md5_tv_template,
1684 HMAC_MD5_TEST_VECTORS);
1da177e4 1685 break;
ef2736fc 1686
1da177e4 1687 case 101:
e9d41164
HX
1688 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1689 HMAC_SHA1_TEST_VECTORS);
1da177e4 1690 break;
ef2736fc 1691
1da177e4 1692 case 102:
e9d41164
HX
1693 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1694 HMAC_SHA256_TEST_VECTORS);
1da177e4
LT
1695 break;
1696
a28091ae
AD
1697 case 103:
1698 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1699 HMAC_SHA384_TEST_VECTORS);
1700 break;
1701
1702 case 104:
1703 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1704 HMAC_SHA512_TEST_VECTORS);
1705 break;
38ed9ab2 1706
cd12fb90
JL
1707 case 105:
1708 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1709 HMAC_SHA224_TEST_VECTORS);
1710 break;
1da177e4 1711
38ed9ab2
HX
1712 case 106:
1713 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1714 XCBC_AES_TEST_VECTORS);
1715 break;
1716
fd4adf1a
AKR
1717 case 107:
1718 test_hash("hmac(rmd128)", hmac_rmd128_tv_template,
1719 HMAC_RMD128_TEST_VECTORS);
1720 break;
1721
1722 case 108:
1723 test_hash("hmac(rmd160)", hmac_rmd160_tv_template,
1724 HMAC_RMD160_TEST_VECTORS);
1725 break;
1726
ebfd9bcf 1727 case 200:
cba83564 1728 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
477035c2 1729 speed_template_16_24_32);
cba83564 1730 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
477035c2 1731 speed_template_16_24_32);
cba83564 1732 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
477035c2 1733 speed_template_16_24_32);
cba83564 1734 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
477035c2 1735 speed_template_16_24_32);
f3d1044c 1736 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
477035c2 1737 speed_template_32_40_48);
f3d1044c 1738 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
477035c2 1739 speed_template_32_40_48);
f19f5111 1740 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
477035c2 1741 speed_template_32_48_64);
f19f5111 1742 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
477035c2 1743 speed_template_32_48_64);
ebfd9bcf
HW
1744 break;
1745
1746 case 201:
cba83564 1747 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
477035c2
SS
1748 des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
1749 speed_template_24);
cba83564 1750 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
477035c2
SS
1751 des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
1752 speed_template_24);
cba83564 1753 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
477035c2
SS
1754 des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
1755 speed_template_24);
cba83564 1756 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
477035c2
SS
1757 des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
1758 speed_template_24);
ebfd9bcf
HW
1759 break;
1760
1761 case 202:
cba83564 1762 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
477035c2 1763 speed_template_16_24_32);
cba83564 1764 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
477035c2 1765 speed_template_16_24_32);
cba83564 1766 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
477035c2 1767 speed_template_16_24_32);
cba83564 1768 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
477035c2 1769 speed_template_16_24_32);
ebfd9bcf
HW
1770 break;
1771
1772 case 203:
cba83564 1773 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
477035c2 1774 speed_template_8_32);
cba83564 1775 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
477035c2 1776 speed_template_8_32);
cba83564 1777 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
477035c2 1778 speed_template_8_32);
cba83564 1779 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
477035c2 1780 speed_template_8_32);
ebfd9bcf
HW
1781 break;
1782
1783 case 204:
cba83564 1784 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
477035c2 1785 speed_template_8);
cba83564 1786 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
477035c2 1787 speed_template_8);
cba83564 1788 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
477035c2 1789 speed_template_8);
cba83564 1790 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
477035c2 1791 speed_template_8);
ebfd9bcf
HW
1792 break;
1793
02ab5a70
NT
1794 case 205:
1795 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
477035c2 1796 speed_template_16_24_32);
02ab5a70 1797 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
477035c2 1798 speed_template_16_24_32);
02ab5a70 1799 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
477035c2 1800 speed_template_16_24_32);
02ab5a70 1801 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
477035c2 1802 speed_template_16_24_32);
02ab5a70
NT
1803 break;
1804
5de8f1b5
TSH
1805 case 206:
1806 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
477035c2 1807 speed_template_16_32);
5de8f1b5
TSH
1808 break;
1809
e8057928
ML
1810 case 300:
1811 /* fall through */
1812
1813 case 301:
e9d41164 1814 test_hash_speed("md4", sec, generic_hash_speed_template);
e8057928
ML
1815 if (mode > 300 && mode < 400) break;
1816
1817 case 302:
e9d41164 1818 test_hash_speed("md5", sec, generic_hash_speed_template);
e8057928
ML
1819 if (mode > 300 && mode < 400) break;
1820
1821 case 303:
e9d41164 1822 test_hash_speed("sha1", sec, generic_hash_speed_template);
e8057928
ML
1823 if (mode > 300 && mode < 400) break;
1824
1825 case 304:
e9d41164 1826 test_hash_speed("sha256", sec, generic_hash_speed_template);
e8057928
ML
1827 if (mode > 300 && mode < 400) break;
1828
1829 case 305:
e9d41164 1830 test_hash_speed("sha384", sec, generic_hash_speed_template);
e8057928
ML
1831 if (mode > 300 && mode < 400) break;
1832
1833 case 306:
e9d41164 1834 test_hash_speed("sha512", sec, generic_hash_speed_template);
e8057928
ML
1835 if (mode > 300 && mode < 400) break;
1836
1837 case 307:
e9d41164 1838 test_hash_speed("wp256", sec, generic_hash_speed_template);
e8057928
ML
1839 if (mode > 300 && mode < 400) break;
1840
1841 case 308:
e9d41164 1842 test_hash_speed("wp384", sec, generic_hash_speed_template);
e8057928
ML
1843 if (mode > 300 && mode < 400) break;
1844
1845 case 309:
e9d41164 1846 test_hash_speed("wp512", sec, generic_hash_speed_template);
e8057928
ML
1847 if (mode > 300 && mode < 400) break;
1848
1849 case 310:
e9d41164 1850 test_hash_speed("tgr128", sec, generic_hash_speed_template);
e8057928
ML
1851 if (mode > 300 && mode < 400) break;
1852
1853 case 311:
e9d41164 1854 test_hash_speed("tgr160", sec, generic_hash_speed_template);
e8057928
ML
1855 if (mode > 300 && mode < 400) break;
1856
1857 case 312:
e9d41164 1858 test_hash_speed("tgr192", sec, generic_hash_speed_template);
e8057928
ML
1859 if (mode > 300 && mode < 400) break;
1860
cd12fb90
JL
1861 case 313:
1862 test_hash_speed("sha224", sec, generic_hash_speed_template);
1863 if (mode > 300 && mode < 400) break;
1864
fd4adf1a
AKR
1865 case 314:
1866 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1867 if (mode > 300 && mode < 400) break;
1868
1869 case 315:
1870 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1871 if (mode > 300 && mode < 400) break;
1872
2998db37
AKR
1873 case 316:
1874 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1875 if (mode > 300 && mode < 400) break;
1876
1877 case 317:
1878 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1879 if (mode > 300 && mode < 400) break;
1880
e8057928
ML
1881 case 399:
1882 break;
1883
1da177e4
LT
1884 case 1000:
1885 test_available();
1886 break;
ef2736fc 1887
1da177e4
LT
1888 default:
1889 /* useful for debugging */
1890 printk("not testing anything\n");
1891 break;
1892 }
1893}
1894
3af5b90b 1895static int __init tcrypt_mod_init(void)
1da177e4 1896{
e3a4ea4f
MH
1897 int err = -ENOMEM;
1898
1da177e4
LT
1899 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1900 if (tvmem == NULL)
e3a4ea4f 1901 return err;
1da177e4
LT
1902
1903 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
e3a4ea4f
MH
1904 if (xbuf == NULL)
1905 goto err_free_tv;
1da177e4 1906
e3a4ea4f
MH
1907 axbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1908 if (axbuf == NULL)
1909 goto err_free_xbuf;
1da177e4 1910
e3a4ea4f 1911 do_test();
14fdf477
ML
1912
1913 /* We intentionaly return -EAGAIN to prevent keeping
1914 * the module. It does all its work from init()
1915 * and doesn't offer any runtime functionality
1916 * => we don't need it in the memory, do we?
1917 * -- mludvig
1918 */
e3a4ea4f
MH
1919 err = -EAGAIN;
1920
1921 kfree(axbuf);
1922 err_free_xbuf:
1923 kfree(xbuf);
1924 err_free_tv:
1925 kfree(tvmem);
1926
1927 return err;
1da177e4
LT
1928}
1929
1930/*
1931 * If an init function is provided, an exit function must also be provided
1932 * to allow module unload.
1933 */
3af5b90b 1934static void __exit tcrypt_mod_fini(void) { }
1da177e4 1935
3af5b90b
KB
1936module_init(tcrypt_mod_init);
1937module_exit(tcrypt_mod_fini);
1da177e4
LT
1938
1939module_param(mode, int, 0);
ebfd9bcf 1940module_param(sec, uint, 0);
6a17944c
HX
1941MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1942 "(defaults to zero which uses CPU cycles instead)");
1da177e4
LT
1943
1944MODULE_LICENSE("GPL");
1945MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1946MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");