aboutsummaryrefslogtreecommitdiff
path: root/crypto/tcrypt.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/tcrypt.c')
-rw-r--r--crypto/tcrypt.c529
1 files changed, 282 insertions, 247 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 1ab8c017a01..6beabc5abd0 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -82,9 +82,8 @@ static char *check[] = {
"des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
"blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
"cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
- "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
"khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
- "camellia", "seed", "salsa20", "lzo", NULL
+ "camellia", "seed", "salsa20", "lzo", "cts", NULL
};
static void hexdump(unsigned char *buf, unsigned int len)
@@ -113,23 +112,11 @@ static void test_hash(char *algo, struct hash_testvec *template,
char result[64];
struct crypto_hash *tfm;
struct hash_desc desc;
- struct hash_testvec *hash_tv;
- unsigned int tsize;
int ret;
+ void *hash_buff;
printk("\ntesting %s\n", algo);
- tsize = sizeof(struct hash_testvec);
- tsize *= tcount;
-
- if (tsize > TVMEMSIZE) {
- printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
- return;
- }
-
- memcpy(tvmem, template, tsize);
- hash_tv = (void *)tvmem;
-
tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(tfm)) {
printk("failed to load transform for %s: %ld\n", algo,
@@ -144,28 +131,36 @@ static void test_hash(char *algo, struct hash_testvec *template,
printk("test %u:\n", i + 1);
memset(result, 0, 64);
- sg_init_one(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
+ hash_buff = kzalloc(template[i].psize, GFP_KERNEL);
+ if (!hash_buff)
+ continue;
+
+ memcpy(hash_buff, template[i].plaintext, template[i].psize);
+ sg_init_one(&sg[0], hash_buff, template[i].psize);
- if (hash_tv[i].ksize) {
- ret = crypto_hash_setkey(tfm, hash_tv[i].key,
- hash_tv[i].ksize);
+ if (template[i].ksize) {
+ ret = crypto_hash_setkey(tfm, template[i].key,
+ template[i].ksize);
if (ret) {
printk("setkey() failed ret=%d\n", ret);
+ kfree(hash_buff);
goto out;
}
}
- ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, result);
+ ret = crypto_hash_digest(&desc, sg, template[i].psize, result);
if (ret) {
printk("digest () failed ret=%d\n", ret);
+ kfree(hash_buff);
goto out;
}
hexdump(result, crypto_hash_digestsize(tfm));
printk("%s\n",
- memcmp(result, hash_tv[i].digest,
+ memcmp(result, template[i].digest,
crypto_hash_digestsize(tfm)) ?
"fail" : "pass");
+ kfree(hash_buff);
}
printk("testing %s across pages\n", algo);
@@ -175,25 +170,25 @@ static void test_hash(char *algo, struct hash_testvec *template,
j = 0;
for (i = 0; i < tcount; i++) {
- if (hash_tv[i].np) {
+ if (template[i].np) {
j++;
printk("test %u:\n", j);
memset(result, 0, 64);
temp = 0;
- sg_init_table(sg, hash_tv[i].np);
- for (k = 0; k < hash_tv[i].np; k++) {
+ sg_init_table(sg, template[i].np);
+ for (k = 0; k < template[i].np; k++) {
memcpy(&xbuf[IDX[k]],
- hash_tv[i].plaintext + temp,
- hash_tv[i].tap[k]);
- temp += hash_tv[i].tap[k];
+ template[i].plaintext + temp,
+ template[i].tap[k]);
+ temp += template[i].tap[k];
sg_set_buf(&sg[k], &xbuf[IDX[k]],
- hash_tv[i].tap[k]);
+ template[i].tap[k]);
}
- if (hash_tv[i].ksize) {
- ret = crypto_hash_setkey(tfm, hash_tv[i].key,
- hash_tv[i].ksize);
+ if (template[i].ksize) {
+ ret = crypto_hash_setkey(tfm, template[i].key,
+ template[i].ksize);
if (ret) {
printk("setkey() failed ret=%d\n", ret);
@@ -201,7 +196,7 @@ static void test_hash(char *algo, struct hash_testvec *template,
}
}
- ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize,
+ ret = crypto_hash_digest(&desc, sg, template[i].psize,
result);
if (ret) {
printk("digest () failed ret=%d\n", ret);
@@ -210,7 +205,7 @@ static void test_hash(char *algo, struct hash_testvec *template,
hexdump(result, crypto_hash_digestsize(tfm));
printk("%s\n",
- memcmp(result, hash_tv[i].digest,
+ memcmp(result, template[i].digest,
crypto_hash_digestsize(tfm)) ?
"fail" : "pass");
}
@@ -224,17 +219,18 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
unsigned int tcount)
{
unsigned int ret, i, j, k, temp;
- unsigned int tsize;
char *q;
struct crypto_aead *tfm;
char *key;
- struct aead_testvec *aead_tv;
struct aead_request *req;
struct scatterlist sg[8];
struct scatterlist asg[8];
const char *e;
struct tcrypt_result result;
unsigned int authsize;
+ void *input;
+ void *assoc;
+ char iv[MAX_IVLEN];
if (enc == ENCRYPT)
e = "encryption";
@@ -243,18 +239,6 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
printk(KERN_INFO "\ntesting %s %s\n", algo, e);
- tsize = sizeof(struct aead_testvec);
- tsize *= tcount;
-
- if (tsize > TVMEMSIZE) {
- printk(KERN_INFO "template (%u) too big for tvmem (%u)\n",
- tsize, TVMEMSIZE);
- return;
- }
-
- memcpy(tvmem, template, tsize);
- aead_tv = (void *)tvmem;
-
init_completion(&result.completion);
tfm = crypto_alloc_aead(algo, 0, 0);
@@ -275,46 +259,68 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
tcrypt_complete, &result);
for (i = 0, j = 0; i < tcount; i++) {
- if (!aead_tv[i].np) {
+ if (!template[i].np) {
printk(KERN_INFO "test %u (%d bit key):\n",
- ++j, aead_tv[i].klen * 8);
+ ++j, template[i].klen * 8);
+
+ /* some tepmplates have no input data but they will
+ * touch input
+ */
+ input = kzalloc(template[i].ilen + template[i].rlen, GFP_KERNEL);
+ if (!input)
+ continue;
+
+ assoc = kzalloc(template[i].alen, GFP_KERNEL);
+ if (!assoc) {
+ kfree(input);
+ continue;
+ }
+
+ memcpy(input, template[i].input, template[i].ilen);
+ memcpy(assoc, template[i].assoc, template[i].alen);
+ if (template[i].iv)
+ memcpy(iv, template[i].iv, MAX_IVLEN);
+ else
+ memset(iv, 0, MAX_IVLEN);
crypto_aead_clear_flags(tfm, ~0);
- if (aead_tv[i].wk)
+ if (template[i].wk)
crypto_aead_set_flags(
tfm, CRYPTO_TFM_REQ_WEAK_KEY);
- key = aead_tv[i].key;
+
+ if (template[i].key)
+ key = template[i].key;
+ else
+ key = kzalloc(template[i].klen, GFP_KERNEL);
ret = crypto_aead_setkey(tfm, key,
- aead_tv[i].klen);
+ template[i].klen);
if (ret) {
printk(KERN_INFO "setkey() failed flags=%x\n",
crypto_aead_get_flags(tfm));
- if (!aead_tv[i].fail)
- goto out;
+ if (!template[i].fail)
+ goto next_one;
}
- authsize = abs(aead_tv[i].rlen - aead_tv[i].ilen);
+ authsize = abs(template[i].rlen - template[i].ilen);
ret = crypto_aead_setauthsize(tfm, authsize);
if (ret) {
printk(KERN_INFO
"failed to set authsize = %u\n",
authsize);
- goto out;
+ goto next_one;
}
- sg_init_one(&sg[0], aead_tv[i].input,
- aead_tv[i].ilen + (enc ? authsize : 0));
+ sg_init_one(&sg[0], input,
+ template[i].ilen + (enc ? authsize : 0));
- sg_init_one(&asg[0], aead_tv[i].assoc,
- aead_tv[i].alen);
+ sg_init_one(&asg[0], assoc, template[i].alen);
aead_request_set_crypt(req, sg, sg,
- aead_tv[i].ilen,
- aead_tv[i].iv);
+ template[i].ilen, iv);
- aead_request_set_assoc(req, asg, aead_tv[i].alen);
+ aead_request_set_assoc(req, asg, template[i].alen);
ret = enc ?
crypto_aead_encrypt(req) :
@@ -335,15 +341,21 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
default:
printk(KERN_INFO "%s () failed err=%d\n",
e, -ret);
- goto out;
+ goto next_one;
}
q = kmap(sg_page(&sg[0])) + sg[0].offset;
- hexdump(q, aead_tv[i].rlen);
+ hexdump(q, template[i].rlen);
printk(KERN_INFO "enc/dec: %s\n",
- memcmp(q, aead_tv[i].result,
- aead_tv[i].rlen) ? "fail" : "pass");
+ memcmp(q, template[i].result,
+ template[i].rlen) ? "fail" : "pass");
+ kunmap(sg_page(&sg[0]));
+next_one:
+ if (!template[i].key)
+ kfree(key);
+ kfree(assoc);
+ kfree(input);
}
}
@@ -352,36 +364,41 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
memset(axbuf, 0, XBUFSIZE);
for (i = 0, j = 0; i < tcount; i++) {
- if (aead_tv[i].np) {
+ if (template[i].np) {
printk(KERN_INFO "test %u (%d bit key):\n",
- ++j, aead_tv[i].klen * 8);
+ ++j, template[i].klen * 8);
+
+ if (template[i].iv)
+ memcpy(iv, template[i].iv, MAX_IVLEN);
+ else
+ memset(iv, 0, MAX_IVLEN);
crypto_aead_clear_flags(tfm, ~0);
- if (aead_tv[i].wk)
+ if (template[i].wk)
crypto_aead_set_flags(
tfm, CRYPTO_TFM_REQ_WEAK_KEY);
- key = aead_tv[i].key;
+ key = template[i].key;
- ret = crypto_aead_setkey(tfm, key, aead_tv[i].klen);
+ ret = crypto_aead_setkey(tfm, key, template[i].klen);
if (ret) {
printk(KERN_INFO "setkey() failed flags=%x\n",
crypto_aead_get_flags(tfm));
- if (!aead_tv[i].fail)
+ if (!template[i].fail)
goto out;
}
- sg_init_table(sg, aead_tv[i].np);
- for (k = 0, temp = 0; k < aead_tv[i].np; k++) {
+ sg_init_table(sg, template[i].np);
+ for (k = 0, temp = 0; k < template[i].np; k++) {
memcpy(&xbuf[IDX[k]],
- aead_tv[i].input + temp,
- aead_tv[i].tap[k]);
- temp += aead_tv[i].tap[k];
+ template[i].input + temp,
+ template[i].tap[k]);
+ temp += template[i].tap[k];
sg_set_buf(&sg[k], &xbuf[IDX[k]],
- aead_tv[i].tap[k]);
+ template[i].tap[k]);
}
- authsize = abs(aead_tv[i].rlen - aead_tv[i].ilen);
+ authsize = abs(template[i].rlen - template[i].ilen);
ret = crypto_aead_setauthsize(tfm, authsize);
if (ret) {
printk(KERN_INFO
@@ -393,21 +410,21 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
if (enc)
sg[k - 1].length += authsize;
- sg_init_table(asg, aead_tv[i].anp);
- for (k = 0, temp = 0; k < aead_tv[i].anp; k++) {
+ sg_init_table(asg, template[i].anp);
+ for (k = 0, temp = 0; k < template[i].anp; k++) {
memcpy(&axbuf[IDX[k]],
- aead_tv[i].assoc + temp,
- aead_tv[i].atap[k]);
- temp += aead_tv[i].atap[k];
+ template[i].assoc + temp,
+ template[i].atap[k]);
+ temp += template[i].atap[k];
sg_set_buf(&asg[k], &axbuf[IDX[k]],
- aead_tv[i].atap[k]);
+ template[i].atap[k]);
}
aead_request_set_crypt(req, sg, sg,
- aead_tv[i].ilen,
- aead_tv[i].iv);
+ template[i].ilen,
+ iv);
- aead_request_set_assoc(req, asg, aead_tv[i].alen);
+ aead_request_set_assoc(req, asg, template[i].alen);
ret = enc ?
crypto_aead_encrypt(req) :
@@ -431,18 +448,19 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
goto out;
}
- for (k = 0, temp = 0; k < aead_tv[i].np; k++) {
+ for (k = 0, temp = 0; k < template[i].np; k++) {
printk(KERN_INFO "page %u\n", k);
q = kmap(sg_page(&sg[k])) + sg[k].offset;
- hexdump(q, aead_tv[i].tap[k]);
+ hexdump(q, template[i].tap[k]);
printk(KERN_INFO "%s\n",
- memcmp(q, aead_tv[i].result + temp,
- aead_tv[i].tap[k] -
- (k < aead_tv[i].np - 1 || enc ?
+ memcmp(q, template[i].result + temp,
+ template[i].tap[k] -
+ (k < template[i].np - 1 || enc ?
0 : authsize)) ?
"fail" : "pass");
- temp += aead_tv[i].tap[k];
+ temp += template[i].tap[k];
+ kunmap(sg_page(&sg[k]));
}
}
}
@@ -456,15 +474,14 @@ static void test_cipher(char *algo, int enc,
struct cipher_testvec *template, unsigned int tcount)
{
unsigned int ret, i, j, k, temp;
- unsigned int tsize;
char *q;
struct crypto_ablkcipher *tfm;
- char *key;
- struct cipher_testvec *cipher_tv;
struct ablkcipher_request *req;
struct scatterlist sg[8];
const char *e;
struct tcrypt_result result;
+ void *data;
+ char iv[MAX_IVLEN];
if (enc == ENCRYPT)
e = "encryption";
@@ -473,16 +490,7 @@ static void test_cipher(char *algo, int enc,
printk("\ntesting %s %s\n", algo, e);
- tsize = sizeof (struct cipher_testvec);
- if (tsize > TVMEMSIZE) {
- printk("template (%u) too big for tvmem (%u)\n", tsize,
- TVMEMSIZE);
- return;
- }
- cipher_tv = (void *)tvmem;
-
init_completion(&result.completion);
-
tfm = crypto_alloc_ablkcipher(algo, 0, 0);
if (IS_ERR(tfm)) {
@@ -502,35 +510,43 @@ static void test_cipher(char *algo, int enc,
j = 0;
for (i = 0; i < tcount; i++) {
- memcpy(cipher_tv, &template[i], tsize);
- if (!(cipher_tv->np)) {
+
+ data = kzalloc(template[i].ilen, GFP_KERNEL);
+ if (!data)
+ continue;
+
+ memcpy(data, template[i].input, template[i].ilen);
+ if (template[i].iv)
+ memcpy(iv, template[i].iv, MAX_IVLEN);
+ else
+ memset(iv, 0, MAX_IVLEN);
+
+ if (!(template[i].np)) {
j++;
printk("test %u (%d bit key):\n",
- j, cipher_tv->klen * 8);
+ j, template[i].klen * 8);
crypto_ablkcipher_clear_flags(tfm, ~0);
- if (cipher_tv->wk)
+ if (template[i].wk)
crypto_ablkcipher_set_flags(
tfm, CRYPTO_TFM_REQ_WEAK_KEY);
- key = cipher_tv->key;
- ret = crypto_ablkcipher_setkey(tfm, key,
- cipher_tv->klen);
+ ret = crypto_ablkcipher_setkey(tfm, template[i].key,
+ template[i].klen);
if (ret) {
printk("setkey() failed flags=%x\n",
crypto_ablkcipher_get_flags(tfm));
- if (!cipher_tv->fail)
+ if (!template[i].fail) {
+ kfree(data);
goto out;
+ }
}
- sg_init_one(&sg[0], cipher_tv->input,
- cipher_tv->ilen);
+ sg_init_one(&sg[0], data, template[i].ilen);
ablkcipher_request_set_crypt(req, sg, sg,
- cipher_tv->ilen,
- cipher_tv->iv);
-
+ template[i].ilen, iv);
ret = enc ?
crypto_ablkcipher_encrypt(req) :
crypto_ablkcipher_decrypt(req);
@@ -549,16 +565,19 @@ static void test_cipher(char *algo, int enc,
/* fall through */
default:
printk("%s () failed err=%d\n", e, -ret);
+ kfree(data);
goto out;
}
q = kmap(sg_page(&sg[0])) + sg[0].offset;
- hexdump(q, cipher_tv->rlen);
+ hexdump(q, template[i].rlen);
printk("%s\n",
- memcmp(q, cipher_tv->result,
- cipher_tv->rlen) ? "fail" : "pass");
+ memcmp(q, template[i].result,
+ template[i].rlen) ? "fail" : "pass");
+ kunmap(sg_page(&sg[0]));
}
+ kfree(data);
}
printk("\ntesting %s %s across pages (chunking)\n", algo, e);
@@ -566,42 +585,53 @@ static void test_cipher(char *algo, int enc,
j = 0;
for (i = 0; i < tcount; i++) {
- memcpy(cipher_tv, &template[i], tsize);
- if (cipher_tv->np) {
+
+ data = kzalloc(template[i].ilen, GFP_KERNEL);
+ if (!data)
+ continue;
+
+ memcpy(data, template[i].input, template[i].ilen);
+
+ if (template[i].iv)
+ memcpy(iv, template[i].iv, MAX_IVLEN);
+ else
+ memset(iv, 0, MAX_IVLEN);
+
+ if (template[i].np) {
j++;
printk("test %u (%d bit key):\n",
- j, cipher_tv->klen * 8);
+ j, template[i].klen * 8);
crypto_ablkcipher_clear_flags(tfm, ~0);
- if (cipher_tv->wk)
+ if (template[i].wk)
crypto_ablkcipher_set_flags(
tfm, CRYPTO_TFM_REQ_WEAK_KEY);
- key = cipher_tv->key;
- ret = crypto_ablkcipher_setkey(tfm, key,
- cipher_tv->klen);
+ ret = crypto_ablkcipher_setkey(tfm, template[i].key,
+ template[i].klen);
if (ret) {
printk("setkey() failed flags=%x\n",
- crypto_ablkcipher_get_flags(tfm));
+ crypto_ablkcipher_get_flags(tfm));
- if (!cipher_tv->fail)
+ if (!template[i].fail) {
+ kfree(data);
goto out;
+ }
}
temp = 0;
- sg_init_table(sg, cipher_tv->np);
- for (k = 0; k < cipher_tv->np; k++) {
+ sg_init_table(sg, template[i].np);
+ for (k = 0; k < template[i].np; k++) {
memcpy(&xbuf[IDX[k]],
- cipher_tv->input + temp,
- cipher_tv->tap[k]);
- temp += cipher_tv->tap[k];
+ template[i].input + temp,
+ template[i].tap[k]);
+ temp += template[i].tap[k];
sg_set_buf(&sg[k], &xbuf[IDX[k]],
- cipher_tv->tap[k]);
+ template[i].tap[k]);
}
ablkcipher_request_set_crypt(req, sg, sg,
- cipher_tv->ilen,
- cipher_tv->iv);
+ template[i].ilen, iv);
ret = enc ?
crypto_ablkcipher_encrypt(req) :
@@ -625,19 +655,19 @@ static void test_cipher(char *algo, int enc,
}
temp = 0;
- for (k = 0; k < cipher_tv->np; k++) {
+ for (k = 0; k < template[i].np; k++) {
printk("page %u\n", k);
q = kmap(sg_page(&sg[k])) + sg[k].offset;
- hexdump(q, cipher_tv->tap[k]);
+ hexdump(q, template[i].tap[k]);
printk("%s\n",
- memcmp(q, cipher_tv->result + temp,
- cipher_tv->tap[k]) ? "fail" :
+ memcmp(q, template[i].result + temp,
+ template[i].tap[k]) ? "fail" :
"pass");
- temp += cipher_tv->tap[k];
+ temp += template[i].tap[k];
+ kunmap(sg_page(&sg[k]));
}
}
}
-
out:
crypto_free_ablkcipher(tfm);
ablkcipher_request_free(req);
@@ -721,15 +751,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 +781,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 {
+
+ b_size = block_sizes;
+ do {
+
+ if ((*keysize + *b_size) > TVMEMSIZE) {
+ printk("template (%u) too big for tvmem (%u)\n",
+ *keysize + *b_size, TVMEMSIZE);
+ goto out;
+ }
- printk("test %u (%d bit key, %d byte blocks): ", i,
- speed[i].klen * 8, speed[i].blen);
+ printk("test %u (%d bit key, %d byte blocks): ", i,
+ *keysize * 8, *b_size);
- memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
+ 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 == speed[i].klen) {
- key = template[j].key;
- break;
+ /* 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);
@@ -1041,22 +1082,10 @@ static void test_comp(char *algo, struct comp_testvec *ctemplate,
unsigned int i;
char result[COMP_BUF_SIZE];
struct crypto_comp *tfm;
- struct comp_testvec *tv;
unsigned int tsize;
printk("\ntesting %s compression\n", algo);
- tsize = sizeof(struct comp_testvec);
- tsize *= ctcount;
- if (tsize > TVMEMSIZE) {
- printk("template (%u) too big for tvmem (%u)\n", tsize,
- TVMEMSIZE);
- return;
- }
-
- memcpy(tvmem, ctemplate, tsize);
- tv = (void *)tvmem;
-
tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(tfm)) {
printk("failed to load transform for %s\n", algo);
@@ -1069,8 +1098,8 @@ static void test_comp(char *algo, struct comp_testvec *ctemplate,
printk("test %u:\n", i + 1);
memset(result, 0, sizeof (result));
- ilen = tv[i].inlen;
- ret = crypto_comp_compress(tfm, tv[i].input,
+ ilen = ctemplate[i].inlen;
+ ret = crypto_comp_compress(tfm, ctemplate[i].input,
ilen, result, &dlen);
if (ret) {
printk("fail: ret=%d\n", ret);
@@ -1078,7 +1107,7 @@ static void test_comp(char *algo, struct comp_testvec *ctemplate,
}
hexdump(result, dlen);
printk("%s (ratio %d:%d)\n",
- memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
+ memcmp(result, ctemplate[i].output, dlen) ? "fail" : "pass",
ilen, dlen);
}
@@ -1092,17 +1121,14 @@ static void test_comp(char *algo, struct comp_testvec *ctemplate,
goto out;
}
- memcpy(tvmem, dtemplate, tsize);
- tv = (void *)tvmem;
-
for (i = 0; i < dtcount; i++) {
int ilen, ret, dlen = COMP_BUF_SIZE;
printk("test %u:\n", i + 1);
memset(result, 0, sizeof (result));
- ilen = tv[i].inlen;
- ret = crypto_comp_decompress(tfm, tv[i].input,
+ ilen = dtemplate[i].inlen;
+ ret = crypto_comp_decompress(tfm, dtemplate[i].input,
ilen, result, &dlen);
if (ret) {
printk("fail: ret=%d\n", ret);
@@ -1110,7 +1136,7 @@ static void test_comp(char *algo, struct comp_testvec *ctemplate,
}
hexdump(result, dlen);
printk("%s (ratio %d:%d)\n",
- memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
+ memcmp(result, dtemplate[i].output, dlen) ? "fail" : "pass",
ilen, dlen);
}
out:
@@ -1301,6 +1327,12 @@ static void do_test(void)
test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
SEED_DEC_TEST_VECTORS);
+ //CTS
+ test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
+ CTS_MODE_ENC_TEST_VECTORS);
+ test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
+ CTS_MODE_DEC_TEST_VECTORS);
+
test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
@@ -1584,6 +1616,13 @@ static void do_test(void)
AES_CCM_DEC_TEST_VECTORS);
break;
+ case 38:
+ test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
+ CTS_MODE_ENC_TEST_VECTORS);
+ test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
+ CTS_MODE_DEC_TEST_VECTORS);
+ break;
+
case 100:
test_hash("hmac(md5)", hmac_md5_tv_template,
HMAC_MD5_TEST_VECTORS);
@@ -1621,89 +1660,85 @@ static void do_test(void)
case 200:
test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
- aes_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
- aes_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
- aes_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
- aes_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
- aes_lrw_speed_template);
+ speed_template_32_40_48);
test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
- aes_lrw_speed_template);
+ speed_template_32_40_48);
test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
- aes_xts_speed_template);
+ speed_template_32_48_64);
test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
- aes_xts_speed_template);
+ speed_template_32_48_64);
break;
case 201:
test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
- des3_ede_enc_tv_template,
- DES3_EDE_ENC_TEST_VECTORS,
- des3_ede_speed_template);
+ des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
+ speed_template_24);
test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
- des3_ede_dec_tv_template,
- DES3_EDE_DEC_TEST_VECTORS,
- des3_ede_speed_template);
+ des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
+ speed_template_24);
test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
- des3_ede_enc_tv_template,
- DES3_EDE_ENC_TEST_VECTORS,
- des3_ede_speed_template);
+ des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
+ speed_template_24);
test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
- des3_ede_dec_tv_template,
- DES3_EDE_DEC_TEST_VECTORS,
- des3_ede_speed_template);
+ des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
+ speed_template_24);
break;
case 202:
test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
- twofish_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
- twofish_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
- twofish_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
- twofish_speed_template);
+ speed_template_16_24_32);
break;
case 203:
test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
- blowfish_speed_template);
+ speed_template_8_32);
test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
- blowfish_speed_template);
+ speed_template_8_32);
test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
- blowfish_speed_template);
+ speed_template_8_32);
test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
- blowfish_speed_template);
+ speed_template_8_32);
break;
case 204:
test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
- des_speed_template);
+ speed_template_8);
test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
- des_speed_template);
+ speed_template_8);
test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
- des_speed_template);
+ speed_template_8);
test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
- des_speed_template);
+ speed_template_8);
break;
case 205:
test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
- camellia_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
- camellia_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
- camellia_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
- camellia_speed_template);
+ speed_template_16_24_32);
break;
case 206:
test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
- salsa20_speed_template);
+ speed_template_16_32);
break;
case 300:
@@ -1775,7 +1810,7 @@ static void do_test(void)
}
}
-static int __init init(void)
+static int __init tcrypt_mod_init(void)
{
int err = -ENOMEM;
@@ -1814,10 +1849,10 @@ static int __init init(void)
* If an init function is provided, an exit function must also be provided
* to allow module unload.
*/
-static void __exit fini(void) { }
+static void __exit tcrypt_mod_fini(void) { }
-module_init(init);
-module_exit(fini);
+module_init(tcrypt_mod_init);
+module_exit(tcrypt_mod_fini);
module_param(mode, int, 0);
module_param(sec, uint, 0);