Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Quick & dirty crypto testing module. |
| 3 | * |
| 4 | * This will only exist until we have a better testing mechanism |
| 5 | * (e.g. a char device). |
| 6 | * |
| 7 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> |
| 8 | * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the Free |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 12 | * Software Foundation; either version 2 of the License, or (at your option) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * any later version. |
| 14 | * |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame^] | 15 | * 2007-11-06 Added SHA-224 and SHA-224-HMAC tests |
Andrew Donofrio | a28091a | 2006-12-10 12:10:20 +1100 | [diff] [blame] | 16 | * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 17 | * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>) |
| 18 | * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt |
| 19 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 22 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/init.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/mm.h> |
| 26 | #include <linux/slab.h> |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 27 | #include <linux/scatterlist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/string.h> |
| 29 | #include <linux/crypto.h> |
| 30 | #include <linux/highmem.h> |
| 31 | #include <linux/moduleparam.h> |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 32 | #include <linux/jiffies.h> |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 33 | #include <linux/timex.h> |
| 34 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include "tcrypt.h" |
| 36 | |
| 37 | /* |
| 38 | * Need to kmalloc() memory for testing kmap(). |
| 39 | */ |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 40 | #define TVMEMSIZE 16384 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 61 | struct tcrypt_result { |
| 62 | struct completion completion; |
| 63 | int err; |
| 64 | }; |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; |
| 67 | |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 68 | /* |
| 69 | * Used by test_cipher_speed() |
| 70 | */ |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 71 | static unsigned int sec; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | static int mode; |
| 74 | static char *xbuf; |
| 75 | static char *tvmem; |
| 76 | |
| 77 | static char *check[] = { |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame^] | 78 | "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 Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 81 | "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", |
David Howells | 9083163 | 2006-12-16 12:13:14 +1100 | [diff] [blame] | 82 | "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", |
Hye-Shik Chang | e2ee95b | 2007-08-21 20:01:03 +0800 | [diff] [blame] | 83 | "camellia", "seed", NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 86 | static void hexdump(unsigned char *buf, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
| 88 | while (len--) |
| 89 | printk("%02x", *buf++); |
| 90 | |
| 91 | printk("\n"); |
| 92 | } |
| 93 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 94 | static 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 Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 105 | static void test_hash(char *algo, struct hash_testvec *template, |
| 106 | unsigned int tcount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 108 | unsigned int i, j, k, temp; |
| 109 | struct scatterlist sg[8]; |
| 110 | char result[64]; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 111 | struct crypto_hash *tfm; |
| 112 | struct hash_desc desc; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 113 | struct hash_testvec *hash_tv; |
| 114 | unsigned int tsize; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 115 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 117 | printk("\ntesting %s\n", algo); |
| 118 | |
| 119 | tsize = sizeof(struct hash_testvec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | tsize *= tcount; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | 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 Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 128 | hash_tv = (void *)tvmem; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 129 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | return; |
| 135 | } |
| 136 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 137 | desc.tfm = tfm; |
| 138 | desc.flags = 0; |
| 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | for (i = 0; i < tcount; i++) { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 141 | printk("test %u:\n", i + 1); |
| 142 | memset(result, 0, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
David S. Miller | b733588 | 2007-10-26 00:38:10 -0700 | [diff] [blame] | 144 | sg_init_one(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 146 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 155 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | printk("%s\n", |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 163 | memcmp(result, hash_tv[i].digest, |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 164 | crypto_hash_digestsize(tfm)) ? |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 165 | "fail" : "pass"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 168 | printk("testing %s across pages\n", algo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | /* setup the dummy buffer first */ |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 171 | memset(xbuf, 0, XBUFSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | j = 0; |
| 174 | for (i = 0; i < tcount; i++) { |
| 175 | if (hash_tv[i].np) { |
| 176 | j++; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 177 | printk("test %u:\n", j); |
| 178 | memset(result, 0, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | temp = 0; |
David S. Miller | b733588 | 2007-10-26 00:38:10 -0700 | [diff] [blame] | 181 | sg_init_table(sg, hash_tv[i].np); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | for (k = 0; k < hash_tv[i].np; k++) { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 183 | memcpy(&xbuf[IDX[k]], |
| 184 | hash_tv[i].plaintext + temp, |
| 185 | hash_tv[i].tap[k]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | temp += hash_tv[i].tap[k]; |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 187 | sg_set_buf(&sg[k], &xbuf[IDX[k]], |
| 188 | hash_tv[i].tap[k]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 191 | if (hash_tv[i].ksize) { |
| 192 | ret = crypto_hash_setkey(tfm, hash_tv[i].key, |
| 193 | hash_tv[i].ksize); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 194 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 195 | if (ret) { |
| 196 | printk("setkey() failed ret=%d\n", ret); |
| 197 | goto out; |
| 198 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 201 | 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 Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 207 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 208 | hexdump(result, crypto_hash_digestsize(tfm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | printk("%s\n", |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 210 | memcmp(result, hash_tv[i].digest, |
| 211 | crypto_hash_digestsize(tfm)) ? |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 212 | "fail" : "pass"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
| 214 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 216 | out: |
| 217 | crypto_free_hash(tfm); |
| 218 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 220 | static void test_cipher(char *algo, int enc, |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 221 | struct cipher_testvec *template, unsigned int tcount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
| 223 | unsigned int ret, i, j, k, temp; |
| 224 | unsigned int tsize; |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 225 | char *q; |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 226 | struct crypto_ablkcipher *tfm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | char *key; |
| 228 | struct cipher_testvec *cipher_tv; |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 229 | struct ablkcipher_request *req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | struct scatterlist sg[8]; |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 231 | const char *e; |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 232 | struct tcrypt_result result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | if (enc == ENCRYPT) |
Herbert Xu | 3cc3816 | 2005-06-22 13:26:36 -0700 | [diff] [blame] | 235 | e = "encryption"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | else |
Herbert Xu | 3cc3816 | 2005-06-22 13:26:36 -0700 | [diff] [blame] | 237 | e = "decryption"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 239 | printk("\ntesting %s %s\n", algo, e); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 241 | tsize = sizeof (struct cipher_testvec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | tsize *= tcount; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | 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 Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 251 | cipher_tv = (void *)tvmem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 253 | init_completion(&result.completion); |
| 254 | |
| 255 | tfm = crypto_alloc_ablkcipher(algo, 0, 0); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 256 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 257 | if (IS_ERR(tfm)) { |
| 258 | printk("failed to load transform for %s: %ld\n", algo, |
| 259 | PTR_ERR(tfm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | return; |
| 261 | } |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 262 | |
| 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 Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | j = 0; |
| 273 | for (i = 0; i < tcount; i++) { |
| 274 | if (!(cipher_tv[i].np)) { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 275 | j++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | printk("test %u (%d bit key):\n", |
| 277 | j, cipher_tv[i].klen * 8); |
| 278 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 279 | crypto_ablkcipher_clear_flags(tfm, ~0); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 280 | if (cipher_tv[i].wk) |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 281 | crypto_ablkcipher_set_flags( |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 282 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | key = cipher_tv[i].key; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 284 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 285 | ret = crypto_ablkcipher_setkey(tfm, key, |
| 286 | cipher_tv[i].klen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | if (ret) { |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 288 | printk("setkey() failed flags=%x\n", |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 289 | crypto_ablkcipher_get_flags(tfm)); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | if (!cipher_tv[i].fail) |
| 292 | goto out; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 293 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
David S. Miller | b733588 | 2007-10-26 00:38:10 -0700 | [diff] [blame] | 295 | sg_init_one(&sg[0], cipher_tv[i].input, |
| 296 | cipher_tv[i].ilen); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 297 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 298 | ablkcipher_request_set_crypt(req, sg, sg, |
| 299 | cipher_tv[i].ilen, |
| 300 | cipher_tv[i].iv); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 301 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 302 | ret = enc ? |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 303 | crypto_ablkcipher_encrypt(req) : |
| 304 | crypto_ablkcipher_decrypt(req); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 305 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 306 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | goto out; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Jens Axboe | 78c2f0b | 2007-10-22 19:40:16 +0200 | [diff] [blame] | 323 | q = kmap(sg_page(&sg[0])) + sg[0].offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | hexdump(q, cipher_tv[i].rlen); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 325 | |
| 326 | printk("%s\n", |
| 327 | memcmp(q, cipher_tv[i].result, |
| 328 | cipher_tv[i].rlen) ? "fail" : "pass"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | } |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 331 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 332 | printk("\ntesting %s %s across pages (chunking)\n", algo, e); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | memset(xbuf, 0, XBUFSIZE); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | j = 0; |
| 336 | for (i = 0; i < tcount; i++) { |
| 337 | if (cipher_tv[i].np) { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 338 | j++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | printk("test %u (%d bit key):\n", |
| 340 | j, cipher_tv[i].klen * 8); |
| 341 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 342 | crypto_ablkcipher_clear_flags(tfm, ~0); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 343 | if (cipher_tv[i].wk) |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 344 | crypto_ablkcipher_set_flags( |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 345 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | key = cipher_tv[i].key; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 347 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 348 | ret = crypto_ablkcipher_setkey(tfm, key, |
| 349 | cipher_tv[i].klen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | if (ret) { |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 351 | printk("setkey() failed flags=%x\n", |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 352 | crypto_ablkcipher_get_flags(tfm)); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | if (!cipher_tv[i].fail) |
| 355 | goto out; |
| 356 | } |
| 357 | |
| 358 | temp = 0; |
David S. Miller | b733588 | 2007-10-26 00:38:10 -0700 | [diff] [blame] | 359 | sg_init_table(sg, cipher_tv[i].np); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | for (k = 0; k < cipher_tv[i].np; k++) { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 361 | memcpy(&xbuf[IDX[k]], |
| 362 | cipher_tv[i].input + temp, |
| 363 | cipher_tv[i].tap[k]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | temp += cipher_tv[i].tap[k]; |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 365 | sg_set_buf(&sg[k], &xbuf[IDX[k]], |
| 366 | cipher_tv[i].tap[k]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 368 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 369 | ablkcipher_request_set_crypt(req, sg, sg, |
| 370 | cipher_tv[i].ilen, |
| 371 | cipher_tv[i].iv); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 372 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 373 | ret = enc ? |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 374 | crypto_ablkcipher_encrypt(req) : |
| 375 | crypto_ablkcipher_decrypt(req); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 376 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 377 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | goto out; |
| 392 | } |
| 393 | |
| 394 | temp = 0; |
| 395 | for (k = 0; k < cipher_tv[i].np; k++) { |
| 396 | printk("page %u\n", k); |
Jens Axboe | 78c2f0b | 2007-10-22 19:40:16 +0200 | [diff] [blame] | 397 | q = kmap(sg_page(&sg[k])) + sg[k].offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | hexdump(q, cipher_tv[i].tap[k]); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 399 | printk("%s\n", |
| 400 | memcmp(q, cipher_tv[i].result + temp, |
| 401 | cipher_tv[i].tap[k]) ? "fail" : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | "pass"); |
| 403 | temp += cipher_tv[i].tap[k]; |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | out: |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 409 | crypto_free_ablkcipher(tfm); |
| 410 | ablkcipher_request_free(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 413 | static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p, |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 414 | int blen, int sec) |
| 415 | { |
Herbert Xu | 6df5b9f | 2005-09-19 22:30:11 +1000 | [diff] [blame] | 416 | struct scatterlist sg[1]; |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 417 | unsigned long start, end; |
| 418 | int bcount; |
| 419 | int ret; |
| 420 | |
David S. Miller | b733588 | 2007-10-26 00:38:10 -0700 | [diff] [blame] | 421 | sg_init_one(sg, p, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 422 | |
| 423 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
| 424 | time_before(jiffies, end); bcount++) { |
| 425 | if (enc) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 426 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 427 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 428 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 429 | |
| 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 Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 439 | static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p, |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 440 | int blen) |
| 441 | { |
Herbert Xu | 6df5b9f | 2005-09-19 22:30:11 +1000 | [diff] [blame] | 442 | struct scatterlist sg[1]; |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 443 | unsigned long cycles = 0; |
| 444 | int ret = 0; |
| 445 | int i; |
| 446 | |
David S. Miller | b733588 | 2007-10-26 00:38:10 -0700 | [diff] [blame] | 447 | sg_init_one(sg, p, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 448 | |
| 449 | local_bh_disable(); |
| 450 | local_irq_disable(); |
| 451 | |
| 452 | /* Warm-up run. */ |
| 453 | for (i = 0; i < 4; i++) { |
| 454 | if (enc) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 455 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 456 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 457 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 458 | |
| 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 Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 469 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 470 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 471 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 472 | end = get_cycles(); |
| 473 | |
| 474 | if (ret) |
| 475 | goto out; |
| 476 | |
| 477 | cycles += end - start; |
| 478 | } |
| 479 | |
| 480 | out: |
| 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 Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 491 | static void test_cipher_speed(char *algo, int enc, unsigned int sec, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 492 | struct cipher_testvec *template, |
| 493 | unsigned int tcount, struct cipher_speed *speed) |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 494 | { |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 495 | unsigned int ret, i, j, iv_len; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 496 | unsigned char *key, *p, iv[128]; |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 497 | struct crypto_blkcipher *tfm; |
| 498 | struct blkcipher_desc desc; |
| 499 | const char *e; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 500 | |
| 501 | if (enc == ENCRYPT) |
| 502 | e = "encryption"; |
| 503 | else |
| 504 | e = "decryption"; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 505 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 506 | printk("\ntesting speed of %s %s\n", algo, e); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 507 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 508 | tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 509 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 510 | if (IS_ERR(tfm)) { |
| 511 | printk("failed to load transform for %s: %ld\n", algo, |
| 512 | PTR_ERR(tfm)); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 513 | return; |
| 514 | } |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 515 | desc.tfm = tfm; |
| 516 | desc.flags = 0; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 517 | |
| 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 Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 532 | for (j = 0; j < tcount; j++) { |
| 533 | if (template[j].klen == speed[i].klen) { |
| 534 | key = template[j].key; |
| 535 | break; |
| 536 | } |
| 537 | } |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 538 | p = (unsigned char *)tvmem + speed[i].klen; |
| 539 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 540 | ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 541 | if (ret) { |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 542 | printk("setkey() failed flags=%x\n", |
| 543 | crypto_blkcipher_get_flags(tfm)); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 544 | goto out; |
| 545 | } |
| 546 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 547 | iv_len = crypto_blkcipher_ivsize(tfm); |
| 548 | if (iv_len) { |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 549 | memset(&iv, 0xff, iv_len); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 550 | crypto_blkcipher_set_iv(tfm, iv, iv_len); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 551 | } |
| 552 | |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 553 | if (sec) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 554 | ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen, |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 555 | sec); |
| 556 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 557 | ret = test_cipher_cycles(&desc, enc, p, speed[i].blen); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 558 | |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 559 | if (ret) { |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 560 | printk("%s() failed flags=%x\n", e, desc.flags); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 561 | break; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 562 | } |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | out: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 566 | crypto_free_blkcipher(tfm); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 569 | static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen, |
| 570 | char *out, int sec) |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 571 | { |
| 572 | struct scatterlist sg[1]; |
| 573 | unsigned long start, end; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 574 | int bcount; |
| 575 | int ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 576 | |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 577 | sg_init_table(sg, 1); |
| 578 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 579 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
| 580 | time_before(jiffies, end); bcount++) { |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 581 | sg_set_buf(sg, p, blen); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 582 | ret = crypto_hash_digest(desc, sg, blen, out); |
| 583 | if (ret) |
| 584 | return ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | printk("%6u opers/sec, %9lu bytes/sec\n", |
| 588 | bcount / sec, ((long)bcount * blen) / sec); |
| 589 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 590 | return 0; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 591 | } |
| 592 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 593 | static 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 Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 604 | sg_init_table(sg, 1); |
| 605 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 606 | 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 Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 612 | sg_set_buf(sg, p + pcount, plen); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 613 | 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 | |
| 629 | static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen, |
| 630 | char *out) |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 631 | { |
| 632 | struct scatterlist sg[1]; |
| 633 | unsigned long cycles = 0; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 634 | int i; |
| 635 | int ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 636 | |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 637 | sg_init_table(sg, 1); |
| 638 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 639 | local_bh_disable(); |
| 640 | local_irq_disable(); |
| 641 | |
| 642 | /* Warm-up run. */ |
| 643 | for (i = 0; i < 4; i++) { |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 644 | sg_set_buf(sg, p, blen); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 645 | ret = crypto_hash_digest(desc, sg, blen, out); |
| 646 | if (ret) |
| 647 | goto out; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | /* The real thing. */ |
| 651 | for (i = 0; i < 8; i++) { |
| 652 | cycles_t start, end; |
| 653 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 654 | start = get_cycles(); |
| 655 | |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 656 | sg_set_buf(sg, p, blen); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 657 | ret = crypto_hash_digest(desc, sg, blen, out); |
| 658 | if (ret) |
| 659 | goto out; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 660 | |
| 661 | end = get_cycles(); |
| 662 | |
| 663 | cycles += end - start; |
| 664 | } |
| 665 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 666 | out: |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 667 | local_irq_enable(); |
| 668 | local_bh_enable(); |
| 669 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 670 | if (ret) |
| 671 | return ret; |
| 672 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 673 | printk("%6lu cycles/operation, %4lu cycles/byte\n", |
| 674 | cycles / 8, cycles / (8 * blen)); |
| 675 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 676 | return 0; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 677 | } |
| 678 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 679 | static int test_hash_cycles(struct hash_desc *desc, char *p, int blen, |
| 680 | int plen, char *out) |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 681 | { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 682 | 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 Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 690 | sg_init_table(sg, 1); |
| 691 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 692 | 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 Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 701 | sg_set_buf(sg, p + pcount, plen); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 702 | ret = crypto_hash_update(desc, sg, plen); |
| 703 | if (ret) |
| 704 | goto out; |
| 705 | } |
Herbert Xu | 29059d1 | 2007-05-18 16:25:19 +1000 | [diff] [blame] | 706 | ret = crypto_hash_final(desc, out); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 707 | 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 Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 721 | sg_set_buf(sg, p + pcount, plen); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 722 | 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 | |
| 735 | out: |
| 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 | |
| 748 | static 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 Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 753 | char output[1024]; |
| 754 | int i; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 755 | int ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 756 | |
| 757 | printk("\ntesting speed of %s\n", algo); |
| 758 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 759 | tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 760 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 761 | if (IS_ERR(tfm)) { |
| 762 | printk("failed to load transform for %s: %ld\n", algo, |
| 763 | PTR_ERR(tfm)); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 764 | return; |
| 765 | } |
| 766 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 767 | desc.tfm = tfm; |
| 768 | desc.flags = 0; |
| 769 | |
| 770 | if (crypto_hash_digestsize(tfm) > sizeof(output)) { |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 771 | printk("digestsize(%u) > outputbuffer(%zu)\n", |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 772 | crypto_hash_digestsize(tfm), sizeof(output)); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 773 | 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 Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 789 | ret = test_hash_jiffies(&desc, tvmem, speed[i].blen, |
| 790 | speed[i].plen, output, sec); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 791 | else |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 792 | 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 Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | out: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 802 | crypto_free_hash(tfm); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 803 | } |
| 804 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 805 | static void test_deflate(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | { |
| 807 | unsigned int i; |
| 808 | char result[COMP_BUF_SIZE]; |
Herbert Xu | e4d5b79 | 2006-08-26 18:12:40 +1000 | [diff] [blame] | 809 | struct crypto_comp *tfm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | 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 Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 823 | tv = (void *)tvmem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
Herbert Xu | ba8da2a | 2006-12-17 08:57:38 +1100 | [diff] [blame] | 825 | tfm = crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC); |
Sebastian Siewior | 7bc301e | 2007-03-21 08:58:43 +1100 | [diff] [blame] | 826 | if (IS_ERR(tfm)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | 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 Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 833 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | 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 Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 860 | tv = (void *)tvmem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | |
| 862 | for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) { |
| 863 | int ilen, ret, dlen = COMP_BUF_SIZE; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | 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 | } |
| 880 | out: |
Herbert Xu | e4d5b79 | 2006-08-26 18:12:40 +1000 | [diff] [blame] | 881 | crypto_free_comp(tfm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | } |
| 883 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 884 | static void test_available(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | { |
| 886 | char **name = check; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 887 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | while (*name) { |
| 889 | printk("alg %s ", *name); |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 890 | printk(crypto_has_alg(*name, 0, 0) ? |
Herbert Xu | e4d5b79 | 2006-08-26 18:12:40 +1000 | [diff] [blame] | 891 | "found\n" : "not found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | name++; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 893 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | } |
| 895 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 896 | static void do_test(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | { |
| 898 | switch (mode) { |
| 899 | |
| 900 | case 0: |
| 901 | test_hash("md5", md5_tv_template, MD5_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 902 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 904 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | //DES |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 906 | 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 Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 914 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | //DES3_EDE |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 916 | 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 Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 920 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 922 | |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame^] | 923 | test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS); |
| 924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 926 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | //BLOWFISH |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 928 | 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 Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 936 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | //TWOFISH |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 938 | 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 Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | //SERPENT |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 948 | 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 Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | //TNEPRES |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 954 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | |
| 959 | //AES |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 960 | 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 Snel | f3d1044 | 2006-11-29 19:01:41 +1100 | [diff] [blame] | 968 | 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 Snel | f19f511 | 2007-09-19 20:23:13 +0800 | [diff] [blame] | 972 | 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 Latten | 41fdab3 | 2007-11-07 22:59:47 +0800 | [diff] [blame] | 976 | test_cipher("ctr(aes,4,8,4)", ENCRYPT, aes_ctr_enc_tv_template, |
Joy Latten | 23e353c | 2007-10-23 08:50:32 +0800 | [diff] [blame] | 977 | AES_CTR_ENC_TEST_VECTORS); |
Joy Latten | 41fdab3 | 2007-11-07 22:59:47 +0800 | [diff] [blame] | 978 | test_cipher("ctr(aes,4,8,4)", DECRYPT, aes_ctr_dec_tv_template, |
Joy Latten | 23e353c | 2007-10-23 08:50:32 +0800 | [diff] [blame] | 979 | AES_CTR_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | |
| 981 | //CAST5 |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 982 | 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 Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 986 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | //CAST6 |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 988 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | |
| 993 | //ARC4 |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 994 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | |
| 999 | //TEA |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1000 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
| 1005 | |
| 1006 | //XTEA |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1007 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | |
| 1012 | //KHAZAD |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1013 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | |
| 1018 | //ANUBIS |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1019 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | |
Aaron Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 1028 | //XETA |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1029 | 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 Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 1033 | |
David Howells | 9083163 | 2006-12-16 12:13:14 +1100 | [diff] [blame] | 1034 | //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 TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1040 | //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 Chang | e2ee95b | 2007-08-21 20:01:03 +0800 | [diff] [blame] | 1054 | //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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | 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 Xu | c907ee7 | 2006-08-21 22:04:03 +1000 | [diff] [blame] | 1069 | test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1070 | 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 Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame^] | 1074 | test_hash("hmac(sha224)", hmac_sha224_tv_template, |
| 1075 | HMAC_SHA224_TEST_VECTORS); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1076 | test_hash("hmac(sha256)", hmac_sha256_tv_template, |
| 1077 | HMAC_SHA256_TEST_VECTORS); |
Andrew Donofrio | a28091a | 2006-12-10 12:10:20 +1100 | [diff] [blame] | 1078 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | |
Kazunori MIYAZAWA | 5b2becf | 2006-10-28 13:18:53 +1000 | [diff] [blame] | 1083 | test_hash("xcbc(aes)", aes_xcbc128_tv_template, |
| 1084 | XCBC_AES_TEST_VECTORS); |
| 1085 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | 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 Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1098 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | break; |
| 1107 | |
| 1108 | case 4: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1109 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | break; |
| 1114 | |
| 1115 | case 5: |
| 1116 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); |
| 1117 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | case 6: |
| 1120 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); |
| 1121 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | case 7: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1124 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | break; |
| 1133 | |
| 1134 | case 8: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1135 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | case 9: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1146 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | break; |
| 1151 | |
| 1152 | case 10: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1153 | 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 Snel | f3d1044 | 2006-11-29 19:01:41 +1100 | [diff] [blame] | 1161 | 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 Snel | f19f511 | 2007-09-19 20:23:13 +0800 | [diff] [blame] | 1165 | 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 Latten | 41fdab3 | 2007-11-07 22:59:47 +0800 | [diff] [blame] | 1169 | test_cipher("ctr(aes,4,8,4)", ENCRYPT, aes_ctr_enc_tv_template, |
Joy Latten | 23e353c | 2007-10-23 08:50:32 +0800 | [diff] [blame] | 1170 | AES_CTR_ENC_TEST_VECTORS); |
Joy Latten | 41fdab3 | 2007-11-07 22:59:47 +0800 | [diff] [blame] | 1171 | test_cipher("ctr(aes,4,8,4)", DECRYPT, aes_ctr_dec_tv_template, |
Joy Latten | 23e353c | 2007-10-23 08:50:32 +0800 | [diff] [blame] | 1172 | AES_CTR_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | break; |
| 1174 | |
| 1175 | case 11: |
| 1176 | test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS); |
| 1177 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | 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 Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1188 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | break; |
| 1193 | |
| 1194 | case 15: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1195 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | break; |
| 1200 | |
| 1201 | case 16: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1202 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | 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 Xu | c907ee7 | 2006-08-21 22:04:03 +1000 | [diff] [blame] | 1213 | test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | break; |
| 1215 | |
| 1216 | case 19: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1217 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | break; |
| 1222 | |
| 1223 | case 20: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1224 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | break; |
| 1229 | |
| 1230 | case 21: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1231 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | 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 Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1250 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | break; |
| 1255 | |
| 1256 | case 26: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1257 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | 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 Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 1279 | |
| 1280 | case 30: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1281 | 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 Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 1285 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | |
David Howells | 9083163 | 2006-12-16 12:13:14 +1100 | [diff] [blame] | 1287 | 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 TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1294 | 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 Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame^] | 1308 | case 33: |
| 1309 | test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS); |
| 1310 | break; |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | case 100: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1313 | test_hash("hmac(md5)", hmac_md5_tv_template, |
| 1314 | HMAC_MD5_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | case 101: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1318 | test_hash("hmac(sha1)", hmac_sha1_tv_template, |
| 1319 | HMAC_SHA1_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | case 102: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1323 | test_hash("hmac(sha256)", hmac_sha256_tv_template, |
| 1324 | HMAC_SHA256_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | break; |
| 1326 | |
Andrew Donofrio | a28091a | 2006-12-10 12:10:20 +1100 | [diff] [blame] | 1327 | 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 Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame^] | 1336 | case 105: |
| 1337 | test_hash("hmac(sha224)", hmac_sha224_tv_template, |
| 1338 | HMAC_SHA224_TEST_VECTORS); |
| 1339 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1341 | case 200: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1342 | test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1343 | aes_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1344 | test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1345 | aes_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1346 | test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1347 | aes_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1348 | test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1349 | aes_speed_template); |
Rik Snel | f3d1044 | 2006-11-29 19:01:41 +1100 | [diff] [blame] | 1350 | 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 Snel | f19f511 | 2007-09-19 20:23:13 +0800 | [diff] [blame] | 1354 | 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 Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1358 | break; |
| 1359 | |
| 1360 | case 201: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1361 | test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1362 | des3_ede_enc_tv_template, |
| 1363 | DES3_EDE_ENC_TEST_VECTORS, |
| 1364 | des3_ede_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1365 | test_cipher_speed("ecb(des3_ede)", DECRYPT, sec, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1366 | des3_ede_dec_tv_template, |
| 1367 | DES3_EDE_DEC_TEST_VECTORS, |
| 1368 | des3_ede_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1369 | test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1370 | des3_ede_enc_tv_template, |
| 1371 | DES3_EDE_ENC_TEST_VECTORS, |
| 1372 | des3_ede_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1373 | test_cipher_speed("cbc(des3_ede)", DECRYPT, sec, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1374 | des3_ede_dec_tv_template, |
| 1375 | DES3_EDE_DEC_TEST_VECTORS, |
| 1376 | des3_ede_speed_template); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1377 | break; |
| 1378 | |
| 1379 | case 202: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1380 | test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1381 | twofish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1382 | test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1383 | twofish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1384 | test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1385 | twofish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1386 | test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1387 | twofish_speed_template); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1388 | break; |
| 1389 | |
| 1390 | case 203: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1391 | test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1392 | blowfish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1393 | test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1394 | blowfish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1395 | test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1396 | blowfish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1397 | test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1398 | blowfish_speed_template); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1399 | break; |
| 1400 | |
| 1401 | case 204: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1402 | test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1403 | des_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1404 | test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1405 | des_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1406 | test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1407 | des_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1408 | test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1409 | des_speed_template); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1410 | break; |
| 1411 | |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1412 | 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 Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1423 | case 300: |
| 1424 | /* fall through */ |
| 1425 | |
| 1426 | case 301: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1427 | test_hash_speed("md4", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1428 | if (mode > 300 && mode < 400) break; |
| 1429 | |
| 1430 | case 302: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1431 | test_hash_speed("md5", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1432 | if (mode > 300 && mode < 400) break; |
| 1433 | |
| 1434 | case 303: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1435 | test_hash_speed("sha1", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1436 | if (mode > 300 && mode < 400) break; |
| 1437 | |
| 1438 | case 304: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1439 | test_hash_speed("sha256", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1440 | if (mode > 300 && mode < 400) break; |
| 1441 | |
| 1442 | case 305: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1443 | test_hash_speed("sha384", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1444 | if (mode > 300 && mode < 400) break; |
| 1445 | |
| 1446 | case 306: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1447 | test_hash_speed("sha512", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1448 | if (mode > 300 && mode < 400) break; |
| 1449 | |
| 1450 | case 307: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1451 | test_hash_speed("wp256", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1452 | if (mode > 300 && mode < 400) break; |
| 1453 | |
| 1454 | case 308: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1455 | test_hash_speed("wp384", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1456 | if (mode > 300 && mode < 400) break; |
| 1457 | |
| 1458 | case 309: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1459 | test_hash_speed("wp512", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1460 | if (mode > 300 && mode < 400) break; |
| 1461 | |
| 1462 | case 310: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1463 | test_hash_speed("tgr128", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1464 | if (mode > 300 && mode < 400) break; |
| 1465 | |
| 1466 | case 311: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1467 | test_hash_speed("tgr160", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1468 | if (mode > 300 && mode < 400) break; |
| 1469 | |
| 1470 | case 312: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1471 | test_hash_speed("tgr192", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1472 | if (mode > 300 && mode < 400) break; |
| 1473 | |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame^] | 1474 | case 313: |
| 1475 | test_hash_speed("sha224", sec, generic_hash_speed_template); |
| 1476 | if (mode > 300 && mode < 400) break; |
| 1477 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1478 | case 399: |
| 1479 | break; |
| 1480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | case 1000: |
| 1482 | test_available(); |
| 1483 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | default: |
| 1486 | /* useful for debugging */ |
| 1487 | printk("not testing anything\n"); |
| 1488 | break; |
| 1489 | } |
| 1490 | } |
| 1491 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1492 | static int __init init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | { |
| 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 Ludvig | 14fdf47 | 2006-05-30 14:49:38 +1000 | [diff] [blame] | 1508 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | /* |
| 1519 | * If an init function is provided, an exit function must also be provided |
| 1520 | * to allow module unload. |
| 1521 | */ |
| 1522 | static void __exit fini(void) { } |
| 1523 | |
| 1524 | module_init(init); |
| 1525 | module_exit(fini); |
| 1526 | |
| 1527 | module_param(mode, int, 0); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1528 | module_param(sec, uint, 0); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 1529 | MODULE_PARM_DESC(sec, "Length in seconds of speed tests " |
| 1530 | "(defaults to zero which uses CPU cycles instead)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | |
| 1532 | MODULE_LICENSE("GPL"); |
| 1533 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); |
| 1534 | MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>"); |