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