blob: 83307420d31c873398006cbd85286ebcf50e2965 [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];
Herbert Xue9d41162006-08-19 21:38:49 +100091 struct crypto_hash *tfm;
92 struct hash_desc desc;
Herbert Xuef2736f2005-06-22 13:26:03 -070093 struct hash_testvec *hash_tv;
94 unsigned int tsize;
Herbert Xue9d41162006-08-19 21:38:49 +100095 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Herbert Xuef2736f2005-06-22 13:26:03 -070097 printk("\ntesting %s\n", algo);
98
99 tsize = sizeof(struct hash_testvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 tsize *= tcount;
Herbert Xuef2736f2005-06-22 13:26:03 -0700101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 if (tsize > TVMEMSIZE) {
103 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
104 return;
105 }
106
107 memcpy(tvmem, template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700108 hash_tv = (void *)tvmem;
Herbert Xue9d41162006-08-19 21:38:49 +1000109
110 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
111 if (IS_ERR(tfm)) {
112 printk("failed to load transform for %s: %ld\n", algo,
113 PTR_ERR(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 return;
115 }
116
Herbert Xue9d41162006-08-19 21:38:49 +1000117 desc.tfm = tfm;
118 desc.flags = 0;
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 for (i = 0; i < tcount; i++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700121 printk("test %u:\n", i + 1);
122 memset(result, 0, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
David Hardeman378f0582005-09-17 17:55:31 +1000124 sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Herbert Xue9d41162006-08-19 21:38:49 +1000126 if (hash_tv[i].ksize) {
127 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
128 hash_tv[i].ksize);
129 if (ret) {
130 printk("setkey() failed ret=%d\n", ret);
131 goto out;
132 }
133 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Herbert Xue9d41162006-08-19 21:38:49 +1000135 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, result);
136 if (ret) {
137 printk("digest () failed ret=%d\n", ret);
138 goto out;
139 }
140
141 hexdump(result, crypto_hash_digestsize(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 printk("%s\n",
Herbert Xuef2736f2005-06-22 13:26:03 -0700143 memcmp(result, hash_tv[i].digest,
Herbert Xue9d41162006-08-19 21:38:49 +1000144 crypto_hash_digestsize(tfm)) ?
Herbert Xuef2736f2005-06-22 13:26:03 -0700145 "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 }
147
Herbert Xuef2736f2005-06-22 13:26:03 -0700148 printk("testing %s across pages\n", algo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150 /* setup the dummy buffer first */
Herbert Xuef2736f2005-06-22 13:26:03 -0700151 memset(xbuf, 0, XBUFSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 j = 0;
154 for (i = 0; i < tcount; i++) {
155 if (hash_tv[i].np) {
156 j++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700157 printk("test %u:\n", j);
158 memset(result, 0, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160 temp = 0;
161 for (k = 0; k < hash_tv[i].np; k++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700162 memcpy(&xbuf[IDX[k]],
163 hash_tv[i].plaintext + temp,
164 hash_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 temp += hash_tv[i].tap[k];
David Hardeman378f0582005-09-17 17:55:31 +1000166 sg_set_buf(&sg[k], &xbuf[IDX[k]],
167 hash_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 }
169
Herbert Xue9d41162006-08-19 21:38:49 +1000170 if (hash_tv[i].ksize) {
171 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
172 hash_tv[i].ksize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700173
Herbert Xue9d41162006-08-19 21:38:49 +1000174 if (ret) {
175 printk("setkey() failed ret=%d\n", ret);
176 goto out;
177 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 }
179
Herbert Xue9d41162006-08-19 21:38:49 +1000180 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize,
181 result);
182 if (ret) {
183 printk("digest () failed ret=%d\n", ret);
184 goto out;
185 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700186
Herbert Xue9d41162006-08-19 21:38:49 +1000187 hexdump(result, crypto_hash_digestsize(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 printk("%s\n",
Herbert Xue9d41162006-08-19 21:38:49 +1000189 memcmp(result, hash_tv[i].digest,
190 crypto_hash_digestsize(tfm)) ?
Herbert Xuef2736f2005-06-22 13:26:03 -0700191 "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 }
193 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Herbert Xue9d41162006-08-19 21:38:49 +1000195out:
196 crypto_free_hash(tfm);
197}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Herbert Xucba83562006-08-13 08:26:09 +1000199static void test_cipher(char *algo, int enc,
Herbert Xuef2736f2005-06-22 13:26:03 -0700200 struct cipher_testvec *template, unsigned int tcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
202 unsigned int ret, i, j, k, temp;
203 unsigned int tsize;
Herbert Xucba83562006-08-13 08:26:09 +1000204 unsigned int iv_len;
205 unsigned int len;
David Hardeman378f0582005-09-17 17:55:31 +1000206 char *q;
Herbert Xucba83562006-08-13 08:26:09 +1000207 struct crypto_blkcipher *tfm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 char *key;
209 struct cipher_testvec *cipher_tv;
Herbert Xucba83562006-08-13 08:26:09 +1000210 struct blkcipher_desc desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 struct scatterlist sg[8];
Herbert Xucba83562006-08-13 08:26:09 +1000212 const char *e;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 if (enc == ENCRYPT)
Herbert Xu3cc38162005-06-22 13:26:36 -0700215 e = "encryption";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 else
Herbert Xu3cc38162005-06-22 13:26:36 -0700217 e = "decryption";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Herbert Xucba83562006-08-13 08:26:09 +1000219 printk("\ntesting %s %s\n", algo, e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Herbert Xuef2736f2005-06-22 13:26:03 -0700221 tsize = sizeof (struct cipher_testvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 tsize *= tcount;
Herbert Xuef2736f2005-06-22 13:26:03 -0700223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 if (tsize > TVMEMSIZE) {
225 printk("template (%u) too big for tvmem (%u)\n", tsize,
226 TVMEMSIZE);
227 return;
228 }
229
230 memcpy(tvmem, template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700231 cipher_tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Herbert Xucba83562006-08-13 08:26:09 +1000233 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
Herbert Xuef2736f2005-06-22 13:26:03 -0700234
Herbert Xucba83562006-08-13 08:26:09 +1000235 if (IS_ERR(tfm)) {
236 printk("failed to load transform for %s: %ld\n", algo,
237 PTR_ERR(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 return;
239 }
Herbert Xucba83562006-08-13 08:26:09 +1000240 desc.tfm = tfm;
241 desc.flags = 0;
Herbert Xuef2736f2005-06-22 13:26:03 -0700242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 j = 0;
244 for (i = 0; i < tcount; i++) {
245 if (!(cipher_tv[i].np)) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700246 j++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 printk("test %u (%d bit key):\n",
248 j, cipher_tv[i].klen * 8);
249
Herbert Xucba83562006-08-13 08:26:09 +1000250 crypto_blkcipher_clear_flags(tfm, ~0);
Herbert Xuef2736f2005-06-22 13:26:03 -0700251 if (cipher_tv[i].wk)
Herbert Xucba83562006-08-13 08:26:09 +1000252 crypto_blkcipher_set_flags(
253 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 key = cipher_tv[i].key;
Herbert Xuef2736f2005-06-22 13:26:03 -0700255
Herbert Xucba83562006-08-13 08:26:09 +1000256 ret = crypto_blkcipher_setkey(tfm, key,
257 cipher_tv[i].klen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000259 printk("setkey() failed flags=%x\n",
260 crypto_blkcipher_get_flags(tfm));
Herbert Xuef2736f2005-06-22 13:26:03 -0700261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 if (!cipher_tv[i].fail)
263 goto out;
Herbert Xuef2736f2005-06-22 13:26:03 -0700264 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
David Hardeman378f0582005-09-17 17:55:31 +1000266 sg_set_buf(&sg[0], cipher_tv[i].input,
267 cipher_tv[i].ilen);
Herbert Xuef2736f2005-06-22 13:26:03 -0700268
Herbert Xucba83562006-08-13 08:26:09 +1000269 iv_len = crypto_blkcipher_ivsize(tfm);
270 if (iv_len)
271 crypto_blkcipher_set_iv(tfm, cipher_tv[i].iv,
272 iv_len);
Herbert Xuef2736f2005-06-22 13:26:03 -0700273
Herbert Xucba83562006-08-13 08:26:09 +1000274 len = cipher_tv[i].ilen;
275 ret = enc ?
276 crypto_blkcipher_encrypt(&desc, sg, sg, len) :
277 crypto_blkcipher_decrypt(&desc, sg, sg, len);
Herbert Xuef2736f2005-06-22 13:26:03 -0700278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000280 printk("%s () failed flags=%x\n", e,
281 desc.flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 goto out;
Herbert Xuef2736f2005-06-22 13:26:03 -0700283 }
284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 q = kmap(sg[0].page) + sg[0].offset;
286 hexdump(q, cipher_tv[i].rlen);
Herbert Xuef2736f2005-06-22 13:26:03 -0700287
288 printk("%s\n",
289 memcmp(q, cipher_tv[i].result,
290 cipher_tv[i].rlen) ? "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 }
292 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700293
Herbert Xucba83562006-08-13 08:26:09 +1000294 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 memset(xbuf, 0, XBUFSIZE);
Herbert Xuef2736f2005-06-22 13:26:03 -0700296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 j = 0;
298 for (i = 0; i < tcount; i++) {
299 if (cipher_tv[i].np) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700300 j++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 printk("test %u (%d bit key):\n",
302 j, cipher_tv[i].klen * 8);
303
Herbert Xucba83562006-08-13 08:26:09 +1000304 crypto_blkcipher_clear_flags(tfm, ~0);
Herbert Xuef2736f2005-06-22 13:26:03 -0700305 if (cipher_tv[i].wk)
Herbert Xucba83562006-08-13 08:26:09 +1000306 crypto_blkcipher_set_flags(
307 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 key = cipher_tv[i].key;
Herbert Xuef2736f2005-06-22 13:26:03 -0700309
Herbert Xucba83562006-08-13 08:26:09 +1000310 ret = crypto_blkcipher_setkey(tfm, key,
311 cipher_tv[i].klen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000313 printk("setkey() failed flags=%x\n",
314 crypto_blkcipher_get_flags(tfm));
Herbert Xuef2736f2005-06-22 13:26:03 -0700315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 if (!cipher_tv[i].fail)
317 goto out;
318 }
319
320 temp = 0;
321 for (k = 0; k < cipher_tv[i].np; k++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700322 memcpy(&xbuf[IDX[k]],
323 cipher_tv[i].input + temp,
324 cipher_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 temp += cipher_tv[i].tap[k];
David Hardeman378f0582005-09-17 17:55:31 +1000326 sg_set_buf(&sg[k], &xbuf[IDX[k]],
327 cipher_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700329
Herbert Xucba83562006-08-13 08:26:09 +1000330 iv_len = crypto_blkcipher_ivsize(tfm);
331 if (iv_len)
332 crypto_blkcipher_set_iv(tfm, cipher_tv[i].iv,
333 iv_len);
Herbert Xuef2736f2005-06-22 13:26:03 -0700334
Herbert Xucba83562006-08-13 08:26:09 +1000335 len = cipher_tv[i].ilen;
336 ret = enc ?
337 crypto_blkcipher_encrypt(&desc, sg, sg, len) :
338 crypto_blkcipher_decrypt(&desc, sg, sg, len);
Herbert Xuef2736f2005-06-22 13:26:03 -0700339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000341 printk("%s () failed flags=%x\n", e,
342 desc.flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 goto out;
344 }
345
346 temp = 0;
347 for (k = 0; k < cipher_tv[i].np; k++) {
348 printk("page %u\n", k);
349 q = kmap(sg[k].page) + sg[k].offset;
350 hexdump(q, cipher_tv[i].tap[k]);
Herbert Xuef2736f2005-06-22 13:26:03 -0700351 printk("%s\n",
352 memcmp(q, cipher_tv[i].result + temp,
353 cipher_tv[i].tap[k]) ? "fail" :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 "pass");
355 temp += cipher_tv[i].tap[k];
356 }
357 }
358 }
359
360out:
Herbert Xucba83562006-08-13 08:26:09 +1000361 crypto_free_blkcipher(tfm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
Herbert Xucba83562006-08-13 08:26:09 +1000364static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
Herbert Xu6a179442005-06-22 13:29:03 -0700365 int blen, int sec)
366{
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000367 struct scatterlist sg[1];
Herbert Xu6a179442005-06-22 13:29:03 -0700368 unsigned long start, end;
369 int bcount;
370 int ret;
371
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000372 sg_set_buf(sg, p, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700373
374 for (start = jiffies, end = start + sec * HZ, bcount = 0;
375 time_before(jiffies, end); bcount++) {
376 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000377 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700378 else
Herbert Xucba83562006-08-13 08:26:09 +1000379 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700380
381 if (ret)
382 return ret;
383 }
384
385 printk("%d operations in %d seconds (%ld bytes)\n",
386 bcount, sec, (long)bcount * blen);
387 return 0;
388}
389
Herbert Xucba83562006-08-13 08:26:09 +1000390static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
Herbert Xu6a179442005-06-22 13:29:03 -0700391 int blen)
392{
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000393 struct scatterlist sg[1];
Herbert Xu6a179442005-06-22 13:29:03 -0700394 unsigned long cycles = 0;
395 int ret = 0;
396 int i;
397
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000398 sg_set_buf(sg, p, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700399
400 local_bh_disable();
401 local_irq_disable();
402
403 /* Warm-up run. */
404 for (i = 0; i < 4; i++) {
405 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000406 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700407 else
Herbert Xucba83562006-08-13 08:26:09 +1000408 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700409
410 if (ret)
411 goto out;
412 }
413
414 /* The real thing. */
415 for (i = 0; i < 8; i++) {
416 cycles_t start, end;
417
418 start = get_cycles();
419 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000420 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700421 else
Herbert Xucba83562006-08-13 08:26:09 +1000422 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700423 end = get_cycles();
424
425 if (ret)
426 goto out;
427
428 cycles += end - start;
429 }
430
431out:
432 local_irq_enable();
433 local_bh_enable();
434
435 if (ret == 0)
436 printk("1 operation in %lu cycles (%d bytes)\n",
437 (cycles + 4) / 8, blen);
438
439 return ret;
440}
441
Herbert Xucba83562006-08-13 08:26:09 +1000442static void test_cipher_speed(char *algo, int enc, unsigned int sec,
Herbert Xudce907c2005-06-22 13:27:51 -0700443 struct cipher_testvec *template,
444 unsigned int tcount, struct cipher_speed *speed)
Harald Welteebfd9bc2005-06-22 13:27:23 -0700445{
Herbert Xudce907c2005-06-22 13:27:51 -0700446 unsigned int ret, i, j, iv_len;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700447 unsigned char *key, *p, iv[128];
Herbert Xucba83562006-08-13 08:26:09 +1000448 struct crypto_blkcipher *tfm;
449 struct blkcipher_desc desc;
450 const char *e;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700451
452 if (enc == ENCRYPT)
453 e = "encryption";
454 else
455 e = "decryption";
Harald Welteebfd9bc2005-06-22 13:27:23 -0700456
Herbert Xucba83562006-08-13 08:26:09 +1000457 printk("\ntesting speed of %s %s\n", algo, e);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700458
Herbert Xucba83562006-08-13 08:26:09 +1000459 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700460
Herbert Xucba83562006-08-13 08:26:09 +1000461 if (IS_ERR(tfm)) {
462 printk("failed to load transform for %s: %ld\n", algo,
463 PTR_ERR(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700464 return;
465 }
Herbert Xucba83562006-08-13 08:26:09 +1000466 desc.tfm = tfm;
467 desc.flags = 0;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700468
469 for (i = 0; speed[i].klen != 0; i++) {
470 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
471 printk("template (%u) too big for tvmem (%u)\n",
472 speed[i].blen + speed[i].klen, TVMEMSIZE);
473 goto out;
474 }
475
476 printk("test %u (%d bit key, %d byte blocks): ", i,
477 speed[i].klen * 8, speed[i].blen);
478
479 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
480
481 /* set key, plain text and IV */
482 key = (unsigned char *)tvmem;
Herbert Xudce907c2005-06-22 13:27:51 -0700483 for (j = 0; j < tcount; j++) {
484 if (template[j].klen == speed[i].klen) {
485 key = template[j].key;
486 break;
487 }
488 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700489 p = (unsigned char *)tvmem + speed[i].klen;
490
Herbert Xucba83562006-08-13 08:26:09 +1000491 ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700492 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000493 printk("setkey() failed flags=%x\n",
494 crypto_blkcipher_get_flags(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700495 goto out;
496 }
497
Herbert Xucba83562006-08-13 08:26:09 +1000498 iv_len = crypto_blkcipher_ivsize(tfm);
499 if (iv_len) {
Harald Welteebfd9bc2005-06-22 13:27:23 -0700500 memset(&iv, 0xff, iv_len);
Herbert Xucba83562006-08-13 08:26:09 +1000501 crypto_blkcipher_set_iv(tfm, iv, iv_len);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700502 }
503
Herbert Xu6a179442005-06-22 13:29:03 -0700504 if (sec)
Herbert Xucba83562006-08-13 08:26:09 +1000505 ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen,
Herbert Xu6a179442005-06-22 13:29:03 -0700506 sec);
507 else
Herbert Xucba83562006-08-13 08:26:09 +1000508 ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700509
Herbert Xu6a179442005-06-22 13:29:03 -0700510 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000511 printk("%s() failed flags=%x\n", e, desc.flags);
Herbert Xu6a179442005-06-22 13:29:03 -0700512 break;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700513 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700514 }
515
516out:
Herbert Xucba83562006-08-13 08:26:09 +1000517 crypto_free_blkcipher(tfm);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700518}
519
Herbert Xue9d41162006-08-19 21:38:49 +1000520static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
521 char *out, int sec)
Michal Ludvige8057922006-05-30 22:04:19 +1000522{
523 struct scatterlist sg[1];
524 unsigned long start, end;
Herbert Xue9d41162006-08-19 21:38:49 +1000525 int bcount;
526 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000527
528 for (start = jiffies, end = start + sec * HZ, bcount = 0;
529 time_before(jiffies, end); bcount++) {
Herbert Xue9d41162006-08-19 21:38:49 +1000530 sg_set_buf(sg, p, blen);
531 ret = crypto_hash_digest(desc, sg, blen, out);
532 if (ret)
533 return ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000534 }
535
536 printk("%6u opers/sec, %9lu bytes/sec\n",
537 bcount / sec, ((long)bcount * blen) / sec);
538
Herbert Xue9d41162006-08-19 21:38:49 +1000539 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000540}
541
Herbert Xue9d41162006-08-19 21:38:49 +1000542static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
543 int plen, char *out, int sec)
544{
545 struct scatterlist sg[1];
546 unsigned long start, end;
547 int bcount, pcount;
548 int ret;
549
550 if (plen == blen)
551 return test_hash_jiffies_digest(desc, p, blen, out, sec);
552
553 for (start = jiffies, end = start + sec * HZ, bcount = 0;
554 time_before(jiffies, end); bcount++) {
555 ret = crypto_hash_init(desc);
556 if (ret)
557 return ret;
558 for (pcount = 0; pcount < blen; pcount += plen) {
559 sg_set_buf(sg, p + pcount, plen);
560 ret = crypto_hash_update(desc, sg, plen);
561 if (ret)
562 return ret;
563 }
564 /* we assume there is enough space in 'out' for the result */
565 ret = crypto_hash_final(desc, out);
566 if (ret)
567 return ret;
568 }
569
570 printk("%6u opers/sec, %9lu bytes/sec\n",
571 bcount / sec, ((long)bcount * blen) / sec);
572
573 return 0;
574}
575
576static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
577 char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000578{
579 struct scatterlist sg[1];
580 unsigned long cycles = 0;
Herbert Xue9d41162006-08-19 21:38:49 +1000581 int i;
582 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000583
584 local_bh_disable();
585 local_irq_disable();
586
587 /* Warm-up run. */
588 for (i = 0; i < 4; i++) {
Herbert Xue9d41162006-08-19 21:38:49 +1000589 sg_set_buf(sg, p, blen);
590 ret = crypto_hash_digest(desc, sg, blen, out);
591 if (ret)
592 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000593 }
594
595 /* The real thing. */
596 for (i = 0; i < 8; i++) {
597 cycles_t start, end;
598
Michal Ludvige8057922006-05-30 22:04:19 +1000599 start = get_cycles();
600
Herbert Xue9d41162006-08-19 21:38:49 +1000601 sg_set_buf(sg, p, blen);
602 ret = crypto_hash_digest(desc, sg, blen, out);
603 if (ret)
604 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000605
606 end = get_cycles();
607
608 cycles += end - start;
609 }
610
Herbert Xue9d41162006-08-19 21:38:49 +1000611out:
Michal Ludvige8057922006-05-30 22:04:19 +1000612 local_irq_enable();
613 local_bh_enable();
614
Herbert Xue9d41162006-08-19 21:38:49 +1000615 if (ret)
616 return ret;
617
Michal Ludvige8057922006-05-30 22:04:19 +1000618 printk("%6lu cycles/operation, %4lu cycles/byte\n",
619 cycles / 8, cycles / (8 * blen));
620
Herbert Xue9d41162006-08-19 21:38:49 +1000621 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000622}
623
Herbert Xue9d41162006-08-19 21:38:49 +1000624static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
625 int plen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000626{
Herbert Xue9d41162006-08-19 21:38:49 +1000627 struct scatterlist sg[1];
628 unsigned long cycles = 0;
629 int i, pcount;
630 int ret;
631
632 if (plen == blen)
633 return test_hash_cycles_digest(desc, p, blen, out);
634
635 local_bh_disable();
636 local_irq_disable();
637
638 /* Warm-up run. */
639 for (i = 0; i < 4; i++) {
640 ret = crypto_hash_init(desc);
641 if (ret)
642 goto out;
643 for (pcount = 0; pcount < blen; pcount += plen) {
644 sg_set_buf(sg, p + pcount, plen);
645 ret = crypto_hash_update(desc, sg, plen);
646 if (ret)
647 goto out;
648 }
649 crypto_hash_final(desc, out);
650 if (ret)
651 goto out;
652 }
653
654 /* The real thing. */
655 for (i = 0; i < 8; i++) {
656 cycles_t start, end;
657
658 start = get_cycles();
659
660 ret = crypto_hash_init(desc);
661 if (ret)
662 goto out;
663 for (pcount = 0; pcount < blen; pcount += plen) {
664 sg_set_buf(sg, p + pcount, plen);
665 ret = crypto_hash_update(desc, sg, plen);
666 if (ret)
667 goto out;
668 }
669 ret = crypto_hash_final(desc, out);
670 if (ret)
671 goto out;
672
673 end = get_cycles();
674
675 cycles += end - start;
676 }
677
678out:
679 local_irq_enable();
680 local_bh_enable();
681
682 if (ret)
683 return ret;
684
685 printk("%6lu cycles/operation, %4lu cycles/byte\n",
686 cycles / 8, cycles / (8 * blen));
687
688 return 0;
689}
690
691static void test_hash_speed(char *algo, unsigned int sec,
692 struct hash_speed *speed)
693{
694 struct crypto_hash *tfm;
695 struct hash_desc desc;
Michal Ludvige8057922006-05-30 22:04:19 +1000696 char output[1024];
697 int i;
Herbert Xue9d41162006-08-19 21:38:49 +1000698 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000699
700 printk("\ntesting speed of %s\n", algo);
701
Herbert Xue9d41162006-08-19 21:38:49 +1000702 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
Michal Ludvige8057922006-05-30 22:04:19 +1000703
Herbert Xue9d41162006-08-19 21:38:49 +1000704 if (IS_ERR(tfm)) {
705 printk("failed to load transform for %s: %ld\n", algo,
706 PTR_ERR(tfm));
Michal Ludvige8057922006-05-30 22:04:19 +1000707 return;
708 }
709
Herbert Xue9d41162006-08-19 21:38:49 +1000710 desc.tfm = tfm;
711 desc.flags = 0;
712
713 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
Michal Ludvige8057922006-05-30 22:04:19 +1000714 printk("digestsize(%u) > outputbuffer(%zu)\n",
Herbert Xue9d41162006-08-19 21:38:49 +1000715 crypto_hash_digestsize(tfm), sizeof(output));
Michal Ludvige8057922006-05-30 22:04:19 +1000716 goto out;
717 }
718
719 for (i = 0; speed[i].blen != 0; i++) {
720 if (speed[i].blen > TVMEMSIZE) {
721 printk("template (%u) too big for tvmem (%u)\n",
722 speed[i].blen, TVMEMSIZE);
723 goto out;
724 }
725
726 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
727 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
728
729 memset(tvmem, 0xff, speed[i].blen);
730
731 if (sec)
Herbert Xue9d41162006-08-19 21:38:49 +1000732 ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
733 speed[i].plen, output, sec);
Michal Ludvige8057922006-05-30 22:04:19 +1000734 else
Herbert Xue9d41162006-08-19 21:38:49 +1000735 ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
736 speed[i].plen, output);
737
738 if (ret) {
739 printk("hashing failed ret=%d\n", ret);
740 break;
741 }
Michal Ludvige8057922006-05-30 22:04:19 +1000742 }
743
744out:
Herbert Xue9d41162006-08-19 21:38:49 +1000745 crypto_free_hash(tfm);
Michal Ludvige8057922006-05-30 22:04:19 +1000746}
747
Herbert Xuef2736f2005-06-22 13:26:03 -0700748static void test_deflate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749{
750 unsigned int i;
751 char result[COMP_BUF_SIZE];
Herbert Xue4d5b792006-08-26 18:12:40 +1000752 struct crypto_comp *tfm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 struct comp_testvec *tv;
754 unsigned int tsize;
755
756 printk("\ntesting deflate compression\n");
757
758 tsize = sizeof (deflate_comp_tv_template);
759 if (tsize > TVMEMSIZE) {
760 printk("template (%u) too big for tvmem (%u)\n", tsize,
761 TVMEMSIZE);
762 return;
763 }
764
765 memcpy(tvmem, deflate_comp_tv_template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700766 tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
768 tfm = crypto_alloc_tfm("deflate", 0);
769 if (tfm == NULL) {
770 printk("failed to load transform for deflate\n");
771 return;
772 }
773
774 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
775 int ilen, ret, dlen = COMP_BUF_SIZE;
Herbert Xuef2736f2005-06-22 13:26:03 -0700776
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 printk("test %u:\n", i + 1);
778 memset(result, 0, sizeof (result));
779
780 ilen = tv[i].inlen;
781 ret = crypto_comp_compress(tfm, tv[i].input,
782 ilen, result, &dlen);
783 if (ret) {
784 printk("fail: ret=%d\n", ret);
785 continue;
786 }
787 hexdump(result, dlen);
788 printk("%s (ratio %d:%d)\n",
789 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
790 ilen, dlen);
791 }
792
793 printk("\ntesting deflate decompression\n");
794
795 tsize = sizeof (deflate_decomp_tv_template);
796 if (tsize > TVMEMSIZE) {
797 printk("template (%u) too big for tvmem (%u)\n", tsize,
798 TVMEMSIZE);
799 goto out;
800 }
801
802 memcpy(tvmem, deflate_decomp_tv_template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700803 tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
806 int ilen, ret, dlen = COMP_BUF_SIZE;
Herbert Xuef2736f2005-06-22 13:26:03 -0700807
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 printk("test %u:\n", i + 1);
809 memset(result, 0, sizeof (result));
810
811 ilen = tv[i].inlen;
812 ret = crypto_comp_decompress(tfm, tv[i].input,
813 ilen, result, &dlen);
814 if (ret) {
815 printk("fail: ret=%d\n", ret);
816 continue;
817 }
818 hexdump(result, dlen);
819 printk("%s (ratio %d:%d)\n",
820 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
821 ilen, dlen);
822 }
823out:
Herbert Xue4d5b792006-08-26 18:12:40 +1000824 crypto_free_comp(tfm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825}
826
Herbert Xuef2736f2005-06-22 13:26:03 -0700827static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828{
829 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -0700830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 while (*name) {
832 printk("alg %s ", *name);
Herbert Xue4d5b792006-08-26 18:12:40 +1000833 printk(crypto_has_alg(*name, 0, CRYPTO_ALG_ASYNC) ?
834 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700836 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837}
838
Herbert Xuef2736f2005-06-22 13:26:03 -0700839static void do_test(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840{
841 switch (mode) {
842
843 case 0:
844 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700845
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700847
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 //DES
Herbert Xucba83562006-08-13 08:26:09 +1000849 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
850 DES_ENC_TEST_VECTORS);
851 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
852 DES_DEC_TEST_VECTORS);
853 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
854 DES_CBC_ENC_TEST_VECTORS);
855 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
856 DES_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700857
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 //DES3_EDE
Herbert Xucba83562006-08-13 08:26:09 +1000859 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
860 DES3_EDE_ENC_TEST_VECTORS);
861 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
862 DES3_EDE_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700863
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700865
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 //BLOWFISH
Herbert Xucba83562006-08-13 08:26:09 +1000869 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
870 BF_ENC_TEST_VECTORS);
871 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
872 BF_DEC_TEST_VECTORS);
873 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
874 BF_CBC_ENC_TEST_VECTORS);
875 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
876 BF_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700877
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 //TWOFISH
Herbert Xucba83562006-08-13 08:26:09 +1000879 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
880 TF_ENC_TEST_VECTORS);
881 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
882 TF_DEC_TEST_VECTORS);
883 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
884 TF_CBC_ENC_TEST_VECTORS);
885 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
886 TF_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700887
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 //SERPENT
Herbert Xucba83562006-08-13 08:26:09 +1000889 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
890 SERPENT_ENC_TEST_VECTORS);
891 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
892 SERPENT_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700893
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 //TNEPRES
Herbert Xucba83562006-08-13 08:26:09 +1000895 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
896 TNEPRES_ENC_TEST_VECTORS);
897 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
898 TNEPRES_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
900 //AES
Herbert Xucba83562006-08-13 08:26:09 +1000901 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
902 AES_ENC_TEST_VECTORS);
903 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
904 AES_DEC_TEST_VECTORS);
905 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
906 AES_CBC_ENC_TEST_VECTORS);
907 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
908 AES_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910 //CAST5
Herbert Xucba83562006-08-13 08:26:09 +1000911 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
912 CAST5_ENC_TEST_VECTORS);
913 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
914 CAST5_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 //CAST6
Herbert Xucba83562006-08-13 08:26:09 +1000917 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
918 CAST6_ENC_TEST_VECTORS);
919 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
920 CAST6_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
922 //ARC4
Herbert Xucba83562006-08-13 08:26:09 +1000923 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
924 ARC4_ENC_TEST_VECTORS);
925 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
926 ARC4_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928 //TEA
Herbert Xucba83562006-08-13 08:26:09 +1000929 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
930 TEA_ENC_TEST_VECTORS);
931 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
932 TEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934
935 //XTEA
Herbert Xucba83562006-08-13 08:26:09 +1000936 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
937 XTEA_ENC_TEST_VECTORS);
938 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
939 XTEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941 //KHAZAD
Herbert Xucba83562006-08-13 08:26:09 +1000942 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
943 KHAZAD_ENC_TEST_VECTORS);
944 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
945 KHAZAD_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
947 //ANUBIS
Herbert Xucba83562006-08-13 08:26:09 +1000948 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
949 ANUBIS_ENC_TEST_VECTORS);
950 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
951 ANUBIS_DEC_TEST_VECTORS);
952 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
953 ANUBIS_CBC_ENC_TEST_VECTORS);
954 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
955 ANUBIS_CBC_ENC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Aaron Grothefb4f10e2005-09-01 17:42:46 -0700957 //XETA
Herbert Xucba83562006-08-13 08:26:09 +1000958 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
959 XETA_ENC_TEST_VECTORS);
960 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
961 XETA_DEC_TEST_VECTORS);
Aaron Grothefb4f10e2005-09-01 17:42:46 -0700962
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
964 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
965 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
966 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
967 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
968 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
969 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
970 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
971 test_deflate();
Herbert Xuc907ee72006-08-21 22:04:03 +1000972 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
Herbert Xue9d41162006-08-19 21:38:49 +1000973 test_hash("hmac(md5)", hmac_md5_tv_template,
974 HMAC_MD5_TEST_VECTORS);
975 test_hash("hmac(sha1)", hmac_sha1_tv_template,
976 HMAC_SHA1_TEST_VECTORS);
977 test_hash("hmac(sha256)", hmac_sha256_tv_template,
978 HMAC_SHA256_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
981 break;
982
983 case 1:
984 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
985 break;
986
987 case 2:
988 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
989 break;
990
991 case 3:
Herbert Xucba83562006-08-13 08:26:09 +1000992 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
993 DES_ENC_TEST_VECTORS);
994 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
995 DES_DEC_TEST_VECTORS);
996 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
997 DES_CBC_ENC_TEST_VECTORS);
998 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
999 DES_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 break;
1001
1002 case 4:
Herbert Xucba83562006-08-13 08:26:09 +10001003 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1004 DES3_EDE_ENC_TEST_VECTORS);
1005 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1006 DES3_EDE_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 break;
1008
1009 case 5:
1010 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1011 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001012
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 case 6:
1014 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1015 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001016
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 case 7:
Herbert Xucba83562006-08-13 08:26:09 +10001018 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1019 BF_ENC_TEST_VECTORS);
1020 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1021 BF_DEC_TEST_VECTORS);
1022 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1023 BF_CBC_ENC_TEST_VECTORS);
1024 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1025 BF_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 break;
1027
1028 case 8:
Herbert Xucba83562006-08-13 08:26:09 +10001029 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1030 TF_ENC_TEST_VECTORS);
1031 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1032 TF_DEC_TEST_VECTORS);
1033 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1034 TF_CBC_ENC_TEST_VECTORS);
1035 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1036 TF_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 case 9:
Herbert Xucba83562006-08-13 08:26:09 +10001040 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1041 SERPENT_ENC_TEST_VECTORS);
1042 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1043 SERPENT_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 break;
1045
1046 case 10:
Herbert Xucba83562006-08-13 08:26:09 +10001047 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1048 AES_ENC_TEST_VECTORS);
1049 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1050 AES_DEC_TEST_VECTORS);
1051 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1052 AES_CBC_ENC_TEST_VECTORS);
1053 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1054 AES_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 break;
1056
1057 case 11:
1058 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1059 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 case 12:
1062 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1063 break;
1064
1065 case 13:
1066 test_deflate();
1067 break;
1068
1069 case 14:
Herbert Xucba83562006-08-13 08:26:09 +10001070 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1071 CAST5_ENC_TEST_VECTORS);
1072 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1073 CAST5_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 break;
1075
1076 case 15:
Herbert Xucba83562006-08-13 08:26:09 +10001077 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1078 CAST6_ENC_TEST_VECTORS);
1079 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1080 CAST6_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 break;
1082
1083 case 16:
Herbert Xucba83562006-08-13 08:26:09 +10001084 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1085 ARC4_ENC_TEST_VECTORS);
1086 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1087 ARC4_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 break;
1089
1090 case 17:
1091 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1092 break;
1093
1094 case 18:
Herbert Xuc907ee72006-08-21 22:04:03 +10001095 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 break;
1097
1098 case 19:
Herbert Xucba83562006-08-13 08:26:09 +10001099 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1100 TEA_ENC_TEST_VECTORS);
1101 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1102 TEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 break;
1104
1105 case 20:
Herbert Xucba83562006-08-13 08:26:09 +10001106 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1107 XTEA_ENC_TEST_VECTORS);
1108 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1109 XTEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 break;
1111
1112 case 21:
Herbert Xucba83562006-08-13 08:26:09 +10001113 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1114 KHAZAD_ENC_TEST_VECTORS);
1115 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1116 KHAZAD_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 break;
1118
1119 case 22:
1120 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1121 break;
1122
1123 case 23:
1124 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1125 break;
1126
1127 case 24:
1128 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1129 break;
1130
1131 case 25:
Herbert Xucba83562006-08-13 08:26:09 +10001132 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1133 TNEPRES_ENC_TEST_VECTORS);
1134 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1135 TNEPRES_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 break;
1137
1138 case 26:
Herbert Xucba83562006-08-13 08:26:09 +10001139 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1140 ANUBIS_ENC_TEST_VECTORS);
1141 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1142 ANUBIS_DEC_TEST_VECTORS);
1143 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1144 ANUBIS_CBC_ENC_TEST_VECTORS);
1145 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1146 ANUBIS_CBC_ENC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 break;
1148
1149 case 27:
1150 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1151 break;
1152
1153 case 28:
1154
1155 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1156 break;
1157
1158 case 29:
1159 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1160 break;
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001161
1162 case 30:
Herbert Xucba83562006-08-13 08:26:09 +10001163 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1164 XETA_ENC_TEST_VECTORS);
1165 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1166 XETA_DEC_TEST_VECTORS);
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001167 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 case 100:
Herbert Xue9d41162006-08-19 21:38:49 +10001170 test_hash("hmac(md5)", hmac_md5_tv_template,
1171 HMAC_MD5_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001173
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 case 101:
Herbert Xue9d41162006-08-19 21:38:49 +10001175 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1176 HMAC_SHA1_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001178
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 case 102:
Herbert Xue9d41162006-08-19 21:38:49 +10001180 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1181 HMAC_SHA256_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 break;
1183
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
Harald Welteebfd9bc2005-06-22 13:27:23 -07001185 case 200:
Herbert Xucba83562006-08-13 08:26:09 +10001186 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001187 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001188 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001189 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001190 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001191 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001192 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001193 aes_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001194 break;
1195
1196 case 201:
Herbert Xucba83562006-08-13 08:26:09 +10001197 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001198 des3_ede_enc_tv_template,
1199 DES3_EDE_ENC_TEST_VECTORS,
1200 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001201 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001202 des3_ede_dec_tv_template,
1203 DES3_EDE_DEC_TEST_VECTORS,
1204 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001205 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001206 des3_ede_enc_tv_template,
1207 DES3_EDE_ENC_TEST_VECTORS,
1208 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001209 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001210 des3_ede_dec_tv_template,
1211 DES3_EDE_DEC_TEST_VECTORS,
1212 des3_ede_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001213 break;
1214
1215 case 202:
Herbert Xucba83562006-08-13 08:26:09 +10001216 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001217 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001218 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001219 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001220 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001221 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001222 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001223 twofish_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001224 break;
1225
1226 case 203:
Herbert Xucba83562006-08-13 08:26:09 +10001227 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001228 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001229 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001230 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001231 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001232 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001233 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001234 blowfish_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001235 break;
1236
1237 case 204:
Herbert Xucba83562006-08-13 08:26:09 +10001238 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001239 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001240 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001241 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001242 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001243 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001244 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001245 des_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001246 break;
1247
Michal Ludvige8057922006-05-30 22:04:19 +10001248 case 300:
1249 /* fall through */
1250
1251 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +10001252 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001253 if (mode > 300 && mode < 400) break;
1254
1255 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +10001256 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001257 if (mode > 300 && mode < 400) break;
1258
1259 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +10001260 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001261 if (mode > 300 && mode < 400) break;
1262
1263 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +10001264 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001265 if (mode > 300 && mode < 400) break;
1266
1267 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +10001268 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001269 if (mode > 300 && mode < 400) break;
1270
1271 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +10001272 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001273 if (mode > 300 && mode < 400) break;
1274
1275 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +10001276 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001277 if (mode > 300 && mode < 400) break;
1278
1279 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +10001280 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001281 if (mode > 300 && mode < 400) break;
1282
1283 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +10001284 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001285 if (mode > 300 && mode < 400) break;
1286
1287 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +10001288 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001289 if (mode > 300 && mode < 400) break;
1290
1291 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +10001292 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001293 if (mode > 300 && mode < 400) break;
1294
1295 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +10001296 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001297 if (mode > 300 && mode < 400) break;
1298
1299 case 399:
1300 break;
1301
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 case 1000:
1303 test_available();
1304 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 default:
1307 /* useful for debugging */
1308 printk("not testing anything\n");
1309 break;
1310 }
1311}
1312
Herbert Xuef2736f2005-06-22 13:26:03 -07001313static int __init init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314{
1315 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1316 if (tvmem == NULL)
1317 return -ENOMEM;
1318
1319 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1320 if (xbuf == NULL) {
1321 kfree(tvmem);
1322 return -ENOMEM;
1323 }
1324
1325 do_test();
1326
1327 kfree(xbuf);
1328 kfree(tvmem);
Michal Ludvig14fdf472006-05-30 14:49:38 +10001329
1330 /* We intentionaly return -EAGAIN to prevent keeping
1331 * the module. It does all its work from init()
1332 * and doesn't offer any runtime functionality
1333 * => we don't need it in the memory, do we?
1334 * -- mludvig
1335 */
1336 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337}
1338
1339/*
1340 * If an init function is provided, an exit function must also be provided
1341 * to allow module unload.
1342 */
1343static void __exit fini(void) { }
1344
1345module_init(init);
1346module_exit(fini);
1347
1348module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001349module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -07001350MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1351 "(defaults to zero which uses CPU cycles instead)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
1353MODULE_LICENSE("GPL");
1354MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1355MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");