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