Commit 7bc301e97b96597df967f11b9fa9cf391109893a

Authored by Sebastian Siewior
Committed by Herbert Xu
1 parent 58e40308f3

[CRYPTO] tcrypt: Fix error checking for comp allocation

This patch fixes loading the tcrypt module while deflate isn't available
at all (isn't build).

Signed-off-by: Sebastian Siewior <linux-crypto@ml.breakpoint.cc>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Showing 1 changed file with 1 additions and 1 deletions Inline Diff

1 /* 1 /*
2 * Quick & dirty crypto testing module. 2 * Quick & dirty crypto testing module.
3 * 3 *
4 * This will only exist until we have a better testing mechanism 4 * This will only exist until we have a better testing mechanism
5 * (e.g. a char device). 5 * (e.g. a char device).
6 * 6 *
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> 7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org> 8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify it 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 11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option) 12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version. 13 * any later version.
14 * 14 *
15 * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests 15 * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests
16 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>) 16 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
17 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt 17 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
18 * 18 *
19 */ 19 */
20 20
21 #include <linux/err.h> 21 #include <linux/err.h>
22 #include <linux/init.h> 22 #include <linux/init.h>
23 #include <linux/module.h> 23 #include <linux/module.h>
24 #include <linux/mm.h> 24 #include <linux/mm.h>
25 #include <linux/slab.h> 25 #include <linux/slab.h>
26 #include <linux/scatterlist.h> 26 #include <linux/scatterlist.h>
27 #include <linux/string.h> 27 #include <linux/string.h>
28 #include <linux/crypto.h> 28 #include <linux/crypto.h>
29 #include <linux/highmem.h> 29 #include <linux/highmem.h>
30 #include <linux/moduleparam.h> 30 #include <linux/moduleparam.h>
31 #include <linux/jiffies.h> 31 #include <linux/jiffies.h>
32 #include <linux/timex.h> 32 #include <linux/timex.h>
33 #include <linux/interrupt.h> 33 #include <linux/interrupt.h>
34 #include "tcrypt.h" 34 #include "tcrypt.h"
35 35
36 /* 36 /*
37 * Need to kmalloc() memory for testing kmap(). 37 * Need to kmalloc() memory for testing kmap().
38 */ 38 */
39 #define TVMEMSIZE 16384 39 #define TVMEMSIZE 16384
40 #define XBUFSIZE 32768 40 #define XBUFSIZE 32768
41 41
42 /* 42 /*
43 * Indexes into the xbuf to simulate cross-page access. 43 * Indexes into the xbuf to simulate cross-page access.
44 */ 44 */
45 #define IDX1 37 45 #define IDX1 37
46 #define IDX2 32400 46 #define IDX2 32400
47 #define IDX3 1 47 #define IDX3 1
48 #define IDX4 8193 48 #define IDX4 8193
49 #define IDX5 22222 49 #define IDX5 22222
50 #define IDX6 17101 50 #define IDX6 17101
51 #define IDX7 27333 51 #define IDX7 27333
52 #define IDX8 3000 52 #define IDX8 3000
53 53
54 /* 54 /*
55 * Used by test_cipher() 55 * Used by test_cipher()
56 */ 56 */
57 #define ENCRYPT 1 57 #define ENCRYPT 1
58 #define DECRYPT 0 58 #define DECRYPT 0
59 59
60 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; 60 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
61 61
62 /* 62 /*
63 * Used by test_cipher_speed() 63 * Used by test_cipher_speed()
64 */ 64 */
65 static unsigned int sec; 65 static unsigned int sec;
66 66
67 static int mode; 67 static int mode;
68 static char *xbuf; 68 static char *xbuf;
69 static char *tvmem; 69 static char *tvmem;
70 70
71 static char *check[] = { 71 static char *check[] = {
72 "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish", 72 "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish",
73 "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6", 73 "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
74 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", 74 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
75 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", 75 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
76 "camellia", NULL 76 "camellia", NULL
77 }; 77 };
78 78
79 static void hexdump(unsigned char *buf, unsigned int len) 79 static void hexdump(unsigned char *buf, unsigned int len)
80 { 80 {
81 while (len--) 81 while (len--)
82 printk("%02x", *buf++); 82 printk("%02x", *buf++);
83 83
84 printk("\n"); 84 printk("\n");
85 } 85 }
86 86
87 static void test_hash(char *algo, struct hash_testvec *template, 87 static void test_hash(char *algo, struct hash_testvec *template,
88 unsigned int tcount) 88 unsigned int tcount)
89 { 89 {
90 unsigned int i, j, k, temp; 90 unsigned int i, j, k, temp;
91 struct scatterlist sg[8]; 91 struct scatterlist sg[8];
92 char result[64]; 92 char result[64];
93 struct crypto_hash *tfm; 93 struct crypto_hash *tfm;
94 struct hash_desc desc; 94 struct hash_desc desc;
95 struct hash_testvec *hash_tv; 95 struct hash_testvec *hash_tv;
96 unsigned int tsize; 96 unsigned int tsize;
97 int ret; 97 int ret;
98 98
99 printk("\ntesting %s\n", algo); 99 printk("\ntesting %s\n", algo);
100 100
101 tsize = sizeof(struct hash_testvec); 101 tsize = sizeof(struct hash_testvec);
102 tsize *= tcount; 102 tsize *= tcount;
103 103
104 if (tsize > TVMEMSIZE) { 104 if (tsize > TVMEMSIZE) {
105 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE); 105 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
106 return; 106 return;
107 } 107 }
108 108
109 memcpy(tvmem, template, tsize); 109 memcpy(tvmem, template, tsize);
110 hash_tv = (void *)tvmem; 110 hash_tv = (void *)tvmem;
111 111
112 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); 112 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
113 if (IS_ERR(tfm)) { 113 if (IS_ERR(tfm)) {
114 printk("failed to load transform for %s: %ld\n", algo, 114 printk("failed to load transform for %s: %ld\n", algo,
115 PTR_ERR(tfm)); 115 PTR_ERR(tfm));
116 return; 116 return;
117 } 117 }
118 118
119 desc.tfm = tfm; 119 desc.tfm = tfm;
120 desc.flags = 0; 120 desc.flags = 0;
121 121
122 for (i = 0; i < tcount; i++) { 122 for (i = 0; i < tcount; i++) {
123 printk("test %u:\n", i + 1); 123 printk("test %u:\n", i + 1);
124 memset(result, 0, 64); 124 memset(result, 0, 64);
125 125
126 sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize); 126 sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
127 127
128 if (hash_tv[i].ksize) { 128 if (hash_tv[i].ksize) {
129 ret = crypto_hash_setkey(tfm, hash_tv[i].key, 129 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
130 hash_tv[i].ksize); 130 hash_tv[i].ksize);
131 if (ret) { 131 if (ret) {
132 printk("setkey() failed ret=%d\n", ret); 132 printk("setkey() failed ret=%d\n", ret);
133 goto out; 133 goto out;
134 } 134 }
135 } 135 }
136 136
137 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, result); 137 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, result);
138 if (ret) { 138 if (ret) {
139 printk("digest () failed ret=%d\n", ret); 139 printk("digest () failed ret=%d\n", ret);
140 goto out; 140 goto out;
141 } 141 }
142 142
143 hexdump(result, crypto_hash_digestsize(tfm)); 143 hexdump(result, crypto_hash_digestsize(tfm));
144 printk("%s\n", 144 printk("%s\n",
145 memcmp(result, hash_tv[i].digest, 145 memcmp(result, hash_tv[i].digest,
146 crypto_hash_digestsize(tfm)) ? 146 crypto_hash_digestsize(tfm)) ?
147 "fail" : "pass"); 147 "fail" : "pass");
148 } 148 }
149 149
150 printk("testing %s across pages\n", algo); 150 printk("testing %s across pages\n", algo);
151 151
152 /* setup the dummy buffer first */ 152 /* setup the dummy buffer first */
153 memset(xbuf, 0, XBUFSIZE); 153 memset(xbuf, 0, XBUFSIZE);
154 154
155 j = 0; 155 j = 0;
156 for (i = 0; i < tcount; i++) { 156 for (i = 0; i < tcount; i++) {
157 if (hash_tv[i].np) { 157 if (hash_tv[i].np) {
158 j++; 158 j++;
159 printk("test %u:\n", j); 159 printk("test %u:\n", j);
160 memset(result, 0, 64); 160 memset(result, 0, 64);
161 161
162 temp = 0; 162 temp = 0;
163 for (k = 0; k < hash_tv[i].np; k++) { 163 for (k = 0; k < hash_tv[i].np; k++) {
164 memcpy(&xbuf[IDX[k]], 164 memcpy(&xbuf[IDX[k]],
165 hash_tv[i].plaintext + temp, 165 hash_tv[i].plaintext + temp,
166 hash_tv[i].tap[k]); 166 hash_tv[i].tap[k]);
167 temp += hash_tv[i].tap[k]; 167 temp += hash_tv[i].tap[k];
168 sg_set_buf(&sg[k], &xbuf[IDX[k]], 168 sg_set_buf(&sg[k], &xbuf[IDX[k]],
169 hash_tv[i].tap[k]); 169 hash_tv[i].tap[k]);
170 } 170 }
171 171
172 if (hash_tv[i].ksize) { 172 if (hash_tv[i].ksize) {
173 ret = crypto_hash_setkey(tfm, hash_tv[i].key, 173 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
174 hash_tv[i].ksize); 174 hash_tv[i].ksize);
175 175
176 if (ret) { 176 if (ret) {
177 printk("setkey() failed ret=%d\n", ret); 177 printk("setkey() failed ret=%d\n", ret);
178 goto out; 178 goto out;
179 } 179 }
180 } 180 }
181 181
182 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, 182 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize,
183 result); 183 result);
184 if (ret) { 184 if (ret) {
185 printk("digest () failed ret=%d\n", ret); 185 printk("digest () failed ret=%d\n", ret);
186 goto out; 186 goto out;
187 } 187 }
188 188
189 hexdump(result, crypto_hash_digestsize(tfm)); 189 hexdump(result, crypto_hash_digestsize(tfm));
190 printk("%s\n", 190 printk("%s\n",
191 memcmp(result, hash_tv[i].digest, 191 memcmp(result, hash_tv[i].digest,
192 crypto_hash_digestsize(tfm)) ? 192 crypto_hash_digestsize(tfm)) ?
193 "fail" : "pass"); 193 "fail" : "pass");
194 } 194 }
195 } 195 }
196 196
197 out: 197 out:
198 crypto_free_hash(tfm); 198 crypto_free_hash(tfm);
199 } 199 }
200 200
201 static void test_cipher(char *algo, int enc, 201 static void test_cipher(char *algo, int enc,
202 struct cipher_testvec *template, unsigned int tcount) 202 struct cipher_testvec *template, unsigned int tcount)
203 { 203 {
204 unsigned int ret, i, j, k, temp; 204 unsigned int ret, i, j, k, temp;
205 unsigned int tsize; 205 unsigned int tsize;
206 unsigned int iv_len; 206 unsigned int iv_len;
207 unsigned int len; 207 unsigned int len;
208 char *q; 208 char *q;
209 struct crypto_blkcipher *tfm; 209 struct crypto_blkcipher *tfm;
210 char *key; 210 char *key;
211 struct cipher_testvec *cipher_tv; 211 struct cipher_testvec *cipher_tv;
212 struct blkcipher_desc desc; 212 struct blkcipher_desc desc;
213 struct scatterlist sg[8]; 213 struct scatterlist sg[8];
214 const char *e; 214 const char *e;
215 215
216 if (enc == ENCRYPT) 216 if (enc == ENCRYPT)
217 e = "encryption"; 217 e = "encryption";
218 else 218 else
219 e = "decryption"; 219 e = "decryption";
220 220
221 printk("\ntesting %s %s\n", algo, e); 221 printk("\ntesting %s %s\n", algo, e);
222 222
223 tsize = sizeof (struct cipher_testvec); 223 tsize = sizeof (struct cipher_testvec);
224 tsize *= tcount; 224 tsize *= tcount;
225 225
226 if (tsize > TVMEMSIZE) { 226 if (tsize > TVMEMSIZE) {
227 printk("template (%u) too big for tvmem (%u)\n", tsize, 227 printk("template (%u) too big for tvmem (%u)\n", tsize,
228 TVMEMSIZE); 228 TVMEMSIZE);
229 return; 229 return;
230 } 230 }
231 231
232 memcpy(tvmem, template, tsize); 232 memcpy(tvmem, template, tsize);
233 cipher_tv = (void *)tvmem; 233 cipher_tv = (void *)tvmem;
234 234
235 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC); 235 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
236 236
237 if (IS_ERR(tfm)) { 237 if (IS_ERR(tfm)) {
238 printk("failed to load transform for %s: %ld\n", algo, 238 printk("failed to load transform for %s: %ld\n", algo,
239 PTR_ERR(tfm)); 239 PTR_ERR(tfm));
240 return; 240 return;
241 } 241 }
242 desc.tfm = tfm; 242 desc.tfm = tfm;
243 desc.flags = 0; 243 desc.flags = 0;
244 244
245 j = 0; 245 j = 0;
246 for (i = 0; i < tcount; i++) { 246 for (i = 0; i < tcount; i++) {
247 if (!(cipher_tv[i].np)) { 247 if (!(cipher_tv[i].np)) {
248 j++; 248 j++;
249 printk("test %u (%d bit key):\n", 249 printk("test %u (%d bit key):\n",
250 j, cipher_tv[i].klen * 8); 250 j, cipher_tv[i].klen * 8);
251 251
252 crypto_blkcipher_clear_flags(tfm, ~0); 252 crypto_blkcipher_clear_flags(tfm, ~0);
253 if (cipher_tv[i].wk) 253 if (cipher_tv[i].wk)
254 crypto_blkcipher_set_flags( 254 crypto_blkcipher_set_flags(
255 tfm, CRYPTO_TFM_REQ_WEAK_KEY); 255 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
256 key = cipher_tv[i].key; 256 key = cipher_tv[i].key;
257 257
258 ret = crypto_blkcipher_setkey(tfm, key, 258 ret = crypto_blkcipher_setkey(tfm, key,
259 cipher_tv[i].klen); 259 cipher_tv[i].klen);
260 if (ret) { 260 if (ret) {
261 printk("setkey() failed flags=%x\n", 261 printk("setkey() failed flags=%x\n",
262 crypto_blkcipher_get_flags(tfm)); 262 crypto_blkcipher_get_flags(tfm));
263 263
264 if (!cipher_tv[i].fail) 264 if (!cipher_tv[i].fail)
265 goto out; 265 goto out;
266 } 266 }
267 267
268 sg_set_buf(&sg[0], cipher_tv[i].input, 268 sg_set_buf(&sg[0], cipher_tv[i].input,
269 cipher_tv[i].ilen); 269 cipher_tv[i].ilen);
270 270
271 iv_len = crypto_blkcipher_ivsize(tfm); 271 iv_len = crypto_blkcipher_ivsize(tfm);
272 if (iv_len) 272 if (iv_len)
273 crypto_blkcipher_set_iv(tfm, cipher_tv[i].iv, 273 crypto_blkcipher_set_iv(tfm, cipher_tv[i].iv,
274 iv_len); 274 iv_len);
275 275
276 len = cipher_tv[i].ilen; 276 len = cipher_tv[i].ilen;
277 ret = enc ? 277 ret = enc ?
278 crypto_blkcipher_encrypt(&desc, sg, sg, len) : 278 crypto_blkcipher_encrypt(&desc, sg, sg, len) :
279 crypto_blkcipher_decrypt(&desc, sg, sg, len); 279 crypto_blkcipher_decrypt(&desc, sg, sg, len);
280 280
281 if (ret) { 281 if (ret) {
282 printk("%s () failed flags=%x\n", e, 282 printk("%s () failed flags=%x\n", e,
283 desc.flags); 283 desc.flags);
284 goto out; 284 goto out;
285 } 285 }
286 286
287 q = kmap(sg[0].page) + sg[0].offset; 287 q = kmap(sg[0].page) + sg[0].offset;
288 hexdump(q, cipher_tv[i].rlen); 288 hexdump(q, cipher_tv[i].rlen);
289 289
290 printk("%s\n", 290 printk("%s\n",
291 memcmp(q, cipher_tv[i].result, 291 memcmp(q, cipher_tv[i].result,
292 cipher_tv[i].rlen) ? "fail" : "pass"); 292 cipher_tv[i].rlen) ? "fail" : "pass");
293 } 293 }
294 } 294 }
295 295
296 printk("\ntesting %s %s across pages (chunking)\n", algo, e); 296 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
297 memset(xbuf, 0, XBUFSIZE); 297 memset(xbuf, 0, XBUFSIZE);
298 298
299 j = 0; 299 j = 0;
300 for (i = 0; i < tcount; i++) { 300 for (i = 0; i < tcount; i++) {
301 if (cipher_tv[i].np) { 301 if (cipher_tv[i].np) {
302 j++; 302 j++;
303 printk("test %u (%d bit key):\n", 303 printk("test %u (%d bit key):\n",
304 j, cipher_tv[i].klen * 8); 304 j, cipher_tv[i].klen * 8);
305 305
306 crypto_blkcipher_clear_flags(tfm, ~0); 306 crypto_blkcipher_clear_flags(tfm, ~0);
307 if (cipher_tv[i].wk) 307 if (cipher_tv[i].wk)
308 crypto_blkcipher_set_flags( 308 crypto_blkcipher_set_flags(
309 tfm, CRYPTO_TFM_REQ_WEAK_KEY); 309 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
310 key = cipher_tv[i].key; 310 key = cipher_tv[i].key;
311 311
312 ret = crypto_blkcipher_setkey(tfm, key, 312 ret = crypto_blkcipher_setkey(tfm, key,
313 cipher_tv[i].klen); 313 cipher_tv[i].klen);
314 if (ret) { 314 if (ret) {
315 printk("setkey() failed flags=%x\n", 315 printk("setkey() failed flags=%x\n",
316 crypto_blkcipher_get_flags(tfm)); 316 crypto_blkcipher_get_flags(tfm));
317 317
318 if (!cipher_tv[i].fail) 318 if (!cipher_tv[i].fail)
319 goto out; 319 goto out;
320 } 320 }
321 321
322 temp = 0; 322 temp = 0;
323 for (k = 0; k < cipher_tv[i].np; k++) { 323 for (k = 0; k < cipher_tv[i].np; k++) {
324 memcpy(&xbuf[IDX[k]], 324 memcpy(&xbuf[IDX[k]],
325 cipher_tv[i].input + temp, 325 cipher_tv[i].input + temp,
326 cipher_tv[i].tap[k]); 326 cipher_tv[i].tap[k]);
327 temp += cipher_tv[i].tap[k]; 327 temp += cipher_tv[i].tap[k];
328 sg_set_buf(&sg[k], &xbuf[IDX[k]], 328 sg_set_buf(&sg[k], &xbuf[IDX[k]],
329 cipher_tv[i].tap[k]); 329 cipher_tv[i].tap[k]);
330 } 330 }
331 331
332 iv_len = crypto_blkcipher_ivsize(tfm); 332 iv_len = crypto_blkcipher_ivsize(tfm);
333 if (iv_len) 333 if (iv_len)
334 crypto_blkcipher_set_iv(tfm, cipher_tv[i].iv, 334 crypto_blkcipher_set_iv(tfm, cipher_tv[i].iv,
335 iv_len); 335 iv_len);
336 336
337 len = cipher_tv[i].ilen; 337 len = cipher_tv[i].ilen;
338 ret = enc ? 338 ret = enc ?
339 crypto_blkcipher_encrypt(&desc, sg, sg, len) : 339 crypto_blkcipher_encrypt(&desc, sg, sg, len) :
340 crypto_blkcipher_decrypt(&desc, sg, sg, len); 340 crypto_blkcipher_decrypt(&desc, sg, sg, len);
341 341
342 if (ret) { 342 if (ret) {
343 printk("%s () failed flags=%x\n", e, 343 printk("%s () failed flags=%x\n", e,
344 desc.flags); 344 desc.flags);
345 goto out; 345 goto out;
346 } 346 }
347 347
348 temp = 0; 348 temp = 0;
349 for (k = 0; k < cipher_tv[i].np; k++) { 349 for (k = 0; k < cipher_tv[i].np; k++) {
350 printk("page %u\n", k); 350 printk("page %u\n", k);
351 q = kmap(sg[k].page) + sg[k].offset; 351 q = kmap(sg[k].page) + sg[k].offset;
352 hexdump(q, cipher_tv[i].tap[k]); 352 hexdump(q, cipher_tv[i].tap[k]);
353 printk("%s\n", 353 printk("%s\n",
354 memcmp(q, cipher_tv[i].result + temp, 354 memcmp(q, cipher_tv[i].result + temp,
355 cipher_tv[i].tap[k]) ? "fail" : 355 cipher_tv[i].tap[k]) ? "fail" :
356 "pass"); 356 "pass");
357 temp += cipher_tv[i].tap[k]; 357 temp += cipher_tv[i].tap[k];
358 } 358 }
359 } 359 }
360 } 360 }
361 361
362 out: 362 out:
363 crypto_free_blkcipher(tfm); 363 crypto_free_blkcipher(tfm);
364 } 364 }
365 365
366 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p, 366 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
367 int blen, int sec) 367 int blen, int sec)
368 { 368 {
369 struct scatterlist sg[1]; 369 struct scatterlist sg[1];
370 unsigned long start, end; 370 unsigned long start, end;
371 int bcount; 371 int bcount;
372 int ret; 372 int ret;
373 373
374 sg_set_buf(sg, p, blen); 374 sg_set_buf(sg, p, blen);
375 375
376 for (start = jiffies, end = start + sec * HZ, bcount = 0; 376 for (start = jiffies, end = start + sec * HZ, bcount = 0;
377 time_before(jiffies, end); bcount++) { 377 time_before(jiffies, end); bcount++) {
378 if (enc) 378 if (enc)
379 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); 379 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
380 else 380 else
381 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); 381 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
382 382
383 if (ret) 383 if (ret)
384 return ret; 384 return ret;
385 } 385 }
386 386
387 printk("%d operations in %d seconds (%ld bytes)\n", 387 printk("%d operations in %d seconds (%ld bytes)\n",
388 bcount, sec, (long)bcount * blen); 388 bcount, sec, (long)bcount * blen);
389 return 0; 389 return 0;
390 } 390 }
391 391
392 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p, 392 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
393 int blen) 393 int blen)
394 { 394 {
395 struct scatterlist sg[1]; 395 struct scatterlist sg[1];
396 unsigned long cycles = 0; 396 unsigned long cycles = 0;
397 int ret = 0; 397 int ret = 0;
398 int i; 398 int i;
399 399
400 sg_set_buf(sg, p, blen); 400 sg_set_buf(sg, p, blen);
401 401
402 local_bh_disable(); 402 local_bh_disable();
403 local_irq_disable(); 403 local_irq_disable();
404 404
405 /* Warm-up run. */ 405 /* Warm-up run. */
406 for (i = 0; i < 4; i++) { 406 for (i = 0; i < 4; i++) {
407 if (enc) 407 if (enc)
408 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); 408 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
409 else 409 else
410 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); 410 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
411 411
412 if (ret) 412 if (ret)
413 goto out; 413 goto out;
414 } 414 }
415 415
416 /* The real thing. */ 416 /* The real thing. */
417 for (i = 0; i < 8; i++) { 417 for (i = 0; i < 8; i++) {
418 cycles_t start, end; 418 cycles_t start, end;
419 419
420 start = get_cycles(); 420 start = get_cycles();
421 if (enc) 421 if (enc)
422 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); 422 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
423 else 423 else
424 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); 424 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
425 end = get_cycles(); 425 end = get_cycles();
426 426
427 if (ret) 427 if (ret)
428 goto out; 428 goto out;
429 429
430 cycles += end - start; 430 cycles += end - start;
431 } 431 }
432 432
433 out: 433 out:
434 local_irq_enable(); 434 local_irq_enable();
435 local_bh_enable(); 435 local_bh_enable();
436 436
437 if (ret == 0) 437 if (ret == 0)
438 printk("1 operation in %lu cycles (%d bytes)\n", 438 printk("1 operation in %lu cycles (%d bytes)\n",
439 (cycles + 4) / 8, blen); 439 (cycles + 4) / 8, blen);
440 440
441 return ret; 441 return ret;
442 } 442 }
443 443
444 static void test_cipher_speed(char *algo, int enc, unsigned int sec, 444 static void test_cipher_speed(char *algo, int enc, unsigned int sec,
445 struct cipher_testvec *template, 445 struct cipher_testvec *template,
446 unsigned int tcount, struct cipher_speed *speed) 446 unsigned int tcount, struct cipher_speed *speed)
447 { 447 {
448 unsigned int ret, i, j, iv_len; 448 unsigned int ret, i, j, iv_len;
449 unsigned char *key, *p, iv[128]; 449 unsigned char *key, *p, iv[128];
450 struct crypto_blkcipher *tfm; 450 struct crypto_blkcipher *tfm;
451 struct blkcipher_desc desc; 451 struct blkcipher_desc desc;
452 const char *e; 452 const char *e;
453 453
454 if (enc == ENCRYPT) 454 if (enc == ENCRYPT)
455 e = "encryption"; 455 e = "encryption";
456 else 456 else
457 e = "decryption"; 457 e = "decryption";
458 458
459 printk("\ntesting speed of %s %s\n", algo, e); 459 printk("\ntesting speed of %s %s\n", algo, e);
460 460
461 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC); 461 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
462 462
463 if (IS_ERR(tfm)) { 463 if (IS_ERR(tfm)) {
464 printk("failed to load transform for %s: %ld\n", algo, 464 printk("failed to load transform for %s: %ld\n", algo,
465 PTR_ERR(tfm)); 465 PTR_ERR(tfm));
466 return; 466 return;
467 } 467 }
468 desc.tfm = tfm; 468 desc.tfm = tfm;
469 desc.flags = 0; 469 desc.flags = 0;
470 470
471 for (i = 0; speed[i].klen != 0; i++) { 471 for (i = 0; speed[i].klen != 0; i++) {
472 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) { 472 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
473 printk("template (%u) too big for tvmem (%u)\n", 473 printk("template (%u) too big for tvmem (%u)\n",
474 speed[i].blen + speed[i].klen, TVMEMSIZE); 474 speed[i].blen + speed[i].klen, TVMEMSIZE);
475 goto out; 475 goto out;
476 } 476 }
477 477
478 printk("test %u (%d bit key, %d byte blocks): ", i, 478 printk("test %u (%d bit key, %d byte blocks): ", i,
479 speed[i].klen * 8, speed[i].blen); 479 speed[i].klen * 8, speed[i].blen);
480 480
481 memset(tvmem, 0xff, speed[i].klen + speed[i].blen); 481 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
482 482
483 /* set key, plain text and IV */ 483 /* set key, plain text and IV */
484 key = (unsigned char *)tvmem; 484 key = (unsigned char *)tvmem;
485 for (j = 0; j < tcount; j++) { 485 for (j = 0; j < tcount; j++) {
486 if (template[j].klen == speed[i].klen) { 486 if (template[j].klen == speed[i].klen) {
487 key = template[j].key; 487 key = template[j].key;
488 break; 488 break;
489 } 489 }
490 } 490 }
491 p = (unsigned char *)tvmem + speed[i].klen; 491 p = (unsigned char *)tvmem + speed[i].klen;
492 492
493 ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen); 493 ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
494 if (ret) { 494 if (ret) {
495 printk("setkey() failed flags=%x\n", 495 printk("setkey() failed flags=%x\n",
496 crypto_blkcipher_get_flags(tfm)); 496 crypto_blkcipher_get_flags(tfm));
497 goto out; 497 goto out;
498 } 498 }
499 499
500 iv_len = crypto_blkcipher_ivsize(tfm); 500 iv_len = crypto_blkcipher_ivsize(tfm);
501 if (iv_len) { 501 if (iv_len) {
502 memset(&iv, 0xff, iv_len); 502 memset(&iv, 0xff, iv_len);
503 crypto_blkcipher_set_iv(tfm, iv, iv_len); 503 crypto_blkcipher_set_iv(tfm, iv, iv_len);
504 } 504 }
505 505
506 if (sec) 506 if (sec)
507 ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen, 507 ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen,
508 sec); 508 sec);
509 else 509 else
510 ret = test_cipher_cycles(&desc, enc, p, speed[i].blen); 510 ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
511 511
512 if (ret) { 512 if (ret) {
513 printk("%s() failed flags=%x\n", e, desc.flags); 513 printk("%s() failed flags=%x\n", e, desc.flags);
514 break; 514 break;
515 } 515 }
516 } 516 }
517 517
518 out: 518 out:
519 crypto_free_blkcipher(tfm); 519 crypto_free_blkcipher(tfm);
520 } 520 }
521 521
522 static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen, 522 static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
523 char *out, int sec) 523 char *out, int sec)
524 { 524 {
525 struct scatterlist sg[1]; 525 struct scatterlist sg[1];
526 unsigned long start, end; 526 unsigned long start, end;
527 int bcount; 527 int bcount;
528 int ret; 528 int ret;
529 529
530 for (start = jiffies, end = start + sec * HZ, bcount = 0; 530 for (start = jiffies, end = start + sec * HZ, bcount = 0;
531 time_before(jiffies, end); bcount++) { 531 time_before(jiffies, end); bcount++) {
532 sg_set_buf(sg, p, blen); 532 sg_set_buf(sg, p, blen);
533 ret = crypto_hash_digest(desc, sg, blen, out); 533 ret = crypto_hash_digest(desc, sg, blen, out);
534 if (ret) 534 if (ret)
535 return ret; 535 return ret;
536 } 536 }
537 537
538 printk("%6u opers/sec, %9lu bytes/sec\n", 538 printk("%6u opers/sec, %9lu bytes/sec\n",
539 bcount / sec, ((long)bcount * blen) / sec); 539 bcount / sec, ((long)bcount * blen) / sec);
540 540
541 return 0; 541 return 0;
542 } 542 }
543 543
544 static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen, 544 static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
545 int plen, char *out, int sec) 545 int plen, char *out, int sec)
546 { 546 {
547 struct scatterlist sg[1]; 547 struct scatterlist sg[1];
548 unsigned long start, end; 548 unsigned long start, end;
549 int bcount, pcount; 549 int bcount, pcount;
550 int ret; 550 int ret;
551 551
552 if (plen == blen) 552 if (plen == blen)
553 return test_hash_jiffies_digest(desc, p, blen, out, sec); 553 return test_hash_jiffies_digest(desc, p, blen, out, sec);
554 554
555 for (start = jiffies, end = start + sec * HZ, bcount = 0; 555 for (start = jiffies, end = start + sec * HZ, bcount = 0;
556 time_before(jiffies, end); bcount++) { 556 time_before(jiffies, end); bcount++) {
557 ret = crypto_hash_init(desc); 557 ret = crypto_hash_init(desc);
558 if (ret) 558 if (ret)
559 return ret; 559 return ret;
560 for (pcount = 0; pcount < blen; pcount += plen) { 560 for (pcount = 0; pcount < blen; pcount += plen) {
561 sg_set_buf(sg, p + pcount, plen); 561 sg_set_buf(sg, p + pcount, plen);
562 ret = crypto_hash_update(desc, sg, plen); 562 ret = crypto_hash_update(desc, sg, plen);
563 if (ret) 563 if (ret)
564 return ret; 564 return ret;
565 } 565 }
566 /* we assume there is enough space in 'out' for the result */ 566 /* we assume there is enough space in 'out' for the result */
567 ret = crypto_hash_final(desc, out); 567 ret = crypto_hash_final(desc, out);
568 if (ret) 568 if (ret)
569 return ret; 569 return ret;
570 } 570 }
571 571
572 printk("%6u opers/sec, %9lu bytes/sec\n", 572 printk("%6u opers/sec, %9lu bytes/sec\n",
573 bcount / sec, ((long)bcount * blen) / sec); 573 bcount / sec, ((long)bcount * blen) / sec);
574 574
575 return 0; 575 return 0;
576 } 576 }
577 577
578 static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen, 578 static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
579 char *out) 579 char *out)
580 { 580 {
581 struct scatterlist sg[1]; 581 struct scatterlist sg[1];
582 unsigned long cycles = 0; 582 unsigned long cycles = 0;
583 int i; 583 int i;
584 int ret; 584 int ret;
585 585
586 local_bh_disable(); 586 local_bh_disable();
587 local_irq_disable(); 587 local_irq_disable();
588 588
589 /* Warm-up run. */ 589 /* Warm-up run. */
590 for (i = 0; i < 4; i++) { 590 for (i = 0; i < 4; i++) {
591 sg_set_buf(sg, p, blen); 591 sg_set_buf(sg, p, blen);
592 ret = crypto_hash_digest(desc, sg, blen, out); 592 ret = crypto_hash_digest(desc, sg, blen, out);
593 if (ret) 593 if (ret)
594 goto out; 594 goto out;
595 } 595 }
596 596
597 /* The real thing. */ 597 /* The real thing. */
598 for (i = 0; i < 8; i++) { 598 for (i = 0; i < 8; i++) {
599 cycles_t start, end; 599 cycles_t start, end;
600 600
601 start = get_cycles(); 601 start = get_cycles();
602 602
603 sg_set_buf(sg, p, blen); 603 sg_set_buf(sg, p, blen);
604 ret = crypto_hash_digest(desc, sg, blen, out); 604 ret = crypto_hash_digest(desc, sg, blen, out);
605 if (ret) 605 if (ret)
606 goto out; 606 goto out;
607 607
608 end = get_cycles(); 608 end = get_cycles();
609 609
610 cycles += end - start; 610 cycles += end - start;
611 } 611 }
612 612
613 out: 613 out:
614 local_irq_enable(); 614 local_irq_enable();
615 local_bh_enable(); 615 local_bh_enable();
616 616
617 if (ret) 617 if (ret)
618 return ret; 618 return ret;
619 619
620 printk("%6lu cycles/operation, %4lu cycles/byte\n", 620 printk("%6lu cycles/operation, %4lu cycles/byte\n",
621 cycles / 8, cycles / (8 * blen)); 621 cycles / 8, cycles / (8 * blen));
622 622
623 return 0; 623 return 0;
624 } 624 }
625 625
626 static int test_hash_cycles(struct hash_desc *desc, char *p, int blen, 626 static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
627 int plen, char *out) 627 int plen, char *out)
628 { 628 {
629 struct scatterlist sg[1]; 629 struct scatterlist sg[1];
630 unsigned long cycles = 0; 630 unsigned long cycles = 0;
631 int i, pcount; 631 int i, pcount;
632 int ret; 632 int ret;
633 633
634 if (plen == blen) 634 if (plen == blen)
635 return test_hash_cycles_digest(desc, p, blen, out); 635 return test_hash_cycles_digest(desc, p, blen, out);
636 636
637 local_bh_disable(); 637 local_bh_disable();
638 local_irq_disable(); 638 local_irq_disable();
639 639
640 /* Warm-up run. */ 640 /* Warm-up run. */
641 for (i = 0; i < 4; i++) { 641 for (i = 0; i < 4; i++) {
642 ret = crypto_hash_init(desc); 642 ret = crypto_hash_init(desc);
643 if (ret) 643 if (ret)
644 goto out; 644 goto out;
645 for (pcount = 0; pcount < blen; pcount += plen) { 645 for (pcount = 0; pcount < blen; pcount += plen) {
646 sg_set_buf(sg, p + pcount, plen); 646 sg_set_buf(sg, p + pcount, plen);
647 ret = crypto_hash_update(desc, sg, plen); 647 ret = crypto_hash_update(desc, sg, plen);
648 if (ret) 648 if (ret)
649 goto out; 649 goto out;
650 } 650 }
651 crypto_hash_final(desc, out); 651 crypto_hash_final(desc, out);
652 if (ret) 652 if (ret)
653 goto out; 653 goto out;
654 } 654 }
655 655
656 /* The real thing. */ 656 /* The real thing. */
657 for (i = 0; i < 8; i++) { 657 for (i = 0; i < 8; i++) {
658 cycles_t start, end; 658 cycles_t start, end;
659 659
660 start = get_cycles(); 660 start = get_cycles();
661 661
662 ret = crypto_hash_init(desc); 662 ret = crypto_hash_init(desc);
663 if (ret) 663 if (ret)
664 goto out; 664 goto out;
665 for (pcount = 0; pcount < blen; pcount += plen) { 665 for (pcount = 0; pcount < blen; pcount += plen) {
666 sg_set_buf(sg, p + pcount, plen); 666 sg_set_buf(sg, p + pcount, plen);
667 ret = crypto_hash_update(desc, sg, plen); 667 ret = crypto_hash_update(desc, sg, plen);
668 if (ret) 668 if (ret)
669 goto out; 669 goto out;
670 } 670 }
671 ret = crypto_hash_final(desc, out); 671 ret = crypto_hash_final(desc, out);
672 if (ret) 672 if (ret)
673 goto out; 673 goto out;
674 674
675 end = get_cycles(); 675 end = get_cycles();
676 676
677 cycles += end - start; 677 cycles += end - start;
678 } 678 }
679 679
680 out: 680 out:
681 local_irq_enable(); 681 local_irq_enable();
682 local_bh_enable(); 682 local_bh_enable();
683 683
684 if (ret) 684 if (ret)
685 return ret; 685 return ret;
686 686
687 printk("%6lu cycles/operation, %4lu cycles/byte\n", 687 printk("%6lu cycles/operation, %4lu cycles/byte\n",
688 cycles / 8, cycles / (8 * blen)); 688 cycles / 8, cycles / (8 * blen));
689 689
690 return 0; 690 return 0;
691 } 691 }
692 692
693 static void test_hash_speed(char *algo, unsigned int sec, 693 static void test_hash_speed(char *algo, unsigned int sec,
694 struct hash_speed *speed) 694 struct hash_speed *speed)
695 { 695 {
696 struct crypto_hash *tfm; 696 struct crypto_hash *tfm;
697 struct hash_desc desc; 697 struct hash_desc desc;
698 char output[1024]; 698 char output[1024];
699 int i; 699 int i;
700 int ret; 700 int ret;
701 701
702 printk("\ntesting speed of %s\n", algo); 702 printk("\ntesting speed of %s\n", algo);
703 703
704 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); 704 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
705 705
706 if (IS_ERR(tfm)) { 706 if (IS_ERR(tfm)) {
707 printk("failed to load transform for %s: %ld\n", algo, 707 printk("failed to load transform for %s: %ld\n", algo,
708 PTR_ERR(tfm)); 708 PTR_ERR(tfm));
709 return; 709 return;
710 } 710 }
711 711
712 desc.tfm = tfm; 712 desc.tfm = tfm;
713 desc.flags = 0; 713 desc.flags = 0;
714 714
715 if (crypto_hash_digestsize(tfm) > sizeof(output)) { 715 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
716 printk("digestsize(%u) > outputbuffer(%zu)\n", 716 printk("digestsize(%u) > outputbuffer(%zu)\n",
717 crypto_hash_digestsize(tfm), sizeof(output)); 717 crypto_hash_digestsize(tfm), sizeof(output));
718 goto out; 718 goto out;
719 } 719 }
720 720
721 for (i = 0; speed[i].blen != 0; i++) { 721 for (i = 0; speed[i].blen != 0; i++) {
722 if (speed[i].blen > TVMEMSIZE) { 722 if (speed[i].blen > TVMEMSIZE) {
723 printk("template (%u) too big for tvmem (%u)\n", 723 printk("template (%u) too big for tvmem (%u)\n",
724 speed[i].blen, TVMEMSIZE); 724 speed[i].blen, TVMEMSIZE);
725 goto out; 725 goto out;
726 } 726 }
727 727
728 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ", 728 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
729 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); 729 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
730 730
731 memset(tvmem, 0xff, speed[i].blen); 731 memset(tvmem, 0xff, speed[i].blen);
732 732
733 if (sec) 733 if (sec)
734 ret = test_hash_jiffies(&desc, tvmem, speed[i].blen, 734 ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
735 speed[i].plen, output, sec); 735 speed[i].plen, output, sec);
736 else 736 else
737 ret = test_hash_cycles(&desc, tvmem, speed[i].blen, 737 ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
738 speed[i].plen, output); 738 speed[i].plen, output);
739 739
740 if (ret) { 740 if (ret) {
741 printk("hashing failed ret=%d\n", ret); 741 printk("hashing failed ret=%d\n", ret);
742 break; 742 break;
743 } 743 }
744 } 744 }
745 745
746 out: 746 out:
747 crypto_free_hash(tfm); 747 crypto_free_hash(tfm);
748 } 748 }
749 749
750 static void test_deflate(void) 750 static void test_deflate(void)
751 { 751 {
752 unsigned int i; 752 unsigned int i;
753 char result[COMP_BUF_SIZE]; 753 char result[COMP_BUF_SIZE];
754 struct crypto_comp *tfm; 754 struct crypto_comp *tfm;
755 struct comp_testvec *tv; 755 struct comp_testvec *tv;
756 unsigned int tsize; 756 unsigned int tsize;
757 757
758 printk("\ntesting deflate compression\n"); 758 printk("\ntesting deflate compression\n");
759 759
760 tsize = sizeof (deflate_comp_tv_template); 760 tsize = sizeof (deflate_comp_tv_template);
761 if (tsize > TVMEMSIZE) { 761 if (tsize > TVMEMSIZE) {
762 printk("template (%u) too big for tvmem (%u)\n", tsize, 762 printk("template (%u) too big for tvmem (%u)\n", tsize,
763 TVMEMSIZE); 763 TVMEMSIZE);
764 return; 764 return;
765 } 765 }
766 766
767 memcpy(tvmem, deflate_comp_tv_template, tsize); 767 memcpy(tvmem, deflate_comp_tv_template, tsize);
768 tv = (void *)tvmem; 768 tv = (void *)tvmem;
769 769
770 tfm = crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC); 770 tfm = crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC);
771 if (tfm == NULL) { 771 if (IS_ERR(tfm)) {
772 printk("failed to load transform for deflate\n"); 772 printk("failed to load transform for deflate\n");
773 return; 773 return;
774 } 774 }
775 775
776 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) { 776 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
777 int ilen, ret, dlen = COMP_BUF_SIZE; 777 int ilen, ret, dlen = COMP_BUF_SIZE;
778 778
779 printk("test %u:\n", i + 1); 779 printk("test %u:\n", i + 1);
780 memset(result, 0, sizeof (result)); 780 memset(result, 0, sizeof (result));
781 781
782 ilen = tv[i].inlen; 782 ilen = tv[i].inlen;
783 ret = crypto_comp_compress(tfm, tv[i].input, 783 ret = crypto_comp_compress(tfm, tv[i].input,
784 ilen, result, &dlen); 784 ilen, result, &dlen);
785 if (ret) { 785 if (ret) {
786 printk("fail: ret=%d\n", ret); 786 printk("fail: ret=%d\n", ret);
787 continue; 787 continue;
788 } 788 }
789 hexdump(result, dlen); 789 hexdump(result, dlen);
790 printk("%s (ratio %d:%d)\n", 790 printk("%s (ratio %d:%d)\n",
791 memcmp(result, tv[i].output, dlen) ? "fail" : "pass", 791 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
792 ilen, dlen); 792 ilen, dlen);
793 } 793 }
794 794
795 printk("\ntesting deflate decompression\n"); 795 printk("\ntesting deflate decompression\n");
796 796
797 tsize = sizeof (deflate_decomp_tv_template); 797 tsize = sizeof (deflate_decomp_tv_template);
798 if (tsize > TVMEMSIZE) { 798 if (tsize > TVMEMSIZE) {
799 printk("template (%u) too big for tvmem (%u)\n", tsize, 799 printk("template (%u) too big for tvmem (%u)\n", tsize,
800 TVMEMSIZE); 800 TVMEMSIZE);
801 goto out; 801 goto out;
802 } 802 }
803 803
804 memcpy(tvmem, deflate_decomp_tv_template, tsize); 804 memcpy(tvmem, deflate_decomp_tv_template, tsize);
805 tv = (void *)tvmem; 805 tv = (void *)tvmem;
806 806
807 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) { 807 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
808 int ilen, ret, dlen = COMP_BUF_SIZE; 808 int ilen, ret, dlen = COMP_BUF_SIZE;
809 809
810 printk("test %u:\n", i + 1); 810 printk("test %u:\n", i + 1);
811 memset(result, 0, sizeof (result)); 811 memset(result, 0, sizeof (result));
812 812
813 ilen = tv[i].inlen; 813 ilen = tv[i].inlen;
814 ret = crypto_comp_decompress(tfm, tv[i].input, 814 ret = crypto_comp_decompress(tfm, tv[i].input,
815 ilen, result, &dlen); 815 ilen, result, &dlen);
816 if (ret) { 816 if (ret) {
817 printk("fail: ret=%d\n", ret); 817 printk("fail: ret=%d\n", ret);
818 continue; 818 continue;
819 } 819 }
820 hexdump(result, dlen); 820 hexdump(result, dlen);
821 printk("%s (ratio %d:%d)\n", 821 printk("%s (ratio %d:%d)\n",
822 memcmp(result, tv[i].output, dlen) ? "fail" : "pass", 822 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
823 ilen, dlen); 823 ilen, dlen);
824 } 824 }
825 out: 825 out:
826 crypto_free_comp(tfm); 826 crypto_free_comp(tfm);
827 } 827 }
828 828
829 static void test_available(void) 829 static void test_available(void)
830 { 830 {
831 char **name = check; 831 char **name = check;
832 832
833 while (*name) { 833 while (*name) {
834 printk("alg %s ", *name); 834 printk("alg %s ", *name);
835 printk(crypto_has_alg(*name, 0, CRYPTO_ALG_ASYNC) ? 835 printk(crypto_has_alg(*name, 0, CRYPTO_ALG_ASYNC) ?
836 "found\n" : "not found\n"); 836 "found\n" : "not found\n");
837 name++; 837 name++;
838 } 838 }
839 } 839 }
840 840
841 static void do_test(void) 841 static void do_test(void)
842 { 842 {
843 switch (mode) { 843 switch (mode) {
844 844
845 case 0: 845 case 0:
846 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS); 846 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
847 847
848 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS); 848 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
849 849
850 //DES 850 //DES
851 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template, 851 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
852 DES_ENC_TEST_VECTORS); 852 DES_ENC_TEST_VECTORS);
853 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template, 853 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
854 DES_DEC_TEST_VECTORS); 854 DES_DEC_TEST_VECTORS);
855 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template, 855 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
856 DES_CBC_ENC_TEST_VECTORS); 856 DES_CBC_ENC_TEST_VECTORS);
857 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template, 857 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
858 DES_CBC_DEC_TEST_VECTORS); 858 DES_CBC_DEC_TEST_VECTORS);
859 859
860 //DES3_EDE 860 //DES3_EDE
861 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template, 861 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
862 DES3_EDE_ENC_TEST_VECTORS); 862 DES3_EDE_ENC_TEST_VECTORS);
863 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template, 863 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
864 DES3_EDE_DEC_TEST_VECTORS); 864 DES3_EDE_DEC_TEST_VECTORS);
865 865
866 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); 866 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
867 867
868 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); 868 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
869 869
870 //BLOWFISH 870 //BLOWFISH
871 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template, 871 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
872 BF_ENC_TEST_VECTORS); 872 BF_ENC_TEST_VECTORS);
873 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template, 873 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
874 BF_DEC_TEST_VECTORS); 874 BF_DEC_TEST_VECTORS);
875 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template, 875 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
876 BF_CBC_ENC_TEST_VECTORS); 876 BF_CBC_ENC_TEST_VECTORS);
877 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template, 877 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
878 BF_CBC_DEC_TEST_VECTORS); 878 BF_CBC_DEC_TEST_VECTORS);
879 879
880 //TWOFISH 880 //TWOFISH
881 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template, 881 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
882 TF_ENC_TEST_VECTORS); 882 TF_ENC_TEST_VECTORS);
883 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template, 883 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
884 TF_DEC_TEST_VECTORS); 884 TF_DEC_TEST_VECTORS);
885 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template, 885 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
886 TF_CBC_ENC_TEST_VECTORS); 886 TF_CBC_ENC_TEST_VECTORS);
887 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template, 887 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
888 TF_CBC_DEC_TEST_VECTORS); 888 TF_CBC_DEC_TEST_VECTORS);
889 889
890 //SERPENT 890 //SERPENT
891 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template, 891 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
892 SERPENT_ENC_TEST_VECTORS); 892 SERPENT_ENC_TEST_VECTORS);
893 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template, 893 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
894 SERPENT_DEC_TEST_VECTORS); 894 SERPENT_DEC_TEST_VECTORS);
895 895
896 //TNEPRES 896 //TNEPRES
897 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template, 897 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
898 TNEPRES_ENC_TEST_VECTORS); 898 TNEPRES_ENC_TEST_VECTORS);
899 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template, 899 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
900 TNEPRES_DEC_TEST_VECTORS); 900 TNEPRES_DEC_TEST_VECTORS);
901 901
902 //AES 902 //AES
903 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template, 903 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
904 AES_ENC_TEST_VECTORS); 904 AES_ENC_TEST_VECTORS);
905 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template, 905 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
906 AES_DEC_TEST_VECTORS); 906 AES_DEC_TEST_VECTORS);
907 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template, 907 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
908 AES_CBC_ENC_TEST_VECTORS); 908 AES_CBC_ENC_TEST_VECTORS);
909 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template, 909 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
910 AES_CBC_DEC_TEST_VECTORS); 910 AES_CBC_DEC_TEST_VECTORS);
911 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template, 911 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
912 AES_LRW_ENC_TEST_VECTORS); 912 AES_LRW_ENC_TEST_VECTORS);
913 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template, 913 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
914 AES_LRW_DEC_TEST_VECTORS); 914 AES_LRW_DEC_TEST_VECTORS);
915 915
916 //CAST5 916 //CAST5
917 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template, 917 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
918 CAST5_ENC_TEST_VECTORS); 918 CAST5_ENC_TEST_VECTORS);
919 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template, 919 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
920 CAST5_DEC_TEST_VECTORS); 920 CAST5_DEC_TEST_VECTORS);
921 921
922 //CAST6 922 //CAST6
923 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template, 923 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
924 CAST6_ENC_TEST_VECTORS); 924 CAST6_ENC_TEST_VECTORS);
925 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template, 925 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
926 CAST6_DEC_TEST_VECTORS); 926 CAST6_DEC_TEST_VECTORS);
927 927
928 //ARC4 928 //ARC4
929 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template, 929 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
930 ARC4_ENC_TEST_VECTORS); 930 ARC4_ENC_TEST_VECTORS);
931 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template, 931 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
932 ARC4_DEC_TEST_VECTORS); 932 ARC4_DEC_TEST_VECTORS);
933 933
934 //TEA 934 //TEA
935 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template, 935 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
936 TEA_ENC_TEST_VECTORS); 936 TEA_ENC_TEST_VECTORS);
937 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template, 937 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
938 TEA_DEC_TEST_VECTORS); 938 TEA_DEC_TEST_VECTORS);
939 939
940 940
941 //XTEA 941 //XTEA
942 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template, 942 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
943 XTEA_ENC_TEST_VECTORS); 943 XTEA_ENC_TEST_VECTORS);
944 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template, 944 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
945 XTEA_DEC_TEST_VECTORS); 945 XTEA_DEC_TEST_VECTORS);
946 946
947 //KHAZAD 947 //KHAZAD
948 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template, 948 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
949 KHAZAD_ENC_TEST_VECTORS); 949 KHAZAD_ENC_TEST_VECTORS);
950 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template, 950 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
951 KHAZAD_DEC_TEST_VECTORS); 951 KHAZAD_DEC_TEST_VECTORS);
952 952
953 //ANUBIS 953 //ANUBIS
954 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template, 954 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
955 ANUBIS_ENC_TEST_VECTORS); 955 ANUBIS_ENC_TEST_VECTORS);
956 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template, 956 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
957 ANUBIS_DEC_TEST_VECTORS); 957 ANUBIS_DEC_TEST_VECTORS);
958 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template, 958 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
959 ANUBIS_CBC_ENC_TEST_VECTORS); 959 ANUBIS_CBC_ENC_TEST_VECTORS);
960 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template, 960 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
961 ANUBIS_CBC_ENC_TEST_VECTORS); 961 ANUBIS_CBC_ENC_TEST_VECTORS);
962 962
963 //XETA 963 //XETA
964 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template, 964 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
965 XETA_ENC_TEST_VECTORS); 965 XETA_ENC_TEST_VECTORS);
966 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template, 966 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
967 XETA_DEC_TEST_VECTORS); 967 XETA_DEC_TEST_VECTORS);
968 968
969 //FCrypt 969 //FCrypt
970 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template, 970 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
971 FCRYPT_ENC_TEST_VECTORS); 971 FCRYPT_ENC_TEST_VECTORS);
972 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template, 972 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
973 FCRYPT_DEC_TEST_VECTORS); 973 FCRYPT_DEC_TEST_VECTORS);
974 974
975 //CAMELLIA 975 //CAMELLIA
976 test_cipher("ecb(camellia)", ENCRYPT, 976 test_cipher("ecb(camellia)", ENCRYPT,
977 camellia_enc_tv_template, 977 camellia_enc_tv_template,
978 CAMELLIA_ENC_TEST_VECTORS); 978 CAMELLIA_ENC_TEST_VECTORS);
979 test_cipher("ecb(camellia)", DECRYPT, 979 test_cipher("ecb(camellia)", DECRYPT,
980 camellia_dec_tv_template, 980 camellia_dec_tv_template,
981 CAMELLIA_DEC_TEST_VECTORS); 981 CAMELLIA_DEC_TEST_VECTORS);
982 test_cipher("cbc(camellia)", ENCRYPT, 982 test_cipher("cbc(camellia)", ENCRYPT,
983 camellia_cbc_enc_tv_template, 983 camellia_cbc_enc_tv_template,
984 CAMELLIA_CBC_ENC_TEST_VECTORS); 984 CAMELLIA_CBC_ENC_TEST_VECTORS);
985 test_cipher("cbc(camellia)", DECRYPT, 985 test_cipher("cbc(camellia)", DECRYPT,
986 camellia_cbc_dec_tv_template, 986 camellia_cbc_dec_tv_template,
987 CAMELLIA_CBC_DEC_TEST_VECTORS); 987 CAMELLIA_CBC_DEC_TEST_VECTORS);
988 988
989 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS); 989 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
990 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS); 990 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
991 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS); 991 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
992 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS); 992 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
993 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS); 993 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
994 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS); 994 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
995 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS); 995 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
996 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); 996 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
997 test_deflate(); 997 test_deflate();
998 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); 998 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
999 test_hash("hmac(md5)", hmac_md5_tv_template, 999 test_hash("hmac(md5)", hmac_md5_tv_template,
1000 HMAC_MD5_TEST_VECTORS); 1000 HMAC_MD5_TEST_VECTORS);
1001 test_hash("hmac(sha1)", hmac_sha1_tv_template, 1001 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1002 HMAC_SHA1_TEST_VECTORS); 1002 HMAC_SHA1_TEST_VECTORS);
1003 test_hash("hmac(sha256)", hmac_sha256_tv_template, 1003 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1004 HMAC_SHA256_TEST_VECTORS); 1004 HMAC_SHA256_TEST_VECTORS);
1005 test_hash("hmac(sha384)", hmac_sha384_tv_template, 1005 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1006 HMAC_SHA384_TEST_VECTORS); 1006 HMAC_SHA384_TEST_VECTORS);
1007 test_hash("hmac(sha512)", hmac_sha512_tv_template, 1007 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1008 HMAC_SHA512_TEST_VECTORS); 1008 HMAC_SHA512_TEST_VECTORS);
1009 1009
1010 test_hash("xcbc(aes)", aes_xcbc128_tv_template, 1010 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1011 XCBC_AES_TEST_VECTORS); 1011 XCBC_AES_TEST_VECTORS);
1012 1012
1013 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS); 1013 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1014 break; 1014 break;
1015 1015
1016 case 1: 1016 case 1:
1017 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS); 1017 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1018 break; 1018 break;
1019 1019
1020 case 2: 1020 case 2:
1021 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS); 1021 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1022 break; 1022 break;
1023 1023
1024 case 3: 1024 case 3:
1025 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template, 1025 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1026 DES_ENC_TEST_VECTORS); 1026 DES_ENC_TEST_VECTORS);
1027 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template, 1027 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1028 DES_DEC_TEST_VECTORS); 1028 DES_DEC_TEST_VECTORS);
1029 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template, 1029 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1030 DES_CBC_ENC_TEST_VECTORS); 1030 DES_CBC_ENC_TEST_VECTORS);
1031 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template, 1031 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1032 DES_CBC_DEC_TEST_VECTORS); 1032 DES_CBC_DEC_TEST_VECTORS);
1033 break; 1033 break;
1034 1034
1035 case 4: 1035 case 4:
1036 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template, 1036 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1037 DES3_EDE_ENC_TEST_VECTORS); 1037 DES3_EDE_ENC_TEST_VECTORS);
1038 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template, 1038 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1039 DES3_EDE_DEC_TEST_VECTORS); 1039 DES3_EDE_DEC_TEST_VECTORS);
1040 break; 1040 break;
1041 1041
1042 case 5: 1042 case 5:
1043 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); 1043 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1044 break; 1044 break;
1045 1045
1046 case 6: 1046 case 6:
1047 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); 1047 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1048 break; 1048 break;
1049 1049
1050 case 7: 1050 case 7:
1051 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template, 1051 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1052 BF_ENC_TEST_VECTORS); 1052 BF_ENC_TEST_VECTORS);
1053 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template, 1053 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1054 BF_DEC_TEST_VECTORS); 1054 BF_DEC_TEST_VECTORS);
1055 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template, 1055 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1056 BF_CBC_ENC_TEST_VECTORS); 1056 BF_CBC_ENC_TEST_VECTORS);
1057 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template, 1057 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1058 BF_CBC_DEC_TEST_VECTORS); 1058 BF_CBC_DEC_TEST_VECTORS);
1059 break; 1059 break;
1060 1060
1061 case 8: 1061 case 8:
1062 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template, 1062 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1063 TF_ENC_TEST_VECTORS); 1063 TF_ENC_TEST_VECTORS);
1064 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template, 1064 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1065 TF_DEC_TEST_VECTORS); 1065 TF_DEC_TEST_VECTORS);
1066 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template, 1066 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1067 TF_CBC_ENC_TEST_VECTORS); 1067 TF_CBC_ENC_TEST_VECTORS);
1068 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template, 1068 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1069 TF_CBC_DEC_TEST_VECTORS); 1069 TF_CBC_DEC_TEST_VECTORS);
1070 break; 1070 break;
1071 1071
1072 case 9: 1072 case 9:
1073 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template, 1073 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1074 SERPENT_ENC_TEST_VECTORS); 1074 SERPENT_ENC_TEST_VECTORS);
1075 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template, 1075 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1076 SERPENT_DEC_TEST_VECTORS); 1076 SERPENT_DEC_TEST_VECTORS);
1077 break; 1077 break;
1078 1078
1079 case 10: 1079 case 10:
1080 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template, 1080 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1081 AES_ENC_TEST_VECTORS); 1081 AES_ENC_TEST_VECTORS);
1082 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template, 1082 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1083 AES_DEC_TEST_VECTORS); 1083 AES_DEC_TEST_VECTORS);
1084 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template, 1084 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1085 AES_CBC_ENC_TEST_VECTORS); 1085 AES_CBC_ENC_TEST_VECTORS);
1086 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template, 1086 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1087 AES_CBC_DEC_TEST_VECTORS); 1087 AES_CBC_DEC_TEST_VECTORS);
1088 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template, 1088 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1089 AES_LRW_ENC_TEST_VECTORS); 1089 AES_LRW_ENC_TEST_VECTORS);
1090 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template, 1090 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1091 AES_LRW_DEC_TEST_VECTORS); 1091 AES_LRW_DEC_TEST_VECTORS);
1092 break; 1092 break;
1093 1093
1094 case 11: 1094 case 11:
1095 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS); 1095 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1096 break; 1096 break;
1097 1097
1098 case 12: 1098 case 12:
1099 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS); 1099 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1100 break; 1100 break;
1101 1101
1102 case 13: 1102 case 13:
1103 test_deflate(); 1103 test_deflate();
1104 break; 1104 break;
1105 1105
1106 case 14: 1106 case 14:
1107 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template, 1107 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1108 CAST5_ENC_TEST_VECTORS); 1108 CAST5_ENC_TEST_VECTORS);
1109 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template, 1109 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1110 CAST5_DEC_TEST_VECTORS); 1110 CAST5_DEC_TEST_VECTORS);
1111 break; 1111 break;
1112 1112
1113 case 15: 1113 case 15:
1114 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template, 1114 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1115 CAST6_ENC_TEST_VECTORS); 1115 CAST6_ENC_TEST_VECTORS);
1116 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template, 1116 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1117 CAST6_DEC_TEST_VECTORS); 1117 CAST6_DEC_TEST_VECTORS);
1118 break; 1118 break;
1119 1119
1120 case 16: 1120 case 16:
1121 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template, 1121 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1122 ARC4_ENC_TEST_VECTORS); 1122 ARC4_ENC_TEST_VECTORS);
1123 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template, 1123 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1124 ARC4_DEC_TEST_VECTORS); 1124 ARC4_DEC_TEST_VECTORS);
1125 break; 1125 break;
1126 1126
1127 case 17: 1127 case 17:
1128 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS); 1128 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1129 break; 1129 break;
1130 1130
1131 case 18: 1131 case 18:
1132 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); 1132 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1133 break; 1133 break;
1134 1134
1135 case 19: 1135 case 19:
1136 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template, 1136 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1137 TEA_ENC_TEST_VECTORS); 1137 TEA_ENC_TEST_VECTORS);
1138 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template, 1138 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1139 TEA_DEC_TEST_VECTORS); 1139 TEA_DEC_TEST_VECTORS);
1140 break; 1140 break;
1141 1141
1142 case 20: 1142 case 20:
1143 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template, 1143 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1144 XTEA_ENC_TEST_VECTORS); 1144 XTEA_ENC_TEST_VECTORS);
1145 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template, 1145 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1146 XTEA_DEC_TEST_VECTORS); 1146 XTEA_DEC_TEST_VECTORS);
1147 break; 1147 break;
1148 1148
1149 case 21: 1149 case 21:
1150 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template, 1150 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1151 KHAZAD_ENC_TEST_VECTORS); 1151 KHAZAD_ENC_TEST_VECTORS);
1152 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template, 1152 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1153 KHAZAD_DEC_TEST_VECTORS); 1153 KHAZAD_DEC_TEST_VECTORS);
1154 break; 1154 break;
1155 1155
1156 case 22: 1156 case 22:
1157 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS); 1157 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1158 break; 1158 break;
1159 1159
1160 case 23: 1160 case 23:
1161 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS); 1161 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1162 break; 1162 break;
1163 1163
1164 case 24: 1164 case 24:
1165 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS); 1165 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1166 break; 1166 break;
1167 1167
1168 case 25: 1168 case 25:
1169 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template, 1169 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1170 TNEPRES_ENC_TEST_VECTORS); 1170 TNEPRES_ENC_TEST_VECTORS);
1171 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template, 1171 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1172 TNEPRES_DEC_TEST_VECTORS); 1172 TNEPRES_DEC_TEST_VECTORS);
1173 break; 1173 break;
1174 1174
1175 case 26: 1175 case 26:
1176 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template, 1176 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1177 ANUBIS_ENC_TEST_VECTORS); 1177 ANUBIS_ENC_TEST_VECTORS);
1178 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template, 1178 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1179 ANUBIS_DEC_TEST_VECTORS); 1179 ANUBIS_DEC_TEST_VECTORS);
1180 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template, 1180 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1181 ANUBIS_CBC_ENC_TEST_VECTORS); 1181 ANUBIS_CBC_ENC_TEST_VECTORS);
1182 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template, 1182 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1183 ANUBIS_CBC_ENC_TEST_VECTORS); 1183 ANUBIS_CBC_ENC_TEST_VECTORS);
1184 break; 1184 break;
1185 1185
1186 case 27: 1186 case 27:
1187 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS); 1187 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1188 break; 1188 break;
1189 1189
1190 case 28: 1190 case 28:
1191 1191
1192 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS); 1192 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1193 break; 1193 break;
1194 1194
1195 case 29: 1195 case 29:
1196 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); 1196 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1197 break; 1197 break;
1198 1198
1199 case 30: 1199 case 30:
1200 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template, 1200 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1201 XETA_ENC_TEST_VECTORS); 1201 XETA_ENC_TEST_VECTORS);
1202 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template, 1202 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1203 XETA_DEC_TEST_VECTORS); 1203 XETA_DEC_TEST_VECTORS);
1204 break; 1204 break;
1205 1205
1206 case 31: 1206 case 31:
1207 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template, 1207 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1208 FCRYPT_ENC_TEST_VECTORS); 1208 FCRYPT_ENC_TEST_VECTORS);
1209 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template, 1209 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1210 FCRYPT_DEC_TEST_VECTORS); 1210 FCRYPT_DEC_TEST_VECTORS);
1211 break; 1211 break;
1212 1212
1213 case 32: 1213 case 32:
1214 test_cipher("ecb(camellia)", ENCRYPT, 1214 test_cipher("ecb(camellia)", ENCRYPT,
1215 camellia_enc_tv_template, 1215 camellia_enc_tv_template,
1216 CAMELLIA_ENC_TEST_VECTORS); 1216 CAMELLIA_ENC_TEST_VECTORS);
1217 test_cipher("ecb(camellia)", DECRYPT, 1217 test_cipher("ecb(camellia)", DECRYPT,
1218 camellia_dec_tv_template, 1218 camellia_dec_tv_template,
1219 CAMELLIA_DEC_TEST_VECTORS); 1219 CAMELLIA_DEC_TEST_VECTORS);
1220 test_cipher("cbc(camellia)", ENCRYPT, 1220 test_cipher("cbc(camellia)", ENCRYPT,
1221 camellia_cbc_enc_tv_template, 1221 camellia_cbc_enc_tv_template,
1222 CAMELLIA_CBC_ENC_TEST_VECTORS); 1222 CAMELLIA_CBC_ENC_TEST_VECTORS);
1223 test_cipher("cbc(camellia)", DECRYPT, 1223 test_cipher("cbc(camellia)", DECRYPT,
1224 camellia_cbc_dec_tv_template, 1224 camellia_cbc_dec_tv_template,
1225 CAMELLIA_CBC_DEC_TEST_VECTORS); 1225 CAMELLIA_CBC_DEC_TEST_VECTORS);
1226 break; 1226 break;
1227 1227
1228 case 100: 1228 case 100:
1229 test_hash("hmac(md5)", hmac_md5_tv_template, 1229 test_hash("hmac(md5)", hmac_md5_tv_template,
1230 HMAC_MD5_TEST_VECTORS); 1230 HMAC_MD5_TEST_VECTORS);
1231 break; 1231 break;
1232 1232
1233 case 101: 1233 case 101:
1234 test_hash("hmac(sha1)", hmac_sha1_tv_template, 1234 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1235 HMAC_SHA1_TEST_VECTORS); 1235 HMAC_SHA1_TEST_VECTORS);
1236 break; 1236 break;
1237 1237
1238 case 102: 1238 case 102:
1239 test_hash("hmac(sha256)", hmac_sha256_tv_template, 1239 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1240 HMAC_SHA256_TEST_VECTORS); 1240 HMAC_SHA256_TEST_VECTORS);
1241 break; 1241 break;
1242 1242
1243 case 103: 1243 case 103:
1244 test_hash("hmac(sha384)", hmac_sha384_tv_template, 1244 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1245 HMAC_SHA384_TEST_VECTORS); 1245 HMAC_SHA384_TEST_VECTORS);
1246 break; 1246 break;
1247 1247
1248 case 104: 1248 case 104:
1249 test_hash("hmac(sha512)", hmac_sha512_tv_template, 1249 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1250 HMAC_SHA512_TEST_VECTORS); 1250 HMAC_SHA512_TEST_VECTORS);
1251 break; 1251 break;
1252 1252
1253 1253
1254 case 200: 1254 case 200:
1255 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, 1255 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1256 aes_speed_template); 1256 aes_speed_template);
1257 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, 1257 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1258 aes_speed_template); 1258 aes_speed_template);
1259 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, 1259 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1260 aes_speed_template); 1260 aes_speed_template);
1261 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, 1261 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1262 aes_speed_template); 1262 aes_speed_template);
1263 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, 1263 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1264 aes_lrw_speed_template); 1264 aes_lrw_speed_template);
1265 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, 1265 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1266 aes_lrw_speed_template); 1266 aes_lrw_speed_template);
1267 break; 1267 break;
1268 1268
1269 case 201: 1269 case 201:
1270 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec, 1270 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1271 des3_ede_enc_tv_template, 1271 des3_ede_enc_tv_template,
1272 DES3_EDE_ENC_TEST_VECTORS, 1272 DES3_EDE_ENC_TEST_VECTORS,
1273 des3_ede_speed_template); 1273 des3_ede_speed_template);
1274 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec, 1274 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1275 des3_ede_dec_tv_template, 1275 des3_ede_dec_tv_template,
1276 DES3_EDE_DEC_TEST_VECTORS, 1276 DES3_EDE_DEC_TEST_VECTORS,
1277 des3_ede_speed_template); 1277 des3_ede_speed_template);
1278 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec, 1278 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1279 des3_ede_enc_tv_template, 1279 des3_ede_enc_tv_template,
1280 DES3_EDE_ENC_TEST_VECTORS, 1280 DES3_EDE_ENC_TEST_VECTORS,
1281 des3_ede_speed_template); 1281 des3_ede_speed_template);
1282 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec, 1282 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1283 des3_ede_dec_tv_template, 1283 des3_ede_dec_tv_template,
1284 DES3_EDE_DEC_TEST_VECTORS, 1284 DES3_EDE_DEC_TEST_VECTORS,
1285 des3_ede_speed_template); 1285 des3_ede_speed_template);
1286 break; 1286 break;
1287 1287
1288 case 202: 1288 case 202:
1289 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, 1289 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1290 twofish_speed_template); 1290 twofish_speed_template);
1291 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, 1291 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1292 twofish_speed_template); 1292 twofish_speed_template);
1293 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, 1293 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1294 twofish_speed_template); 1294 twofish_speed_template);
1295 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, 1295 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1296 twofish_speed_template); 1296 twofish_speed_template);
1297 break; 1297 break;
1298 1298
1299 case 203: 1299 case 203:
1300 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, 1300 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1301 blowfish_speed_template); 1301 blowfish_speed_template);
1302 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, 1302 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1303 blowfish_speed_template); 1303 blowfish_speed_template);
1304 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, 1304 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1305 blowfish_speed_template); 1305 blowfish_speed_template);
1306 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, 1306 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1307 blowfish_speed_template); 1307 blowfish_speed_template);
1308 break; 1308 break;
1309 1309
1310 case 204: 1310 case 204:
1311 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, 1311 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1312 des_speed_template); 1312 des_speed_template);
1313 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, 1313 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1314 des_speed_template); 1314 des_speed_template);
1315 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, 1315 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1316 des_speed_template); 1316 des_speed_template);
1317 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, 1317 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1318 des_speed_template); 1318 des_speed_template);
1319 break; 1319 break;
1320 1320
1321 case 205: 1321 case 205:
1322 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, 1322 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1323 camellia_speed_template); 1323 camellia_speed_template);
1324 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, 1324 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1325 camellia_speed_template); 1325 camellia_speed_template);
1326 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, 1326 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1327 camellia_speed_template); 1327 camellia_speed_template);
1328 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, 1328 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1329 camellia_speed_template); 1329 camellia_speed_template);
1330 break; 1330 break;
1331 1331
1332 case 300: 1332 case 300:
1333 /* fall through */ 1333 /* fall through */
1334 1334
1335 case 301: 1335 case 301:
1336 test_hash_speed("md4", sec, generic_hash_speed_template); 1336 test_hash_speed("md4", sec, generic_hash_speed_template);
1337 if (mode > 300 && mode < 400) break; 1337 if (mode > 300 && mode < 400) break;
1338 1338
1339 case 302: 1339 case 302:
1340 test_hash_speed("md5", sec, generic_hash_speed_template); 1340 test_hash_speed("md5", sec, generic_hash_speed_template);
1341 if (mode > 300 && mode < 400) break; 1341 if (mode > 300 && mode < 400) break;
1342 1342
1343 case 303: 1343 case 303:
1344 test_hash_speed("sha1", sec, generic_hash_speed_template); 1344 test_hash_speed("sha1", sec, generic_hash_speed_template);
1345 if (mode > 300 && mode < 400) break; 1345 if (mode > 300 && mode < 400) break;
1346 1346
1347 case 304: 1347 case 304:
1348 test_hash_speed("sha256", sec, generic_hash_speed_template); 1348 test_hash_speed("sha256", sec, generic_hash_speed_template);
1349 if (mode > 300 && mode < 400) break; 1349 if (mode > 300 && mode < 400) break;
1350 1350
1351 case 305: 1351 case 305:
1352 test_hash_speed("sha384", sec, generic_hash_speed_template); 1352 test_hash_speed("sha384", sec, generic_hash_speed_template);
1353 if (mode > 300 && mode < 400) break; 1353 if (mode > 300 && mode < 400) break;
1354 1354
1355 case 306: 1355 case 306:
1356 test_hash_speed("sha512", sec, generic_hash_speed_template); 1356 test_hash_speed("sha512", sec, generic_hash_speed_template);
1357 if (mode > 300 && mode < 400) break; 1357 if (mode > 300 && mode < 400) break;
1358 1358
1359 case 307: 1359 case 307:
1360 test_hash_speed("wp256", sec, generic_hash_speed_template); 1360 test_hash_speed("wp256", sec, generic_hash_speed_template);
1361 if (mode > 300 && mode < 400) break; 1361 if (mode > 300 && mode < 400) break;
1362 1362
1363 case 308: 1363 case 308:
1364 test_hash_speed("wp384", sec, generic_hash_speed_template); 1364 test_hash_speed("wp384", sec, generic_hash_speed_template);
1365 if (mode > 300 && mode < 400) break; 1365 if (mode > 300 && mode < 400) break;
1366 1366
1367 case 309: 1367 case 309:
1368 test_hash_speed("wp512", sec, generic_hash_speed_template); 1368 test_hash_speed("wp512", sec, generic_hash_speed_template);
1369 if (mode > 300 && mode < 400) break; 1369 if (mode > 300 && mode < 400) break;
1370 1370
1371 case 310: 1371 case 310:
1372 test_hash_speed("tgr128", sec, generic_hash_speed_template); 1372 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1373 if (mode > 300 && mode < 400) break; 1373 if (mode > 300 && mode < 400) break;
1374 1374
1375 case 311: 1375 case 311:
1376 test_hash_speed("tgr160", sec, generic_hash_speed_template); 1376 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1377 if (mode > 300 && mode < 400) break; 1377 if (mode > 300 && mode < 400) break;
1378 1378
1379 case 312: 1379 case 312:
1380 test_hash_speed("tgr192", sec, generic_hash_speed_template); 1380 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1381 if (mode > 300 && mode < 400) break; 1381 if (mode > 300 && mode < 400) break;
1382 1382
1383 case 399: 1383 case 399:
1384 break; 1384 break;
1385 1385
1386 case 1000: 1386 case 1000:
1387 test_available(); 1387 test_available();
1388 break; 1388 break;
1389 1389
1390 default: 1390 default:
1391 /* useful for debugging */ 1391 /* useful for debugging */
1392 printk("not testing anything\n"); 1392 printk("not testing anything\n");
1393 break; 1393 break;
1394 } 1394 }
1395 } 1395 }
1396 1396
1397 static int __init init(void) 1397 static int __init init(void)
1398 { 1398 {
1399 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL); 1399 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1400 if (tvmem == NULL) 1400 if (tvmem == NULL)
1401 return -ENOMEM; 1401 return -ENOMEM;
1402 1402
1403 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL); 1403 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1404 if (xbuf == NULL) { 1404 if (xbuf == NULL) {
1405 kfree(tvmem); 1405 kfree(tvmem);
1406 return -ENOMEM; 1406 return -ENOMEM;
1407 } 1407 }
1408 1408
1409 do_test(); 1409 do_test();
1410 1410
1411 kfree(xbuf); 1411 kfree(xbuf);
1412 kfree(tvmem); 1412 kfree(tvmem);
1413 1413
1414 /* We intentionaly return -EAGAIN to prevent keeping 1414 /* We intentionaly return -EAGAIN to prevent keeping
1415 * the module. It does all its work from init() 1415 * the module. It does all its work from init()
1416 * and doesn't offer any runtime functionality 1416 * and doesn't offer any runtime functionality
1417 * => we don't need it in the memory, do we? 1417 * => we don't need it in the memory, do we?
1418 * -- mludvig 1418 * -- mludvig
1419 */ 1419 */
1420 return -EAGAIN; 1420 return -EAGAIN;
1421 } 1421 }
1422 1422
1423 /* 1423 /*
1424 * If an init function is provided, an exit function must also be provided 1424 * If an init function is provided, an exit function must also be provided
1425 * to allow module unload. 1425 * to allow module unload.
1426 */ 1426 */
1427 static void __exit fini(void) { } 1427 static void __exit fini(void) { }
1428 1428
1429 module_init(init); 1429 module_init(init);
1430 module_exit(fini); 1430 module_exit(fini);
1431 1431
1432 module_param(mode, int, 0); 1432 module_param(mode, int, 0);
1433 module_param(sec, uint, 0); 1433 module_param(sec, uint, 0);
1434 MODULE_PARM_DESC(sec, "Length in seconds of speed tests " 1434 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1435 "(defaults to zero which uses CPU cycles instead)"); 1435 "(defaults to zero which uses CPU cycles instead)");
1436 1436
1437 MODULE_LICENSE("GPL"); 1437 MODULE_LICENSE("GPL");
1438 MODULE_DESCRIPTION("Quick & dirty crypto testing module"); 1438 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1439 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>"); 1439 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");
1440 1440