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