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