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