blob: a890a6792c7b076cbada66fc385090442ee9ffa1 [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
Steffen Klasserta873a5f2009-06-19 19:46:53 +080048static char *alg = NULL;
49static u32 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050static int mode;
Herbert Xuf139cfa2008-07-31 12:23:53 +080051static char *tvmem[TVMEMSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53static char *check[] = {
Jonathan Lynchcd12fb902007-11-10 20:08:25 +080054 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
55 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
56 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
David Howells90831632006-12-16 12:13:14 +110057 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +080058 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +080059 "lzo", "cts", "zlib", NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070060};
61
Herbert Xuf139cfa2008-07-31 12:23:53 +080062static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
63 struct scatterlist *sg, int blen, int sec)
Herbert Xu6a179442005-06-22 13:29:03 -070064{
Herbert Xu6a179442005-06-22 13:29:03 -070065 unsigned long start, end;
66 int bcount;
67 int ret;
68
Herbert Xu6a179442005-06-22 13:29:03 -070069 for (start = jiffies, end = start + sec * HZ, bcount = 0;
70 time_before(jiffies, end); bcount++) {
71 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +100072 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -070073 else
Herbert Xucba83562006-08-13 08:26:09 +100074 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -070075
76 if (ret)
77 return ret;
78 }
79
80 printk("%d operations in %d seconds (%ld bytes)\n",
81 bcount, sec, (long)bcount * blen);
82 return 0;
83}
84
Herbert Xuf139cfa2008-07-31 12:23:53 +080085static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
86 struct scatterlist *sg, int blen)
Herbert Xu6a179442005-06-22 13:29:03 -070087{
Herbert Xu6a179442005-06-22 13:29:03 -070088 unsigned long cycles = 0;
89 int ret = 0;
90 int i;
91
Herbert Xu6a179442005-06-22 13:29:03 -070092 local_bh_disable();
93 local_irq_disable();
94
95 /* Warm-up run. */
96 for (i = 0; i < 4; i++) {
97 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +100098 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -070099 else
Herbert Xucba83562006-08-13 08:26:09 +1000100 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700101
102 if (ret)
103 goto out;
104 }
105
106 /* The real thing. */
107 for (i = 0; i < 8; i++) {
108 cycles_t start, end;
109
110 start = get_cycles();
111 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000112 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700113 else
Herbert Xucba83562006-08-13 08:26:09 +1000114 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700115 end = get_cycles();
116
117 if (ret)
118 goto out;
119
120 cycles += end - start;
121 }
122
123out:
124 local_irq_enable();
125 local_bh_enable();
126
127 if (ret == 0)
128 printk("1 operation in %lu cycles (%d bytes)\n",
129 (cycles + 4) / 8, blen);
130
131 return ret;
132}
133
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800134static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
135
Herbert Xu01b32322008-07-31 15:41:55 +0800136static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
Herbert Xuda7f0332008-07-31 17:08:25 +0800137 struct cipher_speed_template *template,
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800138 unsigned int tcount, u8 *keysize)
Harald Welteebfd9bc2005-06-22 13:27:23 -0700139{
Herbert Xudce907c2005-06-22 13:27:51 -0700140 unsigned int ret, i, j, iv_len;
Herbert Xuda7f0332008-07-31 17:08:25 +0800141 const char *key, iv[128];
Herbert Xucba83562006-08-13 08:26:09 +1000142 struct crypto_blkcipher *tfm;
143 struct blkcipher_desc desc;
144 const char *e;
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800145 u32 *b_size;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700146
147 if (enc == ENCRYPT)
148 e = "encryption";
149 else
150 e = "decryption";
Harald Welteebfd9bc2005-06-22 13:27:23 -0700151
Herbert Xucba83562006-08-13 08:26:09 +1000152 printk("\ntesting speed of %s %s\n", algo, e);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700153
Herbert Xucba83562006-08-13 08:26:09 +1000154 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700155
Herbert Xucba83562006-08-13 08:26:09 +1000156 if (IS_ERR(tfm)) {
157 printk("failed to load transform for %s: %ld\n", algo,
158 PTR_ERR(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700159 return;
160 }
Herbert Xucba83562006-08-13 08:26:09 +1000161 desc.tfm = tfm;
162 desc.flags = 0;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700163
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800164 i = 0;
165 do {
Harald Welteebfd9bc2005-06-22 13:27:23 -0700166
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800167 b_size = block_sizes;
168 do {
Herbert Xuf139cfa2008-07-31 12:23:53 +0800169 struct scatterlist sg[TVMEMSIZE];
Harald Welteebfd9bc2005-06-22 13:27:23 -0700170
Herbert Xuf139cfa2008-07-31 12:23:53 +0800171 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
172 printk("template (%u) too big for "
173 "tvmem (%lu)\n", *keysize + *b_size,
174 TVMEMSIZE * PAGE_SIZE);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800175 goto out;
176 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700177
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800178 printk("test %u (%d bit key, %d byte blocks): ", i,
179 *keysize * 8, *b_size);
180
Herbert Xuf139cfa2008-07-31 12:23:53 +0800181 memset(tvmem[0], 0xff, PAGE_SIZE);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800182
183 /* set key, plain text and IV */
Herbert Xuda7f0332008-07-31 17:08:25 +0800184 key = tvmem[0];
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800185 for (j = 0; j < tcount; j++) {
186 if (template[j].klen == *keysize) {
187 key = template[j].key;
188 break;
189 }
190 }
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800191
192 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
193 if (ret) {
194 printk("setkey() failed flags=%x\n",
195 crypto_blkcipher_get_flags(tfm));
196 goto out;
197 }
198
Herbert Xuf139cfa2008-07-31 12:23:53 +0800199 sg_init_table(sg, TVMEMSIZE);
200 sg_set_buf(sg, tvmem[0] + *keysize,
201 PAGE_SIZE - *keysize);
202 for (j = 1; j < TVMEMSIZE; j++) {
203 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
204 memset (tvmem[j], 0xff, PAGE_SIZE);
205 }
206
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800207 iv_len = crypto_blkcipher_ivsize(tfm);
208 if (iv_len) {
209 memset(&iv, 0xff, iv_len);
210 crypto_blkcipher_set_iv(tfm, iv, iv_len);
211 }
212
213 if (sec)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800214 ret = test_cipher_jiffies(&desc, enc, sg,
215 *b_size, sec);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800216 else
Herbert Xuf139cfa2008-07-31 12:23:53 +0800217 ret = test_cipher_cycles(&desc, enc, sg,
218 *b_size);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800219
220 if (ret) {
221 printk("%s() failed flags=%x\n", e, desc.flags);
Herbert Xudce907c2005-06-22 13:27:51 -0700222 break;
223 }
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800224 b_size++;
225 i++;
226 } while (*b_size);
227 keysize++;
228 } while (*keysize);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700229
230out:
Herbert Xucba83562006-08-13 08:26:09 +1000231 crypto_free_blkcipher(tfm);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700232}
233
Herbert Xuf139cfa2008-07-31 12:23:53 +0800234static int test_hash_jiffies_digest(struct hash_desc *desc,
235 struct scatterlist *sg, int blen,
Herbert Xue9d41162006-08-19 21:38:49 +1000236 char *out, int sec)
Michal Ludvige8057922006-05-30 22:04:19 +1000237{
Michal Ludvige8057922006-05-30 22:04:19 +1000238 unsigned long start, end;
Herbert Xue9d41162006-08-19 21:38:49 +1000239 int bcount;
240 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000241
242 for (start = jiffies, end = start + sec * HZ, bcount = 0;
243 time_before(jiffies, end); bcount++) {
Herbert Xue9d41162006-08-19 21:38:49 +1000244 ret = crypto_hash_digest(desc, sg, blen, out);
245 if (ret)
246 return ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000247 }
248
249 printk("%6u opers/sec, %9lu bytes/sec\n",
250 bcount / sec, ((long)bcount * blen) / sec);
251
Herbert Xue9d41162006-08-19 21:38:49 +1000252 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000253}
254
Herbert Xuf139cfa2008-07-31 12:23:53 +0800255static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
256 int blen, int plen, char *out, int sec)
Herbert Xue9d41162006-08-19 21:38:49 +1000257{
Herbert Xue9d41162006-08-19 21:38:49 +1000258 unsigned long start, end;
259 int bcount, pcount;
260 int ret;
261
262 if (plen == blen)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800263 return test_hash_jiffies_digest(desc, sg, blen, out, sec);
Herbert Xua5a613a2007-10-27 00:51:21 -0700264
Herbert Xue9d41162006-08-19 21:38:49 +1000265 for (start = jiffies, end = start + sec * HZ, bcount = 0;
266 time_before(jiffies, end); bcount++) {
267 ret = crypto_hash_init(desc);
268 if (ret)
269 return ret;
270 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000271 ret = crypto_hash_update(desc, sg, plen);
272 if (ret)
273 return ret;
274 }
275 /* we assume there is enough space in 'out' for the result */
276 ret = crypto_hash_final(desc, out);
277 if (ret)
278 return ret;
279 }
280
281 printk("%6u opers/sec, %9lu bytes/sec\n",
282 bcount / sec, ((long)bcount * blen) / sec);
283
284 return 0;
285}
286
Herbert Xuf139cfa2008-07-31 12:23:53 +0800287static int test_hash_cycles_digest(struct hash_desc *desc,
288 struct scatterlist *sg, int blen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000289{
Michal Ludvige8057922006-05-30 22:04:19 +1000290 unsigned long cycles = 0;
Herbert Xue9d41162006-08-19 21:38:49 +1000291 int i;
292 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000293
294 local_bh_disable();
295 local_irq_disable();
296
297 /* Warm-up run. */
298 for (i = 0; i < 4; i++) {
Herbert Xue9d41162006-08-19 21:38:49 +1000299 ret = crypto_hash_digest(desc, sg, blen, out);
300 if (ret)
301 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000302 }
303
304 /* The real thing. */
305 for (i = 0; i < 8; i++) {
306 cycles_t start, end;
307
Michal Ludvige8057922006-05-30 22:04:19 +1000308 start = get_cycles();
309
Herbert Xue9d41162006-08-19 21:38:49 +1000310 ret = crypto_hash_digest(desc, sg, blen, out);
311 if (ret)
312 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000313
314 end = get_cycles();
315
316 cycles += end - start;
317 }
318
Herbert Xue9d41162006-08-19 21:38:49 +1000319out:
Michal Ludvige8057922006-05-30 22:04:19 +1000320 local_irq_enable();
321 local_bh_enable();
322
Herbert Xue9d41162006-08-19 21:38:49 +1000323 if (ret)
324 return ret;
325
Michal Ludvige8057922006-05-30 22:04:19 +1000326 printk("%6lu cycles/operation, %4lu cycles/byte\n",
327 cycles / 8, cycles / (8 * blen));
328
Herbert Xue9d41162006-08-19 21:38:49 +1000329 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000330}
331
Herbert Xuf139cfa2008-07-31 12:23:53 +0800332static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
333 int blen, int plen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000334{
Herbert Xue9d41162006-08-19 21:38:49 +1000335 unsigned long cycles = 0;
336 int i, pcount;
337 int ret;
338
339 if (plen == blen)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800340 return test_hash_cycles_digest(desc, sg, blen, out);
Herbert Xua5a613a2007-10-27 00:51:21 -0700341
Herbert Xue9d41162006-08-19 21:38:49 +1000342 local_bh_disable();
343 local_irq_disable();
344
345 /* Warm-up run. */
346 for (i = 0; i < 4; i++) {
347 ret = crypto_hash_init(desc);
348 if (ret)
349 goto out;
350 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000351 ret = crypto_hash_update(desc, sg, plen);
352 if (ret)
353 goto out;
354 }
Herbert Xu29059d12007-05-18 16:25:19 +1000355 ret = crypto_hash_final(desc, out);
Herbert Xue9d41162006-08-19 21:38:49 +1000356 if (ret)
357 goto out;
358 }
359
360 /* The real thing. */
361 for (i = 0; i < 8; i++) {
362 cycles_t start, end;
363
364 start = get_cycles();
365
366 ret = crypto_hash_init(desc);
367 if (ret)
368 goto out;
369 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000370 ret = crypto_hash_update(desc, sg, plen);
371 if (ret)
372 goto out;
373 }
374 ret = crypto_hash_final(desc, out);
375 if (ret)
376 goto out;
377
378 end = get_cycles();
379
380 cycles += end - start;
381 }
382
383out:
384 local_irq_enable();
385 local_bh_enable();
386
387 if (ret)
388 return ret;
389
390 printk("%6lu cycles/operation, %4lu cycles/byte\n",
391 cycles / 8, cycles / (8 * blen));
392
393 return 0;
394}
395
Herbert Xu01b32322008-07-31 15:41:55 +0800396static void test_hash_speed(const char *algo, unsigned int sec,
397 struct hash_speed *speed)
Herbert Xue9d41162006-08-19 21:38:49 +1000398{
Herbert Xuf139cfa2008-07-31 12:23:53 +0800399 struct scatterlist sg[TVMEMSIZE];
Herbert Xue9d41162006-08-19 21:38:49 +1000400 struct crypto_hash *tfm;
401 struct hash_desc desc;
Frank Seidel376bacb2009-03-29 15:18:39 +0800402 static char output[1024];
Michal Ludvige8057922006-05-30 22:04:19 +1000403 int i;
Herbert Xue9d41162006-08-19 21:38:49 +1000404 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000405
Frank Seidel376bacb2009-03-29 15:18:39 +0800406 printk(KERN_INFO "\ntesting speed of %s\n", algo);
Michal Ludvige8057922006-05-30 22:04:19 +1000407
Herbert Xue9d41162006-08-19 21:38:49 +1000408 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
Michal Ludvige8057922006-05-30 22:04:19 +1000409
Herbert Xue9d41162006-08-19 21:38:49 +1000410 if (IS_ERR(tfm)) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800411 printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
Herbert Xue9d41162006-08-19 21:38:49 +1000412 PTR_ERR(tfm));
Michal Ludvige8057922006-05-30 22:04:19 +1000413 return;
414 }
415
Herbert Xue9d41162006-08-19 21:38:49 +1000416 desc.tfm = tfm;
417 desc.flags = 0;
418
419 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800420 printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
Herbert Xue9d41162006-08-19 21:38:49 +1000421 crypto_hash_digestsize(tfm), sizeof(output));
Michal Ludvige8057922006-05-30 22:04:19 +1000422 goto out;
423 }
424
Herbert Xuf139cfa2008-07-31 12:23:53 +0800425 sg_init_table(sg, TVMEMSIZE);
426 for (i = 0; i < TVMEMSIZE; i++) {
427 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
428 memset(tvmem[i], 0xff, PAGE_SIZE);
429 }
430
Michal Ludvige8057922006-05-30 22:04:19 +1000431 for (i = 0; speed[i].blen != 0; i++) {
Herbert Xuf139cfa2008-07-31 12:23:53 +0800432 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800433 printk(KERN_ERR
434 "template (%u) too big for tvmem (%lu)\n",
Herbert Xuf139cfa2008-07-31 12:23:53 +0800435 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
Michal Ludvige8057922006-05-30 22:04:19 +1000436 goto out;
437 }
438
Frank Seidel376bacb2009-03-29 15:18:39 +0800439 printk(KERN_INFO "test%3u "
440 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
Michal Ludvige8057922006-05-30 22:04:19 +1000441 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
442
Michal Ludvige8057922006-05-30 22:04:19 +1000443 if (sec)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800444 ret = test_hash_jiffies(&desc, sg, speed[i].blen,
Herbert Xue9d41162006-08-19 21:38:49 +1000445 speed[i].plen, output, sec);
Michal Ludvige8057922006-05-30 22:04:19 +1000446 else
Herbert Xuf139cfa2008-07-31 12:23:53 +0800447 ret = test_hash_cycles(&desc, sg, speed[i].blen,
Herbert Xue9d41162006-08-19 21:38:49 +1000448 speed[i].plen, output);
449
450 if (ret) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800451 printk(KERN_ERR "hashing failed ret=%d\n", ret);
Herbert Xue9d41162006-08-19 21:38:49 +1000452 break;
453 }
Michal Ludvige8057922006-05-30 22:04:19 +1000454 }
455
456out:
Herbert Xue9d41162006-08-19 21:38:49 +1000457 crypto_free_hash(tfm);
Michal Ludvige8057922006-05-30 22:04:19 +1000458}
459
Herbert Xuef2736f2005-06-22 13:26:03 -0700460static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461{
462 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -0700463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 while (*name) {
465 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +1000466 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +1000467 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700469 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470}
471
Herbert Xu01b32322008-07-31 15:41:55 +0800472static inline int tcrypt_test(const char *alg)
473{
Jarod Wilson4e033a62009-05-27 15:10:21 +1000474 int ret;
475
476 ret = alg_test(alg, alg, 0, 0);
477 /* non-fips algs return -EINVAL in fips mode */
478 if (fips_enabled && ret == -EINVAL)
479 ret = 0;
480 return ret;
Herbert Xu01b32322008-07-31 15:41:55 +0800481}
482
Jarod Wilson4e033a62009-05-27 15:10:21 +1000483static int do_test(int m)
Herbert Xu01b32322008-07-31 15:41:55 +0800484{
485 int i;
Jarod Wilson4e033a62009-05-27 15:10:21 +1000486 int ret = 0;
Herbert Xu01b32322008-07-31 15:41:55 +0800487
488 switch (m) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 case 0:
Herbert Xu01b32322008-07-31 15:41:55 +0800490 for (i = 1; i < 200; i++)
Jarod Wilson4e033a62009-05-27 15:10:21 +1000491 ret += do_test(i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 break;
493
494 case 1:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000495 ret += tcrypt_test("md5");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 break;
497
498 case 2:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000499 ret += tcrypt_test("sha1");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 break;
501
502 case 3:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000503 ret += tcrypt_test("ecb(des)");
504 ret += tcrypt_test("cbc(des)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 break;
506
507 case 4:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000508 ret += tcrypt_test("ecb(des3_ede)");
509 ret += tcrypt_test("cbc(des3_ede)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 break;
511
512 case 5:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000513 ret += tcrypt_test("md4");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 case 6:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000517 ret += tcrypt_test("sha256");
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 7:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000521 ret += tcrypt_test("ecb(blowfish)");
522 ret += tcrypt_test("cbc(blowfish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 break;
524
525 case 8:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000526 ret += tcrypt_test("ecb(twofish)");
527 ret += tcrypt_test("cbc(twofish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700529
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 case 9:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000531 ret += tcrypt_test("ecb(serpent)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 break;
533
534 case 10:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000535 ret += tcrypt_test("ecb(aes)");
536 ret += tcrypt_test("cbc(aes)");
537 ret += tcrypt_test("lrw(aes)");
538 ret += tcrypt_test("xts(aes)");
539 ret += tcrypt_test("ctr(aes)");
540 ret += tcrypt_test("rfc3686(ctr(aes))");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 break;
542
543 case 11:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000544 ret += tcrypt_test("sha384");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 case 12:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000548 ret += tcrypt_test("sha512");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 break;
550
551 case 13:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000552 ret += tcrypt_test("deflate");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 break;
554
555 case 14:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000556 ret += tcrypt_test("ecb(cast5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 break;
558
559 case 15:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000560 ret += tcrypt_test("ecb(cast6)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 break;
562
563 case 16:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000564 ret += tcrypt_test("ecb(arc4)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 break;
566
567 case 17:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000568 ret += tcrypt_test("michael_mic");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 break;
570
571 case 18:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000572 ret += tcrypt_test("crc32c");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 break;
574
575 case 19:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000576 ret += tcrypt_test("ecb(tea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 break;
578
579 case 20:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000580 ret += tcrypt_test("ecb(xtea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 break;
582
583 case 21:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000584 ret += tcrypt_test("ecb(khazad)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 break;
586
587 case 22:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000588 ret += tcrypt_test("wp512");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 break;
590
591 case 23:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000592 ret += tcrypt_test("wp384");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 break;
594
595 case 24:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000596 ret += tcrypt_test("wp256");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 break;
598
599 case 25:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000600 ret += tcrypt_test("ecb(tnepres)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 break;
602
603 case 26:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000604 ret += tcrypt_test("ecb(anubis)");
605 ret += tcrypt_test("cbc(anubis)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 break;
607
608 case 27:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000609 ret += tcrypt_test("tgr192");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 break;
611
612 case 28:
613
Jarod Wilson4e033a62009-05-27 15:10:21 +1000614 ret += tcrypt_test("tgr160");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 break;
616
617 case 29:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000618 ret += tcrypt_test("tgr128");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 break;
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +0800620
Aaron Grothefb4f10e2005-09-01 17:42:46 -0700621 case 30:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000622 ret += tcrypt_test("ecb(xeta)");
Aaron Grothefb4f10e2005-09-01 17:42:46 -0700623 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
David Howells90831632006-12-16 12:13:14 +1100625 case 31:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000626 ret += tcrypt_test("pcbc(fcrypt)");
David Howells90831632006-12-16 12:13:14 +1100627 break;
628
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100629 case 32:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000630 ret += tcrypt_test("ecb(camellia)");
631 ret += tcrypt_test("cbc(camellia)");
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100632 break;
Jonathan Lynchcd12fb902007-11-10 20:08:25 +0800633 case 33:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000634 ret += tcrypt_test("sha224");
Jonathan Lynchcd12fb902007-11-10 20:08:25 +0800635 break;
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100636
Tan Swee Heng2407d602007-11-23 19:45:00 +0800637 case 34:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000638 ret += tcrypt_test("salsa20");
Tan Swee Heng2407d602007-11-23 19:45:00 +0800639 break;
640
Herbert Xu8df213d2007-12-02 14:55:47 +1100641 case 35:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000642 ret += tcrypt_test("gcm(aes)");
Herbert Xu8df213d2007-12-02 14:55:47 +1100643 break;
644
Zoltan Sogor0b77abb2007-12-07 16:53:23 +0800645 case 36:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000646 ret += tcrypt_test("lzo");
Zoltan Sogor0b77abb2007-12-07 16:53:23 +0800647 break;
648
Joy Latten93cc74e2007-12-12 20:24:22 +0800649 case 37:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000650 ret += tcrypt_test("ccm(aes)");
Joy Latten93cc74e2007-12-12 20:24:22 +0800651 break;
652
Kevin Coffman76cb9522008-03-24 21:26:16 +0800653 case 38:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000654 ret += tcrypt_test("cts(cbc(aes))");
Kevin Coffman76cb9522008-03-24 21:26:16 +0800655 break;
656
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800657 case 39:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000658 ret += tcrypt_test("rmd128");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800659 break;
660
661 case 40:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000662 ret += tcrypt_test("rmd160");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800663 break;
664
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +0800665 case 41:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000666 ret += tcrypt_test("rmd256");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +0800667 break;
668
669 case 42:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000670 ret += tcrypt_test("rmd320");
Herbert Xu01b32322008-07-31 15:41:55 +0800671 break;
672
673 case 43:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000674 ret += tcrypt_test("ecb(seed)");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +0800675 break;
676
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +0800677 case 44:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000678 ret += tcrypt_test("zlib");
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +0800679 break;
680
Jarod Wilson5d667322009-05-04 19:23:40 +0800681 case 45:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000682 ret += tcrypt_test("rfc4309(ccm(aes))");
Jarod Wilson5d667322009-05-04 19:23:40 +0800683 break;
684
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 case 100:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000686 ret += tcrypt_test("hmac(md5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 case 101:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000690 ret += tcrypt_test("hmac(sha1)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700692
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 case 102:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000694 ret += tcrypt_test("hmac(sha256)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 break;
696
Andrew Donofrioa28091a2006-12-10 12:10:20 +1100697 case 103:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000698 ret += tcrypt_test("hmac(sha384)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +1100699 break;
700
701 case 104:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000702 ret += tcrypt_test("hmac(sha512)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +1100703 break;
Herbert Xu38ed9ab2008-01-01 15:59:28 +1100704
Jonathan Lynchcd12fb902007-11-10 20:08:25 +0800705 case 105:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000706 ret += tcrypt_test("hmac(sha224)");
Jonathan Lynchcd12fb902007-11-10 20:08:25 +0800707 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Herbert Xu38ed9ab2008-01-01 15:59:28 +1100709 case 106:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000710 ret += tcrypt_test("xcbc(aes)");
Herbert Xu38ed9ab2008-01-01 15:59:28 +1100711 break;
712
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800713 case 107:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000714 ret += tcrypt_test("hmac(rmd128)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800715 break;
716
717 case 108:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000718 ret += tcrypt_test("hmac(rmd160)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800719 break;
720
Jarod Wilsone08ca2d2009-05-04 19:46:29 +0800721 case 150:
Jarod Wilson4e033a62009-05-27 15:10:21 +1000722 ret += tcrypt_test("ansi_cprng");
Jarod Wilsone08ca2d2009-05-04 19:46:29 +0800723 break;
724
Harald Welteebfd9bc2005-06-22 13:27:23 -0700725 case 200:
Herbert Xucba83562006-08-13 08:26:09 +1000726 test_cipher_speed("ecb(aes)", ENCRYPT, 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("ecb(aes)", DECRYPT, 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)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800731 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +1000732 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800733 speed_template_16_24_32);
Rik Snelf3d10442006-11-29 19:01:41 +1100734 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800735 speed_template_32_40_48);
Rik Snelf3d10442006-11-29 19:01:41 +1100736 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800737 speed_template_32_40_48);
Rik Snelf19f5112007-09-19 20:23:13 +0800738 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800739 speed_template_32_48_64);
Rik Snelf19f5112007-09-19 20:23:13 +0800740 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800741 speed_template_32_48_64);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700742 break;
743
744 case 201:
Herbert Xucba83562006-08-13 08:26:09 +1000745 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +0800746 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800747 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +1000748 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +0800749 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800750 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +1000751 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +0800752 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800753 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +1000754 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +0800755 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800756 speed_template_24);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700757 break;
758
759 case 202:
Herbert Xucba83562006-08-13 08:26:09 +1000760 test_cipher_speed("ecb(twofish)", ENCRYPT, 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("ecb(twofish)", DECRYPT, 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)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800765 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +1000766 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800767 speed_template_16_24_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700768 break;
769
770 case 203:
Herbert Xucba83562006-08-13 08:26:09 +1000771 test_cipher_speed("ecb(blowfish)", ENCRYPT, 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("ecb(blowfish)", DECRYPT, 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)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800776 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +1000777 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800778 speed_template_8_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700779 break;
780
781 case 204:
Herbert Xucba83562006-08-13 08:26:09 +1000782 test_cipher_speed("ecb(des)", ENCRYPT, 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("ecb(des)", DECRYPT, 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)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800787 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +1000788 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800789 speed_template_8);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700790 break;
791
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100792 case 205:
793 test_cipher_speed("ecb(camellia)", ENCRYPT, 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("ecb(camellia)", DECRYPT, 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)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800798 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100799 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800800 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +1100801 break;
802
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +0800803 case 206:
804 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +0800805 speed_template_16_32);
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +0800806 break;
807
Michal Ludvige8057922006-05-30 22:04:19 +1000808 case 300:
809 /* fall through */
810
811 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +1000812 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000813 if (mode > 300 && mode < 400) break;
814
815 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +1000816 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000817 if (mode > 300 && mode < 400) break;
818
819 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +1000820 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000821 if (mode > 300 && mode < 400) break;
822
823 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +1000824 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000825 if (mode > 300 && mode < 400) break;
826
827 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +1000828 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000829 if (mode > 300 && mode < 400) break;
830
831 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +1000832 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000833 if (mode > 300 && mode < 400) break;
834
835 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +1000836 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000837 if (mode > 300 && mode < 400) break;
838
839 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +1000840 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000841 if (mode > 300 && mode < 400) break;
842
843 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +1000844 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000845 if (mode > 300 && mode < 400) break;
846
847 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +1000848 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000849 if (mode > 300 && mode < 400) break;
850
851 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +1000852 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000853 if (mode > 300 && mode < 400) break;
854
855 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +1000856 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +1000857 if (mode > 300 && mode < 400) break;
858
Jonathan Lynchcd12fb902007-11-10 20:08:25 +0800859 case 313:
860 test_hash_speed("sha224", sec, generic_hash_speed_template);
861 if (mode > 300 && mode < 400) break;
862
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +0800863 case 314:
864 test_hash_speed("rmd128", sec, generic_hash_speed_template);
865 if (mode > 300 && mode < 400) break;
866
867 case 315:
868 test_hash_speed("rmd160", sec, generic_hash_speed_template);
869 if (mode > 300 && mode < 400) break;
870
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +0800871 case 316:
872 test_hash_speed("rmd256", sec, generic_hash_speed_template);
873 if (mode > 300 && mode < 400) break;
874
875 case 317:
876 test_hash_speed("rmd320", sec, generic_hash_speed_template);
877 if (mode > 300 && mode < 400) break;
878
Michal Ludvige8057922006-05-30 22:04:19 +1000879 case 399:
880 break;
881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 case 1000:
883 test_available();
884 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 }
Jarod Wilson4e033a62009-05-27 15:10:21 +1000886
887 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888}
889
Steffen Klasserta873a5f2009-06-19 19:46:53 +0800890static int do_alg_test(const char *alg, u32 type)
891{
Herbert Xuea400652009-06-19 20:37:00 +0800892 return crypto_has_alg(alg, type, CRYPTO_ALG_TYPE_MASK) ? 0 : -ENOENT;
Steffen Klasserta873a5f2009-06-19 19:46:53 +0800893}
894
Kamalesh Babulal3af5b902008-04-05 21:00:57 +0800895static int __init tcrypt_mod_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896{
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800897 int err = -ENOMEM;
Herbert Xuf139cfa2008-07-31 12:23:53 +0800898 int i;
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800899
Herbert Xuf139cfa2008-07-31 12:23:53 +0800900 for (i = 0; i < TVMEMSIZE; i++) {
901 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
902 if (!tvmem[i])
903 goto err_free_tv;
904 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Steffen Klasserta873a5f2009-06-19 19:46:53 +0800906 if (alg)
907 err = do_alg_test(alg, type);
908 else
909 err = do_test(mode);
910
Jarod Wilson4e033a62009-05-27 15:10:21 +1000911 if (err) {
912 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
913 goto err_free_tv;
914 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Jarod Wilson4e033a62009-05-27 15:10:21 +1000916 /* We intentionaly return -EAGAIN to prevent keeping the module,
917 * unless we're running in fips mode. It does all its work from
918 * init() and doesn't offer any runtime functionality, but in
919 * the fips case, checking for a successful load is helpful.
Michal Ludvig14fdf472006-05-30 14:49:38 +1000920 * => we don't need it in the memory, do we?
921 * -- mludvig
922 */
Jarod Wilson4e033a62009-05-27 15:10:21 +1000923 if (!fips_enabled)
924 err = -EAGAIN;
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800925
Herbert Xuf139cfa2008-07-31 12:23:53 +0800926err_free_tv:
927 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
928 free_page((unsigned long)tvmem[i]);
Mikko Herranene3a4ea42007-11-26 22:12:07 +0800929
930 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931}
932
933/*
934 * If an init function is provided, an exit function must also be provided
935 * to allow module unload.
936 */
Kamalesh Babulal3af5b902008-04-05 21:00:57 +0800937static void __exit tcrypt_mod_fini(void) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Kamalesh Babulal3af5b902008-04-05 21:00:57 +0800939module_init(tcrypt_mod_init);
940module_exit(tcrypt_mod_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Steffen Klasserta873a5f2009-06-19 19:46:53 +0800942module_param(alg, charp, 0);
943module_param(type, uint, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700945module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -0700946MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
947 "(defaults to zero which uses CPU cycles instead)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
949MODULE_LICENSE("GPL");
950MODULE_DESCRIPTION("Quick & dirty crypto testing module");
951MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");