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