blob: 4d364ccacbb29643d322a40e609a78e3bbbdbf8c [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 *
Jonathan Lynchcd12fb92007-11-10 20:08:25 +080015 * 2007-11-06 Added SHA-224 and SHA-224-HMAC tests
Andrew Donofrioa28091a2006-12-10 12:10:20 +110016 * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests
Harald Welteebfd9bc2005-06-22 13:27:23 -070017 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
18 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
19 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 */
21
Herbert Xucba83562006-08-13 08:26:09 +100022#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/init.h>
24#include <linux/module.h>
25#include <linux/mm.h>
26#include <linux/slab.h>
David Hardeman378f0582005-09-17 17:55:31 +100027#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/string.h>
29#include <linux/crypto.h>
30#include <linux/highmem.h>
31#include <linux/moduleparam.h>
Harald Welteebfd9bc2005-06-22 13:27:23 -070032#include <linux/jiffies.h>
Herbert Xu6a179442005-06-22 13:29:03 -070033#include <linux/timex.h>
34#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include "tcrypt.h"
36
37/*
38 * Need to kmalloc() memory for testing kmap().
39 */
Harald Welteebfd9bc2005-06-22 13:27:23 -070040#define TVMEMSIZE 16384
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define XBUFSIZE 32768
42
43/*
44 * Indexes into the xbuf to simulate cross-page access.
45 */
46#define IDX1 37
47#define IDX2 32400
48#define IDX3 1
49#define IDX4 8193
50#define IDX5 22222
51#define IDX6 17101
52#define IDX7 27333
53#define IDX8 3000
54
55/*
56* Used by test_cipher()
57*/
58#define ENCRYPT 1
59#define DECRYPT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Herbert Xu6158efc2007-04-04 17:41:07 +100061struct tcrypt_result {
62 struct completion completion;
63 int err;
64};
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
67
Harald Welteebfd9bc2005-06-22 13:27:23 -070068/*
69 * Used by test_cipher_speed()
70 */
Herbert Xu6a179442005-06-22 13:29:03 -070071static unsigned int sec;
Harald Welteebfd9bc2005-06-22 13:27:23 -070072
Linus Torvalds1da177e2005-04-16 15:20:36 -070073static int mode;
74static char *xbuf;
75static char *tvmem;
76
77static char *check[] = {
Jonathan Lynchcd12fb92007-11-10 20:08:25 +080078 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
79 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
80 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
Herbert Xuef2736f2005-06-22 13:26:03 -070081 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
David Howells90831632006-12-16 12:13:14 +110082 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
Hye-Shik Change2ee95b2007-08-21 20:01:03 +080083 "camellia", "seed", NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070084};
85
Herbert Xuef2736f2005-06-22 13:26:03 -070086static void hexdump(unsigned char *buf, unsigned int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
88 while (len--)
89 printk("%02x", *buf++);
90
91 printk("\n");
92}
93
Herbert Xu6158efc2007-04-04 17:41:07 +100094static void tcrypt_complete(struct crypto_async_request *req, int err)
95{
96 struct tcrypt_result *res = req->data;
97
98 if (err == -EINPROGRESS)
99 return;
100
101 res->err = err;
102 complete(&res->completion);
103}
104
Herbert Xuef2736f2005-06-22 13:26:03 -0700105static void test_hash(char *algo, struct hash_testvec *template,
106 unsigned int tcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
Herbert Xuef2736f2005-06-22 13:26:03 -0700108 unsigned int i, j, k, temp;
109 struct scatterlist sg[8];
110 char result[64];
Herbert Xue9d41162006-08-19 21:38:49 +1000111 struct crypto_hash *tfm;
112 struct hash_desc desc;
Herbert Xuef2736f2005-06-22 13:26:03 -0700113 struct hash_testvec *hash_tv;
114 unsigned int tsize;
Herbert Xue9d41162006-08-19 21:38:49 +1000115 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Herbert Xuef2736f2005-06-22 13:26:03 -0700117 printk("\ntesting %s\n", algo);
118
119 tsize = sizeof(struct hash_testvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 tsize *= tcount;
Herbert Xuef2736f2005-06-22 13:26:03 -0700121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 if (tsize > TVMEMSIZE) {
123 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
124 return;
125 }
126
127 memcpy(tvmem, template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700128 hash_tv = (void *)tvmem;
Herbert Xue9d41162006-08-19 21:38:49 +1000129
130 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
131 if (IS_ERR(tfm)) {
132 printk("failed to load transform for %s: %ld\n", algo,
133 PTR_ERR(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 return;
135 }
136
Herbert Xue9d41162006-08-19 21:38:49 +1000137 desc.tfm = tfm;
138 desc.flags = 0;
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 for (i = 0; i < tcount; i++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700141 printk("test %u:\n", i + 1);
142 memset(result, 0, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
David S. Millerb7335882007-10-26 00:38:10 -0700144 sg_init_one(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Herbert Xue9d41162006-08-19 21:38:49 +1000146 if (hash_tv[i].ksize) {
147 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
148 hash_tv[i].ksize);
149 if (ret) {
150 printk("setkey() failed ret=%d\n", ret);
151 goto out;
152 }
153 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Herbert Xue9d41162006-08-19 21:38:49 +1000155 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, result);
156 if (ret) {
157 printk("digest () failed ret=%d\n", ret);
158 goto out;
159 }
160
161 hexdump(result, crypto_hash_digestsize(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 printk("%s\n",
Herbert Xuef2736f2005-06-22 13:26:03 -0700163 memcmp(result, hash_tv[i].digest,
Herbert Xue9d41162006-08-19 21:38:49 +1000164 crypto_hash_digestsize(tfm)) ?
Herbert Xuef2736f2005-06-22 13:26:03 -0700165 "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 }
167
Herbert Xuef2736f2005-06-22 13:26:03 -0700168 printk("testing %s across pages\n", algo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 /* setup the dummy buffer first */
Herbert Xuef2736f2005-06-22 13:26:03 -0700171 memset(xbuf, 0, XBUFSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 j = 0;
174 for (i = 0; i < tcount; i++) {
175 if (hash_tv[i].np) {
176 j++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700177 printk("test %u:\n", j);
178 memset(result, 0, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 temp = 0;
David S. Millerb7335882007-10-26 00:38:10 -0700181 sg_init_table(sg, hash_tv[i].np);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 for (k = 0; k < hash_tv[i].np; k++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700183 memcpy(&xbuf[IDX[k]],
184 hash_tv[i].plaintext + temp,
185 hash_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 temp += hash_tv[i].tap[k];
David Hardeman378f0582005-09-17 17:55:31 +1000187 sg_set_buf(&sg[k], &xbuf[IDX[k]],
188 hash_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 }
190
Herbert Xue9d41162006-08-19 21:38:49 +1000191 if (hash_tv[i].ksize) {
192 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
193 hash_tv[i].ksize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700194
Herbert Xue9d41162006-08-19 21:38:49 +1000195 if (ret) {
196 printk("setkey() failed ret=%d\n", ret);
197 goto out;
198 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 }
200
Herbert Xue9d41162006-08-19 21:38:49 +1000201 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize,
202 result);
203 if (ret) {
204 printk("digest () failed ret=%d\n", ret);
205 goto out;
206 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700207
Herbert Xue9d41162006-08-19 21:38:49 +1000208 hexdump(result, crypto_hash_digestsize(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 printk("%s\n",
Herbert Xue9d41162006-08-19 21:38:49 +1000210 memcmp(result, hash_tv[i].digest,
211 crypto_hash_digestsize(tfm)) ?
Herbert Xuef2736f2005-06-22 13:26:03 -0700212 "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 }
214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Herbert Xue9d41162006-08-19 21:38:49 +1000216out:
217 crypto_free_hash(tfm);
218}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Herbert Xucba83562006-08-13 08:26:09 +1000220static void test_cipher(char *algo, int enc,
Herbert Xuef2736f2005-06-22 13:26:03 -0700221 struct cipher_testvec *template, unsigned int tcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
223 unsigned int ret, i, j, k, temp;
224 unsigned int tsize;
David Hardeman378f0582005-09-17 17:55:31 +1000225 char *q;
Herbert Xu6158efc2007-04-04 17:41:07 +1000226 struct crypto_ablkcipher *tfm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 char *key;
228 struct cipher_testvec *cipher_tv;
Herbert Xu6158efc2007-04-04 17:41:07 +1000229 struct ablkcipher_request *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 struct scatterlist sg[8];
Herbert Xucba83562006-08-13 08:26:09 +1000231 const char *e;
Herbert Xu6158efc2007-04-04 17:41:07 +1000232 struct tcrypt_result result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234 if (enc == ENCRYPT)
Herbert Xu3cc38162005-06-22 13:26:36 -0700235 e = "encryption";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 else
Herbert Xu3cc38162005-06-22 13:26:36 -0700237 e = "decryption";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Herbert Xucba83562006-08-13 08:26:09 +1000239 printk("\ntesting %s %s\n", algo, e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Herbert Xuef2736f2005-06-22 13:26:03 -0700241 tsize = sizeof (struct cipher_testvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 tsize *= tcount;
Herbert Xuef2736f2005-06-22 13:26:03 -0700243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 if (tsize > TVMEMSIZE) {
245 printk("template (%u) too big for tvmem (%u)\n", tsize,
246 TVMEMSIZE);
247 return;
248 }
249
250 memcpy(tvmem, template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700251 cipher_tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Herbert Xu6158efc2007-04-04 17:41:07 +1000253 init_completion(&result.completion);
254
255 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
Herbert Xuef2736f2005-06-22 13:26:03 -0700256
Herbert Xucba83562006-08-13 08:26:09 +1000257 if (IS_ERR(tfm)) {
258 printk("failed to load transform for %s: %ld\n", algo,
259 PTR_ERR(tfm));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 return;
261 }
Herbert Xu6158efc2007-04-04 17:41:07 +1000262
263 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
264 if (!req) {
265 printk("failed to allocate request for %s\n", algo);
266 goto out;
267 }
268
269 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
270 tcrypt_complete, &result);
Herbert Xuef2736f2005-06-22 13:26:03 -0700271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 j = 0;
273 for (i = 0; i < tcount; i++) {
274 if (!(cipher_tv[i].np)) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700275 j++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 printk("test %u (%d bit key):\n",
277 j, cipher_tv[i].klen * 8);
278
Herbert Xu6158efc2007-04-04 17:41:07 +1000279 crypto_ablkcipher_clear_flags(tfm, ~0);
Herbert Xuef2736f2005-06-22 13:26:03 -0700280 if (cipher_tv[i].wk)
Herbert Xu6158efc2007-04-04 17:41:07 +1000281 crypto_ablkcipher_set_flags(
Herbert Xucba83562006-08-13 08:26:09 +1000282 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 key = cipher_tv[i].key;
Herbert Xuef2736f2005-06-22 13:26:03 -0700284
Herbert Xu6158efc2007-04-04 17:41:07 +1000285 ret = crypto_ablkcipher_setkey(tfm, key,
286 cipher_tv[i].klen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000288 printk("setkey() failed flags=%x\n",
Herbert Xu6158efc2007-04-04 17:41:07 +1000289 crypto_ablkcipher_get_flags(tfm));
Herbert Xuef2736f2005-06-22 13:26:03 -0700290
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 if (!cipher_tv[i].fail)
292 goto out;
Herbert Xuef2736f2005-06-22 13:26:03 -0700293 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
David S. Millerb7335882007-10-26 00:38:10 -0700295 sg_init_one(&sg[0], cipher_tv[i].input,
296 cipher_tv[i].ilen);
Herbert Xuef2736f2005-06-22 13:26:03 -0700297
Herbert Xu6158efc2007-04-04 17:41:07 +1000298 ablkcipher_request_set_crypt(req, sg, sg,
299 cipher_tv[i].ilen,
300 cipher_tv[i].iv);
Herbert Xuef2736f2005-06-22 13:26:03 -0700301
Herbert Xucba83562006-08-13 08:26:09 +1000302 ret = enc ?
Herbert Xu6158efc2007-04-04 17:41:07 +1000303 crypto_ablkcipher_encrypt(req) :
304 crypto_ablkcipher_decrypt(req);
Herbert Xuef2736f2005-06-22 13:26:03 -0700305
Herbert Xu6158efc2007-04-04 17:41:07 +1000306 switch (ret) {
307 case 0:
308 break;
309 case -EINPROGRESS:
310 case -EBUSY:
311 ret = wait_for_completion_interruptible(
312 &result.completion);
313 if (!ret && !((ret = result.err))) {
314 INIT_COMPLETION(result.completion);
315 break;
316 }
317 /* fall through */
318 default:
319 printk("%s () failed err=%d\n", e, -ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 goto out;
Herbert Xuef2736f2005-06-22 13:26:03 -0700321 }
322
Jens Axboe78c2f0b2007-10-22 19:40:16 +0200323 q = kmap(sg_page(&sg[0])) + sg[0].offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 hexdump(q, cipher_tv[i].rlen);
Herbert Xuef2736f2005-06-22 13:26:03 -0700325
326 printk("%s\n",
327 memcmp(q, cipher_tv[i].result,
328 cipher_tv[i].rlen) ? "fail" : "pass");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 }
330 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700331
Herbert Xucba83562006-08-13 08:26:09 +1000332 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 memset(xbuf, 0, XBUFSIZE);
Herbert Xuef2736f2005-06-22 13:26:03 -0700334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 j = 0;
336 for (i = 0; i < tcount; i++) {
337 if (cipher_tv[i].np) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700338 j++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 printk("test %u (%d bit key):\n",
340 j, cipher_tv[i].klen * 8);
341
Herbert Xu6158efc2007-04-04 17:41:07 +1000342 crypto_ablkcipher_clear_flags(tfm, ~0);
Herbert Xuef2736f2005-06-22 13:26:03 -0700343 if (cipher_tv[i].wk)
Herbert Xu6158efc2007-04-04 17:41:07 +1000344 crypto_ablkcipher_set_flags(
Herbert Xucba83562006-08-13 08:26:09 +1000345 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 key = cipher_tv[i].key;
Herbert Xuef2736f2005-06-22 13:26:03 -0700347
Herbert Xu6158efc2007-04-04 17:41:07 +1000348 ret = crypto_ablkcipher_setkey(tfm, key,
349 cipher_tv[i].klen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000351 printk("setkey() failed flags=%x\n",
Herbert Xu6158efc2007-04-04 17:41:07 +1000352 crypto_ablkcipher_get_flags(tfm));
Herbert Xuef2736f2005-06-22 13:26:03 -0700353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 if (!cipher_tv[i].fail)
355 goto out;
356 }
357
358 temp = 0;
David S. Millerb7335882007-10-26 00:38:10 -0700359 sg_init_table(sg, cipher_tv[i].np);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 for (k = 0; k < cipher_tv[i].np; k++) {
Herbert Xuef2736f2005-06-22 13:26:03 -0700361 memcpy(&xbuf[IDX[k]],
362 cipher_tv[i].input + temp,
363 cipher_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 temp += cipher_tv[i].tap[k];
David Hardeman378f0582005-09-17 17:55:31 +1000365 sg_set_buf(&sg[k], &xbuf[IDX[k]],
366 cipher_tv[i].tap[k]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 }
Herbert Xuef2736f2005-06-22 13:26:03 -0700368
Herbert Xu6158efc2007-04-04 17:41:07 +1000369 ablkcipher_request_set_crypt(req, sg, sg,
370 cipher_tv[i].ilen,
371 cipher_tv[i].iv);
Herbert Xuef2736f2005-06-22 13:26:03 -0700372
Herbert Xucba83562006-08-13 08:26:09 +1000373 ret = enc ?
Herbert Xu6158efc2007-04-04 17:41:07 +1000374 crypto_ablkcipher_encrypt(req) :
375 crypto_ablkcipher_decrypt(req);
Herbert Xuef2736f2005-06-22 13:26:03 -0700376
Herbert Xu6158efc2007-04-04 17:41:07 +1000377 switch (ret) {
378 case 0:
379 break;
380 case -EINPROGRESS:
381 case -EBUSY:
382 ret = wait_for_completion_interruptible(
383 &result.completion);
384 if (!ret && !((ret = result.err))) {
385 INIT_COMPLETION(result.completion);
386 break;
387 }
388 /* fall through */
389 default:
390 printk("%s () failed err=%d\n", e, -ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 goto out;
392 }
393
394 temp = 0;
395 for (k = 0; k < cipher_tv[i].np; k++) {
396 printk("page %u\n", k);
Jens Axboe78c2f0b2007-10-22 19:40:16 +0200397 q = kmap(sg_page(&sg[k])) + sg[k].offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 hexdump(q, cipher_tv[i].tap[k]);
Herbert Xuef2736f2005-06-22 13:26:03 -0700399 printk("%s\n",
400 memcmp(q, cipher_tv[i].result + temp,
401 cipher_tv[i].tap[k]) ? "fail" :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 "pass");
403 temp += cipher_tv[i].tap[k];
404 }
405 }
406 }
407
408out:
Herbert Xu6158efc2007-04-04 17:41:07 +1000409 crypto_free_ablkcipher(tfm);
410 ablkcipher_request_free(req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
412
Herbert Xucba83562006-08-13 08:26:09 +1000413static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
Herbert Xu6a179442005-06-22 13:29:03 -0700414 int blen, int sec)
415{
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000416 struct scatterlist sg[1];
Herbert Xu6a179442005-06-22 13:29:03 -0700417 unsigned long start, end;
418 int bcount;
419 int ret;
420
David S. Millerb7335882007-10-26 00:38:10 -0700421 sg_init_one(sg, p, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700422
423 for (start = jiffies, end = start + sec * HZ, bcount = 0;
424 time_before(jiffies, end); bcount++) {
425 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000426 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700427 else
Herbert Xucba83562006-08-13 08:26:09 +1000428 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700429
430 if (ret)
431 return ret;
432 }
433
434 printk("%d operations in %d seconds (%ld bytes)\n",
435 bcount, sec, (long)bcount * blen);
436 return 0;
437}
438
Herbert Xucba83562006-08-13 08:26:09 +1000439static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
Herbert Xu6a179442005-06-22 13:29:03 -0700440 int blen)
441{
Herbert Xu6df5b9f2005-09-19 22:30:11 +1000442 struct scatterlist sg[1];
Herbert Xu6a179442005-06-22 13:29:03 -0700443 unsigned long cycles = 0;
444 int ret = 0;
445 int i;
446
David S. Millerb7335882007-10-26 00:38:10 -0700447 sg_init_one(sg, p, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700448
449 local_bh_disable();
450 local_irq_disable();
451
452 /* Warm-up run. */
453 for (i = 0; i < 4; i++) {
454 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000455 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700456 else
Herbert Xucba83562006-08-13 08:26:09 +1000457 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700458
459 if (ret)
460 goto out;
461 }
462
463 /* The real thing. */
464 for (i = 0; i < 8; i++) {
465 cycles_t start, end;
466
467 start = get_cycles();
468 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000469 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700470 else
Herbert Xucba83562006-08-13 08:26:09 +1000471 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700472 end = get_cycles();
473
474 if (ret)
475 goto out;
476
477 cycles += end - start;
478 }
479
480out:
481 local_irq_enable();
482 local_bh_enable();
483
484 if (ret == 0)
485 printk("1 operation in %lu cycles (%d bytes)\n",
486 (cycles + 4) / 8, blen);
487
488 return ret;
489}
490
Herbert Xucba83562006-08-13 08:26:09 +1000491static void test_cipher_speed(char *algo, int enc, unsigned int sec,
Herbert Xudce907c2005-06-22 13:27:51 -0700492 struct cipher_testvec *template,
493 unsigned int tcount, struct cipher_speed *speed)
Harald Welteebfd9bc2005-06-22 13:27:23 -0700494{
Herbert Xudce907c2005-06-22 13:27:51 -0700495 unsigned int ret, i, j, iv_len;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700496 unsigned char *key, *p, iv[128];
Herbert Xucba83562006-08-13 08:26:09 +1000497 struct crypto_blkcipher *tfm;
498 struct blkcipher_desc desc;
499 const char *e;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700500
501 if (enc == ENCRYPT)
502 e = "encryption";
503 else
504 e = "decryption";
Harald Welteebfd9bc2005-06-22 13:27:23 -0700505
Herbert Xucba83562006-08-13 08:26:09 +1000506 printk("\ntesting speed of %s %s\n", algo, e);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700507
Herbert Xucba83562006-08-13 08:26:09 +1000508 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700509
Herbert Xucba83562006-08-13 08:26:09 +1000510 if (IS_ERR(tfm)) {
511 printk("failed to load transform for %s: %ld\n", algo,
512 PTR_ERR(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700513 return;
514 }
Herbert Xucba83562006-08-13 08:26:09 +1000515 desc.tfm = tfm;
516 desc.flags = 0;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700517
518 for (i = 0; speed[i].klen != 0; i++) {
519 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
520 printk("template (%u) too big for tvmem (%u)\n",
521 speed[i].blen + speed[i].klen, TVMEMSIZE);
522 goto out;
523 }
524
525 printk("test %u (%d bit key, %d byte blocks): ", i,
526 speed[i].klen * 8, speed[i].blen);
527
528 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
529
530 /* set key, plain text and IV */
531 key = (unsigned char *)tvmem;
Herbert Xudce907c2005-06-22 13:27:51 -0700532 for (j = 0; j < tcount; j++) {
533 if (template[j].klen == speed[i].klen) {
534 key = template[j].key;
535 break;
536 }
537 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700538 p = (unsigned char *)tvmem + speed[i].klen;
539
Herbert Xucba83562006-08-13 08:26:09 +1000540 ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700541 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000542 printk("setkey() failed flags=%x\n",
543 crypto_blkcipher_get_flags(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700544 goto out;
545 }
546
Herbert Xucba83562006-08-13 08:26:09 +1000547 iv_len = crypto_blkcipher_ivsize(tfm);
548 if (iv_len) {
Harald Welteebfd9bc2005-06-22 13:27:23 -0700549 memset(&iv, 0xff, iv_len);
Herbert Xucba83562006-08-13 08:26:09 +1000550 crypto_blkcipher_set_iv(tfm, iv, iv_len);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700551 }
552
Herbert Xu6a179442005-06-22 13:29:03 -0700553 if (sec)
Herbert Xucba83562006-08-13 08:26:09 +1000554 ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen,
Herbert Xu6a179442005-06-22 13:29:03 -0700555 sec);
556 else
Herbert Xucba83562006-08-13 08:26:09 +1000557 ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700558
Herbert Xu6a179442005-06-22 13:29:03 -0700559 if (ret) {
Herbert Xucba83562006-08-13 08:26:09 +1000560 printk("%s() failed flags=%x\n", e, desc.flags);
Herbert Xu6a179442005-06-22 13:29:03 -0700561 break;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700562 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700563 }
564
565out:
Herbert Xucba83562006-08-13 08:26:09 +1000566 crypto_free_blkcipher(tfm);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700567}
568
Herbert Xue9d41162006-08-19 21:38:49 +1000569static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
570 char *out, int sec)
Michal Ludvige8057922006-05-30 22:04:19 +1000571{
572 struct scatterlist sg[1];
573 unsigned long start, end;
Herbert Xue9d41162006-08-19 21:38:49 +1000574 int bcount;
575 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000576
Herbert Xua5a613a2007-10-27 00:51:21 -0700577 sg_init_table(sg, 1);
578
Michal Ludvige8057922006-05-30 22:04:19 +1000579 for (start = jiffies, end = start + sec * HZ, bcount = 0;
580 time_before(jiffies, end); bcount++) {
Herbert Xua5a613a2007-10-27 00:51:21 -0700581 sg_set_buf(sg, p, blen);
Herbert Xue9d41162006-08-19 21:38:49 +1000582 ret = crypto_hash_digest(desc, sg, blen, out);
583 if (ret)
584 return ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000585 }
586
587 printk("%6u opers/sec, %9lu bytes/sec\n",
588 bcount / sec, ((long)bcount * blen) / sec);
589
Herbert Xue9d41162006-08-19 21:38:49 +1000590 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000591}
592
Herbert Xue9d41162006-08-19 21:38:49 +1000593static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
594 int plen, char *out, int sec)
595{
596 struct scatterlist sg[1];
597 unsigned long start, end;
598 int bcount, pcount;
599 int ret;
600
601 if (plen == blen)
602 return test_hash_jiffies_digest(desc, p, blen, out, sec);
603
Herbert Xua5a613a2007-10-27 00:51:21 -0700604 sg_init_table(sg, 1);
605
Herbert Xue9d41162006-08-19 21:38:49 +1000606 for (start = jiffies, end = start + sec * HZ, bcount = 0;
607 time_before(jiffies, end); bcount++) {
608 ret = crypto_hash_init(desc);
609 if (ret)
610 return ret;
611 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xua5a613a2007-10-27 00:51:21 -0700612 sg_set_buf(sg, p + pcount, plen);
Herbert Xue9d41162006-08-19 21:38:49 +1000613 ret = crypto_hash_update(desc, sg, plen);
614 if (ret)
615 return ret;
616 }
617 /* we assume there is enough space in 'out' for the result */
618 ret = crypto_hash_final(desc, out);
619 if (ret)
620 return ret;
621 }
622
623 printk("%6u opers/sec, %9lu bytes/sec\n",
624 bcount / sec, ((long)bcount * blen) / sec);
625
626 return 0;
627}
628
629static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
630 char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000631{
632 struct scatterlist sg[1];
633 unsigned long cycles = 0;
Herbert Xue9d41162006-08-19 21:38:49 +1000634 int i;
635 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000636
Herbert Xua5a613a2007-10-27 00:51:21 -0700637 sg_init_table(sg, 1);
638
Michal Ludvige8057922006-05-30 22:04:19 +1000639 local_bh_disable();
640 local_irq_disable();
641
642 /* Warm-up run. */
643 for (i = 0; i < 4; i++) {
Herbert Xua5a613a2007-10-27 00:51:21 -0700644 sg_set_buf(sg, p, blen);
Herbert Xue9d41162006-08-19 21:38:49 +1000645 ret = crypto_hash_digest(desc, sg, blen, out);
646 if (ret)
647 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000648 }
649
650 /* The real thing. */
651 for (i = 0; i < 8; i++) {
652 cycles_t start, end;
653
Michal Ludvige8057922006-05-30 22:04:19 +1000654 start = get_cycles();
655
Herbert Xua5a613a2007-10-27 00:51:21 -0700656 sg_set_buf(sg, p, blen);
Herbert Xue9d41162006-08-19 21:38:49 +1000657 ret = crypto_hash_digest(desc, sg, blen, out);
658 if (ret)
659 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000660
661 end = get_cycles();
662
663 cycles += end - start;
664 }
665
Herbert Xue9d41162006-08-19 21:38:49 +1000666out:
Michal Ludvige8057922006-05-30 22:04:19 +1000667 local_irq_enable();
668 local_bh_enable();
669
Herbert Xue9d41162006-08-19 21:38:49 +1000670 if (ret)
671 return ret;
672
Michal Ludvige8057922006-05-30 22:04:19 +1000673 printk("%6lu cycles/operation, %4lu cycles/byte\n",
674 cycles / 8, cycles / (8 * blen));
675
Herbert Xue9d41162006-08-19 21:38:49 +1000676 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000677}
678
Herbert Xue9d41162006-08-19 21:38:49 +1000679static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
680 int plen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000681{
Herbert Xue9d41162006-08-19 21:38:49 +1000682 struct scatterlist sg[1];
683 unsigned long cycles = 0;
684 int i, pcount;
685 int ret;
686
687 if (plen == blen)
688 return test_hash_cycles_digest(desc, p, blen, out);
689
Herbert Xua5a613a2007-10-27 00:51:21 -0700690 sg_init_table(sg, 1);
691
Herbert Xue9d41162006-08-19 21:38:49 +1000692 local_bh_disable();
693 local_irq_disable();
694
695 /* Warm-up run. */
696 for (i = 0; i < 4; i++) {
697 ret = crypto_hash_init(desc);
698 if (ret)
699 goto out;
700 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xua5a613a2007-10-27 00:51:21 -0700701 sg_set_buf(sg, p + pcount, plen);
Herbert Xue9d41162006-08-19 21:38:49 +1000702 ret = crypto_hash_update(desc, sg, plen);
703 if (ret)
704 goto out;
705 }
Herbert Xu29059d12007-05-18 16:25:19 +1000706 ret = crypto_hash_final(desc, out);
Herbert Xue9d41162006-08-19 21:38:49 +1000707 if (ret)
708 goto out;
709 }
710
711 /* The real thing. */
712 for (i = 0; i < 8; i++) {
713 cycles_t start, end;
714
715 start = get_cycles();
716
717 ret = crypto_hash_init(desc);
718 if (ret)
719 goto out;
720 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xua5a613a2007-10-27 00:51:21 -0700721 sg_set_buf(sg, p + pcount, plen);
Herbert Xue9d41162006-08-19 21:38:49 +1000722 ret = crypto_hash_update(desc, sg, plen);
723 if (ret)
724 goto out;
725 }
726 ret = crypto_hash_final(desc, out);
727 if (ret)
728 goto out;
729
730 end = get_cycles();
731
732 cycles += end - start;
733 }
734
735out:
736 local_irq_enable();
737 local_bh_enable();
738
739 if (ret)
740 return ret;
741
742 printk("%6lu cycles/operation, %4lu cycles/byte\n",
743 cycles / 8, cycles / (8 * blen));
744
745 return 0;
746}
747
748static void test_hash_speed(char *algo, unsigned int sec,
749 struct hash_speed *speed)
750{
751 struct crypto_hash *tfm;
752 struct hash_desc desc;
Michal Ludvige8057922006-05-30 22:04:19 +1000753 char output[1024];
754 int i;
Herbert Xue9d41162006-08-19 21:38:49 +1000755 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000756
757 printk("\ntesting speed of %s\n", algo);
758
Herbert Xue9d41162006-08-19 21:38:49 +1000759 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
Michal Ludvige8057922006-05-30 22:04:19 +1000760
Herbert Xue9d41162006-08-19 21:38:49 +1000761 if (IS_ERR(tfm)) {
762 printk("failed to load transform for %s: %ld\n", algo,
763 PTR_ERR(tfm));
Michal Ludvige8057922006-05-30 22:04:19 +1000764 return;
765 }
766
Herbert Xue9d41162006-08-19 21:38:49 +1000767 desc.tfm = tfm;
768 desc.flags = 0;
769
770 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
Michal Ludvige8057922006-05-30 22:04:19 +1000771 printk("digestsize(%u) > outputbuffer(%zu)\n",
Herbert Xue9d41162006-08-19 21:38:49 +1000772 crypto_hash_digestsize(tfm), sizeof(output));
Michal Ludvige8057922006-05-30 22:04:19 +1000773 goto out;
774 }
775
776 for (i = 0; speed[i].blen != 0; i++) {
777 if (speed[i].blen > TVMEMSIZE) {
778 printk("template (%u) too big for tvmem (%u)\n",
779 speed[i].blen, TVMEMSIZE);
780 goto out;
781 }
782
783 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
784 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
785
786 memset(tvmem, 0xff, speed[i].blen);
787
788 if (sec)
Herbert Xue9d41162006-08-19 21:38:49 +1000789 ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
790 speed[i].plen, output, sec);
Michal Ludvige8057922006-05-30 22:04:19 +1000791 else
Herbert Xue9d41162006-08-19 21:38:49 +1000792 ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
793 speed[i].plen, output);
794
795 if (ret) {
796 printk("hashing failed ret=%d\n", ret);
797 break;
798 }
Michal Ludvige8057922006-05-30 22:04:19 +1000799 }
800
801out:
Herbert Xue9d41162006-08-19 21:38:49 +1000802 crypto_free_hash(tfm);
Michal Ludvige8057922006-05-30 22:04:19 +1000803}
804
Herbert Xuef2736f2005-06-22 13:26:03 -0700805static void test_deflate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806{
807 unsigned int i;
808 char result[COMP_BUF_SIZE];
Herbert Xue4d5b792006-08-26 18:12:40 +1000809 struct crypto_comp *tfm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 struct comp_testvec *tv;
811 unsigned int tsize;
812
813 printk("\ntesting deflate compression\n");
814
815 tsize = sizeof (deflate_comp_tv_template);
816 if (tsize > TVMEMSIZE) {
817 printk("template (%u) too big for tvmem (%u)\n", tsize,
818 TVMEMSIZE);
819 return;
820 }
821
822 memcpy(tvmem, deflate_comp_tv_template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700823 tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
Herbert Xuba8da2a2006-12-17 08:57:38 +1100825 tfm = crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC);
Sebastian Siewior7bc301e2007-03-21 08:58:43 +1100826 if (IS_ERR(tfm)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 printk("failed to load transform for deflate\n");
828 return;
829 }
830
831 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
832 int ilen, ret, dlen = COMP_BUF_SIZE;
Herbert Xuef2736f2005-06-22 13:26:03 -0700833
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 printk("test %u:\n", i + 1);
835 memset(result, 0, sizeof (result));
836
837 ilen = tv[i].inlen;
838 ret = crypto_comp_compress(tfm, tv[i].input,
839 ilen, result, &dlen);
840 if (ret) {
841 printk("fail: ret=%d\n", ret);
842 continue;
843 }
844 hexdump(result, dlen);
845 printk("%s (ratio %d:%d)\n",
846 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
847 ilen, dlen);
848 }
849
850 printk("\ntesting deflate decompression\n");
851
852 tsize = sizeof (deflate_decomp_tv_template);
853 if (tsize > TVMEMSIZE) {
854 printk("template (%u) too big for tvmem (%u)\n", tsize,
855 TVMEMSIZE);
856 goto out;
857 }
858
859 memcpy(tvmem, deflate_decomp_tv_template, tsize);
Herbert Xuef2736f2005-06-22 13:26:03 -0700860 tv = (void *)tvmem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
862 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
863 int ilen, ret, dlen = COMP_BUF_SIZE;
Herbert Xuef2736f2005-06-22 13:26:03 -0700864
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 printk("test %u:\n", i + 1);
866 memset(result, 0, sizeof (result));
867
868 ilen = tv[i].inlen;
869 ret = crypto_comp_decompress(tfm, tv[i].input,
870 ilen, result, &dlen);
871 if (ret) {
872 printk("fail: ret=%d\n", ret);
873 continue;
874 }
875 hexdump(result, dlen);
876 printk("%s (ratio %d:%d)\n",
877 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
878 ilen, dlen);
879 }
880out:
Herbert Xue4d5b792006-08-26 18:12:40 +1000881 crypto_free_comp(tfm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882}
883
Herbert Xuef2736f2005-06-22 13:26:03 -0700884static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
886 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -0700887
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 while (*name) {
889 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +1000890 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +1000891 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700893 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894}
895
Herbert Xuef2736f2005-06-22 13:26:03 -0700896static void do_test(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897{
898 switch (mode) {
899
900 case 0:
901 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700902
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700904
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 //DES
Herbert Xucba83562006-08-13 08:26:09 +1000906 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
907 DES_ENC_TEST_VECTORS);
908 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
909 DES_DEC_TEST_VECTORS);
910 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
911 DES_CBC_ENC_TEST_VECTORS);
912 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
913 DES_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 //DES3_EDE
Herbert Xucba83562006-08-13 08:26:09 +1000916 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
917 DES3_EDE_ENC_TEST_VECTORS);
918 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
919 DES3_EDE_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700920
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700922
Jonathan Lynchcd12fb92007-11-10 20:08:25 +0800923 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
924
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700926
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 //BLOWFISH
Herbert Xucba83562006-08-13 08:26:09 +1000928 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
929 BF_ENC_TEST_VECTORS);
930 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
931 BF_DEC_TEST_VECTORS);
932 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
933 BF_CBC_ENC_TEST_VECTORS);
934 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
935 BF_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700936
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 //TWOFISH
Herbert Xucba83562006-08-13 08:26:09 +1000938 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
939 TF_ENC_TEST_VECTORS);
940 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
941 TF_DEC_TEST_VECTORS);
942 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
943 TF_CBC_ENC_TEST_VECTORS);
944 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
945 TF_CBC_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700946
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 //SERPENT
Herbert Xucba83562006-08-13 08:26:09 +1000948 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
949 SERPENT_ENC_TEST_VECTORS);
950 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
951 SERPENT_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700952
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 //TNEPRES
Herbert Xucba83562006-08-13 08:26:09 +1000954 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
955 TNEPRES_ENC_TEST_VECTORS);
956 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
957 TNEPRES_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
959 //AES
Herbert Xucba83562006-08-13 08:26:09 +1000960 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
961 AES_ENC_TEST_VECTORS);
962 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
963 AES_DEC_TEST_VECTORS);
964 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
965 AES_CBC_ENC_TEST_VECTORS);
966 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
967 AES_CBC_DEC_TEST_VECTORS);
Rik Snelf3d10442006-11-29 19:01:41 +1100968 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
969 AES_LRW_ENC_TEST_VECTORS);
970 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
971 AES_LRW_DEC_TEST_VECTORS);
Rik Snelf19f5112007-09-19 20:23:13 +0800972 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
973 AES_XTS_ENC_TEST_VECTORS);
974 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
975 AES_XTS_DEC_TEST_VECTORS);
Joy Latten41fdab32007-11-07 22:59:47 +0800976 test_cipher("ctr(aes,4,8,4)", ENCRYPT, aes_ctr_enc_tv_template,
Joy Latten23e353c2007-10-23 08:50:32 +0800977 AES_CTR_ENC_TEST_VECTORS);
Joy Latten41fdab32007-11-07 22:59:47 +0800978 test_cipher("ctr(aes,4,8,4)", DECRYPT, aes_ctr_dec_tv_template,
Joy Latten23e353c2007-10-23 08:50:32 +0800979 AES_CTR_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
981 //CAST5
Herbert Xucba83562006-08-13 08:26:09 +1000982 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
983 CAST5_ENC_TEST_VECTORS);
984 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
985 CAST5_DEC_TEST_VECTORS);
Herbert Xuef2736f2005-06-22 13:26:03 -0700986
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 //CAST6
Herbert Xucba83562006-08-13 08:26:09 +1000988 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
989 CAST6_ENC_TEST_VECTORS);
990 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
991 CAST6_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
993 //ARC4
Herbert Xucba83562006-08-13 08:26:09 +1000994 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
995 ARC4_ENC_TEST_VECTORS);
996 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
997 ARC4_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
999 //TEA
Herbert Xucba83562006-08-13 08:26:09 +10001000 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1001 TEA_ENC_TEST_VECTORS);
1002 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1003 TEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
1005
1006 //XTEA
Herbert Xucba83562006-08-13 08:26:09 +10001007 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1008 XTEA_ENC_TEST_VECTORS);
1009 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1010 XTEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
1012 //KHAZAD
Herbert Xucba83562006-08-13 08:26:09 +10001013 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1014 KHAZAD_ENC_TEST_VECTORS);
1015 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1016 KHAZAD_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
1018 //ANUBIS
Herbert Xucba83562006-08-13 08:26:09 +10001019 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1020 ANUBIS_ENC_TEST_VECTORS);
1021 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1022 ANUBIS_DEC_TEST_VECTORS);
1023 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1024 ANUBIS_CBC_ENC_TEST_VECTORS);
1025 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1026 ANUBIS_CBC_ENC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001028 //XETA
Herbert Xucba83562006-08-13 08:26:09 +10001029 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1030 XETA_ENC_TEST_VECTORS);
1031 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1032 XETA_DEC_TEST_VECTORS);
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001033
David Howells90831632006-12-16 12:13:14 +11001034 //FCrypt
1035 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1036 FCRYPT_ENC_TEST_VECTORS);
1037 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1038 FCRYPT_DEC_TEST_VECTORS);
1039
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001040 //CAMELLIA
1041 test_cipher("ecb(camellia)", ENCRYPT,
1042 camellia_enc_tv_template,
1043 CAMELLIA_ENC_TEST_VECTORS);
1044 test_cipher("ecb(camellia)", DECRYPT,
1045 camellia_dec_tv_template,
1046 CAMELLIA_DEC_TEST_VECTORS);
1047 test_cipher("cbc(camellia)", ENCRYPT,
1048 camellia_cbc_enc_tv_template,
1049 CAMELLIA_CBC_ENC_TEST_VECTORS);
1050 test_cipher("cbc(camellia)", DECRYPT,
1051 camellia_cbc_dec_tv_template,
1052 CAMELLIA_CBC_DEC_TEST_VECTORS);
1053
Hye-Shik Change2ee95b2007-08-21 20:01:03 +08001054 //SEED
1055 test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template,
1056 SEED_ENC_TEST_VECTORS);
1057 test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
1058 SEED_DEC_TEST_VECTORS);
1059
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1061 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1062 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1063 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1064 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1065 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1066 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1067 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1068 test_deflate();
Herbert Xuc907ee72006-08-21 22:04:03 +10001069 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
Herbert Xue9d41162006-08-19 21:38:49 +10001070 test_hash("hmac(md5)", hmac_md5_tv_template,
1071 HMAC_MD5_TEST_VECTORS);
1072 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1073 HMAC_SHA1_TEST_VECTORS);
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001074 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1075 HMAC_SHA224_TEST_VECTORS);
Herbert Xue9d41162006-08-19 21:38:49 +10001076 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1077 HMAC_SHA256_TEST_VECTORS);
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001078 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1079 HMAC_SHA384_TEST_VECTORS);
1080 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1081 HMAC_SHA512_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
Kazunori MIYAZAWA5b2becf2006-10-28 13:18:53 +10001083 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1084 XCBC_AES_TEST_VECTORS);
1085
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1087 break;
1088
1089 case 1:
1090 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1091 break;
1092
1093 case 2:
1094 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1095 break;
1096
1097 case 3:
Herbert Xucba83562006-08-13 08:26:09 +10001098 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1099 DES_ENC_TEST_VECTORS);
1100 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1101 DES_DEC_TEST_VECTORS);
1102 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1103 DES_CBC_ENC_TEST_VECTORS);
1104 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1105 DES_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 break;
1107
1108 case 4:
Herbert Xucba83562006-08-13 08:26:09 +10001109 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1110 DES3_EDE_ENC_TEST_VECTORS);
1111 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1112 DES3_EDE_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 break;
1114
1115 case 5:
1116 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1117 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 case 6:
1120 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1121 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001122
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 case 7:
Herbert Xucba83562006-08-13 08:26:09 +10001124 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1125 BF_ENC_TEST_VECTORS);
1126 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1127 BF_DEC_TEST_VECTORS);
1128 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1129 BF_CBC_ENC_TEST_VECTORS);
1130 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1131 BF_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 break;
1133
1134 case 8:
Herbert Xucba83562006-08-13 08:26:09 +10001135 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1136 TF_ENC_TEST_VECTORS);
1137 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1138 TF_DEC_TEST_VECTORS);
1139 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1140 TF_CBC_ENC_TEST_VECTORS);
1141 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1142 TF_CBC_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001144
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 case 9:
Herbert Xucba83562006-08-13 08:26:09 +10001146 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1147 SERPENT_ENC_TEST_VECTORS);
1148 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1149 SERPENT_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 break;
1151
1152 case 10:
Herbert Xucba83562006-08-13 08:26:09 +10001153 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1154 AES_ENC_TEST_VECTORS);
1155 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1156 AES_DEC_TEST_VECTORS);
1157 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1158 AES_CBC_ENC_TEST_VECTORS);
1159 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1160 AES_CBC_DEC_TEST_VECTORS);
Rik Snelf3d10442006-11-29 19:01:41 +11001161 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1162 AES_LRW_ENC_TEST_VECTORS);
1163 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1164 AES_LRW_DEC_TEST_VECTORS);
Rik Snelf19f5112007-09-19 20:23:13 +08001165 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1166 AES_XTS_ENC_TEST_VECTORS);
1167 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1168 AES_XTS_DEC_TEST_VECTORS);
Joy Latten41fdab32007-11-07 22:59:47 +08001169 test_cipher("ctr(aes,4,8,4)", ENCRYPT, aes_ctr_enc_tv_template,
Joy Latten23e353c2007-10-23 08:50:32 +08001170 AES_CTR_ENC_TEST_VECTORS);
Joy Latten41fdab32007-11-07 22:59:47 +08001171 test_cipher("ctr(aes,4,8,4)", DECRYPT, aes_ctr_dec_tv_template,
Joy Latten23e353c2007-10-23 08:50:32 +08001172 AES_CTR_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 break;
1174
1175 case 11:
1176 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1177 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001178
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 case 12:
1180 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1181 break;
1182
1183 case 13:
1184 test_deflate();
1185 break;
1186
1187 case 14:
Herbert Xucba83562006-08-13 08:26:09 +10001188 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1189 CAST5_ENC_TEST_VECTORS);
1190 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1191 CAST5_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 break;
1193
1194 case 15:
Herbert Xucba83562006-08-13 08:26:09 +10001195 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1196 CAST6_ENC_TEST_VECTORS);
1197 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1198 CAST6_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 break;
1200
1201 case 16:
Herbert Xucba83562006-08-13 08:26:09 +10001202 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1203 ARC4_ENC_TEST_VECTORS);
1204 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1205 ARC4_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 break;
1207
1208 case 17:
1209 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1210 break;
1211
1212 case 18:
Herbert Xuc907ee72006-08-21 22:04:03 +10001213 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 break;
1215
1216 case 19:
Herbert Xucba83562006-08-13 08:26:09 +10001217 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1218 TEA_ENC_TEST_VECTORS);
1219 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1220 TEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 break;
1222
1223 case 20:
Herbert Xucba83562006-08-13 08:26:09 +10001224 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1225 XTEA_ENC_TEST_VECTORS);
1226 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1227 XTEA_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 break;
1229
1230 case 21:
Herbert Xucba83562006-08-13 08:26:09 +10001231 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1232 KHAZAD_ENC_TEST_VECTORS);
1233 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1234 KHAZAD_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 break;
1236
1237 case 22:
1238 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1239 break;
1240
1241 case 23:
1242 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1243 break;
1244
1245 case 24:
1246 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1247 break;
1248
1249 case 25:
Herbert Xucba83562006-08-13 08:26:09 +10001250 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1251 TNEPRES_ENC_TEST_VECTORS);
1252 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1253 TNEPRES_DEC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 break;
1255
1256 case 26:
Herbert Xucba83562006-08-13 08:26:09 +10001257 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1258 ANUBIS_ENC_TEST_VECTORS);
1259 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1260 ANUBIS_DEC_TEST_VECTORS);
1261 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1262 ANUBIS_CBC_ENC_TEST_VECTORS);
1263 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1264 ANUBIS_CBC_ENC_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 break;
1266
1267 case 27:
1268 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1269 break;
1270
1271 case 28:
1272
1273 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1274 break;
1275
1276 case 29:
1277 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1278 break;
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001279
1280 case 30:
Herbert Xucba83562006-08-13 08:26:09 +10001281 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1282 XETA_ENC_TEST_VECTORS);
1283 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1284 XETA_DEC_TEST_VECTORS);
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001285 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
David Howells90831632006-12-16 12:13:14 +11001287 case 31:
1288 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1289 FCRYPT_ENC_TEST_VECTORS);
1290 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1291 FCRYPT_DEC_TEST_VECTORS);
1292 break;
1293
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001294 case 32:
1295 test_cipher("ecb(camellia)", ENCRYPT,
1296 camellia_enc_tv_template,
1297 CAMELLIA_ENC_TEST_VECTORS);
1298 test_cipher("ecb(camellia)", DECRYPT,
1299 camellia_dec_tv_template,
1300 CAMELLIA_DEC_TEST_VECTORS);
1301 test_cipher("cbc(camellia)", ENCRYPT,
1302 camellia_cbc_enc_tv_template,
1303 CAMELLIA_CBC_ENC_TEST_VECTORS);
1304 test_cipher("cbc(camellia)", DECRYPT,
1305 camellia_cbc_dec_tv_template,
1306 CAMELLIA_CBC_DEC_TEST_VECTORS);
1307 break;
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001308 case 33:
1309 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1310 break;
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001311
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 case 100:
Herbert Xue9d41162006-08-19 21:38:49 +10001313 test_hash("hmac(md5)", hmac_md5_tv_template,
1314 HMAC_MD5_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001316
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 case 101:
Herbert Xue9d41162006-08-19 21:38:49 +10001318 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1319 HMAC_SHA1_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001321
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 case 102:
Herbert Xue9d41162006-08-19 21:38:49 +10001323 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1324 HMAC_SHA256_TEST_VECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 break;
1326
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001327 case 103:
1328 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1329 HMAC_SHA384_TEST_VECTORS);
1330 break;
1331
1332 case 104:
1333 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1334 HMAC_SHA512_TEST_VECTORS);
1335 break;
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001336 case 105:
1337 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1338 HMAC_SHA224_TEST_VECTORS);
1339 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
Harald Welteebfd9bc2005-06-22 13:27:23 -07001341 case 200:
Herbert Xucba83562006-08-13 08:26:09 +10001342 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001343 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001344 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001345 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001346 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001347 aes_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001348 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001349 aes_speed_template);
Rik Snelf3d10442006-11-29 19:01:41 +11001350 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1351 aes_lrw_speed_template);
1352 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1353 aes_lrw_speed_template);
Rik Snelf19f5112007-09-19 20:23:13 +08001354 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1355 aes_xts_speed_template);
1356 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1357 aes_xts_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001358 break;
1359
1360 case 201:
Herbert Xucba83562006-08-13 08:26:09 +10001361 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001362 des3_ede_enc_tv_template,
1363 DES3_EDE_ENC_TEST_VECTORS,
1364 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001365 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001366 des3_ede_dec_tv_template,
1367 DES3_EDE_DEC_TEST_VECTORS,
1368 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001369 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001370 des3_ede_enc_tv_template,
1371 DES3_EDE_ENC_TEST_VECTORS,
1372 des3_ede_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001373 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xudce907c2005-06-22 13:27:51 -07001374 des3_ede_dec_tv_template,
1375 DES3_EDE_DEC_TEST_VECTORS,
1376 des3_ede_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001377 break;
1378
1379 case 202:
Herbert Xucba83562006-08-13 08:26:09 +10001380 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001381 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001382 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001383 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001384 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001385 twofish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001386 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001387 twofish_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001388 break;
1389
1390 case 203:
Herbert Xucba83562006-08-13 08:26:09 +10001391 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001392 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001393 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001394 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001395 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001396 blowfish_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001397 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001398 blowfish_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001399 break;
1400
1401 case 204:
Herbert Xucba83562006-08-13 08:26:09 +10001402 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001403 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001404 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001405 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001406 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001407 des_speed_template);
Herbert Xucba83562006-08-13 08:26:09 +10001408 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Herbert Xudce907c2005-06-22 13:27:51 -07001409 des_speed_template);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001410 break;
1411
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001412 case 205:
1413 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1414 camellia_speed_template);
1415 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1416 camellia_speed_template);
1417 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1418 camellia_speed_template);
1419 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1420 camellia_speed_template);
1421 break;
1422
Michal Ludvige8057922006-05-30 22:04:19 +10001423 case 300:
1424 /* fall through */
1425
1426 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +10001427 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001428 if (mode > 300 && mode < 400) break;
1429
1430 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +10001431 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001432 if (mode > 300 && mode < 400) break;
1433
1434 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +10001435 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001436 if (mode > 300 && mode < 400) break;
1437
1438 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +10001439 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001440 if (mode > 300 && mode < 400) break;
1441
1442 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +10001443 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001444 if (mode > 300 && mode < 400) break;
1445
1446 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +10001447 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001448 if (mode > 300 && mode < 400) break;
1449
1450 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +10001451 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001452 if (mode > 300 && mode < 400) break;
1453
1454 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +10001455 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001456 if (mode > 300 && mode < 400) break;
1457
1458 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +10001459 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001460 if (mode > 300 && mode < 400) break;
1461
1462 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +10001463 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001464 if (mode > 300 && mode < 400) break;
1465
1466 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +10001467 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001468 if (mode > 300 && mode < 400) break;
1469
1470 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +10001471 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001472 if (mode > 300 && mode < 400) break;
1473
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001474 case 313:
1475 test_hash_speed("sha224", sec, generic_hash_speed_template);
1476 if (mode > 300 && mode < 400) break;
1477
Michal Ludvige8057922006-05-30 22:04:19 +10001478 case 399:
1479 break;
1480
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 case 1000:
1482 test_available();
1483 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001484
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 default:
1486 /* useful for debugging */
1487 printk("not testing anything\n");
1488 break;
1489 }
1490}
1491
Herbert Xuef2736f2005-06-22 13:26:03 -07001492static int __init init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493{
1494 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1495 if (tvmem == NULL)
1496 return -ENOMEM;
1497
1498 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1499 if (xbuf == NULL) {
1500 kfree(tvmem);
1501 return -ENOMEM;
1502 }
1503
1504 do_test();
1505
1506 kfree(xbuf);
1507 kfree(tvmem);
Michal Ludvig14fdf472006-05-30 14:49:38 +10001508
1509 /* We intentionaly return -EAGAIN to prevent keeping
1510 * the module. It does all its work from init()
1511 * and doesn't offer any runtime functionality
1512 * => we don't need it in the memory, do we?
1513 * -- mludvig
1514 */
1515 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516}
1517
1518/*
1519 * If an init function is provided, an exit function must also be provided
1520 * to allow module unload.
1521 */
1522static void __exit fini(void) { }
1523
1524module_init(init);
1525module_exit(fini);
1526
1527module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001528module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -07001529MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1530 "(defaults to zero which uses CPU cycles instead)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
1532MODULE_LICENSE("GPL");
1533MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1534MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");