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