[CRYPTO] tcrypt: Use asynchronous hash interface
This patch changes tcrypt to use the new asynchronous hash interface for testing hash algorithm correctness. The speed tests will continue to use the existing interface for now. Signed-off-by: Loc Ho <lho@amcc.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
b8a28251c2
commit
cde0e2c819
1 changed files with 57 additions and 19 deletions
|
@ -104,22 +104,30 @@ static void test_hash(char *algo, struct hash_testvec *template,
|
||||||
unsigned int i, j, k, temp;
|
unsigned int i, j, k, temp;
|
||||||
struct scatterlist sg[8];
|
struct scatterlist sg[8];
|
||||||
char result[64];
|
char result[64];
|
||||||
struct crypto_hash *tfm;
|
struct crypto_ahash *tfm;
|
||||||
struct hash_desc desc;
|
struct ahash_request *req;
|
||||||
|
struct tcrypt_result tresult;
|
||||||
int ret;
|
int ret;
|
||||||
void *hash_buff;
|
void *hash_buff;
|
||||||
|
|
||||||
printk("\ntesting %s\n", algo);
|
printk("\ntesting %s\n", algo);
|
||||||
|
|
||||||
tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
|
init_completion(&tresult.completion);
|
||||||
|
|
||||||
|
tfm = crypto_alloc_ahash(algo, 0, 0);
|
||||||
if (IS_ERR(tfm)) {
|
if (IS_ERR(tfm)) {
|
||||||
printk("failed to load transform for %s: %ld\n", algo,
|
printk("failed to load transform for %s: %ld\n", algo,
|
||||||
PTR_ERR(tfm));
|
PTR_ERR(tfm));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
desc.tfm = tfm;
|
req = ahash_request_alloc(tfm, GFP_KERNEL);
|
||||||
desc.flags = 0;
|
if (!req) {
|
||||||
|
printk(KERN_ERR "failed to allocate request for %s\n", algo);
|
||||||
|
goto out_noreq;
|
||||||
|
}
|
||||||
|
ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
|
||||||
|
tcrypt_complete, &tresult);
|
||||||
|
|
||||||
for (i = 0; i < tcount; i++) {
|
for (i = 0; i < tcount; i++) {
|
||||||
printk("test %u:\n", i + 1);
|
printk("test %u:\n", i + 1);
|
||||||
|
@ -133,8 +141,9 @@ static void test_hash(char *algo, struct hash_testvec *template,
|
||||||
sg_init_one(&sg[0], hash_buff, template[i].psize);
|
sg_init_one(&sg[0], hash_buff, template[i].psize);
|
||||||
|
|
||||||
if (template[i].ksize) {
|
if (template[i].ksize) {
|
||||||
ret = crypto_hash_setkey(tfm, template[i].key,
|
crypto_ahash_clear_flags(tfm, ~0);
|
||||||
template[i].ksize);
|
ret = crypto_ahash_setkey(tfm, template[i].key,
|
||||||
|
template[i].ksize);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printk("setkey() failed ret=%d\n", ret);
|
printk("setkey() failed ret=%d\n", ret);
|
||||||
kfree(hash_buff);
|
kfree(hash_buff);
|
||||||
|
@ -142,17 +151,30 @@ static void test_hash(char *algo, struct hash_testvec *template,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = crypto_hash_digest(&desc, sg, template[i].psize, result);
|
ahash_request_set_crypt(req, sg, result, template[i].psize);
|
||||||
if (ret) {
|
ret = crypto_ahash_digest(req);
|
||||||
|
switch (ret) {
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case -EINPROGRESS:
|
||||||
|
case -EBUSY:
|
||||||
|
ret = wait_for_completion_interruptible(
|
||||||
|
&tresult.completion);
|
||||||
|
if (!ret && !(ret = tresult.err)) {
|
||||||
|
INIT_COMPLETION(tresult.completion);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* fall through */
|
||||||
|
default:
|
||||||
printk("digest () failed ret=%d\n", ret);
|
printk("digest () failed ret=%d\n", ret);
|
||||||
kfree(hash_buff);
|
kfree(hash_buff);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
hexdump(result, crypto_hash_digestsize(tfm));
|
hexdump(result, crypto_ahash_digestsize(tfm));
|
||||||
printk("%s\n",
|
printk("%s\n",
|
||||||
memcmp(result, template[i].digest,
|
memcmp(result, template[i].digest,
|
||||||
crypto_hash_digestsize(tfm)) ?
|
crypto_ahash_digestsize(tfm)) ?
|
||||||
"fail" : "pass");
|
"fail" : "pass");
|
||||||
kfree(hash_buff);
|
kfree(hash_buff);
|
||||||
}
|
}
|
||||||
|
@ -181,8 +203,9 @@ static void test_hash(char *algo, struct hash_testvec *template,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (template[i].ksize) {
|
if (template[i].ksize) {
|
||||||
ret = crypto_hash_setkey(tfm, template[i].key,
|
crypto_ahash_clear_flags(tfm, ~0);
|
||||||
template[i].ksize);
|
ret = crypto_ahash_setkey(tfm, template[i].key,
|
||||||
|
template[i].ksize);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printk("setkey() failed ret=%d\n", ret);
|
printk("setkey() failed ret=%d\n", ret);
|
||||||
|
@ -190,23 +213,38 @@ static void test_hash(char *algo, struct hash_testvec *template,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = crypto_hash_digest(&desc, sg, template[i].psize,
|
ahash_request_set_crypt(req, sg, result,
|
||||||
result);
|
template[i].psize);
|
||||||
if (ret) {
|
ret = crypto_ahash_digest(req);
|
||||||
|
switch (ret) {
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case -EINPROGRESS:
|
||||||
|
case -EBUSY:
|
||||||
|
ret = wait_for_completion_interruptible(
|
||||||
|
&tresult.completion);
|
||||||
|
if (!ret && !(ret = tresult.err)) {
|
||||||
|
INIT_COMPLETION(tresult.completion);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* fall through */
|
||||||
|
default:
|
||||||
printk("digest () failed ret=%d\n", ret);
|
printk("digest () failed ret=%d\n", ret);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
hexdump(result, crypto_hash_digestsize(tfm));
|
hexdump(result, crypto_ahash_digestsize(tfm));
|
||||||
printk("%s\n",
|
printk("%s\n",
|
||||||
memcmp(result, template[i].digest,
|
memcmp(result, template[i].digest,
|
||||||
crypto_hash_digestsize(tfm)) ?
|
crypto_ahash_digestsize(tfm)) ?
|
||||||
"fail" : "pass");
|
"fail" : "pass");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
crypto_free_hash(tfm);
|
ahash_request_free(req);
|
||||||
|
out_noreq:
|
||||||
|
crypto_free_ahash(tfm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_aead(char *algo, int enc, struct aead_testvec *template,
|
static void test_aead(char *algo, int enc, struct aead_testvec *template,
|
||||||
|
|
Loading…
Reference in a new issue