Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Quick & dirty crypto testing module. |
| 3 | * |
| 4 | * This will only exist until we have a better testing mechanism |
| 5 | * (e.g. a char device). |
| 6 | * |
| 7 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> |
| 8 | * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org> |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame] | 9 | * Copyright (c) 2007 Nokia Siemens Networks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License as published by the Free |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 13 | * Software Foundation; either version 2 of the License, or (at your option) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * any later version. |
| 15 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
Herbert Xu | 18e33e6 | 2008-07-10 16:01:22 +0800 | [diff] [blame] | 18 | #include <crypto/hash.h> |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 19 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/init.h> |
| 21 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/slab.h> |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 23 | #include <linux/scatterlist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/moduleparam.h> |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 26 | #include <linux/jiffies.h> |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 27 | #include <linux/timex.h> |
| 28 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include "tcrypt.h" |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 30 | #include "internal.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | /* |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 33 | * Need slab memory for testing (size in number of pages). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | */ |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 35 | #define TVMEMSIZE 4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | /* |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 38 | * Used by test_cipher_speed() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | */ |
| 40 | #define ENCRYPT 1 |
| 41 | #define DECRYPT 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 43 | /* |
| 44 | * Used by test_cipher_speed() |
| 45 | */ |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 46 | static unsigned int sec; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 47 | |
Steffen Klassert | a873a5f | 2009-06-19 19:46:53 +0800 | [diff] [blame] | 48 | static char *alg = NULL; |
| 49 | static u32 type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | static int mode; |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 51 | static char *tvmem[TVMEMSIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | static char *check[] = { |
Jonathan Lynch | cd12fb90 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 54 | "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", |
| 55 | "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes", |
| 56 | "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", |
David Howells | 9083163 | 2006-12-16 12:13:14 +1100 | [diff] [blame] | 57 | "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", |
Adrian-Ken Rueegsegger | 2998db3 | 2008-05-09 21:29:35 +0800 | [diff] [blame] | 58 | "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320", |
Geert Uytterhoeven | 0c01aed | 2009-03-04 15:42:15 +0800 | [diff] [blame] | 59 | "lzo", "cts", "zlib", NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 62 | static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, |
| 63 | struct scatterlist *sg, int blen, int sec) |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 64 | { |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 65 | unsigned long start, end; |
| 66 | int bcount; |
| 67 | int ret; |
| 68 | |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 69 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
| 70 | time_before(jiffies, end); bcount++) { |
| 71 | if (enc) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 72 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 73 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 74 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 75 | |
| 76 | if (ret) |
| 77 | return ret; |
| 78 | } |
| 79 | |
| 80 | printk("%d operations in %d seconds (%ld bytes)\n", |
| 81 | bcount, sec, (long)bcount * blen); |
| 82 | return 0; |
| 83 | } |
| 84 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 85 | static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, |
| 86 | struct scatterlist *sg, int blen) |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 87 | { |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 88 | unsigned long cycles = 0; |
| 89 | int ret = 0; |
| 90 | int i; |
| 91 | |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 92 | local_bh_disable(); |
| 93 | local_irq_disable(); |
| 94 | |
| 95 | /* Warm-up run. */ |
| 96 | for (i = 0; i < 4; i++) { |
| 97 | if (enc) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 98 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 99 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 100 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 101 | |
| 102 | if (ret) |
| 103 | goto out; |
| 104 | } |
| 105 | |
| 106 | /* The real thing. */ |
| 107 | for (i = 0; i < 8; i++) { |
| 108 | cycles_t start, end; |
| 109 | |
| 110 | start = get_cycles(); |
| 111 | if (enc) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 112 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 113 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 114 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 115 | end = get_cycles(); |
| 116 | |
| 117 | if (ret) |
| 118 | goto out; |
| 119 | |
| 120 | cycles += end - start; |
| 121 | } |
| 122 | |
| 123 | out: |
| 124 | local_irq_enable(); |
| 125 | local_bh_enable(); |
| 126 | |
| 127 | if (ret == 0) |
| 128 | printk("1 operation in %lu cycles (%d bytes)\n", |
| 129 | (cycles + 4) / 8, blen); |
| 130 | |
| 131 | return ret; |
| 132 | } |
| 133 | |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 134 | static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 }; |
| 135 | |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 136 | static void test_cipher_speed(const char *algo, int enc, unsigned int sec, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 137 | struct cipher_speed_template *template, |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 138 | unsigned int tcount, u8 *keysize) |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 139 | { |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 140 | unsigned int ret, i, j, iv_len; |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 141 | const char *key, iv[128]; |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 142 | struct crypto_blkcipher *tfm; |
| 143 | struct blkcipher_desc desc; |
| 144 | const char *e; |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 145 | u32 *b_size; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 146 | |
| 147 | if (enc == ENCRYPT) |
| 148 | e = "encryption"; |
| 149 | else |
| 150 | e = "decryption"; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 151 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 152 | printk("\ntesting speed of %s %s\n", algo, e); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 153 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 154 | tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 155 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 156 | if (IS_ERR(tfm)) { |
| 157 | printk("failed to load transform for %s: %ld\n", algo, |
| 158 | PTR_ERR(tfm)); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 159 | return; |
| 160 | } |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 161 | desc.tfm = tfm; |
| 162 | desc.flags = 0; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 163 | |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 164 | i = 0; |
| 165 | do { |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 166 | |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 167 | b_size = block_sizes; |
| 168 | do { |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 169 | struct scatterlist sg[TVMEMSIZE]; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 170 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 171 | if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) { |
| 172 | printk("template (%u) too big for " |
| 173 | "tvmem (%lu)\n", *keysize + *b_size, |
| 174 | TVMEMSIZE * PAGE_SIZE); |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 175 | goto out; |
| 176 | } |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 177 | |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 178 | printk("test %u (%d bit key, %d byte blocks): ", i, |
| 179 | *keysize * 8, *b_size); |
| 180 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 181 | memset(tvmem[0], 0xff, PAGE_SIZE); |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 182 | |
| 183 | /* set key, plain text and IV */ |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 184 | key = tvmem[0]; |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 185 | for (j = 0; j < tcount; j++) { |
| 186 | if (template[j].klen == *keysize) { |
| 187 | key = template[j].key; |
| 188 | break; |
| 189 | } |
| 190 | } |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 191 | |
| 192 | ret = crypto_blkcipher_setkey(tfm, key, *keysize); |
| 193 | if (ret) { |
| 194 | printk("setkey() failed flags=%x\n", |
| 195 | crypto_blkcipher_get_flags(tfm)); |
| 196 | goto out; |
| 197 | } |
| 198 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 199 | sg_init_table(sg, TVMEMSIZE); |
| 200 | sg_set_buf(sg, tvmem[0] + *keysize, |
| 201 | PAGE_SIZE - *keysize); |
| 202 | for (j = 1; j < TVMEMSIZE; j++) { |
| 203 | sg_set_buf(sg + j, tvmem[j], PAGE_SIZE); |
| 204 | memset (tvmem[j], 0xff, PAGE_SIZE); |
| 205 | } |
| 206 | |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 207 | iv_len = crypto_blkcipher_ivsize(tfm); |
| 208 | if (iv_len) { |
| 209 | memset(&iv, 0xff, iv_len); |
| 210 | crypto_blkcipher_set_iv(tfm, iv, iv_len); |
| 211 | } |
| 212 | |
| 213 | if (sec) |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 214 | ret = test_cipher_jiffies(&desc, enc, sg, |
| 215 | *b_size, sec); |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 216 | else |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 217 | ret = test_cipher_cycles(&desc, enc, sg, |
| 218 | *b_size); |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 219 | |
| 220 | if (ret) { |
| 221 | printk("%s() failed flags=%x\n", e, desc.flags); |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 222 | break; |
| 223 | } |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 224 | b_size++; |
| 225 | i++; |
| 226 | } while (*b_size); |
| 227 | keysize++; |
| 228 | } while (*keysize); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 229 | |
| 230 | out: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 231 | crypto_free_blkcipher(tfm); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 234 | static int test_hash_jiffies_digest(struct hash_desc *desc, |
| 235 | struct scatterlist *sg, int blen, |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 236 | char *out, int sec) |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 237 | { |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 238 | unsigned long start, end; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 239 | int bcount; |
| 240 | int ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 241 | |
| 242 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
| 243 | time_before(jiffies, end); bcount++) { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 244 | ret = crypto_hash_digest(desc, sg, blen, out); |
| 245 | if (ret) |
| 246 | return ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | printk("%6u opers/sec, %9lu bytes/sec\n", |
| 250 | bcount / sec, ((long)bcount * blen) / sec); |
| 251 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 252 | return 0; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 253 | } |
| 254 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 255 | static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg, |
| 256 | int blen, int plen, char *out, int sec) |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 257 | { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 258 | unsigned long start, end; |
| 259 | int bcount, pcount; |
| 260 | int ret; |
| 261 | |
| 262 | if (plen == blen) |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 263 | return test_hash_jiffies_digest(desc, sg, blen, out, sec); |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 264 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 265 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
| 266 | time_before(jiffies, end); bcount++) { |
| 267 | ret = crypto_hash_init(desc); |
| 268 | if (ret) |
| 269 | return ret; |
| 270 | for (pcount = 0; pcount < blen; pcount += plen) { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 271 | ret = crypto_hash_update(desc, sg, plen); |
| 272 | if (ret) |
| 273 | return ret; |
| 274 | } |
| 275 | /* we assume there is enough space in 'out' for the result */ |
| 276 | ret = crypto_hash_final(desc, out); |
| 277 | if (ret) |
| 278 | return ret; |
| 279 | } |
| 280 | |
| 281 | printk("%6u opers/sec, %9lu bytes/sec\n", |
| 282 | bcount / sec, ((long)bcount * blen) / sec); |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 287 | static int test_hash_cycles_digest(struct hash_desc *desc, |
| 288 | struct scatterlist *sg, int blen, char *out) |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 289 | { |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 290 | unsigned long cycles = 0; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 291 | int i; |
| 292 | int ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 293 | |
| 294 | local_bh_disable(); |
| 295 | local_irq_disable(); |
| 296 | |
| 297 | /* Warm-up run. */ |
| 298 | for (i = 0; i < 4; i++) { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 299 | ret = crypto_hash_digest(desc, sg, blen, out); |
| 300 | if (ret) |
| 301 | goto out; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /* The real thing. */ |
| 305 | for (i = 0; i < 8; i++) { |
| 306 | cycles_t start, end; |
| 307 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 308 | start = get_cycles(); |
| 309 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 310 | ret = crypto_hash_digest(desc, sg, blen, out); |
| 311 | if (ret) |
| 312 | goto out; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 313 | |
| 314 | end = get_cycles(); |
| 315 | |
| 316 | cycles += end - start; |
| 317 | } |
| 318 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 319 | out: |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 320 | local_irq_enable(); |
| 321 | local_bh_enable(); |
| 322 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 323 | if (ret) |
| 324 | return ret; |
| 325 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 326 | printk("%6lu cycles/operation, %4lu cycles/byte\n", |
| 327 | cycles / 8, cycles / (8 * blen)); |
| 328 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 329 | return 0; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 330 | } |
| 331 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 332 | static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg, |
| 333 | int blen, int plen, char *out) |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 334 | { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 335 | unsigned long cycles = 0; |
| 336 | int i, pcount; |
| 337 | int ret; |
| 338 | |
| 339 | if (plen == blen) |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 340 | return test_hash_cycles_digest(desc, sg, blen, out); |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 341 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 342 | local_bh_disable(); |
| 343 | local_irq_disable(); |
| 344 | |
| 345 | /* Warm-up run. */ |
| 346 | for (i = 0; i < 4; i++) { |
| 347 | ret = crypto_hash_init(desc); |
| 348 | if (ret) |
| 349 | goto out; |
| 350 | for (pcount = 0; pcount < blen; pcount += plen) { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 351 | ret = crypto_hash_update(desc, sg, plen); |
| 352 | if (ret) |
| 353 | goto out; |
| 354 | } |
Herbert Xu | 29059d1 | 2007-05-18 16:25:19 +1000 | [diff] [blame] | 355 | ret = crypto_hash_final(desc, out); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 356 | if (ret) |
| 357 | goto out; |
| 358 | } |
| 359 | |
| 360 | /* The real thing. */ |
| 361 | for (i = 0; i < 8; i++) { |
| 362 | cycles_t start, end; |
| 363 | |
| 364 | start = get_cycles(); |
| 365 | |
| 366 | ret = crypto_hash_init(desc); |
| 367 | if (ret) |
| 368 | goto out; |
| 369 | for (pcount = 0; pcount < blen; pcount += plen) { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 370 | ret = crypto_hash_update(desc, sg, plen); |
| 371 | if (ret) |
| 372 | goto out; |
| 373 | } |
| 374 | ret = crypto_hash_final(desc, out); |
| 375 | if (ret) |
| 376 | goto out; |
| 377 | |
| 378 | end = get_cycles(); |
| 379 | |
| 380 | cycles += end - start; |
| 381 | } |
| 382 | |
| 383 | out: |
| 384 | local_irq_enable(); |
| 385 | local_bh_enable(); |
| 386 | |
| 387 | if (ret) |
| 388 | return ret; |
| 389 | |
| 390 | printk("%6lu cycles/operation, %4lu cycles/byte\n", |
| 391 | cycles / 8, cycles / (8 * blen)); |
| 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 396 | static void test_hash_speed(const char *algo, unsigned int sec, |
| 397 | struct hash_speed *speed) |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 398 | { |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 399 | struct scatterlist sg[TVMEMSIZE]; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 400 | struct crypto_hash *tfm; |
| 401 | struct hash_desc desc; |
Frank Seidel | 376bacb | 2009-03-29 15:18:39 +0800 | [diff] [blame] | 402 | static char output[1024]; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 403 | int i; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 404 | int ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 405 | |
Frank Seidel | 376bacb | 2009-03-29 15:18:39 +0800 | [diff] [blame] | 406 | printk(KERN_INFO "\ntesting speed of %s\n", algo); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 407 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 408 | tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 409 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 410 | if (IS_ERR(tfm)) { |
Frank Seidel | 376bacb | 2009-03-29 15:18:39 +0800 | [diff] [blame] | 411 | printk(KERN_ERR "failed to load transform for %s: %ld\n", algo, |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 412 | PTR_ERR(tfm)); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 413 | return; |
| 414 | } |
| 415 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 416 | desc.tfm = tfm; |
| 417 | desc.flags = 0; |
| 418 | |
| 419 | if (crypto_hash_digestsize(tfm) > sizeof(output)) { |
Frank Seidel | 376bacb | 2009-03-29 15:18:39 +0800 | [diff] [blame] | 420 | printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n", |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 421 | crypto_hash_digestsize(tfm), sizeof(output)); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 422 | goto out; |
| 423 | } |
| 424 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 425 | sg_init_table(sg, TVMEMSIZE); |
| 426 | for (i = 0; i < TVMEMSIZE; i++) { |
| 427 | sg_set_buf(sg + i, tvmem[i], PAGE_SIZE); |
| 428 | memset(tvmem[i], 0xff, PAGE_SIZE); |
| 429 | } |
| 430 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 431 | for (i = 0; speed[i].blen != 0; i++) { |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 432 | if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) { |
Frank Seidel | 376bacb | 2009-03-29 15:18:39 +0800 | [diff] [blame] | 433 | printk(KERN_ERR |
| 434 | "template (%u) too big for tvmem (%lu)\n", |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 435 | speed[i].blen, TVMEMSIZE * PAGE_SIZE); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 436 | goto out; |
| 437 | } |
| 438 | |
Frank Seidel | 376bacb | 2009-03-29 15:18:39 +0800 | [diff] [blame] | 439 | printk(KERN_INFO "test%3u " |
| 440 | "(%5u byte blocks,%5u bytes per update,%4u updates): ", |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 441 | i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); |
| 442 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 443 | if (sec) |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 444 | ret = test_hash_jiffies(&desc, sg, speed[i].blen, |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 445 | speed[i].plen, output, sec); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 446 | else |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 447 | ret = test_hash_cycles(&desc, sg, speed[i].blen, |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 448 | speed[i].plen, output); |
| 449 | |
| 450 | if (ret) { |
Frank Seidel | 376bacb | 2009-03-29 15:18:39 +0800 | [diff] [blame] | 451 | printk(KERN_ERR "hashing failed ret=%d\n", ret); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 452 | break; |
| 453 | } |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | out: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 457 | crypto_free_hash(tfm); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 458 | } |
| 459 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 460 | static void test_available(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | { |
| 462 | char **name = check; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | while (*name) { |
| 465 | printk("alg %s ", *name); |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 466 | printk(crypto_has_alg(*name, 0, 0) ? |
Herbert Xu | e4d5b79 | 2006-08-26 18:12:40 +1000 | [diff] [blame] | 467 | "found\n" : "not found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | name++; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 469 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 472 | static inline int tcrypt_test(const char *alg) |
| 473 | { |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 474 | int ret; |
| 475 | |
| 476 | ret = alg_test(alg, alg, 0, 0); |
| 477 | /* non-fips algs return -EINVAL in fips mode */ |
| 478 | if (fips_enabled && ret == -EINVAL) |
| 479 | ret = 0; |
| 480 | return ret; |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 481 | } |
| 482 | |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 483 | static int do_test(int m) |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 484 | { |
| 485 | int i; |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 486 | int ret = 0; |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 487 | |
| 488 | switch (m) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | case 0: |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 490 | for (i = 1; i < 200; i++) |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 491 | ret += do_test(i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | break; |
| 493 | |
| 494 | case 1: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 495 | ret += tcrypt_test("md5"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | break; |
| 497 | |
| 498 | case 2: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 499 | ret += tcrypt_test("sha1"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | break; |
| 501 | |
| 502 | case 3: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 503 | ret += tcrypt_test("ecb(des)"); |
| 504 | ret += tcrypt_test("cbc(des)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | break; |
| 506 | |
| 507 | case 4: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 508 | ret += tcrypt_test("ecb(des3_ede)"); |
| 509 | ret += tcrypt_test("cbc(des3_ede)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | break; |
| 511 | |
| 512 | case 5: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 513 | ret += tcrypt_test("md4"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | case 6: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 517 | ret += tcrypt_test("sha256"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | case 7: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 521 | ret += tcrypt_test("ecb(blowfish)"); |
| 522 | ret += tcrypt_test("cbc(blowfish)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | break; |
| 524 | |
| 525 | case 8: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 526 | ret += tcrypt_test("ecb(twofish)"); |
| 527 | ret += tcrypt_test("cbc(twofish)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | case 9: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 531 | ret += tcrypt_test("ecb(serpent)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | break; |
| 533 | |
| 534 | case 10: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 535 | ret += tcrypt_test("ecb(aes)"); |
| 536 | ret += tcrypt_test("cbc(aes)"); |
| 537 | ret += tcrypt_test("lrw(aes)"); |
| 538 | ret += tcrypt_test("xts(aes)"); |
| 539 | ret += tcrypt_test("ctr(aes)"); |
| 540 | ret += tcrypt_test("rfc3686(ctr(aes))"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | break; |
| 542 | |
| 543 | case 11: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 544 | ret += tcrypt_test("sha384"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | case 12: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 548 | ret += tcrypt_test("sha512"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | break; |
| 550 | |
| 551 | case 13: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 552 | ret += tcrypt_test("deflate"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | break; |
| 554 | |
| 555 | case 14: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 556 | ret += tcrypt_test("ecb(cast5)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | break; |
| 558 | |
| 559 | case 15: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 560 | ret += tcrypt_test("ecb(cast6)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | break; |
| 562 | |
| 563 | case 16: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 564 | ret += tcrypt_test("ecb(arc4)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | break; |
| 566 | |
| 567 | case 17: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 568 | ret += tcrypt_test("michael_mic"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | break; |
| 570 | |
| 571 | case 18: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 572 | ret += tcrypt_test("crc32c"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | break; |
| 574 | |
| 575 | case 19: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 576 | ret += tcrypt_test("ecb(tea)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | break; |
| 578 | |
| 579 | case 20: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 580 | ret += tcrypt_test("ecb(xtea)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | break; |
| 582 | |
| 583 | case 21: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 584 | ret += tcrypt_test("ecb(khazad)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | break; |
| 586 | |
| 587 | case 22: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 588 | ret += tcrypt_test("wp512"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | break; |
| 590 | |
| 591 | case 23: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 592 | ret += tcrypt_test("wp384"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | break; |
| 594 | |
| 595 | case 24: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 596 | ret += tcrypt_test("wp256"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | break; |
| 598 | |
| 599 | case 25: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 600 | ret += tcrypt_test("ecb(tnepres)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | break; |
| 602 | |
| 603 | case 26: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 604 | ret += tcrypt_test("ecb(anubis)"); |
| 605 | ret += tcrypt_test("cbc(anubis)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | break; |
| 607 | |
| 608 | case 27: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 609 | ret += tcrypt_test("tgr192"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | break; |
| 611 | |
| 612 | case 28: |
| 613 | |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 614 | ret += tcrypt_test("tgr160"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | break; |
| 616 | |
| 617 | case 29: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 618 | ret += tcrypt_test("tgr128"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | break; |
Adrian-Ken Rueegsegger | 2998db3 | 2008-05-09 21:29:35 +0800 | [diff] [blame] | 620 | |
Aaron Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 621 | case 30: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 622 | ret += tcrypt_test("ecb(xeta)"); |
Aaron Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 623 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
David Howells | 9083163 | 2006-12-16 12:13:14 +1100 | [diff] [blame] | 625 | case 31: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 626 | ret += tcrypt_test("pcbc(fcrypt)"); |
David Howells | 9083163 | 2006-12-16 12:13:14 +1100 | [diff] [blame] | 627 | break; |
| 628 | |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 629 | case 32: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 630 | ret += tcrypt_test("ecb(camellia)"); |
| 631 | ret += tcrypt_test("cbc(camellia)"); |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 632 | break; |
Jonathan Lynch | cd12fb90 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 633 | case 33: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 634 | ret += tcrypt_test("sha224"); |
Jonathan Lynch | cd12fb90 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 635 | break; |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 636 | |
Tan Swee Heng | 2407d60 | 2007-11-23 19:45:00 +0800 | [diff] [blame] | 637 | case 34: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 638 | ret += tcrypt_test("salsa20"); |
Tan Swee Heng | 2407d60 | 2007-11-23 19:45:00 +0800 | [diff] [blame] | 639 | break; |
| 640 | |
Herbert Xu | 8df213d | 2007-12-02 14:55:47 +1100 | [diff] [blame] | 641 | case 35: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 642 | ret += tcrypt_test("gcm(aes)"); |
Herbert Xu | 8df213d | 2007-12-02 14:55:47 +1100 | [diff] [blame] | 643 | break; |
| 644 | |
Zoltan Sogor | 0b77abb | 2007-12-07 16:53:23 +0800 | [diff] [blame] | 645 | case 36: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 646 | ret += tcrypt_test("lzo"); |
Zoltan Sogor | 0b77abb | 2007-12-07 16:53:23 +0800 | [diff] [blame] | 647 | break; |
| 648 | |
Joy Latten | 93cc74e | 2007-12-12 20:24:22 +0800 | [diff] [blame] | 649 | case 37: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 650 | ret += tcrypt_test("ccm(aes)"); |
Joy Latten | 93cc74e | 2007-12-12 20:24:22 +0800 | [diff] [blame] | 651 | break; |
| 652 | |
Kevin Coffman | 76cb952 | 2008-03-24 21:26:16 +0800 | [diff] [blame] | 653 | case 38: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 654 | ret += tcrypt_test("cts(cbc(aes))"); |
Kevin Coffman | 76cb952 | 2008-03-24 21:26:16 +0800 | [diff] [blame] | 655 | break; |
| 656 | |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 657 | case 39: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 658 | ret += tcrypt_test("rmd128"); |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 659 | break; |
| 660 | |
| 661 | case 40: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 662 | ret += tcrypt_test("rmd160"); |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 663 | break; |
| 664 | |
Adrian-Ken Rueegsegger | 2998db3 | 2008-05-09 21:29:35 +0800 | [diff] [blame] | 665 | case 41: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 666 | ret += tcrypt_test("rmd256"); |
Adrian-Ken Rueegsegger | 2998db3 | 2008-05-09 21:29:35 +0800 | [diff] [blame] | 667 | break; |
| 668 | |
| 669 | case 42: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 670 | ret += tcrypt_test("rmd320"); |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 671 | break; |
| 672 | |
| 673 | case 43: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 674 | ret += tcrypt_test("ecb(seed)"); |
Adrian-Ken Rueegsegger | 2998db3 | 2008-05-09 21:29:35 +0800 | [diff] [blame] | 675 | break; |
| 676 | |
Geert Uytterhoeven | 0c01aed | 2009-03-04 15:42:15 +0800 | [diff] [blame] | 677 | case 44: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 678 | ret += tcrypt_test("zlib"); |
Geert Uytterhoeven | 0c01aed | 2009-03-04 15:42:15 +0800 | [diff] [blame] | 679 | break; |
| 680 | |
Jarod Wilson | 5d66732 | 2009-05-04 19:23:40 +0800 | [diff] [blame] | 681 | case 45: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 682 | ret += tcrypt_test("rfc4309(ccm(aes))"); |
Jarod Wilson | 5d66732 | 2009-05-04 19:23:40 +0800 | [diff] [blame] | 683 | break; |
| 684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | case 100: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 686 | ret += tcrypt_test("hmac(md5)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | case 101: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 690 | ret += tcrypt_test("hmac(sha1)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | case 102: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 694 | ret += tcrypt_test("hmac(sha256)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | break; |
| 696 | |
Andrew Donofrio | a28091a | 2006-12-10 12:10:20 +1100 | [diff] [blame] | 697 | case 103: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 698 | ret += tcrypt_test("hmac(sha384)"); |
Andrew Donofrio | a28091a | 2006-12-10 12:10:20 +1100 | [diff] [blame] | 699 | break; |
| 700 | |
| 701 | case 104: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 702 | ret += tcrypt_test("hmac(sha512)"); |
Andrew Donofrio | a28091a | 2006-12-10 12:10:20 +1100 | [diff] [blame] | 703 | break; |
Herbert Xu | 38ed9ab | 2008-01-01 15:59:28 +1100 | [diff] [blame] | 704 | |
Jonathan Lynch | cd12fb90 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 705 | case 105: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 706 | ret += tcrypt_test("hmac(sha224)"); |
Jonathan Lynch | cd12fb90 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 707 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
Herbert Xu | 38ed9ab | 2008-01-01 15:59:28 +1100 | [diff] [blame] | 709 | case 106: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 710 | ret += tcrypt_test("xcbc(aes)"); |
Herbert Xu | 38ed9ab | 2008-01-01 15:59:28 +1100 | [diff] [blame] | 711 | break; |
| 712 | |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 713 | case 107: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 714 | ret += tcrypt_test("hmac(rmd128)"); |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 715 | break; |
| 716 | |
| 717 | case 108: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 718 | ret += tcrypt_test("hmac(rmd160)"); |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 719 | break; |
| 720 | |
Jarod Wilson | e08ca2d | 2009-05-04 19:46:29 +0800 | [diff] [blame] | 721 | case 150: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 722 | ret += tcrypt_test("ansi_cprng"); |
Jarod Wilson | e08ca2d | 2009-05-04 19:46:29 +0800 | [diff] [blame] | 723 | break; |
| 724 | |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 725 | case 200: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 726 | test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 727 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 728 | test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 729 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 730 | test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 731 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 732 | test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 733 | speed_template_16_24_32); |
Rik Snel | f3d1044 | 2006-11-29 19:01:41 +1100 | [diff] [blame] | 734 | test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 735 | speed_template_32_40_48); |
Rik Snel | f3d1044 | 2006-11-29 19:01:41 +1100 | [diff] [blame] | 736 | test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 737 | speed_template_32_40_48); |
Rik Snel | f19f511 | 2007-09-19 20:23:13 +0800 | [diff] [blame] | 738 | test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 739 | speed_template_32_48_64); |
Rik Snel | f19f511 | 2007-09-19 20:23:13 +0800 | [diff] [blame] | 740 | test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 741 | speed_template_32_48_64); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 742 | break; |
| 743 | |
| 744 | case 201: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 745 | test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 746 | des3_speed_template, DES3_SPEED_VECTORS, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 747 | speed_template_24); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 748 | test_cipher_speed("ecb(des3_ede)", DECRYPT, sec, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 749 | des3_speed_template, DES3_SPEED_VECTORS, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 750 | speed_template_24); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 751 | test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 752 | des3_speed_template, DES3_SPEED_VECTORS, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 753 | speed_template_24); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 754 | test_cipher_speed("cbc(des3_ede)", DECRYPT, sec, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 755 | des3_speed_template, DES3_SPEED_VECTORS, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 756 | speed_template_24); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 757 | break; |
| 758 | |
| 759 | case 202: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 760 | test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 761 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 762 | test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 763 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 764 | test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 765 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 766 | test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 767 | speed_template_16_24_32); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 768 | break; |
| 769 | |
| 770 | case 203: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 771 | test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 772 | speed_template_8_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 773 | test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 774 | speed_template_8_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 775 | test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 776 | speed_template_8_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 777 | test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 778 | speed_template_8_32); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 779 | break; |
| 780 | |
| 781 | case 204: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 782 | test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 783 | speed_template_8); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 784 | test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 785 | speed_template_8); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 786 | test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 787 | speed_template_8); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 788 | test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 789 | speed_template_8); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 790 | break; |
| 791 | |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 792 | case 205: |
| 793 | test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 794 | speed_template_16_24_32); |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 795 | test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 796 | speed_template_16_24_32); |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 797 | test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 798 | speed_template_16_24_32); |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 799 | test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 800 | speed_template_16_24_32); |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 801 | break; |
| 802 | |
Tan Swee Heng | 5de8f1b | 2007-12-07 17:17:43 +0800 | [diff] [blame] | 803 | case 206: |
| 804 | test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 805 | speed_template_16_32); |
Tan Swee Heng | 5de8f1b | 2007-12-07 17:17:43 +0800 | [diff] [blame] | 806 | break; |
| 807 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 808 | case 300: |
| 809 | /* fall through */ |
| 810 | |
| 811 | case 301: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 812 | test_hash_speed("md4", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 813 | if (mode > 300 && mode < 400) break; |
| 814 | |
| 815 | case 302: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 816 | test_hash_speed("md5", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 817 | if (mode > 300 && mode < 400) break; |
| 818 | |
| 819 | case 303: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 820 | test_hash_speed("sha1", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 821 | if (mode > 300 && mode < 400) break; |
| 822 | |
| 823 | case 304: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 824 | test_hash_speed("sha256", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 825 | if (mode > 300 && mode < 400) break; |
| 826 | |
| 827 | case 305: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 828 | test_hash_speed("sha384", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 829 | if (mode > 300 && mode < 400) break; |
| 830 | |
| 831 | case 306: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 832 | test_hash_speed("sha512", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 833 | if (mode > 300 && mode < 400) break; |
| 834 | |
| 835 | case 307: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 836 | test_hash_speed("wp256", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 837 | if (mode > 300 && mode < 400) break; |
| 838 | |
| 839 | case 308: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 840 | test_hash_speed("wp384", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 841 | if (mode > 300 && mode < 400) break; |
| 842 | |
| 843 | case 309: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 844 | test_hash_speed("wp512", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 845 | if (mode > 300 && mode < 400) break; |
| 846 | |
| 847 | case 310: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 848 | test_hash_speed("tgr128", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 849 | if (mode > 300 && mode < 400) break; |
| 850 | |
| 851 | case 311: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 852 | test_hash_speed("tgr160", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 853 | if (mode > 300 && mode < 400) break; |
| 854 | |
| 855 | case 312: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 856 | test_hash_speed("tgr192", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 857 | if (mode > 300 && mode < 400) break; |
| 858 | |
Jonathan Lynch | cd12fb90 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 859 | case 313: |
| 860 | test_hash_speed("sha224", sec, generic_hash_speed_template); |
| 861 | if (mode > 300 && mode < 400) break; |
| 862 | |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 863 | case 314: |
| 864 | test_hash_speed("rmd128", sec, generic_hash_speed_template); |
| 865 | if (mode > 300 && mode < 400) break; |
| 866 | |
| 867 | case 315: |
| 868 | test_hash_speed("rmd160", sec, generic_hash_speed_template); |
| 869 | if (mode > 300 && mode < 400) break; |
| 870 | |
Adrian-Ken Rueegsegger | 2998db3 | 2008-05-09 21:29:35 +0800 | [diff] [blame] | 871 | case 316: |
| 872 | test_hash_speed("rmd256", sec, generic_hash_speed_template); |
| 873 | if (mode > 300 && mode < 400) break; |
| 874 | |
| 875 | case 317: |
| 876 | test_hash_speed("rmd320", sec, generic_hash_speed_template); |
| 877 | if (mode > 300 && mode < 400) break; |
| 878 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 879 | case 399: |
| 880 | break; |
| 881 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | case 1000: |
| 883 | test_available(); |
| 884 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | } |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 886 | |
| 887 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | } |
| 889 | |
Steffen Klassert | a873a5f | 2009-06-19 19:46:53 +0800 | [diff] [blame] | 890 | static int do_alg_test(const char *alg, u32 type) |
| 891 | { |
Herbert Xu | ea40065 | 2009-06-19 20:37:00 +0800 | [diff] [blame] | 892 | return crypto_has_alg(alg, type, CRYPTO_ALG_TYPE_MASK) ? 0 : -ENOENT; |
Steffen Klassert | a873a5f | 2009-06-19 19:46:53 +0800 | [diff] [blame] | 893 | } |
| 894 | |
Kamalesh Babulal | 3af5b90 | 2008-04-05 21:00:57 +0800 | [diff] [blame] | 895 | static int __init tcrypt_mod_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | { |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame] | 897 | int err = -ENOMEM; |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 898 | int i; |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame] | 899 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 900 | for (i = 0; i < TVMEMSIZE; i++) { |
| 901 | tvmem[i] = (void *)__get_free_page(GFP_KERNEL); |
| 902 | if (!tvmem[i]) |
| 903 | goto err_free_tv; |
| 904 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | |
Steffen Klassert | a873a5f | 2009-06-19 19:46:53 +0800 | [diff] [blame] | 906 | if (alg) |
| 907 | err = do_alg_test(alg, type); |
| 908 | else |
| 909 | err = do_test(mode); |
| 910 | |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 911 | if (err) { |
| 912 | printk(KERN_ERR "tcrypt: one or more tests failed!\n"); |
| 913 | goto err_free_tv; |
| 914 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 916 | /* We intentionaly return -EAGAIN to prevent keeping the module, |
| 917 | * unless we're running in fips mode. It does all its work from |
| 918 | * init() and doesn't offer any runtime functionality, but in |
| 919 | * the fips case, checking for a successful load is helpful. |
Michal Ludvig | 14fdf47 | 2006-05-30 14:49:38 +1000 | [diff] [blame] | 920 | * => we don't need it in the memory, do we? |
| 921 | * -- mludvig |
| 922 | */ |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 923 | if (!fips_enabled) |
| 924 | err = -EAGAIN; |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame] | 925 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 926 | err_free_tv: |
| 927 | for (i = 0; i < TVMEMSIZE && tvmem[i]; i++) |
| 928 | free_page((unsigned long)tvmem[i]); |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame] | 929 | |
| 930 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | /* |
| 934 | * If an init function is provided, an exit function must also be provided |
| 935 | * to allow module unload. |
| 936 | */ |
Kamalesh Babulal | 3af5b90 | 2008-04-05 21:00:57 +0800 | [diff] [blame] | 937 | static void __exit tcrypt_mod_fini(void) { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | |
Kamalesh Babulal | 3af5b90 | 2008-04-05 21:00:57 +0800 | [diff] [blame] | 939 | module_init(tcrypt_mod_init); |
| 940 | module_exit(tcrypt_mod_fini); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | |
Steffen Klassert | a873a5f | 2009-06-19 19:46:53 +0800 | [diff] [blame] | 942 | module_param(alg, charp, 0); |
| 943 | module_param(type, uint, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | module_param(mode, int, 0); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 945 | module_param(sec, uint, 0); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 946 | MODULE_PARM_DESC(sec, "Length in seconds of speed tests " |
| 947 | "(defaults to zero which uses CPU cycles instead)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | |
| 949 | MODULE_LICENSE("GPL"); |
| 950 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); |
| 951 | MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>"); |