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