diff options
author | Sebastian Siewior <sebastian@breakpoint.cc> | 2008-03-11 21:27:11 +0800 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2008-04-21 10:19:21 +0800 |
commit | d5dc392742a9818e2766a63f3533980543e18060 (patch) | |
tree | 2dcd8083cba1b1e22c4e01c50d479ca2502a1139 /crypto/tcrypt.c | |
parent | 477035c2abdcff7583369e5777cb7be1bb1dbea8 (diff) | |
download | linux-stable-d5dc392742a9818e2766a63f3533980543e18060.tar.gz linux-stable-d5dc392742a9818e2766a63f3533980543e18060.tar.bz2 linux-stable-d5dc392742a9818e2766a63f3533980543e18060.zip |
[CRYPTO] tcrypt: Shrink speed templates
The speed templates as it look always the same. The key size
is repeated for each block size and we test always the same
block size. The addition of one inner loop makes it possible
to get rid of the struct and it is possible to use a tiny
u8 array :)
Signed-off-by: Sebastian Siewior <sebastian@breakpoint.cc>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/tcrypt.c')
-rw-r--r-- | crypto/tcrypt.c | 89 |
1 files changed, 50 insertions, 39 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index cff18364fbc1..6b8315b6f2a5 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c @@ -721,15 +721,18 @@ out: return ret; } +static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 }; + static void test_cipher_speed(char *algo, int enc, unsigned int sec, struct cipher_testvec *template, - unsigned int tcount, struct cipher_speed *speed) + unsigned int tcount, u8 *keysize) { unsigned int ret, i, j, iv_len; unsigned char *key, *p, iv[128]; struct crypto_blkcipher *tfm; struct blkcipher_desc desc; const char *e; + u32 *b_size; if (enc == ENCRYPT) e = "encryption"; @@ -748,52 +751,60 @@ static void test_cipher_speed(char *algo, int enc, unsigned int sec, desc.tfm = tfm; desc.flags = 0; - for (i = 0; speed[i].klen != 0; i++) { - if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) { - printk("template (%u) too big for tvmem (%u)\n", - speed[i].blen + speed[i].klen, TVMEMSIZE); - goto out; - } + i = 0; + do { - printk("test %u (%d bit key, %d byte blocks): ", i, - speed[i].klen * 8, speed[i].blen); + b_size = block_sizes; + do { - memset(tvmem, 0xff, speed[i].klen + speed[i].blen); + if ((*keysize + *b_size) > TVMEMSIZE) { + printk("template (%u) too big for tvmem (%u)\n", + *keysize + *b_size, TVMEMSIZE); + goto out; + } - /* set key, plain text and IV */ - key = (unsigned char *)tvmem; - for (j = 0; j < tcount; j++) { - if (template[j].klen == speed[i].klen) { - key = template[j].key; - break; + printk("test %u (%d bit key, %d byte blocks): ", i, + *keysize * 8, *b_size); + + memset(tvmem, 0xff, *keysize + *b_size); + + /* set key, plain text and IV */ + key = (unsigned char *)tvmem; + for (j = 0; j < tcount; j++) { + if (template[j].klen == *keysize) { + key = template[j].key; + break; + } } - } - p = (unsigned char *)tvmem + speed[i].klen; + p = (unsigned char *)tvmem + *keysize; - ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen); - if (ret) { - printk("setkey() failed flags=%x\n", - crypto_blkcipher_get_flags(tfm)); - goto out; - } + ret = crypto_blkcipher_setkey(tfm, key, *keysize); + if (ret) { + printk("setkey() failed flags=%x\n", + crypto_blkcipher_get_flags(tfm)); + goto out; + } - iv_len = crypto_blkcipher_ivsize(tfm); - if (iv_len) { - memset(&iv, 0xff, iv_len); - crypto_blkcipher_set_iv(tfm, iv, iv_len); - } + iv_len = crypto_blkcipher_ivsize(tfm); + if (iv_len) { + memset(&iv, 0xff, iv_len); + crypto_blkcipher_set_iv(tfm, iv, iv_len); + } - if (sec) - ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen, - sec); - else - ret = test_cipher_cycles(&desc, enc, p, speed[i].blen); + if (sec) + ret = test_cipher_jiffies(&desc, enc, p, *b_size, sec); + else + ret = test_cipher_cycles(&desc, enc, p, *b_size); - if (ret) { - printk("%s() failed flags=%x\n", e, desc.flags); - break; - } - } + if (ret) { + printk("%s() failed flags=%x\n", e, desc.flags); + break; + } + b_size++; + i++; + } while (*b_size); + keysize++; + } while (*keysize); out: crypto_free_blkcipher(tfm); |