diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/ecc_asy_key_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/ecc_asy_key_generator_openssl.c index 1fe6536072d94e98a0fb9dbc122039d396d3b879..78c4000d4c8469cdb1732f893e436aea8efa10cc 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/ecc_asy_key_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/ecc_asy_key_generator_openssl.c @@ -1671,6 +1671,7 @@ static HcfResult PackEccPubKey(int32_t curveId, EC_KEY *ecKey, const char *field size_t len = HcfStrlen(fieldType); if (!len) { LOGE("fieldType is empty!"); + HcfFree(returnPubKey); return HCF_INVALID_PARAMS; } tmpFieldType = (char *)HcfMalloc(len + 1, 0); @@ -1711,6 +1712,7 @@ static HcfResult PackEccPriKey(int32_t curveId, EC_KEY *ecKey, const char *field size_t len = HcfStrlen(fieldType); if (!len) { LOGE("fieldType is empty!"); + HcfFree(returnPriKey); return HCF_INVALID_PARAMS; } tmpFieldType = (char *)HcfMalloc(len + 1, 0); diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/sm2_asy_key_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/sm2_asy_key_generator_openssl.c index b070a7a28fb1dbf502b4ecf7af3d3bbc260eae88..6809ceabcd405d0591f5e99f3d3935cd0748c317 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/sm2_asy_key_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/sm2_asy_key_generator_openssl.c @@ -343,18 +343,24 @@ static HcfResult SetEcPubKeyFromPriKey(const HcfBigInteger *priKey, EC_KEY *ecKe } HcfResult ret = HCF_SUCCESS; EC_POINT *point = Openssl_EC_POINT_new(group); - if (point == NULL) { - LOGE("Openssl_EC_POINT_new failed."); - ret = HCF_ERR_CRYPTO_OPERATION; - } - if (!Openssl_EC_POINT_mul(group, point, sk, NULL, NULL, NULL)) { - LOGE("Openssl_EC_POINT_new or Openssl_EC_POINT_mul failed."); - ret = HCF_ERR_CRYPTO_OPERATION; - } - if (!Openssl_EC_KEY_set_public_key(ecKey, point)) { - LOGE("Openssl_EC_KEY_set_public_key failed."); - ret = HCF_ERR_CRYPTO_OPERATION; - } + + do { + if (point == NULL) { + LOGE("Openssl_EC_POINT_new failed."); + ret = HCF_ERR_CRYPTO_OPERATION; + break; + } + if (!Openssl_EC_POINT_mul(group, point, sk, NULL, NULL, NULL)) { + LOGE("Openssl_EC_POINT_new or Openssl_EC_POINT_mul failed."); + ret = HCF_ERR_CRYPTO_OPERATION; + break; + } + if (!Openssl_EC_KEY_set_public_key(ecKey, point)) { + LOGE("Openssl_EC_KEY_set_public_key failed."); + ret = HCF_ERR_CRYPTO_OPERATION; + } + } while (0); + Openssl_EC_POINT_free(point); Openssl_BN_free(sk); return ret; @@ -1154,6 +1160,7 @@ static HcfResult PackSm2PubKey(int32_t curveId, EC_KEY *ecKey, const char *field size_t len = HcfStrlen(fieldType); if (!len) { LOGE("fieldType is empty!"); + HcfFree(returnPubKey); return HCF_INVALID_PARAMS; } tmpFieldType = (char *)HcfMalloc(len + 1, 0); @@ -1194,6 +1201,7 @@ static HcfResult PackSm2PriKey(int32_t curveId, EC_KEY *ecKey, const char *field size_t len = HcfStrlen(fieldType); if (len == 0) { LOGE("fieldType is empty!"); + HcfFree(returnPriKey); return HCF_INVALID_PARAMS; } tmpFieldType = (char *)HcfMalloc(len + 1, 0);