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