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