blob: 24141fb6f5cba0639ae25ccca4d42a79bcd4d032 [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 *
Andrew Donofrioa28091a2006-12-10 12:10:20 +110015 * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests
Harald Welteebfd9bc2005-06-22 13:27:23 -070016 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
17 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
18 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 */
20
Herbert Xucba83562006-08-13 08:26:09 +100021#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/mm.h>
25#include <linux/slab.h>
David Hardeman378f0582005-09-17 17:55:31 +100026#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/string.h>
28#include <linux/crypto.h>
29#include <linux/highmem.h>
30#include <linux/moduleparam.h>
Harald Welteebfd9bc2005-06-22 13:27:23 -070031#include <linux/jiffies.h>
Herbert Xu6a179442005-06-22 13:29:03 -070032#include <linux/timex.h>
33#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "tcrypt.h"
35
36/*
37 * Need to kmalloc() memory for testing kmap().
38 */
Harald Welteebfd9bc2005-06-22 13:27:23 -070039#define TVMEMSIZE 16384
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#define XBUFSIZE 32768
41
42/*
43 * Indexes into the xbuf to simulate cross-page access.
44 */
45#define IDX1 37
46#define IDX2 32400
47#define IDX3 1
48#define IDX4 8193
49#define IDX5 22222
50#define IDX6 17101
51#define IDX7 27333
52#define IDX8 3000
53
54/*
55* Used by test_cipher()
56*/
57#define ENCRYPT 1
58#define DECRYPT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Herbert Xu6158efc2007-04-04 17:41:07 +100060struct tcrypt_result {
61 struct completion completion;
62 int err;
63};
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
66
Harald Welteebfd9bc2005-06-22 13:27:23 -070067/*
68 * Used by test_cipher_speed()
69 */
Herbert Xu6a179442005-06-22 13:29:03 -070070static unsigned int sec;
Harald Welteebfd9bc2005-06-22 13:27:23 -070071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072static int mode;
73static char *xbuf;
74static char *tvmem;
75
76static char *check[] = {
77 "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish",
Herbert Xuef2736f2005-06-22 13:26:03 -070078 "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
79 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
David Howells90831632006-12-16 12:13:14 +110080 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
Hye-Shik Change2ee95b2007-08-21 20:01:03 +080081 "camellia", "seed", NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070082};
83
Herbert Xuef2736f2005-06-22 13:26:03 -070084static void hexdump(unsigned char *buf, unsigned int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
86 while (len--)
87 printk("%02x", *buf++);
88
89 printk("\n");
90}
91
Herbert Xu6158efc2007-04-04 17:41:07 +100092static void tcrypt_complete(struct crypto_async_request *req, int err)
93{
94 struct tcrypt_result *res = req->data;
95
96 if (err == -EINPROGRESS)
97 return;
98
99 res->err = err;
100 complete(&res->completion);
101}
102
Herbert Xuef2736f2005-06-22 13:26:03 -0700103static void test_hash(char *algo, struct hash_testvec *template,
104 unsigned int tcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Herbert Xuef2736f2005-06-22 13:26:03 -0700106 unsigned int i, j, k, temp;
107 struct scatterlist sg[8];
108 char result[64];
Herbert Xue9d41162006-08-19 21:38:49 +1000109 struct crypto_hash *tfm;
110 struct hash_desc desc;
Herbert Xuef2736f2005-06-22 13:26:03 -0700111 struct hash_testvec *hash_tv;
112 unsigned int tsize;
Herbert Xue9d41162006-08-19 21:38:49 +1000113 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Herbert Xuef2736f2005-06-22 13:26:03 -0700115 printk("\ntesting %s\n", algo);
116
117 tsize = sizeof(struct hash_testvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 tsize *= tcount;
Herbert Xuef2736f2005-06-22 13:26:03 -0700119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 if (tsize > TVMEMSIZE) {
121 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
122 return;
123 }
124
125 memcpy(tvmem, template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700126 hash_tv = (void *)tvmem;
Herbert Xue9d41162006-08-19 21:38:49 +1000127
128 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
129 if (IS_ERR(tfm)) {
130 printk("failed to load transform for %s: %ld\n", algo,
131 PTR_ERR(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 return;
133 }
134
Herbert Xue9d41162006-08-19 21:38:49 +1000135 desc.tfm = tfm;
136 desc.flags = 0;
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 for (i = 0; i < tcount; i++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700139 printk("test %u:\n", i + 1);
140 memset(result, 0, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
David S. Millerb7335882007-10-26 00:38:10 -0700142 sg_init_one(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Herbert Xue9d41162006-08-19 21:38:49 +1000144 if (hash_tv[i].ksize) {
145 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
146 hash_tv[i].ksize);
147 if (ret) {
148 printk("setkey() failed ret=%d\n", ret);
149 goto out;
150 }
151 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Herbert Xue9d41162006-08-19 21:38:49 +1000153 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, result);
154 if (ret) {
155 printk("digest () failed ret=%d\n", ret);
156 goto out;
157 }
158
159 hexdump(result, crypto_hash_digestsize(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 printk("%s\n",
Herbert Xuef2736f2005-06-22 13:26:03 -0700161 memcmp(result, hash_tv[i].digest,
Herbert Xue9d41162006-08-19 21:38:49 +1000162 crypto_hash_digestsize(tfm)) ?
Herbert Xuef2736f2005-06-22 13:26:03 -0700163 "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 }
165
Herbert Xuef2736f2005-06-22 13:26:03 -0700166 printk("testing %s across pages\n", algo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 /* setup the dummy buffer first */
Herbert Xuef2736f2005-06-22 13:26:03 -0700169 memset(xbuf, 0, XBUFSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 j = 0;
172 for (i = 0; i < tcount; i++) {
173 if (hash_tv[i].np) {
174 j++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700175 printk("test %u:\n", j);
176 memset(result, 0, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178 temp = 0;
David S. Millerb7335882007-10-26 00:38:10 -0700179 sg_init_table(sg, hash_tv[i].np);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 for (k = 0; k < hash_tv[i].np; k++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700181 memcpy(&xbuf[IDX[k]],
182 hash_tv[i].plaintext + temp,
183 hash_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 temp += hash_tv[i].tap[k];
David Hardeman378f0582005-09-17 17:55:31 +1000185 sg_set_buf(&sg[k], &xbuf[IDX[k]],
186 hash_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
188
Herbert Xue9d41162006-08-19 21:38:49 +1000189 if (hash_tv[i].ksize) {
190 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
191 hash_tv[i].ksize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700192
Herbert Xue9d41162006-08-19 21:38:49 +1000193 if (ret) {
194 printk("setkey() failed ret=%d\n", ret);
195 goto out;
196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 }
198
Herbert Xue9d41162006-08-19 21:38:49 +1000199 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize,
200 result);
201 if (ret) {
202 printk("digest () failed ret=%d\n", ret);
203 goto out;
204 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700205
Herbert Xue9d41162006-08-19 21:38:49 +1000206 hexdump(result, crypto_hash_digestsize(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 printk("%s\n",
Herbert Xue9d41162006-08-19 21:38:49 +1000208 memcmp(result, hash_tv[i].digest,
209 crypto_hash_digestsize(tfm)) ?
Herbert Xuef2736f2005-06-22 13:26:03 -0700210 "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 }
212 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Herbert Xue9d41162006-08-19 21:38:49 +1000214out:
215 crypto_free_hash(tfm);
216}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Herbert Xucba83562006-08-13 08:26:09 +1000218static void test_cipher(char *algo, int enc,
Herbert Xuef2736f2005-06-22 13:26:03 -0700219 struct cipher_testvec *template, unsigned int tcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
221 unsigned int ret, i, j, k, temp;
222 unsigned int tsize;
David Hardeman378f0582005-09-17 17:55:31 +1000223 char *q;
Herbert Xu6158efc2007-04-04 17:41:07 +1000224 struct crypto_ablkcipher *tfm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 char *key;
226 struct cipher_testvec *cipher_tv;
Herbert Xu6158efc2007-04-04 17:41:07 +1000227 struct ablkcipher_request *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 struct scatterlist sg[8];
Herbert Xucba83562006-08-13 08:26:09 +1000229 const char *e;
Herbert Xu6158efc2007-04-04 17:41:07 +1000230 struct tcrypt_result result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 if (enc == ENCRYPT)
Herbert Xu3cc38162005-06-22 13:26:36 -0700233 e = "encryption";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 else
Herbert Xu3cc38162005-06-22 13:26:36 -0700235 e = "decryption";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Herbert Xucba83562006-08-13 08:26:09 +1000237 printk("\ntesting %s %s\n", algo, e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Herbert Xuef2736f2005-06-22 13:26:03 -0700239 tsize = sizeof (struct cipher_testvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 tsize *= tcount;
Herbert Xuef2736f2005-06-22 13:26:03 -0700241
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 if (tsize > TVMEMSIZE) {
243 printk("template (%u) too big for tvmem (%u)\n", tsize,
244 TVMEMSIZE);
245 return;
246 }
247
248 memcpy(tvmem, template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700249 cipher_tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Herbert Xu6158efc2007-04-04 17:41:07 +1000251 init_completion(&result.completion);
252
253 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
Herbert Xuef2736f2005-06-22 13:26:03 -0700254
Herbert Xucba83562006-08-13 08:26:09 +1000255 if (IS_ERR(tfm)) {
256 printk("failed to load transform for %s: %ld\n", algo,
257 PTR_ERR(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 return;
259 }
Herbert Xu6158efc2007-04-04 17:41:07 +1000260
261 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
262 if (!req) {
263 printk("failed to allocate request for %s\n", algo);
264 goto out;
265 }
266
267 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
268 tcrypt_complete, &result);
Herbert Xuef2736f2005-06-22 13:26:03 -0700269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 j = 0;
271 for (i = 0; i < tcount; i++) {
272 if (!(cipher_tv[i].np)) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700273 j++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 printk("test %u (%d bit key):\n",
275 j, cipher_tv[i].klen * 8);
276
Herbert Xu6158efc2007-04-04 17:41:07 +1000277 crypto_ablkcipher_clear_flags(tfm, ~0);
Herbert Xuef2736f2005-06-22 13:26:03 -0700278 if (cipher_tv[i].wk)
Herbert Xu6158efc2007-04-04 17:41:07 +1000279 crypto_ablkcipher_set_flags(
Herbert Xucba83562006-08-13 08:26:09 +1000280 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 key = cipher_tv[i].key;
Herbert Xuef2736f2005-06-22 13:26:03 -0700282
Herbert Xu6158efc2007-04-04 17:41:07 +1000283 ret = crypto_ablkcipher_setkey(tfm, key,
284 cipher_tv[i].klen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000286 printk("setkey() failed flags=%x\n",
Herbert Xu6158efc2007-04-04 17:41:07 +1000287 crypto_ablkcipher_get_flags(tfm));
Herbert Xuef2736f2005-06-22 13:26:03 -0700288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 if (!cipher_tv[i].fail)
290 goto out;
Herbert Xuef2736f2005-06-22 13:26:03 -0700291 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
David S. Millerb7335882007-10-26 00:38:10 -0700293 sg_init_one(&sg[0], cipher_tv[i].input,
294 cipher_tv[i].ilen);
Herbert Xuef2736f2005-06-22 13:26:03 -0700295
Herbert Xu6158efc2007-04-04 17:41:07 +1000296 ablkcipher_request_set_crypt(req, sg, sg,
297 cipher_tv[i].ilen,
298 cipher_tv[i].iv);
Herbert Xuef2736f2005-06-22 13:26:03 -0700299
Herbert Xucba83562006-08-13 08:26:09 +1000300 ret = enc ?
Herbert Xu6158efc2007-04-04 17:41:07 +1000301 crypto_ablkcipher_encrypt(req) :
302 crypto_ablkcipher_decrypt(req);
Herbert Xuef2736f2005-06-22 13:26:03 -0700303
Herbert Xu6158efc2007-04-04 17:41:07 +1000304 switch (ret) {
305 case 0:
306 break;
307 case -EINPROGRESS:
308 case -EBUSY:
309 ret = wait_for_completion_interruptible(
310 &result.completion);
311 if (!ret && !((ret = result.err))) {
312 INIT_COMPLETION(result.completion);
313 break;
314 }
315 /* fall through */
316 default:
317 printk("%s () failed err=%d\n", e, -ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 goto out;
Herbert Xuef2736f2005-06-22 13:26:03 -0700319 }
320
Jens Axboe78c2f0b2007-10-22 19:40:16 +0200321 q = kmap(sg_page(&sg[0])) + sg[0].offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 hexdump(q, cipher_tv[i].rlen);
Herbert Xuef2736f2005-06-22 13:26:03 -0700323
324 printk("%s\n",
325 memcmp(q, cipher_tv[i].result,
326 cipher_tv[i].rlen) ? "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 }
328 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700329
Herbert Xucba83562006-08-13 08:26:09 +1000330 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 memset(xbuf, 0, XBUFSIZE);
Herbert Xuef2736f2005-06-22 13:26:03 -0700332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 j = 0;
334 for (i = 0; i < tcount; i++) {
335 if (cipher_tv[i].np) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700336 j++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 printk("test %u (%d bit key):\n",
338 j, cipher_tv[i].klen * 8);
339
Herbert Xu6158efc2007-04-04 17:41:07 +1000340 crypto_ablkcipher_clear_flags(tfm, ~0);
Herbert Xuef2736f2005-06-22 13:26:03 -0700341 if (cipher_tv[i].wk)
Herbert Xu6158efc2007-04-04 17:41:07 +1000342 crypto_ablkcipher_set_flags(
Herbert Xucba83562006-08-13 08:26:09 +1000343 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 key = cipher_tv[i].key;
Herbert Xuef2736f2005-06-22 13:26:03 -0700345
Herbert Xu6158efc2007-04-04 17:41:07 +1000346 ret = crypto_ablkcipher_setkey(tfm, key,
347 cipher_tv[i].klen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000349 printk("setkey() failed flags=%x\n",
Herbert Xu6158efc2007-04-04 17:41:07 +1000350 crypto_ablkcipher_get_flags(tfm));
Herbert Xuef2736f2005-06-22 13:26:03 -0700351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 if (!cipher_tv[i].fail)
353 goto out;
354 }
355
356 temp = 0;
David S. Millerb7335882007-10-26 00:38:10 -0700357 sg_init_table(sg, cipher_tv[i].np);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 for (k = 0; k < cipher_tv[i].np; k++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700359 memcpy(&xbuf[IDX[k]],
360 cipher_tv[i].input + temp,
361 cipher_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 temp += cipher_tv[i].tap[k];
David Hardeman378f0582005-09-17 17:55:31 +1000363 sg_set_buf(&sg[k], &xbuf[IDX[k]],
364 cipher_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700366
Herbert Xu6158efc2007-04-04 17:41:07 +1000367 ablkcipher_request_set_crypt(req, sg, sg,
368 cipher_tv[i].ilen,
369 cipher_tv[i].iv);
Herbert Xuef2736f2005-06-22 13:26:03 -0700370
Herbert Xucba83562006-08-13 08:26:09 +1000371 ret = enc ?
Herbert Xu6158efc2007-04-04 17:41:07 +1000372 crypto_ablkcipher_encrypt(req) :
373 crypto_ablkcipher_decrypt(req);
Herbert Xuef2736f2005-06-22 13:26:03 -0700374
Herbert Xu6158efc2007-04-04 17:41:07 +1000375 switch (ret) {
376 case 0:
377 break;
378 case -EINPROGRESS:
379 case -EBUSY:
380 ret = wait_for_completion_interruptible(
381 &result.completion);
382 if (!ret && !((ret = result.err))) {
383 INIT_COMPLETION(result.completion);
384 break;
385 }
386 /* fall through */
387 default:
388 printk("%s () failed err=%d\n", e, -ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 goto out;
390 }
391
392 temp = 0;
393 for (k = 0; k < cipher_tv[i].np; k++) {
394 printk("page %u\n", k);
Jens Axboe78c2f0b2007-10-22 19:40:16 +0200395 q = kmap(sg_page(&sg[k])) + sg[k].offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 hexdump(q, cipher_tv[i].tap[k]);
Herbert Xuef2736f2005-06-22 13:26:03 -0700397 printk("%s\n",
398 memcmp(q, cipher_tv[i].result + temp,
399 cipher_tv[i].tap[k]) ? "fail" :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 "pass");
401 temp += cipher_tv[i].tap[k];
402 }
403 }
404 }
405
406out:
Herbert Xu6158efc2007-04-04 17:41:07 +1000407 crypto_free_ablkcipher(tfm);
408 ablkcipher_request_free(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409}
410
Herbert Xucba83562006-08-13 08:26:09 +1000411static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
Herbert Xu6a179442005-06-22 13:29:03 -0700412 int blen, int sec)
413{
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000414 struct scatterlist sg[1];
Herbert Xu6a179442005-06-22 13:29:03 -0700415 unsigned long start, end;
416 int bcount;
417 int ret;
418
David S. Millerb7335882007-10-26 00:38:10 -0700419 sg_init_one(sg, p, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700420
421 for (start = jiffies, end = start + sec * HZ, bcount = 0;
422 time_before(jiffies, end); bcount++) {
423 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000424 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700425 else
Herbert Xucba83562006-08-13 08:26:09 +1000426 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700427
428 if (ret)
429 return ret;
430 }
431
432 printk("%d operations in %d seconds (%ld bytes)\n",
433 bcount, sec, (long)bcount * blen);
434 return 0;
435}
436
Herbert Xucba83562006-08-13 08:26:09 +1000437static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
Herbert Xu6a179442005-06-22 13:29:03 -0700438 int blen)
439{
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000440 struct scatterlist sg[1];
Herbert Xu6a179442005-06-22 13:29:03 -0700441 unsigned long cycles = 0;
442 int ret = 0;
443 int i;
444
David S. Millerb7335882007-10-26 00:38:10 -0700445 sg_init_one(sg, p, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700446
447 local_bh_disable();
448 local_irq_disable();
449
450 /* Warm-up run. */
451 for (i = 0; i < 4; i++) {
452 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000453 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700454 else
Herbert Xucba83562006-08-13 08:26:09 +1000455 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700456
457 if (ret)
458 goto out;
459 }
460
461 /* The real thing. */
462 for (i = 0; i < 8; i++) {
463 cycles_t start, end;
464
465 start = get_cycles();
466 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000467 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700468 else
Herbert Xucba83562006-08-13 08:26:09 +1000469 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700470 end = get_cycles();
471
472 if (ret)
473 goto out;
474
475 cycles += end - start;
476 }
477
478out:
479 local_irq_enable();
480 local_bh_enable();
481
482 if (ret == 0)
483 printk("1 operation in %lu cycles (%d bytes)\n",
484 (cycles + 4) / 8, blen);
485
486 return ret;
487}
488
Herbert Xucba83562006-08-13 08:26:09 +1000489static void test_cipher_speed(char *algo, int enc, unsigned int sec,
Herbert Xudce907c2005-06-22 13:27:51 -0700490 struct cipher_testvec *template,
491 unsigned int tcount, struct cipher_speed *speed)
Harald Welteebfd9bc2005-06-22 13:27:23 -0700492{
Herbert Xudce907c2005-06-22 13:27:51 -0700493 unsigned int ret, i, j, iv_len;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700494 unsigned char *key, *p, iv[128];
Herbert Xucba83562006-08-13 08:26:09 +1000495 struct crypto_blkcipher *tfm;
496 struct blkcipher_desc desc;
497 const char *e;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700498
499 if (enc == ENCRYPT)
500 e = "encryption";
501 else
502 e = "decryption";
Harald Welteebfd9bc2005-06-22 13:27:23 -0700503
Herbert Xucba83562006-08-13 08:26:09 +1000504 printk("\ntesting speed of %s %s\n", algo, e);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700505
Herbert Xucba83562006-08-13 08:26:09 +1000506 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700507
Herbert Xucba83562006-08-13 08:26:09 +1000508 if (IS_ERR(tfm)) {
509 printk("failed to load transform for %s: %ld\n", algo,
510 PTR_ERR(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700511 return;
512 }
Herbert Xucba83562006-08-13 08:26:09 +1000513 desc.tfm = tfm;
514 desc.flags = 0;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700515
516 for (i = 0; speed[i].klen != 0; i++) {
517 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
518 printk("template (%u) too big for tvmem (%u)\n",
519 speed[i].blen + speed[i].klen, TVMEMSIZE);
520 goto out;
521 }
522
523 printk("test %u (%d bit key, %d byte blocks): ", i,
524 speed[i].klen * 8, speed[i].blen);
525
526 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
527
528 /* set key, plain text and IV */
529 key = (unsigned char *)tvmem;
Herbert Xudce907c2005-06-22 13:27:51 -0700530 for (j = 0; j < tcount; j++) {
531 if (template[j].klen == speed[i].klen) {
532 key = template[j].key;
533 break;
534 }
535 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700536 p = (unsigned char *)tvmem + speed[i].klen;
537
Herbert Xucba83562006-08-13 08:26:09 +1000538 ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700539 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000540 printk("setkey() failed flags=%x\n",
541 crypto_blkcipher_get_flags(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700542 goto out;
543 }
544
Herbert Xucba83562006-08-13 08:26:09 +1000545 iv_len = crypto_blkcipher_ivsize(tfm);
546 if (iv_len) {
Harald Welteebfd9bc2005-06-22 13:27:23 -0700547 memset(&iv, 0xff, iv_len);
Herbert Xucba83562006-08-13 08:26:09 +1000548 crypto_blkcipher_set_iv(tfm, iv, iv_len);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700549 }
550
Herbert Xu6a179442005-06-22 13:29:03 -0700551 if (sec)
Herbert Xucba83562006-08-13 08:26:09 +1000552 ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen,
Herbert Xu6a179442005-06-22 13:29:03 -0700553 sec);
554 else
Herbert Xucba83562006-08-13 08:26:09 +1000555 ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700556
Herbert Xu6a179442005-06-22 13:29:03 -0700557 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000558 printk("%s() failed flags=%x\n", e, desc.flags);
Herbert Xu6a179442005-06-22 13:29:03 -0700559 break;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700560 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700561 }
562
563out:
Herbert Xucba83562006-08-13 08:26:09 +1000564 crypto_free_blkcipher(tfm);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700565}
566
Herbert Xue9d41162006-08-19 21:38:49 +1000567static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
568 char *out, int sec)
Michal Ludvige8057922006-05-30 22:04:19 +1000569{
570 struct scatterlist sg[1];
571 unsigned long start, end;
Herbert Xue9d41162006-08-19 21:38:49 +1000572 int bcount;
573 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000574
Herbert Xua5a613a2007-10-27 00:51:21 -0700575 sg_init_table(sg, 1);
576
Michal Ludvige8057922006-05-30 22:04:19 +1000577 for (start = jiffies, end = start + sec * HZ, bcount = 0;
578 time_before(jiffies, end); bcount++) {
Herbert Xua5a613a2007-10-27 00:51:21 -0700579 sg_set_buf(sg, p, blen);
Herbert Xue9d41162006-08-19 21:38:49 +1000580 ret = crypto_hash_digest(desc, sg, blen, out);
581 if (ret)
582 return ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000583 }
584
585 printk("%6u opers/sec, %9lu bytes/sec\n",
586 bcount / sec, ((long)bcount * blen) / sec);
587
Herbert Xue9d41162006-08-19 21:38:49 +1000588 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000589}
590
Herbert Xue9d41162006-08-19 21:38:49 +1000591static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
592 int plen, char *out, int sec)
593{
594 struct scatterlist sg[1];
595 unsigned long start, end;
596 int bcount, pcount;
597 int ret;
598
599 if (plen == blen)
600 return test_hash_jiffies_digest(desc, p, blen, out, sec);
601
Herbert Xua5a613a2007-10-27 00:51:21 -0700602 sg_init_table(sg, 1);
603
Herbert Xue9d41162006-08-19 21:38:49 +1000604 for (start = jiffies, end = start + sec * HZ, bcount = 0;
605 time_before(jiffies, end); bcount++) {
606 ret = crypto_hash_init(desc);
607 if (ret)
608 return ret;
609 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xua5a613a2007-10-27 00:51:21 -0700610 sg_set_buf(sg, p + pcount, plen);
Herbert Xue9d41162006-08-19 21:38:49 +1000611 ret = crypto_hash_update(desc, sg, plen);
612 if (ret)
613 return ret;
614 }
615 /* we assume there is enough space in 'out' for the result */
616 ret = crypto_hash_final(desc, out);
617 if (ret)
618 return ret;
619 }
620
621 printk("%6u opers/sec, %9lu bytes/sec\n",
622 bcount / sec, ((long)bcount * blen) / sec);
623
624 return 0;
625}
626
627static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
628 char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000629{
630 struct scatterlist sg[1];
631 unsigned long cycles = 0;
Herbert Xue9d41162006-08-19 21:38:49 +1000632 int i;
633 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000634
Herbert Xua5a613a2007-10-27 00:51:21 -0700635 sg_init_table(sg, 1);
636
Michal Ludvige8057922006-05-30 22:04:19 +1000637 local_bh_disable();
638 local_irq_disable();
639
640 /* Warm-up run. */
641 for (i = 0; i < 4; i++) {
Herbert Xua5a613a2007-10-27 00:51:21 -0700642 sg_set_buf(sg, p, blen);
Herbert Xue9d41162006-08-19 21:38:49 +1000643 ret = crypto_hash_digest(desc, sg, blen, out);
644 if (ret)
645 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000646 }
647
648 /* The real thing. */
649 for (i = 0; i < 8; i++) {
650 cycles_t start, end;
651
Michal Ludvige8057922006-05-30 22:04:19 +1000652 start = get_cycles();
653
Herbert Xua5a613a2007-10-27 00:51:21 -0700654 sg_set_buf(sg, p, blen);
Herbert Xue9d41162006-08-19 21:38:49 +1000655 ret = crypto_hash_digest(desc, sg, blen, out);
656 if (ret)
657 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000658
659 end = get_cycles();
660
661 cycles += end - start;
662 }
663
Herbert Xue9d41162006-08-19 21:38:49 +1000664out:
Michal Ludvige8057922006-05-30 22:04:19 +1000665 local_irq_enable();
666 local_bh_enable();
667
Herbert Xue9d41162006-08-19 21:38:49 +1000668 if (ret)
669 return ret;
670
Michal Ludvige8057922006-05-30 22:04:19 +1000671 printk("%6lu cycles/operation, %4lu cycles/byte\n",
672 cycles / 8, cycles / (8 * blen));
673
Herbert Xue9d41162006-08-19 21:38:49 +1000674 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000675}
676
Herbert Xue9d41162006-08-19 21:38:49 +1000677static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
678 int plen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000679{
Herbert Xue9d41162006-08-19 21:38:49 +1000680 struct scatterlist sg[1];
681 unsigned long cycles = 0;
682 int i, pcount;
683 int ret;
684
685 if (plen == blen)
686 return test_hash_cycles_digest(desc, p, blen, out);
687
Herbert Xua5a613a2007-10-27 00:51:21 -0700688 sg_init_table(sg, 1);
689
Herbert Xue9d41162006-08-19 21:38:49 +1000690 local_bh_disable();
691 local_irq_disable();
692
693 /* Warm-up run. */
694 for (i = 0; i < 4; i++) {
695 ret = crypto_hash_init(desc);
696 if (ret)
697 goto out;
698 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xua5a613a2007-10-27 00:51:21 -0700699 sg_set_buf(sg, p + pcount, plen);
Herbert Xue9d41162006-08-19 21:38:49 +1000700 ret = crypto_hash_update(desc, sg, plen);
701 if (ret)
702 goto out;
703 }
Herbert Xu29059d12007-05-18 16:25:19 +1000704 ret = crypto_hash_final(desc, out);
Herbert Xue9d41162006-08-19 21:38:49 +1000705 if (ret)
706 goto out;
707 }
708
709 /* The real thing. */
710 for (i = 0; i < 8; i++) {
711 cycles_t start, end;
712
713 start = get_cycles();
714
715 ret = crypto_hash_init(desc);
716 if (ret)
717 goto out;
718 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xua5a613a2007-10-27 00:51:21 -0700719 sg_set_buf(sg, p + pcount, plen);
Herbert Xue9d41162006-08-19 21:38:49 +1000720 ret = crypto_hash_update(desc, sg, plen);
721 if (ret)
722 goto out;
723 }
724 ret = crypto_hash_final(desc, out);
725 if (ret)
726 goto out;
727
728 end = get_cycles();
729
730 cycles += end - start;
731 }
732
733out:
734 local_irq_enable();
735 local_bh_enable();
736
737 if (ret)
738 return ret;
739
740 printk("%6lu cycles/operation, %4lu cycles/byte\n",
741 cycles / 8, cycles / (8 * blen));
742
743 return 0;
744}
745
746static void test_hash_speed(char *algo, unsigned int sec,
747 struct hash_speed *speed)
748{
749 struct crypto_hash *tfm;
750 struct hash_desc desc;
Michal Ludvige8057922006-05-30 22:04:19 +1000751 char output[1024];
752 int i;
Herbert Xue9d41162006-08-19 21:38:49 +1000753 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000754
755 printk("\ntesting speed of %s\n", algo);
756
Herbert Xue9d41162006-08-19 21:38:49 +1000757 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
Michal Ludvige8057922006-05-30 22:04:19 +1000758
Herbert Xue9d41162006-08-19 21:38:49 +1000759 if (IS_ERR(tfm)) {
760 printk("failed to load transform for %s: %ld\n", algo,
761 PTR_ERR(tfm));
Michal Ludvige8057922006-05-30 22:04:19 +1000762 return;
763 }
764
Herbert Xue9d41162006-08-19 21:38:49 +1000765 desc.tfm = tfm;
766 desc.flags = 0;
767
768 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
Michal Ludvige8057922006-05-30 22:04:19 +1000769 printk("digestsize(%u) > outputbuffer(%zu)\n",
Herbert Xue9d41162006-08-19 21:38:49 +1000770 crypto_hash_digestsize(tfm), sizeof(output));
Michal Ludvige8057922006-05-30 22:04:19 +1000771 goto out;
772 }
773
774 for (i = 0; speed[i].blen != 0; i++) {
775 if (speed[i].blen > TVMEMSIZE) {
776 printk("template (%u) too big for tvmem (%u)\n",
777 speed[i].blen, TVMEMSIZE);
778 goto out;
779 }
780
781 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
782 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
783
784 memset(tvmem, 0xff, speed[i].blen);
785
786 if (sec)
Herbert Xue9d41162006-08-19 21:38:49 +1000787 ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
788 speed[i].plen, output, sec);
Michal Ludvige8057922006-05-30 22:04:19 +1000789 else
Herbert Xue9d41162006-08-19 21:38:49 +1000790 ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
791 speed[i].plen, output);
792
793 if (ret) {
794 printk("hashing failed ret=%d\n", ret);
795 break;
796 }
Michal Ludvige8057922006-05-30 22:04:19 +1000797 }
798
799out:
Herbert Xue9d41162006-08-19 21:38:49 +1000800 crypto_free_hash(tfm);
Michal Ludvige8057922006-05-30 22:04:19 +1000801}
802
Herbert Xuef2736f2005-06-22 13:26:03 -0700803static void test_deflate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804{
805 unsigned int i;
806 char result[COMP_BUF_SIZE];
Herbert Xue4d5b792006-08-26 18:12:40 +1000807 struct crypto_comp *tfm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 struct comp_testvec *tv;
809 unsigned int tsize;
810
811 printk("\ntesting deflate compression\n");
812
813 tsize = sizeof (deflate_comp_tv_template);
814 if (tsize > TVMEMSIZE) {
815 printk("template (%u) too big for tvmem (%u)\n", tsize,
816 TVMEMSIZE);
817 return;
818 }
819
820 memcpy(tvmem, deflate_comp_tv_template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700821 tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Herbert Xuba8da2a2006-12-17 08:57:38 +1100823 tfm = crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC);
Sebastian Siewior7bc301e2007-03-21 08:58:43 +1100824 if (IS_ERR(tfm)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 printk("failed to load transform for deflate\n");
826 return;
827 }
828
829 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
830 int ilen, ret, dlen = COMP_BUF_SIZE;
Herbert Xuef2736f2005-06-22 13:26:03 -0700831
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 printk("test %u:\n", i + 1);
833 memset(result, 0, sizeof (result));
834
835 ilen = tv[i].inlen;
836 ret = crypto_comp_compress(tfm, tv[i].input,
837 ilen, result, &dlen);
838 if (ret) {
839 printk("fail: ret=%d\n", ret);
840 continue;
841 }
842 hexdump(result, dlen);
843 printk("%s (ratio %d:%d)\n",
844 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
845 ilen, dlen);
846 }
847
848 printk("\ntesting deflate decompression\n");
849
850 tsize = sizeof (deflate_decomp_tv_template);
851 if (tsize > TVMEMSIZE) {
852 printk("template (%u) too big for tvmem (%u)\n", tsize,
853 TVMEMSIZE);
854 goto out;
855 }
856
857 memcpy(tvmem, deflate_decomp_tv_template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700858 tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
860 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
861 int ilen, ret, dlen = COMP_BUF_SIZE;
Herbert Xuef2736f2005-06-22 13:26:03 -0700862
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 printk("test %u:\n", i + 1);
864 memset(result, 0, sizeof (result));
865
866 ilen = tv[i].inlen;
867 ret = crypto_comp_decompress(tfm, tv[i].input,
868 ilen, result, &dlen);
869 if (ret) {
870 printk("fail: ret=%d\n", ret);
871 continue;
872 }
873 hexdump(result, dlen);
874 printk("%s (ratio %d:%d)\n",
875 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
876 ilen, dlen);
877 }
878out:
Herbert Xue4d5b792006-08-26 18:12:40 +1000879 crypto_free_comp(tfm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880}
881
Herbert Xuef2736f2005-06-22 13:26:03 -0700882static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883{
884 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -0700885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 while (*name) {
887 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +1000888 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +1000889 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700891 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892}
893
Herbert Xuef2736f2005-06-22 13:26:03 -0700894static void do_test(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895{
896 switch (mode) {
897
898 case 0:
899 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700900
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700902
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 //DES
Herbert Xucba83562006-08-13 08:26:09 +1000904 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
905 DES_ENC_TEST_VECTORS);
906 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
907 DES_DEC_TEST_VECTORS);
908 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
909 DES_CBC_ENC_TEST_VECTORS);
910 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
911 DES_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700912
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 //DES3_EDE
Herbert Xucba83562006-08-13 08:26:09 +1000914 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
915 DES3_EDE_ENC_TEST_VECTORS);
916 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
917 DES3_EDE_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700918
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700920
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 //BLOWFISH
Herbert Xucba83562006-08-13 08:26:09 +1000924 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
925 BF_ENC_TEST_VECTORS);
926 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
927 BF_DEC_TEST_VECTORS);
928 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
929 BF_CBC_ENC_TEST_VECTORS);
930 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
931 BF_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700932
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 //TWOFISH
Herbert Xucba83562006-08-13 08:26:09 +1000934 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
935 TF_ENC_TEST_VECTORS);
936 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
937 TF_DEC_TEST_VECTORS);
938 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
939 TF_CBC_ENC_TEST_VECTORS);
940 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
941 TF_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700942
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 //SERPENT
Herbert Xucba83562006-08-13 08:26:09 +1000944 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
945 SERPENT_ENC_TEST_VECTORS);
946 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
947 SERPENT_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700948
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 //TNEPRES
Herbert Xucba83562006-08-13 08:26:09 +1000950 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
951 TNEPRES_ENC_TEST_VECTORS);
952 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
953 TNEPRES_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
955 //AES
Herbert Xucba83562006-08-13 08:26:09 +1000956 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
957 AES_ENC_TEST_VECTORS);
958 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
959 AES_DEC_TEST_VECTORS);
960 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
961 AES_CBC_ENC_TEST_VECTORS);
962 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
963 AES_CBC_DEC_TEST_VECTORS);
Rik Snelf3d10442006-11-29 19:01:41 +1100964 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
965 AES_LRW_ENC_TEST_VECTORS);
966 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
967 AES_LRW_DEC_TEST_VECTORS);
Rik Snelf19f5112007-09-19 20:23:13 +0800968 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
969 AES_XTS_ENC_TEST_VECTORS);
970 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
971 AES_XTS_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
973 //CAST5
Herbert Xucba83562006-08-13 08:26:09 +1000974 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
975 CAST5_ENC_TEST_VECTORS);
976 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
977 CAST5_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700978
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 //CAST6
Herbert Xucba83562006-08-13 08:26:09 +1000980 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
981 CAST6_ENC_TEST_VECTORS);
982 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
983 CAST6_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
985 //ARC4
Herbert Xucba83562006-08-13 08:26:09 +1000986 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
987 ARC4_ENC_TEST_VECTORS);
988 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
989 ARC4_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
991 //TEA
Herbert Xucba83562006-08-13 08:26:09 +1000992 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
993 TEA_ENC_TEST_VECTORS);
994 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
995 TEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
997
998 //XTEA
Herbert Xucba83562006-08-13 08:26:09 +1000999 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1000 XTEA_ENC_TEST_VECTORS);
1001 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1002 XTEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
1004 //KHAZAD
Herbert Xucba83562006-08-13 08:26:09 +10001005 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1006 KHAZAD_ENC_TEST_VECTORS);
1007 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1008 KHAZAD_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
1010 //ANUBIS
Herbert Xucba83562006-08-13 08:26:09 +10001011 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1012 ANUBIS_ENC_TEST_VECTORS);
1013 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1014 ANUBIS_DEC_TEST_VECTORS);
1015 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1016 ANUBIS_CBC_ENC_TEST_VECTORS);
1017 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1018 ANUBIS_CBC_ENC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001020 //XETA
Herbert Xucba83562006-08-13 08:26:09 +10001021 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1022 XETA_ENC_TEST_VECTORS);
1023 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1024 XETA_DEC_TEST_VECTORS);
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001025
David Howells90831632006-12-16 12:13:14 +11001026 //FCrypt
1027 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1028 FCRYPT_ENC_TEST_VECTORS);
1029 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1030 FCRYPT_DEC_TEST_VECTORS);
1031
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001032 //CAMELLIA
1033 test_cipher("ecb(camellia)", ENCRYPT,
1034 camellia_enc_tv_template,
1035 CAMELLIA_ENC_TEST_VECTORS);
1036 test_cipher("ecb(camellia)", DECRYPT,
1037 camellia_dec_tv_template,
1038 CAMELLIA_DEC_TEST_VECTORS);
1039 test_cipher("cbc(camellia)", ENCRYPT,
1040 camellia_cbc_enc_tv_template,
1041 CAMELLIA_CBC_ENC_TEST_VECTORS);
1042 test_cipher("cbc(camellia)", DECRYPT,
1043 camellia_cbc_dec_tv_template,
1044 CAMELLIA_CBC_DEC_TEST_VECTORS);
1045
Hye-Shik Change2ee95b2007-08-21 20:01:03 +08001046 //SEED
1047 test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template,
1048 SEED_ENC_TEST_VECTORS);
1049 test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
1050 SEED_DEC_TEST_VECTORS);
1051
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1053 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1054 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1055 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1056 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1057 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1058 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1059 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1060 test_deflate();
Herbert Xuc907ee72006-08-21 22:04:03 +10001061 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
Herbert Xue9d41162006-08-19 21:38:49 +10001062 test_hash("hmac(md5)", hmac_md5_tv_template,
1063 HMAC_MD5_TEST_VECTORS);
1064 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1065 HMAC_SHA1_TEST_VECTORS);
1066 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1067 HMAC_SHA256_TEST_VECTORS);
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001068 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1069 HMAC_SHA384_TEST_VECTORS);
1070 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1071 HMAC_SHA512_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
Kazunori MIYAZAWA5b2becf2006-10-28 13:18:53 +10001073 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1074 XCBC_AES_TEST_VECTORS);
1075
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1077 break;
1078
1079 case 1:
1080 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1081 break;
1082
1083 case 2:
1084 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1085 break;
1086
1087 case 3:
Herbert Xucba83562006-08-13 08:26:09 +10001088 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1089 DES_ENC_TEST_VECTORS);
1090 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1091 DES_DEC_TEST_VECTORS);
1092 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1093 DES_CBC_ENC_TEST_VECTORS);
1094 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1095 DES_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 break;
1097
1098 case 4:
Herbert Xucba83562006-08-13 08:26:09 +10001099 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1100 DES3_EDE_ENC_TEST_VECTORS);
1101 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1102 DES3_EDE_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 break;
1104
1105 case 5:
1106 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1107 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001108
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 case 6:
1110 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1111 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001112
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 case 7:
Herbert Xucba83562006-08-13 08:26:09 +10001114 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1115 BF_ENC_TEST_VECTORS);
1116 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1117 BF_DEC_TEST_VECTORS);
1118 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1119 BF_CBC_ENC_TEST_VECTORS);
1120 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1121 BF_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 break;
1123
1124 case 8:
Herbert Xucba83562006-08-13 08:26:09 +10001125 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1126 TF_ENC_TEST_VECTORS);
1127 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1128 TF_DEC_TEST_VECTORS);
1129 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1130 TF_CBC_ENC_TEST_VECTORS);
1131 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1132 TF_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001134
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 case 9:
Herbert Xucba83562006-08-13 08:26:09 +10001136 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1137 SERPENT_ENC_TEST_VECTORS);
1138 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1139 SERPENT_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 break;
1141
1142 case 10:
Herbert Xucba83562006-08-13 08:26:09 +10001143 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1144 AES_ENC_TEST_VECTORS);
1145 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1146 AES_DEC_TEST_VECTORS);
1147 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1148 AES_CBC_ENC_TEST_VECTORS);
1149 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1150 AES_CBC_DEC_TEST_VECTORS);
Rik Snelf3d10442006-11-29 19:01:41 +11001151 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1152 AES_LRW_ENC_TEST_VECTORS);
1153 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1154 AES_LRW_DEC_TEST_VECTORS);
Rik Snelf19f5112007-09-19 20:23:13 +08001155 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1156 AES_XTS_ENC_TEST_VECTORS);
1157 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1158 AES_XTS_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 break;
1160
1161 case 11:
1162 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1163 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001164
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 case 12:
1166 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1167 break;
1168
1169 case 13:
1170 test_deflate();
1171 break;
1172
1173 case 14:
Herbert Xucba83562006-08-13 08:26:09 +10001174 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1175 CAST5_ENC_TEST_VECTORS);
1176 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1177 CAST5_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 break;
1179
1180 case 15:
Herbert Xucba83562006-08-13 08:26:09 +10001181 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1182 CAST6_ENC_TEST_VECTORS);
1183 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1184 CAST6_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 break;
1186
1187 case 16:
Herbert Xucba83562006-08-13 08:26:09 +10001188 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1189 ARC4_ENC_TEST_VECTORS);
1190 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1191 ARC4_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 break;
1193
1194 case 17:
1195 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1196 break;
1197
1198 case 18:
Herbert Xuc907ee72006-08-21 22:04:03 +10001199 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 break;
1201
1202 case 19:
Herbert Xucba83562006-08-13 08:26:09 +10001203 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1204 TEA_ENC_TEST_VECTORS);
1205 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1206 TEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 break;
1208
1209 case 20:
Herbert Xucba83562006-08-13 08:26:09 +10001210 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1211 XTEA_ENC_TEST_VECTORS);
1212 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1213 XTEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 break;
1215
1216 case 21:
Herbert Xucba83562006-08-13 08:26:09 +10001217 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1218 KHAZAD_ENC_TEST_VECTORS);
1219 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1220 KHAZAD_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 break;
1222
1223 case 22:
1224 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1225 break;
1226
1227 case 23:
1228 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1229 break;
1230
1231 case 24:
1232 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1233 break;
1234
1235 case 25:
Herbert Xucba83562006-08-13 08:26:09 +10001236 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1237 TNEPRES_ENC_TEST_VECTORS);
1238 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1239 TNEPRES_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 break;
1241
1242 case 26:
Herbert Xucba83562006-08-13 08:26:09 +10001243 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1244 ANUBIS_ENC_TEST_VECTORS);
1245 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1246 ANUBIS_DEC_TEST_VECTORS);
1247 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1248 ANUBIS_CBC_ENC_TEST_VECTORS);
1249 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1250 ANUBIS_CBC_ENC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 break;
1252
1253 case 27:
1254 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1255 break;
1256
1257 case 28:
1258
1259 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1260 break;
1261
1262 case 29:
1263 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1264 break;
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001265
1266 case 30:
Herbert Xucba83562006-08-13 08:26:09 +10001267 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1268 XETA_ENC_TEST_VECTORS);
1269 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1270 XETA_DEC_TEST_VECTORS);
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001271 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
David Howells90831632006-12-16 12:13:14 +11001273 case 31:
1274 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1275 FCRYPT_ENC_TEST_VECTORS);
1276 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1277 FCRYPT_DEC_TEST_VECTORS);
1278 break;
1279
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001280 case 32:
1281 test_cipher("ecb(camellia)", ENCRYPT,
1282 camellia_enc_tv_template,
1283 CAMELLIA_ENC_TEST_VECTORS);
1284 test_cipher("ecb(camellia)", DECRYPT,
1285 camellia_dec_tv_template,
1286 CAMELLIA_DEC_TEST_VECTORS);
1287 test_cipher("cbc(camellia)", ENCRYPT,
1288 camellia_cbc_enc_tv_template,
1289 CAMELLIA_CBC_ENC_TEST_VECTORS);
1290 test_cipher("cbc(camellia)", DECRYPT,
1291 camellia_cbc_dec_tv_template,
1292 CAMELLIA_CBC_DEC_TEST_VECTORS);
1293 break;
1294
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 case 100:
Herbert Xue9d41162006-08-19 21:38:49 +10001296 test_hash("hmac(md5)", hmac_md5_tv_template,
1297 HMAC_MD5_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001299
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 case 101:
Herbert Xue9d41162006-08-19 21:38:49 +10001301 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1302 HMAC_SHA1_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001304
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 case 102:
Herbert Xue9d41162006-08-19 21:38:49 +10001306 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1307 HMAC_SHA256_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 break;
1309
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001310 case 103:
1311 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1312 HMAC_SHA384_TEST_VECTORS);
1313 break;
1314
1315 case 104:
1316 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1317 HMAC_SHA512_TEST_VECTORS);
1318 break;
1319
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
Harald Welteebfd9bc2005-06-22 13:27:23 -07001321 case 200:
Herbert Xucba83562006-08-13 08:26:09 +10001322 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001323 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001324 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001325 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001326 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001327 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001328 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001329 aes_speed_template);
Rik Snelf3d10442006-11-29 19:01:41 +11001330 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1331 aes_lrw_speed_template);
1332 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1333 aes_lrw_speed_template);
Rik Snelf19f5112007-09-19 20:23:13 +08001334 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1335 aes_xts_speed_template);
1336 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1337 aes_xts_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001338 break;
1339
1340 case 201:
Herbert Xucba83562006-08-13 08:26:09 +10001341 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001342 des3_ede_enc_tv_template,
1343 DES3_EDE_ENC_TEST_VECTORS,
1344 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001345 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001346 des3_ede_dec_tv_template,
1347 DES3_EDE_DEC_TEST_VECTORS,
1348 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001349 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001350 des3_ede_enc_tv_template,
1351 DES3_EDE_ENC_TEST_VECTORS,
1352 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001353 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001354 des3_ede_dec_tv_template,
1355 DES3_EDE_DEC_TEST_VECTORS,
1356 des3_ede_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001357 break;
1358
1359 case 202:
Herbert Xucba83562006-08-13 08:26:09 +10001360 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001361 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001362 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001363 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001364 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001365 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001366 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001367 twofish_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001368 break;
1369
1370 case 203:
Herbert Xucba83562006-08-13 08:26:09 +10001371 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001372 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001373 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001374 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001375 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001376 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001377 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001378 blowfish_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001379 break;
1380
1381 case 204:
Herbert Xucba83562006-08-13 08:26:09 +10001382 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001383 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001384 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001385 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001386 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001387 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001388 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001389 des_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001390 break;
1391
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001392 case 205:
1393 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1394 camellia_speed_template);
1395 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1396 camellia_speed_template);
1397 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1398 camellia_speed_template);
1399 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1400 camellia_speed_template);
1401 break;
1402
Michal Ludvige8057922006-05-30 22:04:19 +10001403 case 300:
1404 /* fall through */
1405
1406 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +10001407 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001408 if (mode > 300 && mode < 400) break;
1409
1410 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +10001411 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001412 if (mode > 300 && mode < 400) break;
1413
1414 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +10001415 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001416 if (mode > 300 && mode < 400) break;
1417
1418 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +10001419 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001420 if (mode > 300 && mode < 400) break;
1421
1422 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +10001423 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001424 if (mode > 300 && mode < 400) break;
1425
1426 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +10001427 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001428 if (mode > 300 && mode < 400) break;
1429
1430 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +10001431 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001432 if (mode > 300 && mode < 400) break;
1433
1434 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +10001435 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001436 if (mode > 300 && mode < 400) break;
1437
1438 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +10001439 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001440 if (mode > 300 && mode < 400) break;
1441
1442 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +10001443 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001444 if (mode > 300 && mode < 400) break;
1445
1446 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +10001447 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001448 if (mode > 300 && mode < 400) break;
1449
1450 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +10001451 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001452 if (mode > 300 && mode < 400) break;
1453
1454 case 399:
1455 break;
1456
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 case 1000:
1458 test_available();
1459 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001460
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 default:
1462 /* useful for debugging */
1463 printk("not testing anything\n");
1464 break;
1465 }
1466}
1467
Herbert Xuef2736f2005-06-22 13:26:03 -07001468static int __init init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469{
1470 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1471 if (tvmem == NULL)
1472 return -ENOMEM;
1473
1474 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1475 if (xbuf == NULL) {
1476 kfree(tvmem);
1477 return -ENOMEM;
1478 }
1479
1480 do_test();
1481
1482 kfree(xbuf);
1483 kfree(tvmem);
Michal Ludvig14fdf472006-05-30 14:49:38 +10001484
1485 /* We intentionaly return -EAGAIN to prevent keeping
1486 * the module. It does all its work from init()
1487 * and doesn't offer any runtime functionality
1488 * => we don't need it in the memory, do we?
1489 * -- mludvig
1490 */
1491 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492}
1493
1494/*
1495 * If an init function is provided, an exit function must also be provided
1496 * to allow module unload.
1497 */
1498static void __exit fini(void) { }
1499
1500module_init(init);
1501module_exit(fini);
1502
1503module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001504module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -07001505MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1506 "(defaults to zero which uses CPU cycles instead)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
1508MODULE_LICENSE("GPL");
1509MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1510MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");