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> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * 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] | 12 | * Software Foundation; either version 2 of the License, or (at your option) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * any later version. |
| 14 | * |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 15 | * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>) |
| 16 | * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt |
| 17 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 20 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/init.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/mm.h> |
| 24 | #include <linux/slab.h> |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 25 | #include <linux/scatterlist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/string.h> |
| 27 | #include <linux/crypto.h> |
| 28 | #include <linux/highmem.h> |
| 29 | #include <linux/moduleparam.h> |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 30 | #include <linux/jiffies.h> |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 31 | #include <linux/timex.h> |
| 32 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include "tcrypt.h" |
| 34 | |
| 35 | /* |
| 36 | * Need to kmalloc() memory for testing kmap(). |
| 37 | */ |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 38 | #define TVMEMSIZE 16384 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #define XBUFSIZE 32768 |
| 40 | |
| 41 | /* |
| 42 | * Indexes into the xbuf to simulate cross-page access. |
| 43 | */ |
| 44 | #define IDX1 37 |
| 45 | #define IDX2 32400 |
| 46 | #define IDX3 1 |
| 47 | #define IDX4 8193 |
| 48 | #define IDX5 22222 |
| 49 | #define IDX6 17101 |
| 50 | #define IDX7 27333 |
| 51 | #define IDX8 3000 |
| 52 | |
| 53 | /* |
| 54 | * Used by test_cipher() |
| 55 | */ |
| 56 | #define ENCRYPT 1 |
| 57 | #define DECRYPT 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; |
| 60 | |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 61 | /* |
| 62 | * Used by test_cipher_speed() |
| 63 | */ |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 64 | static unsigned int sec; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | static int mode; |
| 67 | static char *xbuf; |
| 68 | static char *tvmem; |
| 69 | |
| 70 | static char *check[] = { |
| 71 | "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish", |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 72 | "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6", |
| 73 | "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", |
Aaron Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 74 | "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 77 | static void hexdump(unsigned char *buf, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
| 79 | while (len--) |
| 80 | printk("%02x", *buf++); |
| 81 | |
| 82 | printk("\n"); |
| 83 | } |
| 84 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 85 | static void test_hash(char *algo, struct hash_testvec *template, |
| 86 | unsigned int tcount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 88 | unsigned int i, j, k, temp; |
| 89 | struct scatterlist sg[8]; |
| 90 | char result[64]; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 91 | struct crypto_hash *tfm; |
| 92 | struct hash_desc desc; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 93 | struct hash_testvec *hash_tv; |
| 94 | unsigned int tsize; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 95 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 97 | printk("\ntesting %s\n", algo); |
| 98 | |
| 99 | tsize = sizeof(struct hash_testvec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | tsize *= tcount; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | if (tsize > TVMEMSIZE) { |
| 103 | printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE); |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | memcpy(tvmem, template, tsize); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 108 | hash_tv = (void *)tvmem; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 109 | |
| 110 | tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); |
| 111 | if (IS_ERR(tfm)) { |
| 112 | printk("failed to load transform for %s: %ld\n", algo, |
| 113 | PTR_ERR(tfm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return; |
| 115 | } |
| 116 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 117 | desc.tfm = tfm; |
| 118 | desc.flags = 0; |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | for (i = 0; i < tcount; i++) { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 121 | printk("test %u:\n", i + 1); |
| 122 | memset(result, 0, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 124 | sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 126 | if (hash_tv[i].ksize) { |
| 127 | ret = crypto_hash_setkey(tfm, hash_tv[i].key, |
| 128 | hash_tv[i].ksize); |
| 129 | if (ret) { |
| 130 | printk("setkey() failed ret=%d\n", ret); |
| 131 | goto out; |
| 132 | } |
| 133 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 135 | ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, result); |
| 136 | if (ret) { |
| 137 | printk("digest () failed ret=%d\n", ret); |
| 138 | goto out; |
| 139 | } |
| 140 | |
| 141 | hexdump(result, crypto_hash_digestsize(tfm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | printk("%s\n", |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 143 | memcmp(result, hash_tv[i].digest, |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 144 | crypto_hash_digestsize(tfm)) ? |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 145 | "fail" : "pass"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 148 | printk("testing %s across pages\n", algo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | /* setup the dummy buffer first */ |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 151 | memset(xbuf, 0, XBUFSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | j = 0; |
| 154 | for (i = 0; i < tcount; i++) { |
| 155 | if (hash_tv[i].np) { |
| 156 | j++; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 157 | printk("test %u:\n", j); |
| 158 | memset(result, 0, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
| 160 | temp = 0; |
| 161 | for (k = 0; k < hash_tv[i].np; k++) { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 162 | memcpy(&xbuf[IDX[k]], |
| 163 | hash_tv[i].plaintext + temp, |
| 164 | hash_tv[i].tap[k]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | temp += hash_tv[i].tap[k]; |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 166 | sg_set_buf(&sg[k], &xbuf[IDX[k]], |
| 167 | hash_tv[i].tap[k]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 170 | if (hash_tv[i].ksize) { |
| 171 | ret = crypto_hash_setkey(tfm, hash_tv[i].key, |
| 172 | hash_tv[i].ksize); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 173 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 174 | if (ret) { |
| 175 | printk("setkey() failed ret=%d\n", ret); |
| 176 | goto out; |
| 177 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 180 | ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, |
| 181 | result); |
| 182 | if (ret) { |
| 183 | printk("digest () failed ret=%d\n", ret); |
| 184 | goto out; |
| 185 | } |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 186 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 187 | hexdump(result, crypto_hash_digestsize(tfm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | printk("%s\n", |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 189 | memcmp(result, hash_tv[i].digest, |
| 190 | crypto_hash_digestsize(tfm)) ? |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 191 | "fail" : "pass"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 195 | out: |
| 196 | crypto_free_hash(tfm); |
| 197 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 199 | static void test_cipher(char *algo, int enc, |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 200 | struct cipher_testvec *template, unsigned int tcount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
| 202 | unsigned int ret, i, j, k, temp; |
| 203 | unsigned int tsize; |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 204 | unsigned int iv_len; |
| 205 | unsigned int len; |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 206 | char *q; |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 207 | struct crypto_blkcipher *tfm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | char *key; |
| 209 | struct cipher_testvec *cipher_tv; |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 210 | struct blkcipher_desc desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | struct scatterlist sg[8]; |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 212 | const char *e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | if (enc == ENCRYPT) |
Herbert Xu | 3cc3816 | 2005-06-22 13:26:36 -0700 | [diff] [blame] | 215 | e = "encryption"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | else |
Herbert Xu | 3cc3816 | 2005-06-22 13:26:36 -0700 | [diff] [blame] | 217 | e = "decryption"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 219 | printk("\ntesting %s %s\n", algo, e); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 221 | tsize = sizeof (struct cipher_testvec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | tsize *= tcount; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | if (tsize > TVMEMSIZE) { |
| 225 | printk("template (%u) too big for tvmem (%u)\n", tsize, |
| 226 | TVMEMSIZE); |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | memcpy(tvmem, template, tsize); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 231 | cipher_tv = (void *)tvmem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 233 | tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 234 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 235 | if (IS_ERR(tfm)) { |
| 236 | printk("failed to load transform for %s: %ld\n", algo, |
| 237 | PTR_ERR(tfm)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | return; |
| 239 | } |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 240 | desc.tfm = tfm; |
| 241 | desc.flags = 0; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | j = 0; |
| 244 | for (i = 0; i < tcount; i++) { |
| 245 | if (!(cipher_tv[i].np)) { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 246 | j++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | printk("test %u (%d bit key):\n", |
| 248 | j, cipher_tv[i].klen * 8); |
| 249 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 250 | crypto_blkcipher_clear_flags(tfm, ~0); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 251 | if (cipher_tv[i].wk) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 252 | crypto_blkcipher_set_flags( |
| 253 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | key = cipher_tv[i].key; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 255 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 256 | ret = crypto_blkcipher_setkey(tfm, key, |
| 257 | cipher_tv[i].klen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | if (ret) { |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 259 | printk("setkey() failed flags=%x\n", |
| 260 | crypto_blkcipher_get_flags(tfm)); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | if (!cipher_tv[i].fail) |
| 263 | goto out; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 264 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 266 | sg_set_buf(&sg[0], cipher_tv[i].input, |
| 267 | cipher_tv[i].ilen); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 268 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 269 | iv_len = crypto_blkcipher_ivsize(tfm); |
| 270 | if (iv_len) |
| 271 | crypto_blkcipher_set_iv(tfm, cipher_tv[i].iv, |
| 272 | iv_len); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 273 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 274 | len = cipher_tv[i].ilen; |
| 275 | ret = enc ? |
| 276 | crypto_blkcipher_encrypt(&desc, sg, sg, len) : |
| 277 | crypto_blkcipher_decrypt(&desc, sg, sg, len); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | if (ret) { |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 280 | printk("%s () failed flags=%x\n", e, |
| 281 | desc.flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | goto out; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | q = kmap(sg[0].page) + sg[0].offset; |
| 286 | hexdump(q, cipher_tv[i].rlen); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 287 | |
| 288 | printk("%s\n", |
| 289 | memcmp(q, cipher_tv[i].result, |
| 290 | cipher_tv[i].rlen) ? "fail" : "pass"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | } |
| 292 | } |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 293 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 294 | printk("\ntesting %s %s across pages (chunking)\n", algo, e); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | memset(xbuf, 0, XBUFSIZE); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | j = 0; |
| 298 | for (i = 0; i < tcount; i++) { |
| 299 | if (cipher_tv[i].np) { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 300 | j++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | printk("test %u (%d bit key):\n", |
| 302 | j, cipher_tv[i].klen * 8); |
| 303 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 304 | crypto_blkcipher_clear_flags(tfm, ~0); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 305 | if (cipher_tv[i].wk) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 306 | crypto_blkcipher_set_flags( |
| 307 | tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | key = cipher_tv[i].key; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 309 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 310 | ret = crypto_blkcipher_setkey(tfm, key, |
| 311 | cipher_tv[i].klen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | if (ret) { |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 313 | printk("setkey() failed flags=%x\n", |
| 314 | crypto_blkcipher_get_flags(tfm)); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | if (!cipher_tv[i].fail) |
| 317 | goto out; |
| 318 | } |
| 319 | |
| 320 | temp = 0; |
| 321 | for (k = 0; k < cipher_tv[i].np; k++) { |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 322 | memcpy(&xbuf[IDX[k]], |
| 323 | cipher_tv[i].input + temp, |
| 324 | cipher_tv[i].tap[k]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | temp += cipher_tv[i].tap[k]; |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 326 | sg_set_buf(&sg[k], &xbuf[IDX[k]], |
| 327 | cipher_tv[i].tap[k]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 329 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 330 | iv_len = crypto_blkcipher_ivsize(tfm); |
| 331 | if (iv_len) |
| 332 | crypto_blkcipher_set_iv(tfm, cipher_tv[i].iv, |
| 333 | iv_len); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 334 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 335 | len = cipher_tv[i].ilen; |
| 336 | ret = enc ? |
| 337 | crypto_blkcipher_encrypt(&desc, sg, sg, len) : |
| 338 | crypto_blkcipher_decrypt(&desc, sg, sg, len); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | if (ret) { |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 341 | printk("%s () failed flags=%x\n", e, |
| 342 | desc.flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | goto out; |
| 344 | } |
| 345 | |
| 346 | temp = 0; |
| 347 | for (k = 0; k < cipher_tv[i].np; k++) { |
| 348 | printk("page %u\n", k); |
| 349 | q = kmap(sg[k].page) + sg[k].offset; |
| 350 | hexdump(q, cipher_tv[i].tap[k]); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 351 | printk("%s\n", |
| 352 | memcmp(q, cipher_tv[i].result + temp, |
| 353 | cipher_tv[i].tap[k]) ? "fail" : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | "pass"); |
| 355 | temp += cipher_tv[i].tap[k]; |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | out: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 361 | crypto_free_blkcipher(tfm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 364 | 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] | 365 | int blen, int sec) |
| 366 | { |
Herbert Xu | 6df5b9f | 2005-09-19 22:30:11 +1000 | [diff] [blame] | 367 | struct scatterlist sg[1]; |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 368 | unsigned long start, end; |
| 369 | int bcount; |
| 370 | int ret; |
| 371 | |
Herbert Xu | 6df5b9f | 2005-09-19 22:30:11 +1000 | [diff] [blame] | 372 | sg_set_buf(sg, p, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 373 | |
| 374 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
| 375 | time_before(jiffies, end); bcount++) { |
| 376 | if (enc) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 377 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 378 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 379 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 380 | |
| 381 | if (ret) |
| 382 | return ret; |
| 383 | } |
| 384 | |
| 385 | printk("%d operations in %d seconds (%ld bytes)\n", |
| 386 | bcount, sec, (long)bcount * blen); |
| 387 | return 0; |
| 388 | } |
| 389 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 390 | 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] | 391 | int blen) |
| 392 | { |
Herbert Xu | 6df5b9f | 2005-09-19 22:30:11 +1000 | [diff] [blame] | 393 | struct scatterlist sg[1]; |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 394 | unsigned long cycles = 0; |
| 395 | int ret = 0; |
| 396 | int i; |
| 397 | |
Herbert Xu | 6df5b9f | 2005-09-19 22:30:11 +1000 | [diff] [blame] | 398 | sg_set_buf(sg, p, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 399 | |
| 400 | local_bh_disable(); |
| 401 | local_irq_disable(); |
| 402 | |
| 403 | /* Warm-up run. */ |
| 404 | for (i = 0; i < 4; i++) { |
| 405 | if (enc) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 406 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 407 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 408 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 409 | |
| 410 | if (ret) |
| 411 | goto out; |
| 412 | } |
| 413 | |
| 414 | /* The real thing. */ |
| 415 | for (i = 0; i < 8; i++) { |
| 416 | cycles_t start, end; |
| 417 | |
| 418 | start = get_cycles(); |
| 419 | if (enc) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 420 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 421 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 422 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 423 | end = get_cycles(); |
| 424 | |
| 425 | if (ret) |
| 426 | goto out; |
| 427 | |
| 428 | cycles += end - start; |
| 429 | } |
| 430 | |
| 431 | out: |
| 432 | local_irq_enable(); |
| 433 | local_bh_enable(); |
| 434 | |
| 435 | if (ret == 0) |
| 436 | printk("1 operation in %lu cycles (%d bytes)\n", |
| 437 | (cycles + 4) / 8, blen); |
| 438 | |
| 439 | return ret; |
| 440 | } |
| 441 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 442 | static void test_cipher_speed(char *algo, int enc, unsigned int sec, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 443 | struct cipher_testvec *template, |
| 444 | unsigned int tcount, struct cipher_speed *speed) |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 445 | { |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 446 | unsigned int ret, i, j, iv_len; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 447 | unsigned char *key, *p, iv[128]; |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 448 | struct crypto_blkcipher *tfm; |
| 449 | struct blkcipher_desc desc; |
| 450 | const char *e; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 451 | |
| 452 | if (enc == ENCRYPT) |
| 453 | e = "encryption"; |
| 454 | else |
| 455 | e = "decryption"; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 456 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 457 | printk("\ntesting speed of %s %s\n", algo, e); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 458 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 459 | tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 460 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 461 | if (IS_ERR(tfm)) { |
| 462 | printk("failed to load transform for %s: %ld\n", algo, |
| 463 | PTR_ERR(tfm)); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 464 | return; |
| 465 | } |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 466 | desc.tfm = tfm; |
| 467 | desc.flags = 0; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 468 | |
| 469 | for (i = 0; speed[i].klen != 0; i++) { |
| 470 | if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) { |
| 471 | printk("template (%u) too big for tvmem (%u)\n", |
| 472 | speed[i].blen + speed[i].klen, TVMEMSIZE); |
| 473 | goto out; |
| 474 | } |
| 475 | |
| 476 | printk("test %u (%d bit key, %d byte blocks): ", i, |
| 477 | speed[i].klen * 8, speed[i].blen); |
| 478 | |
| 479 | memset(tvmem, 0xff, speed[i].klen + speed[i].blen); |
| 480 | |
| 481 | /* set key, plain text and IV */ |
| 482 | key = (unsigned char *)tvmem; |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 483 | for (j = 0; j < tcount; j++) { |
| 484 | if (template[j].klen == speed[i].klen) { |
| 485 | key = template[j].key; |
| 486 | break; |
| 487 | } |
| 488 | } |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 489 | p = (unsigned char *)tvmem + speed[i].klen; |
| 490 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 491 | ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 492 | if (ret) { |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 493 | printk("setkey() failed flags=%x\n", |
| 494 | crypto_blkcipher_get_flags(tfm)); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 495 | goto out; |
| 496 | } |
| 497 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 498 | iv_len = crypto_blkcipher_ivsize(tfm); |
| 499 | if (iv_len) { |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 500 | memset(&iv, 0xff, iv_len); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 501 | crypto_blkcipher_set_iv(tfm, iv, iv_len); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 504 | if (sec) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 505 | ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen, |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 506 | sec); |
| 507 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 508 | ret = test_cipher_cycles(&desc, enc, p, speed[i].blen); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 509 | |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 510 | if (ret) { |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 511 | printk("%s() failed flags=%x\n", e, desc.flags); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 512 | break; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 513 | } |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | out: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 517 | crypto_free_blkcipher(tfm); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 520 | static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen, |
| 521 | char *out, int sec) |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 522 | { |
| 523 | struct scatterlist sg[1]; |
| 524 | unsigned long start, end; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 525 | int bcount; |
| 526 | int ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 527 | |
| 528 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
| 529 | time_before(jiffies, end); bcount++) { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 530 | sg_set_buf(sg, p, blen); |
| 531 | ret = crypto_hash_digest(desc, sg, blen, out); |
| 532 | if (ret) |
| 533 | return ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | printk("%6u opers/sec, %9lu bytes/sec\n", |
| 537 | bcount / sec, ((long)bcount * blen) / sec); |
| 538 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 539 | return 0; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 540 | } |
| 541 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 542 | static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen, |
| 543 | int plen, char *out, int sec) |
| 544 | { |
| 545 | struct scatterlist sg[1]; |
| 546 | unsigned long start, end; |
| 547 | int bcount, pcount; |
| 548 | int ret; |
| 549 | |
| 550 | if (plen == blen) |
| 551 | return test_hash_jiffies_digest(desc, p, blen, out, sec); |
| 552 | |
| 553 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
| 554 | time_before(jiffies, end); bcount++) { |
| 555 | ret = crypto_hash_init(desc); |
| 556 | if (ret) |
| 557 | return ret; |
| 558 | for (pcount = 0; pcount < blen; pcount += plen) { |
| 559 | sg_set_buf(sg, p + pcount, plen); |
| 560 | ret = crypto_hash_update(desc, sg, plen); |
| 561 | if (ret) |
| 562 | return ret; |
| 563 | } |
| 564 | /* we assume there is enough space in 'out' for the result */ |
| 565 | ret = crypto_hash_final(desc, out); |
| 566 | if (ret) |
| 567 | return ret; |
| 568 | } |
| 569 | |
| 570 | printk("%6u opers/sec, %9lu bytes/sec\n", |
| 571 | bcount / sec, ((long)bcount * blen) / sec); |
| 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | |
| 576 | static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen, |
| 577 | char *out) |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 578 | { |
| 579 | struct scatterlist sg[1]; |
| 580 | unsigned long cycles = 0; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 581 | int i; |
| 582 | int ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 583 | |
| 584 | local_bh_disable(); |
| 585 | local_irq_disable(); |
| 586 | |
| 587 | /* Warm-up run. */ |
| 588 | for (i = 0; i < 4; i++) { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 589 | sg_set_buf(sg, p, blen); |
| 590 | ret = crypto_hash_digest(desc, sg, blen, out); |
| 591 | if (ret) |
| 592 | goto out; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | /* The real thing. */ |
| 596 | for (i = 0; i < 8; i++) { |
| 597 | cycles_t start, end; |
| 598 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 599 | start = get_cycles(); |
| 600 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 601 | sg_set_buf(sg, p, blen); |
| 602 | ret = crypto_hash_digest(desc, sg, blen, out); |
| 603 | if (ret) |
| 604 | goto out; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 605 | |
| 606 | end = get_cycles(); |
| 607 | |
| 608 | cycles += end - start; |
| 609 | } |
| 610 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 611 | out: |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 612 | local_irq_enable(); |
| 613 | local_bh_enable(); |
| 614 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 615 | if (ret) |
| 616 | return ret; |
| 617 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 618 | printk("%6lu cycles/operation, %4lu cycles/byte\n", |
| 619 | cycles / 8, cycles / (8 * blen)); |
| 620 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 621 | return 0; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 622 | } |
| 623 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 624 | static int test_hash_cycles(struct hash_desc *desc, char *p, int blen, |
| 625 | int plen, char *out) |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 626 | { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 627 | struct scatterlist sg[1]; |
| 628 | unsigned long cycles = 0; |
| 629 | int i, pcount; |
| 630 | int ret; |
| 631 | |
| 632 | if (plen == blen) |
| 633 | return test_hash_cycles_digest(desc, p, blen, out); |
| 634 | |
| 635 | local_bh_disable(); |
| 636 | local_irq_disable(); |
| 637 | |
| 638 | /* Warm-up run. */ |
| 639 | for (i = 0; i < 4; i++) { |
| 640 | ret = crypto_hash_init(desc); |
| 641 | if (ret) |
| 642 | goto out; |
| 643 | for (pcount = 0; pcount < blen; pcount += plen) { |
| 644 | sg_set_buf(sg, p + pcount, plen); |
| 645 | ret = crypto_hash_update(desc, sg, plen); |
| 646 | if (ret) |
| 647 | goto out; |
| 648 | } |
| 649 | crypto_hash_final(desc, out); |
| 650 | if (ret) |
| 651 | goto out; |
| 652 | } |
| 653 | |
| 654 | /* The real thing. */ |
| 655 | for (i = 0; i < 8; i++) { |
| 656 | cycles_t start, end; |
| 657 | |
| 658 | start = get_cycles(); |
| 659 | |
| 660 | ret = crypto_hash_init(desc); |
| 661 | if (ret) |
| 662 | goto out; |
| 663 | for (pcount = 0; pcount < blen; pcount += plen) { |
| 664 | sg_set_buf(sg, p + pcount, plen); |
| 665 | ret = crypto_hash_update(desc, sg, plen); |
| 666 | if (ret) |
| 667 | goto out; |
| 668 | } |
| 669 | ret = crypto_hash_final(desc, out); |
| 670 | if (ret) |
| 671 | goto out; |
| 672 | |
| 673 | end = get_cycles(); |
| 674 | |
| 675 | cycles += end - start; |
| 676 | } |
| 677 | |
| 678 | out: |
| 679 | local_irq_enable(); |
| 680 | local_bh_enable(); |
| 681 | |
| 682 | if (ret) |
| 683 | return ret; |
| 684 | |
| 685 | printk("%6lu cycles/operation, %4lu cycles/byte\n", |
| 686 | cycles / 8, cycles / (8 * blen)); |
| 687 | |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | static void test_hash_speed(char *algo, unsigned int sec, |
| 692 | struct hash_speed *speed) |
| 693 | { |
| 694 | struct crypto_hash *tfm; |
| 695 | struct hash_desc desc; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 696 | char output[1024]; |
| 697 | int i; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 698 | int ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 699 | |
| 700 | printk("\ntesting speed of %s\n", algo); |
| 701 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 702 | tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 703 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 704 | if (IS_ERR(tfm)) { |
| 705 | printk("failed to load transform for %s: %ld\n", algo, |
| 706 | PTR_ERR(tfm)); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 707 | return; |
| 708 | } |
| 709 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 710 | desc.tfm = tfm; |
| 711 | desc.flags = 0; |
| 712 | |
| 713 | if (crypto_hash_digestsize(tfm) > sizeof(output)) { |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 714 | printk("digestsize(%u) > outputbuffer(%zu)\n", |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 715 | crypto_hash_digestsize(tfm), sizeof(output)); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 716 | goto out; |
| 717 | } |
| 718 | |
| 719 | for (i = 0; speed[i].blen != 0; i++) { |
| 720 | if (speed[i].blen > TVMEMSIZE) { |
| 721 | printk("template (%u) too big for tvmem (%u)\n", |
| 722 | speed[i].blen, TVMEMSIZE); |
| 723 | goto out; |
| 724 | } |
| 725 | |
| 726 | printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ", |
| 727 | i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); |
| 728 | |
| 729 | memset(tvmem, 0xff, speed[i].blen); |
| 730 | |
| 731 | if (sec) |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 732 | ret = test_hash_jiffies(&desc, tvmem, speed[i].blen, |
| 733 | speed[i].plen, output, sec); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 734 | else |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 735 | ret = test_hash_cycles(&desc, tvmem, speed[i].blen, |
| 736 | speed[i].plen, output); |
| 737 | |
| 738 | if (ret) { |
| 739 | printk("hashing failed ret=%d\n", ret); |
| 740 | break; |
| 741 | } |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | out: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 745 | crypto_free_hash(tfm); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 746 | } |
| 747 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 748 | static void test_deflate(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | { |
| 750 | unsigned int i; |
| 751 | char result[COMP_BUF_SIZE]; |
Herbert Xu | e4d5b79 | 2006-08-26 18:12:40 +1000 | [diff] [blame] | 752 | struct crypto_comp *tfm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | struct comp_testvec *tv; |
| 754 | unsigned int tsize; |
| 755 | |
| 756 | printk("\ntesting deflate compression\n"); |
| 757 | |
| 758 | tsize = sizeof (deflate_comp_tv_template); |
| 759 | if (tsize > TVMEMSIZE) { |
| 760 | printk("template (%u) too big for tvmem (%u)\n", tsize, |
| 761 | TVMEMSIZE); |
| 762 | return; |
| 763 | } |
| 764 | |
| 765 | memcpy(tvmem, deflate_comp_tv_template, tsize); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 766 | tv = (void *)tvmem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | |
| 768 | tfm = crypto_alloc_tfm("deflate", 0); |
| 769 | if (tfm == NULL) { |
| 770 | printk("failed to load transform for deflate\n"); |
| 771 | return; |
| 772 | } |
| 773 | |
| 774 | for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) { |
| 775 | int ilen, ret, dlen = COMP_BUF_SIZE; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 776 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | printk("test %u:\n", i + 1); |
| 778 | memset(result, 0, sizeof (result)); |
| 779 | |
| 780 | ilen = tv[i].inlen; |
| 781 | ret = crypto_comp_compress(tfm, tv[i].input, |
| 782 | ilen, result, &dlen); |
| 783 | if (ret) { |
| 784 | printk("fail: ret=%d\n", ret); |
| 785 | continue; |
| 786 | } |
| 787 | hexdump(result, dlen); |
| 788 | printk("%s (ratio %d:%d)\n", |
| 789 | memcmp(result, tv[i].output, dlen) ? "fail" : "pass", |
| 790 | ilen, dlen); |
| 791 | } |
| 792 | |
| 793 | printk("\ntesting deflate decompression\n"); |
| 794 | |
| 795 | tsize = sizeof (deflate_decomp_tv_template); |
| 796 | if (tsize > TVMEMSIZE) { |
| 797 | printk("template (%u) too big for tvmem (%u)\n", tsize, |
| 798 | TVMEMSIZE); |
| 799 | goto out; |
| 800 | } |
| 801 | |
| 802 | memcpy(tvmem, deflate_decomp_tv_template, tsize); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 803 | tv = (void *)tvmem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | |
| 805 | for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) { |
| 806 | int ilen, ret, dlen = COMP_BUF_SIZE; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | printk("test %u:\n", i + 1); |
| 809 | memset(result, 0, sizeof (result)); |
| 810 | |
| 811 | ilen = tv[i].inlen; |
| 812 | ret = crypto_comp_decompress(tfm, tv[i].input, |
| 813 | ilen, result, &dlen); |
| 814 | if (ret) { |
| 815 | printk("fail: ret=%d\n", ret); |
| 816 | continue; |
| 817 | } |
| 818 | hexdump(result, dlen); |
| 819 | printk("%s (ratio %d:%d)\n", |
| 820 | memcmp(result, tv[i].output, dlen) ? "fail" : "pass", |
| 821 | ilen, dlen); |
| 822 | } |
| 823 | out: |
Herbert Xu | e4d5b79 | 2006-08-26 18:12:40 +1000 | [diff] [blame] | 824 | crypto_free_comp(tfm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | } |
| 826 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 827 | static void test_available(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | { |
| 829 | char **name = check; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 830 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | while (*name) { |
| 832 | printk("alg %s ", *name); |
Herbert Xu | e4d5b79 | 2006-08-26 18:12:40 +1000 | [diff] [blame] | 833 | printk(crypto_has_alg(*name, 0, CRYPTO_ALG_ASYNC) ? |
| 834 | "found\n" : "not found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | name++; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 836 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | } |
| 838 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 839 | static void do_test(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | { |
| 841 | switch (mode) { |
| 842 | |
| 843 | case 0: |
| 844 | test_hash("md5", md5_tv_template, MD5_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | //DES |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 849 | test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template, |
| 850 | DES_ENC_TEST_VECTORS); |
| 851 | test_cipher("ecb(des)", DECRYPT, des_dec_tv_template, |
| 852 | DES_DEC_TEST_VECTORS); |
| 853 | test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template, |
| 854 | DES_CBC_ENC_TEST_VECTORS); |
| 855 | test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template, |
| 856 | DES_CBC_DEC_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | //DES3_EDE |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 859 | test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template, |
| 860 | DES3_EDE_ENC_TEST_VECTORS); |
| 861 | test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template, |
| 862 | DES3_EDE_DEC_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 863 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 865 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | //BLOWFISH |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 869 | test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template, |
| 870 | BF_ENC_TEST_VECTORS); |
| 871 | test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template, |
| 872 | BF_DEC_TEST_VECTORS); |
| 873 | test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template, |
| 874 | BF_CBC_ENC_TEST_VECTORS); |
| 875 | test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template, |
| 876 | BF_CBC_DEC_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | //TWOFISH |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 879 | test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template, |
| 880 | TF_ENC_TEST_VECTORS); |
| 881 | test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template, |
| 882 | TF_DEC_TEST_VECTORS); |
| 883 | test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template, |
| 884 | TF_CBC_ENC_TEST_VECTORS); |
| 885 | test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template, |
| 886 | TF_CBC_DEC_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 887 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | //SERPENT |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 889 | test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template, |
| 890 | SERPENT_ENC_TEST_VECTORS); |
| 891 | test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template, |
| 892 | SERPENT_DEC_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | //TNEPRES |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 895 | test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template, |
| 896 | TNEPRES_ENC_TEST_VECTORS); |
| 897 | test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template, |
| 898 | TNEPRES_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
| 900 | //AES |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 901 | test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template, |
| 902 | AES_ENC_TEST_VECTORS); |
| 903 | test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template, |
| 904 | AES_DEC_TEST_VECTORS); |
| 905 | test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template, |
| 906 | AES_CBC_ENC_TEST_VECTORS); |
| 907 | test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template, |
| 908 | AES_CBC_DEC_TEST_VECTORS); |
Rik Snel | f3d1044 | 2006-11-29 19:01:41 +1100 | [diff] [blame] | 909 | test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template, |
| 910 | AES_LRW_ENC_TEST_VECTORS); |
| 911 | test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template, |
| 912 | AES_LRW_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
| 914 | //CAST5 |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 915 | test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template, |
| 916 | CAST5_ENC_TEST_VECTORS); |
| 917 | test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template, |
| 918 | CAST5_DEC_TEST_VECTORS); |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 919 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | //CAST6 |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 921 | test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template, |
| 922 | CAST6_ENC_TEST_VECTORS); |
| 923 | test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template, |
| 924 | CAST6_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
| 926 | //ARC4 |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 927 | test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template, |
| 928 | ARC4_ENC_TEST_VECTORS); |
| 929 | test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template, |
| 930 | ARC4_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | |
| 932 | //TEA |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 933 | test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template, |
| 934 | TEA_ENC_TEST_VECTORS); |
| 935 | test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template, |
| 936 | TEA_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | |
| 938 | |
| 939 | //XTEA |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 940 | test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template, |
| 941 | XTEA_ENC_TEST_VECTORS); |
| 942 | test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template, |
| 943 | XTEA_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
| 945 | //KHAZAD |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 946 | test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template, |
| 947 | KHAZAD_ENC_TEST_VECTORS); |
| 948 | test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template, |
| 949 | KHAZAD_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | |
| 951 | //ANUBIS |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 952 | test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template, |
| 953 | ANUBIS_ENC_TEST_VECTORS); |
| 954 | test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template, |
| 955 | ANUBIS_DEC_TEST_VECTORS); |
| 956 | test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template, |
| 957 | ANUBIS_CBC_ENC_TEST_VECTORS); |
| 958 | test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template, |
| 959 | ANUBIS_CBC_ENC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | |
Aaron Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 961 | //XETA |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 962 | test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template, |
| 963 | XETA_ENC_TEST_VECTORS); |
| 964 | test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template, |
| 965 | XETA_DEC_TEST_VECTORS); |
Aaron Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS); |
| 968 | test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS); |
| 969 | test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS); |
| 970 | test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS); |
| 971 | test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS); |
| 972 | test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS); |
| 973 | test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS); |
| 974 | test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); |
| 975 | test_deflate(); |
Herbert Xu | c907ee7 | 2006-08-21 22:04:03 +1000 | [diff] [blame] | 976 | test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 977 | test_hash("hmac(md5)", hmac_md5_tv_template, |
| 978 | HMAC_MD5_TEST_VECTORS); |
| 979 | test_hash("hmac(sha1)", hmac_sha1_tv_template, |
| 980 | HMAC_SHA1_TEST_VECTORS); |
| 981 | test_hash("hmac(sha256)", hmac_sha256_tv_template, |
| 982 | HMAC_SHA256_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
Kazunori MIYAZAWA | 5b2becf | 2006-10-28 13:18:53 +1000 | [diff] [blame] | 984 | test_hash("xcbc(aes)", aes_xcbc128_tv_template, |
| 985 | XCBC_AES_TEST_VECTORS); |
| 986 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS); |
| 988 | break; |
| 989 | |
| 990 | case 1: |
| 991 | test_hash("md5", md5_tv_template, MD5_TEST_VECTORS); |
| 992 | break; |
| 993 | |
| 994 | case 2: |
| 995 | test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS); |
| 996 | break; |
| 997 | |
| 998 | case 3: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 999 | test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template, |
| 1000 | DES_ENC_TEST_VECTORS); |
| 1001 | test_cipher("ecb(des)", DECRYPT, des_dec_tv_template, |
| 1002 | DES_DEC_TEST_VECTORS); |
| 1003 | test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template, |
| 1004 | DES_CBC_ENC_TEST_VECTORS); |
| 1005 | test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template, |
| 1006 | DES_CBC_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | break; |
| 1008 | |
| 1009 | case 4: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1010 | test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template, |
| 1011 | DES3_EDE_ENC_TEST_VECTORS); |
| 1012 | test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template, |
| 1013 | DES3_EDE_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | break; |
| 1015 | |
| 1016 | case 5: |
| 1017 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); |
| 1018 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | case 6: |
| 1021 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); |
| 1022 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | case 7: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1025 | test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template, |
| 1026 | BF_ENC_TEST_VECTORS); |
| 1027 | test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template, |
| 1028 | BF_DEC_TEST_VECTORS); |
| 1029 | test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template, |
| 1030 | BF_CBC_ENC_TEST_VECTORS); |
| 1031 | test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template, |
| 1032 | BF_CBC_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | break; |
| 1034 | |
| 1035 | case 8: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1036 | test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template, |
| 1037 | TF_ENC_TEST_VECTORS); |
| 1038 | test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template, |
| 1039 | TF_DEC_TEST_VECTORS); |
| 1040 | test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template, |
| 1041 | TF_CBC_ENC_TEST_VECTORS); |
| 1042 | test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template, |
| 1043 | TF_CBC_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | case 9: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1047 | test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template, |
| 1048 | SERPENT_ENC_TEST_VECTORS); |
| 1049 | test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template, |
| 1050 | SERPENT_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | break; |
| 1052 | |
| 1053 | case 10: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1054 | test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template, |
| 1055 | AES_ENC_TEST_VECTORS); |
| 1056 | test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template, |
| 1057 | AES_DEC_TEST_VECTORS); |
| 1058 | test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template, |
| 1059 | AES_CBC_ENC_TEST_VECTORS); |
| 1060 | test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template, |
| 1061 | AES_CBC_DEC_TEST_VECTORS); |
Rik Snel | f3d1044 | 2006-11-29 19:01:41 +1100 | [diff] [blame] | 1062 | test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template, |
| 1063 | AES_LRW_ENC_TEST_VECTORS); |
| 1064 | test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template, |
| 1065 | AES_LRW_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | break; |
| 1067 | |
| 1068 | case 11: |
| 1069 | test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS); |
| 1070 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | case 12: |
| 1073 | test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS); |
| 1074 | break; |
| 1075 | |
| 1076 | case 13: |
| 1077 | test_deflate(); |
| 1078 | break; |
| 1079 | |
| 1080 | case 14: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1081 | test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template, |
| 1082 | CAST5_ENC_TEST_VECTORS); |
| 1083 | test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template, |
| 1084 | CAST5_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | break; |
| 1086 | |
| 1087 | case 15: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1088 | test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template, |
| 1089 | CAST6_ENC_TEST_VECTORS); |
| 1090 | test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template, |
| 1091 | CAST6_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | break; |
| 1093 | |
| 1094 | case 16: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1095 | test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template, |
| 1096 | ARC4_ENC_TEST_VECTORS); |
| 1097 | test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template, |
| 1098 | ARC4_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | break; |
| 1100 | |
| 1101 | case 17: |
| 1102 | test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS); |
| 1103 | break; |
| 1104 | |
| 1105 | case 18: |
Herbert Xu | c907ee7 | 2006-08-21 22:04:03 +1000 | [diff] [blame] | 1106 | test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | break; |
| 1108 | |
| 1109 | case 19: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1110 | test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template, |
| 1111 | TEA_ENC_TEST_VECTORS); |
| 1112 | test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template, |
| 1113 | TEA_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | break; |
| 1115 | |
| 1116 | case 20: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1117 | test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template, |
| 1118 | XTEA_ENC_TEST_VECTORS); |
| 1119 | test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template, |
| 1120 | XTEA_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | break; |
| 1122 | |
| 1123 | case 21: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1124 | test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template, |
| 1125 | KHAZAD_ENC_TEST_VECTORS); |
| 1126 | test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template, |
| 1127 | KHAZAD_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | break; |
| 1129 | |
| 1130 | case 22: |
| 1131 | test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS); |
| 1132 | break; |
| 1133 | |
| 1134 | case 23: |
| 1135 | test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS); |
| 1136 | break; |
| 1137 | |
| 1138 | case 24: |
| 1139 | test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS); |
| 1140 | break; |
| 1141 | |
| 1142 | case 25: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1143 | test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template, |
| 1144 | TNEPRES_ENC_TEST_VECTORS); |
| 1145 | test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template, |
| 1146 | TNEPRES_DEC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | break; |
| 1148 | |
| 1149 | case 26: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1150 | test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template, |
| 1151 | ANUBIS_ENC_TEST_VECTORS); |
| 1152 | test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template, |
| 1153 | ANUBIS_DEC_TEST_VECTORS); |
| 1154 | test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template, |
| 1155 | ANUBIS_CBC_ENC_TEST_VECTORS); |
| 1156 | test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template, |
| 1157 | ANUBIS_CBC_ENC_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | break; |
| 1159 | |
| 1160 | case 27: |
| 1161 | test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS); |
| 1162 | break; |
| 1163 | |
| 1164 | case 28: |
| 1165 | |
| 1166 | test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS); |
| 1167 | break; |
| 1168 | |
| 1169 | case 29: |
| 1170 | test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); |
| 1171 | break; |
Aaron Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 1172 | |
| 1173 | case 30: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1174 | test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template, |
| 1175 | XETA_ENC_TEST_VECTORS); |
| 1176 | test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template, |
| 1177 | XETA_DEC_TEST_VECTORS); |
Aaron Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 1178 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | case 100: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1181 | test_hash("hmac(md5)", hmac_md5_tv_template, |
| 1182 | HMAC_MD5_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | case 101: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1186 | test_hash("hmac(sha1)", hmac_sha1_tv_template, |
| 1187 | HMAC_SHA1_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | case 102: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1191 | test_hash("hmac(sha256)", hmac_sha256_tv_template, |
| 1192 | HMAC_SHA256_TEST_VECTORS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | break; |
| 1194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1196 | case 200: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1197 | test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1198 | aes_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1199 | test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1200 | aes_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1201 | test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1202 | aes_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1203 | test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1204 | aes_speed_template); |
Rik Snel | f3d1044 | 2006-11-29 19:01:41 +1100 | [diff] [blame] | 1205 | test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, |
| 1206 | aes_lrw_speed_template); |
| 1207 | test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, |
| 1208 | aes_lrw_speed_template); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1209 | break; |
| 1210 | |
| 1211 | case 201: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1212 | test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1213 | des3_ede_enc_tv_template, |
| 1214 | DES3_EDE_ENC_TEST_VECTORS, |
| 1215 | des3_ede_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1216 | test_cipher_speed("ecb(des3_ede)", DECRYPT, sec, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1217 | des3_ede_dec_tv_template, |
| 1218 | DES3_EDE_DEC_TEST_VECTORS, |
| 1219 | des3_ede_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1220 | test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1221 | des3_ede_enc_tv_template, |
| 1222 | DES3_EDE_ENC_TEST_VECTORS, |
| 1223 | des3_ede_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1224 | test_cipher_speed("cbc(des3_ede)", DECRYPT, sec, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1225 | des3_ede_dec_tv_template, |
| 1226 | DES3_EDE_DEC_TEST_VECTORS, |
| 1227 | des3_ede_speed_template); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1228 | break; |
| 1229 | |
| 1230 | case 202: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1231 | test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1232 | twofish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1233 | test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1234 | twofish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1235 | test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1236 | twofish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1237 | test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1238 | twofish_speed_template); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1239 | break; |
| 1240 | |
| 1241 | case 203: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1242 | test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1243 | blowfish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1244 | test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1245 | blowfish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1246 | test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1247 | blowfish_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1248 | test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1249 | blowfish_speed_template); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1250 | break; |
| 1251 | |
| 1252 | case 204: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1253 | test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1254 | des_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1255 | test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1256 | des_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1257 | test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1258 | des_speed_template); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1259 | test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 1260 | des_speed_template); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1261 | break; |
| 1262 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1263 | case 300: |
| 1264 | /* fall through */ |
| 1265 | |
| 1266 | case 301: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1267 | test_hash_speed("md4", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1268 | if (mode > 300 && mode < 400) break; |
| 1269 | |
| 1270 | case 302: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1271 | test_hash_speed("md5", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1272 | if (mode > 300 && mode < 400) break; |
| 1273 | |
| 1274 | case 303: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1275 | test_hash_speed("sha1", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1276 | if (mode > 300 && mode < 400) break; |
| 1277 | |
| 1278 | case 304: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1279 | test_hash_speed("sha256", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1280 | if (mode > 300 && mode < 400) break; |
| 1281 | |
| 1282 | case 305: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1283 | test_hash_speed("sha384", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1284 | if (mode > 300 && mode < 400) break; |
| 1285 | |
| 1286 | case 306: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1287 | test_hash_speed("sha512", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1288 | if (mode > 300 && mode < 400) break; |
| 1289 | |
| 1290 | case 307: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1291 | test_hash_speed("wp256", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1292 | if (mode > 300 && mode < 400) break; |
| 1293 | |
| 1294 | case 308: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1295 | test_hash_speed("wp384", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1296 | if (mode > 300 && mode < 400) break; |
| 1297 | |
| 1298 | case 309: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1299 | test_hash_speed("wp512", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1300 | if (mode > 300 && mode < 400) break; |
| 1301 | |
| 1302 | case 310: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1303 | test_hash_speed("tgr128", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1304 | if (mode > 300 && mode < 400) break; |
| 1305 | |
| 1306 | case 311: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1307 | test_hash_speed("tgr160", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1308 | if (mode > 300 && mode < 400) break; |
| 1309 | |
| 1310 | case 312: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1311 | test_hash_speed("tgr192", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1312 | if (mode > 300 && mode < 400) break; |
| 1313 | |
| 1314 | case 399: |
| 1315 | break; |
| 1316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | case 1000: |
| 1318 | test_available(); |
| 1319 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | default: |
| 1322 | /* useful for debugging */ |
| 1323 | printk("not testing anything\n"); |
| 1324 | break; |
| 1325 | } |
| 1326 | } |
| 1327 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1328 | static int __init init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | { |
| 1330 | tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL); |
| 1331 | if (tvmem == NULL) |
| 1332 | return -ENOMEM; |
| 1333 | |
| 1334 | xbuf = kmalloc(XBUFSIZE, GFP_KERNEL); |
| 1335 | if (xbuf == NULL) { |
| 1336 | kfree(tvmem); |
| 1337 | return -ENOMEM; |
| 1338 | } |
| 1339 | |
| 1340 | do_test(); |
| 1341 | |
| 1342 | kfree(xbuf); |
| 1343 | kfree(tvmem); |
Michal Ludvig | 14fdf47 | 2006-05-30 14:49:38 +1000 | [diff] [blame] | 1344 | |
| 1345 | /* We intentionaly return -EAGAIN to prevent keeping |
| 1346 | * the module. It does all its work from init() |
| 1347 | * and doesn't offer any runtime functionality |
| 1348 | * => we don't need it in the memory, do we? |
| 1349 | * -- mludvig |
| 1350 | */ |
| 1351 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | /* |
| 1355 | * If an init function is provided, an exit function must also be provided |
| 1356 | * to allow module unload. |
| 1357 | */ |
| 1358 | static void __exit fini(void) { } |
| 1359 | |
| 1360 | module_init(init); |
| 1361 | module_exit(fini); |
| 1362 | |
| 1363 | module_param(mode, int, 0); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1364 | module_param(sec, uint, 0); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 1365 | MODULE_PARM_DESC(sec, "Length in seconds of speed tests " |
| 1366 | "(defaults to zero which uses CPU cycles instead)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | |
| 1368 | MODULE_LICENSE("GPL"); |
| 1369 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); |
| 1370 | MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>"); |