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