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