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