blob: d59ba5079d14617a51554b5042ea7a10f5ab8235 [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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 */
17
Herbert Xu18e33e62008-07-10 16:01:22 +080018#include <crypto/hash.h>
Herbert Xucba83562006-08-13 08:26:09 +100019#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/init.h>
21#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/slab.h>
David Hardeman378f0582005-09-17 17:55:31 +100023#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/moduleparam.h>
Harald Welteebfd9bc2005-06-22 13:27:23 -070026#include <linux/jiffies.h>
Herbert Xu6a179442005-06-22 13:29:03 -070027#include <linux/timex.h>
28#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include "tcrypt.h"
Jarod Wilson4e033a62009-05-27 15:10:21 +100030#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32/*
Herbert Xuf139cfa2008-07-31 12:23:53 +080033 * Need slab memory for testing (size in number of pages).
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 */
Herbert Xuf139cfa2008-07-31 12:23:53 +080035#define TVMEMSIZE 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37/*
Herbert Xuda7f0332008-07-31 17:08:25 +080038* Used by test_cipher_speed()
Linus Torvalds1da177e2005-04-16 15:20:36 -070039*/
40#define ENCRYPT 1
41#define DECRYPT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Harald Welteebfd9bc2005-06-22 13:27:23 -070043/*
44 * Used by test_cipher_speed()
45 */
Herbert Xu6a179442005-06-22 13:29:03 -070046static unsigned int sec;
Harald Welteebfd9bc2005-06-22 13:27:23 -070047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048static int mode;
Herbert Xuf139cfa2008-07-31 12:23:53 +080049static char *tvmem[TVMEMSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51static char *check[] = {
Jonathan Lynchcd12fb902007-11-10 20:08:25 +080052 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
53 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
54 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
David Howells90831632006-12-16 12:13:14 +110055 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +080056 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +080057 "lzo", "cts", "zlib", NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070058};
59
Herbert Xuf139cfa2008-07-31 12:23:53 +080060static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
61 struct scatterlist *sg, int blen, int sec)
Herbert Xu6a179442005-06-22 13:29:03 -070062{
Herbert Xu6a179442005-06-22 13:29:03 -070063 unsigned long start, end;
64 int bcount;
65 int ret;
66
Herbert Xu6a179442005-06-22 13:29:03 -070067 for (start = jiffies, end = start + sec * HZ, bcount = 0;
68 time_before(jiffies, end); bcount++) {
69 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +100070 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -070071 else
Herbert Xucba83562006-08-13 08:26:09 +100072 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -070073
74 if (ret)
75 return ret;
76 }
77
78 printk("%d operations in %d seconds (%ld bytes)\n",
79 bcount, sec, (long)bcount * blen);
80 return 0;
81}
82
Herbert Xuf139cfa2008-07-31 12:23:53 +080083static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
84 struct scatterlist *sg, int blen)
Herbert Xu6a179442005-06-22 13:29:03 -070085{
Herbert Xu6a179442005-06-22 13:29:03 -070086 unsigned long cycles = 0;
87 int ret = 0;
88 int i;
89
Herbert Xu6a179442005-06-22 13:29:03 -070090 local_bh_disable();
91 local_irq_disable();
92
93 /* Warm-up run. */
94 for (i = 0; i < 4; i++) {
95 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +100096 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -070097 else
Herbert Xucba83562006-08-13 08:26:09 +100098 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -070099
100 if (ret)
101 goto out;
102 }
103
104 /* The real thing. */
105 for (i = 0; i < 8; i++) {
106 cycles_t start, end;
107
108 start = get_cycles();
109 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000110 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700111 else
Herbert Xucba83562006-08-13 08:26:09 +1000112 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700113 end = get_cycles();
114
115 if (ret)
116 goto out;
117
118 cycles += end - start;
119 }
120
121out:
122 local_irq_enable();
123 local_bh_enable();
124
125 if (ret == 0)
126 printk("1 operation in %lu cycles (%d bytes)\n",
127 (cycles + 4) / 8, blen);
128
129 return ret;
130}
131
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800132static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
133
Herbert Xu01b32322008-07-31 15:41:55 +0800134static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
Herbert Xuda7f0332008-07-31 17:08:25 +0800135 struct cipher_speed_template *template,
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800136 unsigned int tcount, u8 *keysize)
Harald Welteebfd9bc2005-06-22 13:27:23 -0700137{
Herbert Xudce907c2005-06-22 13:27:51 -0700138 unsigned int ret, i, j, iv_len;
Herbert Xuda7f0332008-07-31 17:08:25 +0800139 const char *key, iv[128];
Herbert Xucba83562006-08-13 08:26:09 +1000140 struct crypto_blkcipher *tfm;
141 struct blkcipher_desc desc;
142 const char *e;
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800143 u32 *b_size;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700144
145 if (enc == ENCRYPT)
146 e = "encryption";
147 else
148 e = "decryption";
Harald Welteebfd9bc2005-06-22 13:27:23 -0700149
Herbert Xucba83562006-08-13 08:26:09 +1000150 printk("\ntesting speed of %s %s\n", algo, e);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700151
Herbert Xucba83562006-08-13 08:26:09 +1000152 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700153
Herbert Xucba83562006-08-13 08:26:09 +1000154 if (IS_ERR(tfm)) {
155 printk("failed to load transform for %s: %ld\n", algo,
156 PTR_ERR(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700157 return;
158 }
Herbert Xucba83562006-08-13 08:26:09 +1000159 desc.tfm = tfm;
160 desc.flags = 0;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700161
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800162 i = 0;
163 do {
Harald Welteebfd9bc2005-06-22 13:27:23 -0700164
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800165 b_size = block_sizes;
166 do {
Herbert Xuf139cfa2008-07-31 12:23:53 +0800167 struct scatterlist sg[TVMEMSIZE];
Harald Welteebfd9bc2005-06-22 13:27:23 -0700168
Herbert Xuf139cfa2008-07-31 12:23:53 +0800169 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
170 printk("template (%u) too big for "
171 "tvmem (%lu)\n", *keysize + *b_size,
172 TVMEMSIZE * PAGE_SIZE);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800173 goto out;
174 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700175
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800176 printk("test %u (%d bit key, %d byte blocks): ", i,
177 *keysize * 8, *b_size);
178
Herbert Xuf139cfa2008-07-31 12:23:53 +0800179 memset(tvmem[0], 0xff, PAGE_SIZE);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800180
181 /* set key, plain text and IV */
Herbert Xuda7f0332008-07-31 17:08:25 +0800182 key = tvmem[0];
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800183 for (j = 0; j < tcount; j++) {
184 if (template[j].klen == *keysize) {
185 key = template[j].key;
186 break;
187 }
188 }
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800189
190 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
191 if (ret) {
192 printk("setkey() failed flags=%x\n",
193 crypto_blkcipher_get_flags(tfm));
194 goto out;
195 }
196
Herbert Xuf139cfa2008-07-31 12:23:53 +0800197 sg_init_table(sg, TVMEMSIZE);
198 sg_set_buf(sg, tvmem[0] + *keysize,
199 PAGE_SIZE - *keysize);
200 for (j = 1; j < TVMEMSIZE; j++) {
201 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
202 memset (tvmem[j], 0xff, PAGE_SIZE);
203 }
204
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800205 iv_len = crypto_blkcipher_ivsize(tfm);
206 if (iv_len) {
207 memset(&iv, 0xff, iv_len);
208 crypto_blkcipher_set_iv(tfm, iv, iv_len);
209 }
210
211 if (sec)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800212 ret = test_cipher_jiffies(&desc, enc, sg,
213 *b_size, sec);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800214 else
Herbert Xuf139cfa2008-07-31 12:23:53 +0800215 ret = test_cipher_cycles(&desc, enc, sg,
216 *b_size);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800217
218 if (ret) {
219 printk("%s() failed flags=%x\n", e, desc.flags);
Herbert Xudce907c2005-06-22 13:27:51 -0700220 break;
221 }
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800222 b_size++;
223 i++;
224 } while (*b_size);
225 keysize++;
226 } while (*keysize);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700227
228out:
Herbert Xucba83562006-08-13 08:26:09 +1000229 crypto_free_blkcipher(tfm);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700230}
231
Herbert Xuf139cfa2008-07-31 12:23:53 +0800232static int test_hash_jiffies_digest(struct hash_desc *desc,
233 struct scatterlist *sg, int blen,
Herbert Xue9d41162006-08-19 21:38:49 +1000234 char *out, int sec)
Michal Ludvige8057922006-05-30 22:04:19 +1000235{
Michal Ludvige8057922006-05-30 22:04:19 +1000236 unsigned long start, end;
Herbert Xue9d41162006-08-19 21:38:49 +1000237 int bcount;
238 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000239
240 for (start = jiffies, end = start + sec * HZ, bcount = 0;
241 time_before(jiffies, end); bcount++) {
Herbert Xue9d41162006-08-19 21:38:49 +1000242 ret = crypto_hash_digest(desc, sg, blen, out);
243 if (ret)
244 return ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000245 }
246
247 printk("%6u opers/sec, %9lu bytes/sec\n",
248 bcount / sec, ((long)bcount * blen) / sec);
249
Herbert Xue9d41162006-08-19 21:38:49 +1000250 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000251}
252
Herbert Xuf139cfa2008-07-31 12:23:53 +0800253static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
254 int blen, int plen, char *out, int sec)
Herbert Xue9d41162006-08-19 21:38:49 +1000255{
Herbert Xue9d41162006-08-19 21:38:49 +1000256 unsigned long start, end;
257 int bcount, pcount;
258 int ret;
259
260 if (plen == blen)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800261 return test_hash_jiffies_digest(desc, sg, blen, out, sec);
Herbert Xua5a613a2007-10-27 00:51:21 -0700262
Herbert Xue9d41162006-08-19 21:38:49 +1000263 for (start = jiffies, end = start + sec * HZ, bcount = 0;
264 time_before(jiffies, end); bcount++) {
265 ret = crypto_hash_init(desc);
266 if (ret)
267 return ret;
268 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000269 ret = crypto_hash_update(desc, sg, plen);
270 if (ret)
271 return ret;
272 }
273 /* we assume there is enough space in 'out' for the result */
274 ret = crypto_hash_final(desc, out);
275 if (ret)
276 return ret;
277 }
278
279 printk("%6u opers/sec, %9lu bytes/sec\n",
280 bcount / sec, ((long)bcount * blen) / sec);
281
282 return 0;
283}
284
Herbert Xuf139cfa2008-07-31 12:23:53 +0800285static int test_hash_cycles_digest(struct hash_desc *desc,
286 struct scatterlist *sg, int blen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000287{
Michal Ludvige8057922006-05-30 22:04:19 +1000288 unsigned long cycles = 0;
Herbert Xue9d41162006-08-19 21:38:49 +1000289 int i;
290 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000291
292 local_bh_disable();
293 local_irq_disable();
294
295 /* Warm-up run. */
296 for (i = 0; i < 4; i++) {
Herbert Xue9d41162006-08-19 21:38:49 +1000297 ret = crypto_hash_digest(desc, sg, blen, out);
298 if (ret)
299 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000300 }
301
302 /* The real thing. */
303 for (i = 0; i < 8; i++) {
304 cycles_t start, end;
305
Michal Ludvige8057922006-05-30 22:04:19 +1000306 start = get_cycles();
307
Herbert Xue9d41162006-08-19 21:38:49 +1000308 ret = crypto_hash_digest(desc, sg, blen, out);
309 if (ret)
310 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000311
312 end = get_cycles();
313
314 cycles += end - start;
315 }
316
Herbert Xue9d41162006-08-19 21:38:49 +1000317out:
Michal Ludvige8057922006-05-30 22:04:19 +1000318 local_irq_enable();
319 local_bh_enable();
320
Herbert Xue9d41162006-08-19 21:38:49 +1000321 if (ret)
322 return ret;
323
Michal Ludvige8057922006-05-30 22:04:19 +1000324 printk("%6lu cycles/operation, %4lu cycles/byte\n",
325 cycles / 8, cycles / (8 * blen));
326
Herbert Xue9d41162006-08-19 21:38:49 +1000327 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000328}
329
Herbert Xuf139cfa2008-07-31 12:23:53 +0800330static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
331 int blen, int plen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000332{
Herbert Xue9d41162006-08-19 21:38:49 +1000333 unsigned long cycles = 0;
334 int i, pcount;
335 int ret;
336
337 if (plen == blen)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800338 return test_hash_cycles_digest(desc, sg, blen, out);
Herbert Xua5a613a2007-10-27 00:51:21 -0700339
Herbert Xue9d41162006-08-19 21:38:49 +1000340 local_bh_disable();
341 local_irq_disable();
342
343 /* Warm-up run. */
344 for (i = 0; i < 4; i++) {
345 ret = crypto_hash_init(desc);
346 if (ret)
347 goto out;
348 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000349 ret = crypto_hash_update(desc, sg, plen);
350 if (ret)
351 goto out;
352 }
Herbert Xu29059d12007-05-18 16:25:19 +1000353 ret = crypto_hash_final(desc, out);
Herbert Xue9d41162006-08-19 21:38:49 +1000354 if (ret)
355 goto out;
356 }
357
358 /* The real thing. */
359 for (i = 0; i < 8; i++) {
360 cycles_t start, end;
361
362 start = get_cycles();
363
364 ret = crypto_hash_init(desc);
365 if (ret)
366 goto out;
367 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000368 ret = crypto_hash_update(desc, sg, plen);
369 if (ret)
370 goto out;
371 }
372 ret = crypto_hash_final(desc, out);
373 if (ret)
374 goto out;
375
376 end = get_cycles();
377
378 cycles += end - start;
379 }
380
381out:
382 local_irq_enable();
383 local_bh_enable();
384
385 if (ret)
386 return ret;
387
388 printk("%6lu cycles/operation, %4lu cycles/byte\n",
389 cycles / 8, cycles / (8 * blen));
390
391 return 0;
392}
393
Herbert Xu01b32322008-07-31 15:41:55 +0800394static void test_hash_speed(const char *algo, unsigned int sec,
395 struct hash_speed *speed)
Herbert Xue9d41162006-08-19 21:38:49 +1000396{
Herbert Xuf139cfa2008-07-31 12:23:53 +0800397 struct scatterlist sg[TVMEMSIZE];
Herbert Xue9d41162006-08-19 21:38:49 +1000398 struct crypto_hash *tfm;
399 struct hash_desc desc;
Frank Seidel376bacb2009-03-29 15:18:39 +0800400 static char output[1024];
Michal Ludvige8057922006-05-30 22:04:19 +1000401 int i;
Herbert Xue9d41162006-08-19 21:38:49 +1000402 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000403
Frank Seidel376bacb2009-03-29 15:18:39 +0800404 printk(KERN_INFO "\ntesting speed of %s\n", algo);
Michal Ludvige8057922006-05-30 22:04:19 +1000405
Herbert Xue9d41162006-08-19 21:38:49 +1000406 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
Michal Ludvige8057922006-05-30 22:04:19 +1000407
Herbert Xue9d41162006-08-19 21:38:49 +1000408 if (IS_ERR(tfm)) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800409 printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
Herbert Xue9d41162006-08-19 21:38:49 +1000410 PTR_ERR(tfm));
Michal Ludvige8057922006-05-30 22:04:19 +1000411 return;
412 }
413
Herbert Xue9d41162006-08-19 21:38:49 +1000414 desc.tfm = tfm;
415 desc.flags = 0;
416
417 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800418 printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
Herbert Xue9d41162006-08-19 21:38:49 +1000419 crypto_hash_digestsize(tfm), sizeof(output));
Michal Ludvige8057922006-05-30 22:04:19 +1000420 goto out;
421 }
422
Herbert Xuf139cfa2008-07-31 12:23:53 +0800423 sg_init_table(sg, TVMEMSIZE);
424 for (i = 0; i < TVMEMSIZE; i++) {
425 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
426 memset(tvmem[i], 0xff, PAGE_SIZE);
427 }
428
Michal Ludvige8057922006-05-30 22:04:19 +1000429 for (i = 0; speed[i].blen != 0; i++) {
Herbert Xuf139cfa2008-07-31 12:23:53 +0800430 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800431 printk(KERN_ERR
432 "template (%u) too big for tvmem (%lu)\n",
Herbert Xuf139cfa2008-07-31 12:23:53 +0800433 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
Michal Ludvige8057922006-05-30 22:04:19 +1000434 goto out;
435 }
436
Frank Seidel376bacb2009-03-29 15:18:39 +0800437 printk(KERN_INFO "test%3u "
438 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
Michal Ludvige8057922006-05-30 22:04:19 +1000439 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
440
Michal Ludvige8057922006-05-30 22:04:19 +1000441 if (sec)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800442 ret = test_hash_jiffies(&desc, sg, speed[i].blen,
Herbert Xue9d41162006-08-19 21:38:49 +1000443 speed[i].plen, output, sec);
Michal Ludvige8057922006-05-30 22:04:19 +1000444 else
Herbert Xuf139cfa2008-07-31 12:23:53 +0800445 ret = test_hash_cycles(&desc, sg, speed[i].blen,
Herbert Xue9d41162006-08-19 21:38:49 +1000446 speed[i].plen, output);
447
448 if (ret) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800449 printk(KERN_ERR "hashing failed ret=%d\n", ret);
Herbert Xue9d41162006-08-19 21:38:49 +1000450 break;
451 }
Michal Ludvige8057922006-05-30 22:04:19 +1000452 }
453
454out:
Herbert Xue9d41162006-08-19 21:38:49 +1000455 crypto_free_hash(tfm);
Michal Ludvige8057922006-05-30 22:04:19 +1000456}
457
Herbert Xuef2736f2005-06-22 13:26:03 -0700458static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459{
460 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -0700461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 while (*name) {
463 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +1000464 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +1000465 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700467 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468}
469
Herbert Xu01b32322008-07-31 15:41:55 +0800470static inline int tcrypt_test(const char *alg)
471{
Jarod Wilson4e033a62009-05-27 15:10:21 +1000472 int ret;
473
474 ret = alg_test(alg, alg, 0, 0);
475 /* non-fips algs return -EINVAL in fips mode */
476 if (fips_enabled && ret == -EINVAL)
477 ret = 0;
478 return ret;
Herbert Xu01b32322008-07-31 15:41:55 +0800479}
480
Jarod Wilson4e033a62009-05-27 15:10:21 +1000481static int do_test(int m)
Herbert Xu01b32322008-07-31 15:41:55 +0800482{
483 int i;
Jarod Wilson4e033a62009-05-27 15:10:21 +1000484 int ret = 0;
Herbert Xu01b32322008-07-31 15:41:55 +0800485
486 switch (m) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 case 0:
Herbert Xu01b32322008-07-31 15:41:55 +0800488 for (i = 1; i < 200; i++)
Jarod Wilson4e033a62009-05-27 15:10:21 +1000489 ret += do_test(i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 break;
491
492 case 1:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000493 ret += tcrypt_test("md5");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 break;
495
496 case 2:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000497 ret += tcrypt_test("sha1");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 break;
499
500 case 3:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000501 ret += tcrypt_test("ecb(des)");
502 ret += tcrypt_test("cbc(des)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 break;
504
505 case 4:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000506 ret += tcrypt_test("ecb(des3_ede)");
507 ret += tcrypt_test("cbc(des3_ede)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 break;
509
510 case 5:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000511 ret += tcrypt_test("md4");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 case 6:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000515 ret += tcrypt_test("sha256");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700517
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 case 7:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000519 ret += tcrypt_test("ecb(blowfish)");
520 ret += tcrypt_test("cbc(blowfish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 break;
522
523 case 8:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000524 ret += tcrypt_test("ecb(twofish)");
525 ret += tcrypt_test("cbc(twofish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 case 9:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000529 ret += tcrypt_test("ecb(serpent)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 break;
531
532 case 10:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000533 ret += tcrypt_test("ecb(aes)");
534 ret += tcrypt_test("cbc(aes)");
535 ret += tcrypt_test("lrw(aes)");
536 ret += tcrypt_test("xts(aes)");
537 ret += tcrypt_test("ctr(aes)");
538 ret += tcrypt_test("rfc3686(ctr(aes))");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 break;
540
541 case 11:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000542 ret += tcrypt_test("sha384");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 case 12:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000546 ret += tcrypt_test("sha512");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 break;
548
549 case 13:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000550 ret += tcrypt_test("deflate");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 break;
552
553 case 14:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000554 ret += tcrypt_test("ecb(cast5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 break;
556
557 case 15:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000558 ret += tcrypt_test("ecb(cast6)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 break;
560
561 case 16:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000562 ret += tcrypt_test("ecb(arc4)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 break;
564
565 case 17:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000566 ret += tcrypt_test("michael_mic");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 break;
568
569 case 18:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000570 ret += tcrypt_test("crc32c");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 break;
572
573 case 19:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000574 ret += tcrypt_test("ecb(tea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 break;
576
577 case 20:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000578 ret += tcrypt_test("ecb(xtea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 break;
580
581 case 21:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000582 ret += tcrypt_test("ecb(khazad)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 break;
584
585 case 22:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000586 ret += tcrypt_test("wp512");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 break;
588
589 case 23:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000590 ret += tcrypt_test("wp384");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 break;
592
593 case 24:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000594 ret += tcrypt_test("wp256");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 break;
596
597 case 25:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000598 ret += tcrypt_test("ecb(tnepres)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 break;
600
601 case 26:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000602 ret += tcrypt_test("ecb(anubis)");
603 ret += tcrypt_test("cbc(anubis)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 break;
605
606 case 27:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000607 ret += tcrypt_test("tgr192");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 break;
609
610 case 28:
611
Jarod Wilson4e033a62009-05-27 15:10:21 +1000612 ret += tcrypt_test("tgr160");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 break;
614
615 case 29:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000616 ret += tcrypt_test("tgr128");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 break;
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +0800618
Aaron Grothefb4f10e2005-09-01 17:42:46 -0700619 case 30:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000620 ret += tcrypt_test("ecb(xeta)");
Aaron Grothefb4f10e2005-09-01 17:42:46 -0700621 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
David Howells90831632006-12-16 12:13:14 +1100623 case 31:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000624 ret += tcrypt_test("pcbc(fcrypt)");
David Howells90831632006-12-16 12:13:14 +1100625 break;
626
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100627 case 32:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000628 ret += tcrypt_test("ecb(camellia)");
629 ret += tcrypt_test("cbc(camellia)");
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100630 break;
Jonathan Lynchcd12fb902007-11-10 20:08:25 +0800631 case 33:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000632 ret += tcrypt_test("sha224");
Jonathan Lynchcd12fb902007-11-10 20:08:25 +0800633 break;
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100634
Tan Swee Heng2407d602007-11-23 19:45:00 +0800635 case 34:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000636 ret += tcrypt_test("salsa20");
Tan Swee Heng2407d602007-11-23 19:45:00 +0800637 break;
638
Herbert Xu8df213d2007-12-02 14:55:47 +1100639 case 35:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000640 ret += tcrypt_test("gcm(aes)");
Herbert Xu8df213d2007-12-02 14:55:47 +1100641 break;
642
Zoltan Sogor0b77abb2007-12-07 16:53:23 +0800643 case 36:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000644 ret += tcrypt_test("lzo");
Zoltan Sogor0b77abb2007-12-07 16:53:23 +0800645 break;
646
Joy Latten93cc74e2007-12-12 20:24:22 +0800647 case 37:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000648 ret += tcrypt_test("ccm(aes)");
Joy Latten93cc74e2007-12-12 20:24:22 +0800649 break;
650
Kevin Coffman76cb9522008-03-24 21:26:16 +0800651 case 38:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000652 ret += tcrypt_test("cts(cbc(aes))");
Kevin Coffman76cb9522008-03-24 21:26:16 +0800653 break;
654
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800655 case 39:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000656 ret += tcrypt_test("rmd128");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800657 break;
658
659 case 40:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000660 ret += tcrypt_test("rmd160");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800661 break;
662
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +0800663 case 41:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000664 ret += tcrypt_test("rmd256");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +0800665 break;
666
667 case 42:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000668 ret += tcrypt_test("rmd320");
Herbert Xu01b32322008-07-31 15:41:55 +0800669 break;
670
671 case 43:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000672 ret += tcrypt_test("ecb(seed)");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +0800673 break;
674
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +0800675 case 44:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000676 ret += tcrypt_test("zlib");
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +0800677 break;
678
Jarod Wilson5d667322009-05-04 19:23:40 +0800679 case 45:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000680 ret += tcrypt_test("rfc4309(ccm(aes))");
Jarod Wilson5d667322009-05-04 19:23:40 +0800681 break;
682
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 case 100:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000684 ret += tcrypt_test("hmac(md5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700686
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 case 101:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000688 ret += tcrypt_test("hmac(sha1)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 case 102:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000692 ret += tcrypt_test("hmac(sha256)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 break;
694
Andrew Donofrioa28091a2006-12-10 12:10:20 +1100695 case 103:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000696 ret += tcrypt_test("hmac(sha384)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +1100697 break;
698
699 case 104:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000700 ret += tcrypt_test("hmac(sha512)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +1100701 break;
Herbert Xu38ed9ab2008-01-01 15:59:28 +1100702
Jonathan Lynchcd12fb902007-11-10 20:08:25 +0800703 case 105:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000704 ret += tcrypt_test("hmac(sha224)");
Jonathan Lynchcd12fb902007-11-10 20:08:25 +0800705 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Herbert Xu38ed9ab2008-01-01 15:59:28 +1100707 case 106:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000708 ret += tcrypt_test("xcbc(aes)");
Herbert Xu38ed9ab2008-01-01 15:59:28 +1100709 break;
710
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800711 case 107:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000712 ret += tcrypt_test("hmac(rmd128)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800713 break;
714
715 case 108:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000716 ret += tcrypt_test("hmac(rmd160)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800717 break;
718
Jarod Wilsone08ca2d2009-05-04 19:46:29 +0800719 case 150:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000720 ret += tcrypt_test("ansi_cprng");
Jarod Wilsone08ca2d2009-05-04 19:46:29 +0800721 break;
722
Harald Welteebfd9bc2005-06-22 13:27:23 -0700723 case 200:
Herbert Xucba83562006-08-13 08:26:09 +1000724 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800725 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +1000726 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800727 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +1000728 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800729 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +1000730 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800731 speed_template_16_24_32);
Rik Snelf3d10442006-11-29 19:01:41 +1100732 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800733 speed_template_32_40_48);
Rik Snelf3d10442006-11-29 19:01:41 +1100734 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800735 speed_template_32_40_48);
Rik Snelf19f5112007-09-19 20:23:13 +0800736 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800737 speed_template_32_48_64);
Rik Snelf19f5112007-09-19 20:23:13 +0800738 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800739 speed_template_32_48_64);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700740 break;
741
742 case 201:
Herbert Xucba83562006-08-13 08:26:09 +1000743 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +0800744 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800745 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +1000746 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +0800747 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800748 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +1000749 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +0800750 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800751 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +1000752 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +0800753 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800754 speed_template_24);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700755 break;
756
757 case 202:
Herbert Xucba83562006-08-13 08:26:09 +1000758 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800759 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +1000760 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800761 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +1000762 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800763 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +1000764 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800765 speed_template_16_24_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700766 break;
767
768 case 203:
Herbert Xucba83562006-08-13 08:26:09 +1000769 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800770 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +1000771 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800772 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +1000773 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800774 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +1000775 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800776 speed_template_8_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700777 break;
778
779 case 204:
Herbert Xucba83562006-08-13 08:26:09 +1000780 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800781 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +1000782 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800783 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +1000784 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800785 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +1000786 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800787 speed_template_8);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700788 break;
789
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100790 case 205:
791 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800792 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100793 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800794 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100795 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800796 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100797 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800798 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100799 break;
800
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +0800801 case 206:
802 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800803 speed_template_16_32);
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +0800804 break;
805
Michal Ludvige8057922006-05-30 22:04:19 +1000806 case 300:
807 /* fall through */
808
809 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +1000810 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000811 if (mode > 300 && mode < 400) break;
812
813 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +1000814 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000815 if (mode > 300 && mode < 400) break;
816
817 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +1000818 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000819 if (mode > 300 && mode < 400) break;
820
821 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +1000822 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000823 if (mode > 300 && mode < 400) break;
824
825 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +1000826 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000827 if (mode > 300 && mode < 400) break;
828
829 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +1000830 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000831 if (mode > 300 && mode < 400) break;
832
833 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +1000834 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000835 if (mode > 300 && mode < 400) break;
836
837 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +1000838 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000839 if (mode > 300 && mode < 400) break;
840
841 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +1000842 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000843 if (mode > 300 && mode < 400) break;
844
845 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +1000846 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000847 if (mode > 300 && mode < 400) break;
848
849 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +1000850 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000851 if (mode > 300 && mode < 400) break;
852
853 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +1000854 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000855 if (mode > 300 && mode < 400) break;
856
Jonathan Lynchcd12fb902007-11-10 20:08:25 +0800857 case 313:
858 test_hash_speed("sha224", sec, generic_hash_speed_template);
859 if (mode > 300 && mode < 400) break;
860
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800861 case 314:
862 test_hash_speed("rmd128", sec, generic_hash_speed_template);
863 if (mode > 300 && mode < 400) break;
864
865 case 315:
866 test_hash_speed("rmd160", sec, generic_hash_speed_template);
867 if (mode > 300 && mode < 400) break;
868
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +0800869 case 316:
870 test_hash_speed("rmd256", sec, generic_hash_speed_template);
871 if (mode > 300 && mode < 400) break;
872
873 case 317:
874 test_hash_speed("rmd320", sec, generic_hash_speed_template);
875 if (mode > 300 && mode < 400) break;
876
Michal Ludvige8057922006-05-30 22:04:19 +1000877 case 399:
878 break;
879
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 case 1000:
881 test_available();
882 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 }
Jarod Wilson4e033a62009-05-27 15:10:21 +1000884
885 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886}
887
Kamalesh Babulal3af5b902008-04-05 21:00:57 +0800888static int __init tcrypt_mod_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889{
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800890 int err = -ENOMEM;
Herbert Xuf139cfa2008-07-31 12:23:53 +0800891 int i;
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800892
Herbert Xuf139cfa2008-07-31 12:23:53 +0800893 for (i = 0; i < TVMEMSIZE; i++) {
894 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
895 if (!tvmem[i])
896 goto err_free_tv;
897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Jarod Wilson4e033a62009-05-27 15:10:21 +1000899 err = do_test(mode);
900 if (err) {
901 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
902 goto err_free_tv;
903 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
Jarod Wilson4e033a62009-05-27 15:10:21 +1000905 /* We intentionaly return -EAGAIN to prevent keeping the module,
906 * unless we're running in fips mode. It does all its work from
907 * init() and doesn't offer any runtime functionality, but in
908 * the fips case, checking for a successful load is helpful.
Michal Ludvig14fdf472006-05-30 14:49:38 +1000909 * => we don't need it in the memory, do we?
910 * -- mludvig
911 */
Jarod Wilson4e033a62009-05-27 15:10:21 +1000912 if (!fips_enabled)
913 err = -EAGAIN;
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800914
Herbert Xuf139cfa2008-07-31 12:23:53 +0800915err_free_tv:
916 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
917 free_page((unsigned long)tvmem[i]);
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800918
919 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920}
921
922/*
923 * If an init function is provided, an exit function must also be provided
924 * to allow module unload.
925 */
Kamalesh Babulal3af5b902008-04-05 21:00:57 +0800926static void __exit tcrypt_mod_fini(void) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Kamalesh Babulal3af5b902008-04-05 21:00:57 +0800928module_init(tcrypt_mod_init);
929module_exit(tcrypt_mod_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
931module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700932module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -0700933MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
934 "(defaults to zero which uses CPU cycles instead)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
936MODULE_LICENSE("GPL");
937MODULE_DESCRIPTION("Quick & dirty crypto testing module");
938MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");