blob: 9e4974eb7825862b143b2829a7d0ea9c98f1332f [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"
30
31/*
Herbert Xuf139cfa2008-07-31 12:23:53 +080032 * Need slab memory for testing (size in number of pages).
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 */
Herbert Xuf139cfa2008-07-31 12:23:53 +080034#define TVMEMSIZE 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36/*
Herbert Xuda7f0332008-07-31 17:08:25 +080037* Used by test_cipher_speed()
Linus Torvalds1da177e2005-04-16 15:20:36 -070038*/
39#define ENCRYPT 1
40#define DECRYPT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Harald Welteebfd9bc2005-06-22 13:27:23 -070042/*
43 * Used by test_cipher_speed()
44 */
Herbert Xu6a179442005-06-22 13:29:03 -070045static unsigned int sec;
Harald Welteebfd9bc2005-06-22 13:27:23 -070046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047static int mode;
Herbert Xuf139cfa2008-07-31 12:23:53 +080048static char *tvmem[TVMEMSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50static char *check[] = {
Jonathan Lynchcd12fb902007-11-10 20:08:25 +080051 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
52 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
53 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
David Howells90831632006-12-16 12:13:14 +110054 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +080055 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +080056 "lzo", "cts", "zlib", NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070057};
58
Herbert Xuf139cfa2008-07-31 12:23:53 +080059static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
60 struct scatterlist *sg, int blen, int sec)
Herbert Xu6a179442005-06-22 13:29:03 -070061{
Herbert Xu6a179442005-06-22 13:29:03 -070062 unsigned long start, end;
63 int bcount;
64 int ret;
65
Herbert Xu6a179442005-06-22 13:29:03 -070066 for (start = jiffies, end = start + sec * HZ, bcount = 0;
67 time_before(jiffies, end); bcount++) {
68 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +100069 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -070070 else
Herbert Xucba83562006-08-13 08:26:09 +100071 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -070072
73 if (ret)
74 return ret;
75 }
76
77 printk("%d operations in %d seconds (%ld bytes)\n",
78 bcount, sec, (long)bcount * blen);
79 return 0;
80}
81
Herbert Xuf139cfa2008-07-31 12:23:53 +080082static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
83 struct scatterlist *sg, int blen)
Herbert Xu6a179442005-06-22 13:29:03 -070084{
Herbert Xu6a179442005-06-22 13:29:03 -070085 unsigned long cycles = 0;
86 int ret = 0;
87 int i;
88
Herbert Xu6a179442005-06-22 13:29:03 -070089 local_bh_disable();
90 local_irq_disable();
91
92 /* Warm-up run. */
93 for (i = 0; i < 4; i++) {
94 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +100095 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -070096 else
Herbert Xucba83562006-08-13 08:26:09 +100097 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -070098
99 if (ret)
100 goto out;
101 }
102
103 /* The real thing. */
104 for (i = 0; i < 8; i++) {
105 cycles_t start, end;
106
107 start = get_cycles();
108 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000109 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700110 else
Herbert Xucba83562006-08-13 08:26:09 +1000111 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700112 end = get_cycles();
113
114 if (ret)
115 goto out;
116
117 cycles += end - start;
118 }
119
120out:
121 local_irq_enable();
122 local_bh_enable();
123
124 if (ret == 0)
125 printk("1 operation in %lu cycles (%d bytes)\n",
126 (cycles + 4) / 8, blen);
127
128 return ret;
129}
130
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800131static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
132
Herbert Xu01b32322008-07-31 15:41:55 +0800133static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
Herbert Xuda7f0332008-07-31 17:08:25 +0800134 struct cipher_speed_template *template,
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800135 unsigned int tcount, u8 *keysize)
Harald Welteebfd9bc2005-06-22 13:27:23 -0700136{
Herbert Xudce907c2005-06-22 13:27:51 -0700137 unsigned int ret, i, j, iv_len;
Herbert Xuda7f0332008-07-31 17:08:25 +0800138 const char *key, iv[128];
Herbert Xucba83562006-08-13 08:26:09 +1000139 struct crypto_blkcipher *tfm;
140 struct blkcipher_desc desc;
141 const char *e;
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800142 u32 *b_size;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700143
144 if (enc == ENCRYPT)
145 e = "encryption";
146 else
147 e = "decryption";
Harald Welteebfd9bc2005-06-22 13:27:23 -0700148
Herbert Xucba83562006-08-13 08:26:09 +1000149 printk("\ntesting speed of %s %s\n", algo, e);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700150
Herbert Xucba83562006-08-13 08:26:09 +1000151 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700152
Herbert Xucba83562006-08-13 08:26:09 +1000153 if (IS_ERR(tfm)) {
154 printk("failed to load transform for %s: %ld\n", algo,
155 PTR_ERR(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700156 return;
157 }
Herbert Xucba83562006-08-13 08:26:09 +1000158 desc.tfm = tfm;
159 desc.flags = 0;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700160
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800161 i = 0;
162 do {
Harald Welteebfd9bc2005-06-22 13:27:23 -0700163
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800164 b_size = block_sizes;
165 do {
Herbert Xuf139cfa2008-07-31 12:23:53 +0800166 struct scatterlist sg[TVMEMSIZE];
Harald Welteebfd9bc2005-06-22 13:27:23 -0700167
Herbert Xuf139cfa2008-07-31 12:23:53 +0800168 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
169 printk("template (%u) too big for "
170 "tvmem (%lu)\n", *keysize + *b_size,
171 TVMEMSIZE * PAGE_SIZE);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800172 goto out;
173 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700174
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800175 printk("test %u (%d bit key, %d byte blocks): ", i,
176 *keysize * 8, *b_size);
177
Herbert Xuf139cfa2008-07-31 12:23:53 +0800178 memset(tvmem[0], 0xff, PAGE_SIZE);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800179
180 /* set key, plain text and IV */
Herbert Xuda7f0332008-07-31 17:08:25 +0800181 key = tvmem[0];
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800182 for (j = 0; j < tcount; j++) {
183 if (template[j].klen == *keysize) {
184 key = template[j].key;
185 break;
186 }
187 }
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800188
189 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
190 if (ret) {
191 printk("setkey() failed flags=%x\n",
192 crypto_blkcipher_get_flags(tfm));
193 goto out;
194 }
195
Herbert Xuf139cfa2008-07-31 12:23:53 +0800196 sg_init_table(sg, TVMEMSIZE);
197 sg_set_buf(sg, tvmem[0] + *keysize,
198 PAGE_SIZE - *keysize);
199 for (j = 1; j < TVMEMSIZE; j++) {
200 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
201 memset (tvmem[j], 0xff, PAGE_SIZE);
202 }
203
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800204 iv_len = crypto_blkcipher_ivsize(tfm);
205 if (iv_len) {
206 memset(&iv, 0xff, iv_len);
207 crypto_blkcipher_set_iv(tfm, iv, iv_len);
208 }
209
210 if (sec)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800211 ret = test_cipher_jiffies(&desc, enc, sg,
212 *b_size, sec);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800213 else
Herbert Xuf139cfa2008-07-31 12:23:53 +0800214 ret = test_cipher_cycles(&desc, enc, sg,
215 *b_size);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800216
217 if (ret) {
218 printk("%s() failed flags=%x\n", e, desc.flags);
Herbert Xudce907c2005-06-22 13:27:51 -0700219 break;
220 }
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800221 b_size++;
222 i++;
223 } while (*b_size);
224 keysize++;
225 } while (*keysize);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700226
227out:
Herbert Xucba83562006-08-13 08:26:09 +1000228 crypto_free_blkcipher(tfm);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700229}
230
Herbert Xuf139cfa2008-07-31 12:23:53 +0800231static int test_hash_jiffies_digest(struct hash_desc *desc,
232 struct scatterlist *sg, int blen,
Herbert Xue9d41162006-08-19 21:38:49 +1000233 char *out, int sec)
Michal Ludvige8057922006-05-30 22:04:19 +1000234{
Michal Ludvige8057922006-05-30 22:04:19 +1000235 unsigned long start, end;
Herbert Xue9d41162006-08-19 21:38:49 +1000236 int bcount;
237 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000238
239 for (start = jiffies, end = start + sec * HZ, bcount = 0;
240 time_before(jiffies, end); bcount++) {
Herbert Xue9d41162006-08-19 21:38:49 +1000241 ret = crypto_hash_digest(desc, sg, blen, out);
242 if (ret)
243 return ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000244 }
245
246 printk("%6u opers/sec, %9lu bytes/sec\n",
247 bcount / sec, ((long)bcount * blen) / sec);
248
Herbert Xue9d41162006-08-19 21:38:49 +1000249 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000250}
251
Herbert Xuf139cfa2008-07-31 12:23:53 +0800252static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
253 int blen, int plen, char *out, int sec)
Herbert Xue9d41162006-08-19 21:38:49 +1000254{
Herbert Xue9d41162006-08-19 21:38:49 +1000255 unsigned long start, end;
256 int bcount, pcount;
257 int ret;
258
259 if (plen == blen)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800260 return test_hash_jiffies_digest(desc, sg, blen, out, sec);
Herbert Xua5a613a2007-10-27 00:51:21 -0700261
Herbert Xue9d41162006-08-19 21:38:49 +1000262 for (start = jiffies, end = start + sec * HZ, bcount = 0;
263 time_before(jiffies, end); bcount++) {
264 ret = crypto_hash_init(desc);
265 if (ret)
266 return ret;
267 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000268 ret = crypto_hash_update(desc, sg, plen);
269 if (ret)
270 return ret;
271 }
272 /* we assume there is enough space in 'out' for the result */
273 ret = crypto_hash_final(desc, out);
274 if (ret)
275 return ret;
276 }
277
278 printk("%6u opers/sec, %9lu bytes/sec\n",
279 bcount / sec, ((long)bcount * blen) / sec);
280
281 return 0;
282}
283
Herbert Xuf139cfa2008-07-31 12:23:53 +0800284static int test_hash_cycles_digest(struct hash_desc *desc,
285 struct scatterlist *sg, int blen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000286{
Michal Ludvige8057922006-05-30 22:04:19 +1000287 unsigned long cycles = 0;
Herbert Xue9d41162006-08-19 21:38:49 +1000288 int i;
289 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000290
291 local_bh_disable();
292 local_irq_disable();
293
294 /* Warm-up run. */
295 for (i = 0; i < 4; i++) {
Herbert Xue9d41162006-08-19 21:38:49 +1000296 ret = crypto_hash_digest(desc, sg, blen, out);
297 if (ret)
298 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000299 }
300
301 /* The real thing. */
302 for (i = 0; i < 8; i++) {
303 cycles_t start, end;
304
Michal Ludvige8057922006-05-30 22:04:19 +1000305 start = get_cycles();
306
Herbert Xue9d41162006-08-19 21:38:49 +1000307 ret = crypto_hash_digest(desc, sg, blen, out);
308 if (ret)
309 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000310
311 end = get_cycles();
312
313 cycles += end - start;
314 }
315
Herbert Xue9d41162006-08-19 21:38:49 +1000316out:
Michal Ludvige8057922006-05-30 22:04:19 +1000317 local_irq_enable();
318 local_bh_enable();
319
Herbert Xue9d41162006-08-19 21:38:49 +1000320 if (ret)
321 return ret;
322
Michal Ludvige8057922006-05-30 22:04:19 +1000323 printk("%6lu cycles/operation, %4lu cycles/byte\n",
324 cycles / 8, cycles / (8 * blen));
325
Herbert Xue9d41162006-08-19 21:38:49 +1000326 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000327}
328
Herbert Xuf139cfa2008-07-31 12:23:53 +0800329static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
330 int blen, int plen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000331{
Herbert Xue9d41162006-08-19 21:38:49 +1000332 unsigned long cycles = 0;
333 int i, pcount;
334 int ret;
335
336 if (plen == blen)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800337 return test_hash_cycles_digest(desc, sg, blen, out);
Herbert Xua5a613a2007-10-27 00:51:21 -0700338
Herbert Xue9d41162006-08-19 21:38:49 +1000339 local_bh_disable();
340 local_irq_disable();
341
342 /* Warm-up run. */
343 for (i = 0; i < 4; i++) {
344 ret = crypto_hash_init(desc);
345 if (ret)
346 goto out;
347 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000348 ret = crypto_hash_update(desc, sg, plen);
349 if (ret)
350 goto out;
351 }
Herbert Xu29059d12007-05-18 16:25:19 +1000352 ret = crypto_hash_final(desc, out);
Herbert Xue9d41162006-08-19 21:38:49 +1000353 if (ret)
354 goto out;
355 }
356
357 /* The real thing. */
358 for (i = 0; i < 8; i++) {
359 cycles_t start, end;
360
361 start = get_cycles();
362
363 ret = crypto_hash_init(desc);
364 if (ret)
365 goto out;
366 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000367 ret = crypto_hash_update(desc, sg, plen);
368 if (ret)
369 goto out;
370 }
371 ret = crypto_hash_final(desc, out);
372 if (ret)
373 goto out;
374
375 end = get_cycles();
376
377 cycles += end - start;
378 }
379
380out:
381 local_irq_enable();
382 local_bh_enable();
383
384 if (ret)
385 return ret;
386
387 printk("%6lu cycles/operation, %4lu cycles/byte\n",
388 cycles / 8, cycles / (8 * blen));
389
390 return 0;
391}
392
Herbert Xu01b32322008-07-31 15:41:55 +0800393static void test_hash_speed(const char *algo, unsigned int sec,
394 struct hash_speed *speed)
Herbert Xue9d41162006-08-19 21:38:49 +1000395{
Herbert Xuf139cfa2008-07-31 12:23:53 +0800396 struct scatterlist sg[TVMEMSIZE];
Herbert Xue9d41162006-08-19 21:38:49 +1000397 struct crypto_hash *tfm;
398 struct hash_desc desc;
Frank Seidel376bacb2009-03-29 15:18:39 +0800399 static char output[1024];
Michal Ludvige8057922006-05-30 22:04:19 +1000400 int i;
Herbert Xue9d41162006-08-19 21:38:49 +1000401 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000402
Frank Seidel376bacb2009-03-29 15:18:39 +0800403 printk(KERN_INFO "\ntesting speed of %s\n", algo);
Michal Ludvige8057922006-05-30 22:04:19 +1000404
Herbert Xue9d41162006-08-19 21:38:49 +1000405 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
Michal Ludvige8057922006-05-30 22:04:19 +1000406
Herbert Xue9d41162006-08-19 21:38:49 +1000407 if (IS_ERR(tfm)) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800408 printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
Herbert Xue9d41162006-08-19 21:38:49 +1000409 PTR_ERR(tfm));
Michal Ludvige8057922006-05-30 22:04:19 +1000410 return;
411 }
412
Herbert Xue9d41162006-08-19 21:38:49 +1000413 desc.tfm = tfm;
414 desc.flags = 0;
415
416 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800417 printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
Herbert Xue9d41162006-08-19 21:38:49 +1000418 crypto_hash_digestsize(tfm), sizeof(output));
Michal Ludvige8057922006-05-30 22:04:19 +1000419 goto out;
420 }
421
Herbert Xuf139cfa2008-07-31 12:23:53 +0800422 sg_init_table(sg, TVMEMSIZE);
423 for (i = 0; i < TVMEMSIZE; i++) {
424 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
425 memset(tvmem[i], 0xff, PAGE_SIZE);
426 }
427
Michal Ludvige8057922006-05-30 22:04:19 +1000428 for (i = 0; speed[i].blen != 0; i++) {
Herbert Xuf139cfa2008-07-31 12:23:53 +0800429 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800430 printk(KERN_ERR
431 "template (%u) too big for tvmem (%lu)\n",
Herbert Xuf139cfa2008-07-31 12:23:53 +0800432 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
Michal Ludvige8057922006-05-30 22:04:19 +1000433 goto out;
434 }
435
Frank Seidel376bacb2009-03-29 15:18:39 +0800436 printk(KERN_INFO "test%3u "
437 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
Michal Ludvige8057922006-05-30 22:04:19 +1000438 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
439
Michal Ludvige8057922006-05-30 22:04:19 +1000440 if (sec)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800441 ret = test_hash_jiffies(&desc, sg, speed[i].blen,
Herbert Xue9d41162006-08-19 21:38:49 +1000442 speed[i].plen, output, sec);
Michal Ludvige8057922006-05-30 22:04:19 +1000443 else
Herbert Xuf139cfa2008-07-31 12:23:53 +0800444 ret = test_hash_cycles(&desc, sg, speed[i].blen,
Herbert Xue9d41162006-08-19 21:38:49 +1000445 speed[i].plen, output);
446
447 if (ret) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800448 printk(KERN_ERR "hashing failed ret=%d\n", ret);
Herbert Xue9d41162006-08-19 21:38:49 +1000449 break;
450 }
Michal Ludvige8057922006-05-30 22:04:19 +1000451 }
452
453out:
Herbert Xue9d41162006-08-19 21:38:49 +1000454 crypto_free_hash(tfm);
Michal Ludvige8057922006-05-30 22:04:19 +1000455}
456
Herbert Xuef2736f2005-06-22 13:26:03 -0700457static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458{
459 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -0700460
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 while (*name) {
462 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +1000463 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +1000464 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467}
468
Herbert Xu01b32322008-07-31 15:41:55 +0800469static inline int tcrypt_test(const char *alg)
470{
471 return alg_test(alg, alg, 0, 0);
472}
473
474static void do_test(int m)
475{
476 int i;
477
478 switch (m) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 case 0:
Herbert Xu01b32322008-07-31 15:41:55 +0800480 for (i = 1; i < 200; i++)
481 do_test(i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 break;
483
484 case 1:
Herbert Xu01b32322008-07-31 15:41:55 +0800485 tcrypt_test("md5");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 break;
487
488 case 2:
Herbert Xu01b32322008-07-31 15:41:55 +0800489 tcrypt_test("sha1");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 break;
491
492 case 3:
Herbert Xu01b32322008-07-31 15:41:55 +0800493 tcrypt_test("ecb(des)");
494 tcrypt_test("cbc(des)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 break;
496
497 case 4:
Herbert Xu01b32322008-07-31 15:41:55 +0800498 tcrypt_test("ecb(des3_ede)");
499 tcrypt_test("cbc(des3_ede)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 break;
501
502 case 5:
Herbert Xu01b32322008-07-31 15:41:55 +0800503 tcrypt_test("md4");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 case 6:
Herbert Xu01b32322008-07-31 15:41:55 +0800507 tcrypt_test("sha256");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 case 7:
Herbert Xu01b32322008-07-31 15:41:55 +0800511 tcrypt_test("ecb(blowfish)");
512 tcrypt_test("cbc(blowfish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 break;
514
515 case 8:
Herbert Xu01b32322008-07-31 15:41:55 +0800516 tcrypt_test("ecb(twofish)");
517 tcrypt_test("cbc(twofish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 case 9:
Herbert Xu01b32322008-07-31 15:41:55 +0800521 tcrypt_test("ecb(serpent)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 break;
523
524 case 10:
Herbert Xu01b32322008-07-31 15:41:55 +0800525 tcrypt_test("ecb(aes)");
526 tcrypt_test("cbc(aes)");
527 tcrypt_test("lrw(aes)");
528 tcrypt_test("xts(aes)");
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +0800529 tcrypt_test("ctr(aes)");
Herbert Xu01b32322008-07-31 15:41:55 +0800530 tcrypt_test("rfc3686(ctr(aes))");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 break;
532
533 case 11:
Herbert Xu01b32322008-07-31 15:41:55 +0800534 tcrypt_test("sha384");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 case 12:
Herbert Xu01b32322008-07-31 15:41:55 +0800538 tcrypt_test("sha512");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 break;
540
541 case 13:
Herbert Xu01b32322008-07-31 15:41:55 +0800542 tcrypt_test("deflate");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 break;
544
545 case 14:
Herbert Xu01b32322008-07-31 15:41:55 +0800546 tcrypt_test("ecb(cast5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 break;
548
549 case 15:
Herbert Xu01b32322008-07-31 15:41:55 +0800550 tcrypt_test("ecb(cast6)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 break;
552
553 case 16:
Herbert Xu01b32322008-07-31 15:41:55 +0800554 tcrypt_test("ecb(arc4)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 break;
556
557 case 17:
Herbert Xu01b32322008-07-31 15:41:55 +0800558 tcrypt_test("michael_mic");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 break;
560
561 case 18:
Herbert Xu01b32322008-07-31 15:41:55 +0800562 tcrypt_test("crc32c");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 break;
564
565 case 19:
Herbert Xu01b32322008-07-31 15:41:55 +0800566 tcrypt_test("ecb(tea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 break;
568
569 case 20:
Herbert Xu01b32322008-07-31 15:41:55 +0800570 tcrypt_test("ecb(xtea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 break;
572
573 case 21:
Herbert Xu01b32322008-07-31 15:41:55 +0800574 tcrypt_test("ecb(khazad)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 break;
576
577 case 22:
Herbert Xu01b32322008-07-31 15:41:55 +0800578 tcrypt_test("wp512");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 break;
580
581 case 23:
Herbert Xu01b32322008-07-31 15:41:55 +0800582 tcrypt_test("wp384");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 break;
584
585 case 24:
Herbert Xu01b32322008-07-31 15:41:55 +0800586 tcrypt_test("wp256");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 break;
588
589 case 25:
Herbert Xu01b32322008-07-31 15:41:55 +0800590 tcrypt_test("ecb(tnepres)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 break;
592
593 case 26:
Herbert Xu01b32322008-07-31 15:41:55 +0800594 tcrypt_test("ecb(anubis)");
595 tcrypt_test("cbc(anubis)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 break;
597
598 case 27:
Herbert Xu01b32322008-07-31 15:41:55 +0800599 tcrypt_test("tgr192");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 break;
601
602 case 28:
603
Herbert Xu01b32322008-07-31 15:41:55 +0800604 tcrypt_test("tgr160");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 break;
606
607 case 29:
Herbert Xu01b32322008-07-31 15:41:55 +0800608 tcrypt_test("tgr128");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 break;
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +0800610
Aaron Grothefb4f10e2005-09-01 17:42:46 -0700611 case 30:
Herbert Xu01b32322008-07-31 15:41:55 +0800612 tcrypt_test("ecb(xeta)");
Aaron Grothefb4f10e2005-09-01 17:42:46 -0700613 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
David Howells90831632006-12-16 12:13:14 +1100615 case 31:
Herbert Xu01b32322008-07-31 15:41:55 +0800616 tcrypt_test("pcbc(fcrypt)");
David Howells90831632006-12-16 12:13:14 +1100617 break;
618
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100619 case 32:
Herbert Xu01b32322008-07-31 15:41:55 +0800620 tcrypt_test("ecb(camellia)");
621 tcrypt_test("cbc(camellia)");
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100622 break;
Jonathan Lynchcd12fb902007-11-10 20:08:25 +0800623 case 33:
Herbert Xu01b32322008-07-31 15:41:55 +0800624 tcrypt_test("sha224");
Jonathan Lynchcd12fb902007-11-10 20:08:25 +0800625 break;
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100626
Tan Swee Heng2407d602007-11-23 19:45:00 +0800627 case 34:
Herbert Xu01b32322008-07-31 15:41:55 +0800628 tcrypt_test("salsa20");
Tan Swee Heng2407d602007-11-23 19:45:00 +0800629 break;
630
Herbert Xu8df213d2007-12-02 14:55:47 +1100631 case 35:
Herbert Xu01b32322008-07-31 15:41:55 +0800632 tcrypt_test("gcm(aes)");
Herbert Xu8df213d2007-12-02 14:55:47 +1100633 break;
634
Zoltan Sogor0b77abb2007-12-07 16:53:23 +0800635 case 36:
Herbert Xu01b32322008-07-31 15:41:55 +0800636 tcrypt_test("lzo");
Zoltan Sogor0b77abb2007-12-07 16:53:23 +0800637 break;
638
Joy Latten93cc74e2007-12-12 20:24:22 +0800639 case 37:
Herbert Xu01b32322008-07-31 15:41:55 +0800640 tcrypt_test("ccm(aes)");
Joy Latten93cc74e2007-12-12 20:24:22 +0800641 break;
642
Kevin Coffman76cb9522008-03-24 21:26:16 +0800643 case 38:
Herbert Xu01b32322008-07-31 15:41:55 +0800644 tcrypt_test("cts(cbc(aes))");
Kevin Coffman76cb9522008-03-24 21:26:16 +0800645 break;
646
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800647 case 39:
Herbert Xu01b32322008-07-31 15:41:55 +0800648 tcrypt_test("rmd128");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800649 break;
650
651 case 40:
Herbert Xu01b32322008-07-31 15:41:55 +0800652 tcrypt_test("rmd160");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800653 break;
654
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +0800655 case 41:
Herbert Xu01b32322008-07-31 15:41:55 +0800656 tcrypt_test("rmd256");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +0800657 break;
658
659 case 42:
Herbert Xu01b32322008-07-31 15:41:55 +0800660 tcrypt_test("rmd320");
661 break;
662
663 case 43:
664 tcrypt_test("ecb(seed)");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +0800665 break;
666
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +0800667 case 44:
668 tcrypt_test("zlib");
669 break;
670
Jarod Wilson5d667322009-05-04 19:23:40 +0800671 case 45:
672 tcrypt_test("rfc4309(ccm(aes))");
673 break;
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 case 100:
Herbert Xu01b32322008-07-31 15:41:55 +0800676 tcrypt_test("hmac(md5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 case 101:
Herbert Xu01b32322008-07-31 15:41:55 +0800680 tcrypt_test("hmac(sha1)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700682
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 case 102:
Herbert Xu01b32322008-07-31 15:41:55 +0800684 tcrypt_test("hmac(sha256)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 break;
686
Andrew Donofrioa28091a2006-12-10 12:10:20 +1100687 case 103:
Herbert Xu01b32322008-07-31 15:41:55 +0800688 tcrypt_test("hmac(sha384)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +1100689 break;
690
691 case 104:
Herbert Xu01b32322008-07-31 15:41:55 +0800692 tcrypt_test("hmac(sha512)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +1100693 break;
Herbert Xu38ed9ab2008-01-01 15:59:28 +1100694
Jonathan Lynchcd12fb902007-11-10 20:08:25 +0800695 case 105:
Herbert Xu01b32322008-07-31 15:41:55 +0800696 tcrypt_test("hmac(sha224)");
Jonathan Lynchcd12fb902007-11-10 20:08:25 +0800697 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Herbert Xu38ed9ab2008-01-01 15:59:28 +1100699 case 106:
Herbert Xu01b32322008-07-31 15:41:55 +0800700 tcrypt_test("xcbc(aes)");
Herbert Xu38ed9ab2008-01-01 15:59:28 +1100701 break;
702
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800703 case 107:
Herbert Xu01b32322008-07-31 15:41:55 +0800704 tcrypt_test("hmac(rmd128)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800705 break;
706
707 case 108:
Herbert Xu01b32322008-07-31 15:41:55 +0800708 tcrypt_test("hmac(rmd160)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800709 break;
710
Jarod Wilsone08ca2d2009-05-04 19:46:29 +0800711 case 150:
712 tcrypt_test("ansi_cprng");
713 break;
714
Harald Welteebfd9bc2005-06-22 13:27:23 -0700715 case 200:
Herbert Xucba83562006-08-13 08:26:09 +1000716 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800717 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +1000718 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800719 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +1000720 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800721 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +1000722 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800723 speed_template_16_24_32);
Rik Snelf3d10442006-11-29 19:01:41 +1100724 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800725 speed_template_32_40_48);
Rik Snelf3d10442006-11-29 19:01:41 +1100726 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800727 speed_template_32_40_48);
Rik Snelf19f5112007-09-19 20:23:13 +0800728 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800729 speed_template_32_48_64);
Rik Snelf19f5112007-09-19 20:23:13 +0800730 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800731 speed_template_32_48_64);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700732 break;
733
734 case 201:
Herbert Xucba83562006-08-13 08:26:09 +1000735 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +0800736 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800737 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +1000738 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +0800739 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800740 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +1000741 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +0800742 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800743 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +1000744 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +0800745 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800746 speed_template_24);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700747 break;
748
749 case 202:
Herbert Xucba83562006-08-13 08:26:09 +1000750 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800751 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +1000752 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800753 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +1000754 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800755 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +1000756 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800757 speed_template_16_24_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700758 break;
759
760 case 203:
Herbert Xucba83562006-08-13 08:26:09 +1000761 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800762 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +1000763 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800764 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +1000765 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800766 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +1000767 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800768 speed_template_8_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700769 break;
770
771 case 204:
Herbert Xucba83562006-08-13 08:26:09 +1000772 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800773 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +1000774 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800775 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +1000776 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800777 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +1000778 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800779 speed_template_8);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700780 break;
781
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100782 case 205:
783 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800784 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100785 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800786 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100787 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800788 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100789 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800790 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100791 break;
792
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +0800793 case 206:
794 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800795 speed_template_16_32);
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +0800796 break;
797
Michal Ludvige8057922006-05-30 22:04:19 +1000798 case 300:
799 /* fall through */
800
801 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +1000802 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000803 if (mode > 300 && mode < 400) break;
804
805 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +1000806 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000807 if (mode > 300 && mode < 400) break;
808
809 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +1000810 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000811 if (mode > 300 && mode < 400) break;
812
813 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +1000814 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000815 if (mode > 300 && mode < 400) break;
816
817 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +1000818 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000819 if (mode > 300 && mode < 400) break;
820
821 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +1000822 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000823 if (mode > 300 && mode < 400) break;
824
825 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +1000826 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000827 if (mode > 300 && mode < 400) break;
828
829 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +1000830 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000831 if (mode > 300 && mode < 400) break;
832
833 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +1000834 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000835 if (mode > 300 && mode < 400) break;
836
837 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +1000838 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000839 if (mode > 300 && mode < 400) break;
840
841 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +1000842 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000843 if (mode > 300 && mode < 400) break;
844
845 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +1000846 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000847 if (mode > 300 && mode < 400) break;
848
Jonathan Lynchcd12fb902007-11-10 20:08:25 +0800849 case 313:
850 test_hash_speed("sha224", sec, generic_hash_speed_template);
851 if (mode > 300 && mode < 400) break;
852
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800853 case 314:
854 test_hash_speed("rmd128", sec, generic_hash_speed_template);
855 if (mode > 300 && mode < 400) break;
856
857 case 315:
858 test_hash_speed("rmd160", sec, generic_hash_speed_template);
859 if (mode > 300 && mode < 400) break;
860
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +0800861 case 316:
862 test_hash_speed("rmd256", sec, generic_hash_speed_template);
863 if (mode > 300 && mode < 400) break;
864
865 case 317:
866 test_hash_speed("rmd320", sec, generic_hash_speed_template);
867 if (mode > 300 && mode < 400) break;
868
Michal Ludvige8057922006-05-30 22:04:19 +1000869 case 399:
870 break;
871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 case 1000:
873 test_available();
874 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 }
876}
877
Kamalesh Babulal3af5b902008-04-05 21:00:57 +0800878static int __init tcrypt_mod_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879{
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800880 int err = -ENOMEM;
Herbert Xuf139cfa2008-07-31 12:23:53 +0800881 int i;
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800882
Herbert Xuf139cfa2008-07-31 12:23:53 +0800883 for (i = 0; i < TVMEMSIZE; i++) {
884 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
885 if (!tvmem[i])
886 goto err_free_tv;
887 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
Herbert Xu01b32322008-07-31 15:41:55 +0800889 do_test(mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
Michal Ludvig14fdf472006-05-30 14:49:38 +1000891 /* We intentionaly return -EAGAIN to prevent keeping
892 * the module. It does all its work from init()
893 * and doesn't offer any runtime functionality
894 * => we don't need it in the memory, do we?
895 * -- mludvig
896 */
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800897 err = -EAGAIN;
898
Herbert Xuf139cfa2008-07-31 12:23:53 +0800899err_free_tv:
900 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
901 free_page((unsigned long)tvmem[i]);
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800902
903 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904}
905
906/*
907 * If an init function is provided, an exit function must also be provided
908 * to allow module unload.
909 */
Kamalesh Babulal3af5b902008-04-05 21:00:57 +0800910static void __exit tcrypt_mod_fini(void) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
Kamalesh Babulal3af5b902008-04-05 21:00:57 +0800912module_init(tcrypt_mod_init);
913module_exit(tcrypt_mod_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700916module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -0700917MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
918 "(defaults to zero which uses CPU cycles instead)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
920MODULE_LICENSE("GPL");
921MODULE_DESCRIPTION("Quick & dirty crypto testing module");
922MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");