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