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