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