[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>
This commit is contained in:
parent
477035c2ab
commit
d5dc392742
|
@ -721,15 +721,18 @@ out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
|
||||||
|
|
||||||
static void test_cipher_speed(char *algo, int enc, unsigned int sec,
|
static void test_cipher_speed(char *algo, int enc, unsigned int sec,
|
||||||
struct cipher_testvec *template,
|
struct cipher_testvec *template,
|
||||||
unsigned int tcount, struct cipher_speed *speed)
|
unsigned int tcount, u8 *keysize)
|
||||||
{
|
{
|
||||||
unsigned int ret, i, j, iv_len;
|
unsigned int ret, i, j, iv_len;
|
||||||
unsigned char *key, *p, iv[128];
|
unsigned char *key, *p, iv[128];
|
||||||
struct crypto_blkcipher *tfm;
|
struct crypto_blkcipher *tfm;
|
||||||
struct blkcipher_desc desc;
|
struct blkcipher_desc desc;
|
||||||
const char *e;
|
const char *e;
|
||||||
|
u32 *b_size;
|
||||||
|
|
||||||
if (enc == ENCRYPT)
|
if (enc == ENCRYPT)
|
||||||
e = "encryption";
|
e = "encryption";
|
||||||
|
@ -748,52 +751,60 @@ static void test_cipher_speed(char *algo, int enc, unsigned int sec,
|
||||||
desc.tfm = tfm;
|
desc.tfm = tfm;
|
||||||
desc.flags = 0;
|
desc.flags = 0;
|
||||||
|
|
||||||
for (i = 0; speed[i].klen != 0; i++) {
|
i = 0;
|
||||||
if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
|
do {
|
||||||
printk("template (%u) too big for tvmem (%u)\n",
|
|
||||||
speed[i].blen + speed[i].klen, TVMEMSIZE);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
printk("test %u (%d bit key, %d byte blocks): ", i,
|
b_size = block_sizes;
|
||||||
speed[i].klen * 8, speed[i].blen);
|
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 */
|
printk("test %u (%d bit key, %d byte blocks): ", i,
|
||||||
key = (unsigned char *)tvmem;
|
*keysize * 8, *b_size);
|
||||||
for (j = 0; j < tcount; j++) {
|
|
||||||
if (template[j].klen == speed[i].klen) {
|
memset(tvmem, 0xff, *keysize + *b_size);
|
||||||
key = template[j].key;
|
|
||||||
|
/* 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 + *keysize;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
b_size++;
|
||||||
p = (unsigned char *)tvmem + speed[i].klen;
|
i++;
|
||||||
|
} while (*b_size);
|
||||||
ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
|
keysize++;
|
||||||
if (ret) {
|
} while (*keysize);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (ret) {
|
|
||||||
printk("%s() failed flags=%x\n", e, desc.flags);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
crypto_free_blkcipher(tfm);
|
crypto_free_blkcipher(tfm);
|
||||||
|
|
129
crypto/tcrypt.h
129
crypto/tcrypt.h
|
@ -72,11 +72,6 @@ struct aead_testvec {
|
||||||
unsigned short rlen;
|
unsigned short rlen;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cipher_speed {
|
|
||||||
unsigned char klen;
|
|
||||||
unsigned int blen;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct hash_speed {
|
struct hash_speed {
|
||||||
unsigned int blen; /* buffer length */
|
unsigned int blen; /* buffer length */
|
||||||
unsigned int plen; /* per-update length */
|
unsigned int plen; /* per-update length */
|
||||||
|
@ -8032,123 +8027,13 @@ static struct hash_testvec crc32c_tv_template[] = {
|
||||||
/*
|
/*
|
||||||
* Cipher speed tests
|
* Cipher speed tests
|
||||||
*/
|
*/
|
||||||
static struct cipher_speed speed_template_8[] = {
|
static u8 speed_template_8[] = {8, 0};
|
||||||
{ .klen = 8, .blen = 16, },
|
static u8 speed_template_24[] = {24, 0};
|
||||||
{ .klen = 8, .blen = 64, },
|
static u8 speed_template_8_32[] = {8, 32, 0};
|
||||||
{ .klen = 8, .blen = 256, },
|
static u8 speed_template_16_32[] = {16, 32, 0};
|
||||||
{ .klen = 8, .blen = 1024, },
|
static u8 speed_template_16_24_32[] = {16, 24, 32, 0};
|
||||||
{ .klen = 8, .blen = 8192, },
|
static u8 speed_template_32_40_48[] = {32, 40, 48, 0};
|
||||||
|
static u8 speed_template_32_48_64[] = {32, 48, 64, 0};
|
||||||
/* End marker */
|
|
||||||
{ .klen = 0, .blen = 0, }
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct cipher_speed speed_template_24[] = {
|
|
||||||
{ .klen = 24, .blen = 16, },
|
|
||||||
{ .klen = 24, .blen = 64, },
|
|
||||||
{ .klen = 24, .blen = 256, },
|
|
||||||
{ .klen = 24, .blen = 1024, },
|
|
||||||
{ .klen = 24, .blen = 8192, },
|
|
||||||
|
|
||||||
/* End marker */
|
|
||||||
{ .klen = 0, .blen = 0, }
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct cipher_speed speed_template_8_32[] = {
|
|
||||||
/* Don't support blowfish keys > 256 bit in this test */
|
|
||||||
{ .klen = 8, .blen = 16, },
|
|
||||||
{ .klen = 8, .blen = 64, },
|
|
||||||
{ .klen = 8, .blen = 256, },
|
|
||||||
{ .klen = 8, .blen = 1024, },
|
|
||||||
{ .klen = 8, .blen = 8192, },
|
|
||||||
{ .klen = 32, .blen = 16, },
|
|
||||||
{ .klen = 32, .blen = 64, },
|
|
||||||
{ .klen = 32, .blen = 256, },
|
|
||||||
{ .klen = 32, .blen = 1024, },
|
|
||||||
{ .klen = 32, .blen = 8192, },
|
|
||||||
|
|
||||||
/* End marker */
|
|
||||||
{ .klen = 0, .blen = 0, }
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct cipher_speed speed_template_16_32[] = {
|
|
||||||
{ .klen = 16, .blen = 16, },
|
|
||||||
{ .klen = 16, .blen = 64, },
|
|
||||||
{ .klen = 16, .blen = 256, },
|
|
||||||
{ .klen = 16, .blen = 1024, },
|
|
||||||
{ .klen = 16, .blen = 8192, },
|
|
||||||
{ .klen = 32, .blen = 16, },
|
|
||||||
{ .klen = 32, .blen = 64, },
|
|
||||||
{ .klen = 32, .blen = 256, },
|
|
||||||
{ .klen = 32, .blen = 1024, },
|
|
||||||
{ .klen = 32, .blen = 8192, },
|
|
||||||
|
|
||||||
/* End marker */
|
|
||||||
{ .klen = 0, .blen = 0, }
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct cipher_speed speed_template_16_24_32[] = {
|
|
||||||
{ .klen = 16, .blen = 16, },
|
|
||||||
{ .klen = 16, .blen = 64, },
|
|
||||||
{ .klen = 16, .blen = 256, },
|
|
||||||
{ .klen = 16, .blen = 1024, },
|
|
||||||
{ .klen = 16, .blen = 8192, },
|
|
||||||
{ .klen = 24, .blen = 16, },
|
|
||||||
{ .klen = 24, .blen = 64, },
|
|
||||||
{ .klen = 24, .blen = 256, },
|
|
||||||
{ .klen = 24, .blen = 1024, },
|
|
||||||
{ .klen = 24, .blen = 8192, },
|
|
||||||
{ .klen = 32, .blen = 16, },
|
|
||||||
{ .klen = 32, .blen = 64, },
|
|
||||||
{ .klen = 32, .blen = 256, },
|
|
||||||
{ .klen = 32, .blen = 1024, },
|
|
||||||
{ .klen = 32, .blen = 8192, },
|
|
||||||
|
|
||||||
/* End marker */
|
|
||||||
{ .klen = 0, .blen = 0, }
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct cipher_speed speed_template_32_40_48[] = {
|
|
||||||
{ .klen = 32, .blen = 16, },
|
|
||||||
{ .klen = 32, .blen = 64, },
|
|
||||||
{ .klen = 32, .blen = 256, },
|
|
||||||
{ .klen = 32, .blen = 1024, },
|
|
||||||
{ .klen = 32, .blen = 8192, },
|
|
||||||
{ .klen = 40, .blen = 16, },
|
|
||||||
{ .klen = 40, .blen = 64, },
|
|
||||||
{ .klen = 40, .blen = 256, },
|
|
||||||
{ .klen = 40, .blen = 1024, },
|
|
||||||
{ .klen = 40, .blen = 8192, },
|
|
||||||
{ .klen = 48, .blen = 16, },
|
|
||||||
{ .klen = 48, .blen = 64, },
|
|
||||||
{ .klen = 48, .blen = 256, },
|
|
||||||
{ .klen = 48, .blen = 1024, },
|
|
||||||
{ .klen = 48, .blen = 8192, },
|
|
||||||
|
|
||||||
/* End marker */
|
|
||||||
{ .klen = 0, .blen = 0, }
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct cipher_speed speed_template_32_48_64[] = {
|
|
||||||
{ .klen = 32, .blen = 16, },
|
|
||||||
{ .klen = 32, .blen = 64, },
|
|
||||||
{ .klen = 32, .blen = 256, },
|
|
||||||
{ .klen = 32, .blen = 1024, },
|
|
||||||
{ .klen = 32, .blen = 8192, },
|
|
||||||
{ .klen = 48, .blen = 16, },
|
|
||||||
{ .klen = 48, .blen = 64, },
|
|
||||||
{ .klen = 48, .blen = 256, },
|
|
||||||
{ .klen = 48, .blen = 1024, },
|
|
||||||
{ .klen = 48, .blen = 8192, },
|
|
||||||
{ .klen = 64, .blen = 16, },
|
|
||||||
{ .klen = 64, .blen = 64, },
|
|
||||||
{ .klen = 64, .blen = 256, },
|
|
||||||
{ .klen = 64, .blen = 1024, },
|
|
||||||
{ .klen = 64, .blen = 8192, },
|
|
||||||
|
|
||||||
/* End marker */
|
|
||||||
{ .klen = 0, .blen = 0, }
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Digest speed tests
|
* Digest speed tests
|
||||||
|
|
Loading…
Reference in New Issue