OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [crypto/] [tcrypt.c] - Blame information for rev 1275

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * Quick & dirty crypto testing module.
3
 *
4
 * This will only exist until we have a better testing mechanism
5
 * (e.g. a char device).
6
 *
7
 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8
 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
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
12
 * Software Foundation; either version 2 of the License, or (at your option)
13
 * 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 "tcrypt.h"
28
 
29
#define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK)
30
 
31
/*
32
 * Need to kmalloc() memory for testing kmap().
33
 */
34
#define TVMEMSIZE       4096
35
#define XBUFSIZE        32768
36
 
37
/*
38
 * Indexes into the xbuf to simulate cross-page access.
39
 */
40
#define IDX1            37
41
#define IDX2            32400
42
#define IDX3            1
43
#define IDX4            8193
44
#define IDX5            22222
45
#define IDX6            17101
46
#define IDX7            27333
47
#define IDX8            3000
48
 
49
/*
50
* Used by test_cipher()
51
*/
52
#define ENCRYPT 1
53
#define DECRYPT 0
54
#define MODE_ECB 1
55
#define MODE_CBC 0
56
 
57
static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
58
 
59
static int mode;
60
static char *xbuf;
61
static char *tvmem;
62
 
63
static char *check[] = {
64
        "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish",
65
        "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
66
        "arc4", "deflate", NULL
67
};
68
 
69
static void
70
hexdump(unsigned char *buf, unsigned int len)
71
{
72
        while (len--)
73
                printk("%02x", *buf++);
74
 
75
        printk("\n");
76
}
77
 
78
static void
79
test_hash (char * algo, struct hash_testvec * template, unsigned int tcount)
80
{
81
        char *p;
82
        unsigned int i, j, k, temp;
83
        struct scatterlist sg[8];
84
        char result[64];
85
        struct crypto_tfm *tfm;
86
        struct hash_testvec *hash_tv;
87
        unsigned int tsize;
88
 
89
        printk("\ntesting %s\n", algo);
90
 
91
        tsize = sizeof (struct hash_testvec);
92
        tsize *= tcount;
93
 
94
        if (tsize > TVMEMSIZE) {
95
                printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
96
                return;
97
        }
98
 
99
        memcpy(tvmem, template, tsize);
100
        hash_tv = (void *) tvmem;
101
        tfm = crypto_alloc_tfm(algo, 0);
102
        if (tfm == NULL) {
103
                printk("failed to load transform for %s\n", algo);
104
                return;
105
        }
106
 
107
        for (i = 0; i < tcount; i++) {
108
                printk ("test %u:\n", i + 1);
109
                memset (result, 0, 64);
110
 
111
                p = hash_tv[i].plaintext;
112
                sg[0].page = virt_to_page (p);
113
                sg[0].offset = offset_in_page (p);
114
                sg[0].length = hash_tv[i].psize;
115
 
116
                crypto_digest_init (tfm);
117
                crypto_digest_update (tfm, sg, 1);
118
                crypto_digest_final (tfm, result);
119
 
120
                hexdump (result, crypto_tfm_alg_digestsize (tfm));
121
                printk("%s\n",
122
                        memcmp(result, hash_tv[i].digest,
123
                                crypto_tfm_alg_digestsize(tfm)) ? "fail" :
124
                        "pass");
125
        }
126
 
127
        printk ("testing %s across pages\n", algo);
128
 
129
        /* setup the dummy buffer first */
130
        memset(xbuf, 0, XBUFSIZE);
131
 
132
        j = 0;
133
        for (i = 0; i < tcount; i++) {
134
                if (hash_tv[i].np) {
135
                        j++;
136
                        printk ("test %u:\n", j);
137
                        memset (result, 0, 64);
138
 
139
                        temp = 0;
140
                        for (k = 0; k < hash_tv[i].np; k++) {
141
                                memcpy (&xbuf[IDX[k]], hash_tv[i].plaintext + temp,
142
                                                hash_tv[i].tap[k]);
143
                                temp += hash_tv[i].tap[k];
144
                                p = &xbuf[IDX[k]];
145
                                sg[k].page = virt_to_page (p);
146
                                sg[k].offset = offset_in_page (p);
147
                                sg[k].length = hash_tv[i].tap[k];
148
                        }
149
 
150
                        crypto_digest_digest (tfm, sg, hash_tv[i].np, result);
151
 
152
                        hexdump (result, crypto_tfm_alg_digestsize (tfm));
153
                        printk("%s\n",
154
                                memcmp(result, hash_tv[i].digest,
155
                                        crypto_tfm_alg_digestsize(tfm)) ? "fail" :
156
                                "pass");
157
                }
158
        }
159
 
160
        crypto_free_tfm (tfm);
161
}
162
 
163
 
164
#ifdef CONFIG_CRYPTO_HMAC
165
 
166
static void
167
test_hmac(char *algo, struct hmac_testvec * template, unsigned int tcount)
168
{
169
        char *p;
170
        unsigned int i, j, k, temp;
171
        struct scatterlist sg[8];
172
        char result[64];
173
        struct crypto_tfm *tfm;
174
        struct hmac_testvec *hmac_tv;
175
        unsigned int tsize, klen;
176
 
177
        tfm = crypto_alloc_tfm(algo, 0);
178
        if (tfm == NULL) {
179
                printk("failed to load transform for %s\n", algo);
180
                return;
181
        }
182
 
183
        printk("\ntesting hmac_%s\n", algo);
184
 
185
        tsize = sizeof (struct hmac_testvec);
186
        tsize *= tcount;
187
        if (tsize > TVMEMSIZE) {
188
                printk("template (%u) too big for tvmem (%u)\n", tsize,
189
                       TVMEMSIZE);
190
                goto out;
191
        }
192
 
193
        memcpy(tvmem, template, tsize);
194
        hmac_tv = (void *) tvmem;
195
 
196
        for (i = 0; i < tcount; i++) {
197
                printk("test %u:\n", i + 1);
198
                memset(result, 0, sizeof (result));
199
 
200
                p = hmac_tv[i].plaintext;
201
                klen = hmac_tv[i].ksize;
202
                sg[0].page = virt_to_page(p);
203
                sg[0].offset = offset_in_page(p);
204
                sg[0].length = hmac_tv[i].psize;
205
 
206
                crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, 1, result);
207
 
208
                hexdump(result, crypto_tfm_alg_digestsize(tfm));
209
                printk("%s\n",
210
                       memcmp(result, hmac_tv[i].digest,
211
                              crypto_tfm_alg_digestsize(tfm)) ? "fail" :
212
                       "pass");
213
        }
214
 
215
        printk("\ntesting hmac_%s across pages\n", algo);
216
 
217
        memset(xbuf, 0, XBUFSIZE);
218
 
219
        j = 0;
220
        for (i = 0; i < tcount; i++) {
221
                if (hmac_tv[i].np) {
222
                        j++;
223
                        printk ("test %u:\n",j);
224
                        memset (result, 0, 64);
225
 
226
                        temp = 0;
227
                        klen = hmac_tv[i].ksize;
228
                        for (k = 0; k < hmac_tv[i].np; k++) {
229
                                memcpy (&xbuf[IDX[k]], hmac_tv[i].plaintext + temp,
230
                                                hmac_tv[i].tap[k]);
231
                                temp += hmac_tv[i].tap[k];
232
                                p = &xbuf[IDX[k]];
233
                                sg[k].page = virt_to_page (p);
234
                                sg[k].offset = offset_in_page (p);
235
                                sg[k].length = hmac_tv[i].tap[k];
236
                        }
237
 
238
                        crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, hmac_tv[i].np,
239
                                        result);
240
                        hexdump(result, crypto_tfm_alg_digestsize(tfm));
241
 
242
                        printk("%s\n",
243
                                memcmp(result, hmac_tv[i].digest,
244
                                        crypto_tfm_alg_digestsize(tfm)) ? "fail" :
245
                                "pass");
246
                }
247
        }
248
out:
249
        crypto_free_tfm(tfm);
250
}
251
 
252
#endif  /* CONFIG_CRYPTO_HMAC */
253
 
254
void
255
test_cipher(char * algo, int mode, int enc, struct cipher_testvec * template, unsigned int tcount)
256
{
257
        unsigned int ret, i, j, k, temp;
258
        unsigned int tsize;
259
        char *p, *q;
260
        struct crypto_tfm *tfm;
261
        char *key;
262
        struct cipher_testvec *cipher_tv;
263
        struct scatterlist sg[8];
264
        char e[11], m[4];
265
 
266
        if (enc == ENCRYPT)
267
                strncpy(e, "encryption", 11);
268
        else
269
                strncpy(e, "decryption", 11);
270
        if (mode == MODE_ECB)
271
                strncpy(m, "ECB", 4);
272
        else
273
                strncpy(m, "CBC", 4);
274
 
275
        printk("\ntesting %s %s %s \n", algo, m, e);
276
 
277
        tsize = sizeof (struct cipher_testvec);
278
        tsize *= tcount;
279
 
280
        if (tsize > TVMEMSIZE) {
281
                printk("template (%u) too big for tvmem (%u)\n", tsize,
282
                       TVMEMSIZE);
283
                return;
284
        }
285
 
286
        memcpy(tvmem, template, tsize);
287
        cipher_tv = (void *) tvmem;
288
 
289
        if (mode)
290
                tfm = crypto_alloc_tfm (algo, 0);
291
        else
292
                tfm = crypto_alloc_tfm (algo, CRYPTO_TFM_MODE_CBC);
293
 
294
        if (tfm == NULL) {
295
                printk("failed to load transform for %s %s\n", algo, m);
296
                return;
297
        }
298
 
299
        j = 0;
300
        for (i = 0; i < tcount; i++) {
301
                if (!(cipher_tv[i].np)) {
302
                        j++;
303
                        printk("test %u (%d bit key):\n",
304
                        j, cipher_tv[i].klen * 8);
305
 
306
                        tfm->crt_flags = 0;
307
                        if (cipher_tv[i].wk)
308
                                tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY;
309
                        key = cipher_tv[i].key;
310
 
311
                        ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen);
312
                        if (ret) {
313
                                printk("setkey() failed flags=%x\n", tfm->crt_flags);
314
 
315
                                if (!cipher_tv[i].fail)
316
                                        goto out;
317
                        }
318
 
319
                        p = cipher_tv[i].input;
320
                        sg[0].page = virt_to_page(p);
321
                        sg[0].offset = offset_in_page(p);
322
                        sg[0].length = cipher_tv[i].ilen;
323
 
324
                        if (!mode) {
325
                                crypto_cipher_set_iv(tfm, cipher_tv[i].iv,
326
                                        crypto_tfm_alg_ivsize (tfm));
327
                        }
328
 
329
                        if (enc)
330
                                ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen);
331
                        else
332
                                ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen);
333
 
334
 
335
                        if (ret) {
336
                                printk("%s () failed flags=%x\n", e, tfm->crt_flags);
337
                                goto out;
338
                        }
339
 
340
                        q = kmap(sg[0].page) + sg[0].offset;
341
                        hexdump(q, cipher_tv[i].rlen);
342
 
343
                        printk("%s\n",
344
                                memcmp(q, cipher_tv[i].result, cipher_tv[i].rlen) ? "fail" :
345
                        "pass");
346
                }
347
        }
348
 
349
        printk("\ntesting %s %s %s across pages (chunking) \n", algo, m, e);
350
        memset(xbuf, 0, XBUFSIZE);
351
 
352
        j = 0;
353
        for (i = 0; i < tcount; i++) {
354
                if (cipher_tv[i].np) {
355
                        j++;
356
                        printk("test %u (%d bit key):\n",
357
                        j, cipher_tv[i].klen * 8);
358
 
359
                        tfm->crt_flags = 0;
360
                        if (cipher_tv[i].wk)
361
                                tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY;
362
                        key = cipher_tv[i].key;
363
 
364
                        ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen);
365
                        if (ret) {
366
                                printk("setkey() failed flags=%x\n", tfm->crt_flags);
367
 
368
                                if (!cipher_tv[i].fail)
369
                                        goto out;
370
                        }
371
 
372
                        temp = 0;
373
                        for (k = 0; k < cipher_tv[i].np; k++) {
374
                                memcpy (&xbuf[IDX[k]], cipher_tv[i].input + temp,
375
                                                cipher_tv[i].tap[k]);
376
                                temp += cipher_tv[i].tap[k];
377
                                p = &xbuf[IDX[k]];
378
                                sg[k].page = virt_to_page (p);
379
                                sg[k].offset = offset_in_page (p);
380
                                sg[k].length = cipher_tv[i].tap[k];
381
                        }
382
 
383
                        if (!mode) {
384
                                crypto_cipher_set_iv(tfm, cipher_tv[i].iv,
385
                                                crypto_tfm_alg_ivsize (tfm));
386
                        }
387
 
388
                        if (enc)
389
                                ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen);
390
                        else
391
                                ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen);
392
 
393
                        if (ret) {
394
                                printk("%s () failed flags=%x\n", e, tfm->crt_flags);
395
                                goto out;
396
                        }
397
 
398
                        temp = 0;
399
                        for (k = 0; k < cipher_tv[i].np; k++) {
400
                                printk("page %u\n", k);
401
                                q = kmap(sg[k].page) + sg[k].offset;
402
                                hexdump(q, cipher_tv[i].tap[k]);
403
                                printk("%s\n",
404
                                        memcmp(q, cipher_tv[i].result + temp,
405
                                                cipher_tv[i].tap[k]) ? "fail" :
406
                                        "pass");
407
                                temp += cipher_tv[i].tap[k];
408
                        }
409
                }
410
        }
411
 
412
out:
413
        crypto_free_tfm(tfm);
414
}
415
 
416
static void
417
test_deflate(void)
418
{
419
        unsigned int i;
420
        char result[COMP_BUF_SIZE];
421
        struct crypto_tfm *tfm;
422
        struct comp_testvec *tv;
423
        unsigned int tsize;
424
 
425
        printk("\ntesting deflate compression\n");
426
 
427
        tsize = sizeof (deflate_comp_tv_template);
428
        if (tsize > TVMEMSIZE) {
429
                printk("template (%u) too big for tvmem (%u)\n", tsize,
430
                       TVMEMSIZE);
431
                return;
432
        }
433
 
434
        memcpy(tvmem, deflate_comp_tv_template, tsize);
435
        tv = (void *) tvmem;
436
 
437
        tfm = crypto_alloc_tfm("deflate", 0);
438
        if (tfm == NULL) {
439
                printk("failed to load transform for deflate\n");
440
                return;
441
        }
442
 
443
        for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
444
                int ilen, ret, dlen = COMP_BUF_SIZE;
445
 
446
                printk("test %u:\n", i + 1);
447
                memset(result, 0, sizeof (result));
448
 
449
                ilen = tv[i].inlen;
450
                ret = crypto_comp_compress(tfm, tv[i].input,
451
                                           ilen, result, &dlen);
452
                if (ret) {
453
                        printk("fail: ret=%d\n", ret);
454
                        continue;
455
                }
456
                hexdump(result, dlen);
457
                printk("%s (ratio %d:%d)\n",
458
                       memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
459
                       ilen, dlen);
460
        }
461
 
462
        printk("\ntesting deflate decompression\n");
463
 
464
        tsize = sizeof (deflate_decomp_tv_template);
465
        if (tsize > TVMEMSIZE) {
466
                printk("template (%u) too big for tvmem (%u)\n", tsize,
467
                       TVMEMSIZE);
468
                goto out;
469
        }
470
 
471
        memcpy(tvmem, deflate_decomp_tv_template, tsize);
472
        tv = (void *) tvmem;
473
 
474
        for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
475
                int ilen, ret, dlen = COMP_BUF_SIZE;
476
 
477
                printk("test %u:\n", i + 1);
478
                memset(result, 0, sizeof (result));
479
 
480
                ilen = tv[i].inlen;
481
                ret = crypto_comp_decompress(tfm, tv[i].input,
482
                                             ilen, result, &dlen);
483
                if (ret) {
484
                        printk("fail: ret=%d\n", ret);
485
                        continue;
486
                }
487
                hexdump(result, dlen);
488
                printk("%s (ratio %d:%d)\n",
489
                       memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
490
                       ilen, dlen);
491
        }
492
out:
493
        crypto_free_tfm(tfm);
494
}
495
 
496
static void
497
test_available(void)
498
{
499
        char **name = check;
500
 
501
        while (*name) {
502
                printk("alg %s ", *name);
503
                printk((crypto_alg_available(*name, 0)) ?
504
                        "found\n" : "not found\n");
505
                name++;
506
        }
507
}
508
 
509
static void
510
do_test(void)
511
{
512
        switch (mode) {
513
 
514
        case 0:
515
                test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
516
 
517
                test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
518
 
519
                //DES
520
                test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS);
521
                test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS);
522
                test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS);
523
                test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS);
524
 
525
                //DES3_EDE
526
                test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS);
527
                test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS);
528
 
529
                test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
530
 
531
                test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
532
 
533
                //BLOWFISH
534
                test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS);
535
                test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS);
536
                test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS);
537
                test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS);
538
 
539
                //TWOFISH
540
                test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS);
541
                test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS);
542
                test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS);
543
                test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS);
544
 
545
                //SERPENT
546
                test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS);
547
                test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS);
548
 
549
                //AES
550
                test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS);
551
                test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS);
552
 
553
                //CAST5
554
                test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS);
555
                test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS);
556
 
557
                //CAST6
558
                test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS);
559
                test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS);
560
 
561
                //ARC4
562
                test_cipher ("arc4", MODE_ECB, ENCRYPT, arc4_enc_tv_template, ARC4_ENC_TEST_VECTORS);
563
                test_cipher ("arc4", MODE_ECB, DECRYPT, arc4_dec_tv_template, ARC4_DEC_TEST_VECTORS);
564
 
565
                test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
566
                test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
567
                test_deflate();
568
#ifdef CONFIG_CRYPTO_HMAC
569
                test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
570
                test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
571
                test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
572
#endif          
573
                break;
574
 
575
        case 1:
576
                test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
577
                break;
578
 
579
        case 2:
580
                test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
581
                break;
582
 
583
        case 3:
584
                test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS);
585
                test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS);
586
                test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS);
587
                test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS);
588
                break;
589
 
590
        case 4:
591
                test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS);
592
                test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS);
593
                break;
594
 
595
        case 5:
596
                test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
597
                break;
598
 
599
        case 6:
600
                test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
601
                break;
602
 
603
        case 7:
604
                test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS);
605
                test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS);
606
                test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS);
607
                test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS);
608
                break;
609
 
610
        case 8:
611
                test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS);
612
                test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS);
613
                test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS);
614
                test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS);
615
                break;
616
 
617
        case 9:
618
                break;
619
 
620
        case 10:
621
                test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS);
622
                test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS);
623
                break;
624
 
625
        case 11:
626
                test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
627
                break;
628
 
629
        case 12:
630
                test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
631
                break;
632
 
633
        case 13:
634
                test_deflate();
635
                break;
636
 
637
        case 14:
638
                test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS);
639
                test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS);
640
                break;
641
 
642
        case 15:
643
                test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS);
644
                test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS);
645
                break;
646
 
647
        case 16:
648
                test_cipher ("arc4", MODE_ECB, ENCRYPT, arc4_enc_tv_template, ARC4_ENC_TEST_VECTORS);
649
                test_cipher ("arc4", MODE_ECB, DECRYPT, arc4_dec_tv_template, ARC4_DEC_TEST_VECTORS);
650
                break;
651
 
652
#ifdef CONFIG_CRYPTO_HMAC
653
        case 100:
654
                test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
655
                break;
656
 
657
        case 101:
658
                test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
659
                break;
660
 
661
        case 102:
662
                test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
663
                break;
664
 
665
#endif
666
 
667
        case 1000:
668
                test_available();
669
                break;
670
 
671
        default:
672
                /* useful for debugging */
673
                printk("not testing anything\n");
674
                break;
675
        }
676
}
677
 
678
static int __init
679
init(void)
680
{
681
        tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
682
        if (tvmem == NULL)
683
                return -ENOMEM;
684
 
685
        xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
686
        if (xbuf == NULL) {
687
                kfree(tvmem);
688
                return -ENOMEM;
689
        }
690
 
691
        do_test();
692
 
693
        kfree(xbuf);
694
        kfree(tvmem);
695
        return 0;
696
}
697
 
698
/*
699
 * If an init function is provided, an exit function must also be provided
700
 * to allow module unload.
701
 */
702
static void __exit fini(void) { }
703
 
704
module_init(init);
705
module_exit(fini);
706
 
707
MODULE_PARM(mode, "i");
708
 
709
MODULE_LICENSE("GPL");
710
MODULE_DESCRIPTION("Quick & dirty crypto testing module");
711
MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.