crypto: tcrypt - Fix missing return value check

to #36549273

commit 7b3d52683b upstream

There are several places where the return value check of crypto_aead_setkey
and crypto_aead_setauthsize were lost. It is necessary to add these checks.

At the same time, move the crypto_aead_setauthsize() call out of the loop,
and only need to call it once after load transform.

Fixee: 53f52d7aec ("crypto: tcrypt - Added speed tests for AEAD crypto alogrithms in tcrypt test suite")
Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Reviewed-by: Vitaly Chikunov <vt@altlinux.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: YiLin.Li <YiLin.Li@linux.alibaba.com>
Reviewed-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
This commit is contained in:
Tianjia Zhang 2021-08-13 15:55:06 +08:00 committed by Shile Zhang
parent 836236b47a
commit 3044572533
1 changed files with 19 additions and 10 deletions

View File

@ -293,6 +293,11 @@ static void test_mb_aead_speed(const char *algo, int enc, int secs,
} }
ret = crypto_aead_setauthsize(tfm, authsize); ret = crypto_aead_setauthsize(tfm, authsize);
if (ret) {
pr_err("alg: aead: Failed to setauthsize for %s: %d\n", algo,
ret);
goto out_free_tfm;
}
for (i = 0; i < num_mb; ++i) for (i = 0; i < num_mb; ++i)
if (testmgr_alloc_buf(data[i].xbuf)) { if (testmgr_alloc_buf(data[i].xbuf)) {
@ -318,7 +323,7 @@ static void test_mb_aead_speed(const char *algo, int enc, int secs,
for (i = 0; i < num_mb; ++i) { for (i = 0; i < num_mb; ++i) {
data[i].req = aead_request_alloc(tfm, GFP_KERNEL); data[i].req = aead_request_alloc(tfm, GFP_KERNEL);
if (!data[i].req) { if (!data[i].req) {
pr_err("alg: skcipher: Failed to allocate request for %s\n", pr_err("alg: aead: Failed to allocate request for %s\n",
algo); algo);
while (i--) while (i--)
aead_request_free(data[i].req); aead_request_free(data[i].req);
@ -570,13 +575,19 @@ static void test_aead_speed(const char *algo, int enc, unsigned int secs,
sgout = &sg[9]; sgout = &sg[9];
tfm = crypto_alloc_aead(algo, 0, 0); tfm = crypto_alloc_aead(algo, 0, 0);
if (IS_ERR(tfm)) { if (IS_ERR(tfm)) {
pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo, pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
PTR_ERR(tfm)); PTR_ERR(tfm));
goto out_notfm; goto out_notfm;
} }
ret = crypto_aead_setauthsize(tfm, authsize);
if (ret) {
pr_err("alg: aead: Failed to setauthsize for %s: %d\n", algo,
ret);
goto out_noreq;
}
crypto_init_wait(&wait); crypto_init_wait(&wait);
printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo, printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
get_driver_name(crypto_aead, tfm), e); get_driver_name(crypto_aead, tfm), e);
@ -614,8 +625,13 @@ static void test_aead_speed(const char *algo, int enc, unsigned int secs,
break; break;
} }
} }
ret = crypto_aead_setkey(tfm, key, *keysize); ret = crypto_aead_setkey(tfm, key, *keysize);
ret = crypto_aead_setauthsize(tfm, authsize); if (ret) {
pr_err("setkey() failed flags=%x: %d\n",
crypto_aead_get_flags(tfm), ret);
goto out;
}
iv_len = crypto_aead_ivsize(tfm); iv_len = crypto_aead_ivsize(tfm);
if (iv_len) if (iv_len)
@ -625,15 +641,8 @@ static void test_aead_speed(const char *algo, int enc, unsigned int secs,
printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ", printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
i, *keysize * 8, bs); i, *keysize * 8, bs);
memset(tvmem[0], 0xff, PAGE_SIZE); memset(tvmem[0], 0xff, PAGE_SIZE);
if (ret) {
pr_err("setkey() failed flags=%x\n",
crypto_aead_get_flags(tfm));
goto out;
}
sg_init_aead(sg, xbuf, bs + (enc ? 0 : authsize), sg_init_aead(sg, xbuf, bs + (enc ? 0 : authsize),
assoc, aad_size); assoc, aad_size);