blob: 1ab8c017a0113106c5e25ee2046d36531f9a9777 [file] [log] [blame]
Herbert Xuef2736f2005-06-22 13:26:03 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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>
Mikko Herranene3a4ea42007-11-26 22:12:07 +08009 * Copyright (c) 2007 Nokia Siemens Networks
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
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
Herbert Xuef2736f2005-06-22 13:26:03 -070013 * Software Foundation; either version 2 of the License, or (at your option)
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 * any later version.
15 *
Mikko Herranen28db8e32007-11-26 22:24:11 +080016 * 2007-11-13 Added GCM tests
Mikko Herranene3a4ea42007-11-26 22:12:07 +080017 * 2007-11-13 Added AEAD support
Jonathan Lynchcd12fb902007-11-10 20:08:25 +080018 * 2007-11-06 Added SHA-224 and SHA-224-HMAC tests
Andrew Donofrioa28091a2006-12-10 12:10:20 +110019 * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests
Harald Welteebfd9bc2005-06-22 13:27:23 -070020 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
21 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
22 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 */
24
Herbert Xucba83562006-08-13 08:26:09 +100025#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/module.h>
28#include <linux/mm.h>
29#include <linux/slab.h>
David Hardeman378f0582005-09-17 17:55:31 +100030#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/string.h>
32#include <linux/crypto.h>
33#include <linux/highmem.h>
34#include <linux/moduleparam.h>
Harald Welteebfd9bc2005-06-22 13:27:23 -070035#include <linux/jiffies.h>
Herbert Xu6a179442005-06-22 13:29:03 -070036#include <linux/timex.h>
37#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include "tcrypt.h"
39
40/*
41 * Need to kmalloc() memory for testing kmap().
42 */
Harald Welteebfd9bc2005-06-22 13:27:23 -070043#define TVMEMSIZE 16384
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#define XBUFSIZE 32768
45
46/*
47 * Indexes into the xbuf to simulate cross-page access.
48 */
49#define IDX1 37
50#define IDX2 32400
51#define IDX3 1
52#define IDX4 8193
53#define IDX5 22222
54#define IDX6 17101
55#define IDX7 27333
56#define IDX8 3000
57
58/*
59* Used by test_cipher()
60*/
61#define ENCRYPT 1
62#define DECRYPT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Herbert Xu6158efc2007-04-04 17:41:07 +100064struct tcrypt_result {
65 struct completion completion;
66 int err;
67};
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
70
Harald Welteebfd9bc2005-06-22 13:27:23 -070071/*
72 * Used by test_cipher_speed()
73 */
Herbert Xu6a179442005-06-22 13:29:03 -070074static unsigned int sec;
Harald Welteebfd9bc2005-06-22 13:27:23 -070075
Linus Torvalds1da177e2005-04-16 15:20:36 -070076static int mode;
77static char *xbuf;
Mikko Herranene3a4ea42007-11-26 22:12:07 +080078static char *axbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079static char *tvmem;
80
81static char *check[] = {
Jonathan Lynchcd12fb902007-11-10 20:08:25 +080082 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
83 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
84 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
Herbert Xuef2736f2005-06-22 13:26:03 -070085 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
David Howells90831632006-12-16 12:13:14 +110086 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
Zoltan Sogor0b77abb2007-12-07 16:53:23 +080087 "camellia", "seed", "salsa20", "lzo", NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070088};
89
Herbert Xuef2736f2005-06-22 13:26:03 -070090static void hexdump(unsigned char *buf, unsigned int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
Denis Chenga10e1192007-11-30 16:59:30 +110092 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
93 16, 1,
94 buf, len, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
Herbert Xu6158efc2007-04-04 17:41:07 +100097static void tcrypt_complete(struct crypto_async_request *req, int err)
98{
99 struct tcrypt_result *res = req->data;
100
101 if (err == -EINPROGRESS)
102 return;
103
104 res->err = err;
105 complete(&res->completion);
106}
107
Herbert Xuef2736f2005-06-22 13:26:03 -0700108static void test_hash(char *algo, struct hash_testvec *template,
109 unsigned int tcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
Herbert Xuef2736f2005-06-22 13:26:03 -0700111 unsigned int i, j, k, temp;
112 struct scatterlist sg[8];
113 char result[64];
Herbert Xue9d41162006-08-19 21:38:49 +1000114 struct crypto_hash *tfm;
115 struct hash_desc desc;
Herbert Xuef2736f2005-06-22 13:26:03 -0700116 struct hash_testvec *hash_tv;
117 unsigned int tsize;
Herbert Xue9d41162006-08-19 21:38:49 +1000118 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Herbert Xuef2736f2005-06-22 13:26:03 -0700120 printk("\ntesting %s\n", algo);
121
122 tsize = sizeof(struct hash_testvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 tsize *= tcount;
Herbert Xuef2736f2005-06-22 13:26:03 -0700124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 if (tsize > TVMEMSIZE) {
126 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
127 return;
128 }
129
130 memcpy(tvmem, template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700131 hash_tv = (void *)tvmem;
Herbert Xue9d41162006-08-19 21:38:49 +1000132
133 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
134 if (IS_ERR(tfm)) {
135 printk("failed to load transform for %s: %ld\n", algo,
136 PTR_ERR(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return;
138 }
139
Herbert Xue9d41162006-08-19 21:38:49 +1000140 desc.tfm = tfm;
141 desc.flags = 0;
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 for (i = 0; i < tcount; i++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700144 printk("test %u:\n", i + 1);
145 memset(result, 0, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
David S. Millerb7335882007-10-26 00:38:10 -0700147 sg_init_one(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Herbert Xue9d41162006-08-19 21:38:49 +1000149 if (hash_tv[i].ksize) {
150 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
151 hash_tv[i].ksize);
152 if (ret) {
153 printk("setkey() failed ret=%d\n", ret);
154 goto out;
155 }
156 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Herbert Xue9d41162006-08-19 21:38:49 +1000158 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, result);
159 if (ret) {
160 printk("digest () failed ret=%d\n", ret);
161 goto out;
162 }
163
164 hexdump(result, crypto_hash_digestsize(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 printk("%s\n",
Herbert Xuef2736f2005-06-22 13:26:03 -0700166 memcmp(result, hash_tv[i].digest,
Herbert Xue9d41162006-08-19 21:38:49 +1000167 crypto_hash_digestsize(tfm)) ?
Herbert Xuef2736f2005-06-22 13:26:03 -0700168 "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 }
170
Herbert Xuef2736f2005-06-22 13:26:03 -0700171 printk("testing %s across pages\n", algo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 /* setup the dummy buffer first */
Herbert Xuef2736f2005-06-22 13:26:03 -0700174 memset(xbuf, 0, XBUFSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176 j = 0;
177 for (i = 0; i < tcount; i++) {
178 if (hash_tv[i].np) {
179 j++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700180 printk("test %u:\n", j);
181 memset(result, 0, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183 temp = 0;
David S. Millerb7335882007-10-26 00:38:10 -0700184 sg_init_table(sg, hash_tv[i].np);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 for (k = 0; k < hash_tv[i].np; k++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700186 memcpy(&xbuf[IDX[k]],
187 hash_tv[i].plaintext + temp,
188 hash_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 temp += hash_tv[i].tap[k];
David Hardeman378f0582005-09-17 17:55:31 +1000190 sg_set_buf(&sg[k], &xbuf[IDX[k]],
191 hash_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 }
193
Herbert Xue9d41162006-08-19 21:38:49 +1000194 if (hash_tv[i].ksize) {
195 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
196 hash_tv[i].ksize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700197
Herbert Xue9d41162006-08-19 21:38:49 +1000198 if (ret) {
199 printk("setkey() failed ret=%d\n", ret);
200 goto out;
201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 }
203
Herbert Xue9d41162006-08-19 21:38:49 +1000204 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize,
205 result);
206 if (ret) {
207 printk("digest () failed ret=%d\n", ret);
208 goto out;
209 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700210
Herbert Xue9d41162006-08-19 21:38:49 +1000211 hexdump(result, crypto_hash_digestsize(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 printk("%s\n",
Herbert Xue9d41162006-08-19 21:38:49 +1000213 memcmp(result, hash_tv[i].digest,
214 crypto_hash_digestsize(tfm)) ?
Herbert Xuef2736f2005-06-22 13:26:03 -0700215 "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 }
217 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Herbert Xue9d41162006-08-19 21:38:49 +1000219out:
220 crypto_free_hash(tfm);
221}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800223static void test_aead(char *algo, int enc, struct aead_testvec *template,
224 unsigned int tcount)
225{
226 unsigned int ret, i, j, k, temp;
227 unsigned int tsize;
228 char *q;
229 struct crypto_aead *tfm;
230 char *key;
231 struct aead_testvec *aead_tv;
232 struct aead_request *req;
233 struct scatterlist sg[8];
234 struct scatterlist asg[8];
235 const char *e;
236 struct tcrypt_result result;
Herbert Xu6160b282007-12-04 19:17:50 +1100237 unsigned int authsize;
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800238
239 if (enc == ENCRYPT)
240 e = "encryption";
241 else
242 e = "decryption";
243
244 printk(KERN_INFO "\ntesting %s %s\n", algo, e);
245
246 tsize = sizeof(struct aead_testvec);
247 tsize *= tcount;
248
249 if (tsize > TVMEMSIZE) {
250 printk(KERN_INFO "template (%u) too big for tvmem (%u)\n",
251 tsize, TVMEMSIZE);
252 return;
253 }
254
255 memcpy(tvmem, template, tsize);
256 aead_tv = (void *)tvmem;
257
258 init_completion(&result.completion);
259
260 tfm = crypto_alloc_aead(algo, 0, 0);
261
262 if (IS_ERR(tfm)) {
263 printk(KERN_INFO "failed to load transform for %s: %ld\n",
264 algo, PTR_ERR(tfm));
265 return;
266 }
267
268 req = aead_request_alloc(tfm, GFP_KERNEL);
269 if (!req) {
270 printk(KERN_INFO "failed to allocate request for %s\n", algo);
271 goto out;
272 }
273
274 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
275 tcrypt_complete, &result);
276
277 for (i = 0, j = 0; i < tcount; i++) {
278 if (!aead_tv[i].np) {
279 printk(KERN_INFO "test %u (%d bit key):\n",
280 ++j, aead_tv[i].klen * 8);
281
282 crypto_aead_clear_flags(tfm, ~0);
283 if (aead_tv[i].wk)
284 crypto_aead_set_flags(
285 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
286 key = aead_tv[i].key;
287
288 ret = crypto_aead_setkey(tfm, key,
289 aead_tv[i].klen);
290 if (ret) {
291 printk(KERN_INFO "setkey() failed flags=%x\n",
292 crypto_aead_get_flags(tfm));
293
294 if (!aead_tv[i].fail)
295 goto out;
296 }
297
Joy Latten93cc74e2007-12-12 20:24:22 +0800298 authsize = abs(aead_tv[i].rlen - aead_tv[i].ilen);
299 ret = crypto_aead_setauthsize(tfm, authsize);
300 if (ret) {
301 printk(KERN_INFO
302 "failed to set authsize = %u\n",
303 authsize);
304 goto out;
305 }
306
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800307 sg_init_one(&sg[0], aead_tv[i].input,
Herbert Xu6160b282007-12-04 19:17:50 +1100308 aead_tv[i].ilen + (enc ? authsize : 0));
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800309
310 sg_init_one(&asg[0], aead_tv[i].assoc,
311 aead_tv[i].alen);
312
313 aead_request_set_crypt(req, sg, sg,
314 aead_tv[i].ilen,
315 aead_tv[i].iv);
316
317 aead_request_set_assoc(req, asg, aead_tv[i].alen);
318
Herbert Xu6160b282007-12-04 19:17:50 +1100319 ret = enc ?
320 crypto_aead_encrypt(req) :
321 crypto_aead_decrypt(req);
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800322
323 switch (ret) {
324 case 0:
325 break;
326 case -EINPROGRESS:
327 case -EBUSY:
328 ret = wait_for_completion_interruptible(
329 &result.completion);
330 if (!ret && !(ret = result.err)) {
331 INIT_COMPLETION(result.completion);
332 break;
333 }
334 /* fall through */
335 default:
336 printk(KERN_INFO "%s () failed err=%d\n",
337 e, -ret);
338 goto out;
339 }
340
341 q = kmap(sg_page(&sg[0])) + sg[0].offset;
342 hexdump(q, aead_tv[i].rlen);
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800343
344 printk(KERN_INFO "enc/dec: %s\n",
345 memcmp(q, aead_tv[i].result,
346 aead_tv[i].rlen) ? "fail" : "pass");
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800347 }
348 }
349
350 printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e);
351 memset(xbuf, 0, XBUFSIZE);
Herbert Xu2a999a32007-12-30 20:24:11 +1100352 memset(axbuf, 0, XBUFSIZE);
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800353
354 for (i = 0, j = 0; i < tcount; i++) {
355 if (aead_tv[i].np) {
356 printk(KERN_INFO "test %u (%d bit key):\n",
357 ++j, aead_tv[i].klen * 8);
358
359 crypto_aead_clear_flags(tfm, ~0);
360 if (aead_tv[i].wk)
361 crypto_aead_set_flags(
362 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
363 key = aead_tv[i].key;
364
365 ret = crypto_aead_setkey(tfm, key, aead_tv[i].klen);
366 if (ret) {
367 printk(KERN_INFO "setkey() failed flags=%x\n",
368 crypto_aead_get_flags(tfm));
369
370 if (!aead_tv[i].fail)
371 goto out;
372 }
373
374 sg_init_table(sg, aead_tv[i].np);
375 for (k = 0, temp = 0; k < aead_tv[i].np; k++) {
376 memcpy(&xbuf[IDX[k]],
377 aead_tv[i].input + temp,
378 aead_tv[i].tap[k]);
379 temp += aead_tv[i].tap[k];
380 sg_set_buf(&sg[k], &xbuf[IDX[k]],
381 aead_tv[i].tap[k]);
382 }
383
Joy Latten93cc74e2007-12-12 20:24:22 +0800384 authsize = abs(aead_tv[i].rlen - aead_tv[i].ilen);
385 ret = crypto_aead_setauthsize(tfm, authsize);
386 if (ret) {
387 printk(KERN_INFO
388 "failed to set authsize = %u\n",
389 authsize);
390 goto out;
391 }
392
Herbert Xu6160b282007-12-04 19:17:50 +1100393 if (enc)
394 sg[k - 1].length += authsize;
395
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800396 sg_init_table(asg, aead_tv[i].anp);
397 for (k = 0, temp = 0; k < aead_tv[i].anp; k++) {
398 memcpy(&axbuf[IDX[k]],
399 aead_tv[i].assoc + temp,
400 aead_tv[i].atap[k]);
401 temp += aead_tv[i].atap[k];
402 sg_set_buf(&asg[k], &axbuf[IDX[k]],
403 aead_tv[i].atap[k]);
404 }
405
406 aead_request_set_crypt(req, sg, sg,
407 aead_tv[i].ilen,
408 aead_tv[i].iv);
409
410 aead_request_set_assoc(req, asg, aead_tv[i].alen);
411
Herbert Xu6160b282007-12-04 19:17:50 +1100412 ret = enc ?
413 crypto_aead_encrypt(req) :
414 crypto_aead_decrypt(req);
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800415
416 switch (ret) {
417 case 0:
418 break;
419 case -EINPROGRESS:
420 case -EBUSY:
421 ret = wait_for_completion_interruptible(
422 &result.completion);
423 if (!ret && !(ret = result.err)) {
424 INIT_COMPLETION(result.completion);
425 break;
426 }
427 /* fall through */
428 default:
429 printk(KERN_INFO "%s () failed err=%d\n",
430 e, -ret);
431 goto out;
432 }
433
434 for (k = 0, temp = 0; k < aead_tv[i].np; k++) {
435 printk(KERN_INFO "page %u\n", k);
436 q = kmap(sg_page(&sg[k])) + sg[k].offset;
437 hexdump(q, aead_tv[i].tap[k]);
438 printk(KERN_INFO "%s\n",
439 memcmp(q, aead_tv[i].result + temp,
Herbert Xu6160b282007-12-04 19:17:50 +1100440 aead_tv[i].tap[k] -
441 (k < aead_tv[i].np - 1 || enc ?
442 0 : authsize)) ?
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800443 "fail" : "pass");
444
445 temp += aead_tv[i].tap[k];
446 }
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800447 }
448 }
449
450out:
451 crypto_free_aead(tfm);
452 aead_request_free(req);
453}
454
Herbert Xucba83562006-08-13 08:26:09 +1000455static void test_cipher(char *algo, int enc,
Herbert Xuef2736f2005-06-22 13:26:03 -0700456 struct cipher_testvec *template, unsigned int tcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457{
458 unsigned int ret, i, j, k, temp;
459 unsigned int tsize;
David Hardeman378f0582005-09-17 17:55:31 +1000460 char *q;
Herbert Xu6158efc2007-04-04 17:41:07 +1000461 struct crypto_ablkcipher *tfm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 char *key;
463 struct cipher_testvec *cipher_tv;
Herbert Xu6158efc2007-04-04 17:41:07 +1000464 struct ablkcipher_request *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 struct scatterlist sg[8];
Herbert Xucba83562006-08-13 08:26:09 +1000466 const char *e;
Herbert Xu6158efc2007-04-04 17:41:07 +1000467 struct tcrypt_result result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469 if (enc == ENCRYPT)
Herbert Xu3cc38162005-06-22 13:26:36 -0700470 e = "encryption";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 else
Herbert Xu3cc38162005-06-22 13:26:36 -0700472 e = "decryption";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Herbert Xucba83562006-08-13 08:26:09 +1000474 printk("\ntesting %s %s\n", algo, e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Herbert Xuef2736f2005-06-22 13:26:03 -0700476 tsize = sizeof (struct cipher_testvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 if (tsize > TVMEMSIZE) {
478 printk("template (%u) too big for tvmem (%u)\n", tsize,
479 TVMEMSIZE);
480 return;
481 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700482 cipher_tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Herbert Xu6158efc2007-04-04 17:41:07 +1000484 init_completion(&result.completion);
485
486 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
Herbert Xuef2736f2005-06-22 13:26:03 -0700487
Herbert Xucba83562006-08-13 08:26:09 +1000488 if (IS_ERR(tfm)) {
489 printk("failed to load transform for %s: %ld\n", algo,
490 PTR_ERR(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 return;
492 }
Herbert Xu6158efc2007-04-04 17:41:07 +1000493
494 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
495 if (!req) {
496 printk("failed to allocate request for %s\n", algo);
497 goto out;
498 }
499
500 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
501 tcrypt_complete, &result);
Herbert Xuef2736f2005-06-22 13:26:03 -0700502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 j = 0;
504 for (i = 0; i < tcount; i++) {
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100505 memcpy(cipher_tv, &template[i], tsize);
506 if (!(cipher_tv->np)) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700507 j++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 printk("test %u (%d bit key):\n",
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100509 j, cipher_tv->klen * 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Herbert Xu6158efc2007-04-04 17:41:07 +1000511 crypto_ablkcipher_clear_flags(tfm, ~0);
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100512 if (cipher_tv->wk)
Herbert Xu6158efc2007-04-04 17:41:07 +1000513 crypto_ablkcipher_set_flags(
Herbert Xucba83562006-08-13 08:26:09 +1000514 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100515 key = cipher_tv->key;
Herbert Xuef2736f2005-06-22 13:26:03 -0700516
Herbert Xu6158efc2007-04-04 17:41:07 +1000517 ret = crypto_ablkcipher_setkey(tfm, key,
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100518 cipher_tv->klen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000520 printk("setkey() failed flags=%x\n",
Herbert Xu6158efc2007-04-04 17:41:07 +1000521 crypto_ablkcipher_get_flags(tfm));
Herbert Xuef2736f2005-06-22 13:26:03 -0700522
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100523 if (!cipher_tv->fail)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 goto out;
Herbert Xuef2736f2005-06-22 13:26:03 -0700525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100527 sg_init_one(&sg[0], cipher_tv->input,
528 cipher_tv->ilen);
Herbert Xuef2736f2005-06-22 13:26:03 -0700529
Herbert Xu6158efc2007-04-04 17:41:07 +1000530 ablkcipher_request_set_crypt(req, sg, sg,
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100531 cipher_tv->ilen,
532 cipher_tv->iv);
Herbert Xuef2736f2005-06-22 13:26:03 -0700533
Herbert Xucba83562006-08-13 08:26:09 +1000534 ret = enc ?
Herbert Xu6158efc2007-04-04 17:41:07 +1000535 crypto_ablkcipher_encrypt(req) :
536 crypto_ablkcipher_decrypt(req);
Herbert Xuef2736f2005-06-22 13:26:03 -0700537
Herbert Xu6158efc2007-04-04 17:41:07 +1000538 switch (ret) {
539 case 0:
540 break;
541 case -EINPROGRESS:
542 case -EBUSY:
543 ret = wait_for_completion_interruptible(
544 &result.completion);
545 if (!ret && !((ret = result.err))) {
546 INIT_COMPLETION(result.completion);
547 break;
548 }
549 /* fall through */
550 default:
551 printk("%s () failed err=%d\n", e, -ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 goto out;
Herbert Xuef2736f2005-06-22 13:26:03 -0700553 }
554
Jens Axboe78c2f0b2007-10-22 19:40:16 +0200555 q = kmap(sg_page(&sg[0])) + sg[0].offset;
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100556 hexdump(q, cipher_tv->rlen);
Herbert Xuef2736f2005-06-22 13:26:03 -0700557
558 printk("%s\n",
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100559 memcmp(q, cipher_tv->result,
560 cipher_tv->rlen) ? "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 }
562 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700563
Herbert Xucba83562006-08-13 08:26:09 +1000564 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 memset(xbuf, 0, XBUFSIZE);
Herbert Xuef2736f2005-06-22 13:26:03 -0700566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 j = 0;
568 for (i = 0; i < tcount; i++) {
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100569 memcpy(cipher_tv, &template[i], tsize);
570 if (cipher_tv->np) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700571 j++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 printk("test %u (%d bit key):\n",
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100573 j, cipher_tv->klen * 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Herbert Xu6158efc2007-04-04 17:41:07 +1000575 crypto_ablkcipher_clear_flags(tfm, ~0);
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100576 if (cipher_tv->wk)
Herbert Xu6158efc2007-04-04 17:41:07 +1000577 crypto_ablkcipher_set_flags(
Herbert Xucba83562006-08-13 08:26:09 +1000578 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100579 key = cipher_tv->key;
Herbert Xuef2736f2005-06-22 13:26:03 -0700580
Herbert Xu6158efc2007-04-04 17:41:07 +1000581 ret = crypto_ablkcipher_setkey(tfm, key,
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100582 cipher_tv->klen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000584 printk("setkey() failed flags=%x\n",
Herbert Xu6158efc2007-04-04 17:41:07 +1000585 crypto_ablkcipher_get_flags(tfm));
Herbert Xuef2736f2005-06-22 13:26:03 -0700586
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100587 if (!cipher_tv->fail)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 goto out;
589 }
590
591 temp = 0;
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100592 sg_init_table(sg, cipher_tv->np);
593 for (k = 0; k < cipher_tv->np; k++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700594 memcpy(&xbuf[IDX[k]],
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100595 cipher_tv->input + temp,
596 cipher_tv->tap[k]);
597 temp += cipher_tv->tap[k];
David Hardeman378f0582005-09-17 17:55:31 +1000598 sg_set_buf(&sg[k], &xbuf[IDX[k]],
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100599 cipher_tv->tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700601
Herbert Xu6158efc2007-04-04 17:41:07 +1000602 ablkcipher_request_set_crypt(req, sg, sg,
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100603 cipher_tv->ilen,
604 cipher_tv->iv);
Herbert Xuef2736f2005-06-22 13:26:03 -0700605
Herbert Xucba83562006-08-13 08:26:09 +1000606 ret = enc ?
Herbert Xu6158efc2007-04-04 17:41:07 +1000607 crypto_ablkcipher_encrypt(req) :
608 crypto_ablkcipher_decrypt(req);
Herbert Xuef2736f2005-06-22 13:26:03 -0700609
Herbert Xu6158efc2007-04-04 17:41:07 +1000610 switch (ret) {
611 case 0:
612 break;
613 case -EINPROGRESS:
614 case -EBUSY:
615 ret = wait_for_completion_interruptible(
616 &result.completion);
617 if (!ret && !((ret = result.err))) {
618 INIT_COMPLETION(result.completion);
619 break;
620 }
621 /* fall through */
622 default:
623 printk("%s () failed err=%d\n", e, -ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 goto out;
625 }
626
627 temp = 0;
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100628 for (k = 0; k < cipher_tv->np; k++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 printk("page %u\n", k);
Jens Axboe78c2f0b2007-10-22 19:40:16 +0200630 q = kmap(sg_page(&sg[k])) + sg[k].offset;
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100631 hexdump(q, cipher_tv->tap[k]);
Herbert Xuef2736f2005-06-22 13:26:03 -0700632 printk("%s\n",
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100633 memcmp(q, cipher_tv->result + temp,
634 cipher_tv->tap[k]) ? "fail" :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 "pass");
Tan Swee Heng6d1a69d2007-11-30 00:30:11 +1100636 temp += cipher_tv->tap[k];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 }
638 }
639 }
640
641out:
Herbert Xu6158efc2007-04-04 17:41:07 +1000642 crypto_free_ablkcipher(tfm);
643 ablkcipher_request_free(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644}
645
Herbert Xucba83562006-08-13 08:26:09 +1000646static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
Herbert Xu6a179442005-06-22 13:29:03 -0700647 int blen, int sec)
648{
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000649 struct scatterlist sg[1];
Herbert Xu6a179442005-06-22 13:29:03 -0700650 unsigned long start, end;
651 int bcount;
652 int ret;
653
David S. Millerb7335882007-10-26 00:38:10 -0700654 sg_init_one(sg, p, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700655
656 for (start = jiffies, end = start + sec * HZ, bcount = 0;
657 time_before(jiffies, end); bcount++) {
658 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000659 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700660 else
Herbert Xucba83562006-08-13 08:26:09 +1000661 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700662
663 if (ret)
664 return ret;
665 }
666
667 printk("%d operations in %d seconds (%ld bytes)\n",
668 bcount, sec, (long)bcount * blen);
669 return 0;
670}
671
Herbert Xucba83562006-08-13 08:26:09 +1000672static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
Herbert Xu6a179442005-06-22 13:29:03 -0700673 int blen)
674{
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000675 struct scatterlist sg[1];
Herbert Xu6a179442005-06-22 13:29:03 -0700676 unsigned long cycles = 0;
677 int ret = 0;
678 int i;
679
David S. Millerb7335882007-10-26 00:38:10 -0700680 sg_init_one(sg, p, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700681
682 local_bh_disable();
683 local_irq_disable();
684
685 /* Warm-up run. */
686 for (i = 0; i < 4; i++) {
687 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000688 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700689 else
Herbert Xucba83562006-08-13 08:26:09 +1000690 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700691
692 if (ret)
693 goto out;
694 }
695
696 /* The real thing. */
697 for (i = 0; i < 8; i++) {
698 cycles_t start, end;
699
700 start = get_cycles();
701 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000702 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700703 else
Herbert Xucba83562006-08-13 08:26:09 +1000704 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700705 end = get_cycles();
706
707 if (ret)
708 goto out;
709
710 cycles += end - start;
711 }
712
713out:
714 local_irq_enable();
715 local_bh_enable();
716
717 if (ret == 0)
718 printk("1 operation in %lu cycles (%d bytes)\n",
719 (cycles + 4) / 8, blen);
720
721 return ret;
722}
723
Herbert Xucba83562006-08-13 08:26:09 +1000724static void test_cipher_speed(char *algo, int enc, unsigned int sec,
Herbert Xudce907c2005-06-22 13:27:51 -0700725 struct cipher_testvec *template,
726 unsigned int tcount, struct cipher_speed *speed)
Harald Welteebfd9bc2005-06-22 13:27:23 -0700727{
Herbert Xudce907c2005-06-22 13:27:51 -0700728 unsigned int ret, i, j, iv_len;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700729 unsigned char *key, *p, iv[128];
Herbert Xucba83562006-08-13 08:26:09 +1000730 struct crypto_blkcipher *tfm;
731 struct blkcipher_desc desc;
732 const char *e;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700733
734 if (enc == ENCRYPT)
735 e = "encryption";
736 else
737 e = "decryption";
Harald Welteebfd9bc2005-06-22 13:27:23 -0700738
Herbert Xucba83562006-08-13 08:26:09 +1000739 printk("\ntesting speed of %s %s\n", algo, e);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700740
Herbert Xucba83562006-08-13 08:26:09 +1000741 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700742
Herbert Xucba83562006-08-13 08:26:09 +1000743 if (IS_ERR(tfm)) {
744 printk("failed to load transform for %s: %ld\n", algo,
745 PTR_ERR(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700746 return;
747 }
Herbert Xucba83562006-08-13 08:26:09 +1000748 desc.tfm = tfm;
749 desc.flags = 0;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700750
751 for (i = 0; speed[i].klen != 0; i++) {
752 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
753 printk("template (%u) too big for tvmem (%u)\n",
754 speed[i].blen + speed[i].klen, TVMEMSIZE);
755 goto out;
756 }
757
758 printk("test %u (%d bit key, %d byte blocks): ", i,
759 speed[i].klen * 8, speed[i].blen);
760
761 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
762
763 /* set key, plain text and IV */
764 key = (unsigned char *)tvmem;
Herbert Xudce907c2005-06-22 13:27:51 -0700765 for (j = 0; j < tcount; j++) {
766 if (template[j].klen == speed[i].klen) {
767 key = template[j].key;
768 break;
769 }
770 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700771 p = (unsigned char *)tvmem + speed[i].klen;
772
Herbert Xucba83562006-08-13 08:26:09 +1000773 ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700774 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000775 printk("setkey() failed flags=%x\n",
776 crypto_blkcipher_get_flags(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700777 goto out;
778 }
779
Herbert Xucba83562006-08-13 08:26:09 +1000780 iv_len = crypto_blkcipher_ivsize(tfm);
781 if (iv_len) {
Harald Welteebfd9bc2005-06-22 13:27:23 -0700782 memset(&iv, 0xff, iv_len);
Herbert Xucba83562006-08-13 08:26:09 +1000783 crypto_blkcipher_set_iv(tfm, iv, iv_len);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700784 }
785
Herbert Xu6a179442005-06-22 13:29:03 -0700786 if (sec)
Herbert Xucba83562006-08-13 08:26:09 +1000787 ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen,
Herbert Xu6a179442005-06-22 13:29:03 -0700788 sec);
789 else
Herbert Xucba83562006-08-13 08:26:09 +1000790 ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700791
Herbert Xu6a179442005-06-22 13:29:03 -0700792 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000793 printk("%s() failed flags=%x\n", e, desc.flags);
Herbert Xu6a179442005-06-22 13:29:03 -0700794 break;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700795 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700796 }
797
798out:
Herbert Xucba83562006-08-13 08:26:09 +1000799 crypto_free_blkcipher(tfm);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700800}
801
Herbert Xue9d41162006-08-19 21:38:49 +1000802static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
803 char *out, int sec)
Michal Ludvige8057922006-05-30 22:04:19 +1000804{
805 struct scatterlist sg[1];
806 unsigned long start, end;
Herbert Xue9d41162006-08-19 21:38:49 +1000807 int bcount;
808 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000809
Herbert Xua5a613a2007-10-27 00:51:21 -0700810 sg_init_table(sg, 1);
811
Michal Ludvige8057922006-05-30 22:04:19 +1000812 for (start = jiffies, end = start + sec * HZ, bcount = 0;
813 time_before(jiffies, end); bcount++) {
Herbert Xua5a613a2007-10-27 00:51:21 -0700814 sg_set_buf(sg, p, blen);
Herbert Xue9d41162006-08-19 21:38:49 +1000815 ret = crypto_hash_digest(desc, sg, blen, out);
816 if (ret)
817 return ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000818 }
819
820 printk("%6u opers/sec, %9lu bytes/sec\n",
821 bcount / sec, ((long)bcount * blen) / sec);
822
Herbert Xue9d41162006-08-19 21:38:49 +1000823 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000824}
825
Herbert Xue9d41162006-08-19 21:38:49 +1000826static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
827 int plen, char *out, int sec)
828{
829 struct scatterlist sg[1];
830 unsigned long start, end;
831 int bcount, pcount;
832 int ret;
833
834 if (plen == blen)
835 return test_hash_jiffies_digest(desc, p, blen, out, sec);
836
Herbert Xua5a613a2007-10-27 00:51:21 -0700837 sg_init_table(sg, 1);
838
Herbert Xue9d41162006-08-19 21:38:49 +1000839 for (start = jiffies, end = start + sec * HZ, bcount = 0;
840 time_before(jiffies, end); bcount++) {
841 ret = crypto_hash_init(desc);
842 if (ret)
843 return ret;
844 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xua5a613a2007-10-27 00:51:21 -0700845 sg_set_buf(sg, p + pcount, plen);
Herbert Xue9d41162006-08-19 21:38:49 +1000846 ret = crypto_hash_update(desc, sg, plen);
847 if (ret)
848 return ret;
849 }
850 /* we assume there is enough space in 'out' for the result */
851 ret = crypto_hash_final(desc, out);
852 if (ret)
853 return ret;
854 }
855
856 printk("%6u opers/sec, %9lu bytes/sec\n",
857 bcount / sec, ((long)bcount * blen) / sec);
858
859 return 0;
860}
861
862static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
863 char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000864{
865 struct scatterlist sg[1];
866 unsigned long cycles = 0;
Herbert Xue9d41162006-08-19 21:38:49 +1000867 int i;
868 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000869
Herbert Xua5a613a2007-10-27 00:51:21 -0700870 sg_init_table(sg, 1);
871
Michal Ludvige8057922006-05-30 22:04:19 +1000872 local_bh_disable();
873 local_irq_disable();
874
875 /* Warm-up run. */
876 for (i = 0; i < 4; i++) {
Herbert Xua5a613a2007-10-27 00:51:21 -0700877 sg_set_buf(sg, p, blen);
Herbert Xue9d41162006-08-19 21:38:49 +1000878 ret = crypto_hash_digest(desc, sg, blen, out);
879 if (ret)
880 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000881 }
882
883 /* The real thing. */
884 for (i = 0; i < 8; i++) {
885 cycles_t start, end;
886
Michal Ludvige8057922006-05-30 22:04:19 +1000887 start = get_cycles();
888
Herbert Xua5a613a2007-10-27 00:51:21 -0700889 sg_set_buf(sg, p, blen);
Herbert Xue9d41162006-08-19 21:38:49 +1000890 ret = crypto_hash_digest(desc, sg, blen, out);
891 if (ret)
892 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000893
894 end = get_cycles();
895
896 cycles += end - start;
897 }
898
Herbert Xue9d41162006-08-19 21:38:49 +1000899out:
Michal Ludvige8057922006-05-30 22:04:19 +1000900 local_irq_enable();
901 local_bh_enable();
902
Herbert Xue9d41162006-08-19 21:38:49 +1000903 if (ret)
904 return ret;
905
Michal Ludvige8057922006-05-30 22:04:19 +1000906 printk("%6lu cycles/operation, %4lu cycles/byte\n",
907 cycles / 8, cycles / (8 * blen));
908
Herbert Xue9d41162006-08-19 21:38:49 +1000909 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000910}
911
Herbert Xue9d41162006-08-19 21:38:49 +1000912static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
913 int plen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000914{
Herbert Xue9d41162006-08-19 21:38:49 +1000915 struct scatterlist sg[1];
916 unsigned long cycles = 0;
917 int i, pcount;
918 int ret;
919
920 if (plen == blen)
921 return test_hash_cycles_digest(desc, p, blen, out);
922
Herbert Xua5a613a2007-10-27 00:51:21 -0700923 sg_init_table(sg, 1);
924
Herbert Xue9d41162006-08-19 21:38:49 +1000925 local_bh_disable();
926 local_irq_disable();
927
928 /* Warm-up run. */
929 for (i = 0; i < 4; i++) {
930 ret = crypto_hash_init(desc);
931 if (ret)
932 goto out;
933 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xua5a613a2007-10-27 00:51:21 -0700934 sg_set_buf(sg, p + pcount, plen);
Herbert Xue9d41162006-08-19 21:38:49 +1000935 ret = crypto_hash_update(desc, sg, plen);
936 if (ret)
937 goto out;
938 }
Herbert Xu29059d12007-05-18 16:25:19 +1000939 ret = crypto_hash_final(desc, out);
Herbert Xue9d41162006-08-19 21:38:49 +1000940 if (ret)
941 goto out;
942 }
943
944 /* The real thing. */
945 for (i = 0; i < 8; i++) {
946 cycles_t start, end;
947
948 start = get_cycles();
949
950 ret = crypto_hash_init(desc);
951 if (ret)
952 goto out;
953 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xua5a613a2007-10-27 00:51:21 -0700954 sg_set_buf(sg, p + pcount, plen);
Herbert Xue9d41162006-08-19 21:38:49 +1000955 ret = crypto_hash_update(desc, sg, plen);
956 if (ret)
957 goto out;
958 }
959 ret = crypto_hash_final(desc, out);
960 if (ret)
961 goto out;
962
963 end = get_cycles();
964
965 cycles += end - start;
966 }
967
968out:
969 local_irq_enable();
970 local_bh_enable();
971
972 if (ret)
973 return ret;
974
975 printk("%6lu cycles/operation, %4lu cycles/byte\n",
976 cycles / 8, cycles / (8 * blen));
977
978 return 0;
979}
980
981static void test_hash_speed(char *algo, unsigned int sec,
982 struct hash_speed *speed)
983{
984 struct crypto_hash *tfm;
985 struct hash_desc desc;
Michal Ludvige8057922006-05-30 22:04:19 +1000986 char output[1024];
987 int i;
Herbert Xue9d41162006-08-19 21:38:49 +1000988 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000989
990 printk("\ntesting speed of %s\n", algo);
991
Herbert Xue9d41162006-08-19 21:38:49 +1000992 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
Michal Ludvige8057922006-05-30 22:04:19 +1000993
Herbert Xue9d41162006-08-19 21:38:49 +1000994 if (IS_ERR(tfm)) {
995 printk("failed to load transform for %s: %ld\n", algo,
996 PTR_ERR(tfm));
Michal Ludvige8057922006-05-30 22:04:19 +1000997 return;
998 }
999
Herbert Xue9d41162006-08-19 21:38:49 +10001000 desc.tfm = tfm;
1001 desc.flags = 0;
1002
1003 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
Michal Ludvige8057922006-05-30 22:04:19 +10001004 printk("digestsize(%u) > outputbuffer(%zu)\n",
Herbert Xue9d41162006-08-19 21:38:49 +10001005 crypto_hash_digestsize(tfm), sizeof(output));
Michal Ludvige8057922006-05-30 22:04:19 +10001006 goto out;
1007 }
1008
1009 for (i = 0; speed[i].blen != 0; i++) {
1010 if (speed[i].blen > TVMEMSIZE) {
1011 printk("template (%u) too big for tvmem (%u)\n",
1012 speed[i].blen, TVMEMSIZE);
1013 goto out;
1014 }
1015
1016 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1017 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1018
1019 memset(tvmem, 0xff, speed[i].blen);
1020
1021 if (sec)
Herbert Xue9d41162006-08-19 21:38:49 +10001022 ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
1023 speed[i].plen, output, sec);
Michal Ludvige8057922006-05-30 22:04:19 +10001024 else
Herbert Xue9d41162006-08-19 21:38:49 +10001025 ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
1026 speed[i].plen, output);
1027
1028 if (ret) {
1029 printk("hashing failed ret=%d\n", ret);
1030 break;
1031 }
Michal Ludvige8057922006-05-30 22:04:19 +10001032 }
1033
1034out:
Herbert Xue9d41162006-08-19 21:38:49 +10001035 crypto_free_hash(tfm);
Michal Ludvige8057922006-05-30 22:04:19 +10001036}
1037
Zoltan Sogor91755a92007-12-07 16:48:11 +08001038static void test_comp(char *algo, struct comp_testvec *ctemplate,
1039 struct comp_testvec *dtemplate, int ctcount, int dtcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040{
1041 unsigned int i;
1042 char result[COMP_BUF_SIZE];
Herbert Xue4d5b792006-08-26 18:12:40 +10001043 struct crypto_comp *tfm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 struct comp_testvec *tv;
1045 unsigned int tsize;
1046
Zoltan Sogor91755a92007-12-07 16:48:11 +08001047 printk("\ntesting %s compression\n", algo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
Zoltan Sogor91755a92007-12-07 16:48:11 +08001049 tsize = sizeof(struct comp_testvec);
1050 tsize *= ctcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 if (tsize > TVMEMSIZE) {
1052 printk("template (%u) too big for tvmem (%u)\n", tsize,
1053 TVMEMSIZE);
1054 return;
1055 }
1056
Zoltan Sogor91755a92007-12-07 16:48:11 +08001057 memcpy(tvmem, ctemplate, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -07001058 tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
Zoltan Sogor91755a92007-12-07 16:48:11 +08001060 tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC);
Sebastian Siewior7bc301e2007-03-21 08:58:43 +11001061 if (IS_ERR(tfm)) {
Zoltan Sogor91755a92007-12-07 16:48:11 +08001062 printk("failed to load transform for %s\n", algo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 return;
1064 }
1065
Zoltan Sogor91755a92007-12-07 16:48:11 +08001066 for (i = 0; i < ctcount; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 int ilen, ret, dlen = COMP_BUF_SIZE;
Herbert Xuef2736f2005-06-22 13:26:03 -07001068
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 printk("test %u:\n", i + 1);
1070 memset(result, 0, sizeof (result));
1071
1072 ilen = tv[i].inlen;
1073 ret = crypto_comp_compress(tfm, tv[i].input,
1074 ilen, result, &dlen);
1075 if (ret) {
1076 printk("fail: ret=%d\n", ret);
1077 continue;
1078 }
1079 hexdump(result, dlen);
1080 printk("%s (ratio %d:%d)\n",
1081 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
1082 ilen, dlen);
1083 }
1084
Zoltan Sogor91755a92007-12-07 16:48:11 +08001085 printk("\ntesting %s decompression\n", algo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Zoltan Sogor91755a92007-12-07 16:48:11 +08001087 tsize = sizeof(struct comp_testvec);
1088 tsize *= dtcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 if (tsize > TVMEMSIZE) {
1090 printk("template (%u) too big for tvmem (%u)\n", tsize,
1091 TVMEMSIZE);
1092 goto out;
1093 }
1094
Zoltan Sogor91755a92007-12-07 16:48:11 +08001095 memcpy(tvmem, dtemplate, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -07001096 tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Zoltan Sogor91755a92007-12-07 16:48:11 +08001098 for (i = 0; i < dtcount; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 int ilen, ret, dlen = COMP_BUF_SIZE;
Herbert Xuef2736f2005-06-22 13:26:03 -07001100
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 printk("test %u:\n", i + 1);
1102 memset(result, 0, sizeof (result));
1103
1104 ilen = tv[i].inlen;
1105 ret = crypto_comp_decompress(tfm, tv[i].input,
1106 ilen, result, &dlen);
1107 if (ret) {
1108 printk("fail: ret=%d\n", ret);
1109 continue;
1110 }
1111 hexdump(result, dlen);
1112 printk("%s (ratio %d:%d)\n",
1113 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
1114 ilen, dlen);
1115 }
1116out:
Herbert Xue4d5b792006-08-26 18:12:40 +10001117 crypto_free_comp(tfm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118}
1119
Herbert Xuef2736f2005-06-22 13:26:03 -07001120static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121{
1122 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -07001123
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 while (*name) {
1125 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +10001126 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +10001127 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -07001129 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130}
1131
Herbert Xuef2736f2005-06-22 13:26:03 -07001132static void do_test(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133{
1134 switch (mode) {
1135
1136 case 0:
1137 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -07001138
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -07001140
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 //DES
Herbert Xucba83562006-08-13 08:26:09 +10001142 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1143 DES_ENC_TEST_VECTORS);
1144 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1145 DES_DEC_TEST_VECTORS);
1146 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1147 DES_CBC_ENC_TEST_VECTORS);
1148 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1149 DES_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -07001150
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 //DES3_EDE
Herbert Xucba83562006-08-13 08:26:09 +10001152 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1153 DES3_EDE_ENC_TEST_VECTORS);
1154 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1155 DES3_EDE_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -07001156
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -07001158
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001159 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1160
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -07001162
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 //BLOWFISH
Herbert Xucba83562006-08-13 08:26:09 +10001164 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1165 BF_ENC_TEST_VECTORS);
1166 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1167 BF_DEC_TEST_VECTORS);
1168 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1169 BF_CBC_ENC_TEST_VECTORS);
1170 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1171 BF_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -07001172
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 //TWOFISH
Herbert Xucba83562006-08-13 08:26:09 +10001174 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1175 TF_ENC_TEST_VECTORS);
1176 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1177 TF_DEC_TEST_VECTORS);
1178 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1179 TF_CBC_ENC_TEST_VECTORS);
1180 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1181 TF_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -07001182
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 //SERPENT
Herbert Xucba83562006-08-13 08:26:09 +10001184 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1185 SERPENT_ENC_TEST_VECTORS);
1186 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1187 SERPENT_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -07001188
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 //TNEPRES
Herbert Xucba83562006-08-13 08:26:09 +10001190 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1191 TNEPRES_ENC_TEST_VECTORS);
1192 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1193 TNEPRES_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
1195 //AES
Herbert Xucba83562006-08-13 08:26:09 +10001196 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1197 AES_ENC_TEST_VECTORS);
1198 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1199 AES_DEC_TEST_VECTORS);
1200 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1201 AES_CBC_ENC_TEST_VECTORS);
1202 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1203 AES_CBC_DEC_TEST_VECTORS);
Rik Snelf3d10442006-11-29 19:01:41 +11001204 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1205 AES_LRW_ENC_TEST_VECTORS);
1206 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1207 AES_LRW_DEC_TEST_VECTORS);
Rik Snelf19f5112007-09-19 20:23:13 +08001208 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1209 AES_XTS_ENC_TEST_VECTORS);
1210 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1211 AES_XTS_DEC_TEST_VECTORS);
Herbert Xu5311f242007-12-17 21:34:32 +08001212 test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
Joy Latten23e353c2007-10-23 08:50:32 +08001213 AES_CTR_ENC_TEST_VECTORS);
Herbert Xu5311f242007-12-17 21:34:32 +08001214 test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
Joy Latten23e353c2007-10-23 08:50:32 +08001215 AES_CTR_DEC_TEST_VECTORS);
Mikko Herranen28db8e32007-11-26 22:24:11 +08001216 test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
1217 AES_GCM_ENC_TEST_VECTORS);
1218 test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
1219 AES_GCM_DEC_TEST_VECTORS);
Joy Latten93cc74e2007-12-12 20:24:22 +08001220 test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
1221 AES_CCM_ENC_TEST_VECTORS);
1222 test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
1223 AES_CCM_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
1225 //CAST5
Herbert Xucba83562006-08-13 08:26:09 +10001226 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1227 CAST5_ENC_TEST_VECTORS);
1228 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1229 CAST5_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -07001230
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 //CAST6
Herbert Xucba83562006-08-13 08:26:09 +10001232 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1233 CAST6_ENC_TEST_VECTORS);
1234 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1235 CAST6_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
1237 //ARC4
Herbert Xucba83562006-08-13 08:26:09 +10001238 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1239 ARC4_ENC_TEST_VECTORS);
1240 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1241 ARC4_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
1243 //TEA
Herbert Xucba83562006-08-13 08:26:09 +10001244 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1245 TEA_ENC_TEST_VECTORS);
1246 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1247 TEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
1249
1250 //XTEA
Herbert Xucba83562006-08-13 08:26:09 +10001251 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1252 XTEA_ENC_TEST_VECTORS);
1253 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1254 XTEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
1256 //KHAZAD
Herbert Xucba83562006-08-13 08:26:09 +10001257 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1258 KHAZAD_ENC_TEST_VECTORS);
1259 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1260 KHAZAD_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
1262 //ANUBIS
Herbert Xucba83562006-08-13 08:26:09 +10001263 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1264 ANUBIS_ENC_TEST_VECTORS);
1265 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1266 ANUBIS_DEC_TEST_VECTORS);
1267 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1268 ANUBIS_CBC_ENC_TEST_VECTORS);
1269 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1270 ANUBIS_CBC_ENC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001272 //XETA
Herbert Xucba83562006-08-13 08:26:09 +10001273 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1274 XETA_ENC_TEST_VECTORS);
1275 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1276 XETA_DEC_TEST_VECTORS);
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001277
David Howells90831632006-12-16 12:13:14 +11001278 //FCrypt
1279 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1280 FCRYPT_ENC_TEST_VECTORS);
1281 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1282 FCRYPT_DEC_TEST_VECTORS);
1283
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001284 //CAMELLIA
1285 test_cipher("ecb(camellia)", ENCRYPT,
1286 camellia_enc_tv_template,
1287 CAMELLIA_ENC_TEST_VECTORS);
1288 test_cipher("ecb(camellia)", DECRYPT,
1289 camellia_dec_tv_template,
1290 CAMELLIA_DEC_TEST_VECTORS);
1291 test_cipher("cbc(camellia)", ENCRYPT,
1292 camellia_cbc_enc_tv_template,
1293 CAMELLIA_CBC_ENC_TEST_VECTORS);
1294 test_cipher("cbc(camellia)", DECRYPT,
1295 camellia_cbc_dec_tv_template,
1296 CAMELLIA_CBC_DEC_TEST_VECTORS);
1297
Hye-Shik Change2ee95b2007-08-21 20:01:03 +08001298 //SEED
1299 test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template,
1300 SEED_ENC_TEST_VECTORS);
1301 test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
1302 SEED_DEC_TEST_VECTORS);
1303
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1305 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1306 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1307 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1308 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1309 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1310 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1311 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
Zoltan Sogor91755a92007-12-07 16:48:11 +08001312 test_comp("deflate", deflate_comp_tv_template,
1313 deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
1314 DEFLATE_DECOMP_TEST_VECTORS);
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001315 test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
1316 LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
Herbert Xuc907ee72006-08-21 22:04:03 +10001317 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
Herbert Xue9d41162006-08-19 21:38:49 +10001318 test_hash("hmac(md5)", hmac_md5_tv_template,
1319 HMAC_MD5_TEST_VECTORS);
1320 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1321 HMAC_SHA1_TEST_VECTORS);
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001322 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1323 HMAC_SHA224_TEST_VECTORS);
Herbert Xue9d41162006-08-19 21:38:49 +10001324 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1325 HMAC_SHA256_TEST_VECTORS);
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001326 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1327 HMAC_SHA384_TEST_VECTORS);
1328 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1329 HMAC_SHA512_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Kazunori MIYAZAWA5b2becf2006-10-28 13:18:53 +10001331 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1332 XCBC_AES_TEST_VECTORS);
1333
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1335 break;
1336
1337 case 1:
1338 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1339 break;
1340
1341 case 2:
1342 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1343 break;
1344
1345 case 3:
Herbert Xucba83562006-08-13 08:26:09 +10001346 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1347 DES_ENC_TEST_VECTORS);
1348 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1349 DES_DEC_TEST_VECTORS);
1350 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1351 DES_CBC_ENC_TEST_VECTORS);
1352 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1353 DES_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 break;
1355
1356 case 4:
Herbert Xucba83562006-08-13 08:26:09 +10001357 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1358 DES3_EDE_ENC_TEST_VECTORS);
1359 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1360 DES3_EDE_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 break;
1362
1363 case 5:
1364 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1365 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001366
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 case 6:
1368 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1369 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001370
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 case 7:
Herbert Xucba83562006-08-13 08:26:09 +10001372 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1373 BF_ENC_TEST_VECTORS);
1374 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1375 BF_DEC_TEST_VECTORS);
1376 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1377 BF_CBC_ENC_TEST_VECTORS);
1378 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1379 BF_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 break;
1381
1382 case 8:
Herbert Xucba83562006-08-13 08:26:09 +10001383 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1384 TF_ENC_TEST_VECTORS);
1385 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1386 TF_DEC_TEST_VECTORS);
1387 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1388 TF_CBC_ENC_TEST_VECTORS);
1389 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1390 TF_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001392
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 case 9:
Herbert Xucba83562006-08-13 08:26:09 +10001394 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1395 SERPENT_ENC_TEST_VECTORS);
1396 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1397 SERPENT_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 break;
1399
1400 case 10:
Herbert Xucba83562006-08-13 08:26:09 +10001401 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1402 AES_ENC_TEST_VECTORS);
1403 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1404 AES_DEC_TEST_VECTORS);
1405 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1406 AES_CBC_ENC_TEST_VECTORS);
1407 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1408 AES_CBC_DEC_TEST_VECTORS);
Rik Snelf3d10442006-11-29 19:01:41 +11001409 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1410 AES_LRW_ENC_TEST_VECTORS);
1411 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1412 AES_LRW_DEC_TEST_VECTORS);
Rik Snelf19f5112007-09-19 20:23:13 +08001413 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1414 AES_XTS_ENC_TEST_VECTORS);
1415 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1416 AES_XTS_DEC_TEST_VECTORS);
Herbert Xu5311f242007-12-17 21:34:32 +08001417 test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
Joy Latten23e353c2007-10-23 08:50:32 +08001418 AES_CTR_ENC_TEST_VECTORS);
Herbert Xu5311f242007-12-17 21:34:32 +08001419 test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
Joy Latten23e353c2007-10-23 08:50:32 +08001420 AES_CTR_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 break;
1422
1423 case 11:
1424 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1425 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001426
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 case 12:
1428 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1429 break;
1430
1431 case 13:
Zoltan Sogor91755a92007-12-07 16:48:11 +08001432 test_comp("deflate", deflate_comp_tv_template,
1433 deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
1434 DEFLATE_DECOMP_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 break;
1436
1437 case 14:
Herbert Xucba83562006-08-13 08:26:09 +10001438 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1439 CAST5_ENC_TEST_VECTORS);
1440 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1441 CAST5_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 break;
1443
1444 case 15:
Herbert Xucba83562006-08-13 08:26:09 +10001445 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1446 CAST6_ENC_TEST_VECTORS);
1447 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1448 CAST6_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 break;
1450
1451 case 16:
Herbert Xucba83562006-08-13 08:26:09 +10001452 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1453 ARC4_ENC_TEST_VECTORS);
1454 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1455 ARC4_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 break;
1457
1458 case 17:
1459 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1460 break;
1461
1462 case 18:
Herbert Xuc907ee72006-08-21 22:04:03 +10001463 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 break;
1465
1466 case 19:
Herbert Xucba83562006-08-13 08:26:09 +10001467 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1468 TEA_ENC_TEST_VECTORS);
1469 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1470 TEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 break;
1472
1473 case 20:
Herbert Xucba83562006-08-13 08:26:09 +10001474 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1475 XTEA_ENC_TEST_VECTORS);
1476 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1477 XTEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 break;
1479
1480 case 21:
Herbert Xucba83562006-08-13 08:26:09 +10001481 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1482 KHAZAD_ENC_TEST_VECTORS);
1483 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1484 KHAZAD_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 break;
1486
1487 case 22:
1488 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1489 break;
1490
1491 case 23:
1492 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1493 break;
1494
1495 case 24:
1496 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1497 break;
1498
1499 case 25:
Herbert Xucba83562006-08-13 08:26:09 +10001500 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1501 TNEPRES_ENC_TEST_VECTORS);
1502 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1503 TNEPRES_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 break;
1505
1506 case 26:
Herbert Xucba83562006-08-13 08:26:09 +10001507 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1508 ANUBIS_ENC_TEST_VECTORS);
1509 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1510 ANUBIS_DEC_TEST_VECTORS);
1511 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1512 ANUBIS_CBC_ENC_TEST_VECTORS);
1513 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1514 ANUBIS_CBC_ENC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 break;
1516
1517 case 27:
1518 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1519 break;
1520
1521 case 28:
1522
1523 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1524 break;
1525
1526 case 29:
1527 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1528 break;
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001529
1530 case 30:
Herbert Xucba83562006-08-13 08:26:09 +10001531 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1532 XETA_ENC_TEST_VECTORS);
1533 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1534 XETA_DEC_TEST_VECTORS);
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001535 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
David Howells90831632006-12-16 12:13:14 +11001537 case 31:
1538 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1539 FCRYPT_ENC_TEST_VECTORS);
1540 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1541 FCRYPT_DEC_TEST_VECTORS);
1542 break;
1543
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001544 case 32:
1545 test_cipher("ecb(camellia)", ENCRYPT,
1546 camellia_enc_tv_template,
1547 CAMELLIA_ENC_TEST_VECTORS);
1548 test_cipher("ecb(camellia)", DECRYPT,
1549 camellia_dec_tv_template,
1550 CAMELLIA_DEC_TEST_VECTORS);
1551 test_cipher("cbc(camellia)", ENCRYPT,
1552 camellia_cbc_enc_tv_template,
1553 CAMELLIA_CBC_ENC_TEST_VECTORS);
1554 test_cipher("cbc(camellia)", DECRYPT,
1555 camellia_cbc_dec_tv_template,
1556 CAMELLIA_CBC_DEC_TEST_VECTORS);
1557 break;
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001558 case 33:
1559 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1560 break;
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001561
Tan Swee Heng2407d602007-11-23 19:45:00 +08001562 case 34:
1563 test_cipher("salsa20", ENCRYPT,
1564 salsa20_stream_enc_tv_template,
1565 SALSA20_STREAM_ENC_TEST_VECTORS);
1566 break;
1567
Herbert Xu8df213d2007-12-02 14:55:47 +11001568 case 35:
1569 test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
1570 AES_GCM_ENC_TEST_VECTORS);
1571 test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
1572 AES_GCM_DEC_TEST_VECTORS);
1573 break;
1574
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001575 case 36:
1576 test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
1577 LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
1578 break;
1579
Joy Latten93cc74e2007-12-12 20:24:22 +08001580 case 37:
1581 test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
1582 AES_CCM_ENC_TEST_VECTORS);
1583 test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
1584 AES_CCM_DEC_TEST_VECTORS);
1585 break;
1586
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 case 100:
Herbert Xue9d41162006-08-19 21:38:49 +10001588 test_hash("hmac(md5)", hmac_md5_tv_template,
1589 HMAC_MD5_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001591
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 case 101:
Herbert Xue9d41162006-08-19 21:38:49 +10001593 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1594 HMAC_SHA1_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001596
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 case 102:
Herbert Xue9d41162006-08-19 21:38:49 +10001598 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1599 HMAC_SHA256_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 break;
1601
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001602 case 103:
1603 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1604 HMAC_SHA384_TEST_VECTORS);
1605 break;
1606
1607 case 104:
1608 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1609 HMAC_SHA512_TEST_VECTORS);
1610 break;
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001611
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001612 case 105:
1613 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1614 HMAC_SHA224_TEST_VECTORS);
1615 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001617 case 106:
1618 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1619 XCBC_AES_TEST_VECTORS);
1620 break;
1621
Harald Welteebfd9bc2005-06-22 13:27:23 -07001622 case 200:
Herbert Xucba83562006-08-13 08:26:09 +10001623 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001624 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001625 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001626 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001627 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001628 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001629 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001630 aes_speed_template);
Rik Snelf3d10442006-11-29 19:01:41 +11001631 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1632 aes_lrw_speed_template);
1633 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1634 aes_lrw_speed_template);
Rik Snelf19f5112007-09-19 20:23:13 +08001635 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1636 aes_xts_speed_template);
1637 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1638 aes_xts_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001639 break;
1640
1641 case 201:
Herbert Xucba83562006-08-13 08:26:09 +10001642 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001643 des3_ede_enc_tv_template,
1644 DES3_EDE_ENC_TEST_VECTORS,
1645 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001646 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001647 des3_ede_dec_tv_template,
1648 DES3_EDE_DEC_TEST_VECTORS,
1649 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001650 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001651 des3_ede_enc_tv_template,
1652 DES3_EDE_ENC_TEST_VECTORS,
1653 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001654 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001655 des3_ede_dec_tv_template,
1656 DES3_EDE_DEC_TEST_VECTORS,
1657 des3_ede_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001658 break;
1659
1660 case 202:
Herbert Xucba83562006-08-13 08:26:09 +10001661 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001662 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001663 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001664 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001665 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001666 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001667 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001668 twofish_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001669 break;
1670
1671 case 203:
Herbert Xucba83562006-08-13 08:26:09 +10001672 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001673 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001674 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001675 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001676 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001677 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001678 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001679 blowfish_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001680 break;
1681
1682 case 204:
Herbert Xucba83562006-08-13 08:26:09 +10001683 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001684 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001685 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001686 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001687 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001688 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001689 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001690 des_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001691 break;
1692
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001693 case 205:
1694 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1695 camellia_speed_template);
1696 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1697 camellia_speed_template);
1698 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1699 camellia_speed_template);
1700 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1701 camellia_speed_template);
1702 break;
1703
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001704 case 206:
1705 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1706 salsa20_speed_template);
1707 break;
1708
Michal Ludvige8057922006-05-30 22:04:19 +10001709 case 300:
1710 /* fall through */
1711
1712 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +10001713 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001714 if (mode > 300 && mode < 400) break;
1715
1716 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +10001717 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001718 if (mode > 300 && mode < 400) break;
1719
1720 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +10001721 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001722 if (mode > 300 && mode < 400) break;
1723
1724 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +10001725 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001726 if (mode > 300 && mode < 400) break;
1727
1728 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +10001729 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001730 if (mode > 300 && mode < 400) break;
1731
1732 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +10001733 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001734 if (mode > 300 && mode < 400) break;
1735
1736 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +10001737 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001738 if (mode > 300 && mode < 400) break;
1739
1740 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +10001741 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001742 if (mode > 300 && mode < 400) break;
1743
1744 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +10001745 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001746 if (mode > 300 && mode < 400) break;
1747
1748 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +10001749 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001750 if (mode > 300 && mode < 400) break;
1751
1752 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +10001753 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001754 if (mode > 300 && mode < 400) break;
1755
1756 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +10001757 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001758 if (mode > 300 && mode < 400) break;
1759
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001760 case 313:
1761 test_hash_speed("sha224", sec, generic_hash_speed_template);
1762 if (mode > 300 && mode < 400) break;
1763
Michal Ludvige8057922006-05-30 22:04:19 +10001764 case 399:
1765 break;
1766
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 case 1000:
1768 test_available();
1769 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001770
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 default:
1772 /* useful for debugging */
1773 printk("not testing anything\n");
1774 break;
1775 }
1776}
1777
Herbert Xuef2736f2005-06-22 13:26:03 -07001778static int __init init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779{
Mikko Herranene3a4ea42007-11-26 22:12:07 +08001780 int err = -ENOMEM;
1781
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1783 if (tvmem == NULL)
Mikko Herranene3a4ea42007-11-26 22:12:07 +08001784 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785
1786 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
Mikko Herranene3a4ea42007-11-26 22:12:07 +08001787 if (xbuf == NULL)
1788 goto err_free_tv;
1789
1790 axbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1791 if (axbuf == NULL)
1792 goto err_free_xbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
1794 do_test();
1795
Michal Ludvig14fdf472006-05-30 14:49:38 +10001796 /* We intentionaly return -EAGAIN to prevent keeping
1797 * the module. It does all its work from init()
1798 * and doesn't offer any runtime functionality
1799 * => we don't need it in the memory, do we?
1800 * -- mludvig
1801 */
Mikko Herranene3a4ea42007-11-26 22:12:07 +08001802 err = -EAGAIN;
1803
1804 kfree(axbuf);
1805 err_free_xbuf:
1806 kfree(xbuf);
1807 err_free_tv:
1808 kfree(tvmem);
1809
1810 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811}
1812
1813/*
1814 * If an init function is provided, an exit function must also be provided
1815 * to allow module unload.
1816 */
1817static void __exit fini(void) { }
1818
1819module_init(init);
1820module_exit(fini);
1821
1822module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001823module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -07001824MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1825 "(defaults to zero which uses CPU cycles instead)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826
1827MODULE_LICENSE("GPL");
1828MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1829MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");