diff --git a/plugin/openssl_plugin/common/inc/openssl_adapter.h b/plugin/openssl_plugin/common/inc/openssl_adapter.h index f4c22ab..5ad1a69 100644 --- a/plugin/openssl_plugin/common/inc/openssl_adapter.h +++ b/plugin/openssl_plugin/common/inc/openssl_adapter.h @@ -215,12 +215,6 @@ EVP_PKEY *OpensslD2iAutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, long struct rsa_st *OpensslEvpPkeyGet1Rsa(EVP_PKEY *pkey); int OpensslEvpPkeySet1Rsa(EVP_PKEY *pkey, struct rsa_st *key); int OpensslEvpPkeyAssignRsa(EVP_PKEY *pkey, struct rsa_st *key); -int OpensslI2dPkcs8PrivateKeyBio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, - char *kstr, int klen, pem_password_cb *cb, void *u); -int OpensslPemWriteBioRsaPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc, - unsigned char *kstr, int klen, pem_password_cb *cb, void *u); -int OpensslPemWriteBioPkcs8PrivateKey(BIO *bp, const EVP_PKEY *x, const EVP_CIPHER *enc, - const char *kstr, int klen, pem_password_cb *cb, void *u); int OpensslPemWriteBioRsaPublicKey(BIO *bp, RSA *x); int OpensslPemWriteBioRsaPubKey(BIO *bp, RSA *x); // BIO @@ -365,8 +359,6 @@ int OpensslI2dSm2CipherText(struct Sm2CipherTextSt *sm2Text, unsigned char **ret int OpensslAsn1StringLength(ASN1_OCTET_STRING *p); const unsigned char *OpensslAsn1StringGet0Data(ASN1_OCTET_STRING *p); -size_t OpensslEcPoint2Oct(const EC_GROUP *group, const EC_POINT *p, point_conversion_form_t form, - unsigned char *buf, size_t len, BN_CTX *ctx); OSSL_PARAM_BLD *OpensslOsslParamBldNew(void); void OpensslOsslParamBldFree(OSSL_PARAM_BLD *bld); OSSL_PARAM *OpensslOsslParamBldToParam(OSSL_PARAM_BLD *bld); diff --git a/plugin/openssl_plugin/common/src/openssl_adapter.c b/plugin/openssl_plugin/common/src/openssl_adapter.c index 93c5211..8760c91 100644 --- a/plugin/openssl_plugin/common/src/openssl_adapter.c +++ b/plugin/openssl_plugin/common/src/openssl_adapter.c @@ -809,24 +809,6 @@ int OpensslEvpPkeyAssignRsa(EVP_PKEY *pkey, struct rsa_st *key) return EVP_PKEY_assign_RSA(pkey, key); } -int OpensslI2dPkcs8PrivateKeyBio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, - char *kstr, int klen, pem_password_cb *cb, void *u) -{ - return i2d_PKCS8PrivateKey_bio(bp, x, enc, kstr, klen, cb, u); -} - -int OpensslPemWriteBioPkcs8PrivateKey(BIO *bp, const EVP_PKEY *x, const EVP_CIPHER *enc, - const char *kstr, int klen, pem_password_cb *cb, void *u) -{ - return PEM_write_bio_PKCS8PrivateKey(bp, x, enc, kstr, klen, cb, u); -} - -int OpensslPemWriteBioRsaPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc, - unsigned char *kstr, int klen, pem_password_cb *cb, void *u) -{ - return PEM_write_bio_RSAPrivateKey(bp, x, enc, kstr, klen, cb, u); -} - int OpensslPemWriteBioRsaPublicKey(BIO *bp, RSA *x) { return PEM_write_bio_RSAPublicKey(bp, x); @@ -1371,12 +1353,6 @@ const unsigned char *OpensslAsn1StringGet0Data(ASN1_OCTET_STRING *p) return ASN1_STRING_get0_data(p); } -size_t OpensslEcPoint2Oct(const EC_GROUP *group, const EC_POINT *p, point_conversion_form_t form, - unsigned char *buf, size_t len, BN_CTX *ctx) -{ - return EC_POINT_point2oct(group, p, form, buf, len, ctx); -} - OSSL_PARAM_BLD *OpensslOsslParamBldNew(void) { return OSSL_PARAM_BLD_new(); diff --git a/plugin/openssl_plugin/crypto_operation/signature/src/dsa_openssl.c b/plugin/openssl_plugin/crypto_operation/signature/src/dsa_openssl.c index 26baef9..2debcae 100644 --- a/plugin/openssl_plugin/crypto_operation/signature/src/dsa_openssl.c +++ b/plugin/openssl_plugin/crypto_operation/signature/src/dsa_openssl.c @@ -620,6 +620,7 @@ HcfResult HcfVerifySpiDsaCreate(HcfSignatureParams *params, HcfVerifySpi **retur } else { HcfResult ret = GetOpensslDigestAlg(params->md, &digestAlg); if (ret != HCF_SUCCESS) { + HcfFree(impl); return HCF_INVALID_PARAMS; } impl->base.engineInit = EngineDsaVerifyInit; 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 18e9d7e..4939a42 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 @@ -1143,7 +1143,7 @@ static HcfResult GetCompressedEccPointEncoded(HcfOpensslEccPubKey *impl, HcfBlob LOGE("Failed to get point."); return HCF_ERR_CRYPTO_OPERATION; } - size_t returnDataLen = OpensslEcPoint2Oct(group, point, POINT_CONVERSION_COMPRESSED, NULL, 0, NULL); + size_t returnDataLen = EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED, NULL, 0, NULL); if (returnDataLen == 0) { LOGE("Failed to get compressed key length."); HcfPrintOpensslError(); @@ -1154,7 +1154,7 @@ static HcfResult GetCompressedEccPointEncoded(HcfOpensslEccPubKey *impl, HcfBlob LOGE("Failed to allocate memory for returnBlob data."); return HCF_ERR_MALLOC; } - size_t result = OpensslEcPoint2Oct(group, point, POINT_CONVERSION_COMPRESSED, + size_t result = EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED, returnData, returnDataLen, NULL); if (result != returnDataLen) { LOGE("Failed to convert public key to compressed format."); @@ -1385,7 +1385,7 @@ static HcfResult GetECPriKeyEncodedDer(const HcfPriKey *self, const char *format ret = HCF_ERR_CRYPTO_OPERATION; goto ERR2; } - if (OpensslI2dPkcs8PrivateKeyBio(bio, pkey, NULL, NULL, 0, NULL, NULL) != HCF_OPENSSL_SUCCESS) { + if (i2d_PKCS8PrivateKey_bio(bio, pkey, NULL, NULL, 0, NULL, NULL) != HCF_OPENSSL_SUCCESS) { LOGE("i2d privateKey bio fail."); HcfPrintOpensslError(); ret = HCF_ERR_CRYPTO_OPERATION; diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/ecc_common_param_spec_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/ecc_common_param_spec_generator_openssl.c index 8246b74..8630d23 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/ecc_common_param_spec_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/ecc_common_param_spec_generator_openssl.c @@ -354,7 +354,7 @@ static HcfResult GetECCPointEncoded(const int32_t formatValue, EC_GROUP *ecGroup return HCF_INVALID_PARAMS; } - size_t returnDataLen = OpensslEcPoint2Oct(ecGroup, ecPoint, formatType, NULL, 0, NULL); + size_t returnDataLen = EC_POINT_point2oct(ecGroup, ecPoint, formatType, NULL, 0, NULL); if (returnDataLen == 0) { LOGE("Failed to get encoded point length."); HcfPrintOpensslError(); @@ -366,7 +366,7 @@ static HcfResult GetECCPointEncoded(const int32_t formatValue, EC_GROUP *ecGroup LOGE("Failed to allocate memory for encoded point data."); return HCF_ERR_MALLOC; } - size_t result = OpensslEcPoint2Oct(ecGroup, ecPoint, formatType, returnData, returnDataLen, NULL); + size_t result = EC_POINT_point2oct(ecGroup, ecPoint, formatType, returnData, returnDataLen, NULL); if (result != returnDataLen) { LOGE("Failed to get ECC point encoding."); HcfPrintOpensslError(); diff --git a/plugin/openssl_plugin/key/asy_key_generator/src/rsa_asy_key_generator_openssl.c b/plugin/openssl_plugin/key/asy_key_generator/src/rsa_asy_key_generator_openssl.c index 87d5322..4ad98a2 100644 --- a/plugin/openssl_plugin/key/asy_key_generator/src/rsa_asy_key_generator_openssl.c +++ b/plugin/openssl_plugin/key/asy_key_generator/src/rsa_asy_key_generator_openssl.c @@ -420,7 +420,7 @@ static HcfResult EncodePriKeyToPKCS8(RSA *rsa, HcfBlob *returnBlob) ret = HCF_ERR_CRYPTO_OPERATION; goto ERR2; } - if (OpensslI2dPkcs8PrivateKeyBio(bio, pKey, NULL, NULL, 0, NULL, NULL) != HCF_OPENSSL_SUCCESS) { + if (i2d_PKCS8PrivateKey_bio(bio, pKey, NULL, NULL, 0, NULL, NULL) != HCF_OPENSSL_SUCCESS) { LOGD("[error] i2b_PrivateKey_bio fail."); HcfPrintOpensslError(); ret = HCF_ERR_CRYPTO_OPERATION; @@ -585,7 +585,7 @@ static HcfResult GetPrikeyPkcs8Pem(EVP_PKEY *pkey, char **returnString) HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } - int ret = OpensslPemWriteBioPkcs8PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL); + int ret = PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL); if (ret != HCF_OPENSSL_SUCCESS) { LOGE("OpensslPemWriteBioPkcs8PrivateKey fail."); HcfPrintOpensslError(); @@ -609,7 +609,7 @@ static HcfResult GetPrikeyPkcs1Pem(RSA *sk, char **returnString) HcfPrintOpensslError(); return HCF_ERR_CRYPTO_OPERATION; } - int ret = OpensslPemWriteBioRsaPrivateKey(bio, sk, NULL, NULL, 0, NULL, NULL); + int ret = PEM_write_bio_RSAPrivateKey(bio, sk, NULL, NULL, 0, NULL, NULL); if (ret != HCF_OPENSSL_SUCCESS) { LOGE("OpensslPemWriteBioRsaPrivateKey fail."); HcfPrintOpensslError(); diff --git a/test/unittest/src/openssl_adapter_mock.c b/test/unittest/src/openssl_adapter_mock.c index c97e21f..10e8ed9 100644 --- a/test/unittest/src/openssl_adapter_mock.c +++ b/test/unittest/src/openssl_adapter_mock.c @@ -1212,12 +1212,6 @@ int OpensslEvpPkeyAssignRsa(EVP_PKEY *pkey, struct rsa_st *key) return EVP_PKEY_assign_RSA(pkey, key); } -int OpensslI2dPkcs8PrivateKeyBio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, - char *kstr, int klen, pem_password_cb *cb, void *u) -{ - return i2d_PKCS8PrivateKey_bio(bp, x, enc, kstr, klen, cb, u); -} - BIO *OpensslBioNew(const BIO_METHOD *type) { return BIO_new(type); @@ -1868,15 +1862,6 @@ int OpensslDhSet0Key(DH *dh, BIGNUM *pubKey, BIGNUM *privKey) return DH_set0_key(dh, pubKey, privKey); } -size_t OpensslEcPoint2Oct(const EC_GROUP *group, const EC_POINT *p, point_conversion_form_t form, - unsigned char *buf, size_t len, BN_CTX *ctx) -{ - if (IsNeedMock()) { - return -1; - } - return EC_POINT_point2oct(group, p, form, buf, len, ctx); -} - OSSL_PARAM_BLD *OpensslOsslParamBldNew(void) { if (IsNeedMock()) {