blob: f0aed0106adb1cbf7068f93277857a8bd725e174 [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",
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +110081 "camellia", 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 Hardeman378f0582005-09-17 17:55:31 +1000142 sg_set_buf(&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;
179 for (k = 0; k < hash_tv[i].np; k++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700180 memcpy(&xbuf[IDX[k]],
181 hash_tv[i].plaintext + temp,
182 hash_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 temp += hash_tv[i].tap[k];
David Hardeman378f0582005-09-17 17:55:31 +1000184 sg_set_buf(&sg[k], &xbuf[IDX[k]],
185 hash_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 }
187
Herbert Xue9d41162006-08-19 21:38:49 +1000188 if (hash_tv[i].ksize) {
189 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
190 hash_tv[i].ksize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700191
Herbert Xue9d41162006-08-19 21:38:49 +1000192 if (ret) {
193 printk("setkey() failed ret=%d\n", ret);
194 goto out;
195 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 }
197
Herbert Xue9d41162006-08-19 21:38:49 +1000198 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize,
199 result);
200 if (ret) {
201 printk("digest () failed ret=%d\n", ret);
202 goto out;
203 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700204
Herbert Xue9d41162006-08-19 21:38:49 +1000205 hexdump(result, crypto_hash_digestsize(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 printk("%s\n",
Herbert Xue9d41162006-08-19 21:38:49 +1000207 memcmp(result, hash_tv[i].digest,
208 crypto_hash_digestsize(tfm)) ?
Herbert Xuef2736f2005-06-22 13:26:03 -0700209 "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 }
211 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Herbert Xue9d41162006-08-19 21:38:49 +1000213out:
214 crypto_free_hash(tfm);
215}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Herbert Xucba83562006-08-13 08:26:09 +1000217static void test_cipher(char *algo, int enc,
Herbert Xuef2736f2005-06-22 13:26:03 -0700218 struct cipher_testvec *template, unsigned int tcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
220 unsigned int ret, i, j, k, temp;
221 unsigned int tsize;
David Hardeman378f0582005-09-17 17:55:31 +1000222 char *q;
Herbert Xu6158efc2007-04-04 17:41:07 +1000223 struct crypto_ablkcipher *tfm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 char *key;
225 struct cipher_testvec *cipher_tv;
Herbert Xu6158efc2007-04-04 17:41:07 +1000226 struct ablkcipher_request *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 struct scatterlist sg[8];
Herbert Xucba83562006-08-13 08:26:09 +1000228 const char *e;
Herbert Xu6158efc2007-04-04 17:41:07 +1000229 struct tcrypt_result result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 if (enc == ENCRYPT)
Herbert Xu3cc38162005-06-22 13:26:36 -0700232 e = "encryption";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 else
Herbert Xu3cc38162005-06-22 13:26:36 -0700234 e = "decryption";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Herbert Xucba83562006-08-13 08:26:09 +1000236 printk("\ntesting %s %s\n", algo, e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Herbert Xuef2736f2005-06-22 13:26:03 -0700238 tsize = sizeof (struct cipher_testvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 tsize *= tcount;
Herbert Xuef2736f2005-06-22 13:26:03 -0700240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 if (tsize > TVMEMSIZE) {
242 printk("template (%u) too big for tvmem (%u)\n", tsize,
243 TVMEMSIZE);
244 return;
245 }
246
247 memcpy(tvmem, template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700248 cipher_tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Herbert Xu6158efc2007-04-04 17:41:07 +1000250 init_completion(&result.completion);
251
252 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
Herbert Xuef2736f2005-06-22 13:26:03 -0700253
Herbert Xucba83562006-08-13 08:26:09 +1000254 if (IS_ERR(tfm)) {
255 printk("failed to load transform for %s: %ld\n", algo,
256 PTR_ERR(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 return;
258 }
Herbert Xu6158efc2007-04-04 17:41:07 +1000259
260 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
261 if (!req) {
262 printk("failed to allocate request for %s\n", algo);
263 goto out;
264 }
265
266 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
267 tcrypt_complete, &result);
Herbert Xuef2736f2005-06-22 13:26:03 -0700268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 j = 0;
270 for (i = 0; i < tcount; i++) {
271 if (!(cipher_tv[i].np)) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700272 j++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 printk("test %u (%d bit key):\n",
274 j, cipher_tv[i].klen * 8);
275
Herbert Xu6158efc2007-04-04 17:41:07 +1000276 crypto_ablkcipher_clear_flags(tfm, ~0);
Herbert Xuef2736f2005-06-22 13:26:03 -0700277 if (cipher_tv[i].wk)
Herbert Xu6158efc2007-04-04 17:41:07 +1000278 crypto_ablkcipher_set_flags(
Herbert Xucba83562006-08-13 08:26:09 +1000279 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 key = cipher_tv[i].key;
Herbert Xuef2736f2005-06-22 13:26:03 -0700281
Herbert Xu6158efc2007-04-04 17:41:07 +1000282 ret = crypto_ablkcipher_setkey(tfm, key,
283 cipher_tv[i].klen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000285 printk("setkey() failed flags=%x\n",
Herbert Xu6158efc2007-04-04 17:41:07 +1000286 crypto_ablkcipher_get_flags(tfm));
Herbert Xuef2736f2005-06-22 13:26:03 -0700287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 if (!cipher_tv[i].fail)
289 goto out;
Herbert Xuef2736f2005-06-22 13:26:03 -0700290 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
David Hardeman378f0582005-09-17 17:55:31 +1000292 sg_set_buf(&sg[0], cipher_tv[i].input,
293 cipher_tv[i].ilen);
Herbert Xuef2736f2005-06-22 13:26:03 -0700294
Herbert Xu6158efc2007-04-04 17:41:07 +1000295 ablkcipher_request_set_crypt(req, sg, sg,
296 cipher_tv[i].ilen,
297 cipher_tv[i].iv);
Herbert Xuef2736f2005-06-22 13:26:03 -0700298
Herbert Xucba83562006-08-13 08:26:09 +1000299 ret = enc ?
Herbert Xu6158efc2007-04-04 17:41:07 +1000300 crypto_ablkcipher_encrypt(req) :
301 crypto_ablkcipher_decrypt(req);
Herbert Xuef2736f2005-06-22 13:26:03 -0700302
Herbert Xu6158efc2007-04-04 17:41:07 +1000303 switch (ret) {
304 case 0:
305 break;
306 case -EINPROGRESS:
307 case -EBUSY:
308 ret = wait_for_completion_interruptible(
309 &result.completion);
310 if (!ret && !((ret = result.err))) {
311 INIT_COMPLETION(result.completion);
312 break;
313 }
314 /* fall through */
315 default:
316 printk("%s () failed err=%d\n", e, -ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 goto out;
Herbert Xuef2736f2005-06-22 13:26:03 -0700318 }
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 q = kmap(sg[0].page) + sg[0].offset;
321 hexdump(q, cipher_tv[i].rlen);
Herbert Xuef2736f2005-06-22 13:26:03 -0700322
323 printk("%s\n",
324 memcmp(q, cipher_tv[i].result,
325 cipher_tv[i].rlen) ? "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 }
327 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700328
Herbert Xucba83562006-08-13 08:26:09 +1000329 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 memset(xbuf, 0, XBUFSIZE);
Herbert Xuef2736f2005-06-22 13:26:03 -0700331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 j = 0;
333 for (i = 0; i < tcount; i++) {
334 if (cipher_tv[i].np) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700335 j++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 printk("test %u (%d bit key):\n",
337 j, cipher_tv[i].klen * 8);
338
Herbert Xu6158efc2007-04-04 17:41:07 +1000339 crypto_ablkcipher_clear_flags(tfm, ~0);
Herbert Xuef2736f2005-06-22 13:26:03 -0700340 if (cipher_tv[i].wk)
Herbert Xu6158efc2007-04-04 17:41:07 +1000341 crypto_ablkcipher_set_flags(
Herbert Xucba83562006-08-13 08:26:09 +1000342 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 key = cipher_tv[i].key;
Herbert Xuef2736f2005-06-22 13:26:03 -0700344
Herbert Xu6158efc2007-04-04 17:41:07 +1000345 ret = crypto_ablkcipher_setkey(tfm, key,
346 cipher_tv[i].klen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000348 printk("setkey() failed flags=%x\n",
Herbert Xu6158efc2007-04-04 17:41:07 +1000349 crypto_ablkcipher_get_flags(tfm));
Herbert Xuef2736f2005-06-22 13:26:03 -0700350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 if (!cipher_tv[i].fail)
352 goto out;
353 }
354
355 temp = 0;
356 for (k = 0; k < cipher_tv[i].np; k++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700357 memcpy(&xbuf[IDX[k]],
358 cipher_tv[i].input + temp,
359 cipher_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 temp += cipher_tv[i].tap[k];
David Hardeman378f0582005-09-17 17:55:31 +1000361 sg_set_buf(&sg[k], &xbuf[IDX[k]],
362 cipher_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700364
Herbert Xu6158efc2007-04-04 17:41:07 +1000365 ablkcipher_request_set_crypt(req, sg, sg,
366 cipher_tv[i].ilen,
367 cipher_tv[i].iv);
Herbert Xuef2736f2005-06-22 13:26:03 -0700368
Herbert Xucba83562006-08-13 08:26:09 +1000369 ret = enc ?
Herbert Xu6158efc2007-04-04 17:41:07 +1000370 crypto_ablkcipher_encrypt(req) :
371 crypto_ablkcipher_decrypt(req);
Herbert Xuef2736f2005-06-22 13:26:03 -0700372
Herbert Xu6158efc2007-04-04 17:41:07 +1000373 switch (ret) {
374 case 0:
375 break;
376 case -EINPROGRESS:
377 case -EBUSY:
378 ret = wait_for_completion_interruptible(
379 &result.completion);
380 if (!ret && !((ret = result.err))) {
381 INIT_COMPLETION(result.completion);
382 break;
383 }
384 /* fall through */
385 default:
386 printk("%s () failed err=%d\n", e, -ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 goto out;
388 }
389
390 temp = 0;
391 for (k = 0; k < cipher_tv[i].np; k++) {
392 printk("page %u\n", k);
393 q = kmap(sg[k].page) + sg[k].offset;
394 hexdump(q, cipher_tv[i].tap[k]);
Herbert Xuef2736f2005-06-22 13:26:03 -0700395 printk("%s\n",
396 memcmp(q, cipher_tv[i].result + temp,
397 cipher_tv[i].tap[k]) ? "fail" :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 "pass");
399 temp += cipher_tv[i].tap[k];
400 }
401 }
402 }
403
404out:
Herbert Xu6158efc2007-04-04 17:41:07 +1000405 crypto_free_ablkcipher(tfm);
406 ablkcipher_request_free(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407}
408
Herbert Xucba83562006-08-13 08:26:09 +1000409static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
Herbert Xu6a179442005-06-22 13:29:03 -0700410 int blen, int sec)
411{
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000412 struct scatterlist sg[1];
Herbert Xu6a179442005-06-22 13:29:03 -0700413 unsigned long start, end;
414 int bcount;
415 int ret;
416
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000417 sg_set_buf(sg, p, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700418
419 for (start = jiffies, end = start + sec * HZ, bcount = 0;
420 time_before(jiffies, end); bcount++) {
421 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000422 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700423 else
Herbert Xucba83562006-08-13 08:26:09 +1000424 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700425
426 if (ret)
427 return ret;
428 }
429
430 printk("%d operations in %d seconds (%ld bytes)\n",
431 bcount, sec, (long)bcount * blen);
432 return 0;
433}
434
Herbert Xucba83562006-08-13 08:26:09 +1000435static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
Herbert Xu6a179442005-06-22 13:29:03 -0700436 int blen)
437{
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000438 struct scatterlist sg[1];
Herbert Xu6a179442005-06-22 13:29:03 -0700439 unsigned long cycles = 0;
440 int ret = 0;
441 int i;
442
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000443 sg_set_buf(sg, p, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700444
445 local_bh_disable();
446 local_irq_disable();
447
448 /* Warm-up run. */
449 for (i = 0; i < 4; i++) {
450 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000451 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700452 else
Herbert Xucba83562006-08-13 08:26:09 +1000453 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700454
455 if (ret)
456 goto out;
457 }
458
459 /* The real thing. */
460 for (i = 0; i < 8; i++) {
461 cycles_t start, end;
462
463 start = get_cycles();
464 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000465 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700466 else
Herbert Xucba83562006-08-13 08:26:09 +1000467 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700468 end = get_cycles();
469
470 if (ret)
471 goto out;
472
473 cycles += end - start;
474 }
475
476out:
477 local_irq_enable();
478 local_bh_enable();
479
480 if (ret == 0)
481 printk("1 operation in %lu cycles (%d bytes)\n",
482 (cycles + 4) / 8, blen);
483
484 return ret;
485}
486
Herbert Xucba83562006-08-13 08:26:09 +1000487static void test_cipher_speed(char *algo, int enc, unsigned int sec,
Herbert Xudce907c2005-06-22 13:27:51 -0700488 struct cipher_testvec *template,
489 unsigned int tcount, struct cipher_speed *speed)
Harald Welteebfd9bc2005-06-22 13:27:23 -0700490{
Herbert Xudce907c2005-06-22 13:27:51 -0700491 unsigned int ret, i, j, iv_len;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700492 unsigned char *key, *p, iv[128];
Herbert Xucba83562006-08-13 08:26:09 +1000493 struct crypto_blkcipher *tfm;
494 struct blkcipher_desc desc;
495 const char *e;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700496
497 if (enc == ENCRYPT)
498 e = "encryption";
499 else
500 e = "decryption";
Harald Welteebfd9bc2005-06-22 13:27:23 -0700501
Herbert Xucba83562006-08-13 08:26:09 +1000502 printk("\ntesting speed of %s %s\n", algo, e);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700503
Herbert Xucba83562006-08-13 08:26:09 +1000504 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700505
Herbert Xucba83562006-08-13 08:26:09 +1000506 if (IS_ERR(tfm)) {
507 printk("failed to load transform for %s: %ld\n", algo,
508 PTR_ERR(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700509 return;
510 }
Herbert Xucba83562006-08-13 08:26:09 +1000511 desc.tfm = tfm;
512 desc.flags = 0;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700513
514 for (i = 0; speed[i].klen != 0; i++) {
515 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
516 printk("template (%u) too big for tvmem (%u)\n",
517 speed[i].blen + speed[i].klen, TVMEMSIZE);
518 goto out;
519 }
520
521 printk("test %u (%d bit key, %d byte blocks): ", i,
522 speed[i].klen * 8, speed[i].blen);
523
524 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
525
526 /* set key, plain text and IV */
527 key = (unsigned char *)tvmem;
Herbert Xudce907c2005-06-22 13:27:51 -0700528 for (j = 0; j < tcount; j++) {
529 if (template[j].klen == speed[i].klen) {
530 key = template[j].key;
531 break;
532 }
533 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700534 p = (unsigned char *)tvmem + speed[i].klen;
535
Herbert Xucba83562006-08-13 08:26:09 +1000536 ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700537 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000538 printk("setkey() failed flags=%x\n",
539 crypto_blkcipher_get_flags(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700540 goto out;
541 }
542
Herbert Xucba83562006-08-13 08:26:09 +1000543 iv_len = crypto_blkcipher_ivsize(tfm);
544 if (iv_len) {
Harald Welteebfd9bc2005-06-22 13:27:23 -0700545 memset(&iv, 0xff, iv_len);
Herbert Xucba83562006-08-13 08:26:09 +1000546 crypto_blkcipher_set_iv(tfm, iv, iv_len);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700547 }
548
Herbert Xu6a179442005-06-22 13:29:03 -0700549 if (sec)
Herbert Xucba83562006-08-13 08:26:09 +1000550 ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen,
Herbert Xu6a179442005-06-22 13:29:03 -0700551 sec);
552 else
Herbert Xucba83562006-08-13 08:26:09 +1000553 ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700554
Herbert Xu6a179442005-06-22 13:29:03 -0700555 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000556 printk("%s() failed flags=%x\n", e, desc.flags);
Herbert Xu6a179442005-06-22 13:29:03 -0700557 break;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700558 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700559 }
560
561out:
Herbert Xucba83562006-08-13 08:26:09 +1000562 crypto_free_blkcipher(tfm);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700563}
564
Herbert Xue9d41162006-08-19 21:38:49 +1000565static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
566 char *out, int sec)
Michal Ludvige8057922006-05-30 22:04:19 +1000567{
568 struct scatterlist sg[1];
569 unsigned long start, end;
Herbert Xue9d41162006-08-19 21:38:49 +1000570 int bcount;
571 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000572
573 for (start = jiffies, end = start + sec * HZ, bcount = 0;
574 time_before(jiffies, end); bcount++) {
Herbert Xue9d41162006-08-19 21:38:49 +1000575 sg_set_buf(sg, p, blen);
576 ret = crypto_hash_digest(desc, sg, blen, out);
577 if (ret)
578 return ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000579 }
580
581 printk("%6u opers/sec, %9lu bytes/sec\n",
582 bcount / sec, ((long)bcount * blen) / sec);
583
Herbert Xue9d41162006-08-19 21:38:49 +1000584 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000585}
586
Herbert Xue9d41162006-08-19 21:38:49 +1000587static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
588 int plen, char *out, int sec)
589{
590 struct scatterlist sg[1];
591 unsigned long start, end;
592 int bcount, pcount;
593 int ret;
594
595 if (plen == blen)
596 return test_hash_jiffies_digest(desc, p, blen, out, sec);
597
598 for (start = jiffies, end = start + sec * HZ, bcount = 0;
599 time_before(jiffies, end); bcount++) {
600 ret = crypto_hash_init(desc);
601 if (ret)
602 return ret;
603 for (pcount = 0; pcount < blen; pcount += plen) {
604 sg_set_buf(sg, p + pcount, plen);
605 ret = crypto_hash_update(desc, sg, plen);
606 if (ret)
607 return ret;
608 }
609 /* we assume there is enough space in 'out' for the result */
610 ret = crypto_hash_final(desc, out);
611 if (ret)
612 return ret;
613 }
614
615 printk("%6u opers/sec, %9lu bytes/sec\n",
616 bcount / sec, ((long)bcount * blen) / sec);
617
618 return 0;
619}
620
621static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
622 char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000623{
624 struct scatterlist sg[1];
625 unsigned long cycles = 0;
Herbert Xue9d41162006-08-19 21:38:49 +1000626 int i;
627 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000628
629 local_bh_disable();
630 local_irq_disable();
631
632 /* Warm-up run. */
633 for (i = 0; i < 4; i++) {
Herbert Xue9d41162006-08-19 21:38:49 +1000634 sg_set_buf(sg, p, blen);
635 ret = crypto_hash_digest(desc, sg, blen, out);
636 if (ret)
637 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000638 }
639
640 /* The real thing. */
641 for (i = 0; i < 8; i++) {
642 cycles_t start, end;
643
Michal Ludvige8057922006-05-30 22:04:19 +1000644 start = get_cycles();
645
Herbert Xue9d41162006-08-19 21:38:49 +1000646 sg_set_buf(sg, p, blen);
647 ret = crypto_hash_digest(desc, sg, blen, out);
648 if (ret)
649 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000650
651 end = get_cycles();
652
653 cycles += end - start;
654 }
655
Herbert Xue9d41162006-08-19 21:38:49 +1000656out:
Michal Ludvige8057922006-05-30 22:04:19 +1000657 local_irq_enable();
658 local_bh_enable();
659
Herbert Xue9d41162006-08-19 21:38:49 +1000660 if (ret)
661 return ret;
662
Michal Ludvige8057922006-05-30 22:04:19 +1000663 printk("%6lu cycles/operation, %4lu cycles/byte\n",
664 cycles / 8, cycles / (8 * blen));
665
Herbert Xue9d41162006-08-19 21:38:49 +1000666 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000667}
668
Herbert Xue9d41162006-08-19 21:38:49 +1000669static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
670 int plen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000671{
Herbert Xue9d41162006-08-19 21:38:49 +1000672 struct scatterlist sg[1];
673 unsigned long cycles = 0;
674 int i, pcount;
675 int ret;
676
677 if (plen == blen)
678 return test_hash_cycles_digest(desc, p, blen, out);
679
680 local_bh_disable();
681 local_irq_disable();
682
683 /* Warm-up run. */
684 for (i = 0; i < 4; i++) {
685 ret = crypto_hash_init(desc);
686 if (ret)
687 goto out;
688 for (pcount = 0; pcount < blen; pcount += plen) {
689 sg_set_buf(sg, p + pcount, plen);
690 ret = crypto_hash_update(desc, sg, plen);
691 if (ret)
692 goto out;
693 }
694 crypto_hash_final(desc, out);
695 if (ret)
696 goto out;
697 }
698
699 /* The real thing. */
700 for (i = 0; i < 8; i++) {
701 cycles_t start, end;
702
703 start = get_cycles();
704
705 ret = crypto_hash_init(desc);
706 if (ret)
707 goto out;
708 for (pcount = 0; pcount < blen; pcount += plen) {
709 sg_set_buf(sg, p + pcount, plen);
710 ret = crypto_hash_update(desc, sg, plen);
711 if (ret)
712 goto out;
713 }
714 ret = crypto_hash_final(desc, out);
715 if (ret)
716 goto out;
717
718 end = get_cycles();
719
720 cycles += end - start;
721 }
722
723out:
724 local_irq_enable();
725 local_bh_enable();
726
727 if (ret)
728 return ret;
729
730 printk("%6lu cycles/operation, %4lu cycles/byte\n",
731 cycles / 8, cycles / (8 * blen));
732
733 return 0;
734}
735
736static void test_hash_speed(char *algo, unsigned int sec,
737 struct hash_speed *speed)
738{
739 struct crypto_hash *tfm;
740 struct hash_desc desc;
Michal Ludvige8057922006-05-30 22:04:19 +1000741 char output[1024];
742 int i;
Herbert Xue9d41162006-08-19 21:38:49 +1000743 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000744
745 printk("\ntesting speed of %s\n", algo);
746
Herbert Xue9d41162006-08-19 21:38:49 +1000747 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
Michal Ludvige8057922006-05-30 22:04:19 +1000748
Herbert Xue9d41162006-08-19 21:38:49 +1000749 if (IS_ERR(tfm)) {
750 printk("failed to load transform for %s: %ld\n", algo,
751 PTR_ERR(tfm));
Michal Ludvige8057922006-05-30 22:04:19 +1000752 return;
753 }
754
Herbert Xue9d41162006-08-19 21:38:49 +1000755 desc.tfm = tfm;
756 desc.flags = 0;
757
758 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
Michal Ludvige8057922006-05-30 22:04:19 +1000759 printk("digestsize(%u) > outputbuffer(%zu)\n",
Herbert Xue9d41162006-08-19 21:38:49 +1000760 crypto_hash_digestsize(tfm), sizeof(output));
Michal Ludvige8057922006-05-30 22:04:19 +1000761 goto out;
762 }
763
764 for (i = 0; speed[i].blen != 0; i++) {
765 if (speed[i].blen > TVMEMSIZE) {
766 printk("template (%u) too big for tvmem (%u)\n",
767 speed[i].blen, TVMEMSIZE);
768 goto out;
769 }
770
771 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
772 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
773
774 memset(tvmem, 0xff, speed[i].blen);
775
776 if (sec)
Herbert Xue9d41162006-08-19 21:38:49 +1000777 ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
778 speed[i].plen, output, sec);
Michal Ludvige8057922006-05-30 22:04:19 +1000779 else
Herbert Xue9d41162006-08-19 21:38:49 +1000780 ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
781 speed[i].plen, output);
782
783 if (ret) {
784 printk("hashing failed ret=%d\n", ret);
785 break;
786 }
Michal Ludvige8057922006-05-30 22:04:19 +1000787 }
788
789out:
Herbert Xue9d41162006-08-19 21:38:49 +1000790 crypto_free_hash(tfm);
Michal Ludvige8057922006-05-30 22:04:19 +1000791}
792
Herbert Xuef2736f2005-06-22 13:26:03 -0700793static void test_deflate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794{
795 unsigned int i;
796 char result[COMP_BUF_SIZE];
Herbert Xue4d5b792006-08-26 18:12:40 +1000797 struct crypto_comp *tfm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 struct comp_testvec *tv;
799 unsigned int tsize;
800
801 printk("\ntesting deflate compression\n");
802
803 tsize = sizeof (deflate_comp_tv_template);
804 if (tsize > TVMEMSIZE) {
805 printk("template (%u) too big for tvmem (%u)\n", tsize,
806 TVMEMSIZE);
807 return;
808 }
809
810 memcpy(tvmem, deflate_comp_tv_template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700811 tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
Herbert Xuba8da2a2006-12-17 08:57:38 +1100813 tfm = crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC);
Sebastian Siewior7bc301e2007-03-21 08:58:43 +1100814 if (IS_ERR(tfm)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 printk("failed to load transform for deflate\n");
816 return;
817 }
818
819 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
820 int ilen, ret, dlen = COMP_BUF_SIZE;
Herbert Xuef2736f2005-06-22 13:26:03 -0700821
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 printk("test %u:\n", i + 1);
823 memset(result, 0, sizeof (result));
824
825 ilen = tv[i].inlen;
826 ret = crypto_comp_compress(tfm, tv[i].input,
827 ilen, result, &dlen);
828 if (ret) {
829 printk("fail: ret=%d\n", ret);
830 continue;
831 }
832 hexdump(result, dlen);
833 printk("%s (ratio %d:%d)\n",
834 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
835 ilen, dlen);
836 }
837
838 printk("\ntesting deflate decompression\n");
839
840 tsize = sizeof (deflate_decomp_tv_template);
841 if (tsize > TVMEMSIZE) {
842 printk("template (%u) too big for tvmem (%u)\n", tsize,
843 TVMEMSIZE);
844 goto out;
845 }
846
847 memcpy(tvmem, deflate_decomp_tv_template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700848 tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
850 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
851 int ilen, ret, dlen = COMP_BUF_SIZE;
Herbert Xuef2736f2005-06-22 13:26:03 -0700852
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 printk("test %u:\n", i + 1);
854 memset(result, 0, sizeof (result));
855
856 ilen = tv[i].inlen;
857 ret = crypto_comp_decompress(tfm, tv[i].input,
858 ilen, result, &dlen);
859 if (ret) {
860 printk("fail: ret=%d\n", ret);
861 continue;
862 }
863 hexdump(result, dlen);
864 printk("%s (ratio %d:%d)\n",
865 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
866 ilen, dlen);
867 }
868out:
Herbert Xue4d5b792006-08-26 18:12:40 +1000869 crypto_free_comp(tfm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870}
871
Herbert Xuef2736f2005-06-22 13:26:03 -0700872static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873{
874 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -0700875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 while (*name) {
877 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +1000878 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +1000879 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700881 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882}
883
Herbert Xuef2736f2005-06-22 13:26:03 -0700884static void do_test(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
886 switch (mode) {
887
888 case 0:
889 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 //DES
Herbert Xucba83562006-08-13 08:26:09 +1000894 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
895 DES_ENC_TEST_VECTORS);
896 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
897 DES_DEC_TEST_VECTORS);
898 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
899 DES_CBC_ENC_TEST_VECTORS);
900 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
901 DES_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700902
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 //DES3_EDE
Herbert Xucba83562006-08-13 08:26:09 +1000904 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
905 DES3_EDE_ENC_TEST_VECTORS);
906 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
907 DES3_EDE_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700908
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700912
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 //BLOWFISH
Herbert Xucba83562006-08-13 08:26:09 +1000914 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
915 BF_ENC_TEST_VECTORS);
916 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
917 BF_DEC_TEST_VECTORS);
918 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
919 BF_CBC_ENC_TEST_VECTORS);
920 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
921 BF_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 //TWOFISH
Herbert Xucba83562006-08-13 08:26:09 +1000924 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
925 TF_ENC_TEST_VECTORS);
926 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
927 TF_DEC_TEST_VECTORS);
928 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
929 TF_CBC_ENC_TEST_VECTORS);
930 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
931 TF_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700932
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 //SERPENT
Herbert Xucba83562006-08-13 08:26:09 +1000934 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
935 SERPENT_ENC_TEST_VECTORS);
936 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
937 SERPENT_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 //TNEPRES
Herbert Xucba83562006-08-13 08:26:09 +1000940 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
941 TNEPRES_ENC_TEST_VECTORS);
942 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
943 TNEPRES_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
945 //AES
Herbert Xucba83562006-08-13 08:26:09 +1000946 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
947 AES_ENC_TEST_VECTORS);
948 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
949 AES_DEC_TEST_VECTORS);
950 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
951 AES_CBC_ENC_TEST_VECTORS);
952 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
953 AES_CBC_DEC_TEST_VECTORS);
Rik Snelf3d10442006-11-29 19:01:41 +1100954 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
955 AES_LRW_ENC_TEST_VECTORS);
956 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
957 AES_LRW_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
959 //CAST5
Herbert Xucba83562006-08-13 08:26:09 +1000960 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
961 CAST5_ENC_TEST_VECTORS);
962 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
963 CAST5_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700964
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 //CAST6
Herbert Xucba83562006-08-13 08:26:09 +1000966 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
967 CAST6_ENC_TEST_VECTORS);
968 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
969 CAST6_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
971 //ARC4
Herbert Xucba83562006-08-13 08:26:09 +1000972 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
973 ARC4_ENC_TEST_VECTORS);
974 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
975 ARC4_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 //TEA
Herbert Xucba83562006-08-13 08:26:09 +1000978 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
979 TEA_ENC_TEST_VECTORS);
980 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
981 TEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983
984 //XTEA
Herbert Xucba83562006-08-13 08:26:09 +1000985 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
986 XTEA_ENC_TEST_VECTORS);
987 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
988 XTEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
990 //KHAZAD
Herbert Xucba83562006-08-13 08:26:09 +1000991 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
992 KHAZAD_ENC_TEST_VECTORS);
993 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
994 KHAZAD_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
996 //ANUBIS
Herbert Xucba83562006-08-13 08:26:09 +1000997 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
998 ANUBIS_ENC_TEST_VECTORS);
999 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1000 ANUBIS_DEC_TEST_VECTORS);
1001 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1002 ANUBIS_CBC_ENC_TEST_VECTORS);
1003 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1004 ANUBIS_CBC_ENC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001006 //XETA
Herbert Xucba83562006-08-13 08:26:09 +10001007 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1008 XETA_ENC_TEST_VECTORS);
1009 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1010 XETA_DEC_TEST_VECTORS);
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001011
David Howells90831632006-12-16 12:13:14 +11001012 //FCrypt
1013 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1014 FCRYPT_ENC_TEST_VECTORS);
1015 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1016 FCRYPT_DEC_TEST_VECTORS);
1017
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001018 //CAMELLIA
1019 test_cipher("ecb(camellia)", ENCRYPT,
1020 camellia_enc_tv_template,
1021 CAMELLIA_ENC_TEST_VECTORS);
1022 test_cipher("ecb(camellia)", DECRYPT,
1023 camellia_dec_tv_template,
1024 CAMELLIA_DEC_TEST_VECTORS);
1025 test_cipher("cbc(camellia)", ENCRYPT,
1026 camellia_cbc_enc_tv_template,
1027 CAMELLIA_CBC_ENC_TEST_VECTORS);
1028 test_cipher("cbc(camellia)", DECRYPT,
1029 camellia_cbc_dec_tv_template,
1030 CAMELLIA_CBC_DEC_TEST_VECTORS);
1031
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1033 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1034 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1035 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1036 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1037 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1038 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1039 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1040 test_deflate();
Herbert Xuc907ee72006-08-21 22:04:03 +10001041 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
Herbert Xue9d41162006-08-19 21:38:49 +10001042 test_hash("hmac(md5)", hmac_md5_tv_template,
1043 HMAC_MD5_TEST_VECTORS);
1044 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1045 HMAC_SHA1_TEST_VECTORS);
1046 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1047 HMAC_SHA256_TEST_VECTORS);
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001048 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1049 HMAC_SHA384_TEST_VECTORS);
1050 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1051 HMAC_SHA512_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
Kazunori MIYAZAWA5b2becf2006-10-28 13:18:53 +10001053 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1054 XCBC_AES_TEST_VECTORS);
1055
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1057 break;
1058
1059 case 1:
1060 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1061 break;
1062
1063 case 2:
1064 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1065 break;
1066
1067 case 3:
Herbert Xucba83562006-08-13 08:26:09 +10001068 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1069 DES_ENC_TEST_VECTORS);
1070 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1071 DES_DEC_TEST_VECTORS);
1072 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1073 DES_CBC_ENC_TEST_VECTORS);
1074 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1075 DES_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 break;
1077
1078 case 4:
Herbert Xucba83562006-08-13 08:26:09 +10001079 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1080 DES3_EDE_ENC_TEST_VECTORS);
1081 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1082 DES3_EDE_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 break;
1084
1085 case 5:
1086 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1087 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001088
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 case 6:
1090 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1091 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001092
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 case 7:
Herbert Xucba83562006-08-13 08:26:09 +10001094 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1095 BF_ENC_TEST_VECTORS);
1096 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1097 BF_DEC_TEST_VECTORS);
1098 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1099 BF_CBC_ENC_TEST_VECTORS);
1100 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1101 BF_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 break;
1103
1104 case 8:
Herbert Xucba83562006-08-13 08:26:09 +10001105 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1106 TF_ENC_TEST_VECTORS);
1107 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1108 TF_DEC_TEST_VECTORS);
1109 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1110 TF_CBC_ENC_TEST_VECTORS);
1111 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1112 TF_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001114
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 case 9:
Herbert Xucba83562006-08-13 08:26:09 +10001116 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1117 SERPENT_ENC_TEST_VECTORS);
1118 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1119 SERPENT_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 break;
1121
1122 case 10:
Herbert Xucba83562006-08-13 08:26:09 +10001123 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1124 AES_ENC_TEST_VECTORS);
1125 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1126 AES_DEC_TEST_VECTORS);
1127 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1128 AES_CBC_ENC_TEST_VECTORS);
1129 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1130 AES_CBC_DEC_TEST_VECTORS);
Rik Snelf3d10442006-11-29 19:01:41 +11001131 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1132 AES_LRW_ENC_TEST_VECTORS);
1133 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1134 AES_LRW_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 break;
1136
1137 case 11:
1138 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1139 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001140
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 case 12:
1142 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1143 break;
1144
1145 case 13:
1146 test_deflate();
1147 break;
1148
1149 case 14:
Herbert Xucba83562006-08-13 08:26:09 +10001150 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1151 CAST5_ENC_TEST_VECTORS);
1152 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1153 CAST5_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 break;
1155
1156 case 15:
Herbert Xucba83562006-08-13 08:26:09 +10001157 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1158 CAST6_ENC_TEST_VECTORS);
1159 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1160 CAST6_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 break;
1162
1163 case 16:
Herbert Xucba83562006-08-13 08:26:09 +10001164 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1165 ARC4_ENC_TEST_VECTORS);
1166 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1167 ARC4_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 break;
1169
1170 case 17:
1171 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1172 break;
1173
1174 case 18:
Herbert Xuc907ee72006-08-21 22:04:03 +10001175 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 break;
1177
1178 case 19:
Herbert Xucba83562006-08-13 08:26:09 +10001179 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1180 TEA_ENC_TEST_VECTORS);
1181 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1182 TEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 break;
1184
1185 case 20:
Herbert Xucba83562006-08-13 08:26:09 +10001186 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1187 XTEA_ENC_TEST_VECTORS);
1188 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1189 XTEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 break;
1191
1192 case 21:
Herbert Xucba83562006-08-13 08:26:09 +10001193 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1194 KHAZAD_ENC_TEST_VECTORS);
1195 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1196 KHAZAD_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 break;
1198
1199 case 22:
1200 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1201 break;
1202
1203 case 23:
1204 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1205 break;
1206
1207 case 24:
1208 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1209 break;
1210
1211 case 25:
Herbert Xucba83562006-08-13 08:26:09 +10001212 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1213 TNEPRES_ENC_TEST_VECTORS);
1214 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1215 TNEPRES_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 break;
1217
1218 case 26:
Herbert Xucba83562006-08-13 08:26:09 +10001219 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1220 ANUBIS_ENC_TEST_VECTORS);
1221 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1222 ANUBIS_DEC_TEST_VECTORS);
1223 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1224 ANUBIS_CBC_ENC_TEST_VECTORS);
1225 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1226 ANUBIS_CBC_ENC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 break;
1228
1229 case 27:
1230 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1231 break;
1232
1233 case 28:
1234
1235 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1236 break;
1237
1238 case 29:
1239 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1240 break;
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001241
1242 case 30:
Herbert Xucba83562006-08-13 08:26:09 +10001243 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1244 XETA_ENC_TEST_VECTORS);
1245 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1246 XETA_DEC_TEST_VECTORS);
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001247 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
David Howells90831632006-12-16 12:13:14 +11001249 case 31:
1250 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1251 FCRYPT_ENC_TEST_VECTORS);
1252 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1253 FCRYPT_DEC_TEST_VECTORS);
1254 break;
1255
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001256 case 32:
1257 test_cipher("ecb(camellia)", ENCRYPT,
1258 camellia_enc_tv_template,
1259 CAMELLIA_ENC_TEST_VECTORS);
1260 test_cipher("ecb(camellia)", DECRYPT,
1261 camellia_dec_tv_template,
1262 CAMELLIA_DEC_TEST_VECTORS);
1263 test_cipher("cbc(camellia)", ENCRYPT,
1264 camellia_cbc_enc_tv_template,
1265 CAMELLIA_CBC_ENC_TEST_VECTORS);
1266 test_cipher("cbc(camellia)", DECRYPT,
1267 camellia_cbc_dec_tv_template,
1268 CAMELLIA_CBC_DEC_TEST_VECTORS);
1269 break;
1270
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 case 100:
Herbert Xue9d41162006-08-19 21:38:49 +10001272 test_hash("hmac(md5)", hmac_md5_tv_template,
1273 HMAC_MD5_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001275
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 case 101:
Herbert Xue9d41162006-08-19 21:38:49 +10001277 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1278 HMAC_SHA1_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001280
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 case 102:
Herbert Xue9d41162006-08-19 21:38:49 +10001282 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1283 HMAC_SHA256_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 break;
1285
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001286 case 103:
1287 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1288 HMAC_SHA384_TEST_VECTORS);
1289 break;
1290
1291 case 104:
1292 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1293 HMAC_SHA512_TEST_VECTORS);
1294 break;
1295
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
Harald Welteebfd9bc2005-06-22 13:27:23 -07001297 case 200:
Herbert Xucba83562006-08-13 08:26:09 +10001298 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001299 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001300 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001301 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001302 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001303 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001304 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001305 aes_speed_template);
Rik Snelf3d10442006-11-29 19:01:41 +11001306 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1307 aes_lrw_speed_template);
1308 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1309 aes_lrw_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001310 break;
1311
1312 case 201:
Herbert Xucba83562006-08-13 08:26:09 +10001313 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001314 des3_ede_enc_tv_template,
1315 DES3_EDE_ENC_TEST_VECTORS,
1316 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001317 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001318 des3_ede_dec_tv_template,
1319 DES3_EDE_DEC_TEST_VECTORS,
1320 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001321 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001322 des3_ede_enc_tv_template,
1323 DES3_EDE_ENC_TEST_VECTORS,
1324 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001325 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001326 des3_ede_dec_tv_template,
1327 DES3_EDE_DEC_TEST_VECTORS,
1328 des3_ede_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001329 break;
1330
1331 case 202:
Herbert Xucba83562006-08-13 08:26:09 +10001332 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001333 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001334 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001335 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001336 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001337 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001338 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001339 twofish_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001340 break;
1341
1342 case 203:
Herbert Xucba83562006-08-13 08:26:09 +10001343 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001344 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001345 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001346 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001347 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001348 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001349 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001350 blowfish_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001351 break;
1352
1353 case 204:
Herbert Xucba83562006-08-13 08:26:09 +10001354 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001355 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001356 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001357 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001358 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001359 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001360 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001361 des_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001362 break;
1363
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001364 case 205:
1365 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1366 camellia_speed_template);
1367 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1368 camellia_speed_template);
1369 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1370 camellia_speed_template);
1371 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1372 camellia_speed_template);
1373 break;
1374
Michal Ludvige8057922006-05-30 22:04:19 +10001375 case 300:
1376 /* fall through */
1377
1378 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +10001379 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001380 if (mode > 300 && mode < 400) break;
1381
1382 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +10001383 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001384 if (mode > 300 && mode < 400) break;
1385
1386 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +10001387 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001388 if (mode > 300 && mode < 400) break;
1389
1390 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +10001391 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001392 if (mode > 300 && mode < 400) break;
1393
1394 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +10001395 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001396 if (mode > 300 && mode < 400) break;
1397
1398 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +10001399 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001400 if (mode > 300 && mode < 400) break;
1401
1402 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +10001403 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001404 if (mode > 300 && mode < 400) break;
1405
1406 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +10001407 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001408 if (mode > 300 && mode < 400) break;
1409
1410 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +10001411 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001412 if (mode > 300 && mode < 400) break;
1413
1414 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +10001415 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001416 if (mode > 300 && mode < 400) break;
1417
1418 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +10001419 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001420 if (mode > 300 && mode < 400) break;
1421
1422 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +10001423 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001424 if (mode > 300 && mode < 400) break;
1425
1426 case 399:
1427 break;
1428
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 case 1000:
1430 test_available();
1431 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001432
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 default:
1434 /* useful for debugging */
1435 printk("not testing anything\n");
1436 break;
1437 }
1438}
1439
Herbert Xuef2736f2005-06-22 13:26:03 -07001440static int __init init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441{
1442 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1443 if (tvmem == NULL)
1444 return -ENOMEM;
1445
1446 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1447 if (xbuf == NULL) {
1448 kfree(tvmem);
1449 return -ENOMEM;
1450 }
1451
1452 do_test();
1453
1454 kfree(xbuf);
1455 kfree(tvmem);
Michal Ludvig14fdf472006-05-30 14:49:38 +10001456
1457 /* We intentionaly return -EAGAIN to prevent keeping
1458 * the module. It does all its work from init()
1459 * and doesn't offer any runtime functionality
1460 * => we don't need it in the memory, do we?
1461 * -- mludvig
1462 */
1463 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464}
1465
1466/*
1467 * If an init function is provided, an exit function must also be provided
1468 * to allow module unload.
1469 */
1470static void __exit fini(void) { }
1471
1472module_init(init);
1473module_exit(fini);
1474
1475module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001476module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -07001477MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1478 "(defaults to zero which uses CPU cycles instead)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
1480MODULE_LICENSE("GPL");
1481MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1482MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");