blob: 5a95b4a14c2bdba0e01fb491688cd5e9be74db6d [file] [log] [blame]
Herbert Xuef2736f2005-06-22 13:26:03 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Quick & dirty crypto testing module.
3 *
4 * This will only exist until we have a better testing mechanism
5 * (e.g. a char device).
6 *
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
9 *
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
Herbert Xuef2736f2005-06-22 13:26:03 -070012 * Software Foundation; either version 2 of the License, or (at your option)
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * any later version.
14 *
15 * 14 - 09 - 2003
16 * Rewritten by Kartikey Mahendra Bhatt
17 */
18
19#include <linux/init.h>
20#include <linux/module.h>
21#include <linux/mm.h>
22#include <linux/slab.h>
23#include <asm/scatterlist.h>
24#include <linux/string.h>
25#include <linux/crypto.h>
26#include <linux/highmem.h>
27#include <linux/moduleparam.h>
28#include "tcrypt.h"
29
30/*
31 * Need to kmalloc() memory for testing kmap().
32 */
33#define TVMEMSIZE 4096
34#define XBUFSIZE 32768
35
36/*
37 * Indexes into the xbuf to simulate cross-page access.
38 */
39#define IDX1 37
40#define IDX2 32400
41#define IDX3 1
42#define IDX4 8193
43#define IDX5 22222
44#define IDX6 17101
45#define IDX7 27333
46#define IDX8 3000
47
48/*
49* Used by test_cipher()
50*/
51#define ENCRYPT 1
52#define DECRYPT 0
53#define MODE_ECB 1
54#define MODE_CBC 0
55
56static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
57
58static int mode;
59static char *xbuf;
60static char *tvmem;
61
62static char *check[] = {
63 "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish",
Herbert Xuef2736f2005-06-22 13:26:03 -070064 "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
65 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 "khazad", "wp512", "wp384", "wp256", "tnepres", NULL
67};
68
Herbert Xuef2736f2005-06-22 13:26:03 -070069static void hexdump(unsigned char *buf, unsigned int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
71 while (len--)
72 printk("%02x", *buf++);
73
74 printk("\n");
75}
76
Herbert Xuef2736f2005-06-22 13:26:03 -070077static void test_hash(char *algo, struct hash_testvec *template,
78 unsigned int tcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
Herbert Xuef2736f2005-06-22 13:26:03 -070080 char *p;
81 unsigned int i, j, k, temp;
82 struct scatterlist sg[8];
83 char result[64];
84 struct crypto_tfm *tfm;
85 struct hash_testvec *hash_tv;
86 unsigned int tsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Herbert Xuef2736f2005-06-22 13:26:03 -070088 printk("\ntesting %s\n", algo);
89
90 tsize = sizeof(struct hash_testvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 tsize *= tcount;
Herbert Xuef2736f2005-06-22 13:26:03 -070092
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 if (tsize > TVMEMSIZE) {
94 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
95 return;
96 }
97
98 memcpy(tvmem, template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -070099 hash_tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 tfm = crypto_alloc_tfm(algo, 0);
101 if (tfm == NULL) {
102 printk("failed to load transform for %s\n", algo);
103 return;
104 }
105
106 for (i = 0; i < tcount; i++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700107 printk("test %u:\n", i + 1);
108 memset(result, 0, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 p = hash_tv[i].plaintext;
Herbert Xuef2736f2005-06-22 13:26:03 -0700111 sg[0].page = virt_to_page(p);
112 sg[0].offset = offset_in_page(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 sg[0].length = hash_tv[i].psize;
114
Herbert Xuef2736f2005-06-22 13:26:03 -0700115 crypto_digest_init(tfm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 if (tfm->crt_u.digest.dit_setkey) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700117 crypto_digest_setkey(tfm, hash_tv[i].key,
118 hash_tv[i].ksize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700120 crypto_digest_update(tfm, sg, 1);
121 crypto_digest_final(tfm, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Herbert Xuef2736f2005-06-22 13:26:03 -0700123 hexdump(result, crypto_tfm_alg_digestsize(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 printk("%s\n",
Herbert Xuef2736f2005-06-22 13:26:03 -0700125 memcmp(result, hash_tv[i].digest,
126 crypto_tfm_alg_digestsize(tfm)) ?
127 "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 }
129
Herbert Xuef2736f2005-06-22 13:26:03 -0700130 printk("testing %s across pages\n", algo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 /* setup the dummy buffer first */
Herbert Xuef2736f2005-06-22 13:26:03 -0700133 memset(xbuf, 0, XBUFSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 j = 0;
136 for (i = 0; i < tcount; i++) {
137 if (hash_tv[i].np) {
138 j++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700139 printk("test %u:\n", j);
140 memset(result, 0, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142 temp = 0;
143 for (k = 0; k < hash_tv[i].np; k++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700144 memcpy(&xbuf[IDX[k]],
145 hash_tv[i].plaintext + temp,
146 hash_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 temp += hash_tv[i].tap[k];
148 p = &xbuf[IDX[k]];
Herbert Xuef2736f2005-06-22 13:26:03 -0700149 sg[k].page = virt_to_page(p);
150 sg[k].offset = offset_in_page(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 sg[k].length = hash_tv[i].tap[k];
152 }
153
Herbert Xuef2736f2005-06-22 13:26:03 -0700154 crypto_digest_digest(tfm, sg, hash_tv[i].np, result);
155
156 hexdump(result, crypto_tfm_alg_digestsize(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 printk("%s\n",
Herbert Xuef2736f2005-06-22 13:26:03 -0700158 memcmp(result, hash_tv[i].digest,
159 crypto_tfm_alg_digestsize(tfm)) ?
160 "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
162 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700163
164 crypto_free_tfm(tfm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165}
166
167
168#ifdef CONFIG_CRYPTO_HMAC
169
Herbert Xuef2736f2005-06-22 13:26:03 -0700170static void test_hmac(char *algo, struct hmac_testvec *template,
171 unsigned int tcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
173 char *p;
174 unsigned int i, j, k, temp;
175 struct scatterlist sg[8];
176 char result[64];
177 struct crypto_tfm *tfm;
178 struct hmac_testvec *hmac_tv;
179 unsigned int tsize, klen;
180
181 tfm = crypto_alloc_tfm(algo, 0);
182 if (tfm == NULL) {
183 printk("failed to load transform for %s\n", algo);
184 return;
185 }
186
187 printk("\ntesting hmac_%s\n", algo);
Herbert Xuef2736f2005-06-22 13:26:03 -0700188
189 tsize = sizeof(struct hmac_testvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 tsize *= tcount;
191 if (tsize > TVMEMSIZE) {
192 printk("template (%u) too big for tvmem (%u)\n", tsize,
193 TVMEMSIZE);
194 goto out;
195 }
196
197 memcpy(tvmem, template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700198 hmac_tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 for (i = 0; i < tcount; i++) {
201 printk("test %u:\n", i + 1);
202 memset(result, 0, sizeof (result));
203
204 p = hmac_tv[i].plaintext;
205 klen = hmac_tv[i].ksize;
206 sg[0].page = virt_to_page(p);
207 sg[0].offset = offset_in_page(p);
208 sg[0].length = hmac_tv[i].psize;
209
210 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, 1, result);
211
212 hexdump(result, crypto_tfm_alg_digestsize(tfm));
213 printk("%s\n",
214 memcmp(result, hmac_tv[i].digest,
215 crypto_tfm_alg_digestsize(tfm)) ? "fail" :
216 "pass");
217 }
218
219 printk("\ntesting hmac_%s across pages\n", algo);
220
221 memset(xbuf, 0, XBUFSIZE);
Herbert Xuef2736f2005-06-22 13:26:03 -0700222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 j = 0;
224 for (i = 0; i < tcount; i++) {
225 if (hmac_tv[i].np) {
226 j++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700227 printk("test %u:\n",j);
228 memset(result, 0, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230 temp = 0;
231 klen = hmac_tv[i].ksize;
232 for (k = 0; k < hmac_tv[i].np; k++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700233 memcpy(&xbuf[IDX[k]],
234 hmac_tv[i].plaintext + temp,
235 hmac_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 temp += hmac_tv[i].tap[k];
237 p = &xbuf[IDX[k]];
Herbert Xuef2736f2005-06-22 13:26:03 -0700238 sg[k].page = virt_to_page(p);
239 sg[k].offset = offset_in_page(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 sg[k].length = hmac_tv[i].tap[k];
241 }
242
Herbert Xuef2736f2005-06-22 13:26:03 -0700243 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg,
244 hmac_tv[i].np, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 hexdump(result, crypto_tfm_alg_digestsize(tfm));
Herbert Xuef2736f2005-06-22 13:26:03 -0700246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 printk("%s\n",
Herbert Xuef2736f2005-06-22 13:26:03 -0700248 memcmp(result, hmac_tv[i].digest,
249 crypto_tfm_alg_digestsize(tfm)) ?
250 "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 }
252 }
253out:
254 crypto_free_tfm(tfm);
255}
256
257#endif /* CONFIG_CRYPTO_HMAC */
258
Herbert Xuef2736f2005-06-22 13:26:03 -0700259static void test_cipher(char *algo, int mode, int enc,
260 struct cipher_testvec *template, unsigned int tcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
262 unsigned int ret, i, j, k, temp;
263 unsigned int tsize;
264 char *p, *q;
265 struct crypto_tfm *tfm;
266 char *key;
267 struct cipher_testvec *cipher_tv;
268 struct scatterlist sg[8];
269 char e[11], m[4];
270
271 if (enc == ENCRYPT)
272 strncpy(e, "encryption", 11);
273 else
Herbert Xuef2736f2005-06-22 13:26:03 -0700274 strncpy(e, "decryption", 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 if (mode == MODE_ECB)
Herbert Xuef2736f2005-06-22 13:26:03 -0700276 strncpy(m, "ECB", 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 else
Herbert Xuef2736f2005-06-22 13:26:03 -0700278 strncpy(m, "CBC", 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Herbert Xuef2736f2005-06-22 13:26:03 -0700280 printk("\ntesting %s %s %s\n", algo, m, e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Herbert Xuef2736f2005-06-22 13:26:03 -0700282 tsize = sizeof (struct cipher_testvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 tsize *= tcount;
Herbert Xuef2736f2005-06-22 13:26:03 -0700284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 if (tsize > TVMEMSIZE) {
286 printk("template (%u) too big for tvmem (%u)\n", tsize,
287 TVMEMSIZE);
288 return;
289 }
290
291 memcpy(tvmem, template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700292 cipher_tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Herbert Xuef2736f2005-06-22 13:26:03 -0700294 if (mode)
295 tfm = crypto_alloc_tfm(algo, 0);
296 else
297 tfm = crypto_alloc_tfm(algo, CRYPTO_TFM_MODE_CBC);
298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 if (tfm == NULL) {
300 printk("failed to load transform for %s %s\n", algo, m);
301 return;
302 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 j = 0;
305 for (i = 0; i < tcount; i++) {
306 if (!(cipher_tv[i].np)) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700307 j++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 printk("test %u (%d bit key):\n",
309 j, cipher_tv[i].klen * 8);
310
311 tfm->crt_flags = 0;
Herbert Xuef2736f2005-06-22 13:26:03 -0700312 if (cipher_tv[i].wk)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY;
314 key = cipher_tv[i].key;
Herbert Xuef2736f2005-06-22 13:26:03 -0700315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen);
317 if (ret) {
318 printk("setkey() failed flags=%x\n", tfm->crt_flags);
Herbert Xuef2736f2005-06-22 13:26:03 -0700319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 if (!cipher_tv[i].fail)
321 goto out;
Herbert Xuef2736f2005-06-22 13:26:03 -0700322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 p = cipher_tv[i].input;
325 sg[0].page = virt_to_page(p);
326 sg[0].offset = offset_in_page(p);
327 sg[0].length = cipher_tv[i].ilen;
Herbert Xuef2736f2005-06-22 13:26:03 -0700328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 if (!mode) {
330 crypto_cipher_set_iv(tfm, cipher_tv[i].iv,
Herbert Xuef2736f2005-06-22 13:26:03 -0700331 crypto_tfm_alg_ivsize(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 if (enc)
335 ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen);
336 else
337 ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen);
Herbert Xuef2736f2005-06-22 13:26:03 -0700338
339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 if (ret) {
341 printk("%s () failed flags=%x\n", e, tfm->crt_flags);
342 goto out;
Herbert Xuef2736f2005-06-22 13:26:03 -0700343 }
344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 q = kmap(sg[0].page) + sg[0].offset;
346 hexdump(q, cipher_tv[i].rlen);
Herbert Xuef2736f2005-06-22 13:26:03 -0700347
348 printk("%s\n",
349 memcmp(q, cipher_tv[i].result,
350 cipher_tv[i].rlen) ? "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 }
352 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700353
354 printk("\ntesting %s %s %s across pages (chunking)\n", algo, m, e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 memset(xbuf, 0, XBUFSIZE);
Herbert Xuef2736f2005-06-22 13:26:03 -0700356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 j = 0;
358 for (i = 0; i < tcount; i++) {
359 if (cipher_tv[i].np) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700360 j++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 printk("test %u (%d bit key):\n",
362 j, cipher_tv[i].klen * 8);
363
Herbert Xuef2736f2005-06-22 13:26:03 -0700364 tfm->crt_flags = 0;
365 if (cipher_tv[i].wk)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY;
367 key = cipher_tv[i].key;
Herbert Xuef2736f2005-06-22 13:26:03 -0700368
369 ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 if (ret) {
371 printk("setkey() failed flags=%x\n", tfm->crt_flags);
Herbert Xuef2736f2005-06-22 13:26:03 -0700372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 if (!cipher_tv[i].fail)
374 goto out;
375 }
376
377 temp = 0;
378 for (k = 0; k < cipher_tv[i].np; k++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700379 memcpy(&xbuf[IDX[k]],
380 cipher_tv[i].input + temp,
381 cipher_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 temp += cipher_tv[i].tap[k];
383 p = &xbuf[IDX[k]];
Herbert Xuef2736f2005-06-22 13:26:03 -0700384 sg[k].page = virt_to_page(p);
385 sg[k].offset = offset_in_page(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 sg[k].length = cipher_tv[i].tap[k];
387 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 if (!mode) {
390 crypto_cipher_set_iv(tfm, cipher_tv[i].iv,
Herbert Xuef2736f2005-06-22 13:26:03 -0700391 crypto_tfm_alg_ivsize(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 if (enc)
395 ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen);
396 else
397 ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen);
Herbert Xuef2736f2005-06-22 13:26:03 -0700398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 if (ret) {
400 printk("%s () failed flags=%x\n", e, tfm->crt_flags);
401 goto out;
402 }
403
404 temp = 0;
405 for (k = 0; k < cipher_tv[i].np; k++) {
406 printk("page %u\n", k);
407 q = kmap(sg[k].page) + sg[k].offset;
408 hexdump(q, cipher_tv[i].tap[k]);
Herbert Xuef2736f2005-06-22 13:26:03 -0700409 printk("%s\n",
410 memcmp(q, cipher_tv[i].result + temp,
411 cipher_tv[i].tap[k]) ? "fail" :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 "pass");
413 temp += cipher_tv[i].tap[k];
414 }
415 }
416 }
417
418out:
419 crypto_free_tfm(tfm);
420}
421
Herbert Xuef2736f2005-06-22 13:26:03 -0700422static void test_deflate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
424 unsigned int i;
425 char result[COMP_BUF_SIZE];
426 struct crypto_tfm *tfm;
427 struct comp_testvec *tv;
428 unsigned int tsize;
429
430 printk("\ntesting deflate compression\n");
431
432 tsize = sizeof (deflate_comp_tv_template);
433 if (tsize > TVMEMSIZE) {
434 printk("template (%u) too big for tvmem (%u)\n", tsize,
435 TVMEMSIZE);
436 return;
437 }
438
439 memcpy(tvmem, deflate_comp_tv_template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700440 tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
442 tfm = crypto_alloc_tfm("deflate", 0);
443 if (tfm == NULL) {
444 printk("failed to load transform for deflate\n");
445 return;
446 }
447
448 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
449 int ilen, ret, dlen = COMP_BUF_SIZE;
Herbert Xuef2736f2005-06-22 13:26:03 -0700450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 printk("test %u:\n", i + 1);
452 memset(result, 0, sizeof (result));
453
454 ilen = tv[i].inlen;
455 ret = crypto_comp_compress(tfm, tv[i].input,
456 ilen, result, &dlen);
457 if (ret) {
458 printk("fail: ret=%d\n", ret);
459 continue;
460 }
461 hexdump(result, dlen);
462 printk("%s (ratio %d:%d)\n",
463 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
464 ilen, dlen);
465 }
466
467 printk("\ntesting deflate decompression\n");
468
469 tsize = sizeof (deflate_decomp_tv_template);
470 if (tsize > TVMEMSIZE) {
471 printk("template (%u) too big for tvmem (%u)\n", tsize,
472 TVMEMSIZE);
473 goto out;
474 }
475
476 memcpy(tvmem, deflate_decomp_tv_template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700477 tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
479 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
480 int ilen, ret, dlen = COMP_BUF_SIZE;
Herbert Xuef2736f2005-06-22 13:26:03 -0700481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 printk("test %u:\n", i + 1);
483 memset(result, 0, sizeof (result));
484
485 ilen = tv[i].inlen;
486 ret = crypto_comp_decompress(tfm, tv[i].input,
487 ilen, result, &dlen);
488 if (ret) {
489 printk("fail: ret=%d\n", ret);
490 continue;
491 }
492 hexdump(result, dlen);
493 printk("%s (ratio %d:%d)\n",
494 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
495 ilen, dlen);
496 }
497out:
498 crypto_free_tfm(tfm);
499}
500
Herbert Xuef2736f2005-06-22 13:26:03 -0700501static void test_crc32c(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502{
503#define NUMVEC 6
504#define VECSIZE 40
505
506 int i, j, pass;
507 u32 crc;
508 u8 b, test_vec[NUMVEC][VECSIZE];
509 static u32 vec_results[NUMVEC] = {
510 0x0e2c157f, 0xe980ebf6, 0xde74bded,
511 0xd579c862, 0xba979ad0, 0x2b29d913
512 };
513 static u32 tot_vec_results = 0x24c5d375;
Herbert Xuef2736f2005-06-22 13:26:03 -0700514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 struct scatterlist sg[NUMVEC];
516 struct crypto_tfm *tfm;
517 char *fmtdata = "testing crc32c initialized to %08x: %s\n";
518#define SEEDTESTVAL 0xedcba987
519 u32 seed;
520
521 printk("\ntesting crc32c\n");
522
523 tfm = crypto_alloc_tfm("crc32c", 0);
524 if (tfm == NULL) {
525 printk("failed to load transform for crc32c\n");
526 return;
527 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700528
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 crypto_digest_init(tfm);
530 crypto_digest_final(tfm, (u8*)&crc);
531 printk(fmtdata, crc, (crc == 0) ? "pass" : "ERROR");
Herbert Xuef2736f2005-06-22 13:26:03 -0700532
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 /*
534 * stuff test_vec with known values, simple incrementing
535 * byte values.
536 */
537 b = 0;
538 for (i = 0; i < NUMVEC; i++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700539 for (j = 0; j < VECSIZE; j++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 test_vec[i][j] = ++b;
541 sg[i].page = virt_to_page(test_vec[i]);
542 sg[i].offset = offset_in_page(test_vec[i]);
543 sg[i].length = VECSIZE;
544 }
545
546 seed = SEEDTESTVAL;
547 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
548 crypto_digest_final(tfm, (u8*)&crc);
549 printk("testing crc32c setkey returns %08x : %s\n", crc, (crc == (SEEDTESTVAL ^ ~(u32)0)) ?
550 "pass" : "ERROR");
Herbert Xuef2736f2005-06-22 13:26:03 -0700551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 printk("testing crc32c using update/final:\n");
553
554 pass = 1; /* assume all is well */
Herbert Xuef2736f2005-06-22 13:26:03 -0700555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 for (i = 0; i < NUMVEC; i++) {
557 seed = ~(u32)0;
558 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
559 crypto_digest_update(tfm, &sg[i], 1);
560 crypto_digest_final(tfm, (u8*)&crc);
561 if (crc == vec_results[i]) {
562 printk(" %08x:OK", crc);
563 } else {
564 printk(" %08x:BAD, wanted %08x\n", crc, vec_results[i]);
565 pass = 0;
566 }
567 }
568
569 printk("\ntesting crc32c using incremental accumulator:\n");
570 crc = 0;
571 for (i = 0; i < NUMVEC; i++) {
572 seed = (crc ^ ~(u32)0);
573 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
574 crypto_digest_update(tfm, &sg[i], 1);
575 crypto_digest_final(tfm, (u8*)&crc);
576 }
577 if (crc == tot_vec_results) {
578 printk(" %08x:OK", crc);
579 } else {
580 printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results);
581 pass = 0;
582 }
583
584 printk("\ntesting crc32c using digest:\n");
585 seed = ~(u32)0;
586 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
587 crypto_digest_digest(tfm, sg, NUMVEC, (u8*)&crc);
588 if (crc == tot_vec_results) {
589 printk(" %08x:OK", crc);
590 } else {
591 printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results);
592 pass = 0;
593 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700594
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 printk("\n%s\n", pass ? "pass" : "ERROR");
596
597 crypto_free_tfm(tfm);
598 printk("crc32c test complete\n");
599}
600
Herbert Xuef2736f2005-06-22 13:26:03 -0700601static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
603 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -0700604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 while (*name) {
606 printk("alg %s ", *name);
607 printk((crypto_alg_available(*name, 0)) ?
608 "found\n" : "not found\n");
609 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700610 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611}
612
Herbert Xuef2736f2005-06-22 13:26:03 -0700613static void do_test(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614{
615 switch (mode) {
616
617 case 0:
618 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 //DES
623 test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700624 test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS);
625 test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS);
626 test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS);
627
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 //DES3_EDE
629 test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700630 test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS);
631
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 //BLOWFISH
637 test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS);
638 test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS);
639 test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS);
640 test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 //TWOFISH
643 test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS);
644 test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS);
645 test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS);
646 test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 //SERPENT
649 test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS);
650 test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 //TNEPRES
653 test_cipher ("tnepres", MODE_ECB, ENCRYPT, tnepres_enc_tv_template, TNEPRES_ENC_TEST_VECTORS);
654 test_cipher ("tnepres", MODE_ECB, DECRYPT, tnepres_dec_tv_template, TNEPRES_DEC_TEST_VECTORS);
655
656 //AES
657 test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS);
658 test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS);
659
660 //CAST5
661 test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS);
662 test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 //CAST6
665 test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS);
666 test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS);
667
668 //ARC4
669 test_cipher ("arc4", MODE_ECB, ENCRYPT, arc4_enc_tv_template, ARC4_ENC_TEST_VECTORS);
670 test_cipher ("arc4", MODE_ECB, DECRYPT, arc4_dec_tv_template, ARC4_DEC_TEST_VECTORS);
671
672 //TEA
673 test_cipher ("tea", MODE_ECB, ENCRYPT, tea_enc_tv_template, TEA_ENC_TEST_VECTORS);
674 test_cipher ("tea", MODE_ECB, DECRYPT, tea_dec_tv_template, TEA_DEC_TEST_VECTORS);
675
676
677 //XTEA
678 test_cipher ("xtea", MODE_ECB, ENCRYPT, xtea_enc_tv_template, XTEA_ENC_TEST_VECTORS);
679 test_cipher ("xtea", MODE_ECB, DECRYPT, xtea_dec_tv_template, XTEA_DEC_TEST_VECTORS);
680
681 //KHAZAD
682 test_cipher ("khazad", MODE_ECB, ENCRYPT, khazad_enc_tv_template, KHAZAD_ENC_TEST_VECTORS);
683 test_cipher ("khazad", MODE_ECB, DECRYPT, khazad_dec_tv_template, KHAZAD_DEC_TEST_VECTORS);
684
685 //ANUBIS
686 test_cipher ("anubis", MODE_ECB, ENCRYPT, anubis_enc_tv_template, ANUBIS_ENC_TEST_VECTORS);
687 test_cipher ("anubis", MODE_ECB, DECRYPT, anubis_dec_tv_template, ANUBIS_DEC_TEST_VECTORS);
688 test_cipher ("anubis", MODE_CBC, ENCRYPT, anubis_cbc_enc_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
689 test_cipher ("anubis", MODE_CBC, DECRYPT, anubis_cbc_dec_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
690
691 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
692 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
693 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
694 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
695 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
696 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
697 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
698 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
699 test_deflate();
700 test_crc32c();
701#ifdef CONFIG_CRYPTO_HMAC
702 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700703 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700705#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
707 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
708 break;
709
710 case 1:
711 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
712 break;
713
714 case 2:
715 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
716 break;
717
718 case 3:
719 test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS);
720 test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS);
721 test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS);
722 test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS);
723 break;
724
725 case 4:
726 test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700727 test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 break;
729
730 case 5:
731 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
732 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 case 6:
735 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
736 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700737
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 case 7:
739 test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS);
740 test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS);
741 test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS);
742 test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS);
743 break;
744
745 case 8:
746 test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS);
747 test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS);
748 test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS);
749 test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS);
750 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 case 9:
753 test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS);
754 test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS);
755 break;
756
757 case 10:
758 test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700759 test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 break;
761
762 case 11:
763 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
764 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700765
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 case 12:
767 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
768 break;
769
770 case 13:
771 test_deflate();
772 break;
773
774 case 14:
775 test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS);
776 test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS);
777 break;
778
779 case 15:
780 test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS);
781 test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS);
782 break;
783
784 case 16:
785 test_cipher ("arc4", MODE_ECB, ENCRYPT, arc4_enc_tv_template, ARC4_ENC_TEST_VECTORS);
786 test_cipher ("arc4", MODE_ECB, DECRYPT, arc4_dec_tv_template, ARC4_DEC_TEST_VECTORS);
787 break;
788
789 case 17:
790 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
791 break;
792
793 case 18:
794 test_crc32c();
795 break;
796
797 case 19:
798 test_cipher ("tea", MODE_ECB, ENCRYPT, tea_enc_tv_template, TEA_ENC_TEST_VECTORS);
799 test_cipher ("tea", MODE_ECB, DECRYPT, tea_dec_tv_template, TEA_DEC_TEST_VECTORS);
800 break;
801
802 case 20:
803 test_cipher ("xtea", MODE_ECB, ENCRYPT, xtea_enc_tv_template, XTEA_ENC_TEST_VECTORS);
804 test_cipher ("xtea", MODE_ECB, DECRYPT, xtea_dec_tv_template, XTEA_DEC_TEST_VECTORS);
805 break;
806
807 case 21:
808 test_cipher ("khazad", MODE_ECB, ENCRYPT, khazad_enc_tv_template, KHAZAD_ENC_TEST_VECTORS);
809 test_cipher ("khazad", MODE_ECB, DECRYPT, khazad_dec_tv_template, KHAZAD_DEC_TEST_VECTORS);
810 break;
811
812 case 22:
813 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
814 break;
815
816 case 23:
817 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
818 break;
819
820 case 24:
821 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
822 break;
823
824 case 25:
825 test_cipher ("tnepres", MODE_ECB, ENCRYPT, tnepres_enc_tv_template, TNEPRES_ENC_TEST_VECTORS);
826 test_cipher ("tnepres", MODE_ECB, DECRYPT, tnepres_dec_tv_template, TNEPRES_DEC_TEST_VECTORS);
827 break;
828
829 case 26:
830 test_cipher ("anubis", MODE_ECB, ENCRYPT, anubis_enc_tv_template, ANUBIS_ENC_TEST_VECTORS);
831 test_cipher ("anubis", MODE_ECB, DECRYPT, anubis_dec_tv_template, ANUBIS_DEC_TEST_VECTORS);
832 test_cipher ("anubis", MODE_CBC, ENCRYPT, anubis_cbc_enc_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
833 test_cipher ("anubis", MODE_CBC, DECRYPT, anubis_cbc_dec_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
834 break;
835
836 case 27:
837 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
838 break;
839
840 case 28:
841
842 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
843 break;
844
845 case 29:
846 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
847 break;
848
849#ifdef CONFIG_CRYPTO_HMAC
850 case 100:
851 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
852 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700853
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 case 101:
Herbert Xuef2736f2005-06-22 13:26:03 -0700855 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700857
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 case 102:
859 test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
860 break;
861
862#endif
863
864 case 1000:
865 test_available();
866 break;
Herbert Xuef2736f2005-06-22 13:26:03 -0700867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 default:
869 /* useful for debugging */
870 printk("not testing anything\n");
871 break;
872 }
873}
874
Herbert Xuef2736f2005-06-22 13:26:03 -0700875static int __init init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876{
877 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
878 if (tvmem == NULL)
879 return -ENOMEM;
880
881 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
882 if (xbuf == NULL) {
883 kfree(tvmem);
884 return -ENOMEM;
885 }
886
887 do_test();
888
889 kfree(xbuf);
890 kfree(tvmem);
891 return 0;
892}
893
894/*
895 * If an init function is provided, an exit function must also be provided
896 * to allow module unload.
897 */
898static void __exit fini(void) { }
899
900module_init(init);
901module_exit(fini);
902
903module_param(mode, int, 0);
904
905MODULE_LICENSE("GPL");
906MODULE_DESCRIPTION("Quick & dirty crypto testing module");
907MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");