commit: e26726: digest: fix codecheck warning Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com> (cherry picked from commit f6221f178fe43735fe56d45ae8d030dd949b3a23)
210 lines
5.6 KiB
Diff
210 lines
5.6 KiB
Diff
From dbb4ff29da9ed378d8753a6e5d18e86756c1d254 Mon Sep 17 00:00:00 2001
|
|
From: Zhiqi Song <songzhiqi1@huawei.com>
|
|
Date: Mon, 27 Dec 2021 07:04:43 +0000
|
|
Subject: [PATCH 11/18] ecc: cleanup the form of the return value
|
|
|
|
This patch includes:
|
|
1. Unified the return value form.
|
|
2. Remove redundant goto jumps.
|
|
|
|
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
|
|
---
|
|
src/uadk_ec.c | 20 +++++++++++---------
|
|
src/uadk_ecx.c | 8 ++++----
|
|
src/uadk_pkey.c | 5 ++---
|
|
src/uadk_sm2.c | 8 ++++----
|
|
4 files changed, 21 insertions(+), 20 deletions(-)
|
|
|
|
diff --git a/src/uadk_ec.c b/src/uadk_ec.c
|
|
index 0c8a011..db69871 100644
|
|
--- a/src/uadk_ec.c
|
|
+++ b/src/uadk_ec.c
|
|
@@ -446,7 +446,7 @@ static ECDSA_SIG *ecdsa_do_sign(const unsigned char *dgst, int dlen,
|
|
goto uninit_iot;
|
|
|
|
ret = uadk_ecc_crypto(sess, &req, (void *)sess);
|
|
- if (ret != 1)
|
|
+ if (!ret)
|
|
goto uninit_iot;
|
|
|
|
sig = create_ecdsa_sig(&req);
|
|
@@ -635,11 +635,14 @@ static int ecdsa_do_verify(const unsigned char *dgst, int dlen,
|
|
goto uninit_iot;
|
|
|
|
ret = uadk_ecc_crypto(sess, &req, (void *)sess);
|
|
- if (ret != 1) {
|
|
+ if (!ret) {
|
|
fprintf(stderr, "failed to uadk_ecc_crypto, ret = %d\n", ret);
|
|
goto uninit_iot;
|
|
}
|
|
|
|
+ wd_ecc_del_in(sess, req.src);
|
|
+ wd_ecc_free_sess(sess);
|
|
+
|
|
return ret;
|
|
|
|
uninit_iot:
|
|
@@ -701,7 +704,7 @@ static int set_key_to_ec_key(EC_KEY *ec, struct wd_ecc_req *req)
|
|
tmp = BN_bin2bn((unsigned char *)privkey->data, privkey->dsize, NULL);
|
|
ret = EC_KEY_set_private_key(ec, tmp);
|
|
BN_free(tmp);
|
|
- if (ret != 1) {
|
|
+ if (!ret) {
|
|
fprintf(stderr, "failed to EC KEY set private key\n");
|
|
return -EINVAL;
|
|
}
|
|
@@ -725,7 +728,7 @@ static int set_key_to_ec_key(EC_KEY *ec, struct wd_ecc_req *req)
|
|
|
|
ret = EC_KEY_set_public_key(ec, point);
|
|
EC_POINT_free(point);
|
|
- if (ret != 1) {
|
|
+ if (!ret) {
|
|
fprintf(stderr, "failed to EC_KEY_set_public_key\n");
|
|
return -EINVAL;
|
|
}
|
|
@@ -900,18 +903,17 @@ static int sm2_generate_key(EC_KEY *eckey)
|
|
goto free_sess;
|
|
|
|
ret = uadk_ecc_crypto(sess, &req, (void *)sess);
|
|
- if (ret != 1)
|
|
+ if (!ret)
|
|
goto uninit_iot;
|
|
|
|
ret = set_key_to_ec_key(eckey, &req);
|
|
if (ret)
|
|
goto uninit_iot;
|
|
|
|
- ret = 1;
|
|
wd_ecc_del_out(sess, req.dst);
|
|
wd_ecc_free_sess(sess);
|
|
|
|
- return ret;
|
|
+ return 1;
|
|
|
|
uninit_iot:
|
|
wd_ecc_del_out(sess, req.dst);
|
|
@@ -1119,7 +1121,7 @@ static int ecdh_generate_key(EC_KEY *ecdh)
|
|
goto uninit_iot;
|
|
|
|
ret = uadk_ecc_crypto(sess, &req, (void *)sess);
|
|
- if (ret != 1)
|
|
+ if (!ret)
|
|
goto uninit_iot;
|
|
|
|
ret = ecdh_set_key_to_ec_key(ecdh, &req);
|
|
@@ -1228,7 +1230,7 @@ static int ecdh_compute_key(unsigned char **out, size_t *outlen,
|
|
goto uninit_iot;
|
|
|
|
ret = uadk_ecc_crypto(sess, &req, (void *)sess);
|
|
- if (ret != 1)
|
|
+ if (!ret)
|
|
goto uninit_iot;
|
|
|
|
ret = ecdh_get_shared_key(ecdh, out, outlen, &req);
|
|
diff --git a/src/uadk_ecx.c b/src/uadk_ecx.c
|
|
index 6a9f78c..67f9350 100644
|
|
--- a/src/uadk_ecx.c
|
|
+++ b/src/uadk_ecx.c
|
|
@@ -399,7 +399,7 @@ static int x25519_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
|
|
goto uninit_iot;
|
|
|
|
ret = uadk_ecc_crypto(keygen_ctx->sess, &req, (void *)keygen_ctx->sess);
|
|
- if (ret != 1)
|
|
+ if (!ret)
|
|
goto uninit_iot;
|
|
|
|
ret = ecx_keygen_set_pkey(pkey, keygen_ctx, &req, ecx_key);
|
|
@@ -457,7 +457,7 @@ static int x448_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
|
|
goto uninit_iot;
|
|
|
|
ret = uadk_ecc_crypto(keygen_ctx->sess, &req, (void *)keygen_ctx->sess);
|
|
- if (ret != 1)
|
|
+ if (!ret)
|
|
goto uninit_iot;
|
|
|
|
ret = ecx_keygen_set_pkey(pkey, keygen_ctx, &req, ecx_key);
|
|
@@ -659,7 +659,7 @@ static int x25519_derive(EVP_PKEY_CTX *ctx, unsigned char *key,
|
|
goto uninit_iot;
|
|
|
|
ret = uadk_ecc_crypto(derive_ctx->sess, &req, (void *)derive_ctx);
|
|
- if (ret != 1)
|
|
+ if (!ret)
|
|
goto uninit_iot;
|
|
|
|
wd_ecxdh_get_out_params(req.dst, &s_key);
|
|
@@ -745,7 +745,7 @@ static int x448_derive(EVP_PKEY_CTX *ctx, unsigned char *key,
|
|
goto uninit_iot;
|
|
|
|
ret = uadk_ecc_crypto(derive_ctx->sess, &req, (void *)derive_ctx);
|
|
- if (ret != 1)
|
|
+ if (!ret)
|
|
goto uninit_iot;
|
|
|
|
wd_ecxdh_get_out_params(req.dst, &s_key);
|
|
diff --git a/src/uadk_pkey.c b/src/uadk_pkey.c
|
|
index 62362b0..7ca998b 100644
|
|
--- a/src/uadk_pkey.c
|
|
+++ b/src/uadk_pkey.c
|
|
@@ -273,8 +273,7 @@ static void uadk_wd_ecc_uninit(void)
|
|
ecc_res.pid = 0;
|
|
}
|
|
|
|
-int uadk_ecc_crypto(handle_t sess,
|
|
- struct wd_ecc_req *req, void *usr)
|
|
+int uadk_ecc_crypto(handle_t sess, struct wd_ecc_req *req, void *usr)
|
|
{
|
|
struct uadk_e_cb_info cb_param;
|
|
struct async_op op;
|
|
@@ -314,7 +313,7 @@ int uadk_ecc_crypto(handle_t sess,
|
|
} else {
|
|
ret = wd_do_ecc_sync(sess, req);
|
|
if (ret < 0)
|
|
- return ret;
|
|
+ return 0;
|
|
}
|
|
return 1;
|
|
err:
|
|
diff --git a/src/uadk_sm2.c b/src/uadk_sm2.c
|
|
index 6d5dad0..f602e48 100644
|
|
--- a/src/uadk_sm2.c
|
|
+++ b/src/uadk_sm2.c
|
|
@@ -359,7 +359,7 @@ static int sign_bin_to_ber(EC_KEY *ec, struct wd_dtb *r, struct wd_dtb *s,
|
|
}
|
|
|
|
ret = ECDSA_SIG_set0(e_sig, br, bs);
|
|
- if (ret != 1) {
|
|
+ if (!ret) {
|
|
fprintf(stderr, "failed to ECDSA_SIG_set0\n");
|
|
ret = -EINVAL;
|
|
goto free_s;
|
|
@@ -686,7 +686,7 @@ static int sm2_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
|
|
}
|
|
|
|
ret = uadk_ecc_crypto(smctx->sess, &req, smctx);
|
|
- if (ret != 1) {
|
|
+ if (!ret) {
|
|
fprintf(stderr, "failed to uadk_ecc_crypto, ret = %d\n", ret);
|
|
ret = UADK_DO_SOFT;
|
|
goto uninit_iot;
|
|
@@ -907,7 +907,7 @@ static int sm2_encrypt(EVP_PKEY_CTX *ctx,
|
|
}
|
|
|
|
ret = uadk_ecc_crypto(smctx->sess, &req, smctx);
|
|
- if (ret != 1) {
|
|
+ if (!ret) {
|
|
ret = UADK_DO_SOFT;
|
|
fprintf(stderr, "failed to uadk_ecc_crypto, ret = %d\n", ret);
|
|
goto uninit_iot;
|
|
@@ -1061,7 +1061,7 @@ static int sm2_decrypt(EVP_PKEY_CTX *ctx,
|
|
}
|
|
|
|
ret = uadk_ecc_crypto(smctx->sess, &req, smctx);
|
|
- if (ret != 1) {
|
|
+ if (!ret) {
|
|
ret = UADK_DO_SOFT;
|
|
fprintf(stderr, "failed to uadk_ecc_crypto, ret = %d\n", ret);
|
|
goto uninit_iot;
|
|
--
|
|
2.24.4
|
|
|