blob: 5e2278069d226e9c1a6a0b677fb415a2c6802e3d [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>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
Herbert Xuef2736f2005-06-22 13:26:03 -070012 * Software Foundation; either version 2 of the License, or (at your option)
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * any later version.
14 *
Harald Welteebfd9bc2005-06-22 13:27:23 -070015 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
16 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
17 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 */
19
Herbert Xucba83562006-08-13 08:26:09 +100020#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/init.h>
22#include <linux/module.h>
23#include <linux/mm.h>
24#include <linux/slab.h>
David Hardeman378f0582005-09-17 17:55:31 +100025#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/string.h>
27#include <linux/crypto.h>
28#include <linux/highmem.h>
29#include <linux/moduleparam.h>
Harald Welteebfd9bc2005-06-22 13:27:23 -070030#include <linux/jiffies.h>
Herbert Xu6a179442005-06-22 13:29:03 -070031#include <linux/timex.h>
32#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "tcrypt.h"
34
35/*
36 * Need to kmalloc() memory for testing kmap().
37 */
Harald Welteebfd9bc2005-06-22 13:27:23 -070038#define TVMEMSIZE 16384
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#define XBUFSIZE 32768
40
41/*
42 * Indexes into the xbuf to simulate cross-page access.
43 */
44#define IDX1 37
45#define IDX2 32400
46#define IDX3 1
47#define IDX4 8193
48#define IDX5 22222
49#define IDX6 17101
50#define IDX7 27333
51#define IDX8 3000
52
53/*
54* Used by test_cipher()
55*/
56#define ENCRYPT 1
57#define DECRYPT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
60
Harald Welteebfd9bc2005-06-22 13:27:23 -070061/*
62 * Used by test_cipher_speed()
63 */
Herbert Xu6a179442005-06-22 13:29:03 -070064static unsigned int sec;
Harald Welteebfd9bc2005-06-22 13:27:23 -070065
Linus Torvalds1da177e2005-04-16 15:20:36 -070066static int mode;
67static char *xbuf;
68static char *tvmem;
69
70static char *check[] = {
71 "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish",
Herbert Xuef2736f2005-06-22 13:26:03 -070072 "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
73 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
Aaron Grothefb4f10e2005-09-01 17:42:46 -070074 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070075};
76
Herbert Xuef2736f2005-06-22 13:26:03 -070077static void hexdump(unsigned char *buf, unsigned int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
79 while (len--)
80 printk("%02x", *buf++);
81
82 printk("\n");
83}
84
Herbert Xuef2736f2005-06-22 13:26:03 -070085static void test_hash(char *algo, struct hash_testvec *template,
86 unsigned int tcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Herbert Xuef2736f2005-06-22 13:26:03 -070088 unsigned int i, j, k, temp;
89 struct scatterlist sg[8];
90 char result[64];
91 struct crypto_tfm *tfm;
92 struct hash_testvec *hash_tv;
93 unsigned int tsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Herbert Xuef2736f2005-06-22 13:26:03 -070095 printk("\ntesting %s\n", algo);
96
97 tsize = sizeof(struct hash_testvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 tsize *= tcount;
Herbert Xuef2736f2005-06-22 13:26:03 -070099
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 if (tsize > TVMEMSIZE) {
101 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
102 return;
103 }
104
105 memcpy(tvmem, template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700106 hash_tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 tfm = crypto_alloc_tfm(algo, 0);
108 if (tfm == NULL) {
109 printk("failed to load transform for %s\n", algo);
110 return;
111 }
112
113 for (i = 0; i < tcount; i++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700114 printk("test %u:\n", i + 1);
115 memset(result, 0, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
David Hardeman378f0582005-09-17 17:55:31 +1000117 sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Herbert Xuef2736f2005-06-22 13:26:03 -0700119 crypto_digest_init(tfm);
Herbert Xu560c06a2006-08-13 14:16:39 +1000120 crypto_digest_setkey(tfm, hash_tv[i].key, hash_tv[i].ksize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700121 crypto_digest_update(tfm, sg, 1);
122 crypto_digest_final(tfm, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Herbert Xuef2736f2005-06-22 13:26:03 -0700124 hexdump(result, crypto_tfm_alg_digestsize(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 printk("%s\n",
Herbert Xuef2736f2005-06-22 13:26:03 -0700126 memcmp(result, hash_tv[i].digest,
127 crypto_tfm_alg_digestsize(tfm)) ?
128 "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 }
130
Herbert Xuef2736f2005-06-22 13:26:03 -0700131 printk("testing %s across pages\n", algo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 /* setup the dummy buffer first */
Herbert Xuef2736f2005-06-22 13:26:03 -0700134 memset(xbuf, 0, XBUFSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 j = 0;
137 for (i = 0; i < tcount; i++) {
138 if (hash_tv[i].np) {
139 j++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700140 printk("test %u:\n", j);
141 memset(result, 0, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 temp = 0;
144 for (k = 0; k < hash_tv[i].np; k++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700145 memcpy(&xbuf[IDX[k]],
146 hash_tv[i].plaintext + temp,
147 hash_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 temp += hash_tv[i].tap[k];
David Hardeman378f0582005-09-17 17:55:31 +1000149 sg_set_buf(&sg[k], &xbuf[IDX[k]],
150 hash_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 }
152
Herbert Xuef2736f2005-06-22 13:26:03 -0700153 crypto_digest_digest(tfm, sg, hash_tv[i].np, result);
154
155 hexdump(result, crypto_tfm_alg_digestsize(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 printk("%s\n",
Herbert Xuef2736f2005-06-22 13:26:03 -0700157 memcmp(result, hash_tv[i].digest,
158 crypto_tfm_alg_digestsize(tfm)) ?
159 "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 }
161 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700162
163 crypto_free_tfm(tfm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164}
165
166
167#ifdef CONFIG_CRYPTO_HMAC
168
Herbert Xuef2736f2005-06-22 13:26:03 -0700169static void test_hmac(char *algo, struct hmac_testvec *template,
170 unsigned int tcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 unsigned int i, j, k, temp;
173 struct scatterlist sg[8];
174 char result[64];
175 struct crypto_tfm *tfm;
176 struct hmac_testvec *hmac_tv;
177 unsigned int tsize, klen;
178
179 tfm = crypto_alloc_tfm(algo, 0);
180 if (tfm == NULL) {
181 printk("failed to load transform for %s\n", algo);
182 return;
183 }
184
185 printk("\ntesting hmac_%s\n", algo);
Herbert Xuef2736f2005-06-22 13:26:03 -0700186
187 tsize = sizeof(struct hmac_testvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 tsize *= tcount;
189 if (tsize > TVMEMSIZE) {
190 printk("template (%u) too big for tvmem (%u)\n", tsize,
191 TVMEMSIZE);
192 goto out;
193 }
194
195 memcpy(tvmem, template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700196 hmac_tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 for (i = 0; i < tcount; i++) {
199 printk("test %u:\n", i + 1);
200 memset(result, 0, sizeof (result));
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 klen = hmac_tv[i].ksize;
David Hardeman378f0582005-09-17 17:55:31 +1000203 sg_set_buf(&sg[0], hmac_tv[i].plaintext, hmac_tv[i].psize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, 1, result);
206
207 hexdump(result, crypto_tfm_alg_digestsize(tfm));
208 printk("%s\n",
209 memcmp(result, hmac_tv[i].digest,
210 crypto_tfm_alg_digestsize(tfm)) ? "fail" :
211 "pass");
212 }
213
214 printk("\ntesting hmac_%s across pages\n", algo);
215
216 memset(xbuf, 0, XBUFSIZE);
Herbert Xuef2736f2005-06-22 13:26:03 -0700217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 j = 0;
219 for (i = 0; i < tcount; i++) {
220 if (hmac_tv[i].np) {
221 j++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700222 printk("test %u:\n",j);
223 memset(result, 0, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 temp = 0;
226 klen = hmac_tv[i].ksize;
227 for (k = 0; k < hmac_tv[i].np; k++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700228 memcpy(&xbuf[IDX[k]],
229 hmac_tv[i].plaintext + temp,
230 hmac_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 temp += hmac_tv[i].tap[k];
David Hardeman378f0582005-09-17 17:55:31 +1000232 sg_set_buf(&sg[k], &xbuf[IDX[k]],
233 hmac_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 }
235
Herbert Xuef2736f2005-06-22 13:26:03 -0700236 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg,
237 hmac_tv[i].np, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 hexdump(result, crypto_tfm_alg_digestsize(tfm));
Herbert Xuef2736f2005-06-22 13:26:03 -0700239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 printk("%s\n",
Herbert Xuef2736f2005-06-22 13:26:03 -0700241 memcmp(result, hmac_tv[i].digest,
242 crypto_tfm_alg_digestsize(tfm)) ?
243 "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 }
245 }
246out:
247 crypto_free_tfm(tfm);
248}
249
250#endif /* CONFIG_CRYPTO_HMAC */
251
Herbert Xucba83562006-08-13 08:26:09 +1000252static void test_cipher(char *algo, int enc,
Herbert Xuef2736f2005-06-22 13:26:03 -0700253 struct cipher_testvec *template, unsigned int tcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 unsigned int ret, i, j, k, temp;
256 unsigned int tsize;
Herbert Xucba83562006-08-13 08:26:09 +1000257 unsigned int iv_len;
258 unsigned int len;
David Hardeman378f0582005-09-17 17:55:31 +1000259 char *q;
Herbert Xucba83562006-08-13 08:26:09 +1000260 struct crypto_blkcipher *tfm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 char *key;
262 struct cipher_testvec *cipher_tv;
Herbert Xucba83562006-08-13 08:26:09 +1000263 struct blkcipher_desc desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 struct scatterlist sg[8];
Herbert Xucba83562006-08-13 08:26:09 +1000265 const char *e;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 if (enc == ENCRYPT)
Herbert Xu3cc38162005-06-22 13:26:36 -0700268 e = "encryption";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 else
Herbert Xu3cc38162005-06-22 13:26:36 -0700270 e = "decryption";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Herbert Xucba83562006-08-13 08:26:09 +1000272 printk("\ntesting %s %s\n", algo, e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Herbert Xuef2736f2005-06-22 13:26:03 -0700274 tsize = sizeof (struct cipher_testvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 tsize *= tcount;
Herbert Xuef2736f2005-06-22 13:26:03 -0700276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 if (tsize > TVMEMSIZE) {
278 printk("template (%u) too big for tvmem (%u)\n", tsize,
279 TVMEMSIZE);
280 return;
281 }
282
283 memcpy(tvmem, template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700284 cipher_tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Herbert Xucba83562006-08-13 08:26:09 +1000286 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
Herbert Xuef2736f2005-06-22 13:26:03 -0700287
Herbert Xucba83562006-08-13 08:26:09 +1000288 if (IS_ERR(tfm)) {
289 printk("failed to load transform for %s: %ld\n", algo,
290 PTR_ERR(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 return;
292 }
Herbert Xucba83562006-08-13 08:26:09 +1000293 desc.tfm = tfm;
294 desc.flags = 0;
Herbert Xuef2736f2005-06-22 13:26:03 -0700295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 j = 0;
297 for (i = 0; i < tcount; i++) {
298 if (!(cipher_tv[i].np)) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700299 j++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 printk("test %u (%d bit key):\n",
301 j, cipher_tv[i].klen * 8);
302
Herbert Xucba83562006-08-13 08:26:09 +1000303 crypto_blkcipher_clear_flags(tfm, ~0);
Herbert Xuef2736f2005-06-22 13:26:03 -0700304 if (cipher_tv[i].wk)
Herbert Xucba83562006-08-13 08:26:09 +1000305 crypto_blkcipher_set_flags(
306 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 key = cipher_tv[i].key;
Herbert Xuef2736f2005-06-22 13:26:03 -0700308
Herbert Xucba83562006-08-13 08:26:09 +1000309 ret = crypto_blkcipher_setkey(tfm, key,
310 cipher_tv[i].klen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000312 printk("setkey() failed flags=%x\n",
313 crypto_blkcipher_get_flags(tfm));
Herbert Xuef2736f2005-06-22 13:26:03 -0700314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 if (!cipher_tv[i].fail)
316 goto out;
Herbert Xuef2736f2005-06-22 13:26:03 -0700317 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
David Hardeman378f0582005-09-17 17:55:31 +1000319 sg_set_buf(&sg[0], cipher_tv[i].input,
320 cipher_tv[i].ilen);
Herbert Xuef2736f2005-06-22 13:26:03 -0700321
Herbert Xucba83562006-08-13 08:26:09 +1000322 iv_len = crypto_blkcipher_ivsize(tfm);
323 if (iv_len)
324 crypto_blkcipher_set_iv(tfm, cipher_tv[i].iv,
325 iv_len);
Herbert Xuef2736f2005-06-22 13:26:03 -0700326
Herbert Xucba83562006-08-13 08:26:09 +1000327 len = cipher_tv[i].ilen;
328 ret = enc ?
329 crypto_blkcipher_encrypt(&desc, sg, sg, len) :
330 crypto_blkcipher_decrypt(&desc, sg, sg, len);
Herbert Xuef2736f2005-06-22 13:26:03 -0700331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000333 printk("%s () failed flags=%x\n", e,
334 desc.flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 goto out;
Herbert Xuef2736f2005-06-22 13:26:03 -0700336 }
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 q = kmap(sg[0].page) + sg[0].offset;
339 hexdump(q, cipher_tv[i].rlen);
Herbert Xuef2736f2005-06-22 13:26:03 -0700340
341 printk("%s\n",
342 memcmp(q, cipher_tv[i].result,
343 cipher_tv[i].rlen) ? "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 }
345 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700346
Herbert Xucba83562006-08-13 08:26:09 +1000347 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 memset(xbuf, 0, XBUFSIZE);
Herbert Xuef2736f2005-06-22 13:26:03 -0700349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 j = 0;
351 for (i = 0; i < tcount; i++) {
352 if (cipher_tv[i].np) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700353 j++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 printk("test %u (%d bit key):\n",
355 j, cipher_tv[i].klen * 8);
356
Herbert Xucba83562006-08-13 08:26:09 +1000357 crypto_blkcipher_clear_flags(tfm, ~0);
Herbert Xuef2736f2005-06-22 13:26:03 -0700358 if (cipher_tv[i].wk)
Herbert Xucba83562006-08-13 08:26:09 +1000359 crypto_blkcipher_set_flags(
360 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 key = cipher_tv[i].key;
Herbert Xuef2736f2005-06-22 13:26:03 -0700362
Herbert Xucba83562006-08-13 08:26:09 +1000363 ret = crypto_blkcipher_setkey(tfm, key,
364 cipher_tv[i].klen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000366 printk("setkey() failed flags=%x\n",
367 crypto_blkcipher_get_flags(tfm));
Herbert Xuef2736f2005-06-22 13:26:03 -0700368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 if (!cipher_tv[i].fail)
370 goto out;
371 }
372
373 temp = 0;
374 for (k = 0; k < cipher_tv[i].np; k++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700375 memcpy(&xbuf[IDX[k]],
376 cipher_tv[i].input + temp,
377 cipher_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 temp += cipher_tv[i].tap[k];
David Hardeman378f0582005-09-17 17:55:31 +1000379 sg_set_buf(&sg[k], &xbuf[IDX[k]],
380 cipher_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700382
Herbert Xucba83562006-08-13 08:26:09 +1000383 iv_len = crypto_blkcipher_ivsize(tfm);
384 if (iv_len)
385 crypto_blkcipher_set_iv(tfm, cipher_tv[i].iv,
386 iv_len);
Herbert Xuef2736f2005-06-22 13:26:03 -0700387
Herbert Xucba83562006-08-13 08:26:09 +1000388 len = cipher_tv[i].ilen;
389 ret = enc ?
390 crypto_blkcipher_encrypt(&desc, sg, sg, len) :
391 crypto_blkcipher_decrypt(&desc, sg, sg, len);
Herbert Xuef2736f2005-06-22 13:26:03 -0700392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000394 printk("%s () failed flags=%x\n", e,
395 desc.flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 goto out;
397 }
398
399 temp = 0;
400 for (k = 0; k < cipher_tv[i].np; k++) {
401 printk("page %u\n", k);
402 q = kmap(sg[k].page) + sg[k].offset;
403 hexdump(q, cipher_tv[i].tap[k]);
Herbert Xuef2736f2005-06-22 13:26:03 -0700404 printk("%s\n",
405 memcmp(q, cipher_tv[i].result + temp,
406 cipher_tv[i].tap[k]) ? "fail" :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 "pass");
408 temp += cipher_tv[i].tap[k];
409 }
410 }
411 }
412
413out:
Herbert Xucba83562006-08-13 08:26:09 +1000414 crypto_free_blkcipher(tfm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415}
416
Herbert Xucba83562006-08-13 08:26:09 +1000417static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
Herbert Xu6a179442005-06-22 13:29:03 -0700418 int blen, int sec)
419{
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000420 struct scatterlist sg[1];
Herbert Xu6a179442005-06-22 13:29:03 -0700421 unsigned long start, end;
422 int bcount;
423 int ret;
424
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000425 sg_set_buf(sg, p, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700426
427 for (start = jiffies, end = start + sec * HZ, bcount = 0;
428 time_before(jiffies, end); bcount++) {
429 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000430 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700431 else
Herbert Xucba83562006-08-13 08:26:09 +1000432 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700433
434 if (ret)
435 return ret;
436 }
437
438 printk("%d operations in %d seconds (%ld bytes)\n",
439 bcount, sec, (long)bcount * blen);
440 return 0;
441}
442
Herbert Xucba83562006-08-13 08:26:09 +1000443static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
Herbert Xu6a179442005-06-22 13:29:03 -0700444 int blen)
445{
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000446 struct scatterlist sg[1];
Herbert Xu6a179442005-06-22 13:29:03 -0700447 unsigned long cycles = 0;
448 int ret = 0;
449 int i;
450
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000451 sg_set_buf(sg, p, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700452
453 local_bh_disable();
454 local_irq_disable();
455
456 /* Warm-up run. */
457 for (i = 0; i < 4; i++) {
458 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000459 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700460 else
Herbert Xucba83562006-08-13 08:26:09 +1000461 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700462
463 if (ret)
464 goto out;
465 }
466
467 /* The real thing. */
468 for (i = 0; i < 8; i++) {
469 cycles_t start, end;
470
471 start = get_cycles();
472 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000473 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700474 else
Herbert Xucba83562006-08-13 08:26:09 +1000475 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700476 end = get_cycles();
477
478 if (ret)
479 goto out;
480
481 cycles += end - start;
482 }
483
484out:
485 local_irq_enable();
486 local_bh_enable();
487
488 if (ret == 0)
489 printk("1 operation in %lu cycles (%d bytes)\n",
490 (cycles + 4) / 8, blen);
491
492 return ret;
493}
494
Herbert Xucba83562006-08-13 08:26:09 +1000495static void test_cipher_speed(char *algo, int enc, unsigned int sec,
Herbert Xudce907c2005-06-22 13:27:51 -0700496 struct cipher_testvec *template,
497 unsigned int tcount, struct cipher_speed *speed)
Harald Welteebfd9bc2005-06-22 13:27:23 -0700498{
Herbert Xudce907c2005-06-22 13:27:51 -0700499 unsigned int ret, i, j, iv_len;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700500 unsigned char *key, *p, iv[128];
Herbert Xucba83562006-08-13 08:26:09 +1000501 struct crypto_blkcipher *tfm;
502 struct blkcipher_desc desc;
503 const char *e;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700504
505 if (enc == ENCRYPT)
506 e = "encryption";
507 else
508 e = "decryption";
Harald Welteebfd9bc2005-06-22 13:27:23 -0700509
Herbert Xucba83562006-08-13 08:26:09 +1000510 printk("\ntesting speed of %s %s\n", algo, e);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700511
Herbert Xucba83562006-08-13 08:26:09 +1000512 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700513
Herbert Xucba83562006-08-13 08:26:09 +1000514 if (IS_ERR(tfm)) {
515 printk("failed to load transform for %s: %ld\n", algo,
516 PTR_ERR(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700517 return;
518 }
Herbert Xucba83562006-08-13 08:26:09 +1000519 desc.tfm = tfm;
520 desc.flags = 0;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700521
522 for (i = 0; speed[i].klen != 0; i++) {
523 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
524 printk("template (%u) too big for tvmem (%u)\n",
525 speed[i].blen + speed[i].klen, TVMEMSIZE);
526 goto out;
527 }
528
529 printk("test %u (%d bit key, %d byte blocks): ", i,
530 speed[i].klen * 8, speed[i].blen);
531
532 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
533
534 /* set key, plain text and IV */
535 key = (unsigned char *)tvmem;
Herbert Xudce907c2005-06-22 13:27:51 -0700536 for (j = 0; j < tcount; j++) {
537 if (template[j].klen == speed[i].klen) {
538 key = template[j].key;
539 break;
540 }
541 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700542 p = (unsigned char *)tvmem + speed[i].klen;
543
Herbert Xucba83562006-08-13 08:26:09 +1000544 ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700545 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000546 printk("setkey() failed flags=%x\n",
547 crypto_blkcipher_get_flags(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700548 goto out;
549 }
550
Herbert Xucba83562006-08-13 08:26:09 +1000551 iv_len = crypto_blkcipher_ivsize(tfm);
552 if (iv_len) {
Harald Welteebfd9bc2005-06-22 13:27:23 -0700553 memset(&iv, 0xff, iv_len);
Herbert Xucba83562006-08-13 08:26:09 +1000554 crypto_blkcipher_set_iv(tfm, iv, iv_len);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700555 }
556
Herbert Xu6a179442005-06-22 13:29:03 -0700557 if (sec)
Herbert Xucba83562006-08-13 08:26:09 +1000558 ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen,
Herbert Xu6a179442005-06-22 13:29:03 -0700559 sec);
560 else
Herbert Xucba83562006-08-13 08:26:09 +1000561 ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700562
Herbert Xu6a179442005-06-22 13:29:03 -0700563 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000564 printk("%s() failed flags=%x\n", e, desc.flags);
Herbert Xu6a179442005-06-22 13:29:03 -0700565 break;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700566 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700567 }
568
569out:
Herbert Xucba83562006-08-13 08:26:09 +1000570 crypto_free_blkcipher(tfm);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700571}
572
Michal Ludvige8057922006-05-30 22:04:19 +1000573static void test_digest_jiffies(struct crypto_tfm *tfm, char *p, int blen,
574 int plen, char *out, int sec)
575{
576 struct scatterlist sg[1];
577 unsigned long start, end;
578 int bcount, pcount;
579
580 for (start = jiffies, end = start + sec * HZ, bcount = 0;
581 time_before(jiffies, end); bcount++) {
582 crypto_digest_init(tfm);
583 for (pcount = 0; pcount < blen; pcount += plen) {
584 sg_set_buf(sg, p + pcount, plen);
585 crypto_digest_update(tfm, sg, 1);
586 }
587 /* we assume there is enough space in 'out' for the result */
588 crypto_digest_final(tfm, out);
589 }
590
591 printk("%6u opers/sec, %9lu bytes/sec\n",
592 bcount / sec, ((long)bcount * blen) / sec);
593
594 return;
595}
596
597static void test_digest_cycles(struct crypto_tfm *tfm, char *p, int blen,
598 int plen, char *out)
599{
600 struct scatterlist sg[1];
601 unsigned long cycles = 0;
602 int i, pcount;
603
604 local_bh_disable();
605 local_irq_disable();
606
607 /* Warm-up run. */
608 for (i = 0; i < 4; i++) {
609 crypto_digest_init(tfm);
610 for (pcount = 0; pcount < blen; pcount += plen) {
611 sg_set_buf(sg, p + pcount, plen);
612 crypto_digest_update(tfm, sg, 1);
613 }
614 crypto_digest_final(tfm, out);
615 }
616
617 /* The real thing. */
618 for (i = 0; i < 8; i++) {
619 cycles_t start, end;
620
621 crypto_digest_init(tfm);
622
623 start = get_cycles();
624
625 for (pcount = 0; pcount < blen; pcount += plen) {
626 sg_set_buf(sg, p + pcount, plen);
627 crypto_digest_update(tfm, sg, 1);
628 }
629 crypto_digest_final(tfm, out);
630
631 end = get_cycles();
632
633 cycles += end - start;
634 }
635
636 local_irq_enable();
637 local_bh_enable();
638
639 printk("%6lu cycles/operation, %4lu cycles/byte\n",
640 cycles / 8, cycles / (8 * blen));
641
642 return;
643}
644
645static void test_digest_speed(char *algo, unsigned int sec,
646 struct digest_speed *speed)
647{
648 struct crypto_tfm *tfm;
649 char output[1024];
650 int i;
651
652 printk("\ntesting speed of %s\n", algo);
653
654 tfm = crypto_alloc_tfm(algo, 0);
655
656 if (tfm == NULL) {
657 printk("failed to load transform for %s\n", algo);
658 return;
659 }
660
661 if (crypto_tfm_alg_digestsize(tfm) > sizeof(output)) {
662 printk("digestsize(%u) > outputbuffer(%zu)\n",
663 crypto_tfm_alg_digestsize(tfm), sizeof(output));
664 goto out;
665 }
666
667 for (i = 0; speed[i].blen != 0; i++) {
668 if (speed[i].blen > TVMEMSIZE) {
669 printk("template (%u) too big for tvmem (%u)\n",
670 speed[i].blen, TVMEMSIZE);
671 goto out;
672 }
673
674 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
675 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
676
677 memset(tvmem, 0xff, speed[i].blen);
678
679 if (sec)
680 test_digest_jiffies(tfm, tvmem, speed[i].blen, speed[i].plen, output, sec);
681 else
682 test_digest_cycles(tfm, tvmem, speed[i].blen, speed[i].plen, output);
683 }
684
685out:
686 crypto_free_tfm(tfm);
687}
688
Herbert Xuef2736f2005-06-22 13:26:03 -0700689static void test_deflate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
691 unsigned int i;
692 char result[COMP_BUF_SIZE];
693 struct crypto_tfm *tfm;
694 struct comp_testvec *tv;
695 unsigned int tsize;
696
697 printk("\ntesting deflate compression\n");
698
699 tsize = sizeof (deflate_comp_tv_template);
700 if (tsize > TVMEMSIZE) {
701 printk("template (%u) too big for tvmem (%u)\n", tsize,
702 TVMEMSIZE);
703 return;
704 }
705
706 memcpy(tvmem, deflate_comp_tv_template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700707 tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
709 tfm = crypto_alloc_tfm("deflate", 0);
710 if (tfm == NULL) {
711 printk("failed to load transform for deflate\n");
712 return;
713 }
714
715 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
716 int ilen, ret, dlen = COMP_BUF_SIZE;
Herbert Xuef2736f2005-06-22 13:26:03 -0700717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 printk("test %u:\n", i + 1);
719 memset(result, 0, sizeof (result));
720
721 ilen = tv[i].inlen;
722 ret = crypto_comp_compress(tfm, tv[i].input,
723 ilen, result, &dlen);
724 if (ret) {
725 printk("fail: ret=%d\n", ret);
726 continue;
727 }
728 hexdump(result, dlen);
729 printk("%s (ratio %d:%d)\n",
730 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
731 ilen, dlen);
732 }
733
734 printk("\ntesting deflate decompression\n");
735
736 tsize = sizeof (deflate_decomp_tv_template);
737 if (tsize > TVMEMSIZE) {
738 printk("template (%u) too big for tvmem (%u)\n", tsize,
739 TVMEMSIZE);
740 goto out;
741 }
742
743 memcpy(tvmem, deflate_decomp_tv_template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700744 tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
746 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
747 int ilen, ret, dlen = COMP_BUF_SIZE;
Herbert Xuef2736f2005-06-22 13:26:03 -0700748
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 printk("test %u:\n", i + 1);
750 memset(result, 0, sizeof (result));
751
752 ilen = tv[i].inlen;
753 ret = crypto_comp_decompress(tfm, tv[i].input,
754 ilen, result, &dlen);
755 if (ret) {
756 printk("fail: ret=%d\n", ret);
757 continue;
758 }
759 hexdump(result, dlen);
760 printk("%s (ratio %d:%d)\n",
761 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
762 ilen, dlen);
763 }
764out:
765 crypto_free_tfm(tfm);
766}
767
Herbert Xuef2736f2005-06-22 13:26:03 -0700768static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769{
770 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -0700771
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 while (*name) {
773 printk("alg %s ", *name);
774 printk((crypto_alg_available(*name, 0)) ?
775 "found\n" : "not found\n");
776 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700777 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778}
779
Herbert Xuef2736f2005-06-22 13:26:03 -0700780static void do_test(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781{
782 switch (mode) {
783
784 case 0:
785 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700786
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700788
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 //DES
Herbert Xucba83562006-08-13 08:26:09 +1000790 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
791 DES_ENC_TEST_VECTORS);
792 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
793 DES_DEC_TEST_VECTORS);
794 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
795 DES_CBC_ENC_TEST_VECTORS);
796 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
797 DES_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700798
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 //DES3_EDE
Herbert Xucba83562006-08-13 08:26:09 +1000800 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
801 DES3_EDE_ENC_TEST_VECTORS);
802 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
803 DES3_EDE_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700804
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700806
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700808
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 //BLOWFISH
Herbert Xucba83562006-08-13 08:26:09 +1000810 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
811 BF_ENC_TEST_VECTORS);
812 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
813 BF_DEC_TEST_VECTORS);
814 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
815 BF_CBC_ENC_TEST_VECTORS);
816 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
817 BF_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700818
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 //TWOFISH
Herbert Xucba83562006-08-13 08:26:09 +1000820 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
821 TF_ENC_TEST_VECTORS);
822 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
823 TF_DEC_TEST_VECTORS);
824 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
825 TF_CBC_ENC_TEST_VECTORS);
826 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
827 TF_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700828
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 //SERPENT
Herbert Xucba83562006-08-13 08:26:09 +1000830 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
831 SERPENT_ENC_TEST_VECTORS);
832 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
833 SERPENT_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 //TNEPRES
Herbert Xucba83562006-08-13 08:26:09 +1000836 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
837 TNEPRES_ENC_TEST_VECTORS);
838 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
839 TNEPRES_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
841 //AES
Herbert Xucba83562006-08-13 08:26:09 +1000842 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
843 AES_ENC_TEST_VECTORS);
844 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
845 AES_DEC_TEST_VECTORS);
846 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
847 AES_CBC_ENC_TEST_VECTORS);
848 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
849 AES_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 //CAST5
Herbert Xucba83562006-08-13 08:26:09 +1000852 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
853 CAST5_ENC_TEST_VECTORS);
854 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
855 CAST5_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 //CAST6
Herbert Xucba83562006-08-13 08:26:09 +1000858 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
859 CAST6_ENC_TEST_VECTORS);
860 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
861 CAST6_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
863 //ARC4
Herbert Xucba83562006-08-13 08:26:09 +1000864 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
865 ARC4_ENC_TEST_VECTORS);
866 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
867 ARC4_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
869 //TEA
Herbert Xucba83562006-08-13 08:26:09 +1000870 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
871 TEA_ENC_TEST_VECTORS);
872 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
873 TEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
875
876 //XTEA
Herbert Xucba83562006-08-13 08:26:09 +1000877 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
878 XTEA_ENC_TEST_VECTORS);
879 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
880 XTEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
882 //KHAZAD
Herbert Xucba83562006-08-13 08:26:09 +1000883 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
884 KHAZAD_ENC_TEST_VECTORS);
885 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
886 KHAZAD_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
888 //ANUBIS
Herbert Xucba83562006-08-13 08:26:09 +1000889 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
890 ANUBIS_ENC_TEST_VECTORS);
891 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
892 ANUBIS_DEC_TEST_VECTORS);
893 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
894 ANUBIS_CBC_ENC_TEST_VECTORS);
895 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
896 ANUBIS_CBC_ENC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
Aaron Grothefb4f10e2005-09-01 17:42:46 -0700898 //XETA
Herbert Xucba83562006-08-13 08:26:09 +1000899 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
900 XETA_ENC_TEST_VECTORS);
901 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
902 XETA_DEC_TEST_VECTORS);
Aaron Grothefb4f10e2005-09-01 17:42:46 -0700903
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
905 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
906 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
907 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
908 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
909 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
910 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
911 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
912 test_deflate();
Herbert Xuc907ee72006-08-21 22:04:03 +1000913 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914#ifdef CONFIG_CRYPTO_HMAC
915 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700916 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700918#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
920 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
921 break;
922
923 case 1:
924 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
925 break;
926
927 case 2:
928 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
929 break;
930
931 case 3:
Herbert Xucba83562006-08-13 08:26:09 +1000932 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
933 DES_ENC_TEST_VECTORS);
934 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
935 DES_DEC_TEST_VECTORS);
936 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
937 DES_CBC_ENC_TEST_VECTORS);
938 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
939 DES_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 break;
941
942 case 4:
Herbert Xucba83562006-08-13 08:26:09 +1000943 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
944 DES3_EDE_ENC_TEST_VECTORS);
945 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
946 DES3_EDE_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 break;
948
949 case 5:
950 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
951 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700952
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 case 6:
954 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
955 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 case 7:
Herbert Xucba83562006-08-13 08:26:09 +1000958 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
959 BF_ENC_TEST_VECTORS);
960 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
961 BF_DEC_TEST_VECTORS);
962 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
963 BF_CBC_ENC_TEST_VECTORS);
964 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
965 BF_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 break;
967
968 case 8:
Herbert Xucba83562006-08-13 08:26:09 +1000969 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
970 TF_ENC_TEST_VECTORS);
971 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
972 TF_DEC_TEST_VECTORS);
973 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
974 TF_CBC_ENC_TEST_VECTORS);
975 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
976 TF_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700978
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 case 9:
Herbert Xucba83562006-08-13 08:26:09 +1000980 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
981 SERPENT_ENC_TEST_VECTORS);
982 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
983 SERPENT_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 break;
985
986 case 10:
Herbert Xucba83562006-08-13 08:26:09 +1000987 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
988 AES_ENC_TEST_VECTORS);
989 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
990 AES_DEC_TEST_VECTORS);
991 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
992 AES_CBC_ENC_TEST_VECTORS);
993 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
994 AES_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 break;
996
997 case 11:
998 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
999 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001000
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 case 12:
1002 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1003 break;
1004
1005 case 13:
1006 test_deflate();
1007 break;
1008
1009 case 14:
Herbert Xucba83562006-08-13 08:26:09 +10001010 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1011 CAST5_ENC_TEST_VECTORS);
1012 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1013 CAST5_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 break;
1015
1016 case 15:
Herbert Xucba83562006-08-13 08:26:09 +10001017 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1018 CAST6_ENC_TEST_VECTORS);
1019 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1020 CAST6_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 break;
1022
1023 case 16:
Herbert Xucba83562006-08-13 08:26:09 +10001024 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1025 ARC4_ENC_TEST_VECTORS);
1026 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1027 ARC4_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 break;
1029
1030 case 17:
1031 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1032 break;
1033
1034 case 18:
Herbert Xuc907ee72006-08-21 22:04:03 +10001035 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 break;
1037
1038 case 19:
Herbert Xucba83562006-08-13 08:26:09 +10001039 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1040 TEA_ENC_TEST_VECTORS);
1041 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1042 TEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 break;
1044
1045 case 20:
Herbert Xucba83562006-08-13 08:26:09 +10001046 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1047 XTEA_ENC_TEST_VECTORS);
1048 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1049 XTEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 break;
1051
1052 case 21:
Herbert Xucba83562006-08-13 08:26:09 +10001053 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1054 KHAZAD_ENC_TEST_VECTORS);
1055 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1056 KHAZAD_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 break;
1058
1059 case 22:
1060 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1061 break;
1062
1063 case 23:
1064 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1065 break;
1066
1067 case 24:
1068 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1069 break;
1070
1071 case 25:
Herbert Xucba83562006-08-13 08:26:09 +10001072 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1073 TNEPRES_ENC_TEST_VECTORS);
1074 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1075 TNEPRES_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 break;
1077
1078 case 26:
Herbert Xucba83562006-08-13 08:26:09 +10001079 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1080 ANUBIS_ENC_TEST_VECTORS);
1081 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1082 ANUBIS_DEC_TEST_VECTORS);
1083 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1084 ANUBIS_CBC_ENC_TEST_VECTORS);
1085 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1086 ANUBIS_CBC_ENC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 break;
1088
1089 case 27:
1090 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1091 break;
1092
1093 case 28:
1094
1095 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1096 break;
1097
1098 case 29:
1099 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1100 break;
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001101
1102 case 30:
Herbert Xucba83562006-08-13 08:26:09 +10001103 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1104 XETA_ENC_TEST_VECTORS);
1105 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1106 XETA_DEC_TEST_VECTORS);
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001107 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
1109#ifdef CONFIG_CRYPTO_HMAC
1110 case 100:
1111 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
1112 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001113
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 case 101:
Herbert Xuef2736f2005-06-22 13:26:03 -07001115 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001117
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 case 102:
1119 test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
1120 break;
1121
1122#endif
1123
Harald Welteebfd9bc2005-06-22 13:27:23 -07001124 case 200:
Herbert Xucba83562006-08-13 08:26:09 +10001125 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001126 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001127 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001128 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001129 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001130 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001131 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001132 aes_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001133 break;
1134
1135 case 201:
Herbert Xucba83562006-08-13 08:26:09 +10001136 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001137 des3_ede_enc_tv_template,
1138 DES3_EDE_ENC_TEST_VECTORS,
1139 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001140 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001141 des3_ede_dec_tv_template,
1142 DES3_EDE_DEC_TEST_VECTORS,
1143 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001144 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001145 des3_ede_enc_tv_template,
1146 DES3_EDE_ENC_TEST_VECTORS,
1147 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001148 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001149 des3_ede_dec_tv_template,
1150 DES3_EDE_DEC_TEST_VECTORS,
1151 des3_ede_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001152 break;
1153
1154 case 202:
Herbert Xucba83562006-08-13 08:26:09 +10001155 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001156 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001157 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001158 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001159 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001160 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001161 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001162 twofish_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001163 break;
1164
1165 case 203:
Herbert Xucba83562006-08-13 08:26:09 +10001166 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001167 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001168 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001169 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001170 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001171 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001172 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001173 blowfish_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001174 break;
1175
1176 case 204:
Herbert Xucba83562006-08-13 08:26:09 +10001177 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001178 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001179 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001180 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001181 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001182 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001183 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001184 des_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001185 break;
1186
Michal Ludvige8057922006-05-30 22:04:19 +10001187 case 300:
1188 /* fall through */
1189
1190 case 301:
1191 test_digest_speed("md4", sec, generic_digest_speed_template);
1192 if (mode > 300 && mode < 400) break;
1193
1194 case 302:
1195 test_digest_speed("md5", sec, generic_digest_speed_template);
1196 if (mode > 300 && mode < 400) break;
1197
1198 case 303:
1199 test_digest_speed("sha1", sec, generic_digest_speed_template);
1200 if (mode > 300 && mode < 400) break;
1201
1202 case 304:
1203 test_digest_speed("sha256", sec, generic_digest_speed_template);
1204 if (mode > 300 && mode < 400) break;
1205
1206 case 305:
1207 test_digest_speed("sha384", sec, generic_digest_speed_template);
1208 if (mode > 300 && mode < 400) break;
1209
1210 case 306:
1211 test_digest_speed("sha512", sec, generic_digest_speed_template);
1212 if (mode > 300 && mode < 400) break;
1213
1214 case 307:
1215 test_digest_speed("wp256", sec, generic_digest_speed_template);
1216 if (mode > 300 && mode < 400) break;
1217
1218 case 308:
1219 test_digest_speed("wp384", sec, generic_digest_speed_template);
1220 if (mode > 300 && mode < 400) break;
1221
1222 case 309:
1223 test_digest_speed("wp512", sec, generic_digest_speed_template);
1224 if (mode > 300 && mode < 400) break;
1225
1226 case 310:
1227 test_digest_speed("tgr128", sec, generic_digest_speed_template);
1228 if (mode > 300 && mode < 400) break;
1229
1230 case 311:
1231 test_digest_speed("tgr160", sec, generic_digest_speed_template);
1232 if (mode > 300 && mode < 400) break;
1233
1234 case 312:
1235 test_digest_speed("tgr192", sec, generic_digest_speed_template);
1236 if (mode > 300 && mode < 400) break;
1237
1238 case 399:
1239 break;
1240
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 case 1000:
1242 test_available();
1243 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001244
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 default:
1246 /* useful for debugging */
1247 printk("not testing anything\n");
1248 break;
1249 }
1250}
1251
Herbert Xuef2736f2005-06-22 13:26:03 -07001252static int __init init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253{
1254 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1255 if (tvmem == NULL)
1256 return -ENOMEM;
1257
1258 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1259 if (xbuf == NULL) {
1260 kfree(tvmem);
1261 return -ENOMEM;
1262 }
1263
1264 do_test();
1265
1266 kfree(xbuf);
1267 kfree(tvmem);
Michal Ludvig14fdf472006-05-30 14:49:38 +10001268
1269 /* We intentionaly return -EAGAIN to prevent keeping
1270 * the module. It does all its work from init()
1271 * and doesn't offer any runtime functionality
1272 * => we don't need it in the memory, do we?
1273 * -- mludvig
1274 */
1275 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276}
1277
1278/*
1279 * If an init function is provided, an exit function must also be provided
1280 * to allow module unload.
1281 */
1282static void __exit fini(void) { }
1283
1284module_init(init);
1285module_exit(fini);
1286
1287module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001288module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -07001289MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1290 "(defaults to zero which uses CPU cycles instead)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
1292MODULE_LICENSE("GPL");
1293MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1294MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");