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> |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame^] | 9 | * Copyright (c) 2007 Nokia Siemens Networks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify it |
| 12 | * 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] | 13 | * Software Foundation; either version 2 of the License, or (at your option) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * any later version. |
| 15 | * |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame^] | 16 | * 2007-11-13 Added AEAD support |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 17 | * 2007-11-06 Added SHA-224 and SHA-224-HMAC tests |
Andrew Donofrio | a28091a | 2006-12-10 12:10:20 +1100 | [diff] [blame] | 18 | * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 19 | * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>) |
| 20 | * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt |
| 21 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | */ |
| 23 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 24 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/init.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/mm.h> |
| 28 | #include <linux/slab.h> |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 29 | #include <linux/scatterlist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/string.h> |
| 31 | #include <linux/crypto.h> |
| 32 | #include <linux/highmem.h> |
| 33 | #include <linux/moduleparam.h> |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 34 | #include <linux/jiffies.h> |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 35 | #include <linux/timex.h> |
| 36 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include "tcrypt.h" |
| 38 | |
| 39 | /* |
| 40 | * Need to kmalloc() memory for testing kmap(). |
| 41 | */ |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 42 | #define TVMEMSIZE 16384 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #define XBUFSIZE 32768 |
| 44 | |
| 45 | /* |
| 46 | * Indexes into the xbuf to simulate cross-page access. |
| 47 | */ |
| 48 | #define IDX1 37 |
| 49 | #define IDX2 32400 |
| 50 | #define IDX3 1 |
| 51 | #define IDX4 8193 |
| 52 | #define IDX5 22222 |
| 53 | #define IDX6 17101 |
| 54 | #define IDX7 27333 |
| 55 | #define IDX8 3000 |
| 56 | |
| 57 | /* |
| 58 | * Used by test_cipher() |
| 59 | */ |
| 60 | #define ENCRYPT 1 |
| 61 | #define DECRYPT 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 63 | struct tcrypt_result { |
| 64 | struct completion completion; |
| 65 | int err; |
| 66 | }; |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; |
| 69 | |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 70 | /* |
| 71 | * Used by test_cipher_speed() |
| 72 | */ |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 73 | static unsigned int sec; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | static int mode; |
| 76 | static char *xbuf; |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame^] | 77 | static char *axbuf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | static char *tvmem; |
| 79 | |
| 80 | static char *check[] = { |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 81 | "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", |
| 82 | "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes", |
| 83 | "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 84 | "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", |
David Howells | 9083163 | 2006-12-16 12:13:14 +1100 | [diff] [blame] | 85 | "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", |
Tan Swee Heng | 2407d60 | 2007-11-23 19:45:00 +0800 | [diff] [blame] | 86 | "camellia", "seed", "salsa20", NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 89 | static void hexdump(unsigned char *buf, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
| 91 | while (len--) |
| 92 | printk("%02x", *buf++); |
| 93 | |
| 94 | printk("\n"); |
| 95 | } |
| 96 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 97 | static void tcrypt_complete(struct crypto_async_request *req, int err) |
| 98 | { |
| 99 | struct tcrypt_result *res = req->data; |
| 100 | |
| 101 | if (err == -EINPROGRESS) |
| 102 | return; |
| 103 | |
| 104 | res->err = err; |
| 105 | complete(&res->completion); |
| 106 | } |
| 107 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 108 | static void test_hash(char *algo, struct hash_testvec *template, |
| 109 | unsigned int tcount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 111 | unsigned int i, j, k, temp; |
| 112 | struct scatterlist sg[8]; |
| 113 | char result[64]; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 114 | struct crypto_hash *tfm; |
| 115 | struct hash_desc desc; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 116 | struct hash_testvec *hash_tv; |
| 117 | unsigned int tsize; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 118 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 120 | printk("\ntesting %s\n", algo); |
| 121 | |
| 122 | tsize = sizeof(struct hash_testvec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | tsize *= tcount; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | if (tsize > TVMEMSIZE) { |
| 126 | printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE); |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | memcpy(tvmem, template, tsize); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 131 | hash_tv = (void *)tvmem; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 132 | |
| 133 | tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); |
| 134 | if (IS_ERR(tfm)) { |
| 135 | printk("failed to load transform for %s: %ld\n", algo, |
| 136 | PTR_ERR(tfm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | return; |
| 138 | } |
| 139 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 140 | desc.tfm = tfm; |
| 141 | desc.flags = 0; |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | for (i = 0; i < tcount; i++) { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 144 | printk("test %u:\n", i + 1); |
| 145 | memset(result, 0, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
David S. Miller | b733588 | 2007-10-26 00:38:10 -0700 | [diff] [blame] | 147 | 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] | 148 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 149 | if (hash_tv[i].ksize) { |
| 150 | ret = crypto_hash_setkey(tfm, hash_tv[i].key, |
| 151 | hash_tv[i].ksize); |
| 152 | if (ret) { |
| 153 | printk("setkey() failed ret=%d\n", ret); |
| 154 | goto out; |
| 155 | } |
| 156 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 158 | ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, result); |
| 159 | if (ret) { |
| 160 | printk("digest () failed ret=%d\n", ret); |
| 161 | goto out; |
| 162 | } |
| 163 | |
| 164 | hexdump(result, crypto_hash_digestsize(tfm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | printk("%s\n", |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 166 | memcmp(result, hash_tv[i].digest, |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 167 | crypto_hash_digestsize(tfm)) ? |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 168 | "fail" : "pass"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 171 | printk("testing %s across pages\n", algo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | /* setup the dummy buffer first */ |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 174 | memset(xbuf, 0, XBUFSIZE); |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame^] | 175 | memset(axbuf, 0, XBUFSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | j = 0; |
| 178 | for (i = 0; i < tcount; i++) { |
| 179 | if (hash_tv[i].np) { |
| 180 | j++; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 181 | printk("test %u:\n", j); |
| 182 | memset(result, 0, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | temp = 0; |
David S. Miller | b733588 | 2007-10-26 00:38:10 -0700 | [diff] [blame] | 185 | sg_init_table(sg, hash_tv[i].np); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | for (k = 0; k < hash_tv[i].np; k++) { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 187 | memcpy(&xbuf[IDX[k]], |
| 188 | hash_tv[i].plaintext + temp, |
| 189 | hash_tv[i].tap[k]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | temp += hash_tv[i].tap[k]; |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 191 | sg_set_buf(&sg[k], &xbuf[IDX[k]], |
| 192 | hash_tv[i].tap[k]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 195 | if (hash_tv[i].ksize) { |
| 196 | ret = crypto_hash_setkey(tfm, hash_tv[i].key, |
| 197 | hash_tv[i].ksize); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 198 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 199 | if (ret) { |
| 200 | printk("setkey() failed ret=%d\n", ret); |
| 201 | goto out; |
| 202 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 205 | ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, |
| 206 | result); |
| 207 | if (ret) { |
| 208 | printk("digest () failed ret=%d\n", ret); |
| 209 | goto out; |
| 210 | } |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 211 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 212 | hexdump(result, crypto_hash_digestsize(tfm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | printk("%s\n", |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 214 | memcmp(result, hash_tv[i].digest, |
| 215 | crypto_hash_digestsize(tfm)) ? |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 216 | "fail" : "pass"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | } |
| 218 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 220 | out: |
| 221 | crypto_free_hash(tfm); |
| 222 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame^] | 224 | static void test_aead(char *algo, int enc, struct aead_testvec *template, |
| 225 | unsigned int tcount) |
| 226 | { |
| 227 | unsigned int ret, i, j, k, temp; |
| 228 | unsigned int tsize; |
| 229 | char *q; |
| 230 | struct crypto_aead *tfm; |
| 231 | char *key; |
| 232 | struct aead_testvec *aead_tv; |
| 233 | struct aead_request *req; |
| 234 | struct scatterlist sg[8]; |
| 235 | struct scatterlist asg[8]; |
| 236 | const char *e; |
| 237 | struct tcrypt_result result; |
| 238 | |
| 239 | if (enc == ENCRYPT) |
| 240 | e = "encryption"; |
| 241 | else |
| 242 | e = "decryption"; |
| 243 | |
| 244 | printk(KERN_INFO "\ntesting %s %s\n", algo, e); |
| 245 | |
| 246 | tsize = sizeof(struct aead_testvec); |
| 247 | tsize *= tcount; |
| 248 | |
| 249 | if (tsize > TVMEMSIZE) { |
| 250 | printk(KERN_INFO "template (%u) too big for tvmem (%u)\n", |
| 251 | tsize, TVMEMSIZE); |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | memcpy(tvmem, template, tsize); |
| 256 | aead_tv = (void *)tvmem; |
| 257 | |
| 258 | init_completion(&result.completion); |
| 259 | |
| 260 | tfm = crypto_alloc_aead(algo, 0, 0); |
| 261 | |
| 262 | if (IS_ERR(tfm)) { |
| 263 | printk(KERN_INFO "failed to load transform for %s: %ld\n", |
| 264 | algo, PTR_ERR(tfm)); |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | req = aead_request_alloc(tfm, GFP_KERNEL); |
| 269 | if (!req) { |
| 270 | printk(KERN_INFO "failed to allocate request for %s\n", algo); |
| 271 | goto out; |
| 272 | } |
| 273 | |
| 274 | aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
| 275 | tcrypt_complete, &result); |
| 276 | |
| 277 | for (i = 0, j = 0; i < tcount; i++) { |
| 278 | if (!aead_tv[i].np) { |
| 279 | printk(KERN_INFO "test %u (%d bit key):\n", |
| 280 | ++j, aead_tv[i].klen * 8); |
| 281 | |
| 282 | crypto_aead_clear_flags(tfm, ~0); |
| 283 | if (aead_tv[i].wk) |
| 284 | crypto_aead_set_flags( |
| 285 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
| 286 | key = aead_tv[i].key; |
| 287 | |
| 288 | ret = crypto_aead_setkey(tfm, key, |
| 289 | aead_tv[i].klen); |
| 290 | if (ret) { |
| 291 | printk(KERN_INFO "setkey() failed flags=%x\n", |
| 292 | crypto_aead_get_flags(tfm)); |
| 293 | |
| 294 | if (!aead_tv[i].fail) |
| 295 | goto out; |
| 296 | } |
| 297 | |
| 298 | sg_init_one(&sg[0], aead_tv[i].input, |
| 299 | aead_tv[i].ilen); |
| 300 | |
| 301 | sg_init_one(&asg[0], aead_tv[i].assoc, |
| 302 | aead_tv[i].alen); |
| 303 | |
| 304 | aead_request_set_crypt(req, sg, sg, |
| 305 | aead_tv[i].ilen, |
| 306 | aead_tv[i].iv); |
| 307 | |
| 308 | aead_request_set_assoc(req, asg, aead_tv[i].alen); |
| 309 | |
| 310 | if (enc) { |
| 311 | ret = crypto_aead_encrypt(req); |
| 312 | } else { |
| 313 | memcpy(req->__ctx, aead_tv[i].tag, |
| 314 | aead_tv[i].tlen); |
| 315 | ret = crypto_aead_decrypt(req); |
| 316 | } |
| 317 | |
| 318 | switch (ret) { |
| 319 | case 0: |
| 320 | break; |
| 321 | case -EINPROGRESS: |
| 322 | case -EBUSY: |
| 323 | ret = wait_for_completion_interruptible( |
| 324 | &result.completion); |
| 325 | if (!ret && !(ret = result.err)) { |
| 326 | INIT_COMPLETION(result.completion); |
| 327 | break; |
| 328 | } |
| 329 | /* fall through */ |
| 330 | default: |
| 331 | printk(KERN_INFO "%s () failed err=%d\n", |
| 332 | e, -ret); |
| 333 | goto out; |
| 334 | } |
| 335 | |
| 336 | q = kmap(sg_page(&sg[0])) + sg[0].offset; |
| 337 | hexdump(q, aead_tv[i].rlen); |
| 338 | printk(KERN_INFO "auth tag: "); |
| 339 | hexdump((unsigned char *)req->__ctx, aead_tv[i].tlen); |
| 340 | |
| 341 | printk(KERN_INFO "enc/dec: %s\n", |
| 342 | memcmp(q, aead_tv[i].result, |
| 343 | aead_tv[i].rlen) ? "fail" : "pass"); |
| 344 | |
| 345 | printk(KERN_INFO "auth tag: %s\n", |
| 346 | memcmp(req->__ctx, aead_tv[i].tag, |
| 347 | aead_tv[i].tlen) ? "fail" : "pass"); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e); |
| 352 | memset(xbuf, 0, XBUFSIZE); |
| 353 | |
| 354 | for (i = 0, j = 0; i < tcount; i++) { |
| 355 | if (aead_tv[i].np) { |
| 356 | printk(KERN_INFO "test %u (%d bit key):\n", |
| 357 | ++j, aead_tv[i].klen * 8); |
| 358 | |
| 359 | crypto_aead_clear_flags(tfm, ~0); |
| 360 | if (aead_tv[i].wk) |
| 361 | crypto_aead_set_flags( |
| 362 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
| 363 | key = aead_tv[i].key; |
| 364 | |
| 365 | ret = crypto_aead_setkey(tfm, key, aead_tv[i].klen); |
| 366 | if (ret) { |
| 367 | printk(KERN_INFO "setkey() failed flags=%x\n", |
| 368 | crypto_aead_get_flags(tfm)); |
| 369 | |
| 370 | if (!aead_tv[i].fail) |
| 371 | goto out; |
| 372 | } |
| 373 | |
| 374 | sg_init_table(sg, aead_tv[i].np); |
| 375 | for (k = 0, temp = 0; k < aead_tv[i].np; k++) { |
| 376 | memcpy(&xbuf[IDX[k]], |
| 377 | aead_tv[i].input + temp, |
| 378 | aead_tv[i].tap[k]); |
| 379 | temp += aead_tv[i].tap[k]; |
| 380 | sg_set_buf(&sg[k], &xbuf[IDX[k]], |
| 381 | aead_tv[i].tap[k]); |
| 382 | } |
| 383 | |
| 384 | sg_init_table(asg, aead_tv[i].anp); |
| 385 | for (k = 0, temp = 0; k < aead_tv[i].anp; k++) { |
| 386 | memcpy(&axbuf[IDX[k]], |
| 387 | aead_tv[i].assoc + temp, |
| 388 | aead_tv[i].atap[k]); |
| 389 | temp += aead_tv[i].atap[k]; |
| 390 | sg_set_buf(&asg[k], &axbuf[IDX[k]], |
| 391 | aead_tv[i].atap[k]); |
| 392 | } |
| 393 | |
| 394 | aead_request_set_crypt(req, sg, sg, |
| 395 | aead_tv[i].ilen, |
| 396 | aead_tv[i].iv); |
| 397 | |
| 398 | aead_request_set_assoc(req, asg, aead_tv[i].alen); |
| 399 | |
| 400 | if (enc) { |
| 401 | ret = crypto_aead_encrypt(req); |
| 402 | } else { |
| 403 | memcpy(req->__ctx, aead_tv[i].tag, |
| 404 | aead_tv[i].tlen); |
| 405 | ret = crypto_aead_decrypt(req); |
| 406 | } |
| 407 | |
| 408 | switch (ret) { |
| 409 | case 0: |
| 410 | break; |
| 411 | case -EINPROGRESS: |
| 412 | case -EBUSY: |
| 413 | ret = wait_for_completion_interruptible( |
| 414 | &result.completion); |
| 415 | if (!ret && !(ret = result.err)) { |
| 416 | INIT_COMPLETION(result.completion); |
| 417 | break; |
| 418 | } |
| 419 | /* fall through */ |
| 420 | default: |
| 421 | printk(KERN_INFO "%s () failed err=%d\n", |
| 422 | e, -ret); |
| 423 | goto out; |
| 424 | } |
| 425 | |
| 426 | for (k = 0, temp = 0; k < aead_tv[i].np; k++) { |
| 427 | printk(KERN_INFO "page %u\n", k); |
| 428 | q = kmap(sg_page(&sg[k])) + sg[k].offset; |
| 429 | hexdump(q, aead_tv[i].tap[k]); |
| 430 | printk(KERN_INFO "%s\n", |
| 431 | memcmp(q, aead_tv[i].result + temp, |
| 432 | aead_tv[i].tap[k]) ? |
| 433 | "fail" : "pass"); |
| 434 | |
| 435 | temp += aead_tv[i].tap[k]; |
| 436 | } |
| 437 | printk(KERN_INFO "auth tag: "); |
| 438 | hexdump((unsigned char *)req->__ctx, aead_tv[i].tlen); |
| 439 | |
| 440 | printk(KERN_INFO "auth tag: %s\n", |
| 441 | memcmp(req->__ctx, aead_tv[i].tag, |
| 442 | aead_tv[i].tlen) ? "fail" : "pass"); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | out: |
| 447 | crypto_free_aead(tfm); |
| 448 | aead_request_free(req); |
| 449 | } |
| 450 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 451 | static void test_cipher(char *algo, int enc, |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 452 | struct cipher_testvec *template, unsigned int tcount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | { |
| 454 | unsigned int ret, i, j, k, temp; |
| 455 | unsigned int tsize; |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 456 | char *q; |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 457 | struct crypto_ablkcipher *tfm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | char *key; |
| 459 | struct cipher_testvec *cipher_tv; |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 460 | struct ablkcipher_request *req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | struct scatterlist sg[8]; |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 462 | const char *e; |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 463 | struct tcrypt_result result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
| 465 | if (enc == ENCRYPT) |
Herbert Xu | 3cc3816 | 2005-06-22 13:26:36 -0700 | [diff] [blame] | 466 | e = "encryption"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | else |
Herbert Xu | 3cc3816 | 2005-06-22 13:26:36 -0700 | [diff] [blame] | 468 | e = "decryption"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 470 | printk("\ntesting %s %s\n", algo, e); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 472 | tsize = sizeof (struct cipher_testvec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | tsize *= tcount; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | if (tsize > TVMEMSIZE) { |
| 476 | printk("template (%u) too big for tvmem (%u)\n", tsize, |
| 477 | TVMEMSIZE); |
| 478 | return; |
| 479 | } |
| 480 | |
| 481 | memcpy(tvmem, template, tsize); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 482 | cipher_tv = (void *)tvmem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 484 | init_completion(&result.completion); |
| 485 | |
| 486 | tfm = crypto_alloc_ablkcipher(algo, 0, 0); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 487 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 488 | if (IS_ERR(tfm)) { |
| 489 | printk("failed to load transform for %s: %ld\n", algo, |
| 490 | PTR_ERR(tfm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | return; |
| 492 | } |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 493 | |
| 494 | req = ablkcipher_request_alloc(tfm, GFP_KERNEL); |
| 495 | if (!req) { |
| 496 | printk("failed to allocate request for %s\n", algo); |
| 497 | goto out; |
| 498 | } |
| 499 | |
| 500 | ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
| 501 | tcrypt_complete, &result); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | j = 0; |
| 504 | for (i = 0; i < tcount; i++) { |
| 505 | if (!(cipher_tv[i].np)) { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 506 | j++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | printk("test %u (%d bit key):\n", |
| 508 | j, cipher_tv[i].klen * 8); |
| 509 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 510 | crypto_ablkcipher_clear_flags(tfm, ~0); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 511 | if (cipher_tv[i].wk) |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 512 | crypto_ablkcipher_set_flags( |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 513 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | key = cipher_tv[i].key; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 515 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 516 | ret = crypto_ablkcipher_setkey(tfm, key, |
| 517 | cipher_tv[i].klen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | if (ret) { |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 519 | printk("setkey() failed flags=%x\n", |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 520 | crypto_ablkcipher_get_flags(tfm)); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | if (!cipher_tv[i].fail) |
| 523 | goto out; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 524 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
David S. Miller | b733588 | 2007-10-26 00:38:10 -0700 | [diff] [blame] | 526 | sg_init_one(&sg[0], cipher_tv[i].input, |
| 527 | cipher_tv[i].ilen); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 528 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 529 | ablkcipher_request_set_crypt(req, sg, sg, |
| 530 | cipher_tv[i].ilen, |
| 531 | cipher_tv[i].iv); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 532 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 533 | ret = enc ? |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 534 | crypto_ablkcipher_encrypt(req) : |
| 535 | crypto_ablkcipher_decrypt(req); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 536 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 537 | switch (ret) { |
| 538 | case 0: |
| 539 | break; |
| 540 | case -EINPROGRESS: |
| 541 | case -EBUSY: |
| 542 | ret = wait_for_completion_interruptible( |
| 543 | &result.completion); |
| 544 | if (!ret && !((ret = result.err))) { |
| 545 | INIT_COMPLETION(result.completion); |
| 546 | break; |
| 547 | } |
| 548 | /* fall through */ |
| 549 | default: |
| 550 | printk("%s () failed err=%d\n", e, -ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | goto out; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Jens Axboe | 78c2f0b | 2007-10-22 19:40:16 +0200 | [diff] [blame] | 554 | q = kmap(sg_page(&sg[0])) + sg[0].offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | hexdump(q, cipher_tv[i].rlen); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 556 | |
| 557 | printk("%s\n", |
| 558 | memcmp(q, cipher_tv[i].result, |
| 559 | cipher_tv[i].rlen) ? "fail" : "pass"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | } |
| 561 | } |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 562 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 563 | printk("\ntesting %s %s across pages (chunking)\n", algo, e); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | memset(xbuf, 0, XBUFSIZE); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | j = 0; |
| 567 | for (i = 0; i < tcount; i++) { |
| 568 | if (cipher_tv[i].np) { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 569 | j++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | printk("test %u (%d bit key):\n", |
| 571 | j, cipher_tv[i].klen * 8); |
| 572 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 573 | crypto_ablkcipher_clear_flags(tfm, ~0); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 574 | if (cipher_tv[i].wk) |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 575 | crypto_ablkcipher_set_flags( |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 576 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | key = cipher_tv[i].key; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 578 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 579 | ret = crypto_ablkcipher_setkey(tfm, key, |
| 580 | cipher_tv[i].klen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | if (ret) { |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 582 | printk("setkey() failed flags=%x\n", |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 583 | crypto_ablkcipher_get_flags(tfm)); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | if (!cipher_tv[i].fail) |
| 586 | goto out; |
| 587 | } |
| 588 | |
| 589 | temp = 0; |
David S. Miller | b733588 | 2007-10-26 00:38:10 -0700 | [diff] [blame] | 590 | sg_init_table(sg, cipher_tv[i].np); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | for (k = 0; k < cipher_tv[i].np; k++) { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 592 | memcpy(&xbuf[IDX[k]], |
| 593 | cipher_tv[i].input + temp, |
| 594 | cipher_tv[i].tap[k]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | temp += cipher_tv[i].tap[k]; |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 596 | sg_set_buf(&sg[k], &xbuf[IDX[k]], |
| 597 | cipher_tv[i].tap[k]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | } |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 599 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 600 | ablkcipher_request_set_crypt(req, sg, sg, |
| 601 | cipher_tv[i].ilen, |
| 602 | cipher_tv[i].iv); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 603 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 604 | ret = enc ? |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 605 | crypto_ablkcipher_encrypt(req) : |
| 606 | crypto_ablkcipher_decrypt(req); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 607 | |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 608 | switch (ret) { |
| 609 | case 0: |
| 610 | break; |
| 611 | case -EINPROGRESS: |
| 612 | case -EBUSY: |
| 613 | ret = wait_for_completion_interruptible( |
| 614 | &result.completion); |
| 615 | if (!ret && !((ret = result.err))) { |
| 616 | INIT_COMPLETION(result.completion); |
| 617 | break; |
| 618 | } |
| 619 | /* fall through */ |
| 620 | default: |
| 621 | printk("%s () failed err=%d\n", e, -ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | goto out; |
| 623 | } |
| 624 | |
| 625 | temp = 0; |
| 626 | for (k = 0; k < cipher_tv[i].np; k++) { |
| 627 | printk("page %u\n", k); |
Jens Axboe | 78c2f0b | 2007-10-22 19:40:16 +0200 | [diff] [blame] | 628 | q = kmap(sg_page(&sg[k])) + sg[k].offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | hexdump(q, cipher_tv[i].tap[k]); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 630 | printk("%s\n", |
| 631 | memcmp(q, cipher_tv[i].result + temp, |
| 632 | cipher_tv[i].tap[k]) ? "fail" : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | "pass"); |
| 634 | temp += cipher_tv[i].tap[k]; |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | out: |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 640 | crypto_free_ablkcipher(tfm); |
| 641 | ablkcipher_request_free(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | } |
| 643 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 644 | 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] | 645 | int blen, int sec) |
| 646 | { |
Herbert Xu | 6df5b9f | 2005-09-19 22:30:11 +1000 | [diff] [blame] | 647 | struct scatterlist sg[1]; |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 648 | unsigned long start, end; |
| 649 | int bcount; |
| 650 | int ret; |
| 651 | |
David S. Miller | b733588 | 2007-10-26 00:38:10 -0700 | [diff] [blame] | 652 | sg_init_one(sg, p, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 653 | |
| 654 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
| 655 | time_before(jiffies, end); bcount++) { |
| 656 | if (enc) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 657 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 658 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 659 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 660 | |
| 661 | if (ret) |
| 662 | return ret; |
| 663 | } |
| 664 | |
| 665 | printk("%d operations in %d seconds (%ld bytes)\n", |
| 666 | bcount, sec, (long)bcount * blen); |
| 667 | return 0; |
| 668 | } |
| 669 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 670 | 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] | 671 | int blen) |
| 672 | { |
Herbert Xu | 6df5b9f | 2005-09-19 22:30:11 +1000 | [diff] [blame] | 673 | struct scatterlist sg[1]; |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 674 | unsigned long cycles = 0; |
| 675 | int ret = 0; |
| 676 | int i; |
| 677 | |
David S. Miller | b733588 | 2007-10-26 00:38:10 -0700 | [diff] [blame] | 678 | sg_init_one(sg, p, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 679 | |
| 680 | local_bh_disable(); |
| 681 | local_irq_disable(); |
| 682 | |
| 683 | /* Warm-up run. */ |
| 684 | for (i = 0; i < 4; i++) { |
| 685 | if (enc) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 686 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 687 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 688 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 689 | |
| 690 | if (ret) |
| 691 | goto out; |
| 692 | } |
| 693 | |
| 694 | /* The real thing. */ |
| 695 | for (i = 0; i < 8; i++) { |
| 696 | cycles_t start, end; |
| 697 | |
| 698 | start = get_cycles(); |
| 699 | if (enc) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 700 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 701 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 702 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 703 | end = get_cycles(); |
| 704 | |
| 705 | if (ret) |
| 706 | goto out; |
| 707 | |
| 708 | cycles += end - start; |
| 709 | } |
| 710 | |
| 711 | out: |
| 712 | local_irq_enable(); |
| 713 | local_bh_enable(); |
| 714 | |
| 715 | if (ret == 0) |
| 716 | printk("1 operation in %lu cycles (%d bytes)\n", |
| 717 | (cycles + 4) / 8, blen); |
| 718 | |
| 719 | return ret; |
| 720 | } |
| 721 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 722 | static void test_cipher_speed(char *algo, int enc, unsigned int sec, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 723 | struct cipher_testvec *template, |
| 724 | unsigned int tcount, struct cipher_speed *speed) |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 725 | { |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 726 | unsigned int ret, i, j, iv_len; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 727 | unsigned char *key, *p, iv[128]; |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 728 | struct crypto_blkcipher *tfm; |
| 729 | struct blkcipher_desc desc; |
| 730 | const char *e; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 731 | |
| 732 | if (enc == ENCRYPT) |
| 733 | e = "encryption"; |
| 734 | else |
| 735 | e = "decryption"; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 736 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 737 | printk("\ntesting speed of %s %s\n", algo, e); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 738 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 739 | tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 740 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 741 | if (IS_ERR(tfm)) { |
| 742 | printk("failed to load transform for %s: %ld\n", algo, |
| 743 | PTR_ERR(tfm)); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 744 | return; |
| 745 | } |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 746 | desc.tfm = tfm; |
| 747 | desc.flags = 0; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 748 | |
| 749 | for (i = 0; speed[i].klen != 0; i++) { |
| 750 | if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) { |
| 751 | printk("template (%u) too big for tvmem (%u)\n", |
| 752 | speed[i].blen + speed[i].klen, TVMEMSIZE); |
| 753 | goto out; |
| 754 | } |
| 755 | |
| 756 | printk("test %u (%d bit key, %d byte blocks): ", i, |
| 757 | speed[i].klen * 8, speed[i].blen); |
| 758 | |
| 759 | memset(tvmem, 0xff, speed[i].klen + speed[i].blen); |
| 760 | |
| 761 | /* set key, plain text and IV */ |
| 762 | key = (unsigned char *)tvmem; |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 763 | for (j = 0; j < tcount; j++) { |
| 764 | if (template[j].klen == speed[i].klen) { |
| 765 | key = template[j].key; |
| 766 | break; |
| 767 | } |
| 768 | } |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 769 | p = (unsigned char *)tvmem + speed[i].klen; |
| 770 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 771 | ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 772 | if (ret) { |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 773 | printk("setkey() failed flags=%x\n", |
| 774 | crypto_blkcipher_get_flags(tfm)); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 775 | goto out; |
| 776 | } |
| 777 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 778 | iv_len = crypto_blkcipher_ivsize(tfm); |
| 779 | if (iv_len) { |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 780 | memset(&iv, 0xff, iv_len); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 781 | crypto_blkcipher_set_iv(tfm, iv, iv_len); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 784 | if (sec) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 785 | ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen, |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 786 | sec); |
| 787 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 788 | ret = test_cipher_cycles(&desc, enc, p, speed[i].blen); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 789 | |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 790 | if (ret) { |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 791 | printk("%s() failed flags=%x\n", e, desc.flags); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 792 | break; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 793 | } |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | out: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 797 | crypto_free_blkcipher(tfm); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 800 | static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen, |
| 801 | char *out, int sec) |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 802 | { |
| 803 | struct scatterlist sg[1]; |
| 804 | unsigned long start, end; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 805 | int bcount; |
| 806 | int ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 807 | |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 808 | sg_init_table(sg, 1); |
| 809 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 810 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
| 811 | time_before(jiffies, end); bcount++) { |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 812 | sg_set_buf(sg, p, blen); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 813 | ret = crypto_hash_digest(desc, sg, blen, out); |
| 814 | if (ret) |
| 815 | return ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | printk("%6u opers/sec, %9lu bytes/sec\n", |
| 819 | bcount / sec, ((long)bcount * blen) / sec); |
| 820 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 821 | return 0; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 822 | } |
| 823 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 824 | static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen, |
| 825 | int plen, char *out, int sec) |
| 826 | { |
| 827 | struct scatterlist sg[1]; |
| 828 | unsigned long start, end; |
| 829 | int bcount, pcount; |
| 830 | int ret; |
| 831 | |
| 832 | if (plen == blen) |
| 833 | return test_hash_jiffies_digest(desc, p, blen, out, sec); |
| 834 | |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 835 | sg_init_table(sg, 1); |
| 836 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 837 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
| 838 | time_before(jiffies, end); bcount++) { |
| 839 | ret = crypto_hash_init(desc); |
| 840 | if (ret) |
| 841 | return ret; |
| 842 | for (pcount = 0; pcount < blen; pcount += plen) { |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 843 | sg_set_buf(sg, p + pcount, plen); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 844 | ret = crypto_hash_update(desc, sg, plen); |
| 845 | if (ret) |
| 846 | return ret; |
| 847 | } |
| 848 | /* we assume there is enough space in 'out' for the result */ |
| 849 | ret = crypto_hash_final(desc, out); |
| 850 | if (ret) |
| 851 | return ret; |
| 852 | } |
| 853 | |
| 854 | printk("%6u opers/sec, %9lu bytes/sec\n", |
| 855 | bcount / sec, ((long)bcount * blen) / sec); |
| 856 | |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen, |
| 861 | char *out) |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 862 | { |
| 863 | struct scatterlist sg[1]; |
| 864 | unsigned long cycles = 0; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 865 | int i; |
| 866 | int ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 867 | |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 868 | sg_init_table(sg, 1); |
| 869 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 870 | local_bh_disable(); |
| 871 | local_irq_disable(); |
| 872 | |
| 873 | /* Warm-up run. */ |
| 874 | for (i = 0; i < 4; i++) { |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 875 | sg_set_buf(sg, p, blen); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 876 | ret = crypto_hash_digest(desc, sg, blen, out); |
| 877 | if (ret) |
| 878 | goto out; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | /* The real thing. */ |
| 882 | for (i = 0; i < 8; i++) { |
| 883 | cycles_t start, end; |
| 884 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 885 | start = get_cycles(); |
| 886 | |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 887 | sg_set_buf(sg, p, blen); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 888 | ret = crypto_hash_digest(desc, sg, blen, out); |
| 889 | if (ret) |
| 890 | goto out; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 891 | |
| 892 | end = get_cycles(); |
| 893 | |
| 894 | cycles += end - start; |
| 895 | } |
| 896 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 897 | out: |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 898 | local_irq_enable(); |
| 899 | local_bh_enable(); |
| 900 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 901 | if (ret) |
| 902 | return ret; |
| 903 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 904 | printk("%6lu cycles/operation, %4lu cycles/byte\n", |
| 905 | cycles / 8, cycles / (8 * blen)); |
| 906 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 907 | return 0; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 908 | } |
| 909 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 910 | static int test_hash_cycles(struct hash_desc *desc, char *p, int blen, |
| 911 | int plen, char *out) |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 912 | { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 913 | struct scatterlist sg[1]; |
| 914 | unsigned long cycles = 0; |
| 915 | int i, pcount; |
| 916 | int ret; |
| 917 | |
| 918 | if (plen == blen) |
| 919 | return test_hash_cycles_digest(desc, p, blen, out); |
| 920 | |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 921 | sg_init_table(sg, 1); |
| 922 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 923 | local_bh_disable(); |
| 924 | local_irq_disable(); |
| 925 | |
| 926 | /* Warm-up run. */ |
| 927 | for (i = 0; i < 4; i++) { |
| 928 | ret = crypto_hash_init(desc); |
| 929 | if (ret) |
| 930 | goto out; |
| 931 | for (pcount = 0; pcount < blen; pcount += plen) { |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 932 | sg_set_buf(sg, p + pcount, plen); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 933 | ret = crypto_hash_update(desc, sg, plen); |
| 934 | if (ret) |
| 935 | goto out; |
| 936 | } |
Herbert Xu | 29059d1 | 2007-05-18 16:25:19 +1000 | [diff] [blame] | 937 | ret = crypto_hash_final(desc, out); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 938 | if (ret) |
| 939 | goto out; |
| 940 | } |
| 941 | |
| 942 | /* The real thing. */ |
| 943 | for (i = 0; i < 8; i++) { |
| 944 | cycles_t start, end; |
| 945 | |
| 946 | start = get_cycles(); |
| 947 | |
| 948 | ret = crypto_hash_init(desc); |
| 949 | if (ret) |
| 950 | goto out; |
| 951 | for (pcount = 0; pcount < blen; pcount += plen) { |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 952 | sg_set_buf(sg, p + pcount, plen); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 953 | ret = crypto_hash_update(desc, sg, plen); |
| 954 | if (ret) |
| 955 | goto out; |
| 956 | } |
| 957 | ret = crypto_hash_final(desc, out); |
| 958 | if (ret) |
| 959 | goto out; |
| 960 | |
| 961 | end = get_cycles(); |
| 962 | |
| 963 | cycles += end - start; |
| 964 | } |
| 965 | |
| 966 | out: |
| 967 | local_irq_enable(); |
| 968 | local_bh_enable(); |
| 969 | |
| 970 | if (ret) |
| 971 | return ret; |
| 972 | |
| 973 | printk("%6lu cycles/operation, %4lu cycles/byte\n", |
| 974 | cycles / 8, cycles / (8 * blen)); |
| 975 | |
| 976 | return 0; |
| 977 | } |
| 978 | |
| 979 | static void test_hash_speed(char *algo, unsigned int sec, |
| 980 | struct hash_speed *speed) |
| 981 | { |
| 982 | struct crypto_hash *tfm; |
| 983 | struct hash_desc desc; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 984 | char output[1024]; |
| 985 | int i; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 986 | int ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 987 | |
| 988 | printk("\ntesting speed of %s\n", algo); |
| 989 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 990 | tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 991 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 992 | if (IS_ERR(tfm)) { |
| 993 | printk("failed to load transform for %s: %ld\n", algo, |
| 994 | PTR_ERR(tfm)); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 995 | return; |
| 996 | } |
| 997 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 998 | desc.tfm = tfm; |
| 999 | desc.flags = 0; |
| 1000 | |
| 1001 | if (crypto_hash_digestsize(tfm) > sizeof(output)) { |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1002 | printk("digestsize(%u) > outputbuffer(%zu)\n", |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1003 | crypto_hash_digestsize(tfm), sizeof(output)); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1004 | goto out; |
| 1005 | } |
| 1006 | |
| 1007 | for (i = 0; speed[i].blen != 0; i++) { |
| 1008 | if (speed[i].blen > TVMEMSIZE) { |
| 1009 | printk("template (%u) too big for tvmem (%u)\n", |
| 1010 | speed[i].blen, TVMEMSIZE); |
| 1011 | goto out; |
| 1012 | } |
| 1013 | |
| 1014 | printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ", |
| 1015 | i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); |
| 1016 | |
| 1017 | memset(tvmem, 0xff, speed[i].blen); |
| 1018 | |
| 1019 | if (sec) |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1020 | ret = test_hash_jiffies(&desc, tvmem, speed[i].blen, |
| 1021 | speed[i].plen, output, sec); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1022 | else |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1023 | ret = test_hash_cycles(&desc, tvmem, speed[i].blen, |
| 1024 | speed[i].plen, output); |
| 1025 | |
| 1026 | if (ret) { |
| 1027 | printk("hashing failed ret=%d\n", ret); |
| 1028 | break; |
| 1029 | } |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | out: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1033 | crypto_free_hash(tfm); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1034 | } |
| 1035 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1036 | static void test_deflate(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | { |
| 1038 | unsigned int i; |
| 1039 | char result[COMP_BUF_SIZE]; |
Herbert Xu | e4d5b79 | 2006-08-26 18:12:40 +1000 | [diff] [blame] | 1040 | struct crypto_comp *tfm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | struct comp_testvec *tv; |
| 1042 | unsigned int tsize; |
| 1043 | |
| 1044 | printk("\ntesting deflate compression\n"); |
| 1045 | |
| 1046 | tsize = sizeof (deflate_comp_tv_template); |
| 1047 | if (tsize > TVMEMSIZE) { |
| 1048 | printk("template (%u) too big for tvmem (%u)\n", tsize, |
| 1049 | TVMEMSIZE); |
| 1050 | return; |
| 1051 | } |
| 1052 | |
| 1053 | memcpy(tvmem, deflate_comp_tv_template, tsize); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1054 | tv = (void *)tvmem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | |
Herbert Xu | ba8da2a | 2006-12-17 08:57:38 +1100 | [diff] [blame] | 1056 | tfm = crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC); |
Sebastian Siewior | 7bc301e | 2007-03-21 08:58:43 +1100 | [diff] [blame] | 1057 | if (IS_ERR(tfm)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | printk("failed to load transform for deflate\n"); |
| 1059 | return; |
| 1060 | } |
| 1061 | |
| 1062 | for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) { |
| 1063 | int ilen, ret, dlen = COMP_BUF_SIZE; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | printk("test %u:\n", i + 1); |
| 1066 | memset(result, 0, sizeof (result)); |
| 1067 | |
| 1068 | ilen = tv[i].inlen; |
| 1069 | ret = crypto_comp_compress(tfm, tv[i].input, |
| 1070 | ilen, result, &dlen); |
| 1071 | if (ret) { |
| 1072 | printk("fail: ret=%d\n", ret); |
| 1073 | continue; |
| 1074 | } |
| 1075 | hexdump(result, dlen); |
| 1076 | printk("%s (ratio %d:%d)\n", |
| 1077 | memcmp(result, tv[i].output, dlen) ? "fail" : "pass", |
| 1078 | ilen, dlen); |
| 1079 | } |
| 1080 | |
| 1081 | printk("\ntesting deflate decompression\n"); |
| 1082 | |
| 1083 | tsize = sizeof (deflate_decomp_tv_template); |
| 1084 | if (tsize > TVMEMSIZE) { |
| 1085 | printk("template (%u) too big for tvmem (%u)\n", tsize, |
| 1086 | TVMEMSIZE); |
| 1087 | goto out; |
| 1088 | } |
| 1089 | |
| 1090 | memcpy(tvmem, deflate_decomp_tv_template, tsize); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1091 | tv = (void *)tvmem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | |
| 1093 | for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) { |
| 1094 | int ilen, ret, dlen = COMP_BUF_SIZE; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1095 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | printk("test %u:\n", i + 1); |
| 1097 | memset(result, 0, sizeof (result)); |
| 1098 | |
| 1099 | ilen = tv[i].inlen; |
| 1100 | ret = crypto_comp_decompress(tfm, tv[i].input, |
| 1101 | ilen, result, &dlen); |
| 1102 | if (ret) { |
| 1103 | printk("fail: ret=%d\n", ret); |
| 1104 | continue; |
| 1105 | } |
| 1106 | hexdump(result, dlen); |
| 1107 | printk("%s (ratio %d:%d)\n", |
| 1108 | memcmp(result, tv[i].output, dlen) ? "fail" : "pass", |
| 1109 | ilen, dlen); |
| 1110 | } |
| 1111 | out: |
Herbert Xu | e4d5b79 | 2006-08-26 18:12:40 +1000 | [diff] [blame] | 1112 | crypto_free_comp(tfm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | } |
| 1114 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1115 | static void test_available(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | { |
| 1117 | char **name = check; |
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 | while (*name) { |
| 1120 | printk("alg %s ", *name); |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 1121 | printk(crypto_has_alg(*name, 0, 0) ? |
Herbert Xu | e4d5b79 | 2006-08-26 18:12:40 +1000 | [diff] [blame] | 1122 | "found\n" : "not found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | name++; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1124 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1127 | static void do_test(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | { |
| 1129 | switch (mode) { |
| 1130 | |
| 1131 | case 0: |
| 1132 | test_hash("md5", md5_tv_template, MD5_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | //DES |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1137 | test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template, |
| 1138 | DES_ENC_TEST_VECTORS); |
| 1139 | test_cipher("ecb(des)", DECRYPT, des_dec_tv_template, |
| 1140 | DES_DEC_TEST_VECTORS); |
| 1141 | test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template, |
| 1142 | DES_CBC_ENC_TEST_VECTORS); |
| 1143 | test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template, |
| 1144 | DES_CBC_DEC_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | //DES3_EDE |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1147 | test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template, |
| 1148 | DES3_EDE_ENC_TEST_VECTORS); |
| 1149 | test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template, |
| 1150 | DES3_EDE_DEC_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1153 | |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 1154 | test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS); |
| 1155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | //BLOWFISH |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1159 | test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template, |
| 1160 | BF_ENC_TEST_VECTORS); |
| 1161 | test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template, |
| 1162 | BF_DEC_TEST_VECTORS); |
| 1163 | test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template, |
| 1164 | BF_CBC_ENC_TEST_VECTORS); |
| 1165 | test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template, |
| 1166 | BF_CBC_DEC_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | //TWOFISH |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1169 | test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template, |
| 1170 | TF_ENC_TEST_VECTORS); |
| 1171 | test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template, |
| 1172 | TF_DEC_TEST_VECTORS); |
| 1173 | test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template, |
| 1174 | TF_CBC_ENC_TEST_VECTORS); |
| 1175 | test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template, |
| 1176 | TF_CBC_DEC_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | //SERPENT |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1179 | test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template, |
| 1180 | SERPENT_ENC_TEST_VECTORS); |
| 1181 | test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template, |
| 1182 | SERPENT_DEC_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | //TNEPRES |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1185 | test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template, |
| 1186 | TNEPRES_ENC_TEST_VECTORS); |
| 1187 | test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template, |
| 1188 | TNEPRES_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | |
| 1190 | //AES |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1191 | test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template, |
| 1192 | AES_ENC_TEST_VECTORS); |
| 1193 | test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template, |
| 1194 | AES_DEC_TEST_VECTORS); |
| 1195 | test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template, |
| 1196 | AES_CBC_ENC_TEST_VECTORS); |
| 1197 | test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template, |
| 1198 | AES_CBC_DEC_TEST_VECTORS); |
Rik Snel | f3d1044 | 2006-11-29 19:01:41 +1100 | [diff] [blame] | 1199 | test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template, |
| 1200 | AES_LRW_ENC_TEST_VECTORS); |
| 1201 | test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template, |
| 1202 | AES_LRW_DEC_TEST_VECTORS); |
Rik Snel | f19f511 | 2007-09-19 20:23:13 +0800 | [diff] [blame] | 1203 | test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template, |
| 1204 | AES_XTS_ENC_TEST_VECTORS); |
| 1205 | test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template, |
| 1206 | AES_XTS_DEC_TEST_VECTORS); |
Joy Latten | 41fdab3 | 2007-11-07 22:59:47 +0800 | [diff] [blame] | 1207 | 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] | 1208 | AES_CTR_ENC_TEST_VECTORS); |
Joy Latten | 41fdab3 | 2007-11-07 22:59:47 +0800 | [diff] [blame] | 1209 | 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] | 1210 | AES_CTR_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | |
| 1212 | //CAST5 |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1213 | test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template, |
| 1214 | CAST5_ENC_TEST_VECTORS); |
| 1215 | test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template, |
| 1216 | CAST5_DEC_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | //CAST6 |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1219 | test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template, |
| 1220 | CAST6_ENC_TEST_VECTORS); |
| 1221 | test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template, |
| 1222 | CAST6_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | |
| 1224 | //ARC4 |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1225 | test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template, |
| 1226 | ARC4_ENC_TEST_VECTORS); |
| 1227 | test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template, |
| 1228 | ARC4_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | |
| 1230 | //TEA |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1231 | test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template, |
| 1232 | TEA_ENC_TEST_VECTORS); |
| 1233 | test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template, |
| 1234 | TEA_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | |
| 1236 | |
| 1237 | //XTEA |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1238 | test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template, |
| 1239 | XTEA_ENC_TEST_VECTORS); |
| 1240 | test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template, |
| 1241 | XTEA_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | |
| 1243 | //KHAZAD |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1244 | test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template, |
| 1245 | KHAZAD_ENC_TEST_VECTORS); |
| 1246 | test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template, |
| 1247 | KHAZAD_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | |
| 1249 | //ANUBIS |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1250 | test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template, |
| 1251 | ANUBIS_ENC_TEST_VECTORS); |
| 1252 | test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template, |
| 1253 | ANUBIS_DEC_TEST_VECTORS); |
| 1254 | test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template, |
| 1255 | ANUBIS_CBC_ENC_TEST_VECTORS); |
| 1256 | test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template, |
| 1257 | ANUBIS_CBC_ENC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | |
Aaron Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 1259 | //XETA |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1260 | test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template, |
| 1261 | XETA_ENC_TEST_VECTORS); |
| 1262 | test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template, |
| 1263 | XETA_DEC_TEST_VECTORS); |
Aaron Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 1264 | |
David Howells | 9083163 | 2006-12-16 12:13:14 +1100 | [diff] [blame] | 1265 | //FCrypt |
| 1266 | test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template, |
| 1267 | FCRYPT_ENC_TEST_VECTORS); |
| 1268 | test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template, |
| 1269 | FCRYPT_DEC_TEST_VECTORS); |
| 1270 | |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1271 | //CAMELLIA |
| 1272 | test_cipher("ecb(camellia)", ENCRYPT, |
| 1273 | camellia_enc_tv_template, |
| 1274 | CAMELLIA_ENC_TEST_VECTORS); |
| 1275 | test_cipher("ecb(camellia)", DECRYPT, |
| 1276 | camellia_dec_tv_template, |
| 1277 | CAMELLIA_DEC_TEST_VECTORS); |
| 1278 | test_cipher("cbc(camellia)", ENCRYPT, |
| 1279 | camellia_cbc_enc_tv_template, |
| 1280 | CAMELLIA_CBC_ENC_TEST_VECTORS); |
| 1281 | test_cipher("cbc(camellia)", DECRYPT, |
| 1282 | camellia_cbc_dec_tv_template, |
| 1283 | CAMELLIA_CBC_DEC_TEST_VECTORS); |
| 1284 | |
Hye-Shik Chang | e2ee95b | 2007-08-21 20:01:03 +0800 | [diff] [blame] | 1285 | //SEED |
| 1286 | test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template, |
| 1287 | SEED_ENC_TEST_VECTORS); |
| 1288 | test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template, |
| 1289 | SEED_DEC_TEST_VECTORS); |
| 1290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS); |
| 1292 | test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS); |
| 1293 | test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS); |
| 1294 | test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS); |
| 1295 | test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS); |
| 1296 | test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS); |
| 1297 | test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS); |
| 1298 | test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); |
| 1299 | test_deflate(); |
Herbert Xu | c907ee7 | 2006-08-21 22:04:03 +1000 | [diff] [blame] | 1300 | test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1301 | test_hash("hmac(md5)", hmac_md5_tv_template, |
| 1302 | HMAC_MD5_TEST_VECTORS); |
| 1303 | test_hash("hmac(sha1)", hmac_sha1_tv_template, |
| 1304 | HMAC_SHA1_TEST_VECTORS); |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 1305 | test_hash("hmac(sha224)", hmac_sha224_tv_template, |
| 1306 | HMAC_SHA224_TEST_VECTORS); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1307 | test_hash("hmac(sha256)", hmac_sha256_tv_template, |
| 1308 | HMAC_SHA256_TEST_VECTORS); |
Andrew Donofrio | a28091a | 2006-12-10 12:10:20 +1100 | [diff] [blame] | 1309 | test_hash("hmac(sha384)", hmac_sha384_tv_template, |
| 1310 | HMAC_SHA384_TEST_VECTORS); |
| 1311 | test_hash("hmac(sha512)", hmac_sha512_tv_template, |
| 1312 | HMAC_SHA512_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | |
Kazunori MIYAZAWA | 5b2becf | 2006-10-28 13:18:53 +1000 | [diff] [blame] | 1314 | test_hash("xcbc(aes)", aes_xcbc128_tv_template, |
| 1315 | XCBC_AES_TEST_VECTORS); |
| 1316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS); |
| 1318 | break; |
| 1319 | |
| 1320 | case 1: |
| 1321 | test_hash("md5", md5_tv_template, MD5_TEST_VECTORS); |
| 1322 | break; |
| 1323 | |
| 1324 | case 2: |
| 1325 | test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS); |
| 1326 | break; |
| 1327 | |
| 1328 | case 3: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1329 | test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template, |
| 1330 | DES_ENC_TEST_VECTORS); |
| 1331 | test_cipher("ecb(des)", DECRYPT, des_dec_tv_template, |
| 1332 | DES_DEC_TEST_VECTORS); |
| 1333 | test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template, |
| 1334 | DES_CBC_ENC_TEST_VECTORS); |
| 1335 | test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template, |
| 1336 | DES_CBC_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | break; |
| 1338 | |
| 1339 | case 4: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1340 | test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template, |
| 1341 | DES3_EDE_ENC_TEST_VECTORS); |
| 1342 | test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template, |
| 1343 | DES3_EDE_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | break; |
| 1345 | |
| 1346 | case 5: |
| 1347 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); |
| 1348 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | case 6: |
| 1351 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); |
| 1352 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | case 7: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1355 | test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template, |
| 1356 | BF_ENC_TEST_VECTORS); |
| 1357 | test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template, |
| 1358 | BF_DEC_TEST_VECTORS); |
| 1359 | test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template, |
| 1360 | BF_CBC_ENC_TEST_VECTORS); |
| 1361 | test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template, |
| 1362 | BF_CBC_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | break; |
| 1364 | |
| 1365 | case 8: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1366 | test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template, |
| 1367 | TF_ENC_TEST_VECTORS); |
| 1368 | test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template, |
| 1369 | TF_DEC_TEST_VECTORS); |
| 1370 | test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template, |
| 1371 | TF_CBC_ENC_TEST_VECTORS); |
| 1372 | test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template, |
| 1373 | TF_CBC_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | case 9: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1377 | test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template, |
| 1378 | SERPENT_ENC_TEST_VECTORS); |
| 1379 | test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template, |
| 1380 | SERPENT_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | break; |
| 1382 | |
| 1383 | case 10: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1384 | test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template, |
| 1385 | AES_ENC_TEST_VECTORS); |
| 1386 | test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template, |
| 1387 | AES_DEC_TEST_VECTORS); |
| 1388 | test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template, |
| 1389 | AES_CBC_ENC_TEST_VECTORS); |
| 1390 | test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template, |
| 1391 | AES_CBC_DEC_TEST_VECTORS); |
Rik Snel | f3d1044 | 2006-11-29 19:01:41 +1100 | [diff] [blame] | 1392 | test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template, |
| 1393 | AES_LRW_ENC_TEST_VECTORS); |
| 1394 | test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template, |
| 1395 | AES_LRW_DEC_TEST_VECTORS); |
Rik Snel | f19f511 | 2007-09-19 20:23:13 +0800 | [diff] [blame] | 1396 | test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template, |
| 1397 | AES_XTS_ENC_TEST_VECTORS); |
| 1398 | test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template, |
| 1399 | AES_XTS_DEC_TEST_VECTORS); |
Joy Latten | 41fdab3 | 2007-11-07 22:59:47 +0800 | [diff] [blame] | 1400 | 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] | 1401 | AES_CTR_ENC_TEST_VECTORS); |
Joy Latten | 41fdab3 | 2007-11-07 22:59:47 +0800 | [diff] [blame] | 1402 | 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] | 1403 | AES_CTR_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | break; |
| 1405 | |
| 1406 | case 11: |
| 1407 | test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS); |
| 1408 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | case 12: |
| 1411 | test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS); |
| 1412 | break; |
| 1413 | |
| 1414 | case 13: |
| 1415 | test_deflate(); |
| 1416 | break; |
| 1417 | |
| 1418 | case 14: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1419 | test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template, |
| 1420 | CAST5_ENC_TEST_VECTORS); |
| 1421 | test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template, |
| 1422 | CAST5_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | break; |
| 1424 | |
| 1425 | case 15: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1426 | test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template, |
| 1427 | CAST6_ENC_TEST_VECTORS); |
| 1428 | test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template, |
| 1429 | CAST6_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | break; |
| 1431 | |
| 1432 | case 16: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1433 | test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template, |
| 1434 | ARC4_ENC_TEST_VECTORS); |
| 1435 | test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template, |
| 1436 | ARC4_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | break; |
| 1438 | |
| 1439 | case 17: |
| 1440 | test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS); |
| 1441 | break; |
| 1442 | |
| 1443 | case 18: |
Herbert Xu | c907ee7 | 2006-08-21 22:04:03 +1000 | [diff] [blame] | 1444 | test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | break; |
| 1446 | |
| 1447 | case 19: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1448 | test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template, |
| 1449 | TEA_ENC_TEST_VECTORS); |
| 1450 | test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template, |
| 1451 | TEA_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | break; |
| 1453 | |
| 1454 | case 20: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1455 | test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template, |
| 1456 | XTEA_ENC_TEST_VECTORS); |
| 1457 | test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template, |
| 1458 | XTEA_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | break; |
| 1460 | |
| 1461 | case 21: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1462 | test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template, |
| 1463 | KHAZAD_ENC_TEST_VECTORS); |
| 1464 | test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template, |
| 1465 | KHAZAD_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | break; |
| 1467 | |
| 1468 | case 22: |
| 1469 | test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS); |
| 1470 | break; |
| 1471 | |
| 1472 | case 23: |
| 1473 | test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS); |
| 1474 | break; |
| 1475 | |
| 1476 | case 24: |
| 1477 | test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS); |
| 1478 | break; |
| 1479 | |
| 1480 | case 25: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1481 | test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template, |
| 1482 | TNEPRES_ENC_TEST_VECTORS); |
| 1483 | test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template, |
| 1484 | TNEPRES_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | break; |
| 1486 | |
| 1487 | case 26: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1488 | test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template, |
| 1489 | ANUBIS_ENC_TEST_VECTORS); |
| 1490 | test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template, |
| 1491 | ANUBIS_DEC_TEST_VECTORS); |
| 1492 | test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template, |
| 1493 | ANUBIS_CBC_ENC_TEST_VECTORS); |
| 1494 | test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template, |
| 1495 | ANUBIS_CBC_ENC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | break; |
| 1497 | |
| 1498 | case 27: |
| 1499 | test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS); |
| 1500 | break; |
| 1501 | |
| 1502 | case 28: |
| 1503 | |
| 1504 | test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS); |
| 1505 | break; |
| 1506 | |
| 1507 | case 29: |
| 1508 | test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); |
| 1509 | break; |
Aaron Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 1510 | |
| 1511 | case 30: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1512 | test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template, |
| 1513 | XETA_ENC_TEST_VECTORS); |
| 1514 | test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template, |
| 1515 | XETA_DEC_TEST_VECTORS); |
Aaron Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 1516 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | |
David Howells | 9083163 | 2006-12-16 12:13:14 +1100 | [diff] [blame] | 1518 | case 31: |
| 1519 | test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template, |
| 1520 | FCRYPT_ENC_TEST_VECTORS); |
| 1521 | test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template, |
| 1522 | FCRYPT_DEC_TEST_VECTORS); |
| 1523 | break; |
| 1524 | |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1525 | case 32: |
| 1526 | test_cipher("ecb(camellia)", ENCRYPT, |
| 1527 | camellia_enc_tv_template, |
| 1528 | CAMELLIA_ENC_TEST_VECTORS); |
| 1529 | test_cipher("ecb(camellia)", DECRYPT, |
| 1530 | camellia_dec_tv_template, |
| 1531 | CAMELLIA_DEC_TEST_VECTORS); |
| 1532 | test_cipher("cbc(camellia)", ENCRYPT, |
| 1533 | camellia_cbc_enc_tv_template, |
| 1534 | CAMELLIA_CBC_ENC_TEST_VECTORS); |
| 1535 | test_cipher("cbc(camellia)", DECRYPT, |
| 1536 | camellia_cbc_dec_tv_template, |
| 1537 | CAMELLIA_CBC_DEC_TEST_VECTORS); |
| 1538 | break; |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 1539 | case 33: |
| 1540 | test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS); |
| 1541 | break; |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1542 | |
Tan Swee Heng | 2407d60 | 2007-11-23 19:45:00 +0800 | [diff] [blame] | 1543 | case 34: |
| 1544 | test_cipher("salsa20", ENCRYPT, |
| 1545 | salsa20_stream_enc_tv_template, |
| 1546 | SALSA20_STREAM_ENC_TEST_VECTORS); |
| 1547 | break; |
| 1548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | case 100: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1550 | test_hash("hmac(md5)", hmac_md5_tv_template, |
| 1551 | HMAC_MD5_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | case 101: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1555 | test_hash("hmac(sha1)", hmac_sha1_tv_template, |
| 1556 | HMAC_SHA1_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | case 102: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1560 | test_hash("hmac(sha256)", hmac_sha256_tv_template, |
| 1561 | HMAC_SHA256_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | break; |
| 1563 | |
Andrew Donofrio | a28091a | 2006-12-10 12:10:20 +1100 | [diff] [blame] | 1564 | case 103: |
| 1565 | test_hash("hmac(sha384)", hmac_sha384_tv_template, |
| 1566 | HMAC_SHA384_TEST_VECTORS); |
| 1567 | break; |
| 1568 | |
| 1569 | case 104: |
| 1570 | test_hash("hmac(sha512)", hmac_sha512_tv_template, |
| 1571 | HMAC_SHA512_TEST_VECTORS); |
| 1572 | break; |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 1573 | case 105: |
| 1574 | test_hash("hmac(sha224)", hmac_sha224_tv_template, |
| 1575 | HMAC_SHA224_TEST_VECTORS); |
| 1576 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1578 | case 200: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1579 | test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1580 | aes_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1581 | test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1582 | aes_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1583 | test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1584 | aes_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1585 | test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1586 | aes_speed_template); |
Rik Snel | f3d1044 | 2006-11-29 19:01:41 +1100 | [diff] [blame] | 1587 | test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, |
| 1588 | aes_lrw_speed_template); |
| 1589 | test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, |
| 1590 | aes_lrw_speed_template); |
Rik Snel | f19f511 | 2007-09-19 20:23:13 +0800 | [diff] [blame] | 1591 | test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, |
| 1592 | aes_xts_speed_template); |
| 1593 | test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, |
| 1594 | aes_xts_speed_template); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1595 | break; |
| 1596 | |
| 1597 | case 201: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1598 | test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1599 | des3_ede_enc_tv_template, |
| 1600 | DES3_EDE_ENC_TEST_VECTORS, |
| 1601 | des3_ede_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1602 | test_cipher_speed("ecb(des3_ede)", DECRYPT, sec, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1603 | des3_ede_dec_tv_template, |
| 1604 | DES3_EDE_DEC_TEST_VECTORS, |
| 1605 | des3_ede_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1606 | test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1607 | des3_ede_enc_tv_template, |
| 1608 | DES3_EDE_ENC_TEST_VECTORS, |
| 1609 | des3_ede_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1610 | test_cipher_speed("cbc(des3_ede)", DECRYPT, sec, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1611 | des3_ede_dec_tv_template, |
| 1612 | DES3_EDE_DEC_TEST_VECTORS, |
| 1613 | des3_ede_speed_template); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1614 | break; |
| 1615 | |
| 1616 | case 202: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1617 | test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1618 | twofish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1619 | test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1620 | twofish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1621 | test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1622 | twofish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1623 | test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1624 | twofish_speed_template); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1625 | break; |
| 1626 | |
| 1627 | case 203: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1628 | test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1629 | blowfish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1630 | test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1631 | blowfish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1632 | test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1633 | blowfish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1634 | test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1635 | blowfish_speed_template); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1636 | break; |
| 1637 | |
| 1638 | case 204: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1639 | test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1640 | des_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1641 | test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1642 | des_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1643 | test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1644 | des_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1645 | test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1646 | des_speed_template); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1647 | break; |
| 1648 | |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1649 | case 205: |
| 1650 | test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, |
| 1651 | camellia_speed_template); |
| 1652 | test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, |
| 1653 | camellia_speed_template); |
| 1654 | test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, |
| 1655 | camellia_speed_template); |
| 1656 | test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, |
| 1657 | camellia_speed_template); |
| 1658 | break; |
| 1659 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1660 | case 300: |
| 1661 | /* fall through */ |
| 1662 | |
| 1663 | case 301: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1664 | test_hash_speed("md4", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1665 | if (mode > 300 && mode < 400) break; |
| 1666 | |
| 1667 | case 302: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1668 | test_hash_speed("md5", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1669 | if (mode > 300 && mode < 400) break; |
| 1670 | |
| 1671 | case 303: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1672 | test_hash_speed("sha1", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1673 | if (mode > 300 && mode < 400) break; |
| 1674 | |
| 1675 | case 304: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1676 | test_hash_speed("sha256", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1677 | if (mode > 300 && mode < 400) break; |
| 1678 | |
| 1679 | case 305: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1680 | test_hash_speed("sha384", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1681 | if (mode > 300 && mode < 400) break; |
| 1682 | |
| 1683 | case 306: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1684 | test_hash_speed("sha512", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1685 | if (mode > 300 && mode < 400) break; |
| 1686 | |
| 1687 | case 307: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1688 | test_hash_speed("wp256", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1689 | if (mode > 300 && mode < 400) break; |
| 1690 | |
| 1691 | case 308: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1692 | test_hash_speed("wp384", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1693 | if (mode > 300 && mode < 400) break; |
| 1694 | |
| 1695 | case 309: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1696 | test_hash_speed("wp512", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1697 | if (mode > 300 && mode < 400) break; |
| 1698 | |
| 1699 | case 310: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1700 | test_hash_speed("tgr128", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1701 | if (mode > 300 && mode < 400) break; |
| 1702 | |
| 1703 | case 311: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1704 | test_hash_speed("tgr160", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1705 | if (mode > 300 && mode < 400) break; |
| 1706 | |
| 1707 | case 312: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1708 | test_hash_speed("tgr192", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1709 | if (mode > 300 && mode < 400) break; |
| 1710 | |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 1711 | case 313: |
| 1712 | test_hash_speed("sha224", sec, generic_hash_speed_template); |
| 1713 | if (mode > 300 && mode < 400) break; |
| 1714 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1715 | case 399: |
| 1716 | break; |
| 1717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | case 1000: |
| 1719 | test_available(); |
| 1720 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | default: |
| 1723 | /* useful for debugging */ |
| 1724 | printk("not testing anything\n"); |
| 1725 | break; |
| 1726 | } |
| 1727 | } |
| 1728 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1729 | static int __init init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | { |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame^] | 1731 | int err = -ENOMEM; |
| 1732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL); |
| 1734 | if (tvmem == NULL) |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame^] | 1735 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | |
| 1737 | xbuf = kmalloc(XBUFSIZE, GFP_KERNEL); |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame^] | 1738 | if (xbuf == NULL) |
| 1739 | goto err_free_tv; |
| 1740 | |
| 1741 | axbuf = kmalloc(XBUFSIZE, GFP_KERNEL); |
| 1742 | if (axbuf == NULL) |
| 1743 | goto err_free_xbuf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | |
| 1745 | do_test(); |
| 1746 | |
Michal Ludvig | 14fdf47 | 2006-05-30 14:49:38 +1000 | [diff] [blame] | 1747 | /* We intentionaly return -EAGAIN to prevent keeping |
| 1748 | * the module. It does all its work from init() |
| 1749 | * and doesn't offer any runtime functionality |
| 1750 | * => we don't need it in the memory, do we? |
| 1751 | * -- mludvig |
| 1752 | */ |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame^] | 1753 | err = -EAGAIN; |
| 1754 | |
| 1755 | kfree(axbuf); |
| 1756 | err_free_xbuf: |
| 1757 | kfree(xbuf); |
| 1758 | err_free_tv: |
| 1759 | kfree(tvmem); |
| 1760 | |
| 1761 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | /* |
| 1765 | * If an init function is provided, an exit function must also be provided |
| 1766 | * to allow module unload. |
| 1767 | */ |
| 1768 | static void __exit fini(void) { } |
| 1769 | |
| 1770 | module_init(init); |
| 1771 | module_exit(fini); |
| 1772 | |
| 1773 | module_param(mode, int, 0); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1774 | module_param(sec, uint, 0); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 1775 | MODULE_PARM_DESC(sec, "Length in seconds of speed tests " |
| 1776 | "(defaults to zero which uses CPU cycles instead)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | |
| 1778 | MODULE_LICENSE("GPL"); |
| 1779 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); |
| 1780 | MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>"); |