diff options
Diffstat (limited to 'crypto/tcrypt.c')
-rw-r--r-- | crypto/tcrypt.c | 580 |
1 files changed, 407 insertions, 173 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index 92b0352c8e92..bd7524cfff33 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Quick & dirty crypto testing module. | 2 | * Quick & dirty crypto testing module. |
3 | * | 3 | * |
4 | * This will only exist until we have a better testing mechanism | 4 | * This will only exist until we have a better testing mechanism |
@@ -9,11 +9,12 @@ | |||
9 | * | 9 | * |
10 | * This program is free software; you can redistribute it and/or modify it | 10 | * This program is free software; you can redistribute it and/or modify it |
11 | * under the terms of the GNU General Public License as published by the Free | 11 | * under the terms of the GNU General Public License as published by the Free |
12 | * Software Foundation; either version 2 of the License, or (at your option) | 12 | * Software Foundation; either version 2 of the License, or (at your option) |
13 | * any later version. | 13 | * any later version. |
14 | * | 14 | * |
15 | * 14 - 09 - 2003 | 15 | * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>) |
16 | * Rewritten by Kartikey Mahendra Bhatt | 16 | * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt |
17 | * | ||
17 | */ | 18 | */ |
18 | 19 | ||
19 | #include <linux/init.h> | 20 | #include <linux/init.h> |
@@ -25,12 +26,15 @@ | |||
25 | #include <linux/crypto.h> | 26 | #include <linux/crypto.h> |
26 | #include <linux/highmem.h> | 27 | #include <linux/highmem.h> |
27 | #include <linux/moduleparam.h> | 28 | #include <linux/moduleparam.h> |
29 | #include <linux/jiffies.h> | ||
30 | #include <linux/timex.h> | ||
31 | #include <linux/interrupt.h> | ||
28 | #include "tcrypt.h" | 32 | #include "tcrypt.h" |
29 | 33 | ||
30 | /* | 34 | /* |
31 | * Need to kmalloc() memory for testing kmap(). | 35 | * Need to kmalloc() memory for testing kmap(). |
32 | */ | 36 | */ |
33 | #define TVMEMSIZE 4096 | 37 | #define TVMEMSIZE 16384 |
34 | #define XBUFSIZE 32768 | 38 | #define XBUFSIZE 32768 |
35 | 39 | ||
36 | /* | 40 | /* |
@@ -55,19 +59,23 @@ | |||
55 | 59 | ||
56 | static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; | 60 | static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; |
57 | 61 | ||
62 | /* | ||
63 | * Used by test_cipher_speed() | ||
64 | */ | ||
65 | static unsigned int sec; | ||
66 | |||
58 | static int mode; | 67 | static int mode; |
59 | static char *xbuf; | 68 | static char *xbuf; |
60 | static char *tvmem; | 69 | static char *tvmem; |
61 | 70 | ||
62 | static char *check[] = { | 71 | static char *check[] = { |
63 | "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish", | 72 | "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish", |
64 | "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6", | 73 | "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6", |
65 | "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", | 74 | "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", |
66 | "khazad", "wp512", "wp384", "wp256", "tnepres", NULL | 75 | "khazad", "wp512", "wp384", "wp256", "tnepres", NULL |
67 | }; | 76 | }; |
68 | 77 | ||
69 | static void | 78 | static void hexdump(unsigned char *buf, unsigned int len) |
70 | hexdump(unsigned char *buf, unsigned int len) | ||
71 | { | 79 | { |
72 | while (len--) | 80 | while (len--) |
73 | printk("%02x", *buf++); | 81 | printk("%02x", *buf++); |
@@ -75,29 +83,29 @@ hexdump(unsigned char *buf, unsigned int len) | |||
75 | printk("\n"); | 83 | printk("\n"); |
76 | } | 84 | } |
77 | 85 | ||
78 | static void | 86 | static void test_hash(char *algo, struct hash_testvec *template, |
79 | test_hash (char * algo, struct hash_testvec * template, unsigned int tcount) | 87 | unsigned int tcount) |
80 | { | 88 | { |
81 | char *p; | 89 | char *p; |
82 | unsigned int i, j, k, temp; | 90 | unsigned int i, j, k, temp; |
83 | struct scatterlist sg[8]; | 91 | struct scatterlist sg[8]; |
84 | char result[64]; | 92 | char result[64]; |
85 | struct crypto_tfm *tfm; | 93 | struct crypto_tfm *tfm; |
86 | struct hash_testvec *hash_tv; | 94 | struct hash_testvec *hash_tv; |
87 | unsigned int tsize; | 95 | unsigned int tsize; |
88 | 96 | ||
89 | printk("\ntesting %s\n", algo); | 97 | printk("\ntesting %s\n", algo); |
90 | 98 | ||
91 | tsize = sizeof (struct hash_testvec); | 99 | tsize = sizeof(struct hash_testvec); |
92 | tsize *= tcount; | 100 | tsize *= tcount; |
93 | 101 | ||
94 | if (tsize > TVMEMSIZE) { | 102 | if (tsize > TVMEMSIZE) { |
95 | printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE); | 103 | printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE); |
96 | return; | 104 | return; |
97 | } | 105 | } |
98 | 106 | ||
99 | memcpy(tvmem, template, tsize); | 107 | memcpy(tvmem, template, tsize); |
100 | hash_tv = (void *) tvmem; | 108 | hash_tv = (void *)tvmem; |
101 | tfm = crypto_alloc_tfm(algo, 0); | 109 | tfm = crypto_alloc_tfm(algo, 0); |
102 | if (tfm == NULL) { | 110 | if (tfm == NULL) { |
103 | printk("failed to load transform for %s\n", algo); | 111 | printk("failed to load transform for %s\n", algo); |
@@ -105,70 +113,71 @@ test_hash (char * algo, struct hash_testvec * template, unsigned int tcount) | |||
105 | } | 113 | } |
106 | 114 | ||
107 | for (i = 0; i < tcount; i++) { | 115 | for (i = 0; i < tcount; i++) { |
108 | printk ("test %u:\n", i + 1); | 116 | printk("test %u:\n", i + 1); |
109 | memset (result, 0, 64); | 117 | memset(result, 0, 64); |
110 | 118 | ||
111 | p = hash_tv[i].plaintext; | 119 | p = hash_tv[i].plaintext; |
112 | sg[0].page = virt_to_page (p); | 120 | sg[0].page = virt_to_page(p); |
113 | sg[0].offset = offset_in_page (p); | 121 | sg[0].offset = offset_in_page(p); |
114 | sg[0].length = hash_tv[i].psize; | 122 | sg[0].length = hash_tv[i].psize; |
115 | 123 | ||
116 | crypto_digest_init (tfm); | 124 | crypto_digest_init(tfm); |
117 | if (tfm->crt_u.digest.dit_setkey) { | 125 | if (tfm->crt_u.digest.dit_setkey) { |
118 | crypto_digest_setkey (tfm, hash_tv[i].key, | 126 | crypto_digest_setkey(tfm, hash_tv[i].key, |
119 | hash_tv[i].ksize); | 127 | hash_tv[i].ksize); |
120 | } | 128 | } |
121 | crypto_digest_update (tfm, sg, 1); | 129 | crypto_digest_update(tfm, sg, 1); |
122 | crypto_digest_final (tfm, result); | 130 | crypto_digest_final(tfm, result); |
123 | 131 | ||
124 | hexdump (result, crypto_tfm_alg_digestsize (tfm)); | 132 | hexdump(result, crypto_tfm_alg_digestsize(tfm)); |
125 | printk("%s\n", | 133 | printk("%s\n", |
126 | memcmp(result, hash_tv[i].digest, | 134 | memcmp(result, hash_tv[i].digest, |
127 | crypto_tfm_alg_digestsize(tfm)) ? "fail" : | 135 | crypto_tfm_alg_digestsize(tfm)) ? |
128 | "pass"); | 136 | "fail" : "pass"); |
129 | } | 137 | } |
130 | 138 | ||
131 | printk ("testing %s across pages\n", algo); | 139 | printk("testing %s across pages\n", algo); |
132 | 140 | ||
133 | /* setup the dummy buffer first */ | 141 | /* setup the dummy buffer first */ |
134 | memset(xbuf, 0, XBUFSIZE); | 142 | memset(xbuf, 0, XBUFSIZE); |
135 | 143 | ||
136 | j = 0; | 144 | j = 0; |
137 | for (i = 0; i < tcount; i++) { | 145 | for (i = 0; i < tcount; i++) { |
138 | if (hash_tv[i].np) { | 146 | if (hash_tv[i].np) { |
139 | j++; | 147 | j++; |
140 | printk ("test %u:\n", j); | 148 | printk("test %u:\n", j); |
141 | memset (result, 0, 64); | 149 | memset(result, 0, 64); |
142 | 150 | ||
143 | temp = 0; | 151 | temp = 0; |
144 | for (k = 0; k < hash_tv[i].np; k++) { | 152 | for (k = 0; k < hash_tv[i].np; k++) { |
145 | memcpy (&xbuf[IDX[k]], hash_tv[i].plaintext + temp, | 153 | memcpy(&xbuf[IDX[k]], |
146 | hash_tv[i].tap[k]); | 154 | hash_tv[i].plaintext + temp, |
155 | hash_tv[i].tap[k]); | ||
147 | temp += hash_tv[i].tap[k]; | 156 | temp += hash_tv[i].tap[k]; |
148 | p = &xbuf[IDX[k]]; | 157 | p = &xbuf[IDX[k]]; |
149 | sg[k].page = virt_to_page (p); | 158 | sg[k].page = virt_to_page(p); |
150 | sg[k].offset = offset_in_page (p); | 159 | sg[k].offset = offset_in_page(p); |
151 | sg[k].length = hash_tv[i].tap[k]; | 160 | sg[k].length = hash_tv[i].tap[k]; |
152 | } | 161 | } |
153 | 162 | ||
154 | crypto_digest_digest (tfm, sg, hash_tv[i].np, result); | 163 | crypto_digest_digest(tfm, sg, hash_tv[i].np, result); |
155 | 164 | ||
156 | hexdump (result, crypto_tfm_alg_digestsize (tfm)); | 165 | hexdump(result, crypto_tfm_alg_digestsize(tfm)); |
157 | printk("%s\n", | 166 | printk("%s\n", |
158 | memcmp(result, hash_tv[i].digest, | 167 | memcmp(result, hash_tv[i].digest, |
159 | crypto_tfm_alg_digestsize(tfm)) ? "fail" : | 168 | crypto_tfm_alg_digestsize(tfm)) ? |
160 | "pass"); | 169 | "fail" : "pass"); |
161 | } | 170 | } |
162 | } | 171 | } |
163 | 172 | ||
164 | crypto_free_tfm (tfm); | 173 | crypto_free_tfm(tfm); |
165 | } | 174 | } |
166 | 175 | ||
167 | 176 | ||
168 | #ifdef CONFIG_CRYPTO_HMAC | 177 | #ifdef CONFIG_CRYPTO_HMAC |
169 | 178 | ||
170 | static void | 179 | static void test_hmac(char *algo, struct hmac_testvec *template, |
171 | test_hmac(char *algo, struct hmac_testvec * template, unsigned int tcount) | 180 | unsigned int tcount) |
172 | { | 181 | { |
173 | char *p; | 182 | char *p; |
174 | unsigned int i, j, k, temp; | 183 | unsigned int i, j, k, temp; |
@@ -185,8 +194,8 @@ test_hmac(char *algo, struct hmac_testvec * template, unsigned int tcount) | |||
185 | } | 194 | } |
186 | 195 | ||
187 | printk("\ntesting hmac_%s\n", algo); | 196 | printk("\ntesting hmac_%s\n", algo); |
188 | 197 | ||
189 | tsize = sizeof (struct hmac_testvec); | 198 | tsize = sizeof(struct hmac_testvec); |
190 | tsize *= tcount; | 199 | tsize *= tcount; |
191 | if (tsize > TVMEMSIZE) { | 200 | if (tsize > TVMEMSIZE) { |
192 | printk("template (%u) too big for tvmem (%u)\n", tsize, | 201 | printk("template (%u) too big for tvmem (%u)\n", tsize, |
@@ -195,7 +204,7 @@ test_hmac(char *algo, struct hmac_testvec * template, unsigned int tcount) | |||
195 | } | 204 | } |
196 | 205 | ||
197 | memcpy(tvmem, template, tsize); | 206 | memcpy(tvmem, template, tsize); |
198 | hmac_tv = (void *) tvmem; | 207 | hmac_tv = (void *)tvmem; |
199 | 208 | ||
200 | for (i = 0; i < tcount; i++) { | 209 | for (i = 0; i < tcount; i++) { |
201 | printk("test %u:\n", i + 1); | 210 | printk("test %u:\n", i + 1); |
@@ -219,34 +228,35 @@ test_hmac(char *algo, struct hmac_testvec * template, unsigned int tcount) | |||
219 | printk("\ntesting hmac_%s across pages\n", algo); | 228 | printk("\ntesting hmac_%s across pages\n", algo); |
220 | 229 | ||
221 | memset(xbuf, 0, XBUFSIZE); | 230 | memset(xbuf, 0, XBUFSIZE); |
222 | 231 | ||
223 | j = 0; | 232 | j = 0; |
224 | for (i = 0; i < tcount; i++) { | 233 | for (i = 0; i < tcount; i++) { |
225 | if (hmac_tv[i].np) { | 234 | if (hmac_tv[i].np) { |
226 | j++; | 235 | j++; |
227 | printk ("test %u:\n",j); | 236 | printk("test %u:\n",j); |
228 | memset (result, 0, 64); | 237 | memset(result, 0, 64); |
229 | 238 | ||
230 | temp = 0; | 239 | temp = 0; |
231 | klen = hmac_tv[i].ksize; | 240 | klen = hmac_tv[i].ksize; |
232 | for (k = 0; k < hmac_tv[i].np; k++) { | 241 | for (k = 0; k < hmac_tv[i].np; k++) { |
233 | memcpy (&xbuf[IDX[k]], hmac_tv[i].plaintext + temp, | 242 | memcpy(&xbuf[IDX[k]], |
234 | hmac_tv[i].tap[k]); | 243 | hmac_tv[i].plaintext + temp, |
244 | hmac_tv[i].tap[k]); | ||
235 | temp += hmac_tv[i].tap[k]; | 245 | temp += hmac_tv[i].tap[k]; |
236 | p = &xbuf[IDX[k]]; | 246 | p = &xbuf[IDX[k]]; |
237 | sg[k].page = virt_to_page (p); | 247 | sg[k].page = virt_to_page(p); |
238 | sg[k].offset = offset_in_page (p); | 248 | sg[k].offset = offset_in_page(p); |
239 | sg[k].length = hmac_tv[i].tap[k]; | 249 | sg[k].length = hmac_tv[i].tap[k]; |
240 | } | 250 | } |
241 | 251 | ||
242 | crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, hmac_tv[i].np, | 252 | crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, |
243 | result); | 253 | hmac_tv[i].np, result); |
244 | hexdump(result, crypto_tfm_alg_digestsize(tfm)); | 254 | hexdump(result, crypto_tfm_alg_digestsize(tfm)); |
245 | 255 | ||
246 | printk("%s\n", | 256 | printk("%s\n", |
247 | memcmp(result, hmac_tv[i].digest, | 257 | memcmp(result, hmac_tv[i].digest, |
248 | crypto_tfm_alg_digestsize(tfm)) ? "fail" : | 258 | crypto_tfm_alg_digestsize(tfm)) ? |
249 | "pass"); | 259 | "fail" : "pass"); |
250 | } | 260 | } |
251 | } | 261 | } |
252 | out: | 262 | out: |
@@ -255,8 +265,8 @@ out: | |||
255 | 265 | ||
256 | #endif /* CONFIG_CRYPTO_HMAC */ | 266 | #endif /* CONFIG_CRYPTO_HMAC */ |
257 | 267 | ||
258 | static void | 268 | static void test_cipher(char *algo, int mode, int enc, |
259 | test_cipher(char * algo, int mode, int enc, struct cipher_testvec * template, unsigned int tcount) | 269 | struct cipher_testvec *template, unsigned int tcount) |
260 | { | 270 | { |
261 | unsigned int ret, i, j, k, temp; | 271 | unsigned int ret, i, j, k, temp; |
262 | unsigned int tsize; | 272 | unsigned int tsize; |
@@ -265,22 +275,22 @@ test_cipher(char * algo, int mode, int enc, struct cipher_testvec * template, un | |||
265 | char *key; | 275 | char *key; |
266 | struct cipher_testvec *cipher_tv; | 276 | struct cipher_testvec *cipher_tv; |
267 | struct scatterlist sg[8]; | 277 | struct scatterlist sg[8]; |
268 | char e[11], m[4]; | 278 | const char *e, *m; |
269 | 279 | ||
270 | if (enc == ENCRYPT) | 280 | if (enc == ENCRYPT) |
271 | strncpy(e, "encryption", 11); | 281 | e = "encryption"; |
272 | else | 282 | else |
273 | strncpy(e, "decryption", 11); | 283 | e = "decryption"; |
274 | if (mode == MODE_ECB) | 284 | if (mode == MODE_ECB) |
275 | strncpy(m, "ECB", 4); | 285 | m = "ECB"; |
276 | else | 286 | else |
277 | strncpy(m, "CBC", 4); | 287 | m = "CBC"; |
278 | 288 | ||
279 | printk("\ntesting %s %s %s \n", algo, m, e); | 289 | printk("\ntesting %s %s %s\n", algo, m, e); |
280 | 290 | ||
281 | tsize = sizeof (struct cipher_testvec); | 291 | tsize = sizeof (struct cipher_testvec); |
282 | tsize *= tcount; | 292 | tsize *= tcount; |
283 | 293 | ||
284 | if (tsize > TVMEMSIZE) { | 294 | if (tsize > TVMEMSIZE) { |
285 | printk("template (%u) too big for tvmem (%u)\n", tsize, | 295 | printk("template (%u) too big for tvmem (%u)\n", tsize, |
286 | TVMEMSIZE); | 296 | TVMEMSIZE); |
@@ -288,112 +298,113 @@ test_cipher(char * algo, int mode, int enc, struct cipher_testvec * template, un | |||
288 | } | 298 | } |
289 | 299 | ||
290 | memcpy(tvmem, template, tsize); | 300 | memcpy(tvmem, template, tsize); |
291 | cipher_tv = (void *) tvmem; | 301 | cipher_tv = (void *)tvmem; |
302 | |||
303 | if (mode) | ||
304 | tfm = crypto_alloc_tfm(algo, 0); | ||
305 | else | ||
306 | tfm = crypto_alloc_tfm(algo, CRYPTO_TFM_MODE_CBC); | ||
292 | 307 | ||
293 | if (mode) | ||
294 | tfm = crypto_alloc_tfm (algo, 0); | ||
295 | else | ||
296 | tfm = crypto_alloc_tfm (algo, CRYPTO_TFM_MODE_CBC); | ||
297 | |||
298 | if (tfm == NULL) { | 308 | if (tfm == NULL) { |
299 | printk("failed to load transform for %s %s\n", algo, m); | 309 | printk("failed to load transform for %s %s\n", algo, m); |
300 | return; | 310 | return; |
301 | } | 311 | } |
302 | 312 | ||
303 | j = 0; | 313 | j = 0; |
304 | for (i = 0; i < tcount; i++) { | 314 | for (i = 0; i < tcount; i++) { |
305 | if (!(cipher_tv[i].np)) { | 315 | if (!(cipher_tv[i].np)) { |
306 | j++; | 316 | j++; |
307 | printk("test %u (%d bit key):\n", | 317 | printk("test %u (%d bit key):\n", |
308 | j, cipher_tv[i].klen * 8); | 318 | j, cipher_tv[i].klen * 8); |
309 | 319 | ||
310 | tfm->crt_flags = 0; | 320 | tfm->crt_flags = 0; |
311 | if (cipher_tv[i].wk) | 321 | if (cipher_tv[i].wk) |
312 | tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY; | 322 | tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY; |
313 | key = cipher_tv[i].key; | 323 | key = cipher_tv[i].key; |
314 | 324 | ||
315 | ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen); | 325 | ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen); |
316 | if (ret) { | 326 | if (ret) { |
317 | printk("setkey() failed flags=%x\n", tfm->crt_flags); | 327 | printk("setkey() failed flags=%x\n", tfm->crt_flags); |
318 | 328 | ||
319 | if (!cipher_tv[i].fail) | 329 | if (!cipher_tv[i].fail) |
320 | goto out; | 330 | goto out; |
321 | } | 331 | } |
322 | 332 | ||
323 | p = cipher_tv[i].input; | 333 | p = cipher_tv[i].input; |
324 | sg[0].page = virt_to_page(p); | 334 | sg[0].page = virt_to_page(p); |
325 | sg[0].offset = offset_in_page(p); | 335 | sg[0].offset = offset_in_page(p); |
326 | sg[0].length = cipher_tv[i].ilen; | 336 | sg[0].length = cipher_tv[i].ilen; |
327 | 337 | ||
328 | if (!mode) { | 338 | if (!mode) { |
329 | crypto_cipher_set_iv(tfm, cipher_tv[i].iv, | 339 | crypto_cipher_set_iv(tfm, cipher_tv[i].iv, |
330 | crypto_tfm_alg_ivsize (tfm)); | 340 | crypto_tfm_alg_ivsize(tfm)); |
331 | } | 341 | } |
332 | 342 | ||
333 | if (enc) | 343 | if (enc) |
334 | ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen); | 344 | ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen); |
335 | else | 345 | else |
336 | ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen); | 346 | ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen); |
337 | 347 | ||
338 | 348 | ||
339 | if (ret) { | 349 | if (ret) { |
340 | printk("%s () failed flags=%x\n", e, tfm->crt_flags); | 350 | printk("%s () failed flags=%x\n", e, tfm->crt_flags); |
341 | goto out; | 351 | goto out; |
342 | } | 352 | } |
343 | 353 | ||
344 | q = kmap(sg[0].page) + sg[0].offset; | 354 | q = kmap(sg[0].page) + sg[0].offset; |
345 | hexdump(q, cipher_tv[i].rlen); | 355 | hexdump(q, cipher_tv[i].rlen); |
346 | 356 | ||
347 | printk("%s\n", | 357 | printk("%s\n", |
348 | memcmp(q, cipher_tv[i].result, cipher_tv[i].rlen) ? "fail" : | 358 | memcmp(q, cipher_tv[i].result, |
349 | "pass"); | 359 | cipher_tv[i].rlen) ? "fail" : "pass"); |
350 | } | 360 | } |
351 | } | 361 | } |
352 | 362 | ||
353 | printk("\ntesting %s %s %s across pages (chunking) \n", algo, m, e); | 363 | printk("\ntesting %s %s %s across pages (chunking)\n", algo, m, e); |
354 | memset(xbuf, 0, XBUFSIZE); | 364 | memset(xbuf, 0, XBUFSIZE); |
355 | 365 | ||
356 | j = 0; | 366 | j = 0; |
357 | for (i = 0; i < tcount; i++) { | 367 | for (i = 0; i < tcount; i++) { |
358 | if (cipher_tv[i].np) { | 368 | if (cipher_tv[i].np) { |
359 | j++; | 369 | j++; |
360 | printk("test %u (%d bit key):\n", | 370 | printk("test %u (%d bit key):\n", |
361 | j, cipher_tv[i].klen * 8); | 371 | j, cipher_tv[i].klen * 8); |
362 | 372 | ||
363 | tfm->crt_flags = 0; | 373 | tfm->crt_flags = 0; |
364 | if (cipher_tv[i].wk) | 374 | if (cipher_tv[i].wk) |
365 | tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY; | 375 | tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY; |
366 | key = cipher_tv[i].key; | 376 | key = cipher_tv[i].key; |
367 | 377 | ||
368 | ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen); | 378 | ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen); |
369 | if (ret) { | 379 | if (ret) { |
370 | printk("setkey() failed flags=%x\n", tfm->crt_flags); | 380 | printk("setkey() failed flags=%x\n", tfm->crt_flags); |
371 | 381 | ||
372 | if (!cipher_tv[i].fail) | 382 | if (!cipher_tv[i].fail) |
373 | goto out; | 383 | goto out; |
374 | } | 384 | } |
375 | 385 | ||
376 | temp = 0; | 386 | temp = 0; |
377 | for (k = 0; k < cipher_tv[i].np; k++) { | 387 | for (k = 0; k < cipher_tv[i].np; k++) { |
378 | memcpy (&xbuf[IDX[k]], cipher_tv[i].input + temp, | 388 | memcpy(&xbuf[IDX[k]], |
379 | cipher_tv[i].tap[k]); | 389 | cipher_tv[i].input + temp, |
390 | cipher_tv[i].tap[k]); | ||
380 | temp += cipher_tv[i].tap[k]; | 391 | temp += cipher_tv[i].tap[k]; |
381 | p = &xbuf[IDX[k]]; | 392 | p = &xbuf[IDX[k]]; |
382 | sg[k].page = virt_to_page (p); | 393 | sg[k].page = virt_to_page(p); |
383 | sg[k].offset = offset_in_page (p); | 394 | sg[k].offset = offset_in_page(p); |
384 | sg[k].length = cipher_tv[i].tap[k]; | 395 | sg[k].length = cipher_tv[i].tap[k]; |
385 | } | 396 | } |
386 | 397 | ||
387 | if (!mode) { | 398 | if (!mode) { |
388 | crypto_cipher_set_iv(tfm, cipher_tv[i].iv, | 399 | crypto_cipher_set_iv(tfm, cipher_tv[i].iv, |
389 | crypto_tfm_alg_ivsize (tfm)); | 400 | crypto_tfm_alg_ivsize(tfm)); |
390 | } | 401 | } |
391 | 402 | ||
392 | if (enc) | 403 | if (enc) |
393 | ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen); | 404 | ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen); |
394 | else | 405 | else |
395 | ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen); | 406 | ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen); |
396 | 407 | ||
397 | if (ret) { | 408 | if (ret) { |
398 | printk("%s () failed flags=%x\n", e, tfm->crt_flags); | 409 | printk("%s () failed flags=%x\n", e, tfm->crt_flags); |
399 | goto out; | 410 | goto out; |
@@ -404,9 +415,9 @@ test_cipher(char * algo, int mode, int enc, struct cipher_testvec * template, un | |||
404 | printk("page %u\n", k); | 415 | printk("page %u\n", k); |
405 | q = kmap(sg[k].page) + sg[k].offset; | 416 | q = kmap(sg[k].page) + sg[k].offset; |
406 | hexdump(q, cipher_tv[i].tap[k]); | 417 | hexdump(q, cipher_tv[i].tap[k]); |
407 | printk("%s\n", | 418 | printk("%s\n", |
408 | memcmp(q, cipher_tv[i].result + temp, | 419 | memcmp(q, cipher_tv[i].result + temp, |
409 | cipher_tv[i].tap[k]) ? "fail" : | 420 | cipher_tv[i].tap[k]) ? "fail" : |
410 | "pass"); | 421 | "pass"); |
411 | temp += cipher_tv[i].tap[k]; | 422 | temp += cipher_tv[i].tap[k]; |
412 | } | 423 | } |
@@ -417,8 +428,169 @@ out: | |||
417 | crypto_free_tfm(tfm); | 428 | crypto_free_tfm(tfm); |
418 | } | 429 | } |
419 | 430 | ||
420 | static void | 431 | static int test_cipher_jiffies(struct crypto_tfm *tfm, int enc, char *p, |
421 | test_deflate(void) | 432 | int blen, int sec) |
433 | { | ||
434 | struct scatterlist sg[8]; | ||
435 | unsigned long start, end; | ||
436 | int bcount; | ||
437 | int ret; | ||
438 | |||
439 | sg[0].page = virt_to_page(p); | ||
440 | sg[0].offset = offset_in_page(p); | ||
441 | sg[0].length = blen; | ||
442 | |||
443 | for (start = jiffies, end = start + sec * HZ, bcount = 0; | ||
444 | time_before(jiffies, end); bcount++) { | ||
445 | if (enc) | ||
446 | ret = crypto_cipher_encrypt(tfm, sg, sg, blen); | ||
447 | else | ||
448 | ret = crypto_cipher_decrypt(tfm, sg, sg, blen); | ||
449 | |||
450 | if (ret) | ||
451 | return ret; | ||
452 | } | ||
453 | |||
454 | printk("%d operations in %d seconds (%ld bytes)\n", | ||
455 | bcount, sec, (long)bcount * blen); | ||
456 | return 0; | ||
457 | } | ||
458 | |||
459 | static int test_cipher_cycles(struct crypto_tfm *tfm, int enc, char *p, | ||
460 | int blen) | ||
461 | { | ||
462 | struct scatterlist sg[8]; | ||
463 | unsigned long cycles = 0; | ||
464 | int ret = 0; | ||
465 | int i; | ||
466 | |||
467 | sg[0].page = virt_to_page(p); | ||
468 | sg[0].offset = offset_in_page(p); | ||
469 | sg[0].length = blen; | ||
470 | |||
471 | local_bh_disable(); | ||
472 | local_irq_disable(); | ||
473 | |||
474 | /* Warm-up run. */ | ||
475 | for (i = 0; i < 4; i++) { | ||
476 | if (enc) | ||
477 | ret = crypto_cipher_encrypt(tfm, sg, sg, blen); | ||
478 | else | ||
479 | ret = crypto_cipher_decrypt(tfm, sg, sg, blen); | ||
480 | |||
481 | if (ret) | ||
482 | goto out; | ||
483 | } | ||
484 | |||
485 | /* The real thing. */ | ||
486 | for (i = 0; i < 8; i++) { | ||
487 | cycles_t start, end; | ||
488 | |||
489 | start = get_cycles(); | ||
490 | if (enc) | ||
491 | ret = crypto_cipher_encrypt(tfm, sg, sg, blen); | ||
492 | else | ||
493 | ret = crypto_cipher_decrypt(tfm, sg, sg, blen); | ||
494 | end = get_cycles(); | ||
495 | |||
496 | if (ret) | ||
497 | goto out; | ||
498 | |||
499 | cycles += end - start; | ||
500 | } | ||
501 | |||
502 | out: | ||
503 | local_irq_enable(); | ||
504 | local_bh_enable(); | ||
505 | |||
506 | if (ret == 0) | ||
507 | printk("1 operation in %lu cycles (%d bytes)\n", | ||
508 | (cycles + 4) / 8, blen); | ||
509 | |||
510 | return ret; | ||
511 | } | ||
512 | |||
513 | static void test_cipher_speed(char *algo, int mode, int enc, unsigned int sec, | ||
514 | struct cipher_testvec *template, | ||
515 | unsigned int tcount, struct cipher_speed *speed) | ||
516 | { | ||
517 | unsigned int ret, i, j, iv_len; | ||
518 | unsigned char *key, *p, iv[128]; | ||
519 | struct crypto_tfm *tfm; | ||
520 | const char *e, *m; | ||
521 | |||
522 | if (enc == ENCRYPT) | ||
523 | e = "encryption"; | ||
524 | else | ||
525 | e = "decryption"; | ||
526 | if (mode == MODE_ECB) | ||
527 | m = "ECB"; | ||
528 | else | ||
529 | m = "CBC"; | ||
530 | |||
531 | printk("\ntesting speed of %s %s %s\n", algo, m, e); | ||
532 | |||
533 | if (mode) | ||
534 | tfm = crypto_alloc_tfm(algo, 0); | ||
535 | else | ||
536 | tfm = crypto_alloc_tfm(algo, CRYPTO_TFM_MODE_CBC); | ||
537 | |||
538 | if (tfm == NULL) { | ||
539 | printk("failed to load transform for %s %s\n", algo, m); | ||
540 | return; | ||
541 | } | ||
542 | |||
543 | for (i = 0; speed[i].klen != 0; i++) { | ||
544 | if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) { | ||
545 | printk("template (%u) too big for tvmem (%u)\n", | ||
546 | speed[i].blen + speed[i].klen, TVMEMSIZE); | ||
547 | goto out; | ||
548 | } | ||
549 | |||
550 | printk("test %u (%d bit key, %d byte blocks): ", i, | ||
551 | speed[i].klen * 8, speed[i].blen); | ||
552 | |||
553 | memset(tvmem, 0xff, speed[i].klen + speed[i].blen); | ||
554 | |||
555 | /* set key, plain text and IV */ | ||
556 | key = (unsigned char *)tvmem; | ||
557 | for (j = 0; j < tcount; j++) { | ||
558 | if (template[j].klen == speed[i].klen) { | ||
559 | key = template[j].key; | ||
560 | break; | ||
561 | } | ||
562 | } | ||
563 | p = (unsigned char *)tvmem + speed[i].klen; | ||
564 | |||
565 | ret = crypto_cipher_setkey(tfm, key, speed[i].klen); | ||
566 | if (ret) { | ||
567 | printk("setkey() failed flags=%x\n", tfm->crt_flags); | ||
568 | goto out; | ||
569 | } | ||
570 | |||
571 | if (!mode) { | ||
572 | iv_len = crypto_tfm_alg_ivsize(tfm); | ||
573 | memset(&iv, 0xff, iv_len); | ||
574 | crypto_cipher_set_iv(tfm, iv, iv_len); | ||
575 | } | ||
576 | |||
577 | if (sec) | ||
578 | ret = test_cipher_jiffies(tfm, enc, p, speed[i].blen, | ||
579 | sec); | ||
580 | else | ||
581 | ret = test_cipher_cycles(tfm, enc, p, speed[i].blen); | ||
582 | |||
583 | if (ret) { | ||
584 | printk("%s() failed flags=%x\n", e, tfm->crt_flags); | ||
585 | break; | ||
586 | } | ||
587 | } | ||
588 | |||
589 | out: | ||
590 | crypto_free_tfm(tfm); | ||
591 | } | ||
592 | |||
593 | static void test_deflate(void) | ||
422 | { | 594 | { |
423 | unsigned int i; | 595 | unsigned int i; |
424 | char result[COMP_BUF_SIZE]; | 596 | char result[COMP_BUF_SIZE]; |
@@ -436,7 +608,7 @@ test_deflate(void) | |||
436 | } | 608 | } |
437 | 609 | ||
438 | memcpy(tvmem, deflate_comp_tv_template, tsize); | 610 | memcpy(tvmem, deflate_comp_tv_template, tsize); |
439 | tv = (void *) tvmem; | 611 | tv = (void *)tvmem; |
440 | 612 | ||
441 | tfm = crypto_alloc_tfm("deflate", 0); | 613 | tfm = crypto_alloc_tfm("deflate", 0); |
442 | if (tfm == NULL) { | 614 | if (tfm == NULL) { |
@@ -446,7 +618,7 @@ test_deflate(void) | |||
446 | 618 | ||
447 | for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) { | 619 | for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) { |
448 | int ilen, ret, dlen = COMP_BUF_SIZE; | 620 | int ilen, ret, dlen = COMP_BUF_SIZE; |
449 | 621 | ||
450 | printk("test %u:\n", i + 1); | 622 | printk("test %u:\n", i + 1); |
451 | memset(result, 0, sizeof (result)); | 623 | memset(result, 0, sizeof (result)); |
452 | 624 | ||
@@ -473,11 +645,11 @@ test_deflate(void) | |||
473 | } | 645 | } |
474 | 646 | ||
475 | memcpy(tvmem, deflate_decomp_tv_template, tsize); | 647 | memcpy(tvmem, deflate_decomp_tv_template, tsize); |
476 | tv = (void *) tvmem; | 648 | tv = (void *)tvmem; |
477 | 649 | ||
478 | for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) { | 650 | for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) { |
479 | int ilen, ret, dlen = COMP_BUF_SIZE; | 651 | int ilen, ret, dlen = COMP_BUF_SIZE; |
480 | 652 | ||
481 | printk("test %u:\n", i + 1); | 653 | printk("test %u:\n", i + 1); |
482 | memset(result, 0, sizeof (result)); | 654 | memset(result, 0, sizeof (result)); |
483 | 655 | ||
@@ -497,8 +669,7 @@ out: | |||
497 | crypto_free_tfm(tfm); | 669 | crypto_free_tfm(tfm); |
498 | } | 670 | } |
499 | 671 | ||
500 | static void | 672 | static void test_crc32c(void) |
501 | test_crc32c(void) | ||
502 | { | 673 | { |
503 | #define NUMVEC 6 | 674 | #define NUMVEC 6 |
504 | #define VECSIZE 40 | 675 | #define VECSIZE 40 |
@@ -511,7 +682,7 @@ test_crc32c(void) | |||
511 | 0xd579c862, 0xba979ad0, 0x2b29d913 | 682 | 0xd579c862, 0xba979ad0, 0x2b29d913 |
512 | }; | 683 | }; |
513 | static u32 tot_vec_results = 0x24c5d375; | 684 | static u32 tot_vec_results = 0x24c5d375; |
514 | 685 | ||
515 | struct scatterlist sg[NUMVEC]; | 686 | struct scatterlist sg[NUMVEC]; |
516 | struct crypto_tfm *tfm; | 687 | struct crypto_tfm *tfm; |
517 | char *fmtdata = "testing crc32c initialized to %08x: %s\n"; | 688 | char *fmtdata = "testing crc32c initialized to %08x: %s\n"; |
@@ -525,18 +696,18 @@ test_crc32c(void) | |||
525 | printk("failed to load transform for crc32c\n"); | 696 | printk("failed to load transform for crc32c\n"); |
526 | return; | 697 | return; |
527 | } | 698 | } |
528 | 699 | ||
529 | crypto_digest_init(tfm); | 700 | crypto_digest_init(tfm); |
530 | crypto_digest_final(tfm, (u8*)&crc); | 701 | crypto_digest_final(tfm, (u8*)&crc); |
531 | printk(fmtdata, crc, (crc == 0) ? "pass" : "ERROR"); | 702 | printk(fmtdata, crc, (crc == 0) ? "pass" : "ERROR"); |
532 | 703 | ||
533 | /* | 704 | /* |
534 | * stuff test_vec with known values, simple incrementing | 705 | * stuff test_vec with known values, simple incrementing |
535 | * byte values. | 706 | * byte values. |
536 | */ | 707 | */ |
537 | b = 0; | 708 | b = 0; |
538 | for (i = 0; i < NUMVEC; i++) { | 709 | for (i = 0; i < NUMVEC; i++) { |
539 | for (j = 0; j < VECSIZE; j++) | 710 | for (j = 0; j < VECSIZE; j++) |
540 | test_vec[i][j] = ++b; | 711 | test_vec[i][j] = ++b; |
541 | sg[i].page = virt_to_page(test_vec[i]); | 712 | sg[i].page = virt_to_page(test_vec[i]); |
542 | sg[i].offset = offset_in_page(test_vec[i]); | 713 | sg[i].offset = offset_in_page(test_vec[i]); |
@@ -548,11 +719,11 @@ test_crc32c(void) | |||
548 | crypto_digest_final(tfm, (u8*)&crc); | 719 | crypto_digest_final(tfm, (u8*)&crc); |
549 | printk("testing crc32c setkey returns %08x : %s\n", crc, (crc == (SEEDTESTVAL ^ ~(u32)0)) ? | 720 | printk("testing crc32c setkey returns %08x : %s\n", crc, (crc == (SEEDTESTVAL ^ ~(u32)0)) ? |
550 | "pass" : "ERROR"); | 721 | "pass" : "ERROR"); |
551 | 722 | ||
552 | printk("testing crc32c using update/final:\n"); | 723 | printk("testing crc32c using update/final:\n"); |
553 | 724 | ||
554 | pass = 1; /* assume all is well */ | 725 | pass = 1; /* assume all is well */ |
555 | 726 | ||
556 | for (i = 0; i < NUMVEC; i++) { | 727 | for (i = 0; i < NUMVEC; i++) { |
557 | seed = ~(u32)0; | 728 | seed = ~(u32)0; |
558 | (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32)); | 729 | (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32)); |
@@ -591,66 +762,64 @@ test_crc32c(void) | |||
591 | printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results); | 762 | printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results); |
592 | pass = 0; | 763 | pass = 0; |
593 | } | 764 | } |
594 | 765 | ||
595 | printk("\n%s\n", pass ? "pass" : "ERROR"); | 766 | printk("\n%s\n", pass ? "pass" : "ERROR"); |
596 | 767 | ||
597 | crypto_free_tfm(tfm); | 768 | crypto_free_tfm(tfm); |
598 | printk("crc32c test complete\n"); | 769 | printk("crc32c test complete\n"); |
599 | } | 770 | } |
600 | 771 | ||
601 | static void | 772 | static void test_available(void) |
602 | test_available(void) | ||
603 | { | 773 | { |
604 | char **name = check; | 774 | char **name = check; |
605 | 775 | ||
606 | while (*name) { | 776 | while (*name) { |
607 | printk("alg %s ", *name); | 777 | printk("alg %s ", *name); |
608 | printk((crypto_alg_available(*name, 0)) ? | 778 | printk((crypto_alg_available(*name, 0)) ? |
609 | "found\n" : "not found\n"); | 779 | "found\n" : "not found\n"); |
610 | name++; | 780 | name++; |
611 | } | 781 | } |
612 | } | 782 | } |
613 | 783 | ||
614 | static void | 784 | static void do_test(void) |
615 | do_test(void) | ||
616 | { | 785 | { |
617 | switch (mode) { | 786 | switch (mode) { |
618 | 787 | ||
619 | case 0: | 788 | case 0: |
620 | test_hash("md5", md5_tv_template, MD5_TEST_VECTORS); | 789 | test_hash("md5", md5_tv_template, MD5_TEST_VECTORS); |
621 | 790 | ||
622 | test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS); | 791 | test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS); |
623 | 792 | ||
624 | //DES | 793 | //DES |
625 | test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS); | 794 | test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS); |
626 | test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS); | 795 | test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS); |
627 | test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS); | 796 | test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS); |
628 | test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS); | 797 | test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS); |
629 | 798 | ||
630 | //DES3_EDE | 799 | //DES3_EDE |
631 | test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS); | 800 | test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS); |
632 | test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS); | 801 | test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS); |
633 | 802 | ||
634 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); | 803 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); |
635 | 804 | ||
636 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); | 805 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); |
637 | 806 | ||
638 | //BLOWFISH | 807 | //BLOWFISH |
639 | test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS); | 808 | test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS); |
640 | test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS); | 809 | test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS); |
641 | test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS); | 810 | test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS); |
642 | test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS); | 811 | test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS); |
643 | 812 | ||
644 | //TWOFISH | 813 | //TWOFISH |
645 | test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS); | 814 | test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS); |
646 | test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS); | 815 | test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS); |
647 | test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS); | 816 | test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS); |
648 | test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS); | 817 | test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS); |
649 | 818 | ||
650 | //SERPENT | 819 | //SERPENT |
651 | test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS); | 820 | test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS); |
652 | test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS); | 821 | test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS); |
653 | 822 | ||
654 | //TNEPRES | 823 | //TNEPRES |
655 | test_cipher ("tnepres", MODE_ECB, ENCRYPT, tnepres_enc_tv_template, TNEPRES_ENC_TEST_VECTORS); | 824 | test_cipher ("tnepres", MODE_ECB, ENCRYPT, tnepres_enc_tv_template, TNEPRES_ENC_TEST_VECTORS); |
656 | test_cipher ("tnepres", MODE_ECB, DECRYPT, tnepres_dec_tv_template, TNEPRES_DEC_TEST_VECTORS); | 825 | test_cipher ("tnepres", MODE_ECB, DECRYPT, tnepres_dec_tv_template, TNEPRES_DEC_TEST_VECTORS); |
@@ -662,7 +831,7 @@ do_test(void) | |||
662 | //CAST5 | 831 | //CAST5 |
663 | test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS); | 832 | test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS); |
664 | test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS); | 833 | test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS); |
665 | 834 | ||
666 | //CAST6 | 835 | //CAST6 |
667 | test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS); | 836 | test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS); |
668 | test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS); | 837 | test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS); |
@@ -702,9 +871,9 @@ do_test(void) | |||
702 | test_crc32c(); | 871 | test_crc32c(); |
703 | #ifdef CONFIG_CRYPTO_HMAC | 872 | #ifdef CONFIG_CRYPTO_HMAC |
704 | test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS); | 873 | test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS); |
705 | test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS); | 874 | test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS); |
706 | test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS); | 875 | test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS); |
707 | #endif | 876 | #endif |
708 | 877 | ||
709 | test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS); | 878 | test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS); |
710 | break; | 879 | break; |
@@ -726,17 +895,17 @@ do_test(void) | |||
726 | 895 | ||
727 | case 4: | 896 | case 4: |
728 | test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS); | 897 | test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS); |
729 | test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS); | 898 | test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS); |
730 | break; | 899 | break; |
731 | 900 | ||
732 | case 5: | 901 | case 5: |
733 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); | 902 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); |
734 | break; | 903 | break; |
735 | 904 | ||
736 | case 6: | 905 | case 6: |
737 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); | 906 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); |
738 | break; | 907 | break; |
739 | 908 | ||
740 | case 7: | 909 | case 7: |
741 | test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS); | 910 | test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS); |
742 | test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS); | 911 | test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS); |
@@ -750,7 +919,7 @@ do_test(void) | |||
750 | test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS); | 919 | test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS); |
751 | test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS); | 920 | test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS); |
752 | break; | 921 | break; |
753 | 922 | ||
754 | case 9: | 923 | case 9: |
755 | test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS); | 924 | test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS); |
756 | test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS); | 925 | test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS); |
@@ -758,13 +927,13 @@ do_test(void) | |||
758 | 927 | ||
759 | case 10: | 928 | case 10: |
760 | test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS); | 929 | test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS); |
761 | test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS); | 930 | test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS); |
762 | break; | 931 | break; |
763 | 932 | ||
764 | case 11: | 933 | case 11: |
765 | test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS); | 934 | test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS); |
766 | break; | 935 | break; |
767 | 936 | ||
768 | case 12: | 937 | case 12: |
769 | test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS); | 938 | test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS); |
770 | break; | 939 | break; |
@@ -852,21 +1021,84 @@ do_test(void) | |||
852 | case 100: | 1021 | case 100: |
853 | test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS); | 1022 | test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS); |
854 | break; | 1023 | break; |
855 | 1024 | ||
856 | case 101: | 1025 | case 101: |
857 | test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS); | 1026 | test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS); |
858 | break; | 1027 | break; |
859 | 1028 | ||
860 | case 102: | 1029 | case 102: |
861 | test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS); | 1030 | test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS); |
862 | break; | 1031 | break; |
863 | 1032 | ||
864 | #endif | 1033 | #endif |
865 | 1034 | ||
1035 | case 200: | ||
1036 | test_cipher_speed("aes", MODE_ECB, ENCRYPT, sec, NULL, 0, | ||
1037 | aes_speed_template); | ||
1038 | test_cipher_speed("aes", MODE_ECB, DECRYPT, sec, NULL, 0, | ||
1039 | aes_speed_template); | ||
1040 | test_cipher_speed("aes", MODE_CBC, ENCRYPT, sec, NULL, 0, | ||
1041 | aes_speed_template); | ||
1042 | test_cipher_speed("aes", MODE_CBC, DECRYPT, sec, NULL, 0, | ||
1043 | aes_speed_template); | ||
1044 | break; | ||
1045 | |||
1046 | case 201: | ||
1047 | test_cipher_speed("des3_ede", MODE_ECB, ENCRYPT, sec, | ||
1048 | des3_ede_enc_tv_template, | ||
1049 | DES3_EDE_ENC_TEST_VECTORS, | ||
1050 | des3_ede_speed_template); | ||
1051 | test_cipher_speed("des3_ede", MODE_ECB, DECRYPT, sec, | ||
1052 | des3_ede_dec_tv_template, | ||
1053 | DES3_EDE_DEC_TEST_VECTORS, | ||
1054 | des3_ede_speed_template); | ||
1055 | test_cipher_speed("des3_ede", MODE_CBC, ENCRYPT, sec, | ||
1056 | des3_ede_enc_tv_template, | ||
1057 | DES3_EDE_ENC_TEST_VECTORS, | ||
1058 | des3_ede_speed_template); | ||
1059 | test_cipher_speed("des3_ede", MODE_CBC, DECRYPT, sec, | ||
1060 | des3_ede_dec_tv_template, | ||
1061 | DES3_EDE_DEC_TEST_VECTORS, | ||
1062 | des3_ede_speed_template); | ||
1063 | break; | ||
1064 | |||
1065 | case 202: | ||
1066 | test_cipher_speed("twofish", MODE_ECB, ENCRYPT, sec, NULL, 0, | ||
1067 | twofish_speed_template); | ||
1068 | test_cipher_speed("twofish", MODE_ECB, DECRYPT, sec, NULL, 0, | ||
1069 | twofish_speed_template); | ||
1070 | test_cipher_speed("twofish", MODE_CBC, ENCRYPT, sec, NULL, 0, | ||
1071 | twofish_speed_template); | ||
1072 | test_cipher_speed("twofish", MODE_CBC, DECRYPT, sec, NULL, 0, | ||
1073 | twofish_speed_template); | ||
1074 | break; | ||
1075 | |||
1076 | case 203: | ||
1077 | test_cipher_speed("blowfish", MODE_ECB, ENCRYPT, sec, NULL, 0, | ||
1078 | blowfish_speed_template); | ||
1079 | test_cipher_speed("blowfish", MODE_ECB, DECRYPT, sec, NULL, 0, | ||
1080 | blowfish_speed_template); | ||
1081 | test_cipher_speed("blowfish", MODE_CBC, ENCRYPT, sec, NULL, 0, | ||
1082 | blowfish_speed_template); | ||
1083 | test_cipher_speed("blowfish", MODE_CBC, DECRYPT, sec, NULL, 0, | ||
1084 | blowfish_speed_template); | ||
1085 | break; | ||
1086 | |||
1087 | case 204: | ||
1088 | test_cipher_speed("des", MODE_ECB, ENCRYPT, sec, NULL, 0, | ||
1089 | des_speed_template); | ||
1090 | test_cipher_speed("des", MODE_ECB, DECRYPT, sec, NULL, 0, | ||
1091 | des_speed_template); | ||
1092 | test_cipher_speed("des", MODE_CBC, ENCRYPT, sec, NULL, 0, | ||
1093 | des_speed_template); | ||
1094 | test_cipher_speed("des", MODE_CBC, DECRYPT, sec, NULL, 0, | ||
1095 | des_speed_template); | ||
1096 | break; | ||
1097 | |||
866 | case 1000: | 1098 | case 1000: |
867 | test_available(); | 1099 | test_available(); |
868 | break; | 1100 | break; |
869 | 1101 | ||
870 | default: | 1102 | default: |
871 | /* useful for debugging */ | 1103 | /* useful for debugging */ |
872 | printk("not testing anything\n"); | 1104 | printk("not testing anything\n"); |
@@ -874,8 +1106,7 @@ do_test(void) | |||
874 | } | 1106 | } |
875 | } | 1107 | } |
876 | 1108 | ||
877 | static int __init | 1109 | static int __init init(void) |
878 | init(void) | ||
879 | { | 1110 | { |
880 | tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL); | 1111 | tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL); |
881 | if (tvmem == NULL) | 1112 | if (tvmem == NULL) |
@@ -904,6 +1135,9 @@ module_init(init); | |||
904 | module_exit(fini); | 1135 | module_exit(fini); |
905 | 1136 | ||
906 | module_param(mode, int, 0); | 1137 | module_param(mode, int, 0); |
1138 | module_param(sec, uint, 0); | ||
1139 | MODULE_PARM_DESC(sec, "Length in seconds of speed tests " | ||
1140 | "(defaults to zero which uses CPU cycles instead)"); | ||
907 | 1141 | ||
908 | MODULE_LICENSE("GPL"); | 1142 | MODULE_LICENSE("GPL"); |
909 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); | 1143 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); |