Remove NULL checks on inputs that are guaranteed non-NULL by the OpenSSL engine/provider framework or by internal call sites: - eckey_check() in uadk_ec.c: the eckey argument is provided by the ECDSA_METHOD / ECDH_METHOD callbacks. - uadk_prov_ecx_keygen/derive: static functions with always-valid args. Also remove redundant = NULL initializations on local variables that are assigned from function return values before any use, including: - BN_CTX_new / BN_CTX_get / BN_new / BN_bin2bn return values - OPENSSL_zalloc / create_ecdsa_sig return values Variables initialized via function output parameters (e.g. ECDSA_SIG_get0, wd_ecxdh_get_out_params, EC_KEY_METHOD_get_*) retain their = NULL initialization. Signed-off-by: Weili Qian <qianweili@huawei.com> --- src/uadk_ec.c | 9 ++------- src/uadk_prov_ecx.c | 10 +--------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/uadk_ec.c b/src/uadk_ec.c index 648cce9..e76a127 100644 --- a/src/uadk_ec.c +++ b/src/uadk_ec.c @@ -259,11 +259,6 @@ static int eckey_check(const EC_KEY *eckey) const EC_POINT *g; int bits; - if (!eckey) { - fprintf(stderr, "eckey is NULL\n"); - return -1; - } - group = EC_KEY_get0_group(eckey); if (!group) { fprintf(stderr, "group is NULL\n"); @@ -483,8 +478,8 @@ static ECDSA_SIG *ecdsa_do_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey) { struct wd_ecc_req req; - ECDSA_SIG *sig = NULL; struct wd_dtb tdgst; + ECDSA_SIG *sig; handle_t sess; int ret; @@ -1401,7 +1396,7 @@ static int ecdh_set_cofactor_privkey(handle_t sess, const EC_KEY *ecdh) goto end; } - key_bytes = (EC_GROUP_get_degree(group) + 7) / 8; + key_bytes = (EC_GROUP_get_degree(group) + UADK_ECC_PADDING) >> TRANS_BITS_BYTES_SHIFT; ret = uadk_ecc_set_private_key_bn(sess, cofactor_priv, key_bytes); end: diff --git a/src/uadk_prov_ecx.c b/src/uadk_prov_ecx.c index cdd49ff..0b85d75 100644 --- a/src/uadk_prov_ecx.c +++ b/src/uadk_prov_ecx.c @@ -744,9 +744,6 @@ static int uadk_prov_ecx_keygen(PROV_ECX_KEYMGMT_CTX *gctx, ECX_KEY **ecx_key) struct wd_ecc_req req = {0}; int ret; - if (ecx_key == NULL) - return UADK_P_FAIL; - *ecx_key = uadk_prov_ecx_create_prikey(gctx); if (*ecx_key == NULL || !(gctx->selection & OSSL_KEYMGMT_SELECT_KEYPAIR)) return UADK_P_FAIL; @@ -1126,11 +1123,6 @@ static int uadk_prov_ecx_derive(PROV_ECX_KEYEXCH_CTX *ecxctx, unsigned char *key ECX_KEY *ecx_key; int ret; - if (ecxctx == NULL) { - UADK_ERR("invalid: ctx is NULL\n"); - return UADK_P_FAIL; - } - peer_ecx_key = ecxctx->peerkey; ecx_key = ecxctx->key; if (peer_ecx_key == NULL || ecx_key == NULL) { @@ -1528,7 +1520,7 @@ exe_soft: static void *uadk_keyexch_x25519_newctx(void *provctx) { - PROV_ECX_KEYEXCH_CTX *ecxctx = NULL; + PROV_ECX_KEYEXCH_CTX *ecxctx; ecxctx = OPENSSL_zalloc(sizeof(PROV_ECX_KEYEXCH_CTX)); if (ecxctx == NULL) { -- 2.43.0