Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 99279
b: refs/heads/master
c: cde0e2c
h: refs/heads/master
i:
  99277: dcba5c1
  99275: e80f519
  99271: 26147eb
  99263: a82cab6
v: v3
  • Loading branch information
Loc Ho authored and Herbert Xu committed Jul 10, 2008
1 parent 2e37e1d commit 52bb6fc
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 20 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: b8a28251c2066a2ac6481fc49ced5eb7f078e49b
refs/heads/master: cde0e2c819aad91ed1e1c2e8aa64c16e7774c769
76 changes: 57 additions & 19 deletions trunk/crypto/tcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,30 @@ static void test_hash(char *algo, struct hash_testvec *template,
unsigned int i, j, k, temp;
struct scatterlist sg[8];
char result[64];
struct crypto_hash *tfm;
struct hash_desc desc;
struct crypto_ahash *tfm;
struct ahash_request *req;
struct tcrypt_result tresult;
int ret;
void *hash_buff;

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)) {
printk("failed to load transform for %s: %ld\n", algo,
PTR_ERR(tfm));
return;
}

desc.tfm = tfm;
desc.flags = 0;
req = ahash_request_alloc(tfm, GFP_KERNEL);
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++) {
printk("test %u:\n", i + 1);
Expand All @@ -133,26 +141,40 @@ static void test_hash(char *algo, struct hash_testvec *template,
sg_init_one(&sg[0], hash_buff, template[i].psize);

if (template[i].ksize) {
ret = crypto_hash_setkey(tfm, template[i].key,
template[i].ksize);
crypto_ahash_clear_flags(tfm, ~0);
ret = crypto_ahash_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, template[i].psize, result);
if (ret) {
ahash_request_set_crypt(req, sg, result, template[i].psize);
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);
kfree(hash_buff);
goto out;
}

hexdump(result, crypto_hash_digestsize(tfm));
hexdump(result, crypto_ahash_digestsize(tfm));
printk("%s\n",
memcmp(result, template[i].digest,
crypto_hash_digestsize(tfm)) ?
crypto_ahash_digestsize(tfm)) ?
"fail" : "pass");
kfree(hash_buff);
}
Expand Down Expand Up @@ -181,32 +203,48 @@ static void test_hash(char *algo, struct hash_testvec *template,
}

if (template[i].ksize) {
ret = crypto_hash_setkey(tfm, template[i].key,
template[i].ksize);
crypto_ahash_clear_flags(tfm, ~0);
ret = crypto_ahash_setkey(tfm, template[i].key,
template[i].ksize);

if (ret) {
printk("setkey() failed ret=%d\n", ret);
goto out;
}
}

ret = crypto_hash_digest(&desc, sg, template[i].psize,
result);
if (ret) {
ahash_request_set_crypt(req, sg, result,
template[i].psize);
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);
goto out;
}

hexdump(result, crypto_hash_digestsize(tfm));
hexdump(result, crypto_ahash_digestsize(tfm));
printk("%s\n",
memcmp(result, template[i].digest,
crypto_hash_digestsize(tfm)) ?
crypto_ahash_digestsize(tfm)) ?
"fail" : "pass");
}
}

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,
Expand Down

0 comments on commit 52bb6fc

Please sign in to comment.