Commit | Line | Data |
---|---|---|
ef2736fc | 1 | /* |
1da177e4 LT |
2 | * 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> | |
e3a4ea4f | 9 | * Copyright (c) 2007 Nokia Siemens Networks |
1da177e4 LT |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify it | |
12 | * under the terms of the GNU General Public License as published by the Free | |
ef2736fc | 13 | * Software Foundation; either version 2 of the License, or (at your option) |
1da177e4 LT |
14 | * any later version. |
15 | * | |
1da177e4 LT |
16 | */ |
17 | ||
cba83564 | 18 | #include <linux/err.h> |
1da177e4 LT |
19 | #include <linux/init.h> |
20 | #include <linux/module.h> | |
21 | #include <linux/mm.h> | |
22 | #include <linux/slab.h> | |
378f058c | 23 | #include <linux/scatterlist.h> |
1da177e4 LT |
24 | #include <linux/string.h> |
25 | #include <linux/crypto.h> | |
26 | #include <linux/highmem.h> | |
27 | #include <linux/moduleparam.h> | |
ebfd9bcf | 28 | #include <linux/jiffies.h> |
6a17944c HX |
29 | #include <linux/timex.h> |
30 | #include <linux/interrupt.h> | |
1da177e4 LT |
31 | #include "tcrypt.h" |
32 | ||
33 | /* | |
34 | * Need to kmalloc() memory for testing kmap(). | |
35 | */ | |
ebfd9bcf | 36 | #define TVMEMSIZE 16384 |
1da177e4 LT |
37 | #define XBUFSIZE 32768 |
38 | ||
39 | /* | |
40 | * Indexes into the xbuf to simulate cross-page access. | |
41 | */ | |
a558f1d4 | 42 | #define IDX1 32 |
1da177e4 LT |
43 | #define IDX2 32400 |
44 | #define IDX3 1 | |
45 | #define IDX4 8193 | |
46 | #define IDX5 22222 | |
47 | #define IDX6 17101 | |
48 | #define IDX7 27333 | |
49 | #define IDX8 3000 | |
50 | ||
51 | /* | |
52 | * Used by test_cipher() | |
53 | */ | |
54 | #define ENCRYPT 1 | |
55 | #define DECRYPT 0 | |
1da177e4 | 56 | |
6158efc0 HX |
57 | struct tcrypt_result { |
58 | struct completion completion; | |
59 | int err; | |
60 | }; | |
61 | ||
1da177e4 LT |
62 | static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; |
63 | ||
ebfd9bcf HW |
64 | /* |
65 | * Used by test_cipher_speed() | |
66 | */ | |
6a17944c | 67 | static unsigned int sec; |
ebfd9bcf | 68 | |
1da177e4 LT |
69 | static int mode; |
70 | static char *xbuf; | |
e3a4ea4f | 71 | static char *axbuf; |
1da177e4 LT |
72 | static char *tvmem; |
73 | ||
74 | static char *check[] = { | |
cd12fb90 JL |
75 | "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", |
76 | "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes", | |
77 | "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", | |
90831639 | 78 | "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", |
2998db37 AKR |
79 | "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320", |
80 | "lzo", "cts", NULL | |
1da177e4 LT |
81 | }; |
82 | ||
ef2736fc | 83 | static void hexdump(unsigned char *buf, unsigned int len) |
1da177e4 | 84 | { |
a10e1194 DC |
85 | print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET, |
86 | 16, 1, | |
87 | buf, len, false); | |
1da177e4 LT |
88 | } |
89 | ||
6158efc0 HX |
90 | static void tcrypt_complete(struct crypto_async_request *req, int err) |
91 | { | |
92 | struct tcrypt_result *res = req->data; | |
93 | ||
94 | if (err == -EINPROGRESS) | |
95 | return; | |
96 | ||
97 | res->err = err; | |
98 | complete(&res->completion); | |
99 | } | |
100 | ||
ef2736fc HX |
101 | static void test_hash(char *algo, struct hash_testvec *template, |
102 | unsigned int tcount) | |
1da177e4 | 103 | { |
ef2736fc HX |
104 | unsigned int i, j, k, temp; |
105 | struct scatterlist sg[8]; | |
106 | char result[64]; | |
e9d41164 HX |
107 | struct crypto_hash *tfm; |
108 | struct hash_desc desc; | |
e9d41164 | 109 | int ret; |
562954d5 | 110 | void *hash_buff; |
ef2736fc HX |
111 | |
112 | printk("\ntesting %s\n", algo); | |
113 | ||
e9d41164 HX |
114 | tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); |
115 | if (IS_ERR(tfm)) { | |
116 | printk("failed to load transform for %s: %ld\n", algo, | |
117 | PTR_ERR(tfm)); | |
1da177e4 LT |
118 | return; |
119 | } | |
120 | ||
e9d41164 HX |
121 | desc.tfm = tfm; |
122 | desc.flags = 0; | |
123 | ||
1da177e4 | 124 | for (i = 0; i < tcount; i++) { |
ef2736fc HX |
125 | printk("test %u:\n", i + 1); |
126 | memset(result, 0, 64); | |
1da177e4 | 127 | |
562954d5 SS |
128 | hash_buff = kzalloc(template[i].psize, GFP_KERNEL); |
129 | if (!hash_buff) | |
130 | continue; | |
1da177e4 | 131 | |
562954d5 SS |
132 | memcpy(hash_buff, template[i].plaintext, template[i].psize); |
133 | sg_init_one(&sg[0], hash_buff, template[i].psize); | |
134 | ||
135 | if (template[i].ksize) { | |
136 | ret = crypto_hash_setkey(tfm, template[i].key, | |
137 | template[i].ksize); | |
e9d41164 HX |
138 | if (ret) { |
139 | printk("setkey() failed ret=%d\n", ret); | |
562954d5 | 140 | kfree(hash_buff); |
e9d41164 HX |
141 | goto out; |
142 | } | |
143 | } | |
144 | ||
562954d5 | 145 | ret = crypto_hash_digest(&desc, sg, template[i].psize, result); |
e9d41164 HX |
146 | if (ret) { |
147 | printk("digest () failed ret=%d\n", ret); | |
562954d5 | 148 | kfree(hash_buff); |
e9d41164 HX |
149 | goto out; |
150 | } | |
1da177e4 | 151 | |
e9d41164 | 152 | hexdump(result, crypto_hash_digestsize(tfm)); |
1da177e4 | 153 | printk("%s\n", |
562954d5 | 154 | memcmp(result, template[i].digest, |
e9d41164 | 155 | crypto_hash_digestsize(tfm)) ? |
ef2736fc | 156 | "fail" : "pass"); |
562954d5 | 157 | kfree(hash_buff); |
1da177e4 LT |
158 | } |
159 | ||
ef2736fc | 160 | printk("testing %s across pages\n", algo); |
1da177e4 LT |
161 | |
162 | /* setup the dummy buffer first */ | |
ef2736fc | 163 | memset(xbuf, 0, XBUFSIZE); |
1da177e4 LT |
164 | |
165 | j = 0; | |
166 | for (i = 0; i < tcount; i++) { | |
562954d5 | 167 | if (template[i].np) { |
1da177e4 | 168 | j++; |
ef2736fc HX |
169 | printk("test %u:\n", j); |
170 | memset(result, 0, 64); | |
1da177e4 LT |
171 | |
172 | temp = 0; | |
562954d5 SS |
173 | sg_init_table(sg, template[i].np); |
174 | for (k = 0; k < template[i].np; k++) { | |
ef2736fc | 175 | memcpy(&xbuf[IDX[k]], |
562954d5 SS |
176 | template[i].plaintext + temp, |
177 | template[i].tap[k]); | |
178 | temp += template[i].tap[k]; | |
378f058c | 179 | sg_set_buf(&sg[k], &xbuf[IDX[k]], |
562954d5 | 180 | template[i].tap[k]); |
1da177e4 LT |
181 | } |
182 | ||
562954d5 SS |
183 | if (template[i].ksize) { |
184 | ret = crypto_hash_setkey(tfm, template[i].key, | |
185 | template[i].ksize); | |
ef2736fc | 186 | |
e9d41164 HX |
187 | if (ret) { |
188 | printk("setkey() failed ret=%d\n", ret); | |
189 | goto out; | |
190 | } | |
1da177e4 LT |
191 | } |
192 | ||
562954d5 | 193 | ret = crypto_hash_digest(&desc, sg, template[i].psize, |
e9d41164 HX |
194 | result); |
195 | if (ret) { | |
196 | printk("digest () failed ret=%d\n", ret); | |
197 | goto out; | |
198 | } | |
ef2736fc | 199 | |
e9d41164 | 200 | hexdump(result, crypto_hash_digestsize(tfm)); |
1da177e4 | 201 | printk("%s\n", |
562954d5 | 202 | memcmp(result, template[i].digest, |
e9d41164 | 203 | crypto_hash_digestsize(tfm)) ? |
ef2736fc | 204 | "fail" : "pass"); |
1da177e4 LT |
205 | } |
206 | } | |
e9d41164 | 207 | |
1da177e4 | 208 | out: |
e9d41164 | 209 | crypto_free_hash(tfm); |
1da177e4 LT |
210 | } |
211 | ||
e3a4ea4f MH |
212 | static void test_aead(char *algo, int enc, struct aead_testvec *template, |
213 | unsigned int tcount) | |
214 | { | |
a558f1d4 | 215 | unsigned int ret, i, j, k, n, temp; |
e3a4ea4f MH |
216 | char *q; |
217 | struct crypto_aead *tfm; | |
218 | char *key; | |
e3a4ea4f MH |
219 | struct aead_request *req; |
220 | struct scatterlist sg[8]; | |
221 | struct scatterlist asg[8]; | |
222 | const char *e; | |
223 | struct tcrypt_result result; | |
6160b289 | 224 | unsigned int authsize; |
562954d5 SS |
225 | void *input; |
226 | void *assoc; | |
227 | char iv[MAX_IVLEN]; | |
e3a4ea4f MH |
228 | |
229 | if (enc == ENCRYPT) | |
230 | e = "encryption"; | |
231 | else | |
232 | e = "decryption"; | |
233 | ||
234 | printk(KERN_INFO "\ntesting %s %s\n", algo, e); | |
235 | ||
e3a4ea4f MH |
236 | init_completion(&result.completion); |
237 | ||
238 | tfm = crypto_alloc_aead(algo, 0, 0); | |
239 | ||
240 | if (IS_ERR(tfm)) { | |
241 | printk(KERN_INFO "failed to load transform for %s: %ld\n", | |
242 | algo, PTR_ERR(tfm)); | |
243 | return; | |
244 | } | |
245 | ||
246 | req = aead_request_alloc(tfm, GFP_KERNEL); | |
247 | if (!req) { | |
248 | printk(KERN_INFO "failed to allocate request for %s\n", algo); | |
249 | goto out; | |
250 | } | |
251 | ||
252 | aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, | |
253 | tcrypt_complete, &result); | |
254 | ||
255 | for (i = 0, j = 0; i < tcount; i++) { | |
562954d5 | 256 | if (!template[i].np) { |
e3a4ea4f | 257 | printk(KERN_INFO "test %u (%d bit key):\n", |
562954d5 SS |
258 | ++j, template[i].klen * 8); |
259 | ||
260 | /* some tepmplates have no input data but they will | |
261 | * touch input | |
262 | */ | |
263 | input = kzalloc(template[i].ilen + template[i].rlen, GFP_KERNEL); | |
264 | if (!input) | |
265 | continue; | |
266 | ||
267 | assoc = kzalloc(template[i].alen, GFP_KERNEL); | |
268 | if (!assoc) { | |
269 | kfree(input); | |
270 | continue; | |
271 | } | |
272 | ||
273 | memcpy(input, template[i].input, template[i].ilen); | |
274 | memcpy(assoc, template[i].assoc, template[i].alen); | |
275 | if (template[i].iv) | |
276 | memcpy(iv, template[i].iv, MAX_IVLEN); | |
277 | else | |
278 | memset(iv, 0, MAX_IVLEN); | |
e3a4ea4f MH |
279 | |
280 | crypto_aead_clear_flags(tfm, ~0); | |
562954d5 | 281 | if (template[i].wk) |
e3a4ea4f MH |
282 | crypto_aead_set_flags( |
283 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); | |
562954d5 SS |
284 | |
285 | if (template[i].key) | |
286 | key = template[i].key; | |
287 | else | |
288 | key = kzalloc(template[i].klen, GFP_KERNEL); | |
e3a4ea4f MH |
289 | |
290 | ret = crypto_aead_setkey(tfm, key, | |
562954d5 | 291 | template[i].klen); |
e3a4ea4f MH |
292 | if (ret) { |
293 | printk(KERN_INFO "setkey() failed flags=%x\n", | |
294 | crypto_aead_get_flags(tfm)); | |
295 | ||
562954d5 SS |
296 | if (!template[i].fail) |
297 | goto next_one; | |
e3a4ea4f MH |
298 | } |
299 | ||
562954d5 | 300 | authsize = abs(template[i].rlen - template[i].ilen); |
93cc74e0 JL |
301 | ret = crypto_aead_setauthsize(tfm, authsize); |
302 | if (ret) { | |
303 | printk(KERN_INFO | |
304 | "failed to set authsize = %u\n", | |
305 | authsize); | |
562954d5 | 306 | goto next_one; |
93cc74e0 JL |
307 | } |
308 | ||
562954d5 SS |
309 | sg_init_one(&sg[0], input, |
310 | template[i].ilen + (enc ? authsize : 0)); | |
e3a4ea4f | 311 | |
562954d5 | 312 | sg_init_one(&asg[0], assoc, template[i].alen); |
e3a4ea4f MH |
313 | |
314 | aead_request_set_crypt(req, sg, sg, | |
562954d5 | 315 | template[i].ilen, iv); |
e3a4ea4f | 316 | |
562954d5 | 317 | aead_request_set_assoc(req, asg, template[i].alen); |
e3a4ea4f | 318 | |
6160b289 HX |
319 | ret = enc ? |
320 | crypto_aead_encrypt(req) : | |
321 | crypto_aead_decrypt(req); | |
e3a4ea4f MH |
322 | |
323 | switch (ret) { | |
324 | case 0: | |
325 | break; | |
326 | case -EINPROGRESS: | |
327 | case -EBUSY: | |
328 | ret = wait_for_completion_interruptible( | |
329 | &result.completion); | |
330 | if (!ret && !(ret = result.err)) { | |
331 | INIT_COMPLETION(result.completion); | |
332 | break; | |
333 | } | |
334 | /* fall through */ | |
335 | default: | |
336 | printk(KERN_INFO "%s () failed err=%d\n", | |
337 | e, -ret); | |
562954d5 | 338 | goto next_one; |
e3a4ea4f MH |
339 | } |
340 | ||
341 | q = kmap(sg_page(&sg[0])) + sg[0].offset; | |
562954d5 | 342 | hexdump(q, template[i].rlen); |
e3a4ea4f MH |
343 | |
344 | printk(KERN_INFO "enc/dec: %s\n", | |
562954d5 SS |
345 | memcmp(q, template[i].result, |
346 | template[i].rlen) ? "fail" : "pass"); | |
347 | kunmap(sg_page(&sg[0])); | |
348 | next_one: | |
349 | if (!template[i].key) | |
350 | kfree(key); | |
351 | kfree(assoc); | |
352 | kfree(input); | |
e3a4ea4f MH |
353 | } |
354 | } | |
355 | ||
356 | printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e); | |
2a999a3a | 357 | memset(axbuf, 0, XBUFSIZE); |
e3a4ea4f MH |
358 | |
359 | for (i = 0, j = 0; i < tcount; i++) { | |
562954d5 | 360 | if (template[i].np) { |
e3a4ea4f | 361 | printk(KERN_INFO "test %u (%d bit key):\n", |
562954d5 SS |
362 | ++j, template[i].klen * 8); |
363 | ||
364 | if (template[i].iv) | |
365 | memcpy(iv, template[i].iv, MAX_IVLEN); | |
366 | else | |
367 | memset(iv, 0, MAX_IVLEN); | |
e3a4ea4f MH |
368 | |
369 | crypto_aead_clear_flags(tfm, ~0); | |
562954d5 | 370 | if (template[i].wk) |
e3a4ea4f MH |
371 | crypto_aead_set_flags( |
372 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); | |
562954d5 | 373 | key = template[i].key; |
e3a4ea4f | 374 | |
562954d5 | 375 | ret = crypto_aead_setkey(tfm, key, template[i].klen); |
e3a4ea4f MH |
376 | if (ret) { |
377 | printk(KERN_INFO "setkey() failed flags=%x\n", | |
378 | crypto_aead_get_flags(tfm)); | |
379 | ||
562954d5 | 380 | if (!template[i].fail) |
e3a4ea4f MH |
381 | goto out; |
382 | } | |
383 | ||
a558f1d4 | 384 | memset(xbuf, 0, XBUFSIZE); |
562954d5 SS |
385 | sg_init_table(sg, template[i].np); |
386 | for (k = 0, temp = 0; k < template[i].np; k++) { | |
e3a4ea4f | 387 | memcpy(&xbuf[IDX[k]], |
562954d5 SS |
388 | template[i].input + temp, |
389 | template[i].tap[k]); | |
390 | temp += template[i].tap[k]; | |
e3a4ea4f | 391 | sg_set_buf(&sg[k], &xbuf[IDX[k]], |
562954d5 | 392 | template[i].tap[k]); |
e3a4ea4f MH |
393 | } |
394 | ||
562954d5 | 395 | authsize = abs(template[i].rlen - template[i].ilen); |
93cc74e0 JL |
396 | ret = crypto_aead_setauthsize(tfm, authsize); |
397 | if (ret) { | |
398 | printk(KERN_INFO | |
399 | "failed to set authsize = %u\n", | |
400 | authsize); | |
401 | goto out; | |
402 | } | |
403 | ||
6160b289 HX |
404 | if (enc) |
405 | sg[k - 1].length += authsize; | |
406 | ||
562954d5 SS |
407 | sg_init_table(asg, template[i].anp); |
408 | for (k = 0, temp = 0; k < template[i].anp; k++) { | |
e3a4ea4f | 409 | memcpy(&axbuf[IDX[k]], |
562954d5 SS |
410 | template[i].assoc + temp, |
411 | template[i].atap[k]); | |
412 | temp += template[i].atap[k]; | |
e3a4ea4f | 413 | sg_set_buf(&asg[k], &axbuf[IDX[k]], |
562954d5 | 414 | template[i].atap[k]); |
e3a4ea4f MH |
415 | } |
416 | ||
417 | aead_request_set_crypt(req, sg, sg, | |
562954d5 SS |
418 | template[i].ilen, |
419 | iv); | |
e3a4ea4f | 420 | |
562954d5 | 421 | aead_request_set_assoc(req, asg, template[i].alen); |
e3a4ea4f | 422 | |
6160b289 HX |
423 | ret = enc ? |
424 | crypto_aead_encrypt(req) : | |
425 | crypto_aead_decrypt(req); | |
e3a4ea4f MH |
426 | |
427 | switch (ret) { | |
428 | case 0: | |
429 | break; | |
430 | case -EINPROGRESS: | |
431 | case -EBUSY: | |
432 | ret = wait_for_completion_interruptible( | |
433 | &result.completion); | |
434 | if (!ret && !(ret = result.err)) { | |
435 | INIT_COMPLETION(result.completion); | |
436 | break; | |
437 | } | |
438 | /* fall through */ | |
439 | default: | |
440 | printk(KERN_INFO "%s () failed err=%d\n", | |
441 | e, -ret); | |
442 | goto out; | |
443 | } | |
444 | ||
562954d5 | 445 | for (k = 0, temp = 0; k < template[i].np; k++) { |
e3a4ea4f MH |
446 | printk(KERN_INFO "page %u\n", k); |
447 | q = kmap(sg_page(&sg[k])) + sg[k].offset; | |
562954d5 | 448 | hexdump(q, template[i].tap[k]); |
e3a4ea4f | 449 | printk(KERN_INFO "%s\n", |
562954d5 SS |
450 | memcmp(q, template[i].result + temp, |
451 | template[i].tap[k] - | |
452 | (k < template[i].np - 1 || enc ? | |
6160b289 | 453 | 0 : authsize)) ? |
e3a4ea4f MH |
454 | "fail" : "pass"); |
455 | ||
a558f1d4 PM |
456 | for (n = 0; q[template[i].tap[k] + n]; n++) |
457 | ; | |
458 | if (n) { | |
459 | printk("Result buffer corruption %u " | |
460 | "bytes:\n", n); | |
461 | hexdump(&q[template[i].tap[k]], n); | |
462 | } | |
463 | ||
562954d5 SS |
464 | temp += template[i].tap[k]; |
465 | kunmap(sg_page(&sg[k])); | |
e3a4ea4f | 466 | } |
e3a4ea4f MH |
467 | } |
468 | } | |
469 | ||
470 | out: | |
471 | crypto_free_aead(tfm); | |
472 | aead_request_free(req); | |
473 | } | |
474 | ||
cba83564 | 475 | static void test_cipher(char *algo, int enc, |
ef2736fc | 476 | struct cipher_testvec *template, unsigned int tcount) |
1da177e4 | 477 | { |
a558f1d4 | 478 | unsigned int ret, i, j, k, n, temp; |
378f058c | 479 | char *q; |
6158efc0 | 480 | struct crypto_ablkcipher *tfm; |
6158efc0 | 481 | struct ablkcipher_request *req; |
1da177e4 | 482 | struct scatterlist sg[8]; |
cba83564 | 483 | const char *e; |
6158efc0 | 484 | struct tcrypt_result result; |
562954d5 SS |
485 | void *data; |
486 | char iv[MAX_IVLEN]; | |
1da177e4 LT |
487 | |
488 | if (enc == ENCRYPT) | |
3cc3816f | 489 | e = "encryption"; |
1da177e4 | 490 | else |
3cc3816f | 491 | e = "decryption"; |
1da177e4 | 492 | |
cba83564 | 493 | printk("\ntesting %s %s\n", algo, e); |
1da177e4 | 494 | |
6158efc0 | 495 | init_completion(&result.completion); |
6158efc0 | 496 | tfm = crypto_alloc_ablkcipher(algo, 0, 0); |
1da177e4 | 497 | |
cba83564 HX |
498 | if (IS_ERR(tfm)) { |
499 | printk("failed to load transform for %s: %ld\n", algo, | |
500 | PTR_ERR(tfm)); | |
1da177e4 LT |
501 | return; |
502 | } | |
6158efc0 HX |
503 | |
504 | req = ablkcipher_request_alloc(tfm, GFP_KERNEL); | |
505 | if (!req) { | |
506 | printk("failed to allocate request for %s\n", algo); | |
507 | goto out; | |
508 | } | |
509 | ||
510 | ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, | |
511 | tcrypt_complete, &result); | |
ef2736fc | 512 | |
1da177e4 LT |
513 | j = 0; |
514 | for (i = 0; i < tcount; i++) { | |
562954d5 SS |
515 | |
516 | data = kzalloc(template[i].ilen, GFP_KERNEL); | |
517 | if (!data) | |
518 | continue; | |
519 | ||
520 | memcpy(data, template[i].input, template[i].ilen); | |
521 | if (template[i].iv) | |
522 | memcpy(iv, template[i].iv, MAX_IVLEN); | |
523 | else | |
524 | memset(iv, 0, MAX_IVLEN); | |
525 | ||
526 | if (!(template[i].np)) { | |
ef2736fc | 527 | j++; |
1da177e4 | 528 | printk("test %u (%d bit key):\n", |
562954d5 | 529 | j, template[i].klen * 8); |
1da177e4 | 530 | |
6158efc0 | 531 | crypto_ablkcipher_clear_flags(tfm, ~0); |
562954d5 | 532 | if (template[i].wk) |
6158efc0 | 533 | crypto_ablkcipher_set_flags( |
cba83564 | 534 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
ef2736fc | 535 | |
562954d5 SS |
536 | ret = crypto_ablkcipher_setkey(tfm, template[i].key, |
537 | template[i].klen); | |
1da177e4 | 538 | if (ret) { |
cba83564 | 539 | printk("setkey() failed flags=%x\n", |
6158efc0 | 540 | crypto_ablkcipher_get_flags(tfm)); |
ef2736fc | 541 | |
562954d5 SS |
542 | if (!template[i].fail) { |
543 | kfree(data); | |
1da177e4 | 544 | goto out; |
562954d5 | 545 | } |
ef2736fc | 546 | } |
1da177e4 | 547 | |
562954d5 | 548 | sg_init_one(&sg[0], data, template[i].ilen); |
ef2736fc | 549 | |
6158efc0 | 550 | ablkcipher_request_set_crypt(req, sg, sg, |
562954d5 | 551 | template[i].ilen, iv); |
cba83564 | 552 | ret = enc ? |
6158efc0 HX |
553 | crypto_ablkcipher_encrypt(req) : |
554 | crypto_ablkcipher_decrypt(req); | |
ef2736fc | 555 | |
6158efc0 HX |
556 | switch (ret) { |
557 | case 0: | |
558 | break; | |
559 | case -EINPROGRESS: | |
560 | case -EBUSY: | |
561 | ret = wait_for_completion_interruptible( | |
562 | &result.completion); | |
563 | if (!ret && !((ret = result.err))) { | |
564 | INIT_COMPLETION(result.completion); | |
565 | break; | |
566 | } | |
567 | /* fall through */ | |
568 | default: | |
569 | printk("%s () failed err=%d\n", e, -ret); | |
562954d5 | 570 | kfree(data); |
1da177e4 | 571 | goto out; |
ef2736fc HX |
572 | } |
573 | ||
78c2f0b8 | 574 | q = kmap(sg_page(&sg[0])) + sg[0].offset; |
562954d5 | 575 | hexdump(q, template[i].rlen); |
ef2736fc HX |
576 | |
577 | printk("%s\n", | |
562954d5 SS |
578 | memcmp(q, template[i].result, |
579 | template[i].rlen) ? "fail" : "pass"); | |
580 | kunmap(sg_page(&sg[0])); | |
1da177e4 | 581 | } |
562954d5 | 582 | kfree(data); |
1da177e4 | 583 | } |
ef2736fc | 584 | |
cba83564 | 585 | printk("\ntesting %s %s across pages (chunking)\n", algo, e); |
ef2736fc | 586 | |
1da177e4 LT |
587 | j = 0; |
588 | for (i = 0; i < tcount; i++) { | |
562954d5 | 589 | |
562954d5 SS |
590 | if (template[i].iv) |
591 | memcpy(iv, template[i].iv, MAX_IVLEN); | |
592 | else | |
593 | memset(iv, 0, MAX_IVLEN); | |
594 | ||
595 | if (template[i].np) { | |
ef2736fc | 596 | j++; |
1da177e4 | 597 | printk("test %u (%d bit key):\n", |
562954d5 | 598 | j, template[i].klen * 8); |
1da177e4 | 599 | |
a558f1d4 | 600 | memset(xbuf, 0, XBUFSIZE); |
6158efc0 | 601 | crypto_ablkcipher_clear_flags(tfm, ~0); |
562954d5 | 602 | if (template[i].wk) |
6158efc0 | 603 | crypto_ablkcipher_set_flags( |
cba83564 | 604 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
ef2736fc | 605 | |
562954d5 SS |
606 | ret = crypto_ablkcipher_setkey(tfm, template[i].key, |
607 | template[i].klen); | |
1da177e4 | 608 | if (ret) { |
cba83564 | 609 | printk("setkey() failed flags=%x\n", |
562954d5 | 610 | crypto_ablkcipher_get_flags(tfm)); |
ef2736fc | 611 | |
dbb018cd | 612 | if (!template[i].fail) |
1da177e4 LT |
613 | goto out; |
614 | } | |
615 | ||
616 | temp = 0; | |
562954d5 SS |
617 | sg_init_table(sg, template[i].np); |
618 | for (k = 0; k < template[i].np; k++) { | |
ef2736fc | 619 | memcpy(&xbuf[IDX[k]], |
562954d5 SS |
620 | template[i].input + temp, |
621 | template[i].tap[k]); | |
622 | temp += template[i].tap[k]; | |
378f058c | 623 | sg_set_buf(&sg[k], &xbuf[IDX[k]], |
562954d5 | 624 | template[i].tap[k]); |
1da177e4 | 625 | } |
ef2736fc | 626 | |
6158efc0 | 627 | ablkcipher_request_set_crypt(req, sg, sg, |
562954d5 | 628 | template[i].ilen, iv); |
ef2736fc | 629 | |
cba83564 | 630 | ret = enc ? |
6158efc0 HX |
631 | crypto_ablkcipher_encrypt(req) : |
632 | crypto_ablkcipher_decrypt(req); | |
ef2736fc | 633 | |
6158efc0 HX |
634 | switch (ret) { |
635 | case 0: | |
636 | break; | |
637 | case -EINPROGRESS: | |
638 | case -EBUSY: | |
639 | ret = wait_for_completion_interruptible( | |
640 | &result.completion); | |
641 | if (!ret && !((ret = result.err))) { | |
642 | INIT_COMPLETION(result.completion); | |
643 | break; | |
644 | } | |
645 | /* fall through */ | |
646 | default: | |
647 | printk("%s () failed err=%d\n", e, -ret); | |
1da177e4 LT |
648 | goto out; |
649 | } | |
650 | ||
651 | temp = 0; | |
562954d5 | 652 | for (k = 0; k < template[i].np; k++) { |
1da177e4 | 653 | printk("page %u\n", k); |
78c2f0b8 | 654 | q = kmap(sg_page(&sg[k])) + sg[k].offset; |
562954d5 | 655 | hexdump(q, template[i].tap[k]); |
ef2736fc | 656 | printk("%s\n", |
562954d5 SS |
657 | memcmp(q, template[i].result + temp, |
658 | template[i].tap[k]) ? "fail" : | |
1da177e4 | 659 | "pass"); |
a558f1d4 PM |
660 | |
661 | for (n = 0; q[template[i].tap[k] + n]; n++) | |
662 | ; | |
663 | if (n) { | |
664 | printk("Result buffer corruption %u " | |
665 | "bytes:\n", n); | |
666 | hexdump(&q[template[i].tap[k]], n); | |
667 | } | |
562954d5 SS |
668 | temp += template[i].tap[k]; |
669 | kunmap(sg_page(&sg[k])); | |
1da177e4 LT |
670 | } |
671 | } | |
672 | } | |
1da177e4 | 673 | out: |
6158efc0 HX |
674 | crypto_free_ablkcipher(tfm); |
675 | ablkcipher_request_free(req); | |
1da177e4 LT |
676 | } |
677 | ||
cba83564 | 678 | static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p, |
6a17944c HX |
679 | int blen, int sec) |
680 | { | |
6df5b9f4 | 681 | struct scatterlist sg[1]; |
6a17944c HX |
682 | unsigned long start, end; |
683 | int bcount; | |
684 | int ret; | |
685 | ||
b7335885 | 686 | sg_init_one(sg, p, blen); |
6a17944c HX |
687 | |
688 | for (start = jiffies, end = start + sec * HZ, bcount = 0; | |
689 | time_before(jiffies, end); bcount++) { | |
690 | if (enc) | |
cba83564 | 691 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
6a17944c | 692 | else |
cba83564 | 693 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
6a17944c HX |
694 | |
695 | if (ret) | |
696 | return ret; | |
697 | } | |
698 | ||
699 | printk("%d operations in %d seconds (%ld bytes)\n", | |
700 | bcount, sec, (long)bcount * blen); | |
701 | return 0; | |
702 | } | |
703 | ||
cba83564 | 704 | static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p, |
6a17944c HX |
705 | int blen) |
706 | { | |
6df5b9f4 | 707 | struct scatterlist sg[1]; |
6a17944c HX |
708 | unsigned long cycles = 0; |
709 | int ret = 0; | |
710 | int i; | |
711 | ||
b7335885 | 712 | sg_init_one(sg, p, blen); |
6a17944c HX |
713 | |
714 | local_bh_disable(); | |
715 | local_irq_disable(); | |
716 | ||
717 | /* Warm-up run. */ | |
718 | for (i = 0; i < 4; i++) { | |
719 | if (enc) | |
cba83564 | 720 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
6a17944c | 721 | else |
cba83564 | 722 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
6a17944c HX |
723 | |
724 | if (ret) | |
725 | goto out; | |
726 | } | |
727 | ||
728 | /* The real thing. */ | |
729 | for (i = 0; i < 8; i++) { | |
730 | cycles_t start, end; | |
731 | ||
732 | start = get_cycles(); | |
733 | if (enc) | |
cba83564 | 734 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
6a17944c | 735 | else |
cba83564 | 736 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
6a17944c HX |
737 | end = get_cycles(); |
738 | ||
739 | if (ret) | |
740 | goto out; | |
741 | ||
742 | cycles += end - start; | |
743 | } | |
744 | ||
745 | out: | |
746 | local_irq_enable(); | |
747 | local_bh_enable(); | |
748 | ||
749 | if (ret == 0) | |
750 | printk("1 operation in %lu cycles (%d bytes)\n", | |
751 | (cycles + 4) / 8, blen); | |
752 | ||
753 | return ret; | |
754 | } | |
755 | ||
d5dc3927 SS |
756 | static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 }; |
757 | ||
cba83564 | 758 | static void test_cipher_speed(char *algo, int enc, unsigned int sec, |
dce907c0 | 759 | struct cipher_testvec *template, |
d5dc3927 | 760 | unsigned int tcount, u8 *keysize) |
ebfd9bcf | 761 | { |
dce907c0 | 762 | unsigned int ret, i, j, iv_len; |
ebfd9bcf | 763 | unsigned char *key, *p, iv[128]; |
cba83564 HX |
764 | struct crypto_blkcipher *tfm; |
765 | struct blkcipher_desc desc; | |
766 | const char *e; | |
d5dc3927 | 767 | u32 *b_size; |
ebfd9bcf HW |
768 | |
769 | if (enc == ENCRYPT) | |
770 | e = "encryption"; | |
771 | else | |
772 | e = "decryption"; | |
ebfd9bcf | 773 | |
cba83564 | 774 | printk("\ntesting speed of %s %s\n", algo, e); |
ebfd9bcf | 775 | |
cba83564 | 776 | tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC); |
ebfd9bcf | 777 | |
cba83564 HX |
778 | if (IS_ERR(tfm)) { |
779 | printk("failed to load transform for %s: %ld\n", algo, | |
780 | PTR_ERR(tfm)); | |
ebfd9bcf HW |
781 | return; |
782 | } | |
cba83564 HX |
783 | desc.tfm = tfm; |
784 | desc.flags = 0; | |
ebfd9bcf | 785 | |
d5dc3927 SS |
786 | i = 0; |
787 | do { | |
ebfd9bcf | 788 | |
d5dc3927 SS |
789 | b_size = block_sizes; |
790 | do { | |
ebfd9bcf | 791 | |
d5dc3927 SS |
792 | if ((*keysize + *b_size) > TVMEMSIZE) { |
793 | printk("template (%u) too big for tvmem (%u)\n", | |
794 | *keysize + *b_size, TVMEMSIZE); | |
795 | goto out; | |
796 | } | |
ebfd9bcf | 797 | |
d5dc3927 SS |
798 | printk("test %u (%d bit key, %d byte blocks): ", i, |
799 | *keysize * 8, *b_size); | |
800 | ||
801 | memset(tvmem, 0xff, *keysize + *b_size); | |
802 | ||
803 | /* set key, plain text and IV */ | |
804 | key = (unsigned char *)tvmem; | |
805 | for (j = 0; j < tcount; j++) { | |
806 | if (template[j].klen == *keysize) { | |
807 | key = template[j].key; | |
808 | break; | |
809 | } | |
dce907c0 | 810 | } |
d5dc3927 | 811 | p = (unsigned char *)tvmem + *keysize; |
ebfd9bcf | 812 | |
d5dc3927 SS |
813 | ret = crypto_blkcipher_setkey(tfm, key, *keysize); |
814 | if (ret) { | |
815 | printk("setkey() failed flags=%x\n", | |
816 | crypto_blkcipher_get_flags(tfm)); | |
817 | goto out; | |
818 | } | |
ebfd9bcf | 819 | |
d5dc3927 SS |
820 | iv_len = crypto_blkcipher_ivsize(tfm); |
821 | if (iv_len) { | |
822 | memset(&iv, 0xff, iv_len); | |
823 | crypto_blkcipher_set_iv(tfm, iv, iv_len); | |
824 | } | |
ebfd9bcf | 825 | |
d5dc3927 SS |
826 | if (sec) |
827 | ret = test_cipher_jiffies(&desc, enc, p, *b_size, sec); | |
828 | else | |
829 | ret = test_cipher_cycles(&desc, enc, p, *b_size); | |
ebfd9bcf | 830 | |
d5dc3927 SS |
831 | if (ret) { |
832 | printk("%s() failed flags=%x\n", e, desc.flags); | |
833 | break; | |
834 | } | |
835 | b_size++; | |
836 | i++; | |
837 | } while (*b_size); | |
838 | keysize++; | |
839 | } while (*keysize); | |
ebfd9bcf HW |
840 | |
841 | out: | |
cba83564 | 842 | crypto_free_blkcipher(tfm); |
ebfd9bcf HW |
843 | } |
844 | ||
e9d41164 HX |
845 | static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen, |
846 | char *out, int sec) | |
847 | { | |
848 | struct scatterlist sg[1]; | |
849 | unsigned long start, end; | |
850 | int bcount; | |
851 | int ret; | |
852 | ||
a5a613a4 HX |
853 | sg_init_table(sg, 1); |
854 | ||
e9d41164 HX |
855 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
856 | time_before(jiffies, end); bcount++) { | |
a5a613a4 | 857 | sg_set_buf(sg, p, blen); |
e9d41164 HX |
858 | ret = crypto_hash_digest(desc, sg, blen, out); |
859 | if (ret) | |
860 | return ret; | |
861 | } | |
862 | ||
863 | printk("%6u opers/sec, %9lu bytes/sec\n", | |
864 | bcount / sec, ((long)bcount * blen) / sec); | |
865 | ||
866 | return 0; | |
867 | } | |
868 | ||
869 | static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen, | |
870 | int plen, char *out, int sec) | |
e8057928 ML |
871 | { |
872 | struct scatterlist sg[1]; | |
873 | unsigned long start, end; | |
874 | int bcount, pcount; | |
e9d41164 HX |
875 | int ret; |
876 | ||
877 | if (plen == blen) | |
878 | return test_hash_jiffies_digest(desc, p, blen, out, sec); | |
e8057928 | 879 | |
a5a613a4 HX |
880 | sg_init_table(sg, 1); |
881 | ||
e8057928 ML |
882 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
883 | time_before(jiffies, end); bcount++) { | |
e9d41164 HX |
884 | ret = crypto_hash_init(desc); |
885 | if (ret) | |
886 | return ret; | |
e8057928 | 887 | for (pcount = 0; pcount < blen; pcount += plen) { |
a5a613a4 | 888 | sg_set_buf(sg, p + pcount, plen); |
e9d41164 HX |
889 | ret = crypto_hash_update(desc, sg, plen); |
890 | if (ret) | |
891 | return ret; | |
e8057928 ML |
892 | } |
893 | /* we assume there is enough space in 'out' for the result */ | |
e9d41164 HX |
894 | ret = crypto_hash_final(desc, out); |
895 | if (ret) | |
896 | return ret; | |
e8057928 ML |
897 | } |
898 | ||
899 | printk("%6u opers/sec, %9lu bytes/sec\n", | |
900 | bcount / sec, ((long)bcount * blen) / sec); | |
901 | ||
e9d41164 HX |
902 | return 0; |
903 | } | |
904 | ||
905 | static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen, | |
906 | char *out) | |
907 | { | |
908 | struct scatterlist sg[1]; | |
909 | unsigned long cycles = 0; | |
910 | int i; | |
911 | int ret; | |
912 | ||
a5a613a4 HX |
913 | sg_init_table(sg, 1); |
914 | ||
e9d41164 HX |
915 | local_bh_disable(); |
916 | local_irq_disable(); | |
917 | ||
918 | /* Warm-up run. */ | |
919 | for (i = 0; i < 4; i++) { | |
a5a613a4 | 920 | sg_set_buf(sg, p, blen); |
e9d41164 HX |
921 | ret = crypto_hash_digest(desc, sg, blen, out); |
922 | if (ret) | |
923 | goto out; | |
924 | } | |
925 | ||
926 | /* The real thing. */ | |
927 | for (i = 0; i < 8; i++) { | |
928 | cycles_t start, end; | |
929 | ||
930 | start = get_cycles(); | |
931 | ||
a5a613a4 | 932 | sg_set_buf(sg, p, blen); |
e9d41164 HX |
933 | ret = crypto_hash_digest(desc, sg, blen, out); |
934 | if (ret) | |
935 | goto out; | |
936 | ||
937 | end = get_cycles(); | |
938 | ||
939 | cycles += end - start; | |
940 | } | |
941 | ||
942 | out: | |
943 | local_irq_enable(); | |
944 | local_bh_enable(); | |
945 | ||
946 | if (ret) | |
947 | return ret; | |
948 | ||
949 | printk("%6lu cycles/operation, %4lu cycles/byte\n", | |
950 | cycles / 8, cycles / (8 * blen)); | |
951 | ||
952 | return 0; | |
e8057928 ML |
953 | } |
954 | ||
e9d41164 HX |
955 | static int test_hash_cycles(struct hash_desc *desc, char *p, int blen, |
956 | int plen, char *out) | |
e8057928 ML |
957 | { |
958 | struct scatterlist sg[1]; | |
959 | unsigned long cycles = 0; | |
960 | int i, pcount; | |
e9d41164 HX |
961 | int ret; |
962 | ||
963 | if (plen == blen) | |
964 | return test_hash_cycles_digest(desc, p, blen, out); | |
e8057928 | 965 | |
a5a613a4 HX |
966 | sg_init_table(sg, 1); |
967 | ||
e8057928 ML |
968 | local_bh_disable(); |
969 | local_irq_disable(); | |
970 | ||
971 | /* Warm-up run. */ | |
972 | for (i = 0; i < 4; i++) { | |
e9d41164 HX |
973 | ret = crypto_hash_init(desc); |
974 | if (ret) | |
975 | goto out; | |
e8057928 | 976 | for (pcount = 0; pcount < blen; pcount += plen) { |
a5a613a4 | 977 | sg_set_buf(sg, p + pcount, plen); |
e9d41164 HX |
978 | ret = crypto_hash_update(desc, sg, plen); |
979 | if (ret) | |
980 | goto out; | |
e8057928 | 981 | } |
29059d12 | 982 | ret = crypto_hash_final(desc, out); |
e9d41164 HX |
983 | if (ret) |
984 | goto out; | |
e8057928 ML |
985 | } |
986 | ||
987 | /* The real thing. */ | |
988 | for (i = 0; i < 8; i++) { | |
989 | cycles_t start, end; | |
990 | ||
e8057928 ML |
991 | start = get_cycles(); |
992 | ||
e9d41164 HX |
993 | ret = crypto_hash_init(desc); |
994 | if (ret) | |
995 | goto out; | |
e8057928 | 996 | for (pcount = 0; pcount < blen; pcount += plen) { |
a5a613a4 | 997 | sg_set_buf(sg, p + pcount, plen); |
e9d41164 HX |
998 | ret = crypto_hash_update(desc, sg, plen); |
999 | if (ret) | |
1000 | goto out; | |
e8057928 | 1001 | } |
e9d41164 HX |
1002 | ret = crypto_hash_final(desc, out); |
1003 | if (ret) | |
1004 | goto out; | |
e8057928 ML |
1005 | |
1006 | end = get_cycles(); | |
1007 | ||
1008 | cycles += end - start; | |
1009 | } | |
1010 | ||
e9d41164 | 1011 | out: |
e8057928 ML |
1012 | local_irq_enable(); |
1013 | local_bh_enable(); | |
1014 | ||
e9d41164 HX |
1015 | if (ret) |
1016 | return ret; | |
1017 | ||
e8057928 ML |
1018 | printk("%6lu cycles/operation, %4lu cycles/byte\n", |
1019 | cycles / 8, cycles / (8 * blen)); | |
1020 | ||
e9d41164 | 1021 | return 0; |
e8057928 ML |
1022 | } |
1023 | ||
e9d41164 HX |
1024 | static void test_hash_speed(char *algo, unsigned int sec, |
1025 | struct hash_speed *speed) | |
e8057928 | 1026 | { |
e9d41164 HX |
1027 | struct crypto_hash *tfm; |
1028 | struct hash_desc desc; | |
e8057928 ML |
1029 | char output[1024]; |
1030 | int i; | |
e9d41164 | 1031 | int ret; |
e8057928 ML |
1032 | |
1033 | printk("\ntesting speed of %s\n", algo); | |
1034 | ||
e9d41164 | 1035 | tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); |
e8057928 | 1036 | |
e9d41164 HX |
1037 | if (IS_ERR(tfm)) { |
1038 | printk("failed to load transform for %s: %ld\n", algo, | |
1039 | PTR_ERR(tfm)); | |
e8057928 ML |
1040 | return; |
1041 | } | |
1042 | ||
e9d41164 HX |
1043 | desc.tfm = tfm; |
1044 | desc.flags = 0; | |
1045 | ||
1046 | if (crypto_hash_digestsize(tfm) > sizeof(output)) { | |
e8057928 | 1047 | printk("digestsize(%u) > outputbuffer(%zu)\n", |
e9d41164 | 1048 | crypto_hash_digestsize(tfm), sizeof(output)); |
e8057928 ML |
1049 | goto out; |
1050 | } | |
1051 | ||
1052 | for (i = 0; speed[i].blen != 0; i++) { | |
1053 | if (speed[i].blen > TVMEMSIZE) { | |
1054 | printk("template (%u) too big for tvmem (%u)\n", | |
1055 | speed[i].blen, TVMEMSIZE); | |
1056 | goto out; | |
1057 | } | |
1058 | ||
1059 | printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ", | |
1060 | i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); | |
1061 | ||
1062 | memset(tvmem, 0xff, speed[i].blen); | |
1063 | ||
1064 | if (sec) | |
e9d41164 HX |
1065 | ret = test_hash_jiffies(&desc, tvmem, speed[i].blen, |
1066 | speed[i].plen, output, sec); | |
e8057928 | 1067 | else |
e9d41164 HX |
1068 | ret = test_hash_cycles(&desc, tvmem, speed[i].blen, |
1069 | speed[i].plen, output); | |
1070 | ||
1071 | if (ret) { | |
1072 | printk("hashing failed ret=%d\n", ret); | |
1073 | break; | |
1074 | } | |
e8057928 ML |
1075 | } |
1076 | ||
1077 | out: | |
e9d41164 | 1078 | crypto_free_hash(tfm); |
e8057928 ML |
1079 | } |
1080 | ||
91755a92 ZS |
1081 | static void test_comp(char *algo, struct comp_testvec *ctemplate, |
1082 | struct comp_testvec *dtemplate, int ctcount, int dtcount) | |
1da177e4 LT |
1083 | { |
1084 | unsigned int i; | |
1085 | char result[COMP_BUF_SIZE]; | |
e4d5b79c | 1086 | struct crypto_comp *tfm; |
1da177e4 LT |
1087 | unsigned int tsize; |
1088 | ||
91755a92 | 1089 | printk("\ntesting %s compression\n", algo); |
1da177e4 | 1090 | |
91755a92 | 1091 | tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC); |
7bc301e9 | 1092 | if (IS_ERR(tfm)) { |
91755a92 | 1093 | printk("failed to load transform for %s\n", algo); |
1da177e4 LT |
1094 | return; |
1095 | } | |
1096 | ||
91755a92 | 1097 | for (i = 0; i < ctcount; i++) { |
1da177e4 | 1098 | int ilen, ret, dlen = COMP_BUF_SIZE; |
ef2736fc | 1099 | |
1da177e4 LT |
1100 | printk("test %u:\n", i + 1); |
1101 | memset(result, 0, sizeof (result)); | |
1102 | ||
562954d5 SS |
1103 | ilen = ctemplate[i].inlen; |
1104 | ret = crypto_comp_compress(tfm, ctemplate[i].input, | |
1da177e4 LT |
1105 | ilen, result, &dlen); |
1106 | if (ret) { | |
1107 | printk("fail: ret=%d\n", ret); | |
1108 | continue; | |
1109 | } | |
1110 | hexdump(result, dlen); | |
1111 | printk("%s (ratio %d:%d)\n", | |
562954d5 | 1112 | memcmp(result, ctemplate[i].output, dlen) ? "fail" : "pass", |
1da177e4 LT |
1113 | ilen, dlen); |
1114 | } | |
1115 | ||
91755a92 | 1116 | printk("\ntesting %s decompression\n", algo); |
1da177e4 | 1117 | |
91755a92 ZS |
1118 | tsize = sizeof(struct comp_testvec); |
1119 | tsize *= dtcount; | |
1da177e4 LT |
1120 | if (tsize > TVMEMSIZE) { |
1121 | printk("template (%u) too big for tvmem (%u)\n", tsize, | |
1122 | TVMEMSIZE); | |
1123 | goto out; | |
1124 | } | |
1125 | ||
91755a92 | 1126 | for (i = 0; i < dtcount; i++) { |
1da177e4 | 1127 | int ilen, ret, dlen = COMP_BUF_SIZE; |
ef2736fc | 1128 | |
1da177e4 LT |
1129 | printk("test %u:\n", i + 1); |
1130 | memset(result, 0, sizeof (result)); | |
1131 | ||
562954d5 SS |
1132 | ilen = dtemplate[i].inlen; |
1133 | ret = crypto_comp_decompress(tfm, dtemplate[i].input, | |
1da177e4 LT |
1134 | ilen, result, &dlen); |
1135 | if (ret) { | |
1136 | printk("fail: ret=%d\n", ret); | |
1137 | continue; | |
1138 | } | |
1139 | hexdump(result, dlen); | |
1140 | printk("%s (ratio %d:%d)\n", | |
562954d5 | 1141 | memcmp(result, dtemplate[i].output, dlen) ? "fail" : "pass", |
1da177e4 LT |
1142 | ilen, dlen); |
1143 | } | |
1144 | out: | |
e4d5b79c | 1145 | crypto_free_comp(tfm); |
1da177e4 LT |
1146 | } |
1147 | ||
ef2736fc | 1148 | static void test_available(void) |
1da177e4 LT |
1149 | { |
1150 | char **name = check; | |
ef2736fc | 1151 | |
1da177e4 LT |
1152 | while (*name) { |
1153 | printk("alg %s ", *name); | |
6158efc0 | 1154 | printk(crypto_has_alg(*name, 0, 0) ? |
e4d5b79c | 1155 | "found\n" : "not found\n"); |
1da177e4 | 1156 | name++; |
ef2736fc | 1157 | } |
1da177e4 LT |
1158 | } |
1159 | ||
ef2736fc | 1160 | static void do_test(void) |
1da177e4 LT |
1161 | { |
1162 | switch (mode) { | |
1163 | ||
1164 | case 0: | |
1165 | test_hash("md5", md5_tv_template, MD5_TEST_VECTORS); | |
ef2736fc | 1166 | |
1da177e4 | 1167 | test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS); |
ef2736fc | 1168 | |
1da177e4 | 1169 | //DES |
cba83564 HX |
1170 | test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template, |
1171 | DES_ENC_TEST_VECTORS); | |
1172 | test_cipher("ecb(des)", DECRYPT, des_dec_tv_template, | |
1173 | DES_DEC_TEST_VECTORS); | |
1174 | test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template, | |
1175 | DES_CBC_ENC_TEST_VECTORS); | |
1176 | test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template, | |
1177 | DES_CBC_DEC_TEST_VECTORS); | |
ef2736fc | 1178 | |
1da177e4 | 1179 | //DES3_EDE |
cba83564 HX |
1180 | test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template, |
1181 | DES3_EDE_ENC_TEST_VECTORS); | |
1182 | test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template, | |
1183 | DES3_EDE_DEC_TEST_VECTORS); | |
ef2736fc | 1184 | |
1da177e4 | 1185 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); |
ef2736fc | 1186 | |
cd12fb90 JL |
1187 | test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS); |
1188 | ||
1da177e4 | 1189 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); |
ef2736fc | 1190 | |
1da177e4 | 1191 | //BLOWFISH |
cba83564 HX |
1192 | test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template, |
1193 | BF_ENC_TEST_VECTORS); | |
1194 | test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template, | |
1195 | BF_DEC_TEST_VECTORS); | |
1196 | test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template, | |
1197 | BF_CBC_ENC_TEST_VECTORS); | |
1198 | test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template, | |
1199 | BF_CBC_DEC_TEST_VECTORS); | |
ef2736fc | 1200 | |
1da177e4 | 1201 | //TWOFISH |
cba83564 HX |
1202 | test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template, |
1203 | TF_ENC_TEST_VECTORS); | |
1204 | test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template, | |
1205 | TF_DEC_TEST_VECTORS); | |
1206 | test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template, | |
1207 | TF_CBC_ENC_TEST_VECTORS); | |
1208 | test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template, | |
1209 | TF_CBC_DEC_TEST_VECTORS); | |
ef2736fc | 1210 | |
1da177e4 | 1211 | //SERPENT |
cba83564 HX |
1212 | test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template, |
1213 | SERPENT_ENC_TEST_VECTORS); | |
1214 | test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template, | |
1215 | SERPENT_DEC_TEST_VECTORS); | |
ef2736fc | 1216 | |
1da177e4 | 1217 | //TNEPRES |
cba83564 HX |
1218 | test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template, |
1219 | TNEPRES_ENC_TEST_VECTORS); | |
1220 | test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template, | |
1221 | TNEPRES_DEC_TEST_VECTORS); | |
1da177e4 LT |
1222 | |
1223 | //AES | |
cba83564 HX |
1224 | test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template, |
1225 | AES_ENC_TEST_VECTORS); | |
1226 | test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template, | |
1227 | AES_DEC_TEST_VECTORS); | |
1228 | test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template, | |
1229 | AES_CBC_ENC_TEST_VECTORS); | |
1230 | test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template, | |
1231 | AES_CBC_DEC_TEST_VECTORS); | |
f3d1044c RS |
1232 | test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template, |
1233 | AES_LRW_ENC_TEST_VECTORS); | |
1234 | test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template, | |
1235 | AES_LRW_DEC_TEST_VECTORS); | |
f19f5111 RS |
1236 | test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template, |
1237 | AES_XTS_ENC_TEST_VECTORS); | |
1238 | test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template, | |
1239 | AES_XTS_DEC_TEST_VECTORS); | |
5311f248 | 1240 | test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template, |
23e353c8 | 1241 | AES_CTR_ENC_TEST_VECTORS); |
5311f248 | 1242 | test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template, |
23e353c8 | 1243 | AES_CTR_DEC_TEST_VECTORS); |
28db8e3e MH |
1244 | test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template, |
1245 | AES_GCM_ENC_TEST_VECTORS); | |
1246 | test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template, | |
1247 | AES_GCM_DEC_TEST_VECTORS); | |
93cc74e0 JL |
1248 | test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template, |
1249 | AES_CCM_ENC_TEST_VECTORS); | |
1250 | test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template, | |
1251 | AES_CCM_DEC_TEST_VECTORS); | |
1da177e4 LT |
1252 | |
1253 | //CAST5 | |
cba83564 HX |
1254 | test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template, |
1255 | CAST5_ENC_TEST_VECTORS); | |
1256 | test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template, | |
1257 | CAST5_DEC_TEST_VECTORS); | |
ef2736fc | 1258 | |
1da177e4 | 1259 | //CAST6 |
cba83564 HX |
1260 | test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template, |
1261 | CAST6_ENC_TEST_VECTORS); | |
1262 | test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template, | |
1263 | CAST6_DEC_TEST_VECTORS); | |
1da177e4 LT |
1264 | |
1265 | //ARC4 | |
cba83564 HX |
1266 | test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template, |
1267 | ARC4_ENC_TEST_VECTORS); | |
1268 | test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template, | |
1269 | ARC4_DEC_TEST_VECTORS); | |
1da177e4 LT |
1270 | |
1271 | //TEA | |
cba83564 HX |
1272 | test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template, |
1273 | TEA_ENC_TEST_VECTORS); | |
1274 | test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template, | |
1275 | TEA_DEC_TEST_VECTORS); | |
1da177e4 LT |
1276 | |
1277 | ||
1278 | //XTEA | |
cba83564 HX |
1279 | test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template, |
1280 | XTEA_ENC_TEST_VECTORS); | |
1281 | test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template, | |
1282 | XTEA_DEC_TEST_VECTORS); | |
1da177e4 LT |
1283 | |
1284 | //KHAZAD | |
cba83564 HX |
1285 | test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template, |
1286 | KHAZAD_ENC_TEST_VECTORS); | |
1287 | test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template, | |
1288 | KHAZAD_DEC_TEST_VECTORS); | |
1da177e4 LT |
1289 | |
1290 | //ANUBIS | |
cba83564 HX |
1291 | test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template, |
1292 | ANUBIS_ENC_TEST_VECTORS); | |
1293 | test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template, | |
1294 | ANUBIS_DEC_TEST_VECTORS); | |
1295 | test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template, | |
1296 | ANUBIS_CBC_ENC_TEST_VECTORS); | |
1297 | test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template, | |
1298 | ANUBIS_CBC_ENC_TEST_VECTORS); | |
1da177e4 | 1299 | |
fb4f10ed | 1300 | //XETA |
cba83564 HX |
1301 | test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template, |
1302 | XETA_ENC_TEST_VECTORS); | |
1303 | test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template, | |
1304 | XETA_DEC_TEST_VECTORS); | |
fb4f10ed | 1305 | |
90831639 DH |
1306 | //FCrypt |
1307 | test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template, | |
1308 | FCRYPT_ENC_TEST_VECTORS); | |
1309 | test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template, | |
1310 | FCRYPT_DEC_TEST_VECTORS); | |
1311 | ||
02ab5a70 NT |
1312 | //CAMELLIA |
1313 | test_cipher("ecb(camellia)", ENCRYPT, | |
1314 | camellia_enc_tv_template, | |
1315 | CAMELLIA_ENC_TEST_VECTORS); | |
1316 | test_cipher("ecb(camellia)", DECRYPT, | |
1317 | camellia_dec_tv_template, | |
1318 | CAMELLIA_DEC_TEST_VECTORS); | |
1319 | test_cipher("cbc(camellia)", ENCRYPT, | |
1320 | camellia_cbc_enc_tv_template, | |
1321 | CAMELLIA_CBC_ENC_TEST_VECTORS); | |
1322 | test_cipher("cbc(camellia)", DECRYPT, | |
1323 | camellia_cbc_dec_tv_template, | |
1324 | CAMELLIA_CBC_DEC_TEST_VECTORS); | |
1325 | ||
e2ee95b8 HSC |
1326 | //SEED |
1327 | test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template, | |
1328 | SEED_ENC_TEST_VECTORS); | |
1329 | test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template, | |
1330 | SEED_DEC_TEST_VECTORS); | |
1331 | ||
76cb9521 KC |
1332 | //CTS |
1333 | test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template, | |
1334 | CTS_MODE_ENC_TEST_VECTORS); | |
1335 | test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template, | |
1336 | CTS_MODE_DEC_TEST_VECTORS); | |
1337 | ||
1da177e4 LT |
1338 | test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS); |
1339 | test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS); | |
1340 | test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS); | |
1341 | test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS); | |
1342 | test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS); | |
1343 | test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS); | |
1344 | test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS); | |
1345 | test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); | |
91755a92 ZS |
1346 | test_comp("deflate", deflate_comp_tv_template, |
1347 | deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS, | |
1348 | DEFLATE_DECOMP_TEST_VECTORS); | |
0b77abb3 ZS |
1349 | test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template, |
1350 | LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS); | |
c907ee76 | 1351 | test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); |
e9d41164 HX |
1352 | test_hash("hmac(md5)", hmac_md5_tv_template, |
1353 | HMAC_MD5_TEST_VECTORS); | |
1354 | test_hash("hmac(sha1)", hmac_sha1_tv_template, | |
1355 | HMAC_SHA1_TEST_VECTORS); | |
cd12fb90 JL |
1356 | test_hash("hmac(sha224)", hmac_sha224_tv_template, |
1357 | HMAC_SHA224_TEST_VECTORS); | |
e9d41164 HX |
1358 | test_hash("hmac(sha256)", hmac_sha256_tv_template, |
1359 | HMAC_SHA256_TEST_VECTORS); | |
a28091ae AD |
1360 | test_hash("hmac(sha384)", hmac_sha384_tv_template, |
1361 | HMAC_SHA384_TEST_VECTORS); | |
1362 | test_hash("hmac(sha512)", hmac_sha512_tv_template, | |
1363 | HMAC_SHA512_TEST_VECTORS); | |
1da177e4 | 1364 | |
5b2becf5 KM |
1365 | test_hash("xcbc(aes)", aes_xcbc128_tv_template, |
1366 | XCBC_AES_TEST_VECTORS); | |
1367 | ||
1da177e4 LT |
1368 | test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS); |
1369 | break; | |
1370 | ||
1371 | case 1: | |
1372 | test_hash("md5", md5_tv_template, MD5_TEST_VECTORS); | |
1373 | break; | |
1374 | ||
1375 | case 2: | |
1376 | test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS); | |
1377 | break; | |
1378 | ||
1379 | case 3: | |
cba83564 HX |
1380 | test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template, |
1381 | DES_ENC_TEST_VECTORS); | |
1382 | test_cipher("ecb(des)", DECRYPT, des_dec_tv_template, | |
1383 | DES_DEC_TEST_VECTORS); | |
1384 | test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template, | |
1385 | DES_CBC_ENC_TEST_VECTORS); | |
1386 | test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template, | |
1387 | DES_CBC_DEC_TEST_VECTORS); | |
1da177e4 LT |
1388 | break; |
1389 | ||
1390 | case 4: | |
cba83564 HX |
1391 | test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template, |
1392 | DES3_EDE_ENC_TEST_VECTORS); | |
1393 | test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template, | |
1394 | DES3_EDE_DEC_TEST_VECTORS); | |
1da177e4 LT |
1395 | break; |
1396 | ||
1397 | case 5: | |
1398 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); | |
1399 | break; | |
ef2736fc | 1400 | |
1da177e4 LT |
1401 | case 6: |
1402 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); | |
1403 | break; | |
ef2736fc | 1404 | |
1da177e4 | 1405 | case 7: |
cba83564 HX |
1406 | test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template, |
1407 | BF_ENC_TEST_VECTORS); | |
1408 | test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template, | |
1409 | BF_DEC_TEST_VECTORS); | |
1410 | test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template, | |
1411 | BF_CBC_ENC_TEST_VECTORS); | |
1412 | test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template, | |
1413 | BF_CBC_DEC_TEST_VECTORS); | |
1da177e4 LT |
1414 | break; |
1415 | ||
1416 | case 8: | |
cba83564 HX |
1417 | test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template, |
1418 | TF_ENC_TEST_VECTORS); | |
1419 | test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template, | |
1420 | TF_DEC_TEST_VECTORS); | |
1421 | test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template, | |
1422 | TF_CBC_ENC_TEST_VECTORS); | |
1423 | test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template, | |
1424 | TF_CBC_DEC_TEST_VECTORS); | |
1da177e4 | 1425 | break; |
ef2736fc | 1426 | |
1da177e4 | 1427 | case 9: |
cba83564 HX |
1428 | test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template, |
1429 | SERPENT_ENC_TEST_VECTORS); | |
1430 | test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template, | |
1431 | SERPENT_DEC_TEST_VECTORS); | |
1da177e4 LT |
1432 | break; |
1433 | ||
1434 | case 10: | |
cba83564 HX |
1435 | test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template, |
1436 | AES_ENC_TEST_VECTORS); | |
1437 | test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template, | |
1438 | AES_DEC_TEST_VECTORS); | |
1439 | test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template, | |
1440 | AES_CBC_ENC_TEST_VECTORS); | |
1441 | test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template, | |
1442 | AES_CBC_DEC_TEST_VECTORS); | |
f3d1044c RS |
1443 | test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template, |
1444 | AES_LRW_ENC_TEST_VECTORS); | |
1445 | test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template, | |
1446 | AES_LRW_DEC_TEST_VECTORS); | |
f19f5111 RS |
1447 | test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template, |
1448 | AES_XTS_ENC_TEST_VECTORS); | |
1449 | test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template, | |
1450 | AES_XTS_DEC_TEST_VECTORS); | |
5311f248 | 1451 | test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template, |
23e353c8 | 1452 | AES_CTR_ENC_TEST_VECTORS); |
5311f248 | 1453 | test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template, |
23e353c8 | 1454 | AES_CTR_DEC_TEST_VECTORS); |
1da177e4 LT |
1455 | break; |
1456 | ||
1457 | case 11: | |
1458 | test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS); | |
1459 | break; | |
ef2736fc | 1460 | |
1da177e4 LT |
1461 | case 12: |
1462 | test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS); | |
1463 | break; | |
1464 | ||
1465 | case 13: | |
91755a92 ZS |
1466 | test_comp("deflate", deflate_comp_tv_template, |
1467 | deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS, | |
1468 | DEFLATE_DECOMP_TEST_VECTORS); | |
1da177e4 LT |
1469 | break; |
1470 | ||
1471 | case 14: | |
cba83564 HX |
1472 | test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template, |
1473 | CAST5_ENC_TEST_VECTORS); | |
1474 | test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template, | |
1475 | CAST5_DEC_TEST_VECTORS); | |
1da177e4 LT |
1476 | break; |
1477 | ||
1478 | case 15: | |
cba83564 HX |
1479 | test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template, |
1480 | CAST6_ENC_TEST_VECTORS); | |
1481 | test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template, | |
1482 | CAST6_DEC_TEST_VECTORS); | |
1da177e4 LT |
1483 | break; |
1484 | ||
1485 | case 16: | |
cba83564 HX |
1486 | test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template, |
1487 | ARC4_ENC_TEST_VECTORS); | |
1488 | test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template, | |
1489 | ARC4_DEC_TEST_VECTORS); | |
1da177e4 LT |
1490 | break; |
1491 | ||
1492 | case 17: | |
1493 | test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS); | |
1494 | break; | |
1495 | ||
1496 | case 18: | |
c907ee76 | 1497 | test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); |
1da177e4 LT |
1498 | break; |
1499 | ||
1500 | case 19: | |
cba83564 HX |
1501 | test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template, |
1502 | TEA_ENC_TEST_VECTORS); | |
1503 | test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template, | |
1504 | TEA_DEC_TEST_VECTORS); | |
1da177e4 LT |
1505 | break; |
1506 | ||
1507 | case 20: | |
cba83564 HX |
1508 | test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template, |
1509 | XTEA_ENC_TEST_VECTORS); | |
1510 | test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template, | |
1511 | XTEA_DEC_TEST_VECTORS); | |
1da177e4 LT |
1512 | break; |
1513 | ||
1514 | case 21: | |
cba83564 HX |
1515 | test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template, |
1516 | KHAZAD_ENC_TEST_VECTORS); | |
1517 | test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template, | |
1518 | KHAZAD_DEC_TEST_VECTORS); | |
1da177e4 LT |
1519 | break; |
1520 | ||
1521 | case 22: | |
1522 | test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS); | |
1523 | break; | |
1524 | ||
1525 | case 23: | |
1526 | test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS); | |
1527 | break; | |
1528 | ||
1529 | case 24: | |
1530 | test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS); | |
1531 | break; | |
1532 | ||
1533 | case 25: | |
cba83564 HX |
1534 | test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template, |
1535 | TNEPRES_ENC_TEST_VECTORS); | |
1536 | test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template, | |
1537 | TNEPRES_DEC_TEST_VECTORS); | |
1da177e4 LT |
1538 | break; |
1539 | ||
1540 | case 26: | |
cba83564 HX |
1541 | test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template, |
1542 | ANUBIS_ENC_TEST_VECTORS); | |
1543 | test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template, | |
1544 | ANUBIS_DEC_TEST_VECTORS); | |
1545 | test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template, | |
1546 | ANUBIS_CBC_ENC_TEST_VECTORS); | |
1547 | test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template, | |
1548 | ANUBIS_CBC_ENC_TEST_VECTORS); | |
1da177e4 LT |
1549 | break; |
1550 | ||
1551 | case 27: | |
1552 | test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS); | |
1553 | break; | |
1554 | ||
1555 | case 28: | |
1556 | ||
1557 | test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS); | |
1558 | break; | |
1559 | ||
1560 | case 29: | |
1561 | test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); | |
1562 | break; | |
2998db37 | 1563 | |
fb4f10ed | 1564 | case 30: |
cba83564 HX |
1565 | test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template, |
1566 | XETA_ENC_TEST_VECTORS); | |
1567 | test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template, | |
1568 | XETA_DEC_TEST_VECTORS); | |
fb4f10ed | 1569 | break; |
1da177e4 | 1570 | |
90831639 DH |
1571 | case 31: |
1572 | test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template, | |
1573 | FCRYPT_ENC_TEST_VECTORS); | |
1574 | test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template, | |
1575 | FCRYPT_DEC_TEST_VECTORS); | |
1576 | break; | |
1577 | ||
02ab5a70 NT |
1578 | case 32: |
1579 | test_cipher("ecb(camellia)", ENCRYPT, | |
1580 | camellia_enc_tv_template, | |
1581 | CAMELLIA_ENC_TEST_VECTORS); | |
1582 | test_cipher("ecb(camellia)", DECRYPT, | |
1583 | camellia_dec_tv_template, | |
1584 | CAMELLIA_DEC_TEST_VECTORS); | |
1585 | test_cipher("cbc(camellia)", ENCRYPT, | |
1586 | camellia_cbc_enc_tv_template, | |
1587 | CAMELLIA_CBC_ENC_TEST_VECTORS); | |
1588 | test_cipher("cbc(camellia)", DECRYPT, | |
1589 | camellia_cbc_dec_tv_template, | |
1590 | CAMELLIA_CBC_DEC_TEST_VECTORS); | |
1591 | break; | |
cd12fb90 JL |
1592 | case 33: |
1593 | test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS); | |
1594 | break; | |
02ab5a70 | 1595 | |
2407d608 TSH |
1596 | case 34: |
1597 | test_cipher("salsa20", ENCRYPT, | |
1598 | salsa20_stream_enc_tv_template, | |
1599 | SALSA20_STREAM_ENC_TEST_VECTORS); | |
1600 | break; | |
1601 | ||
8df213d9 HX |
1602 | case 35: |
1603 | test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template, | |
1604 | AES_GCM_ENC_TEST_VECTORS); | |
1605 | test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template, | |
1606 | AES_GCM_DEC_TEST_VECTORS); | |
1607 | break; | |
1608 | ||
0b77abb3 ZS |
1609 | case 36: |
1610 | test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template, | |
1611 | LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS); | |
1612 | break; | |
1613 | ||
93cc74e0 JL |
1614 | case 37: |
1615 | test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template, | |
1616 | AES_CCM_ENC_TEST_VECTORS); | |
1617 | test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template, | |
1618 | AES_CCM_DEC_TEST_VECTORS); | |
1619 | break; | |
1620 | ||
76cb9521 KC |
1621 | case 38: |
1622 | test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template, | |
1623 | CTS_MODE_ENC_TEST_VECTORS); | |
1624 | test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template, | |
1625 | CTS_MODE_DEC_TEST_VECTORS); | |
1626 | break; | |
1627 | ||
fd4adf1a AKR |
1628 | case 39: |
1629 | test_hash("rmd128", rmd128_tv_template, RMD128_TEST_VECTORS); | |
1630 | break; | |
1631 | ||
1632 | case 40: | |
1633 | test_hash("rmd160", rmd160_tv_template, RMD160_TEST_VECTORS); | |
1634 | break; | |
1635 | ||
2998db37 AKR |
1636 | case 41: |
1637 | test_hash("rmd256", rmd256_tv_template, RMD256_TEST_VECTORS); | |
1638 | break; | |
1639 | ||
1640 | case 42: | |
1641 | test_hash("rmd320", rmd320_tv_template, RMD320_TEST_VECTORS); | |
1642 | break; | |
1643 | ||
1da177e4 | 1644 | case 100: |
e9d41164 HX |
1645 | test_hash("hmac(md5)", hmac_md5_tv_template, |
1646 | HMAC_MD5_TEST_VECTORS); | |
1da177e4 | 1647 | break; |
ef2736fc | 1648 | |
1da177e4 | 1649 | case 101: |
e9d41164 HX |
1650 | test_hash("hmac(sha1)", hmac_sha1_tv_template, |
1651 | HMAC_SHA1_TEST_VECTORS); | |
1da177e4 | 1652 | break; |
ef2736fc | 1653 | |
1da177e4 | 1654 | case 102: |
e9d41164 HX |
1655 | test_hash("hmac(sha256)", hmac_sha256_tv_template, |
1656 | HMAC_SHA256_TEST_VECTORS); | |
1da177e4 LT |
1657 | break; |
1658 | ||
a28091ae AD |
1659 | case 103: |
1660 | test_hash("hmac(sha384)", hmac_sha384_tv_template, | |
1661 | HMAC_SHA384_TEST_VECTORS); | |
1662 | break; | |
1663 | ||
1664 | case 104: | |
1665 | test_hash("hmac(sha512)", hmac_sha512_tv_template, | |
1666 | HMAC_SHA512_TEST_VECTORS); | |
1667 | break; | |
38ed9ab2 | 1668 | |
cd12fb90 JL |
1669 | case 105: |
1670 | test_hash("hmac(sha224)", hmac_sha224_tv_template, | |
1671 | HMAC_SHA224_TEST_VECTORS); | |
1672 | break; | |
1da177e4 | 1673 | |
38ed9ab2 HX |
1674 | case 106: |
1675 | test_hash("xcbc(aes)", aes_xcbc128_tv_template, | |
1676 | XCBC_AES_TEST_VECTORS); | |
1677 | break; | |
1678 | ||
fd4adf1a AKR |
1679 | case 107: |
1680 | test_hash("hmac(rmd128)", hmac_rmd128_tv_template, | |
1681 | HMAC_RMD128_TEST_VECTORS); | |
1682 | break; | |
1683 | ||
1684 | case 108: | |
1685 | test_hash("hmac(rmd160)", hmac_rmd160_tv_template, | |
1686 | HMAC_RMD160_TEST_VECTORS); | |
1687 | break; | |
1688 | ||
ebfd9bcf | 1689 | case 200: |
cba83564 | 1690 | test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1691 | speed_template_16_24_32); |
cba83564 | 1692 | test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 1693 | speed_template_16_24_32); |
cba83564 | 1694 | test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1695 | speed_template_16_24_32); |
cba83564 | 1696 | test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 1697 | speed_template_16_24_32); |
f3d1044c | 1698 | test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1699 | speed_template_32_40_48); |
f3d1044c | 1700 | test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 1701 | speed_template_32_40_48); |
f19f5111 | 1702 | test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1703 | speed_template_32_48_64); |
f19f5111 | 1704 | test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 1705 | speed_template_32_48_64); |
ebfd9bcf HW |
1706 | break; |
1707 | ||
1708 | case 201: | |
cba83564 | 1709 | test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec, |
477035c2 SS |
1710 | des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS, |
1711 | speed_template_24); | |
cba83564 | 1712 | test_cipher_speed("ecb(des3_ede)", DECRYPT, sec, |
477035c2 SS |
1713 | des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS, |
1714 | speed_template_24); | |
cba83564 | 1715 | test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec, |
477035c2 SS |
1716 | des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS, |
1717 | speed_template_24); | |
cba83564 | 1718 | test_cipher_speed("cbc(des3_ede)", DECRYPT, sec, |
477035c2 SS |
1719 | des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS, |
1720 | speed_template_24); | |
ebfd9bcf HW |
1721 | break; |
1722 | ||
1723 | case 202: | |
cba83564 | 1724 | test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1725 | speed_template_16_24_32); |
cba83564 | 1726 | test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, |
477035c2 | 1727 | speed_template_16_24_32); |
cba83564 | 1728 | test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1729 | speed_template_16_24_32); |
cba83564 | 1730 | test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, |
477035c2 | 1731 | speed_template_16_24_32); |
ebfd9bcf HW |
1732 | break; |
1733 | ||
1734 | case 203: | |
cba83564 | 1735 | test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1736 | speed_template_8_32); |
cba83564 | 1737 | test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, |
477035c2 | 1738 | speed_template_8_32); |
cba83564 | 1739 | test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1740 | speed_template_8_32); |
cba83564 | 1741 | test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, |
477035c2 | 1742 | speed_template_8_32); |
ebfd9bcf HW |
1743 | break; |
1744 | ||
1745 | case 204: | |
cba83564 | 1746 | test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1747 | speed_template_8); |
cba83564 | 1748 | test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, |
477035c2 | 1749 | speed_template_8); |
cba83564 | 1750 | test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1751 | speed_template_8); |
cba83564 | 1752 | test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, |
477035c2 | 1753 | speed_template_8); |
ebfd9bcf HW |
1754 | break; |
1755 | ||
02ab5a70 NT |
1756 | case 205: |
1757 | test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, | |
477035c2 | 1758 | speed_template_16_24_32); |
02ab5a70 | 1759 | test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, |
477035c2 | 1760 | speed_template_16_24_32); |
02ab5a70 | 1761 | test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1762 | speed_template_16_24_32); |
02ab5a70 | 1763 | test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, |
477035c2 | 1764 | speed_template_16_24_32); |
02ab5a70 NT |
1765 | break; |
1766 | ||
5de8f1b5 TSH |
1767 | case 206: |
1768 | test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0, | |
477035c2 | 1769 | speed_template_16_32); |
5de8f1b5 TSH |
1770 | break; |
1771 | ||
e8057928 ML |
1772 | case 300: |
1773 | /* fall through */ | |
1774 | ||
1775 | case 301: | |
e9d41164 | 1776 | test_hash_speed("md4", sec, generic_hash_speed_template); |
e8057928 ML |
1777 | if (mode > 300 && mode < 400) break; |
1778 | ||
1779 | case 302: | |
e9d41164 | 1780 | test_hash_speed("md5", sec, generic_hash_speed_template); |
e8057928 ML |
1781 | if (mode > 300 && mode < 400) break; |
1782 | ||
1783 | case 303: | |
e9d41164 | 1784 | test_hash_speed("sha1", sec, generic_hash_speed_template); |
e8057928 ML |
1785 | if (mode > 300 && mode < 400) break; |
1786 | ||
1787 | case 304: | |
e9d41164 | 1788 | test_hash_speed("sha256", sec, generic_hash_speed_template); |
e8057928 ML |
1789 | if (mode > 300 && mode < 400) break; |
1790 | ||
1791 | case 305: | |
e9d41164 | 1792 | test_hash_speed("sha384", sec, generic_hash_speed_template); |
e8057928 ML |
1793 | if (mode > 300 && mode < 400) break; |
1794 | ||
1795 | case 306: | |
e9d41164 | 1796 | test_hash_speed("sha512", sec, generic_hash_speed_template); |
e8057928 ML |
1797 | if (mode > 300 && mode < 400) break; |
1798 | ||
1799 | case 307: | |
e9d41164 | 1800 | test_hash_speed("wp256", sec, generic_hash_speed_template); |
e8057928 ML |
1801 | if (mode > 300 && mode < 400) break; |
1802 | ||
1803 | case 308: | |
e9d41164 | 1804 | test_hash_speed("wp384", sec, generic_hash_speed_template); |
e8057928 ML |
1805 | if (mode > 300 && mode < 400) break; |
1806 | ||
1807 | case 309: | |
e9d41164 | 1808 | test_hash_speed("wp512", sec, generic_hash_speed_template); |
e8057928 ML |
1809 | if (mode > 300 && mode < 400) break; |
1810 | ||
1811 | case 310: | |
e9d41164 | 1812 | test_hash_speed("tgr128", sec, generic_hash_speed_template); |
e8057928 ML |
1813 | if (mode > 300 && mode < 400) break; |
1814 | ||
1815 | case 311: | |
e9d41164 | 1816 | test_hash_speed("tgr160", sec, generic_hash_speed_template); |
e8057928 ML |
1817 | if (mode > 300 && mode < 400) break; |
1818 | ||
1819 | case 312: | |
e9d41164 | 1820 | test_hash_speed("tgr192", sec, generic_hash_speed_template); |
e8057928 ML |
1821 | if (mode > 300 && mode < 400) break; |
1822 | ||
cd12fb90 JL |
1823 | case 313: |
1824 | test_hash_speed("sha224", sec, generic_hash_speed_template); | |
1825 | if (mode > 300 && mode < 400) break; | |
1826 | ||
fd4adf1a AKR |
1827 | case 314: |
1828 | test_hash_speed("rmd128", sec, generic_hash_speed_template); | |
1829 | if (mode > 300 && mode < 400) break; | |
1830 | ||
1831 | case 315: | |
1832 | test_hash_speed("rmd160", sec, generic_hash_speed_template); | |
1833 | if (mode > 300 && mode < 400) break; | |
1834 | ||
2998db37 AKR |
1835 | case 316: |
1836 | test_hash_speed("rmd256", sec, generic_hash_speed_template); | |
1837 | if (mode > 300 && mode < 400) break; | |
1838 | ||
1839 | case 317: | |
1840 | test_hash_speed("rmd320", sec, generic_hash_speed_template); | |
1841 | if (mode > 300 && mode < 400) break; | |
1842 | ||
e8057928 ML |
1843 | case 399: |
1844 | break; | |
1845 | ||
1da177e4 LT |
1846 | case 1000: |
1847 | test_available(); | |
1848 | break; | |
ef2736fc | 1849 | |
1da177e4 LT |
1850 | default: |
1851 | /* useful for debugging */ | |
1852 | printk("not testing anything\n"); | |
1853 | break; | |
1854 | } | |
1855 | } | |
1856 | ||
3af5b90b | 1857 | static int __init tcrypt_mod_init(void) |
1da177e4 | 1858 | { |
e3a4ea4f MH |
1859 | int err = -ENOMEM; |
1860 | ||
1da177e4 LT |
1861 | tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL); |
1862 | if (tvmem == NULL) | |
e3a4ea4f | 1863 | return err; |
1da177e4 LT |
1864 | |
1865 | xbuf = kmalloc(XBUFSIZE, GFP_KERNEL); | |
e3a4ea4f MH |
1866 | if (xbuf == NULL) |
1867 | goto err_free_tv; | |
1da177e4 | 1868 | |
e3a4ea4f MH |
1869 | axbuf = kmalloc(XBUFSIZE, GFP_KERNEL); |
1870 | if (axbuf == NULL) | |
1871 | goto err_free_xbuf; | |
1da177e4 | 1872 | |
e3a4ea4f | 1873 | do_test(); |
14fdf477 ML |
1874 | |
1875 | /* We intentionaly return -EAGAIN to prevent keeping | |
1876 | * the module. It does all its work from init() | |
1877 | * and doesn't offer any runtime functionality | |
1878 | * => we don't need it in the memory, do we? | |
1879 | * -- mludvig | |
1880 | */ | |
e3a4ea4f MH |
1881 | err = -EAGAIN; |
1882 | ||
1883 | kfree(axbuf); | |
1884 | err_free_xbuf: | |
1885 | kfree(xbuf); | |
1886 | err_free_tv: | |
1887 | kfree(tvmem); | |
1888 | ||
1889 | return err; | |
1da177e4 LT |
1890 | } |
1891 | ||
1892 | /* | |
1893 | * If an init function is provided, an exit function must also be provided | |
1894 | * to allow module unload. | |
1895 | */ | |
3af5b90b | 1896 | static void __exit tcrypt_mod_fini(void) { } |
1da177e4 | 1897 | |
3af5b90b KB |
1898 | module_init(tcrypt_mod_init); |
1899 | module_exit(tcrypt_mod_fini); | |
1da177e4 LT |
1900 | |
1901 | module_param(mode, int, 0); | |
ebfd9bcf | 1902 | module_param(sec, uint, 0); |
6a17944c HX |
1903 | MODULE_PARM_DESC(sec, "Length in seconds of speed tests " |
1904 | "(defaults to zero which uses CPU cycles instead)"); | |
1da177e4 LT |
1905 | |
1906 | MODULE_LICENSE("GPL"); | |
1907 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); | |
1908 | MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>"); |